From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Phil Sainty Newsgroups: gmane.emacs.devel Subject: [PATCH] Enhance the use of prefix arguments when filling text Date: Sun, 13 Nov 2016 00:21:08 +1300 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------27AAB4DCF8EF05347D9AC935" X-Trace: blaine.gmane.org 1478949696 12676 195.159.176.226 (12 Nov 2016 11:21:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 12 Nov 2016 11:21:36 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Nov 12 12:21:31 2016 Return-path: Envelope-to: ged-emacs-devel@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 1c5WNB-0001wx-RW for ged-emacs-devel@m.gmane.org; Sat, 12 Nov 2016 12:21:26 +0100 Original-Received: from localhost ([::1]:57668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5WNE-0003ki-P4 for ged-emacs-devel@m.gmane.org; Sat, 12 Nov 2016 06:21:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5WN4-0003kY-Ew for emacs-devel@gnu.org; Sat, 12 Nov 2016 06:21:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5WN1-0000uu-9e for emacs-devel@gnu.org; Sat, 12 Nov 2016 06:21:18 -0500 Original-Received: from [219.88.242.22] (port=39779 helo=mail.orcon.net.nz) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c5WN0-0000uX-On for emacs-devel@gnu.org; Sat, 12 Nov 2016 06:21:15 -0500 Original-Received: from [192.168.20.100] ([150.107.172.166]) (authenticated bits=0) by mail.orcon.net.nz (8.14.3/8.14.3/Debian-9.4) with ESMTP id uACBL755006054 for ; Sun, 13 Nov 2016 00:21:08 +1300 X-Bayes-Prob: 0.0001 (Score 0: No Bayes scoring rules defined, tokens from: outbound) X-CanIt-Geo: ip=150.107.172.166; country=NZ; region=Bay of Plenty Region; city=Tauranga; latitude=-37.6686; longitude=176.2664; http://maps.google.com/maps?q=-37.6686,176.2664&z=6 X-CanItPRO-Stream: base:outbound X-Canit-Stats-ID: 02S6Xl8h1 - d6b665a36f62 - 20161113 X-Scanned-By: CanIt (www . roaringpenguin . com) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 219.88.242.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:209354 Archived-At: This is a multi-part message in MIME format. --------------27AAB4DCF8EF05347D9AC935 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit This patch enables the use of a numeric prefix argument to select a one-time `fill-column' value, over-riding the value for that call. It takes effect before the main fill loop in `fill-region-as-paragraph' (which is ultimately used by all the other fill commands), by which time the likes of `emacs-lisp-docstring-fill-column' have already been dealt with, and won't clobber the prefix value. A prefix argument of `-' now means "un-fill" (turning multiple lines into a single long line), by using most-positive-fixnum as the fill-column for that call. All fill commands accept a JUSTIFY argument, and at present a prefix argument of any kind always simply means JUSTIFY is 'full. As that interactive behaviour is implemented independently by each command, this patch necessarily changes the interactive argument handling for each fill command, to prevent them from justifying when we are just setting a fill column. With the patch, negative numeric arguments now mean JUSTIFY using the specified fill column. In all cases a plain C-u still means (only) JUSTIFY. A new user option `fill-interactive-prefix-type' determines whether or not the new behaviour is used. There is a setting to revert to the original behaviour (where any prefix argument means JUSTIFY), and also a hybrid setting to combine the old and new behaviours in a practical manner. This initial patch addresses only the commands in fill.el itself, but changes for other fill commands ought to follow a similar pattern. The patch is also missing documentation changes to the modified commands and to the info manuals, but I'm sending it as-is for review of the general idea and implementation. The patch was rolled against the emacs-25 branch. -Phil --------------27AAB4DCF8EF05347D9AC935 Content-Type: text/x-patch; name="0001-Enhance-use-of-prefix-arguments-when-filling-text.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Enhance-use-of-prefix-arguments-when-filling-text.patch" >From acbbc93a4efb33850dbe5e7a42c4c237962fe354 Mon Sep 17 00:00:00 2001 From: Phil Sainty Date: Sat, 12 Nov 2016 22:31:53 +1300 Subject: [PATCH] Enhance the use of prefix arguments when filling text * lisp/textmodes/fill.el (fill-region-as-paragraph): Modify fill-column locally, based on the interactive prefix argument. (fill-interactive-prefix-type): New user option. (fill-interactive-column, fill-interactive-justify-arg): New functions. (fill-region-as-paragraph, fill-paragraph, fill-region, fill-nonuniform-paragraphs, fill-individual-paragraphs): Change how interactive JUSTIFY argument is calculated. --- lisp/textmodes/fill.el | 94 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 88 insertions(+), 6 deletions(-) diff --git a/lisp/textmodes/fill.el b/lisp/textmodes/fill.el index 100e2a2..788546a 100644 --- a/lisp/textmodes/fill.el +++ b/lisp/textmodes/fill.el @@ -618,6 +618,87 @@ fill-indent-to-left-margin (indent-line-to (current-left-margin)) (put-text-property beg (point) 'face 'default))) +(defcustom fill-interactive-prefix-type 'column-and-justify + "Determines how fill commands interpret a prefix argument. + +Under the default `column-and-justify' setting, a plain C-u +argument sets the JUSTIFY argument; a positive numeric argument +specifies `fill-column' for the duration of the command; a +negative numeric argument specifies both a `fill-column' value +and JUSTIFY together; and a plain `-' argument causes the text to +be 'un-filled' into a single line. Temporary fill-column values +are displayed in the echo area. A numeric prefix argument of +zero does not modify the fill-column, but also causes the current +value to be displayed. + +The `justify' setting is the original behaviour, where any prefix +argument simply means JUSTIFY. + +The `hybrid' setting behaves like `column-and-justify' with the +exception of single-digit numeric arguments, which mean JUSTIFY. +Because fill-columns of less than 10 are unlikely to be useful, +this setting provides the new features while still enabling the +use of a numeric prefix argument to mean JUSTIFY for users who +were used to doing that." + :type '(choice (const :tag "Fill-column and/or justify" column-and-justify) + (const :tag "Justify only" justify) + (const :tag "Hybrid" hybrid)) + :safe 'symbolp + :group 'fill) + +(defun fill-interactive-justify-arg () + "Determine the JUSTIFY argument for the current fill command +based on the interactive `current-prefix-arg', and the user +option `fill-interactive-prefix-type'. + +Called in the interactive forms of fill commands. + +Returns either 'full or nil in all cases." + (cond + ;; column-and-justify + ((eq fill-interactive-prefix-type 'column-and-justify) + (if (or (consp current-prefix-arg) + (and (integerp current-prefix-arg) + (< current-prefix-arg 0))) + 'full)) + ;; hybrid + ((eq fill-interactive-prefix-type 'hybrid) + (if (or (consp current-prefix-arg) + (and (integerp current-prefix-arg) + (< current-prefix-arg 10))) + 'full)) + ;; justify + ((eq fill-interactive-prefix-type 'justify) + (if current-prefix-arg 'full)))) + +(defun fill-interactive-column (col) + "Return column COL, modified based on the current prefix arg +and the user option `fill-interactive-prefix-type'. + +`fill-region-as-paragraph' let-binds `fill-column' to this value." + (cond + ;; justify (do nothing; ignore remaining conditions) + ((eq fill-interactive-prefix-type 'justify)) + ;; un-fill + ((eq current-prefix-arg '-) + (setq col most-positive-fixnum) + (message "Un-filling")) + ;; column-and-justify + ((and (eq fill-interactive-prefix-type 'column-and-justify) + (integerp current-prefix-arg)) + (unless (eq 0 current-prefix-arg) + (setq col (abs current-prefix-arg))) + (message "Using fill column %d" col)) + ;; hybrid + ((and (eq fill-interactive-prefix-type 'hybrid) + (integerp current-prefix-arg) + (or (> current-prefix-arg 9) + (< current-prefix-arg 0))) + (setq col (abs current-prefix-arg)) + (message "Using fill column %d" col))) + ;; return the column, possibly unchanged. + col) + (defun fill-region-as-paragraph (from to &optional justify nosqueeze squeeze-after) "Fill the region as one paragraph. @@ -642,7 +723,7 @@ fill-region-as-paragraph (interactive (progn (barf-if-buffer-read-only) (list (region-beginning) (region-end) - (if current-prefix-arg 'full)))) + (fill-interactive-justify-arg)))) (unless (memq justify '(t nil none full center left right)) (setq justify 'full)) @@ -726,7 +807,8 @@ fill-region-as-paragraph ;; This is the actual filling loop. (goto-char from) - (let (linebeg) + (let ((fill-column (fill-interactive-column fill-column)) + linebeg) (while (< (point) to) (setq linebeg (point)) (move-to-column (current-fill-column)) @@ -803,7 +885,7 @@ fill-paragraph region, instead of just filling the current paragraph." (interactive (progn (barf-if-buffer-read-only) - (list (if current-prefix-arg 'full) t))) + (list (fill-interactive-justify-arg) t))) (or ;; 1. Fill the region if it is active when called interactively. (and region transient-mark-mode mark-active @@ -1023,7 +1105,7 @@ fill-region (interactive (progn (barf-if-buffer-read-only) (list (region-beginning) (region-end) - (if current-prefix-arg 'full)))) + (fill-interactive-justify-arg)))) (unless (memq justify '(t nil none full center left right)) (setq justify 'full)) (let ((start-point (point-marker)) @@ -1383,7 +1465,7 @@ fill-nonuniform-paragraphs (interactive (progn (barf-if-buffer-read-only) (list (region-beginning) (region-end) - (if current-prefix-arg 'full)))) + (fill-interactive-justify-arg)))) (let ((fill-individual-varying-indent t)) (fill-individual-paragraphs min max justifyp citation-regexp))) @@ -1413,7 +1495,7 @@ fill-individual-paragraphs (interactive (progn (barf-if-buffer-read-only) (list (region-beginning) (region-end) - (if current-prefix-arg 'full)))) + (fill-interactive-justify-arg)))) (save-restriction (save-excursion (goto-char min) -- 2.8.3 --------------27AAB4DCF8EF05347D9AC935--