branch: externals/aggressive-indent commit 1d7185d27020c3e91a7da21800716079297938ac Author: Artur Malabarba <bruce.connor...@gmail.com> Commit: Artur Malabarba <bruce.connor...@gmail.com>
Fix #106 - Define variable: aggressive-indent-region-function --- aggressive-indent.el | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/aggressive-indent.el b/aggressive-indent.el index a3b2b82..8718373 100644 --- a/aggressive-indent.el +++ b/aggressive-indent.el @@ -280,6 +280,12 @@ erroring again." (message aggressive-indent--error-message er)))))) ;;; Indenting defun +(defcustom aggressive-indent-region-function #'indent-region + "Function called to indent a region. +It is called with two arguments, the region beginning and end." + :risky t + :type 'function) + ;;;###autoload (defun aggressive-indent-indent-defun (&optional l r) "Indent current defun. @@ -288,13 +294,13 @@ If L and R are provided, use them for finding the start and end of defun." (interactive) (let ((p (point-marker))) (set-marker-insertion-type p t) - (indent-region - (save-excursion - (when l (goto-char l)) - (beginning-of-defun 1) (point)) - (save-excursion - (when r (goto-char r)) - (end-of-defun 1) (point))) + (funcall aggressive-indent-region-function + (save-excursion + (when l (goto-char l)) + (beginning-of-defun 1) (point)) + (save-excursion + (when r (goto-char r)) + (end-of-defun 1) (point))) (goto-char p))) (defun aggressive-indent--softly-indent-defun (&optional l r) @@ -327,7 +333,7 @@ Return non-nil only if the line's indentation actually changed." (forward-sexp 1) (comment-forward (point-max))) (when (looking-at "^") - (indent-region line-end (1- (point)))) + (funcall aggressive-indent-region-function line-end (1- (point)))) (skip-chars-forward "[:blank:]"))))) (defun aggressive-indent--extend-end-to-whole-sexps (beg end) @@ -342,8 +348,8 @@ Return non-nil only if the line's indentation actually changed." ;;;###autoload (defun aggressive-indent-indent-region-and-on (l r) "Indent region between L and R, and then some. -Call `indent-region' between L and R, and then keep indenting -until nothing more happens." +Call `aggressive-indent-region-function' between L and R, and +then keep indenting until nothing more happens." (interactive "r") (let ((p (point-marker)) was-begining-of-line) @@ -359,7 +365,7 @@ until nothing more happens." (cl-incf l))) ;; Indent the affected region. (goto-char r) - (unless (= l r) (indent-region l r)) + (unless (= l r) (funcall aggressive-indent-region-function l r)) ;; And then we indent each following line until nothing happens. (forward-line 1) (skip-chars-forward "[:blank:]\n\r\xc")