[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 2f6e30c: Revert mark-paragraph change and add tests
From: |
Lars Ingebrigtsen |
Subject: |
master 2f6e30c: Revert mark-paragraph change and add tests |
Date: |
Thu, 7 Jan 2021 07:09:00 -0500 (EST) |
branch: master
commit 2f6e30cd86a575ef06e8d056fbb6582336f6aadd
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Revert mark-paragraph change and add tests
* lisp/textmodes/paragraphs.el (mark-paragraph): Revert
eb090f65ceb0ae8a90829e911694348583135ba5 (bug#45318). This restores
the behaviour from Emacs 27 -- further work is needed on this patch.
---
lisp/textmodes/paragraphs.el | 63 ++++++++--------------
.../paragraphs-resources/mark-paragraph.bin | 9 ++++
test/lisp/textmodes/paragraphs-tests.el | 23 ++++++++
3 files changed, 55 insertions(+), 40 deletions(-)
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index 217ae10..96edfd6 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -371,50 +371,33 @@ See `forward-paragraph' for more information."
(defun mark-paragraph (&optional arg allow-extend)
"Put point at beginning of this paragraph, mark at end.
-The paragraph marked is the one that contains point or follows
-point.
+The paragraph marked is the one that contains point or follows point.
-With argument ARG, puts mark at the end of this or a following
-paragraph, so that the number of paragraphs marked equals ARG.
+With argument ARG, puts mark at end of a following paragraph, so that
+the number of paragraphs marked equals ARG.
-If ARG is negative, point is put at the end of this paragraph,
-mark is put at the beginning of this or a previous paragraph.
+If ARG is negative, point is put at end of this paragraph, mark is put
+at beginning of this or a previous paragraph.
Interactively (or if ALLOW-EXTEND is non-nil), if this command is
-repeated or (in Transient Mark mode) if the mark is active, it
-marks the next ARG paragraphs after the region already marked.
-This also means when activating the mark immediately before using
-this command, the current paragraph is only marked from point."
- (interactive "P\np")
- (let ((numeric-arg (prefix-numeric-value arg)))
- (cond ((zerop numeric-arg))
- ((and allow-extend
- (or (and (eq last-command this-command) mark-active)
- (region-active-p)))
- (if arg
- (setq arg numeric-arg)
- (if (< (mark) (point))
- (setq arg -1)
- (setq arg 1)))
- (set-mark
- (save-excursion
- (goto-char (mark))
- (forward-paragraph arg)
- (point))))
- ;; don't activate the mark when at eob
- ((and (eobp) (> numeric-arg 0)))
- (t
- (unless (save-excursion
- (forward-line 0)
- (looking-at paragraph-start))
- (backward-paragraph (cond ((> numeric-arg 0) 1)
- ((< numeric-arg 0) -1)
- (t 0))))
- (push-mark
- (save-excursion
- (forward-paragraph numeric-arg)
- (point))
- t t)))))
+repeated or (in Transient Mark mode) if the mark is active,
+it marks the next ARG paragraphs after the ones already marked."
+ (interactive "p\np")
+ (unless arg (setq arg 1))
+ (when (zerop arg)
+ (error "Cannot mark zero paragraphs"))
+ (cond ((and allow-extend
+ (or (and (eq last-command this-command) (mark t))
+ (and transient-mark-mode mark-active)))
+ (set-mark
+ (save-excursion
+ (goto-char (mark))
+ (forward-paragraph arg)
+ (point))))
+ (t
+ (forward-paragraph arg)
+ (push-mark nil t t)
+ (backward-paragraph arg))))
(defun kill-paragraph (arg)
"Kill forward to end of paragraph.
diff --git a/test/lisp/textmodes/paragraphs-resources/mark-paragraph.bin
b/test/lisp/textmodes/paragraphs-resources/mark-paragraph.bin
new file mode 100644
index 0000000..1905477
--- /dev/null
+++ b/test/lisp/textmodes/paragraphs-resources/mark-paragraph.bin
@@ -0,0 +1,9 @@
+First
+paragraph
+
+Second
+
+Third
+paragraph
+
+No line end
\ No newline at end of file
diff --git a/test/lisp/textmodes/paragraphs-tests.el
b/test/lisp/textmodes/paragraphs-tests.el
index bf7f370..7121690 100644
--- a/test/lisp/textmodes/paragraphs-tests.el
+++ b/test/lisp/textmodes/paragraphs-tests.el
@@ -24,6 +24,7 @@
;;; Code:
(require 'ert)
+(require 'ert-x)
;; (require 'paragraphs) ; loaded by default
(ert-deftest paragraphs-tests-sentence-end ()
@@ -161,5 +162,27 @@
(should (equal (buffer-string)
"First sentence. Third sentence. Second sentence."))))
+(ert-deftest test-mark-paragraphs ()
+ (with-current-buffer
+ (find-file-noselect (ert-resource-file "mark-paragraph.bin"))
+ (goto-char (point-max))
+ ;; Just a sanity check that the file hasn't changed.
+ (should (= (point) 54))
+ (mark-paragraph)
+ (should (= (point) 42))
+ (should (= (mark) 54))
+ ;; Doesn't move.
+ (mark-paragraph)
+ (should (= (point) 42))
+ (should (= (mark) 54))
+ (forward-line -1)
+ (mark-paragraph)
+ (should (= (point) 25))
+ (should (= (mark) 42))
+ (goto-char (point-min))
+ (mark-paragraph)
+ (should (= (point) 1))
+ (should (= (mark) 17))))
+
(provide 'paragraphs-tests)
;;; paragraphs-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 2f6e30c: Revert mark-paragraph change and add tests,
Lars Ingebrigtsen <=