From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [Emacs-diffs] scratch/widen-less a4ba846: Replace prog-widen with consolidating widen calls Date: Wed, 29 Nov 2017 20:53:47 -0500 Message-ID: References: <20171129233237.27462.23351@vcs0.savannah.gnu.org> <20171129233238.504B5204F1@vcs0.savannah.gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1512006846 20006 195.159.176.226 (30 Nov 2017 01:54:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 30 Nov 2017 01:54:06 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Dmitry Gutov To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 30 02:54:00 2017 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 1eKE32-0004XV-Kf for ged-emacs-devel@m.gmane.org; Thu, 30 Nov 2017 02:53:56 +0100 Original-Received: from localhost ([::1]:45879 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKE39-0001G3-O4 for ged-emacs-devel@m.gmane.org; Wed, 29 Nov 2017 20:54:03 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKE2z-0001Fk-N8 for emacs-devel@gnu.org; Wed, 29 Nov 2017 20:53:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eKE2w-0003fj-6y for emacs-devel@gnu.org; Wed, 29 Nov 2017 20:53:53 -0500 Original-Received: from pmta11.teksavvy.com ([76.10.157.34]:29736) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1eKE2v-0003eX-UC for emacs-devel@gnu.org; Wed, 29 Nov 2017 20:53:50 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2EdCwDhYx9a/1rWbkFTCRwBAQEEAQEKA?= =?us-ascii?q?QGDPGZuJ48TjX0BgXw0AUmXeQ4iC4USBAIChRREFAEBAQEBAQEBAQNoKIJrSFg?= =?us-ascii?q?BAQEBAQEjAg1eAQEBAgEBAVQYCwULCzQSFBMBBA03GooACBCpO4pmAQEBAQEFA?= =?us-ascii?q?QEBAQEeBYNBhUiCdTaEdoYiBYo6iFOPQId0hxGSAIdajHmLAzYjgVEyGggwOoI?= =?us-ascii?q?pgweBbCM2iXcBAQE?= X-IPAS-Result: =?us-ascii?q?A2EdCwDhYx9a/1rWbkFTCRwBAQEEAQEKAQGDPGZuJ48TjX0?= =?us-ascii?q?BgXw0AUmXeQ4iC4USBAIChRREFAEBAQEBAQEBAQNoKIJrSFgBAQEBAQEjAg1eA?= =?us-ascii?q?QEBAgEBAVQYCwULCzQSFBMBBA03GooACBCpO4pmAQEBAQEFAQEBAQEeBYNBhUi?= =?us-ascii?q?CdTaEdoYiBYo6iFOPQId0hxGSAIdajHmLAzYjgVEyGggwOoIpgweBbCM2iXcBA?= =?us-ascii?q?QE?= X-IronPort-AV: E=Sophos;i="5.45,339,1508817600"; d="scan'208";a="10780322" Original-Received: from 65-110-214-90.cpe.pppoe.ca (HELO pastel.home) ([65.110.214.90]) by smtp.teksavvy.com with ESMTP; 29 Nov 2017 20:53:48 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id D7B4361295; Wed, 29 Nov 2017 20:53:47 -0500 (EST) In-Reply-To: <20171129233238.504B5204F1@vcs0.savannah.gnu.org> (Dmitry Gutov's message of "Wed, 29 Nov 2017 18:32:38 -0500 (EST)") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 76.10.157.34 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:220527 Archived-At: > Replace prog-widen with consolidating widen calls So, IIUC the idea is that the multi-major-mode framework will *have* to use narrowing to indicate to the sub-modes the boundaries of the current chunk, right? Stefan > --- > doc/lispref/text.texi | 45 +++++---------------------------------------- > etc/NEWS | 8 ++++---- > lisp/indent.el | 12 +++++++++--- > lisp/progmodes/prog-mode.el | 28 ++-------------------------- > lisp/progmodes/python.el | 34 ++++++++-------------------------- > lisp/progmodes/ruby-mode.el | 1 - > lisp/vc/add-log.el | 4 +++- > 7 files changed, 31 insertions(+), 101 deletions(-) > diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi > index 1e19f75..5a63e5b 100644 > --- a/doc/lispref/text.texi > +++ b/doc/lispref/text.texi > @@ -2407,42 +2407,17 @@ such multi-mode indentation. > This variable, when non-@code{nil}, holds the indentation context for > the sub-mode's indentation engine provided by the superior major mode. > The value should be a list of the form @code{(@var{first-column} > -@w{(@var{start} . @var{end})} @code{prev-chunk})}. The members of the > -list have the following meaning: > +@code{...rest})}. The members of the list have the following meaning: > @table @var > @item first-column > The column to be used for top-level constructs. This replaces the > default value of the top-level column used by the sub-mode, usually > zero. > -@item start > -@itemx end > -The region of the code chunk to be indented by the sub-mode. The > -value of @var{end} can be @code{nil}, which stands for the value of > -@code{point-max}. > -@item prev-chunk > -If this is non-@code{nil}, it should provide the sub-mode's > -indentation engine with a virtual context of the code chunk. Valid > -values include: > - > -@itemize @minus > -@item > -A string whose contents is the text the sub-mode's indentation engine > -should consider to precede the code chunk. The sub-mode's indentation > -engine can add text properties to that string, to be reused in > -repeated calls with the same string, thus using it as a cache. An > -example where this is useful is code chunks that need to be indented > -as function bodies, but lack the function's preamble---the string > -could then include that missing preamble. > -@item > -A function. It is expected to be called with the start position of > -the current chunk, and should return a cons cell > -@w{@code{(@var{prev-start} . @var{prev-end})}} that specifies the > -region of the previous code chunk, or @code{nil} if there is no previous > -chunk. This is useful in literate-programming sources, where code is > -split into chunks, and correct indentation needs to access previous > -chunks. > -@end itemize > +@item rest > +Reserved for future use. The intent is to provide the sub-mode's > +indentation engine with a virtual context of the code chunk. Working > +patches that use this in a significant fashion are welcome. > @end table > @end defvar > @@ -2457,16 +2432,6 @@ function's value is the column number to use for top-level constructs. > When no superior mode is in effect, this function returns zero. > @end defun > -@defun prog-widen > -Call this function instead of @code{widen} to remove any restrictions > -imposed by the mode's indentation engine and restore the restrictions > -recorded in @code{prog-indentation-context}. This prevents the > -indentation engine of a sub-mode from inadvertently operating on text > -outside of the chunk it was supposed to indent, and preserves the > -restriction imposed by the superior mode. When no superior mode is in > -effect, this function just calls @code{widen}. > -@end defun > - > @node Region Indent > @subsection Indenting an Entire Region > diff --git a/etc/NEWS b/etc/NEWS > index 4ccf468..6e1561d 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -1108,10 +1108,10 @@ programming languages in the same buffer, like literate programming > environments or ANTLR programs with embedded Python code. > A major mode can provide indentation context for a sub-mode through > -the 'prog-indentation-context' variable. To support this, modes that > -provide indentation should use 'prog-widen' instead of 'widen' and > -'prog-first-column' instead of a literal zero. See the node > -"(elisp) Mode-Specific Indent" in the ELisp manual for more details. > +the 'prog-indentation-context' variable. To support this, modes > +should use 'prog-first-column' instead of a literal zero and never > +call 'widen' in their indentation functions. See the node "(elisp) > +Mode-Specific Indent" in the ELisp manual for more details. > ** ERC > diff --git a/lisp/indent.el b/lisp/indent.el > index d5ba0bd..ccf0e99 100644 > --- a/lisp/indent.el > +++ b/lisp/indent.el > @@ -69,6 +69,8 @@ variable is `indent-relative' or `indent-relative-maybe', handle > it specially (since those functions are used for tabbing); in > that case, indent by aligning to the previous non-blank line." > (interactive) > + (save-restriction > + (widen) > (syntax-propertize (line-end-position)) > (if (memq indent-line-function > '(indent-relative indent-relative-maybe)) > @@ -84,7 +86,7 @@ that case, indent by aligning to the previous non-blank line." > (indent-line-to column) > (save-excursion (indent-line-to column)))) > ;; The normal case. > - (funcall indent-line-function))) > + (funcall indent-line-function)))) > (defun indent--default-inside-comment () > (unless (or (> (current-column) (current-indentation)) > @@ -144,7 +146,9 @@ prefix argument is ignored." > (indent--default-inside-comment) > (when (or (<= (current-column) (current-indentation)) > (not (eq tab-always-indent 'complete))) > - (funcall (default-value 'indent-line-function)))) > + (save-restriction > + (widen) > + (funcall (default-value 'indent-line-function))))) > (cond > ;; If the text was already indented right, try completion. > @@ -538,7 +542,9 @@ column to indent to; if it is nil, use one of the three methods above." > (forward-line 1))))) > ;; Use indent-region-function is available. > (indent-region-function > - (funcall indent-region-function start end)) > + (save-restriction > + (widen) > + (funcall indent-region-function start end))) > ;; Else, use a default implementation that calls indent-line-function on > ;; each line. > (t (indent-region-line-by-line start end))) > diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el > index f727e45..b36d242 100644 > --- a/lisp/progmodes/prog-mode.el > +++ b/lisp/progmodes/prog-mode.el > @@ -64,37 +64,13 @@ mode, it should bind this variable to non-nil around the call. > The non-nil value should be a list of the form: > - (FIRST-COLUMN (START . END) PREVIOUS-CHUNKS) > + (FIRST-COLUMN ...REST) > FIRST-COLUMN is the column the indentation engine of the sub-mode > should use for top-level language constructs inside the code > chunk (instead of 0). > -START and END specify the region of the code chunk. END can be > -nil, which stands for the value of `point-max'. The function > -`prog-widen' uses this to restore restrictions imposed by the > -sub-mode's indentation engine. > - > -PREVIOUS-CHUNKS, if non-nil, provides the indentation engine of > -the sub-mode with the virtual context of the code chunk. Valid > -values are: > - > - - A string containing text which the indentation engine can > - consider as standing in front of the code chunk. To cache the > - string's calculated syntactic information for repeated calls > - with the same string, the sub-mode can add text-properties to > - the string. > - > - A typical use case is for grammars with code chunks which are > - to be indented like function bodies -- the string would contain > - the corresponding function preamble. > - > - - A function, to be called with the start position of the current > - chunk. It should return either the region of the previous chunk > - as (PREV-START . PREV-END), or nil if there is no previous chunk. > - > - A typical use case are literate programming sources -- the > - function would successively return the previous code chunks.") > +REST is currently unused, but can be defined in future versions.") > (defun prog-indent-sexp (&optional defun) > "Indent the expression after point. > diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el > index d4226e5..104889a 100644 > --- a/lisp/progmodes/python.el > +++ b/lisp/progmodes/python.el > @@ -287,10 +287,6 @@ > ;;; 24.x Compat > > -(unless (fboundp 'prog-widen) > - (defun prog-widen () > - (widen))) > - > (unless (fboundp 'prog-first-column) > (defun prog-first-column () > 0)) > @@ -785,7 +781,7 @@ work on `python-indent-calculate-indentation' instead." > (interactive) > (save-excursion > (save-restriction > - (prog-widen) > + (widen) > (goto-char (point-min)) > (let ((block-end)) > (while (and (not block-end) > @@ -883,8 +879,6 @@ keyword > :at-dedenter-block-start > - Point is on a line starting a dedenter block. > - START is the position where the dedenter block starts." > - (save-restriction > - (prog-widen) > (let ((ppss (save-excursion > (beginning-of-line) > (syntax-ppss)))) > @@ -1022,7 +1016,7 @@ keyword > (looking-at (python-rx block-ender))) > :after-block-end) > (t :after-line)) > - (point))))))))) > + (point)))))))) > (defun python-indent--calculate-indentation () > "Internal implementation of `python-indent-calculate-indentation'. > @@ -1030,8 +1024,6 @@ May return an integer for the maximum possible indentation at > current context or a list of integers. The latter case is only > happening for :at-dedenter-block-start context since the > possibilities can be narrowed to specific indentation points." > - (save-restriction > - (prog-widen) > (save-excursion > (pcase (python-indent-context) > (`(:no-indent . ,_) (prog-first-column)) ; usually 0 > @@ -1081,7 +1073,7 @@ possibilities can be narrowed to specific indentation points." > (`(,(or :inside-paren-newline-start-from-block) . ,start) > ;; Add two indentation levels to make the suite stand out. > (goto-char start) > - (+ (current-indentation) (* python-indent-offset 2))))))) > + (+ (current-indentation) (* python-indent-offset 2)))))) > (defun python-indent--calculate-levels (indentation) > "Calculate levels list given INDENTATION. > @@ -4589,8 +4581,6 @@ To this: > Optional argument INCLUDE-TYPE indicates to include the type of the defun. > This function can be used as the value of `add-log-current-defun-function' > since it returns nil if point is not inside a defun." > - (save-restriction > - (prog-widen) > (save-excursion > (end-of-line 1) > (let ((names) > @@ -4644,7 +4634,7 @@ since it returns nil if point is not inside a defun." > (and (= (current-indentation) 0) (throw 'exit t)))) > (and names > (concat (and type (format "%s " type)) > - (mapconcat 'identity names "."))))))) > + (mapconcat 'identity names ".")))))) > (defun python-info-current-symbol (&optional replace-self) > "Return current symbol using dotty syntax. > @@ -4788,12 +4778,10 @@ likely an invalid python file." > "Message the first line of the block the current statement closes." > (let ((point (python-info-dedenter-opening-block-position))) > (when point > - (save-restriction > - (prog-widen) > (message "Closes %s" (save-excursion > (goto-char point) > (buffer-substring > - (point) (line-end-position)))))))) > + (point) (line-end-position))))))) > (defun python-info-dedenter-statement-p () > "Return point if current statement is a dedenter. > @@ -4809,8 +4797,6 @@ statement." > "Return non-nil if current line ends with backslash. > With optional argument LINE-NUMBER, check that line instead." > (save-excursion > - (save-restriction > - (prog-widen) > (when line-number > (python-util-goto-line line-number)) > (while (and (not (eobp)) > @@ -4819,14 +4805,12 @@ With optional argument LINE-NUMBER, check that line instead." > (not (equal (char-before (point)) ?\\))) > (forward-line 1)) > (when (equal (char-before) ?\\) > - (point-marker))))) > + (point-marker)))) > (defun python-info-beginning-of-backslash (&optional line-number) > "Return the point where the backslashed line start. > Optional argument LINE-NUMBER forces the line number to check against." > (save-excursion > - (save-restriction > - (prog-widen) > (when line-number > (python-util-goto-line line-number)) > (when (python-info-line-ends-backslash-p) > @@ -4835,15 +4819,13 @@ Optional argument LINE-NUMBER forces the line number to check against." > (python-syntax-context 'paren)) > (forward-line -1)) > (back-to-indentation) > - (point-marker))))) > + (point-marker)))) > (defun python-info-continuation-line-p () > "Check if current line is continuation of another. > When current line is continuation of another return the point > where the continued line ends." > (save-excursion > - (save-restriction > - (prog-widen) > (let* ((context-type (progn > (back-to-indentation) > (python-syntax-context-type))) > @@ -4869,7 +4851,7 @@ where the continued line ends." > (python-util-forward-comment -1) > (when (and (equal (1- line-start) (line-number-at-pos)) > (python-info-line-ends-backslash-p)) > - (point-marker)))))))) > + (point-marker))))))) > (defun python-info-block-continuation-line-p () > "Return non-nil if current line is a continuation of a block." > diff --git a/lisp/progmodes/ruby-mode.el b/lisp/progmodes/ruby-mode.el > index dc1b0f8..7c10114 100644 > --- a/lisp/progmodes/ruby-mode.el > +++ b/lisp/progmodes/ruby-mode.el > @@ -1364,7 +1364,6 @@ delimiter." > "\\)\\>"))) > (eq (ruby-deep-indent-paren-p t) 'space) > (not (bobp))) > - (widen) > (goto-char (or begin parse-start)) > (skip-syntax-forward " ") > (current-column)) > diff --git a/lisp/vc/add-log.el b/lisp/vc/add-log.el > index 392147b..9da8abc 100644 > --- a/lisp/vc/add-log.el > +++ b/lisp/vc/add-log.el > @@ -1133,6 +1133,8 @@ identifiers followed by `:' or `='. See variables > Has a preference of looking backwards." > (condition-case nil > (save-excursion > + (save-restriction > + (widen) > (if add-log-current-defun-function > (funcall add-log-current-defun-function) > ;; If all else fails, try heuristics > @@ -1147,7 +1149,7 @@ Has a preference of looking backwards." > (when (string-match "\\([^ \t\n\r\f].*[^ \t\n\r\f]\\)" > result) > (setq result (match-string-no-properties 1 result))) > - result)))) > + result))))) > (error nil))) > (defvar change-log-get-method-definition-md) > _______________________________________________ > Emacs-diffs mailing list > Emacs-diffs@gnu.org > https://lists.gnu.org/mailman/listinfo/emacs-diffs