GNU bug report logs - #18847
24.4; Inconsistent behaviour of M-h with negative arguments

Previous Next

Package: emacs;

Reported by: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)

Date: Sun, 26 Oct 2014 23:29:01 UTC

Severity: wishlist

Merged with 45318

Found in versions 24.4, 28.0.50

To reply to this bug, email your comments to 18847 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#18847; Package emacs. (Sun, 26 Oct 2014 23:29:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm):
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 26 Oct 2014 23:29:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4; Inconsistent behaviour of M-h with negative arguments
Date: Mon, 27 Oct 2014 00:27:20 +0100
Hello,

please try M-- M-h M-h M-h.

below some paragraphs.  The behaviour is not in line with the other
marking commands like M-@, ...

Here's a suggestion and a matching patch:

(defun mark-paragraph (&optional arg allow-extend)
  "Put mark at beginning of this paragraph,  point at end.
The paragraph marked is the one that contains point or follows
point. 

With argument ARG, puts mark at the end of a following paragraph,
so that the number of paragraphs marked equals ARG.

If ARG is negative, point is put at the beginning of this
paragraph, mark is put at the end of this or a previous
paragraph.

Interactively, if this command is repeated or (in Transient Mark
Mode) if the mark is active, it marks the next ARG paragraphs
after the ones already marked.  This means when activating the
mark before using this command, the current paragraph is only
marked from point."
  (interactive "P\np")
  (let ((numeric-arg (prefix-numeric-value arg)))
    (cond ((eobp)			; smart-aleck?
	   (backward-paragraph (abs numeric-arg))
	   (push-mark nil t t)
	   (forward-paragraph (abs numeric-arg)))
	  ((and allow-extend ;we already called this function or have
			     ;a (possibly empty) region
		(or (eq last-command this-command)
		    (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))))
	  ((zerop numeric-arg)		
	   (message "Will not mark zero paragraphs."))
	  (t
	   (forward-paragraph numeric-arg)
	   (push-mark nil t t)
	   (backward-paragraph numeric-arg)))))


Thank you for your troubles!

diff -c /usr/local/src/emacs-24.4/lisp/textmodes/paragraphs.el /usr/local/src/emacs/lisp/textmodes/paragraphs.el
*** /usr/local/src/emacs-24.4/lisp/textmodes/paragraphs.el	2014-03-21 06:34:40.000000000 +0100
--- /usr/local/src/emacs/lisp/textmodes/paragraphs.el	2014-10-27 00:22:41.874845901 +0100
***************
*** 370,403 ****
    (forward-paragraph (- arg)))
  
  (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.
  
! 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 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 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.
--- 370,417 ----
    (forward-paragraph (- arg)))
  
  (defun mark-paragraph (&optional arg allow-extend)
!   "Put mark at beginning of this paragraph,  point at end.
! The paragraph marked is the one that contains point or follows
! point.
  
! With argument ARG, puts mark at the end of a following paragraph,
! so that the number of paragraphs marked equals ARG.
  
! If ARG is negative, point is put at the beginning of this
! paragraph, mark is put at the end of this or a previous
! paragraph.
  
! Interactively, if this command is repeated or (in Transient Mark
! Mode) if the mark is active, it marks the next ARG paragraphs
! after the ones already marked.  This means when activating the
! mark before using this command, the current paragraph is only
! marked from point."
!   (interactive "P\np")
!   (let ((numeric-arg (prefix-numeric-value arg)))
!     (cond ((eobp)			; smart-aleck?
! 	   (backward-paragraph (abs numeric-arg))
! 	   (push-mark nil t t)
! 	   (forward-paragraph (abs numeric-arg)))
! 	  ((and allow-extend ;we already called this function or have
! 			     ;a (possibly empty) region
! 		(or (eq last-command this-command)
! 		    (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))))
! 	  ((zerop numeric-arg)
! 	   (message "Will not mark zero paragraphs."))
! 	  (t
! 	   (forward-paragraph numeric-arg)
! 	   (push-mark nil t t)
! 	   (backward-paragraph numeric-arg)))))
  
  (defun kill-paragraph (arg)
    "Kill forward to end of paragraph.

Diff finished.  Mon Oct 27 00:22:49 2014


-- 
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18847; Package emacs. (Mon, 27 Oct 2014 09:21:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#18847: 24.4;
 Inconsistent behaviour of M-h with negative arguments
Date: Mon, 27 Oct 2014 08:37:44 +0100
dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm) writes:

> Hello,
>
> please try M-- M-h M-h M-h.
>
> below some paragraphs.  The behaviour is not in line with the other
> marking commands like M-@, ...
>
> Here's a suggestion and a matching patch:

I'm sorry, I overlooked a special case:

(defun mark-paragraph (&optional arg allow-extend)
  "Put mark at beginning of this paragraph,  point at end.
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.
 
If ARG is negative, point is put at the beginning of this
paragraph, mark is put at the end of this or a previous
paragraph.

Interactively, 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 ((eobp)			; smart-aleck?
	   (backward-paragraph (abs numeric-arg))
	   (push-mark nil t t)
	   (forward-paragraph (abs numeric-arg)))
	  ((and allow-extend
		(or (region-active-p)
		    (and (eq last-command this-command) mark-active)))
	   (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))))
	  ((zerop numeric-arg)
	   (message "Will not mark zero paragraphs."))
	  (t
	   (forward-paragraph numeric-arg)
	   (push-mark nil t t)
	   (backward-paragraph numeric-arg)))))


