aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Wedler2015-06-14 14:47:16 +0000
committerChristoph Wedler2015-06-14 14:47:16 +0000
commit52da972751d50c2bf27315c7cad96a185b5eb103 (patch)
treebeaad7c5ba14ef7c5323b07aaee206f2053f6906
parent57e7666477a9cd14ad4f1386856686a23bfb87fd (diff)
downloademacs-52da972751d50c2bf27315c7cad96a185b5eb103.tar.gz
emacs-52da972751d50c2bf27315c7cad96a185b5eb103.zip
Some generic support for multi-mode indentation.
* lisp/progmodes/prog-mode.el (prog-indentation-context): New variable. (prog-first-column, prog-widen): New convenience functions.
-rw-r--r--ChangeLog.27
-rw-r--r--lisp/progmodes/prog-mode.el66
2 files changed, 73 insertions, 0 deletions
diff --git a/ChangeLog.2 b/ChangeLog.2
index b8e1e38a586..5935503abc9 100644
--- a/ChangeLog.2
+++ b/ChangeLog.2
@@ -1,3 +1,10 @@
12015-06-14 Christoph Wedler <christoph.wedler@sap.com>
2
3 Some generic support for multi-mode indentation.
4 * lisp/progmodes/prog-mode.el (prog-indentation-context): New
5 variable.
6 (prog-first-column, prog-widen): New convenience functions.
7
12015-06-13 Glenn Morris <rgm@gnu.org> 82015-06-13 Glenn Morris <rgm@gnu.org>
2 9
3 Tweaks for getting repository version; a bit more like it was for bzr. 10 Tweaks for getting repository version; a bit more like it was for bzr.
diff --git a/lisp/progmodes/prog-mode.el b/lisp/progmodes/prog-mode.el
index 0d9fabd2057..cb8aaad589d 100644
--- a/lisp/progmodes/prog-mode.el
+++ b/lisp/progmodes/prog-mode.el
@@ -48,6 +48,51 @@
48 map) 48 map)
49 "Keymap used for programming modes.") 49 "Keymap used for programming modes.")
50 50
51(defvar prog-indentation-context nil
52 "Non-nil while indenting embedded code chunks.
53There are languages where part of the code is actually written in
54a sub language, e.g., a Yacc/Bison or ANTLR grammar also consists
55of plain C code. This variable enables the major mode of the
56main language to use the indentation engine of the sub mode for
57lines in code chunks written in the sub language.
58
59When a major mode of such a main language decides to delegate the
60indentation of a line/region to the indentation engine of the sub
61mode, it is supposed to bind this variable to non-nil around the call.
62
63The non-nil value looks as follows
64 \(FIRST-COLUMN (START . END) PREVIOUS-CHUNKS)
65
66FIRST-COLUMN is the column the indentation engine of the sub mode
67should usually choose for top-level language constructs inside
68the code chunk (instead of 0).
69
70START to END is the region of the code chunk. See function
71`prog-widen' for additional info.
72
73PREVIOUS-CHUNKS, if non-nil, provides the indentation engine of
74the sub mode with the virtual context of the code chunk. Valid
75values are:
76
77 - A string containing code which the indentation engine can
78 consider as standing in front of the code chunk. To cache the
79 string's calculated syntactic information for repeated calls
80 with the same string, it is valid and expected for the inner
81 mode to add text-properties to the string.
82
83 A typical use case is for grammars with code chunks which are
84 to be indented like function bodies - the string would contain
85 a corresponding function header.
86
87 - A function called with the start position of the current
88 chunk. It will return either the region of the previous chunk
89 as \(PREV-START . PREV-END) or nil if there is no further
90 previous chunk.
91
92 A typical use case are literate programming sources - the
93 function would successively return the code chunks of the
94 previous macro definitions for the same name.")
95
51(defun prog-indent-sexp (&optional defun) 96(defun prog-indent-sexp (&optional defun)
52 "Indent the expression after point. 97 "Indent the expression after point.
53When interactively called with prefix, indent the enclosing defun 98When interactively called with prefix, indent the enclosing defun
@@ -61,6 +106,27 @@ instead."
61 (end (progn (forward-sexp 1) (point)))) 106 (end (progn (forward-sexp 1) (point))))
62 (indent-region start end nil)))) 107 (indent-region start end nil))))
63 108
109(defun prog-first-column ()
110 "Return the indentation column normally used for top-level constructs."
111 (or (car prog-indentation-context) 0))
112
113(defun prog-widen ()
114 "Remove restrictions (narrowing) from current code chunk or buffer.
115This function can be used instead of `widen' in any function used
116by the indentation engine to make it respect the value
117`prog-indentation-context'.
118
119This function (like 'widen') is useful inside a
120`save-restriction' to make the indentation correctly work when
121narrowing is in effect."
122 (let ((chunk (cadr prog-indentation-context)))
123 (if chunk
124 ;; no widen necessary here, as narrow-to-region changes (not
125 ;; just narrows) existing restrictions
126 (narrow-to-region (car chunk) (or (cdr chunk) (point-max)))
127 (widen))))
128
129
64(defvar-local prettify-symbols-alist nil 130(defvar-local prettify-symbols-alist nil
65 "Alist of symbol prettifications. 131 "Alist of symbol prettifications.
66Each element looks like (SYMBOL . CHARACTER), where the symbol 132Each element looks like (SYMBOL . CHARACTER), where the symbol