General & minor refactoring

This commit is contained in:
Henrik Lissner 2018-08-28 13:36:44 +02:00
parent ed0cbc1323
commit 2b560a6a0e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
6 changed files with 30 additions and 29 deletions

View file

@ -144,27 +144,28 @@ Advanced examples:
;; format a region rather than the whole buffer.
(require 'format-all)
(save-restriction
(let* ((beg (save-excursion (goto-char beg) (line-beginning-position)))
(end (save-excursion (goto-char end)
(if (bolp) (backward-char))
(line-end-position)))
(file buffer-file-name)
(dir default-directory)
(mode major-mode)
(input (buffer-substring-no-properties beg end))
(leading-indent 0)
final-output)
(with-temp-buffer
(with-silent-modifications
(setq buffer-file-name file
default-directory dir)
(delay-mode-hooks (funcall mode))
(save-excursion (insert input))
(setq leading-indent (current-indentation))
(indent-rigidly (point-min) (point-max) (- leading-indent))
;; From `format-all-buffer'
(cl-destructuring-bind (formatter mode-result) (format-all-probe)
(unless formatter (error "Don't know how to format %S code" major-mode))
(cl-destructuring-bind (formatter mode-result) (format-all-probe)
(unless formatter
(user-error "Don't know how to format %S code" major-mode))
(let* ((beg (save-excursion (goto-char beg) (line-beginning-position)))
(end (save-excursion (goto-char end)
(if (bolp) (backward-char))
(line-end-position)))
(file buffer-file-name)
(dir default-directory)
(mode major-mode)
(input (buffer-substring-no-properties beg end))
(leading-indent 0)
final-output)
(with-temp-buffer
(with-silent-modifications
(setq buffer-file-name file
default-directory dir)
(delay-mode-hooks (funcall mode))
(save-excursion (insert input))
(setq leading-indent (current-indentation))
(indent-rigidly (point-min) (point-max) (- leading-indent))
;; From `format-all-buffer'
(let ((f-function (gethash formatter format-all-format-table))
(executable (format-all-formatter-executable formatter)))
(cl-destructuring-bind (output errput first-diff)