diff -c /usr/local/src/emacs-24.4/lisp/textmodes/paragraphs.el /usr/local/src/emacs/lisp/textmodes/paragraphs.el
*** /usr/local/src/emacs-24.4/lisp/textmodes/paragraphs.el	2014-03-21 06:34:40.000000000 +0100
--- /usr/local/src/emacs/lisp/textmodes/paragraphs.el	2014-10-27 08:31:27.457755345 +0100
***************
*** 370,403 ****
    (forward-paragraph (- arg)))
  
  (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.
  
! 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 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 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.
--- 370,416 ----
    (forward-paragraph (- arg)))
  
  (defun mark-paragraph (&optional arg allow-extend)
!   "Put mark at beginning of this paragraph,  point at end.
! 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.
  
! If ARG is negative, point is put at the beginning of this
! paragraph, mark is put at the end of this or a previous
! paragraph.
  
! Interactively, 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 ((eobp)			; smart-aleck?
! 	   (backward-paragraph (abs numeric-arg))
! 	   (push-mark nil t t)
! 	   (forward-paragraph (abs numeric-arg)))
! 	  ((and allow-extend
! 		(or (region-active-p)
! 		    (and (eq last-command this-command) mark-active)))
! 	   (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))))
! 	  ((zerop numeric-arg)
! 	   (message "Will not mark zero paragraphs."))
! 	  (t
! 	   (forward-paragraph numeric-arg)
! 	   (push-mark nil t t)
! 	   (backward-paragraph numeric-arg)))))
  
  (defun kill-paragraph (arg)
    "Kill forward to end of paragraph.

Diff finished.  Mon Oct 27 08:31:56 2014



> (defun mark-paragraph (&optional arg allow-extend)
>   "Put mark at beginning of this paragraph,  point at end.
> The paragraph marked is the one that contains point or follows
> point. 
>
> With argument ARG, puts mark at the end of a following paragraph,
> so that the number of paragraphs marked equals ARG.
>
> If ARG is negative, point is put at the beginning of this
> paragraph, mark is put at the end of this or a previous
> paragraph.
>
> Interactively, if this command is repeated or (in Transient Mark
> Mode) if the mark is active, it marks the next ARG paragraphs
> after the ones already marked.  This means when activating the
> mark before using this command, the current paragraph is only
> marked from point."
>   (interactive "P\np")
>   (let ((numeric-arg (prefix-numeric-value arg)))
>     (cond ((eobp)			; smart-aleck?
> 	   (backward-paragraph (abs numeric-arg))
> 	   (push-mark nil t t)
> 	   (forward-paragraph (abs numeric-arg)))
> 	  ((and allow-extend ;we already called this function or have
> 			     ;a (possibly empty) region
> 		(or (eq last-command this-command)
> 		    (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))))
> 	  ((zerop numeric-arg)		
> 	   (message "Will not mark zero paragraphs."))
> 	  (t
> 	   (forward-paragraph numeric-arg)
> 	   (push-mark nil t t)
> 	   (backward-paragraph numeric-arg)))))
>
>
> Thank you for your troubles!
>
> diff -c /usr/local/src/emacs-24.4/lisp/textmodes/paragraphs.el /usr/local/src/emacs/lisp/textmodes/paragraphs.el
> *** /usr/local/src/emacs-24.4/lisp/textmodes/paragraphs.el	2014-03-21 06:34:40.000000000 +0100
> --- /usr/local/src/emacs/lisp/textmodes/paragraphs.el	2014-10-27 00:22:41.874845901 +0100
> ***************
> *** 370,403 ****
>     (forward-paragraph (- arg)))
>   
>   (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.
>   
> ! 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 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 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.
> --- 370,417 ----
>     (forward-paragraph (- arg)))
>   
>   (defun mark-paragraph (&optional arg allow-extend)
> !   "Put mark at beginning of this paragraph,  point at end.
> ! The paragraph marked is the one that contains point or follows
> ! point.
>   
> ! With argument ARG, puts mark at the end of a following paragraph,
> ! so that the number of paragraphs marked equals ARG.
>   
> ! If ARG is negative, point is put at the beginning of this
> ! paragraph, mark is put at the end of this or a previous
> ! paragraph.
>   
> ! Interactively, if this command is repeated or (in Transient Mark
> ! Mode) if the mark is active, it marks the next ARG paragraphs
> ! after the ones already marked.  This means when activating the
> ! mark before using this command, the current paragraph is only
> ! marked from point."
> !   (interactive "P\np")
> !   (let ((numeric-arg (prefix-numeric-value arg)))
> !     (cond ((eobp)			; smart-aleck?
> ! 	   (backward-paragraph (abs numeric-arg))
> ! 	   (push-mark nil t t)
> ! 	   (forward-paragraph (abs numeric-arg)))
> ! 	  ((and allow-extend ;we already called this function or have
> ! 			     ;a (possibly empty) region
> ! 		(or (eq last-command this-command)
> ! 		    (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))))
> ! 	  ((zerop numeric-arg)
> ! 	   (message "Will not mark zero paragraphs."))
> ! 	  (t
> ! 	   (forward-paragraph numeric-arg)
> ! 	   (push-mark nil t t)
> ! 	   (backward-paragraph numeric-arg)))))
>   
>   (defun kill-paragraph (arg)
>     "Kill forward to end of paragraph.
>
> Diff finished.  Mon Oct 27 00:22:49 2014

-- 
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18847; Package emacs. (Tue, 28 Oct 2014 17:06:02 GMT) Full text and rfc822 format available.

Message #11 received at 18847 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)
Cc: 18847 <at> debbugs.gnu.org
Subject: Re: bug#18847: 24.4;
 Inconsistent behaviour of M-h with negative arguments
Date: Tue, 28 Oct 2014 13:04:44 -0400
> please try M-- M-h M-h M-h.
> below some paragraphs.  The behaviour is not in line with the other
> marking commands like M-@, ...

Could you give more details about which differences you're thinking of?
I have my ideas, but they don't seem to match yours, at least based on
my reading of your patch.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18847; Package emacs. (Thu, 30 Oct 2014 16:36:02 GMT) Full text and rfc822 format available.

Message #14 received at 18847 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)
Cc: 18847 <at> debbugs.gnu.org
Subject: Re: bug#18847: 24.4;
 Inconsistent behaviour of M-h with negative arguments
Date: Thu, 30 Oct 2014 12:35:00 -0400
[ Be careful to keep 18847 <at> debbugs.gnu.org in the Cc, please.  ]

> 1) The sole real bug - in my opinion - is that M-h doesn't retain the
>    "marking direction" from a negative argument when repeating.

