aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2016-03-28 03:51:21 +0300
committerDmitry Gutov2016-03-28 03:59:05 +0300
commit124c48619e2c68c497d9075e6e940142c174c77b (patch)
tree013cb50ed9f472ea2f7f036f310be00c4d98770b
parente65c3079c65595d95749348366af9811fafff062 (diff)
downloademacs-124c48619e2c68c497d9075e6e940142c174c77b.tar.gz
emacs-124c48619e2c68c497d9075e6e940142c174c77b.zip
Remove prog-indentation-context
* lisp/progmodes/prog-mode.el: (prog-indentation-context) (prog-first-column, prog-widen): Remove, as discussed in http://lists.gnu.org/archive/html/emacs-devel/2016-03/msg01425.html. * doc/lispref/text.texi (Mode-Specific Indent): Remove references to them. * etc/NEWS: Ditto. * lisp/progmodes/python.el: (prog-widen, prog-first-column): Remove the compatibility aliases and all uses. Do not merge to master.
-rw-r--r--doc/lispref/text.texi77
-rw-r--r--etc/NEWS12
-rw-r--r--lisp/progmodes/prog-mode.el68
-rw-r--r--lisp/progmodes/python.el36
4 files changed, 12 insertions, 181 deletions
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi
index 4c3a1a01e7d..6b93e51fc60 100644
--- a/doc/lispref/text.texi
+++ b/doc/lispref/text.texi
@@ -2365,83 +2365,6 @@ already indented, it calls @code{completion-at-point} to complete the
2365text at point (@pxref{Completion in Buffers}). 2365text at point (@pxref{Completion in Buffers}).
2366@end defopt 2366@end defopt
2367 2367
2368@cindex literate programming
2369@cindex multi-mode indentation
2370 Some major modes need to support embedded regions of text whose
2371syntax belongs to a different major mode. Examples include
2372@dfn{literate programming} source files that combine documentation and
2373snippets of source code, Yacc/Bison programs that include snippets of
2374plain C code, etc. To correctly indent the embedded chunks, the major
2375mode needs to delegate the indentation to another mode's indentation
2376engine (e.g., call @code{c-indent-defun} for C code or
2377@code{python-indent-line} for Python), while providing it with some
2378context to guide the indentation. The following facilities support
2379such multi-mode indentation.
2380
2381@defvar prog-indentation-context
2382This variable, when non-@code{nil}, holds the indentation context for
2383the sub-mode's indentation engine provided by the superior major mode.
2384The value should be a list of the form @code{(@var{first-column}
2385@w{(@var{start} . @var{end})} @code{prev-chunk})}. The members of the
2386list have the following meaning:
2387
2388@table @var
2389@item first-column
2390The column to be used for top-level constructs. This replaces the
2391default value of the top-level column used by the sub-mode, usually
2392zero.
2393@item start
2394@itemx end
2395The region of the code chunk to be indented by the sub-mode. The
2396value of @var{end} can be @code{nil}, which stands for the value of
2397@code{point-max}.
2398@item prev-chunk
2399If this is non-@code{nil}, it should provide the sub-mode's
2400indentation engine with a virtual context of the code chunk. Valid
2401values include:
2402
2403@itemize @minus
2404@item
2405A string whose contents is the text the sub-mode's indentation engine
2406should consider to precede the code chunk. The sub-mode's indentation
2407engine can add text properties to that string, to be reused in
2408repeated calls with the same string, thus using it as a cache. An
2409example where this is useful is code chunks that need to be indented
2410as function bodies, but lack the function's preamble---the string
2411could then include that missing preamble.
2412@item
2413A function. It is expected to be called with the start position of
2414the current chunk, and should return a cons cell
2415@w{@code{(@var{prev-start} . @var{prev-end})}} that specifies the
2416region of the previous code chunk, or @code{nil} if there is no previous
2417chunk. This is useful in literate-programming sources, where code is
2418split into chunks, and correct indentation needs to access previous
2419chunks.
2420@end itemize
2421@end table
2422@end defvar
2423
2424The following convenience functions should be used by major mode's
2425indentation engine in support of invocations as sub-modes of another
2426major mode.
2427
2428@defun prog-first-column
2429Call this function instead of using a literal value (usually, zero) of
2430the column number for indenting top-level program constructs. The
2431function's value is the column number to use for top-level constructs.
2432When no superior mode is in effect, this function returns zero.
2433@end defun
2434
2435@defun prog-widen
2436Call this function instead of @code{widen} to remove any restrictions
2437imposed by the mode's indentation engine and restore the restrictions
2438recorded in @code{prog-indentation-context}. This prevents the
2439indentation engine of a sub-mode from inadvertently operating on text
2440outside of the chunk it was supposed to indent, and preserves the
2441restriction imposed by the superior mode. When no superior mode is in
2442effect, this function just calls @code{widen}.
2443@end defun
2444
2445 2368
2446@node Region Indent 2369@node Region Indent
2447@subsection Indenting an Entire Region 2370@subsection Indenting an Entire Region
diff --git a/etc/NEWS b/etc/NEWS
index 96ec1f1ddfa..5599bd9dddd 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -396,18 +396,6 @@ the ordering of object keys by default.
396'json-pretty-print-buffer-ordered' pretty prints JSON objects with 396'json-pretty-print-buffer-ordered' pretty prints JSON objects with
397object keys sorted alphabetically. 397object keys sorted alphabetically.
398 398
399+++
400** Prog mode has some support for multi-mode indentation.
401This allows better indentation support in modes that support multiple
402programming languages in the same buffer, like literate programming
403environments or ANTLR programs with embedded Python code.
404
405A major mode can provide indentation context for a sub-mode through
406the 'prog-indentation-context' variable. To support this, modes that
407provide indentation should use 'prog-widen' instead of 'widen' and
408'prog-first-column' instead of a literal zero. See the node
409"Mode-Specific Indent" in the ELisp manual for more details.
410
411** Prettify Symbols mode 399** Prettify Symbols mode
412 400
413+++ 401+++
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 718b33932ed..3f25a0c0647 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -49,53 +49,6 @@
49 map) 49 map)
50 "Keymap used for programming modes.") 50 "Keymap used for programming modes.")
51 51
52(defvar prog-indentation-context nil
53 "When non-nil, provides context for indenting embedded code chunks.
54
55There are languages where part of the code is actually written in
56a sub language, e.g., a Yacc/Bison or ANTLR grammar also consists
57of plain C code. This variable enables the major mode of the
58main language to use the indentation engine of the sub-mode for
59lines in code chunks written in the sub-mode's language.
60
61When a major mode of such a main language decides to delegate the
62indentation of a line/region to the indentation engine of the sub
63mode, it should bind this variable to non-nil around the call.
64
65The non-nil value should be a list of the form:
66
67 (FIRST-COLUMN (START . END) PREVIOUS-CHUNKS)
68
69FIRST-COLUMN is the column the indentation engine of the sub-mode
70should use for top-level language constructs inside the code
71chunk (instead of 0).
72
73START and END specify the region of the code chunk. END can be
74nil, which stands for the value of `point-max'. The function
75`prog-widen' uses this to restore restrictions imposed by the
76sub-mode's indentation engine.
77
78PREVIOUS-CHUNKS, if non-nil, provides the indentation engine of
79the sub-mode with the virtual context of the code chunk. Valid
80values are:
81
82 - A string containing text which the indentation engine can
83 consider as standing in front of the code chunk. To cache the
84 string's calculated syntactic information for repeated calls
85 with the same string, the sub-mode can add text-properties to
86 the string.
87
88 A typical use case is for grammars with code chunks which are
89 to be indented like function bodies -- the string would contain
90 the corresponding function preamble.
91
92 - A function, to be called with the start position of the current
93 chunk. It should return either the region of the previous chunk
94 as (PREV-START . PREV-END), or nil if there is no previous chunk.
95
96 A typical use case are literate programming sources -- the
97 function would successively return the previous code chunks.")
98
99(defun prog-indent-sexp (&optional defun) 52(defun prog-indent-sexp (&optional defun)
100 "Indent the expression after point. 53 "Indent the expression after point.
101When interactively called with prefix, indent the enclosing defun 54When interactively called with prefix, indent the enclosing defun
@@ -109,27 +62,6 @@ instead."
109 (end (progn (forward-sexp 1) (point)))) 62 (end (progn (forward-sexp 1) (point))))
110 (indent-region start end nil)))) 63 (indent-region start end nil))))
111 64
112(defun prog-first-column ()
113 "Return the indentation column normally used for top-level constructs."
114 (or (car prog-indentation-context) 0))
115
116(defun prog-widen ()
117 "Remove restrictions (narrowing) from current code chunk or buffer.
118This function should be used instead of `widen' in any function used
119by the indentation engine to make it respect the value of
120`prog-indentation-context'.
121
122This function (like `widen') is useful inside a
123`save-restriction' to make the indentation correctly work when
124narrowing is in effect."
125 (let ((chunk (cadr prog-indentation-context)))
126 (if chunk
127 ;; No call to `widen' is necessary here, as narrow-to-region
128 ;; changes (not just narrows) the existing restrictions
129 (narrow-to-region (car chunk) (or (cdr chunk) (point-max)))
130 (widen))))
131
132
133(defvar-local prettify-symbols-alist nil 65(defvar-local prettify-symbols-alist nil
134 "Alist of symbol prettifications. 66 "Alist of symbol prettifications.
135Each element looks like (SYMBOL . CHARACTER), where the symbol 67Each element looks like (SYMBOL . CHARACTER), where the symbol
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 5aeefe47a54..90097df7ef1 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -283,18 +283,6 @@
283 :version "24.3" 283 :version "24.3"
284 :link '(emacs-commentary-link "python")) 284 :link '(emacs-commentary-link "python"))
285 285
286
287;;; 24.x Compat
288
289
290(unless (fboundp 'prog-widen)
291 (defun prog-widen ()
292 (widen)))
293
294(unless (fboundp 'prog-first-column)
295 (defun prog-first-column ()
296 0))
297
298 286
299;;; Bindings 287;;; Bindings
300 288
@@ -761,7 +749,7 @@ work on `python-indent-calculate-indentation' instead."
761 (interactive) 749 (interactive)
762 (save-excursion 750 (save-excursion
763 (save-restriction 751 (save-restriction
764 (prog-widen) 752 (widen)
765 (goto-char (point-min)) 753 (goto-char (point-min))
766 (let ((block-end)) 754 (let ((block-end))
767 (while (and (not block-end) 755 (while (and (not block-end)
@@ -860,7 +848,7 @@ keyword
860 - Point is on a line starting a dedenter block. 848 - Point is on a line starting a dedenter block.
861 - START is the position where the dedenter block starts." 849 - START is the position where the dedenter block starts."
862 (save-restriction 850 (save-restriction
863 (prog-widen) 851 (widen)
864 (let ((ppss (save-excursion 852 (let ((ppss (save-excursion
865 (beginning-of-line) 853 (beginning-of-line)
866 (syntax-ppss)))) 854 (syntax-ppss))))
@@ -1007,10 +995,10 @@ current context or a list of integers. The latter case is only
1007happening for :at-dedenter-block-start context since the 995happening for :at-dedenter-block-start context since the
1008possibilities can be narrowed to specific indentation points." 996possibilities can be narrowed to specific indentation points."
1009 (save-restriction 997 (save-restriction
1010 (prog-widen) 998 (widen)
1011 (save-excursion 999 (save-excursion
1012 (pcase (python-indent-context) 1000 (pcase (python-indent-context)
1013 (`(:no-indent . ,_) (prog-first-column)) ; usually 0 1001 (`(:no-indent . ,_) 0)
1014 (`(,(or :after-line 1002 (`(,(or :after-line
1015 :after-comment 1003 :after-comment
1016 :inside-string 1004 :inside-string
@@ -1048,7 +1036,7 @@ possibilities can be narrowed to specific indentation points."
1048 (let ((opening-block-start-points 1036 (let ((opening-block-start-points
1049 (python-info-dedenter-opening-block-positions))) 1037 (python-info-dedenter-opening-block-positions)))
1050 (if (not opening-block-start-points) 1038 (if (not opening-block-start-points)
1051 (prog-first-column) ; if not found default to first column 1039 0 ; if not found default to first column
1052 (mapcar (lambda (pos) 1040 (mapcar (lambda (pos)
1053 (save-excursion 1041 (save-excursion
1054 (goto-char pos) 1042 (goto-char pos)
@@ -1066,7 +1054,7 @@ integers. Levels are returned in ascending order, and in the
1066case INDENTATION is a list, this order is enforced." 1054case INDENTATION is a list, this order is enforced."
1067 (if (listp indentation) 1055 (if (listp indentation)
1068 (sort (copy-sequence indentation) #'<) 1056 (sort (copy-sequence indentation) #'<)
1069 (nconc (number-sequence (prog-first-column) (1- indentation) 1057 (nconc (number-sequence 0 (1- indentation)
1070 python-indent-offset) 1058 python-indent-offset)
1071 (list indentation)))) 1059 (list indentation))))
1072 1060
@@ -1091,7 +1079,7 @@ minimum."
1091 (python-indent--previous-level levels (current-indentation)) 1079 (python-indent--previous-level levels (current-indentation))
1092 (if levels 1080 (if levels
1093 (apply #'max levels) 1081 (apply #'max levels)
1094 (prog-first-column))))) 1082 0))))
1095 1083
1096(defun python-indent-line (&optional previous) 1084(defun python-indent-line (&optional previous)
1097 "Internal implementation of `python-indent-line-function'. 1085 "Internal implementation of `python-indent-line-function'.
@@ -4479,7 +4467,7 @@ Optional argument INCLUDE-TYPE indicates to include the type of the defun.
4479This function can be used as the value of `add-log-current-defun-function' 4467This function can be used as the value of `add-log-current-defun-function'
4480since it returns nil if point is not inside a defun." 4468since it returns nil if point is not inside a defun."
4481 (save-restriction 4469 (save-restriction
4482 (prog-widen) 4470 (widen)
4483 (save-excursion 4471 (save-excursion
4484 (end-of-line 1) 4472 (end-of-line 1)
4485 (let ((names) 4473 (let ((names)
@@ -4662,7 +4650,7 @@ likely an invalid python file."
4662 (let ((point (python-info-dedenter-opening-block-position))) 4650 (let ((point (python-info-dedenter-opening-block-position)))
4663 (when point 4651 (when point
4664 (save-restriction 4652 (save-restriction
4665 (prog-widen) 4653 (widen)
4666 (message "Closes %s" (save-excursion 4654 (message "Closes %s" (save-excursion
4667 (goto-char point) 4655 (goto-char point)
4668 (buffer-substring 4656 (buffer-substring
@@ -4683,7 +4671,7 @@ statement."
4683With optional argument LINE-NUMBER, check that line instead." 4671With optional argument LINE-NUMBER, check that line instead."
4684 (save-excursion 4672 (save-excursion
4685 (save-restriction 4673 (save-restriction
4686 (prog-widen) 4674 (widen)
4687 (when line-number 4675 (when line-number
4688 (python-util-goto-line line-number)) 4676 (python-util-goto-line line-number))
4689 (while (and (not (eobp)) 4677 (while (and (not (eobp))
@@ -4699,7 +4687,7 @@ With optional argument LINE-NUMBER, check that line instead."
4699Optional argument LINE-NUMBER forces the line number to check against." 4687Optional argument LINE-NUMBER forces the line number to check against."
4700 (save-excursion 4688 (save-excursion
4701 (save-restriction 4689 (save-restriction
4702 (prog-widen) 4690 (widen)
4703 (when line-number 4691 (when line-number
4704 (python-util-goto-line line-number)) 4692 (python-util-goto-line line-number))
4705 (when (python-info-line-ends-backslash-p) 4693 (when (python-info-line-ends-backslash-p)
@@ -4716,7 +4704,7 @@ When current line is continuation of another return the point
4716where the continued line ends." 4704where the continued line ends."
4717 (save-excursion 4705 (save-excursion
4718 (save-restriction 4706 (save-restriction
4719 (prog-widen) 4707 (widen)
4720 (let* ((context-type (progn 4708 (let* ((context-type (progn
4721 (back-to-indentation) 4709 (back-to-indentation)
4722 (python-syntax-context-type))) 4710 (python-syntax-context-type)))