From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel,gmane.emacs.bugs Subject: [PATCH] Make `cycle-spacing' behave more like `just-one-space' if called once. Date: Mon, 10 Feb 2014 13:19:19 +0100 Organization: Google Inc Message-ID: References: <20140129202810.GA3092@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1395876834 24457 80.91.229.3 (26 Mar 2014 23:33:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 26 Mar 2014 23:33:54 +0000 (UTC) Cc: Alan Mackenzie , emacs-devel@gnu.org, Stefan Monnier , Richard Stallman To: bug-gnu-emacs@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Mar 27 00:34:04 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 1WSxKc-0004Ng-12 for ged-emacs-devel@m.gmane.org; Thu, 27 Mar 2014 00:34:02 +0100 Original-Received: from localhost ([::1]:50682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WSxKb-0008En-6H for ged-emacs-devel@m.gmane.org; Wed, 26 Mar 2014 19:34:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43491) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WSxKW-0008DZ-Uq for emacs-devel@gnu.org; Wed, 26 Mar 2014 19:33:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WSxKT-0003RL-Ve for emacs-devel@gnu.org; Wed, 26 Mar 2014 19:33:56 -0400 Original-Received: from mail-ee0-x230.google.com ([2a00:1450:4013:c00::230]:36797) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WSxKT-0003Qu-Ip for emacs-devel@gnu.org; Wed, 26 Mar 2014 19:33:53 -0400 Original-Received: by mail-ee0-f48.google.com with SMTP id b57so2201414eek.21 for ; Wed, 26 Mar 2014 16:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:in-reply-to:date:organization :organization:references:user-agent:face:message-id:mime-version :content-type; bh=9eDytL76B7PlE4VDS3jt491+dpZU2D1WswQGA7jUPwE=; b=BX4XtS6H/5R7l/ivmFc4WejZwmgYlTlMVJHmwfwYkInr70W2wm3EMh/TSTja+SugTo DQGyPHo34+F05ZD0JWFngwerZV0NLSLL6/IrDp8n/LOGEdQQjcdqrPAV4WQnNQndHXgc w+fkVOAJEIrlF5ZVUS7YtxkLlgEbNHl0MLAXUjHg/UGAMCASY8cIMS9nzSfzXVr+5JAb JPaaD3yvOXbPRRRGSdxJoas3xWwgufu8kGTZuUN1q4Klh9u/svuQCfLxZTYO2kAcwZiH 2yjcu/MmmChrDW6jbYCJ6aFAthqboEG96G5dinHn75x2bzwM6JVNeQRMEygOQIt1qDd4 yNvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:in-reply-to:date :organization:organization:references:user-agent:face:message-id :mime-version:content-type; bh=9eDytL76B7PlE4VDS3jt491+dpZU2D1WswQGA7jUPwE=; b=j8oI4cjHSfOddCjh9PyFwmtEWrbUdTBtkjaLynTXkvr/9QclPJl7oJ+971huoMFiad sUHImTWsRrA9qxlPaocAJRmyFPslFS5t0oGKe4O/iryctT/NhbrGV8jYMUv2dgO0H0Kn vy0B4yzu7U81YZrXaeF+NEld9V/t0r1sGpDb5lCANY5UEuTinFx0PE3YaAFeGGFx/kgL +9RUJVQofzgyb41hl6LkTTvXMHkq5lzQcI8gZhVsTRDbqxpW9U2UnuCU6JQaCkXdCaaL r90nEe1Zzqm9jqD5eD4SOcSG3nNOyeVzZQ/Gm0/MEdnywot2KdATJSVgv4YJC74qH5lC qT1w== X-Gm-Message-State: ALoCoQkcKU9GtjS6W6UgCTptKrW8ZmIEB4SA24HG+Isjt1uABxk46cc0zljr7M49SkAZOgzq3MnfkdhTVeizvmCFfElPxe4q6uHY4PTdD1UIRbJOhZ7tKoQqFMv+8+7HAvCbxR3H1wXBy894blYESAyY0LSBI32cbr6I93vCtP0dhd6DYHqvSwKNFY3xKPfu/7PKhddtLil9mdIKLfbsku61pJzoR7tHwA== X-Received: by 10.14.87.201 with SMTP id y49mr11107222eee.62.1395876831745; Wed, 26 Mar 2014 16:33:51 -0700 (PDT) Original-Received: from mpn-glaptop.roam.corp.google.com ([2620:0:105f:301:5c2e:340a:2353:4f86]) by mx.google.com with ESMTPSA id o7sm366423eew.25.2014.03.26.16.33.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 26 Mar 2014 16:33:50 -0700 (PDT) In-Reply-To: Original-Organization: http://mina86.com/ User-Agent: Notmuch/0.17+15~gb65ca8e (http://notmuchmail.org) Emacs/24.3.50.1 (x86_64-unknown-linux-gnu) X-Face: PbkBB1w#)bOqd`iCe"Ds{e+!C7`pkC9a|f)Qo^BMQvy\q5x3?vDQJeN(DS?|-^$uMti[3D*#^_Ts"pU$jBQLq~Ud6iNwAw_r_o_4]|JO?]}P_}Nc&"p#D(ZgUb4uCNPe7~a[DbPG0T~!&c.y$Ur,=N4RT>]dNpd; KFrfMCylc}gc??'U2j,!8%xdD Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACQElEQVQ4jW3TMWvbQBQHcBk1xE6WyALX1069oZBMlq+ouUwpEQQ6uRjttkWP4CmBgGM0BQLBdPFZYPsyFUo6uEtKDQ7oy/U96XR2Ux8ehH/89Z6enqxBcS7Lg81jmSuujrfCZcLI/TYYvbGj+jbgFpHJ/bqQAUISj8iLyu4LuFHJTosxsucO4jSDNE0Hq3hwK/ceQ5sx97b8LcUDsILfk+ovHkOIsMbBfg43VuQ5Ln9YAGCkUdKJoXR9EclFBhixy3EGVz1K6eEkhxCAkeMMnqoAhAKwhoUJkDrCqvbecaYINlFKSRS1i12VKH1XpUd4qxL876EkMcDvHj3s5RBajHHMlA5iK32e0C7VgG0RlzFPvoYHZLRmAC0BmNcBruhkE0KsMsbEc62ZwUJDxWUdMsMhVqovoT96i/DnX/ASvz/6hbCabELLk/6FF/8PNpPCGqcZTGFcBhhAaZZDbQPaAB3+KrWWy2XgbYDNIinkdWAFcCpraDE/knwe5DBqGmgzESl1p2E4MWAz0VUPgYYzmfWb9yS4vCvgsxJriNTHoIBz5YteBvg+VGISQWUqhMiByPIPpygeDBE6elD973xWwKkEiHZAHKjhuPsFnBuArrzxtakRcISv+XMIPl4aGBUJm8Emk7qBYU8IlgNEIpiJhk/No24jHwkKTFHDWfPniR 4iw5vJaw2nzSjfq2zffcE/GDjRC2dn0J0XwPAbDL84TvaFCJEU4Oml9pRyEUhR3Cl2t01AoEjRbs0sYugp14/4X5n4pU4EHHnMAAAAAElFTkSuQmCC X-PGP-FP: AC1F 5F5C D418 88F8 CC84 5858 2060 4012 5075 1FF4 X-PGP: 50751FF4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::230 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:171020 gmane.emacs.bugs:87430 Archived-At: * 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 + + * 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 * 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