unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Mekeor Melire <mekeor.melire@gmail.com>
To: 27507@debbugs.gnu.org
Subject: bug#27507: [PATCH] Make `cycle-spacing' allow 'negative-zero in place of an integer
Date: Tue, 27 Jun 2017 18:18:06 +0200	[thread overview]
Message-ID: <87vanhpfpd.fsf@gmail.com> (raw)

* 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)





             reply	other threads:[~2017-06-27 16:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-27 16:18 Mekeor Melire [this message]
2017-06-30  1:29 ` bug#27507: [PATCH] Make `cycle-spacing' allow 'negative-zero in place of an integer npostavs
2017-07-01 16:17   ` Mekeor Melire
2017-07-01 18:15     ` npostavs
2017-10-17  0:25       ` Noam Postavsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vanhpfpd.fsf@gmail.com \
    --to=mekeor.melire@gmail.com \
    --cc=27507@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).