diff options
| author | Basil L. Contovounesios | 2019-03-27 15:13:25 +0000 |
|---|---|---|
| committer | Basil L. Contovounesios | 2019-03-31 17:08:21 +0100 |
| commit | 0cd250e9583deb1e1f4d8dae2ec44c4f7c13efa6 (patch) | |
| tree | a50516ab3cc6eebcfc683a037a88d31a805c8a7f /lisp | |
| parent | 99be0aba4defb8377cb148f7805ea07babc6182f (diff) | |
| download | emacs-0cd250e9583deb1e1f4d8dae2ec44c4f7c13efa6.tar.gz emacs-0cd250e9583deb1e1f4d8dae2ec44c4f7c13efa6.zip | |
Fix recently extended delete-indentation behavior
* doc/lispref/text.texi (User-Level Deletion): Document new optional
arguments of delete-indentation.
* lisp/simple.el (delete-indentation): Do not barf if called
interactively when region is inactive. (bug#35021)
Do not skip blank lines. (bug#35036)
Consistently deactivate mark even when no text was changed.
Handle active region spanning a single line.
* test/lisp/simple-tests.el (simple-test--buffer-substrings):
New convenience function.
(simple-test--dummy-buffer, simple-test--transpositions): Use it.
(simple-delete-indentation-no-region)
(simple-delete-indentation-inactive-region): Update commentary.
Call delete-indentation interactively when testing for behavior with
inactive region and region is not explicitly defined.
(simple-delete-indentation-blank-line)
(simple-delete-indentation-boundaries)
(simple-delete-indentation-region)
(simple-delete-indentation-prefix): New tests.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/simple.el | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index f76f31ad146..306df967661 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -598,30 +598,38 @@ When called from Lisp code, ARG may be a prefix string to copy." | |||
| 598 | If there is a fill prefix, delete it from the beginning of this | 598 | If there is a fill prefix, delete it from the beginning of this |
| 599 | line. | 599 | line. |
| 600 | With prefix ARG, join the current line to the following line. | 600 | With prefix ARG, join the current line to the following line. |
| 601 | If the region is active, join all the lines in the region. (The | 601 | When BEG and END are non-nil, join all lines in the region they |
| 602 | region is ignored if prefix argument is given.)" | 602 | define. Interactively, BEG and END are, respectively, the start |
| 603 | (interactive "*P\nr") | 603 | and end of the region if it is active, else nil. (The region is |
| 604 | (if arg (forward-line 1) | 604 | ignored if prefix ARG is given.)" |
| 605 | (if (use-region-p) | 605 | (interactive |
| 606 | (goto-char end))) | 606 | (progn (barf-if-buffer-read-only) |
| 607 | (beginning-of-line) | 607 | (cons current-prefix-arg |
| 608 | (while (eq (preceding-char) ?\n) | 608 | (and (use-region-p) |
| 609 | (progn | 609 | (list (region-beginning) (region-end)))))) |
| 610 | (delete-region (point) (1- (point))) | 610 | ;; Consistently deactivate mark even when no text is changed. |
| 611 | ;; If the second line started with the fill prefix, | 611 | (setq deactivate-mark t) |
| 612 | (if (and beg (not arg)) | ||
| 613 | ;; Region is active. Go to END, but only if region spans | ||
| 614 | ;; multiple lines. | ||
| 615 | (and (goto-char beg) | ||
| 616 | (> end (line-end-position)) | ||
| 617 | (goto-char end)) | ||
| 618 | ;; Region is inactive. Set a loop sentinel | ||
| 619 | ;; (subtracting 1 in order to compare less than BOB). | ||
| 620 | (setq beg (1- (line-beginning-position (and arg 2)))) | ||
| 621 | (when arg (forward-line))) | ||
| 622 | (let ((prefix (and (> (length fill-prefix) 0) | ||
| 623 | (regexp-quote fill-prefix)))) | ||
| 624 | (while (and (> (line-beginning-position) beg) | ||
| 625 | (forward-line 0) | ||
| 626 | (= (preceding-char) ?\n)) | ||
| 627 | (delete-char -1) | ||
| 628 | ;; If the appended line started with the fill prefix, | ||
| 612 | ;; delete the prefix. | 629 | ;; delete the prefix. |
| 613 | (if (and fill-prefix | 630 | (if (and prefix (looking-at prefix)) |
| 614 | (<= (+ (point) (length fill-prefix)) (point-max)) | 631 | (replace-match "" t t)) |
| 615 | (string= fill-prefix | 632 | (fixup-whitespace)))) |
| 616 | (buffer-substring (point) | ||
| 617 | (+ (point) (length fill-prefix))))) | ||
| 618 | (delete-region (point) (+ (point) (length fill-prefix)))) | ||
| 619 | (fixup-whitespace) | ||
| 620 | (if (and (use-region-p) | ||
| 621 | beg | ||
| 622 | (not arg) | ||
| 623 | (< beg (point-at-bol))) | ||
| 624 | (beginning-of-line))))) | ||
| 625 | 633 | ||
| 626 | (defalias 'join-line #'delete-indentation) ; easier to find | 634 | (defalias 'join-line #'delete-indentation) ; easier to find |
| 627 | 635 | ||