GNU bug report logs - #17110
[PATCH] Make `cycle-spacing' behave more like `just-one-space' if called once.

Previous Next

Package: emacs;

Reported by: Michal Nazarewicz <mina86 <at> mina86.com>

Date: Wed, 26 Mar 2014 23:35:02 UTC

Severity: wishlist

Tags: patch

Fixed in version 25.1

Done: Glenn Morris <rgm <at> gnu.org>

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 17110 in the body.
You can then email your comments to 17110 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#17110; Package emacs. (Wed, 26 Mar 2014 23:35:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Michal Nazarewicz <mina86 <at> mina86.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 26 Mar 2014 23:35:02 GMT) Full text and rfc822 format available.

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

From: Michal Nazarewicz <mina86 <at> mina86.com>
To: bug-gnu-emacs <at> gnu.org
Cc: Alan Mackenzie <acm <at> muc.de>, emacs-devel <at> gnu.org,
 Stefan Monnier <monnier <at> iro.umontreal.ca>, Richard Stallman <rms <at> gnu.org>,
 Glenn Morris <rgm <at> gnu.org>
Subject: [PATCH] Make `cycle-spacing' behave more like `just-one-space' if
 called once.
Date: Mon, 10 Feb 2014 13:19:19 +0100
* simple.el (cycle-spacing): Never delete spaces on first run by
default, but do so in a new 'fast mode and if there are already
N spaces (the previous behaviour).

Compare N with its value in previous invocation so that changing
prefix argument restarts `cycle-spacing' sequence.

The idea is that with this change, binding M-SPC to
`cycle-spacing' should not introduce any changes in behaviour of
the binding so long as users do not type M-SPC twice in a raw with
the same prefix argument or lack thereof.
---
 lisp/ChangeLog | 14 ++++++++++++++
 lisp/simple.el | 59 ++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 47 insertions(+), 26 deletions(-)

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b61da99..e53eacd 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,17 @@
+2014-03-26  Michal Nazarewicz  <mina86 <at> mina86.com>
+
+	* simple.el (cycle-spacing): Never delete spaces on first run by
+	default, but do so in a new 'fast mode and if there are already
+	N spaces (the previous behaviour).
+
+	Compare N with its value in previous invocation so that changing
+	prefix argument restarts `cycle-spacing' sequence.
+
+	The idea is that with this change, binding M-SPC to
+	`cycle-spacing' should not introduce any changes in behaviour of
+	the binding so long as users do not type M-SPC twice in a raw with
+	the same prefix argument or lack thereof.
+
 2014-03-26  Daniel Colascione  <dancol <at> dancol.org>
 
 	* simple.el (process-menu-mode-map): New variable.
diff --git a/lisp/simple.el b/lisp/simple.el
index 2ee6231..2bfab4a 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -801,44 +801,51 @@ If BACKWARD-ONLY is non-nil, only delete them before point."
 If N is negative, delete newlines as well, leaving -N spaces.
 See also `cycle-spacing'."
   (interactive "*p")
-  (cycle-spacing n nil t))
+  (cycle-spacing n nil 'single-shot))
 
 (defvar cycle-spacing--context nil
   "Store context used in consecutive calls to `cycle-spacing' command.
-The first time this function is run, it saves the original point
-position and original spacing around the point in this
-variable.")
+The first time this function is run, it saves N argument, the
+original point position and original spacing around the point in
+this variable.")
 
-(defun cycle-spacing (&optional n preserve-nl-back single-shot)
+(defun cycle-spacing (&optional n preserve-nl-back mode)
   "Manipulate whitespace around point in a smart way.
-In interactive use, this function behaves differently in successive
-consecutive calls.
+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.)
+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.)
 
-The second call in a sequence (or the first call if the above does
-not result in any changes) deletes all spaces.
+The second call in a sequence deletes all spaces.
 
-The third call in a sequence restores the original whitespace (and point).
+The third call in a sequence restores the original
+whitespace (and point).
 
