aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-01-07 13:08:45 +0100
committerLars Ingebrigtsen2021-01-07 13:08:52 +0100
commit2f6e30cd86a575ef06e8d056fbb6582336f6aadd (patch)
treede9b39322e130df388badd094d106603f470a1d1
parent9db1c0993a99853968c021d094eba37c0cae60bb (diff)
downloademacs-2f6e30cd86a575ef06e8d056fbb6582336f6aadd.tar.gz
emacs-2f6e30cd86a575ef06e8d056fbb6582336f6aadd.zip
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.
-rw-r--r--lisp/textmodes/paragraphs.el63
-rw-r--r--test/lisp/textmodes/paragraphs-resources/mark-paragraph.bin9
-rw-r--r--test/lisp/textmodes/paragraphs-tests.el23
3 files changed, 55 insertions, 40 deletions
diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index 217ae10fe4d..96edfd6de36 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -371,50 +371,33 @@ See `forward-paragraph' for more information."
371 371
372(defun mark-paragraph (&optional arg allow-extend) 372(defun mark-paragraph (&optional arg allow-extend)
373 "Put point at beginning of this paragraph, mark at end. 373 "Put point at beginning of this paragraph, mark at end.
374The paragraph marked is the one that contains point or follows 374The paragraph marked is the one that contains point or follows point.
375point.
376 375
377With argument ARG, puts mark at the end of this or a following 376With argument ARG, puts mark at end of a following paragraph, so that
378paragraph, so that the number of paragraphs marked equals ARG. 377the number of paragraphs marked equals ARG.
379 378
380If ARG is negative, point is put at the end of this paragraph, 379If ARG is negative, point is put at end of this paragraph, mark is put
381mark is put at the beginning of this or a previous paragraph. 380at beginning of this or a previous paragraph.
382 381
383Interactively (or if ALLOW-EXTEND is non-nil), if this command is 382Interactively (or if ALLOW-EXTEND is non-nil), if this command is
384repeated or (in Transient Mark mode) if the mark is active, it 383repeated or (in Transient Mark mode) if the mark is active,
385marks the next ARG paragraphs after the region already marked. 384it marks the next ARG paragraphs after the ones already marked."
386This also means when activating the mark immediately before using 385 (interactive "p\np")
387this command, the current paragraph is only marked from point." 386 (unless arg (setq arg 1))
388 (interactive "P\np") 387 (when (zerop arg)
389 (let ((numeric-arg (prefix-numeric-value arg))) 388 (error "Cannot mark zero paragraphs"))
390 (cond ((zerop numeric-arg)) 389 (cond ((and allow-extend
391 ((and allow-extend 390 (or (and (eq last-command this-command) (mark t))
392 (or (and (eq last-command this-command) mark-active) 391 (and transient-mark-mode mark-active)))
393 (region-active-p))) 392 (set-mark
394 (if arg 393 (save-excursion
395 (setq arg numeric-arg) 394 (goto-char (mark))
396 (if (< (mark) (point)) 395 (forward-paragraph arg)
397 (setq arg -1) 396 (point))))
398 (setq arg 1))) 397 (t
399 (set-mark 398 (forward-paragraph arg)
400 (save-excursion 399 (push-mark nil t t)
401 (goto-char (mark)) 400 (backward-paragraph arg))))
402 (forward-paragraph arg)
403 (point))))
404 ;; don't activate the mark when at eob
405 ((and (eobp) (> numeric-arg 0)))
406 (t
407 (unless (save-excursion
408 (forward-line 0)
409 (looking-at paragraph-start))
410 (backward-paragraph (cond ((> numeric-arg 0) 1)
411 ((< numeric-arg 0) -1)
412 (t 0))))
413 (push-mark
414 (save-excursion
415 (forward-paragraph numeric-arg)
416 (point))
417 t t)))))
418 401
419(defun kill-paragraph (arg) 402(defun kill-paragraph (arg)
420 "Kill forward to end of paragraph. 403 "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 00000000000..1905477af8c
--- /dev/null
+++ b/test/lisp/textmodes/paragraphs-resources/mark-paragraph.bin
@@ -0,0 +1,9 @@
1First
2paragraph
3
4Second
5
6Third
7paragraph
8
9No 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 bf7f37090f5..712169029de 100644
--- a/test/lisp/textmodes/paragraphs-tests.el
+++ b/test/lisp/textmodes/paragraphs-tests.el
@@ -24,6 +24,7 @@
24;;; Code: 24;;; Code:
25 25
26(require 'ert) 26(require 'ert)
27(require 'ert-x)
27;; (require 'paragraphs) ; loaded by default 28;; (require 'paragraphs) ; loaded by default
28 29
29(ert-deftest paragraphs-tests-sentence-end () 30(ert-deftest paragraphs-tests-sentence-end ()
@@ -161,5 +162,27 @@
161 (should (equal (buffer-string) 162 (should (equal (buffer-string)
162 "First sentence. Third sentence. Second sentence.")))) 163 "First sentence. Third sentence. Second sentence."))))
163 164
165(ert-deftest test-mark-paragraphs ()
166 (with-current-buffer
167 (find-file-noselect (ert-resource-file "mark-paragraph.bin"))
168 (goto-char (point-max))
169 ;; Just a sanity check that the file hasn't changed.
170 (should (= (point) 54))
171 (mark-paragraph)
172 (should (= (point) 42))
173 (should (= (mark) 54))
174 ;; Doesn't move.
175 (mark-paragraph)
176 (should (= (point) 42))
177 (should (= (mark) 54))
178 (forward-line -1)
179 (mark-paragraph)
180 (should (= (point) 25))
181 (should (= (mark) 42))
182 (goto-char (point-min))
183 (mark-paragraph)
184 (should (= (point) 1))
185 (should (= (mark) 17))))
186
164(provide 'paragraphs-tests) 187(provide 'paragraphs-tests)
165;;; paragraphs-tests.el ends here 188;;; paragraphs-tests.el ends here