OK, I agree with this, it's a plain bug.

> 2) When applying M-h (or any other marking command) at the end of a
>    buffer (at least interactively, I failed to address this), the right
>    thing to do is marking (a) previous element(s).  I would like to know
>    if you find this a good idea.

I have no opinion on this, I never use M-h myself.

> 3) M-h (C-M-h and C-x C-p ) differ from C-@ and C-M-@ that they are
>    always marking (a) whole element(s).  I wanted to clarify in the
>    documentation string that a marking from point is also achievable
>    with M-h.

So this part is just a docstring change, right?

> 4) M-h does signal an error applying zero as an argument, the other
>    marking commands just ignore zero, so I thought a message might be a
>    good compromise to the current state...

I have no opinion on this one either.  It doesn't seem terribly
important, so reducing discrepancies in this case might be the
dominating factor.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18847; Package emacs. (Mon, 03 Nov 2014 17:57:01 GMT) Full text and rfc822 format available.

Message #17 received at 18847 <at> debbugs.gnu.org (full text, mbox):

From: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 18847 <at> debbugs.gnu.org
Subject: Re: bug#18847: 24.4;
 Inconsistent behaviour of M-h with negative arguments
Date: Mon, 03 Nov 2014 18:56:00 +0100
Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:

> [ Be careful to keep 18847 <at> debbugs.gnu.org in the Cc, please.  ]

