summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/lua-mode.el
diff options
context:
space:
mode:
Diffstat (limited to '.emacs.d/lisp/lua-mode.el')
-rw-r--r--.emacs.d/lisp/lua-mode.el251
1 files changed, 145 insertions, 106 deletions
diff --git a/.emacs.d/lisp/lua-mode.el b/.emacs.d/lisp/lua-mode.el
index af94a13..640e490 100644
--- a/.emacs.d/lisp/lua-mode.el
+++ b/.emacs.d/lisp/lua-mode.el
@@ -1,4 +1,4 @@
1;;; lua-mode.el --- a major-mode for editing Lua scripts 1;;; lua-mode.el --- a major-mode for editing Lua scripts -*- lexical-binding: t -*-
2 2
3;; Author: 2011-2013 immerrr <immerrr+lua@gmail.com> 3;; Author: 2011-2013 immerrr <immerrr+lua@gmail.com>
4;; 2010-2011 Reuben Thomas <rrt@sc3d.org> 4;; 2010-2011 Reuben Thomas <rrt@sc3d.org>
@@ -13,6 +13,7 @@
13;; 13;;
14;; URL: http://immerrr.github.com/lua-mode 14;; URL: http://immerrr.github.com/lua-mode
15;; Version: 20151025 15;; Version: 20151025
16;; Package-Requires: ((emacs "24.3"))
16;; 17;;
17;; This file is NOT part of Emacs. 18;; This file is NOT part of Emacs.
18;; 19;;
@@ -40,7 +41,7 @@
40 41
41;;; Commentary: 42;;; Commentary:
42 43
43;; lua-mode provides support for editing Lua, including automatical 44;; lua-mode provides support for editing Lua, including automatic
44;; indentation, syntactical font-locking, running interactive shell, 45;; indentation, syntactical font-locking, running interactive shell,
45;; interacting with `hs-minor-mode' and online documentation lookup. 46;; interacting with `hs-minor-mode' and online documentation lookup.
46 47
@@ -86,7 +87,7 @@
86 87
87;;; Code: 88;;; Code:
88(eval-when-compile 89(eval-when-compile
89 (require 'cl)) 90 (require 'cl-lib))
90 91
91(require 'comint) 92(require 'comint)
92(require 'newcomment) 93(require 'newcomment)
@@ -101,80 +102,120 @@
101 (require 'compile)) 102 (require 'compile))
102 103
103(eval-and-compile 104(eval-and-compile
104 (defvar lua-rx-constituents) 105 (if (fboundp #'rx-let)
105 (defvar rx-parent) 106 (progn
107 ;; Emacs 27+ way of customizing rx
108 (defvar lua--rx-bindings)
109
110 (setq
111 lua--rx-bindings
112 '((symbol (&rest x) (seq symbol-start (or x) symbol-end))
113 (ws (* (any " \t")))
114 (ws+ (+ (any " \t")))
115
116 (lua-name (symbol (seq (+ (any alpha "_")) (* (any alnum "_")))))
117 (lua-funcname (seq lua-name (* ws "." ws lua-name)
118 (opt ws ":" ws lua-name)))
119 (lua-funcheader
120 ;; Outer (seq ...) is here to shy-group the definition
121 (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname))
122 (seq (group-n 1 lua-funcname) ws "=" ws
123 (symbol "function")))))
124 (lua-number
125 (seq (or (seq (+ digit) (opt ".") (* digit))
126 (seq (* digit) (opt ".") (+ digit)))
127 (opt (regexp "[eE][+-]?[0-9]+"))))
128 (lua-assignment-op (seq "=" (or buffer-end (not (any "=")))))
129 (lua-token (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
130 ">" "=" ";" ":" "," "." ".." "..."))
131 (lua-keyword
132 (symbol "and" "break" "do" "else" "elseif" "end" "for" "function"
133 "goto" "if" "in" "local" "not" "or" "repeat" "return"
134 "then" "until" "while"))))
135
136 (defmacro lua-rx (&rest regexps)
137 (eval `(rx-let ,lua--rx-bindings
138 (rx ,@regexps))))
106 139
107 (defun lua-rx-to-string (form &optional no-group) 140 (defun lua-rx-to-string (form &optional no-group)
108 "Lua-specific replacement for `rx-to-string'. 141 (rx-let-eval lua--rx-bindings
142 (rx-to-string form no-group))))
143 (progn
144 ;; Pre-Emacs 27 way of customizing rx
145 (defvar lua-rx-constituents)
146 (defvar rx-parent)
147
148 (defun lua-rx-to-string (form &optional no-group)
149 "Lua-specific replacement for `rx-to-string'.
109 150
110See `rx-to-string' documentation for more information FORM and 151See `rx-to-string' documentation for more information FORM and
111NO-GROUP arguments." 152NO-GROUP arguments."
112 (let ((rx-constituents lua-rx-constituents)) 153 (let ((rx-constituents lua-rx-constituents))
113 (rx-to-string form no-group))) 154 (rx-to-string form no-group)))
114 155
115 (defmacro lua-rx (&rest regexps) 156 (defmacro lua-rx (&rest regexps)
116 "Lua-specific replacement for `rx'. 157 "Lua-specific replacement for `rx'.
117 158
118See `rx' documentation for more information about REGEXPS param." 159See `rx' documentation for more information about REGEXPS param."
119 (cond ((null regexps) 160 (cond ((null regexps)
120 (error "No regexp")) 161 (error "No regexp"))
121 ((cdr regexps) 162 ((cdr regexps)
122 (lua-rx-to-string `(and ,@regexps) t)) 163 (lua-rx-to-string `(and ,@regexps) t))
123 (t 164 (t
124 (lua-rx-to-string (car regexps) t)))) 165 (lua-rx-to-string (car regexps) t))))
125 166
126 (defun lua--new-rx-form (form) 167 (defun lua--new-rx-form (form)
127 "Add FORM definition to `lua-rx' macro. 168 "Add FORM definition to `lua-rx' macro.
128 169
129FORM is a cons (NAME . DEFN), see more in `rx-constituents' doc. 170FORM is a cons (NAME . DEFN), see more in `rx-constituents' doc.
130This function enables specifying new definitions using old ones: 171This function enables specifying new definitions using old ones:
131if DEFN is a list that starts with `:rx' symbol its second 172if DEFN is a list that starts with `:rx' symbol its second
132element is itself expanded with `lua-rx-to-string'. " 173element is itself expanded with `lua-rx-to-string'. "
133 (let ((name (car form)) 174 (let ((form-definition (cdr form)))
134 (form-definition (cdr form))) 175 (when (and (listp form-definition) (eq ':rx (car form-definition)))
135 (when (and (listp form-definition) (eq ':rx (car form-definition))) 176 (setcdr form (lua-rx-to-string (cadr form-definition) 'nogroup)))
136 (setcdr form (lua-rx-to-string (cadr form-definition) 'nogroup))) 177 (push form lua-rx-constituents)))
137 (push form lua-rx-constituents)))
138 178
139 (defun lua--rx-symbol (form) 179 (defun lua--rx-symbol (form)
140 ;; form is a list (symbol XXX ...) 180 ;; form is a list (symbol XXX ...)
141 ;; Skip initial 'symbol 181 ;; Skip initial 'symbol
142 (setq form (cdr form)) 182 (setq form (cdr form))
143 ;; If there's only one element, take it from the list, otherwise wrap the 183 ;; If there's only one element, take it from the list, otherwise wrap the
144 ;; whole list into `(or XXX ...)' form. 184 ;; whole list into `(or XXX ...)' form.
145 (setq form (if (eq 1 (length form)) 185 (setq form (if (eq 1 (length form))
146 (car form) 186 (car form)
147 (append '(or) form))) 187 (append '(or) form)))
148 (rx-form `(seq symbol-start ,form symbol-end) rx-parent)) 188 (and (fboundp 'rx-form) ; Silence Emacs 27's byte-compiler.
189 (rx-form `(seq symbol-start ,form symbol-end) rx-parent)))
149 190
150 (setq lua-rx-constituents (copy-sequence rx-constituents)) 191 (setq lua-rx-constituents (copy-sequence rx-constituents))
151 192
152 (mapc #'lua--new-rx-form 193 (mapc 'lua--new-rx-form
153 `((symbol lua--rx-symbol 1 nil) 194 `((symbol lua--rx-symbol 1 nil)
154 (ws . "[ \t]*") (ws+ . "[ \t]+") 195 (ws . "[ \t]*") (ws+ . "[ \t]+")
155 (lua-name :rx (symbol (regexp "[[:alpha:]_]+[[:alnum:]_]*"))) 196 (lua-name :rx (symbol (regexp "[[:alpha:]_]+[[:alnum:]_]*")))
156 (lua-funcname 197 (lua-funcname
157 :rx (seq lua-name (* ws "." ws lua-name) 198 :rx (seq lua-name (* ws "." ws lua-name)
158 (opt ws ":" ws lua-name))) 199 (opt ws ":" ws lua-name)))
159 (lua-funcheader 200 (lua-funcheader
160 ;; Outer (seq ...) is here to shy-group the definition 201 ;; Outer (seq ...) is here to shy-group the definition
161 :rx (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname)) 202 :rx (seq (or (seq (symbol "function") ws (group-n 1 lua-funcname))
162 (seq (group-n 1 lua-funcname) ws "=" ws 203 (seq (group-n 1 lua-funcname) ws "=" ws
163 (symbol "function"))))) 204 (symbol "function")))))
164 (lua-number 205 (lua-number
165 :rx (seq (or (seq (+ digit) (opt ".") (* digit)) 206 :rx (seq (or (seq (+ digit) (opt ".") (* digit))
166 (seq (* digit) (opt ".") (+ digit))) 207 (seq (* digit) (opt ".") (+ digit)))
167 (opt (regexp "[eE][+-]?[0-9]+")))) 208 (opt (regexp "[eE][+-]?[0-9]+"))))
168 (lua-assignment-op 209 (lua-assignment-op
169 :rx (seq "=" (or buffer-end (not (any "="))))) 210 :rx (seq "=" (or buffer-end (not (any "=")))))
170 (lua-token 211 (lua-token
171 :rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<" 212 :rx (or "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<"
172 ">" "=" ";" ":" "," "." ".." "...")) 213 ">" "=" ";" ":" "," "." ".." "..."))
173 (lua-keyword 214 (lua-keyword
174 :rx (symbol "and" "break" "do" "else" "elseif" "end" "for" "function" 215 :rx (symbol "and" "break" "do" "else" "elseif" "end" "for" "function"
175 "goto" "if" "in" "local" "not" "or" "repeat" "return" 216 "goto" "if" "in" "local" "not" "or" "repeat" "return"
176 "then" "until" "while"))) 217 "then" "until" "while")))
177 )) 218 ))))
178 219
179 220
180;; Local variables 221;; Local variables
@@ -277,8 +318,7 @@ If the latter is nil, the keymap translates into `lua-mode-map' verbatim.")
277 318
278 319
279(defvar lua-mode-map 320(defvar lua-mode-map
280 (let ((result-map (make-sparse-keymap)) 321 (let ((result-map (make-sparse-keymap)))
281 prefix-key)
282 (unless (boundp 'electric-indent-chars) 322 (unless (boundp 'electric-indent-chars)
283 (mapc (lambda (electric-char) 323 (mapc (lambda (electric-char)
284 (define-key result-map 324 (define-key result-map
@@ -488,7 +528,7 @@ groups set according to next matched token:
488 528
489Blanks & comments between tokens are silently skipped. 529Blanks & comments between tokens are silently skipped.
490Groups 6-9 can be used in any of argument regexps." 530Groups 6-9 can be used in any of argument regexps."
491 (lexical-let* 531 (let*
492 ((delimited-matcher-re-template 532 ((delimited-matcher-re-template
493 "\\=\\(?2:.*?\\)\\(?:\\(?%s:\\(?4:%s\\)\\|\\(?5:%s\\)\\)\\|\\(?%s:\\(?1:%s\\)\\)\\)") 533 "\\=\\(?2:.*?\\)\\(?:\\(?%s:\\(?4:%s\\)\\|\\(?5:%s\\)\\)\\|\\(?%s:\\(?1:%s\\)\\)\\)")
494 ;; There's some magic to this regexp. It works as follows: 534 ;; There's some magic to this regexp. It works as follows:
@@ -515,7 +555,6 @@ Groups 6-9 can be used in any of argument regexps."
515 555
516 (lambda (end) 556 (lambda (end)
517 (let* ((prev-elt-p (match-beginning 1)) 557 (let* ((prev-elt-p (match-beginning 1))
518 (prev-sep-p (match-beginning 4))
519 (prev-end-p (match-beginning 5)) 558 (prev-end-p (match-beginning 5))
520 559
521 (regexp (if prev-elt-p sep-or-end-expected-re elt-expected-re)) 560 (regexp (if prev-elt-p sep-or-end-expected-re elt-expected-re))
@@ -567,7 +606,7 @@ Groups 6-9 can be used in any of argument regexps."
567 (,(lua-rx "::" ws lua-name ws "::") 606 (,(lua-rx "::" ws lua-name ws "::")
568 . font-lock-constant-face) 607 . font-lock-constant-face)
569 608
570 ;; Hightlights the name of the label in the "goto" statement like 609 ;; Highlights the name of the label in the "goto" statement like
571 ;; "goto label" 610 ;; "goto label"
572 (,(lua-rx (symbol (seq "goto" ws+ (group-n 1 lua-name)))) 611 (,(lua-rx (symbol (seq "goto" ws+ (group-n 1 lua-name))))
573 (1 font-lock-constant-face)) 612 (1 font-lock-constant-face))
@@ -669,9 +708,6 @@ Groups 6-9 can be used in any of argument regexps."
669 :abbrev-table lua-mode-abbrev-table 708 :abbrev-table lua-mode-abbrev-table
670 :syntax-table lua-mode-syntax-table 709 :syntax-table lua-mode-syntax-table
671 :group 'lua 710 :group 'lua
672 (setq comint-prompt-regexp lua-prompt-regexp)
673
674
675 (setq-local font-lock-defaults '(lua-font-lock-keywords ;; keywords 711 (setq-local font-lock-defaults '(lua-font-lock-keywords ;; keywords
676 nil ;; keywords-only 712 nil ;; keywords-only
677 nil ;; case-fold 713 nil ;; case-fold
@@ -900,7 +936,7 @@ Return the amount the indentation changed by."
900 (back-to-indentation) 936 (back-to-indentation)
901 (if (lua-comment-or-string-p) 937 (if (lua-comment-or-string-p)
902 (setq indent (lua-calculate-string-or-comment-indentation)) ;; just restore point position 938 (setq indent (lua-calculate-string-or-comment-indentation)) ;; just restore point position
903 (setq indent (max 0 (lua-calculate-indentation nil)))) 939 (setq indent (max 0 (lua-calculate-indentation))))
904 940
905 (when (not (equal indent (current-column))) 941 (when (not (equal indent (current-column)))
906 (delete-region (line-beginning-position) (point)) 942 (delete-region (line-beginning-position) (point))
@@ -981,8 +1017,8 @@ ignored, nil otherwise."
981Each token information entry is of the form: 1017Each token information entry is of the form:
982 KEYWORD FORWARD-MATCH-REGEXP BACKWARDS-MATCH-REGEXP TOKEN-TYPE 1018 KEYWORD FORWARD-MATCH-REGEXP BACKWARDS-MATCH-REGEXP TOKEN-TYPE
983KEYWORD is the token. 1019KEYWORD is the token.
984FORWARD-MATCH-REGEXP is a regexp that matches all possble tokens when going forward. 1020FORWARD-MATCH-REGEXP is a regexp that matches all possible tokens when going forward.
985BACKWARDS-MATCH-REGEXP is a regexp that matches all possble tokens when going backwards. 1021BACKWARDS-MATCH-REGEXP is a regexp that matches all possible tokens when going backwards.
986TOKEN-TYPE determines where the token occurs on a statement. open indicates that the token appears at start, close indicates that it appears at end, middle indicates that it is a middle type token, and middle-or-open indicates that it can appear both as a middle or an open type.") 1022TOKEN-TYPE determines where the token occurs on a statement. open indicates that the token appears at start, close indicates that it appears at end, middle indicates that it is a middle type token, and middle-or-open indicates that it can appear both as a middle or an open type.")
987 1023
988(defconst lua-indentation-modifier-regexp 1024(defconst lua-indentation-modifier-regexp
@@ -1009,12 +1045,12 @@ TOKEN-TYPE determines where the token occurs on a statement. open indicates that
1009 "Returns the relevant match regexp from token info" 1045 "Returns the relevant match regexp from token info"
1010 (cond 1046 (cond
1011 ((eq direction 'forward) (cadr token-info)) 1047 ((eq direction 'forward) (cadr token-info))
1012 ((eq direction 'backward) (caddr token-info)) 1048 ((eq direction 'backward) (nth 2 token-info))
1013 (t nil))) 1049 (t nil)))
1014 1050
1015(defun lua-get-token-type (token-info) 1051(defun lua-get-token-type (token-info)
1016 "Returns the relevant match regexp from token info" 1052 "Returns the relevant match regexp from token info"
1017 (cadddr token-info)) 1053 (nth 3 token-info))
1018 1054
1019(defun lua-backwards-to-block-begin-or-end () 1055(defun lua-backwards-to-block-begin-or-end ()
1020 "Move backwards to nearest block begin or end. Returns nil if not successful." 1056 "Move backwards to nearest block begin or end. Returns nil if not successful."
@@ -1101,8 +1137,11 @@ DIRECTION has to be either 'forward or 'backward."
1101(defun lua-goto-matching-block-token (&optional parse-start direction) 1137(defun lua-goto-matching-block-token (&optional parse-start direction)
1102 "Find block begion/end token matching the one at the point. 1138 "Find block begion/end token matching the one at the point.
1103This function moves the point to the token that matches the one 1139This function moves the point to the token that matches the one
1104at the current point. Returns the point position of the first character of 1140at the current point. Returns the point position of the first character of
1105the matching token if successful, nil otherwise." 1141the matching token if successful, nil otherwise.
1142
1143Optional PARSE-START is a position to which the point should be moved first.
1144DIRECTION has to be 'forward or 'backward ('forward by default)."
1106 (if parse-start (goto-char parse-start)) 1145 (if parse-start (goto-char parse-start))
1107 (let ((case-fold-search nil)) 1146 (let ((case-fold-search nil))
1108 (if (looking-at lua-indentation-modifier-regexp) 1147 (if (looking-at lua-indentation-modifier-regexp)
@@ -1114,7 +1153,10 @@ the matching token if successful, nil otherwise."
1114(defun lua-goto-matching-block (&optional noreport) 1153(defun lua-goto-matching-block (&optional noreport)
1115 "Go to the keyword balancing the one under the point. 1154 "Go to the keyword balancing the one under the point.
1116If the point is on a keyword/brace that starts a block, go to the 1155If the point is on a keyword/brace that starts a block, go to the
1117matching keyword that ends the block, and vice versa." 1156matching keyword that ends the block, and vice versa.
1157
1158If optional NOREPORT is non-nil, it won't flag an error if there
1159is no block open/close open."
1118 (interactive) 1160 (interactive)
1119 ;; search backward to the beginning of the keyword if necessary 1161 ;; search backward to the beginning of the keyword if necessary
1120 (if (eq (char-syntax (following-char)) ?w) 1162 (if (eq (char-syntax (following-char)) ?w)
@@ -1129,7 +1171,7 @@ matching keyword that ends the block, and vice versa."
1129 "Move 1 line forward (back if BACK is non-nil) skipping blank lines. 1171 "Move 1 line forward (back if BACK is non-nil) skipping blank lines.
1130 1172
1131Moves point 1 line forward (or backward) skipping lines that contain 1173Moves point 1 line forward (or backward) skipping lines that contain
1132no Lua code besides comments. The point is put to the beginning of 1174no Lua code besides comments. The point is put to the beginning of
1133the line. 1175the line.
1134 1176
1135Returns final value of point as integer or nil if operation failed." 1177Returns final value of point as integer or nil if operation failed."
@@ -1160,7 +1202,7 @@ Returns final value of point as integer or nil if operation failed."
1160 t) 1202 t)
1161 "\\)" 1203 "\\)"
1162 "\\s *\\=")) 1204 "\\s *\\="))
1163 "Regexp that matches the ending of a line that needs continuation 1205 "Regexp that matches the ending of a line that needs continuation.
1164 1206
1165This regexp starts from eol and looks for a binary operator or an unclosed 1207This regexp starts from eol and looks for a binary operator or an unclosed
1166block intro (i.e. 'for' without 'do' or 'if' without 'then') followed by 1208block intro (i.e. 'for' without 'do' or 'if' without 'then') followed by
@@ -1179,15 +1221,15 @@ an optional whitespace till the end of the line.")
1179 t) 1221 t)
1180 "\\($\\|[^" lua-operator-class "]\\)" 1222 "\\($\\|[^" lua-operator-class "]\\)"
1181 "\\)")) 1223 "\\)"))
1182 "Regexp that matches a line that continues previous one 1224 "Regexp that matches a line that continues previous one.
1183 1225
1184This regexp means, starting from point there is an optional whitespace followed 1226This regexp means, starting from point there is an optional whitespace followed
1185by Lua binary operator. Lua is very liberal when it comes to continuation line, 1227by Lua binary operator. Lua is very liberal when it comes to continuation line,
1186so we're safe to assume that every line that starts with a binop continues 1228so we're safe to assume that every line that starts with a binop continues
1187previous one even though it looked like an end-of-statement.") 1229previous one even though it looked like an end-of-statement.")
1188 1230
1189(defun lua-last-token-continues-p () 1231(defun lua-last-token-continues-p ()
1190 "Returns true if the last token on this line is a continuation token." 1232 "Return non-nil if the last token on this line is a continuation token."
1191 (let ((line-begin (line-beginning-position)) 1233 (let ((line-begin (line-beginning-position))
1192 (line-end (line-end-position))) 1234 (line-end (line-end-position)))
1193 (save-excursion 1235 (save-excursion
@@ -1201,7 +1243,7 @@ previous one even though it looked like an end-of-statement.")
1201 (re-search-backward lua-cont-eol-regexp line-begin t)))) 1243 (re-search-backward lua-cont-eol-regexp line-begin t))))
1202 1244
1203(defun lua-first-token-continues-p () 1245(defun lua-first-token-continues-p ()
1204 "Returns true if the first token on this line is a continuation token." 1246 "Return non-nil if the first token on this line is a continuation token."
1205 (let ((line-end (line-end-position))) 1247 (let ((line-end (line-end-position)))
1206 (save-excursion 1248 (save-excursion
1207 (beginning-of-line) 1249 (beginning-of-line)
@@ -1219,14 +1261,15 @@ previous one even though it looked like an end-of-statement.")
1219 "\\_>\\)"))) 1261 "\\_>\\)")))
1220 1262
1221(defun lua-first-token-starts-block-p () 1263(defun lua-first-token-starts-block-p ()
1222 "Returns true if the first token on this line is a block starter token." 1264 "Return non-nil if the first token on this line is a block starter token."
1223 (let ((line-end (line-end-position))) 1265 (let ((line-end (line-end-position)))
1224 (save-excursion 1266 (save-excursion
1225 (beginning-of-line) 1267 (beginning-of-line)
1226 (re-search-forward (concat "\\s *" lua-block-starter-regexp) line-end t)))) 1268 (re-search-forward (concat "\\s *" lua-block-starter-regexp) line-end t))))
1227 1269
1228(defun lua-is-continuing-statement-p (&optional parse-start) 1270(defun lua-is-continuing-statement-p (&optional parse-start)
1229 "Return non-nil if the line continues a statement. 1271 "Return non-nil if the line at PARSE-START continues a statement.
1272
1230More specifically, return the point in the line that is continued. 1273More specifically, return the point in the line that is continued.
1231The criteria for a continuing statement are: 1274The criteria for a continuing statement are:
1232 1275
@@ -1246,8 +1289,10 @@ The criteria for a continuing statement are:
1246 (lua-last-token-continues-p))))))) 1289 (lua-last-token-continues-p)))))))
1247 1290
1248(defun lua-make-indentation-info-pair (found-token found-pos) 1291(defun lua-make-indentation-info-pair (found-token found-pos)
1249 "This is a helper function to lua-calculate-indentation-info. Don't 1292 "Create a pair from FOUND-TOKEN and FOUND-POS for indentation calculation.
1250use standalone." 1293
1294This is a helper function to lua-calculate-indentation-info.
1295Don't use standalone."
1251 (cond 1296 (cond
1252 ;; function is a bit tricky to indent right. They can appear in a lot ot 1297 ;; function is a bit tricky to indent right. They can appear in a lot ot
1253 ;; different contexts. Until I find a shortcut, I'll leave it with a simple 1298 ;; different contexts. Until I find a shortcut, I'll leave it with a simple
@@ -1321,17 +1366,17 @@ use standalone."
1321 (- lua-indent-level)))))) 1366 (- lua-indent-level))))))
1322 1367
1323(defun lua-add-indentation-info-pair (pair info) 1368(defun lua-add-indentation-info-pair (pair info)
1324 "Add the given indentation info pair to the list of indentation information. 1369 "Add the given indentation info PAIR to the list of indentation INFO.
1325This function has special case handling for two tokens: remove-matching, 1370This function has special case handling for two tokens: remove-matching,
1326and replace-matching. These two tokens are cleanup tokens that remove or 1371and replace-matching. These two tokens are cleanup tokens that remove or
1327alter the effect of a previously recorded indentation info. 1372alter the effect of a previously recorded indentation info.
1328 1373
1329When a remove-matching token is encountered, the last recorded info, i.e. 1374When a remove-matching token is encountered, the last recorded info, i.e.
1330the car of the list is removed. This is used to roll-back an indentation of a 1375the car of the list is removed. This is used to roll-back an indentation of a
1331block opening statement when it is closed. 1376block opening statement when it is closed.
1332 1377
1333When a replace-matching token is seen, the last recorded info is removed, 1378When a replace-matching token is seen, the last recorded info is removed,
1334and the cdr of the replace-matching info is added in its place. This is used 1379and the cdr of the replace-matching info is added in its place. This is used
1335when a middle-of the block (the only case is 'else') is seen on the same line 1380when a middle-of the block (the only case is 'else') is seen on the same line
1336the block is opened." 1381the block is opened."
1337 (cond 1382 (cond
@@ -1354,9 +1399,7 @@ Return list of indentation modifiers from point to BOUND."
1354 (while (lua-find-regexp 'forward lua-indentation-modifier-regexp 1399 (while (lua-find-regexp 'forward lua-indentation-modifier-regexp
1355 bound) 1400 bound)
1356 (let ((found-token (match-string 0)) 1401 (let ((found-token (match-string 0))
1357 (found-pos (match-beginning 0)) 1402 (found-pos (match-beginning 0)))
1358 (found-end (match-end 0))
1359 (data (match-data)))
1360 (setq indentation-info 1403 (setq indentation-info
1361 (lua-add-indentation-info-pair 1404 (lua-add-indentation-info-pair
1362 (lua-make-indentation-info-pair found-token found-pos) 1405 (lua-make-indentation-info-pair found-token found-pos)
@@ -1370,8 +1413,7 @@ The effect of each token can be either a shift relative to the current
1370indentation level, or indentation to some absolute column. This information 1413indentation level, or indentation to some absolute column. This information
1371is collected in a list of indentation info pairs, which denote absolute 1414is collected in a list of indentation info pairs, which denote absolute
1372and relative each, and the shift/column to indent to." 1415and relative each, and the shift/column to indent to."
1373 (let ((combined-line-end (line-end-position)) 1416 (let (indentation-info)
1374 indentation-info)
1375 1417
1376 (while (lua-is-continuing-statement-p) 1418 (while (lua-is-continuing-statement-p)
1377 (lua-forward-line-skip-blanks 'back)) 1419 (lua-forward-line-skip-blanks 'back))
@@ -1541,11 +1583,10 @@ If not, return nil."
1541 (current-indentation) 1583 (current-indentation)
1542 (current-column))))))) 1584 (current-column)))))))
1543 1585
1544(defun lua-calculate-indentation (&optional parse-start) 1586(defun lua-calculate-indentation ()
1545 "Return appropriate indentation for current line as Lua code." 1587 "Return appropriate indentation for current line as Lua code."
1546 (save-excursion 1588 (save-excursion
1547 (let ((continuing-p (lua-is-continuing-statement-p)) 1589 (let ((cur-line-begin-pos (line-beginning-position)))
1548 (cur-line-begin-pos (line-beginning-position)))
1549 (or 1590 (or
1550 ;; when calculating indentation, do the following: 1591 ;; when calculating indentation, do the following:
1551 ;; 1. check, if the line starts with indentation-modifier (open/close brace) 1592 ;; 1. check, if the line starts with indentation-modifier (open/close brace)
@@ -1689,7 +1730,8 @@ When called interactively, switch to the process buffer."
1689 (setq compilation-error-regexp-alist 1730 (setq compilation-error-regexp-alist
1690 (cons (list lua-traceback-line-re 1 2) 1731 (cons (list lua-traceback-line-re 1 2)
1691 compilation-error-regexp-alist)) 1732 compilation-error-regexp-alist))
1692 (compilation-shell-minor-mode 1)) 1733 (compilation-shell-minor-mode 1)
1734 (setq-local comint-prompt-regexp lua-prompt-regexp))
1693 1735
1694 ;; when called interactively, switch to process buffer 1736 ;; when called interactively, switch to process buffer
1695 (if (called-interactively-p 'any) 1737 (if (called-interactively-p 'any)
@@ -1856,13 +1898,10 @@ left out."
1856 "Forward to block end" 1898 "Forward to block end"
1857 (interactive "p") 1899 (interactive "p")
1858 ;; negative offsets not supported 1900 ;; negative offsets not supported
1859 (assert (or (not count) (>= count 0))) 1901 (cl-assert (or (not count) (>= count 0)))
1860 (save-match-data 1902 (save-match-data
1861 (let* ((count (or count 1)) 1903 (let ((count (or count 1))
1862 (block-start (mapcar 'car lua-sexp-alist)) 1904 (block-start (mapcar 'car lua-sexp-alist)))
1863 (block-end (mapcar 'cdr lua-sexp-alist))
1864 (block-regex (regexp-opt (append block-start block-end) 'words))
1865 current-exp)
1866 (while (> count 0) 1905 (while (> count 0)
1867 ;; skip whitespace 1906 ;; skip whitespace
1868 (skip-chars-forward " \t\n") 1907 (skip-chars-forward " \t\n")