diff options
| author | Stefan Monnier | 2017-01-30 13:06:07 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2017-01-30 13:06:07 -0500 |
| commit | 499780daef5b9c5d426923ac325b111d3b14267f (patch) | |
| tree | 6f4ff137c2110a3ced5a3908ab1a7379252dbceb /lisp | |
| parent | f74d496478cd57f252817bd7437fe1b7972ce01f (diff) | |
| download | emacs-499780daef5b9c5d426923ac325b111d3b14267f.tar.gz emacs-499780daef5b9c5d426923ac325b111d3b14267f.zip | |
* lisp/indent.el (indent-region-line-by-line): New function.
Extracted from indent-region.
(indent-region, indent-region-function): Use it.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/indent.el | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/lisp/indent.el b/lisp/indent.el index db31f0454ce..fdd184c7998 100644 --- a/lisp/indent.el +++ b/lisp/indent.el | |||
| @@ -487,9 +487,9 @@ line, but does not move past any whitespace that was explicitly inserted | |||
| 487 | (if (memq (current-justification) '(center right)) | 487 | (if (memq (current-justification) '(center right)) |
| 488 | (skip-chars-forward " \t"))) | 488 | (skip-chars-forward " \t"))) |
| 489 | 489 | ||
| 490 | (defvar indent-region-function nil | 490 | (defvar indent-region-function #'indent-region-line-by-line |
| 491 | "Short cut function to indent region using `indent-according-to-mode'. | 491 | "Short cut function to indent region using `indent-according-to-mode'. |
| 492 | A value of nil means really run `indent-according-to-mode' on each line.") | 492 | Default is to really run `indent-according-to-mode' on each line.") |
| 493 | 493 | ||
| 494 | (defun indent-region (start end &optional column) | 494 | (defun indent-region (start end &optional column) |
| 495 | "Indent each nonblank line in the region. | 495 | "Indent each nonblank line in the region. |
| @@ -541,24 +541,26 @@ column to indent to; if it is nil, use one of the three methods above." | |||
| 541 | (funcall indent-region-function start end)) | 541 | (funcall indent-region-function start end)) |
| 542 | ;; Else, use a default implementation that calls indent-line-function on | 542 | ;; Else, use a default implementation that calls indent-line-function on |
| 543 | ;; each line. | 543 | ;; each line. |
| 544 | (t | 544 | (t (indent-region-line-by-line start end))) |
| 545 | (save-excursion | ||
| 546 | (setq end (copy-marker end)) | ||
| 547 | (goto-char start) | ||
| 548 | (let ((pr (unless (minibufferp) | ||
| 549 | (make-progress-reporter "Indenting region..." (point) end)))) | ||
| 550 | (while (< (point) end) | ||
| 551 | (or (and (bolp) (eolp)) | ||
| 552 | (indent-according-to-mode)) | ||
| 553 | (forward-line 1) | ||
| 554 | (and pr (progress-reporter-update pr (point)))) | ||
| 555 | (and pr (progress-reporter-done pr)) | ||
| 556 | (move-marker end nil))))) | ||
| 557 | ;; In most cases, reindenting modifies the buffer, but it may also | 545 | ;; In most cases, reindenting modifies the buffer, but it may also |
| 558 | ;; leave it unmodified, in which case we have to deactivate the mark | 546 | ;; leave it unmodified, in which case we have to deactivate the mark |
| 559 | ;; by hand. | 547 | ;; by hand. |
| 560 | (setq deactivate-mark t)) | 548 | (setq deactivate-mark t)) |
| 561 | 549 | ||
| 550 | (defun indent-region-line-by-line (start end) | ||
| 551 | (save-excursion | ||
| 552 | (setq end (copy-marker end)) | ||
| 553 | (goto-char start) | ||
| 554 | (let ((pr (unless (minibufferp) | ||
| 555 | (make-progress-reporter "Indenting region..." (point) end)))) | ||
| 556 | (while (< (point) end) | ||
| 557 | (or (and (bolp) (eolp)) | ||
| 558 | (indent-according-to-mode)) | ||
| 559 | (forward-line 1) | ||
| 560 | (and pr (progress-reporter-update pr (point)))) | ||
| 561 | (and pr (progress-reporter-done pr)) | ||
| 562 | (move-marker end nil)))) | ||
| 563 | |||
| 562 | (define-obsolete-function-alias 'indent-relative-maybe | 564 | (define-obsolete-function-alias 'indent-relative-maybe |
| 563 | 'indent-relative-first-indent-point "26.1") | 565 | 'indent-relative-first-indent-point "26.1") |
| 564 | 566 | ||