GNU bug report logs - #27507
[PATCH] Make `cycle-spacing' allow 'negative-zero in place of an integer

Previous Next

Package: emacs;

Reported by: Mekeor Melire <mekeor.melire <at> gmail.com>

Date: Tue, 27 Jun 2017 16:55:03 UTC

Severity: wishlist

Tags: moreinfo, patch

Done: Mekeor Melire <mekeor.melire <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 27507 in the body.
You can then email your comments to 27507 AT debbugs.gnu.org in the normal way.

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#27507; Package emacs. (Tue, 27 Jun 2017 16:55:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mekeor Melire <mekeor.melire <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 27 Jun 2017 16:55:03 GMT) Full text and rfc822 format available.

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

From: Mekeor Melire <mekeor.melire <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Make `cycle-spacing' allow 'negative-zero in place of an
 integer
Date: Tue, 27 Jun 2017 18:18:06 +0200
* lisp/simple.el (cycle-spacing): beside accepting an integer as first
argument N, also allow N to be 'negative-zero. This allows to delete
all spaces including newlines with (cycle-spacing 'negative-zero).
---
 lisp/simple.el | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index a5565ab..00df813 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -867,18 +867,20 @@ The first time `cycle-spacing' runs, it saves in this variable:
 its N argument, the original point position, and the original spacing
 around point.")
 
-(defun cycle-spacing (&optional n preserve-nl-back mode)
+(defun cycle-spacing (&optional n-or-negative-zero preserve-nl-back mode)
   "Manipulate whitespace around point in a smart way.
 In interactive use, this function behaves differently in successive
 consecutive calls.
 
 The first call in a sequence acts like `just-one-space'.
 It deletes all spaces and tabs around point, leaving one space
-\(or N spaces).  N is the prefix argument.  If N is negative,
-it deletes newlines as well, leaving -N spaces.
-\(If PRESERVE-NL-BACK is non-nil, it does not delete newlines before point.)
+\(or N spaces).  N is the prefix argument.  If N is a negative integer,
+it deletes newlines as well, leaving -N spaces. If N is 'negative-zero, it
+deletes all spaces and newlines. \(If PRESERVE-NL-BACK is non-nil, it does
+not delete newlines before point.)
 
-The second call in a sequence deletes all spaces.
+The second call in a sequence deletes all spaces. It is skipped if N is 0
+or the symbol 'negative-zero.
 
 The third call in a sequence restores the original whitespace (and point).
 
@@ -890,9 +892,14 @@ the function goes straight to the second step.
 Repeatedly calling the function with different values of N starts a
 new sequence each time."
   (interactive "*p")
-  (let ((orig-pos	 (point))
-	(skip-characters (if (and n (< n 0)) " \t\n\r" " \t"))
-	(num		 (abs (or n 1))))
+  (letrec
+    ((orig-pos	 (point))
+     (n-is-negative-zero (eq n-or-negative-zero 'negative-zero))
+     (n (if (or (null n-or-negative-zero) n-is-negative-zero)
+            0 n-or-negative-zero))
+     (skip-characters (if (or n-is-negative-zero (< n 0)) " \t\n\r" " \t"))
+     (num	      (abs (or n 1))))
+
     (skip-chars-backward (if preserve-nl-back " \t" skip-characters))
     (constrain-to-field nil orig-pos)
     (cond
-- 
2.8.4 (Apple Git-73)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27507; Package emacs. (Fri, 30 Jun 2017 01:28:02 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Mekeor Melire <mekeor.melire <at> gmail.com>
Cc: 27507 <at> debbugs.gnu.org
Subject: Re: bug#27507: [PATCH] Make `cycle-spacing' allow 'negative-zero in
 place of an integer
Date: Thu, 29 Jun 2017 21:29:02 -0400
Mekeor Melire <mekeor.melire <at> gmail.com> writes:

> * lisp/simple.el (cycle-spacing): beside accepting an integer as first
> argument N, also allow N to be 'negative-zero. This allows to delete
> all spaces including newlines with (cycle-spacing 'negative-zero).

This behaviour can't be used interactively right?  If you want a
function to delete all space including newlines, I think it's better to
add one instead of adding yet another mode to cycle-spacing which won't
even be used by interactive callers.

That is, instead of (cycle-spacing 'negative-zero) something like
(delete-whitespace).

> +  (letrec

You only need let* here, I think.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27507; Package emacs. (Sat, 01 Jul 2017 16:18:02 GMT) Full text and rfc822 format available.

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

From: Mekeor Melire <mekeor.melire <at> gmail.com>
To: npostavs <at> users.sourceforge.net
Cc: Mekeor Melire <mekeor.melire <at> gmail.com>, 27507 <at> debbugs.gnu.org
Subject: Re: bug#27507: [PATCH] Make `cycle-spacing' allow 'negative-zero in
 place of an integer
Date: Sat, 01 Jul 2017 18:17:06 +0200
npostavs <at> users.sourceforge.net writes:

> Mekeor Melire <mekeor.melire <at> gmail.com> writes:

>> * lisp/simple.el (cycle-spacing): beside accepting an integer as first
>> argument N, also allow N to be 'negative-zero. This allows to delete
>> all spaces including newlines with (cycle-spacing 'negative-zero).

> This behaviour can't be used interactively right?  If you want a
> function to delete all space including newlines, I think it's better to
> add one instead of adding yet another mode to cycle-spacing which won't
> even be used by interactive callers.

> That is, instead of (cycle-spacing 'negative-zero) something like
> (delete-whitespace).

Well, the point is that delete-whitespace would mostly have the same
logic as cycle-spacing. So, should we define a more general function
then, which both delete-whitespace and cycle-spacing would be based
upon?

So, currently `cycle-spacing' is used like this:

    (cycle-spacing &optional N PRESERVE-NL-BACK MODE)

And the problem is that the sign(ature) of N is used to determine
whether to delete newlines as well. So, if N is zero, we have a problem.
So, I think we shouldn't use the signature of N but instead that should
be another argument. But maybe let's use that new argument for a new
function so that cycle-spacing stays backwardscompatible?

So, I propose something like this:

    (defun (cycle-spacing &optional n preserve-nl-back mode)
      (cycle-spacing-general n preserve-nl-back (< n 0) mode))

    (defun (cycle-spacing-general &optional n preserve-nl-back delete-newlines mode)
      ;; use (abs n) in place of n here
      ;; ...
      )

    ;; this is optional:
    (defun (delete-whitespace &optional n preserve-n-back mode)
      (cycle-spacing-general n preserve-nl-back t mode))


>> +  (letrec
>
> You only need let* here, I think.

Uhm, I'm not sure. I'll check it out.


Thanks for your feedback!




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27507; Package emacs. (Sat, 01 Jul 2017 18:15:01 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Mekeor Melire <mekeor.melire <at> gmail.com>
Cc: 27507 <at> debbugs.gnu.org
Subject: Re: bug#27507: [PATCH] Make `cycle-spacing' allow 'negative-zero in
 place of an integer
Date: Sat, 01 Jul 2017 14:15:42 -0400
Mekeor Melire <mekeor.melire <at> gmail.com> writes:

> Well, the point is that delete-whitespace would mostly have the same
> logic as cycle-spacing. So, should we define a more general function
> then, which both delete-whitespace and cycle-spacing would be based
> upon?  So, currently `cycle-spacing' is used like this:
>
>     (cycle-spacing &optional N PRESERVE-NL-BACK MODE)
>
> And the problem is that the sign(ature) of N is used to determine
> whether to delete newlines as well. So, if N is zero, we have a
> problem.

I'm still a bit confused why you specfically want to use cycle-spacing
to delete newlines and spaces.  What logic of cycle-spacing would be
applicable when N is zero?  Can you give an example usage?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27507; Package emacs. (Tue, 17 Oct 2017 00:26:01 GMT) Full text and rfc822 format available.

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

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Mekeor Melire <mekeor.melire <at> gmail.com>
Cc: 27507 <at> debbugs.gnu.org
Subject: Re: bug#27507: [PATCH] Make `cycle-spacing' allow 'negative-zero in
 place of an integer
Date: Mon, 16 Oct 2017 20:25:26 -0400
tags 27507 + moreinfo
quit

npostavs <at> users.sourceforge.net writes:

> Mekeor Melire <mekeor.melire <at> gmail.com> writes:
>
>> Well, the point is that delete-whitespace would mostly have the same
>> logic as cycle-spacing. So, should we define a more general function
>> then, which both delete-whitespace and cycle-spacing would be based
>> upon?  So, currently `cycle-spacing' is used like this:
>>
>>     (cycle-spacing &optional N PRESERVE-NL-BACK MODE)
>>
>> And the problem is that the sign(ature) of N is used to determine
>> whether to delete newlines as well. So, if N is zero, we have a
>> problem.
>
> I'm still a bit confused why you specfically want to use cycle-spacing
> to delete newlines and spaces.  What logic of cycle-spacing would be
> applicable when N is zero?  Can you give an example usage?

Ping?




Added tag(s) moreinfo. Request was from Noam Postavsky <npostavs <at> users.sourceforge.net> to control <at> debbugs.gnu.org. (Tue, 17 Oct 2017 00:26:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 27507 <at> debbugs.gnu.org and Mekeor Melire <mekeor.melire <at> gmail.com> Request was from Mekeor Melire <mekeor.melire <at> gmail.com> to control <at> debbugs.gnu.org. (Thu, 09 Nov 2017 22:36: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. (Fri, 08 Dec 2017 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 199 days ago.

Previous Next


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