-If SINGLE-SHOT is non-nil, it only performs the first step in the sequence."
+If MODE is 'single-shot only the first step is performed.  If
+MODE is 'fast and the first step did not result in any
+change (i.e. there was exactly (abs N) spaces around point)
+function goes to the second step immediately.
+
+Running the function with different N arguments initiates a new
+sequence each time."
   (interactive "*p")
   (let ((orig-pos	 (point))
 	(skip-characters (if (and n (< n 0)) " \t\n\r" " \t"))
-	(n		 (abs (or n 1))))
+	(num		 (abs (or n 1))))
     (skip-chars-backward (if preserve-nl-back " \t" skip-characters))
     (constrain-to-field nil orig-pos)
     (cond
-     ;; Command run for the first time or single-shot is non-nil.
-     ((or single-shot
+     ;; Command run for the first time, single-shot mode or different argument
+     ((or (eq 'single-shot mode)
 	  (not (equal last-command this-command))
-	  (not cycle-spacing--context))
+	  (not cycle-spacing--context)
+	  (not (eq (car cycle-spacing--context) n)))
       (let* ((start (point))
-	     (n	    (- n (skip-chars-forward " " (+ n (point)))))
+	     (num   (- num (skip-chars-forward " " (+ num (point)))))
 	     (mid   (point))
 	     (end   (progn
 		      (skip-chars-forward skip-characters)
@@ -846,12 +853,12 @@ If SINGLE-SHOT is non-nil, it only performs the first step in the sequence."
 	(setq cycle-spacing--context  ;; Save for later.
 	      ;; Special handling for case where there was no space at all.
 	      (unless (= start end)
-		(cons orig-pos (buffer-substring start (point)))))
+                (cons n (cons orig-pos (buffer-substring start (point))))))
 	;; If this run causes no change in buffer content, delete all spaces,
 	;; otherwise delete all excess spaces.
-	(delete-region (if (and (not single-shot) (zerop n) (= mid end))
+	(delete-region (if (and (eq mode 'fast) (zerop num) (= mid end))
 			   start mid) end)
-        (insert (make-string n ?\s))))
+        (insert (make-string num ?\s))))
 
      ;; Command run for the second time.
      ((not (equal orig-pos (point)))
@@ -859,8 +866,8 @@ If SINGLE-SHOT is non-nil, it only performs the first step in the sequence."
 
      ;; Command run for the third time.
      (t
-      (insert (cdr cycle-spacing--context))
-      (goto-char (car cycle-spacing--context))
+      (insert (cddr cycle-spacing--context))
+      (goto-char (cadr cycle-spacing--context))
       (setq cycle-spacing--context nil)))))
 
 (defun beginning-of-buffer (&optional arg)
-- 
1.9.1.423.g4596e3a




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17110; Package emacs. (Thu, 27 Mar 2014 14:29:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Michal Nazarewicz <mina86 <at> mina86.com>
Cc: Alan Mackenzie <acm <at> muc.de>, bug-gnu-emacs <at> gnu.org, emacs-devel <at> gnu.org,
 Richard Stallman <rms <at> gnu.org>, Glenn Morris <rgm <at> gnu.org>
Subject: Re: [PATCH] Make `cycle-spacing' behave more like `just-one-space' if
 called once.
Date: Thu, 27 Mar 2014 10:27:14 -0400
> * simple.el (cycle-spacing): Never delete spaces on first run by
> default, but do so in a new 'fast mode and if there are already
> N spaces (the previous behaviour).

Looks OK to me (for trunk).


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#17110; Package emacs. (Fri, 28 Mar 2014 16:30:02 GMT) Full text and rfc822 format available.

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

From: Michal Nazarewicz <mina86 <at> mina86.com>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Alan Mackenzie <acm <at> muc.de>, bug-gnu-emacs <at> gnu.org, emacs-devel <at> gnu.org,
 Richard Stallman <rms <at> gnu.org>, Glenn Morris <rgm <at> gnu.org>
Subject: Re: [PATCH] Make `cycle-spacing' behave more like `just-one-space' if
 called once.
Date: Fri, 28 Mar 2014 17:29:20 +0100
[Message part 1 (text/plain, inline)]
On Thu, Mar 27 2014, Stefan Monnier wrote:
>> * simple.el (cycle-spacing): Never delete spaces on first run by
>> default, but do so in a new 'fast mode and if there are already
>> N spaces (the previous behaviour).
>
> Looks OK to me (for trunk).

Thanks, pushed.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn <at> google.com>--<xmpp:mina86 <at> jabber.org>--ooO--(_)--Ooo--
[Message part 2 (text/plain, inline)]

[signature.asc (application/pgp-signature, inline)]

bug marked as fixed in version 24.5, send any further explanations to 17110 <at> debbugs.gnu.org and Michal Nazarewicz <mina86 <at> mina86.com> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Mon, 31 Mar 2014 00: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. (Mon, 28 Apr 2014 11:24:03 GMT) Full text and rfc822 format available.

bug unarchived. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sat, 04 Oct 2014 16:36:03 GMT) Full text and rfc822 format available.

bug Marked as fixed in versions 25.1. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sat, 04 Oct 2014 16:36:03 GMT) Full text and rfc822 format available.

bug No longer marked as fixed in versions 24.5. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sat, 04 Oct 2014 16:36:03 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. (Sun, 02 Nov 2014 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 226 days ago.

Previous Next


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