Sorry, I overlooked the Cc field.

....

>> 2) When applying M-h (or any other marking command) at the end of a
>>    buffer (at least interactively, I failed to address this), the right
>>    thing to do is marking (a) previous element(s).  I would like to know
>>    if you find this a good idea.
>
> I have no opinion on this, I never use M-h myself.

Interesting, no M-h!  Anyway, in the meantime I tested M-h more
thoroughly in these borderline cases and I think its behaviour is
actually not correct.  I suggest to separate this issue and possible
enhancements from the current subject.

>> 3) M-h (C-M-h and C-x C-p ) differ from C-@ and C-M-@ that they are
>>    always marking (a) whole element(s).  I wanted to clarify in the
>>    documentation string that a marking from point is also achievable
>>    with M-h.
>
> So this part is just a docstring change, right?

Exactly.

>> 4) M-h does signal an error applying zero as an argument, the other
>>    marking commands just ignore zero, so I thought a message might be a
>>    good compromise to the current state...
>
> I have no opinion on this one either.  It doesn't seem terribly
> important, so reducing discrepancies in this case might be the
> dominating factor.

Right, I dropped the zero argument message. (But still inhibited M-h to
activate the mark in this situation.)

Thank you for your patience

       Dieter


(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.

With argument ARG, puts mark at the end of this or 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.

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))))
	  (t
	   (forward-paragraph numeric-arg)
	   (push-mark nil t t)
	   (backward-paragraph numeric-arg)))))

diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index 3e77d37..e1a735d 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -370,34 +370,47 @@ See `forward-paragraph' for more information."
   (forward-paragraph (- arg)))
 
 (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.
-
-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 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 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))))
+  "Put mark at beginning of this paragraph,  point at end.
+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.
+
+If ARG is negative, point is put at the beginning of this
+paragraph, mark is put at the end of this or a previous
+paragraph.
+
+Interactively, 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 ((eobp)			; smart-aleck?
+	   (backward-paragraph (abs numeric-arg))
+	   (push-mark nil t t)
+	   (forward-paragraph (abs numeric-arg)))
+	  ((and allow-extend
+		(or (region-active-p)
+		    (and (eq last-command this-command) mark-active)))
+	   (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))))
+	  ((zerop numeric-arg)
+	   (message "Will not mark zero paragraphs."))
+	  (t
+	   (forward-paragraph numeric-arg)
+	   (push-mark nil t t)
+	   (backward-paragraph numeric-arg)))))
 
 (defun kill-paragraph (arg)
   "Kill forward to end of paragraph.



-- 
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18847; Package emacs. (Sat, 15 Nov 2014 19:14:02 GMT) Full text and rfc822 format available.

Message #20 received at 18847 <at> debbugs.gnu.org (full text, mbox):

From: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: 18847 <at> debbugs.gnu.org
Subject: Re: bug#18847: 24.4;
 Inconsistent behaviour of M-h with negative arguments
Date: Sat, 15 Nov 2014 20:13:03 +0100
The following patches

1) solve bug#18847 (when applying M-h with negative arguments and
   repeating this command)

2) solve another - not reported - bug.  When, e.g. at the end of the
   buffer, the numbers of paragraphs left in the buffer is less than
   ARG, then paragraphs are also marked *before* the current paragraph
   (contradicting the function's documentation)

3) (hopefully) clarifying a bit the documentation of mark-paragraph

4) aligning the behaviour of a zero argument to other marking commands
   (doing nothing, no error signal)

It still remains one anomaly - in my opinon - but only for a fringe
case, at the moment C-h and forward/backward-paragraph consider empty
lines at the end or the beginning of the buffer as an additional
paragraph...

Anyway, could some good soul apply the patches to emacs-24?

Thank you

      Dieter

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a6ab3b8..463753c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
+2014-11-15  H. Dieter Wilhelm <dieter <at> duenenhof-wilhelm.de>
+	* textmodes/paragraph.el (mark-paragraph): Handling of
+	negative arguments (bug#18847)
+
 2014-11-14  Ivan Andrus  <darthandrus <at> gmail.com>
 
 	* progmodes/python.el (python-ffap-module-path): Use


diff --git a/lisp/textmodes/paragraphs.el b/lisp/textmodes/paragraphs.el
index 3e77d37..d17cf09 100644
--- a/lisp/textmodes/paragraphs.el
+++ b/lisp/textmodes/paragraphs.el
@@ -371,33 +371,47 @@ 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 end of a following paragraph, so that
-the number of paragraphs marked equals ARG.
+With argument ARG, puts mark at the end of this or a following
+paragraph, so that the number of paragraphs marked equals ARG.
 
-If ARG is negative, point is put at end of this paragraph, mark is put
-at beginning of this or a previous paragraph.
+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.
 
 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 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))))
+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 (signum numeric-arg)))
+	   (push-mark
+	    (save-excursion
+	      (forward-paragraph numeric-arg)
+	      (point)) t t)))))
 
 (defun kill-paragraph (arg)
   "Kill forward to end of paragraph.



-- 
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany




Added tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Wed, 12 Aug 2020 16:56:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#18847; Package emacs. (Thu, 13 Aug 2020 09:53:02 GMT) Full text and rfc822 format available.

Message #25 received at 18847 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm)
Cc: Stefan Monnier <monnier <at> IRO.UMontreal.CA>, 18847 <at> debbugs.gnu.org
Subject: Re: bug#18847: 24.4; Inconsistent behaviour of M-h with negative
 arguments
Date: Thu, 13 Aug 2020 11:51:58 +0200
dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm) writes:

> The following patches
>
> 1) solve bug#18847 (when applying M-h with negative arguments and
>    repeating this command)
>
> 2) solve another - not reported - bug.  When, e.g. at the end of the
>    buffer, the numbers of paragraphs left in the buffer is less than
>    ARG, then paragraphs are also marked *before* the current paragraph
>    (contradicting the function's documentation)
>
> 3) (hopefully) clarifying a bit the documentation of mark-paragraph
>
> 4) aligning the behaviour of a zero argument to other marking commands
>    (doing nothing, no error signal)

Thanks; I've now applied this patch to Emacs 28 (with some small
whitespace changes).

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 13 Aug 2020 09:53:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 18847 <at> debbugs.gnu.org and dieter <at> duenenhof-wilhelm.de (H. Dieter Wilhelm) Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Thu, 13 Aug 2020 09:53:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 10 Sep 2020 11:24:10 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Mon, 11 Oct 2021 12:16:04 GMT) Full text and rfc822 format available.

bug No longer marked as fixed in versions 28.1 and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 11 Oct 2021 12:16:04 GMT) Full text and rfc822 format available.

Removed tag(s) patch. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Mon, 11 Oct 2021 12:16:04 GMT) Full text and rfc822 format available.

Forcibly Merged 18847 45318. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Mon, 11 Oct 2021 12:16:04 GMT) Full text and rfc822 format available.

Removed tag(s) fixed. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Mon, 11 Oct 2021 12:54:03 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 343 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.