From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mekeor Melire Newsgroups: gmane.emacs.bugs Subject: bug#27507: [PATCH] Make `cycle-spacing' allow 'negative-zero in place of an integer Date: Tue, 27 Jun 2017 18:18:06 +0200 Message-ID: <87vanhpfpd.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1498583547 23793 195.159.176.226 (27 Jun 2017 17:12:27 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 27 Jun 2017 17:12:27 +0000 (UTC) To: 27507@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 27 19:12:20 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPu2D-0005fJ-7V for geb-bug-gnu-emacs@m.gmane.org; Tue, 27 Jun 2017 19:12:17 +0200 Original-Received: from localhost ([::1]:57212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPu2I-0007x7-DW for geb-bug-gnu-emacs@m.gmane.org; Tue, 27 Jun 2017 13:12:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54476) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPtla-0000HQ-T9 for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2017 12:55:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPtlX-000061-Kw for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2017 12:55:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:38404) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPtlX-00005p-HG for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2017 12:55:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dPtlX-0003Hb-B7 for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2017 12:55:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mekeor Melire Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 27 Jun 2017 16:55:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27507 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.149858249012557 (code B ref -1); Tue, 27 Jun 2017 16:55:03 +0000 Original-Received: (at submit) by debbugs.gnu.org; 27 Jun 2017 16:54:50 +0000 Original-Received: from localhost ([127.0.0.1]:41069 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPtlK-0003GS-D8 for submit@debbugs.gnu.org; Tue, 27 Jun 2017 12:54:50 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34590) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPtlI-0003G3-M6 for submit@debbugs.gnu.org; Tue, 27 Jun 2017 12:54:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPtlB-0008F1-LD for submit@debbugs.gnu.org; Tue, 27 Jun 2017 12:54:43 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:53715) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dPtlB-0008El-Eo for submit@debbugs.gnu.org; Tue, 27 Jun 2017 12:54:41 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPtl9-0007Cb-OB for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2017 12:54:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPtC2-0007IJ-GO for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2017 12:18:23 -0400 Original-Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:34878) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPtC2-0007H8-9w for bug-gnu-emacs@gnu.org; Tue, 27 Jun 2017 12:18:22 -0400 Original-Received: by mail-wm0-x230.google.com with SMTP id w126so29379838wme.0 for ; Tue, 27 Jun 2017 09:18:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version; bh=uNgDZBt2Nf+Mp/vfusV5zxTEFOzs7AlBEZ9gA+aRkyc=; b=V1BCtYc+txAinELLYoo6qZjGGSQrTKQqBKQ3ln7DIdCHystO7VsEo3FZ/Elhv5e5Bu 86Px+JAJ+QJn8PRhG05HZ9JWIwKazmm9sRBy4IPEgkfmFbDBnSwyJZcrtsAXH7XhSpZJ eytRXS+SO5cw4OUxa4uDHRte8eN8XCnRc/223tXgVZJRgfCfx4Nq5vaoGju4ec/sP55W bdnV5kasj6jK8umt4x9wEEnbi5HWJneOSfsFzv9zyL36TPS238Eu156QYpmctHWJV3Mb +Pn5YMNMGzNYhLG1599nl0pDEGRG3OzUkl7CFkO9jOHco6EzmURgJhk+Pk3l1XQIk5JP XGUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=uNgDZBt2Nf+Mp/vfusV5zxTEFOzs7AlBEZ9gA+aRkyc=; b=bczqAcFg64WC7wMgPVPK1aLEaI0PChcPQxdCAtvoSczvht2uZEALXkAwZxRxG1wYsX YFSp5DTOzgOJDi8lMB+LweOO7ZsOoIwgsTPwr+QnnbQiwQpwWJx7+I/Sx0L+3kHg2Bgf kt6IbInWuI//ZizEI6o1j4+Vs5uf9VOtxC7iyAg04qP4xnq/ISXp9Iu56grks/bWWkgY Dz1wd3XIzxdENJwvn28r5TYxw6Vr9nNuVzMzDa5YREMoafr0zjjX13Kr3/EU69CHkAeA jFj0np+je9pJZB6v/FxjV07LPBGO8McF79WrEHk56F8/Hm51y2mwT3xHNHyAWGEF4W8A 3n5A== X-Gm-Message-State: AKS2vOxNOtrdl0yKsdEn3/tgeZQdsC0yEjdYjWCVvyUnGXJl3oVCgDrs NCBev6uIwMzs872v X-Received: by 10.28.145.12 with SMTP id t12mr3717857wmd.7.1498580299228; Tue, 27 Jun 2017 09:18:19 -0700 (PDT) Original-Received: from melibre. ([2001:4ca0:0:f225:c202:3d69:23de:b71a]) by smtp.gmail.com with ESMTPSA id l190sm3561357wmb.18.2017.06.27.09.18.16 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Jun 2017 09:18:18 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:133961 Archived-At: * 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)