From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel Subject: [PATCH] Make `cycle-spacing' behave more like `just-one-space' if colled once. Date: Mon, 10 Feb 2014 14:06:48 +0100 Message-ID: <1392037608-7240-1-git-send-email-mpn@google.com> References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1392037631 10692 80.91.229.3 (10 Feb 2014 13:07:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Feb 2014 13:07:11 +0000 (UTC) Cc: emacs-devel@gnu.org To: Glenn Morris , Teemu Likonen , David Kastrup , Alan Mackenzie , =?UTF-8?q?Johan=20Bockg=C3=A5rd?= , Richard Stallman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Feb 10 14:07:17 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WCqZt-0006T9-Eh for ged-emacs-devel@m.gmane.org; Mon, 10 Feb 2014 14:07:13 +0100 Original-Received: from localhost ([::1]:55511 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCqZs-0001mX-St for ged-emacs-devel@m.gmane.org; Mon, 10 Feb 2014 08:07:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCqZl-0001mI-GB for emacs-devel@gnu.org; Mon, 10 Feb 2014 08:07:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WCqZe-0001W3-Ab for emacs-devel@gnu.org; Mon, 10 Feb 2014 08:07:05 -0500 Original-Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]:63330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCqZe-0001Ve-0z for emacs-devel@gnu.org; Mon, 10 Feb 2014 08:06:58 -0500 Original-Received: by mail-wi0-f178.google.com with SMTP id cc10so2774816wib.5 for ; Mon, 10 Feb 2014 05:06:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DtVTgua4IvxiJ70RFDMTCR4oKXgu+bl6ei/a6jIN+JI=; b=LF6QoffotXf+up5DId6K5ThOT6af4+Szp3SAslfYssb3pMSTAtusqjv0i02ufdf96f 8Hm7FsAFF5rY/i8HIZ3UuYZW3IOYn14P8WBmZAePgPytSau+GyxNquTrx8CJ/BuD/kt+ 1S/9dtcPuUFWiyhcbtI0Yb9iHgEFd/4NJVjjEG+sghAA/KFtTYwehd3fb6J8Lf7ON+5t WGva8tik0xxg0hOJRtn3XebjxApLSy3gGaw7B0R4JqagW/3qmwyoA1eBrscci5AlKjDf l5cOjuC56l9hSg0st4Bt39q1K+7QvI9yDjanOstIa8O65Ls657ut/N8/pMNBL6sKp8Fa EMDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DtVTgua4IvxiJ70RFDMTCR4oKXgu+bl6ei/a6jIN+JI=; b=fDCfDVT/Ro1fsqAzAlrIeDp05kTEZ3ONPidOHXqf8HqSlv/LMt0IivngaiHlXBMquN 732TpXpbmygAGQK8IfjHxI4Nm38o6kcb+PBRjMYU7Qd2hitk8Wobv2Ubv7fIMqGVqkQe N5k0G2aDqM3ulo4f5VqjQTONG3qS93xqrAF2o2XfmrVreBskfr+G4Fky47FtNBRJvs1c oRbkcFFQlpLaaKAiAf6Arx3XQeFIffpgYFE4kJxoqKNikAJgNZUJKkSuscYcl6UIPMnb J/VoDn3kxzS4aU52A6otxBIajXdjkTfEWhi+J9I7bT88B40lvPjGR+WYlDXi7vQ4rO2F 1SIA== X-Gm-Message-State: ALoCoQlJcgtMpAYG7e7Vj2dKhKEzUkMj73ISCoelFZarEAVIzYbJ7phLpo0PUON/v+3/t7z9X66/89SVz3vmNoF0agyFO+KcqgBcgbrWvZ1vE1CWNW4/cLEPTlEMTuomMMR9qR2RcZzeU6tnotaI3StjfSx2f7tpmijRK4g0z2gMZ1Uq+rUYovE4hq9ej0Mon4XJ6Sy6/VG7 X-Received: by 10.180.105.41 with SMTP id gj9mr10415233wib.28.1392037616776; Mon, 10 Feb 2014 05:06:56 -0800 (PST) Original-Received: from mpn-glaptop.home (159-205-221-55.adsl.inetia.pl. [159.205.221.55]) by mx.google.com with ESMTPSA id pm2sm38667376wic.0.2014.02.10.05.06.54 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 10 Feb 2014 05:06:55 -0800 (PST) X-Mailer: git-send-email 1.8.5.3 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::232 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:169505 Archived-At: From: Michal Nazarewicz * 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 2e6ef1f..fc0d891 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,17 @@ +2014-02-10 Michal Nazarewicz + + * 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-02-10 Michael Albinus * net/tramp-sh.el (tramp-sh-handle-start-file-process): Do not diff --git a/lisp/simple.el b/lisp/simple.el index c20bf13..6ee895b 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -800,44 +800,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) @@ -845,12 +852,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))) @@ -858,8 +865,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.8.5.3