aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjohn muhl2025-03-20 14:43:38 -0500
committerPo Lu2025-08-25 09:59:04 +0800
commit142f1b2a9bd2f3ef713d5da13c4166605f18c084 (patch)
treed2d7ee581bb715e04bec237f8fa1fb7b38aae998
parentee36cac7bab0e14011ecbc781ec04f08f0609ee1 (diff)
downloademacs-142f1b2a9bd2f3ef713d5da13c4166605f18c084.tar.gz
emacs-142f1b2a9bd2f3ef713d5da13c4166605f18c084.zip
Replace 1-armed 'if' with 'when' in 'lua-mode'
* lisp/progmodes/lua-mode.el (lua--customize-set-prefix-key) (lua-electric-match, lua-prefix-key-update-bindings) (lua-indent-line, lua-find-matching-token-word) (lua-goto-matching-block-token, lua-last-token-continues-p) (lua-is-continuing-statement-p) (lua--goto-line-beginning-rightmost-closer, lua-start-process) (lua-prompt-line): Replace.
-rw-r--r--lisp/progmodes/lua-mode.el126
1 files changed, 63 insertions, 63 deletions
diff --git a/lisp/progmodes/lua-mode.el b/lisp/progmodes/lua-mode.el
index 224fc4aa728..d2d9dba7731 100644
--- a/lisp/progmodes/lua-mode.el
+++ b/lisp/progmodes/lua-mode.el
@@ -217,12 +217,12 @@ Should be a list of strings."
217 217
218(defun lua--customize-set-prefix-key (prefix-key-sym prefix-key-val) 218(defun lua--customize-set-prefix-key (prefix-key-sym prefix-key-val)
219 (cl-assert (eq prefix-key-sym 'lua-prefix-key)) 219 (cl-assert (eq prefix-key-sym 'lua-prefix-key))
220 (set prefix-key-sym (if (and prefix-key-val (> (length prefix-key-val) 0)) 220 (set prefix-key-sym (when (and prefix-key-val (> (length prefix-key-val) 0))
221 ;; read-kbd-macro returns a string or a vector 221 ;; read-kbd-macro returns a string or a vector
222 ;; in both cases (elt x 0) is ok 222 ;; in both cases (elt x 0) is ok
223 (elt (read-kbd-macro prefix-key-val) 0))) 223 (elt (read-kbd-macro prefix-key-val) 0)))
224 (if (fboundp 'lua-prefix-key-update-bindings) 224 (when (fboundp 'lua-prefix-key-update-bindings)
225 (lua-prefix-key-update-bindings))) 225 (lua-prefix-key-update-bindings)))
226 226
227(defcustom lua-prefix-key "\C-c" 227(defcustom lua-prefix-key "\C-c"
228 "Prefix for all lua-mode commands." 228 "Prefix for all lua-mode commands."
@@ -574,8 +574,8 @@ index of respective Lua reference manuals.")
574 (interactive "P") 574 (interactive "P")
575 (let (blink-paren-function) 575 (let (blink-paren-function)
576 (self-insert-command (prefix-numeric-value arg))) 576 (self-insert-command (prefix-numeric-value arg)))
577 (if lua-electric-flag 577 (when lua-electric-flag
578 (lua-indent-line)) 578 (lua-indent-line))
579 (blink-matching-open)) 579 (blink-matching-open))
580 580
581;; private functions 581;; private functions
@@ -608,8 +608,8 @@ index of respective Lua reference manuals.")
608 ;; if prefix-map is a parent, delete the parent 608 ;; if prefix-map is a parent, delete the parent
609 (set-keymap-parent lua-mode-map nil) 609 (set-keymap-parent lua-mode-map nil)
610 ;; otherwise, look for it among children 610 ;; otherwise, look for it among children
611 (if (setq old-cons (rassoc lua-prefix-mode-map lua-mode-map)) 611 (when (setq old-cons (rassoc lua-prefix-mode-map lua-mode-map))
612 (delq old-cons lua-mode-map))) 612 (delq old-cons lua-mode-map)))
613 613
614 (if (null lua-prefix-key) 614 (if (null lua-prefix-key)
615 (set-keymap-parent lua-mode-map lua-prefix-mode-map) 615 (set-keymap-parent lua-mode-map lua-prefix-mode-map)
@@ -754,8 +754,8 @@ Return the amount the indentation changed by."
754 754
755 ;; If initial point was within line's indentation, 755 ;; If initial point was within line's indentation,
756 ;; position after the indentation. Else stay at same point in text. 756 ;; position after the indentation. Else stay at same point in text.
757 (if (> (- (point-max) pos) (point)) 757 (when (> (- (point-max) pos) (point)) ; 03e991
758 (goto-char (- (point-max) pos))) 758 (goto-char (- (point-max) pos))) ; 03e991
759 759
760 indent)) 760 indent))
761 761
@@ -935,18 +935,18 @@ DIRECTION has to be either \\='forward or \\='backward."
935 ;; if we are searching forward from the token at the current point 935 ;; if we are searching forward from the token at the current point
936 ;; (i.e. for a closing token), need to step one character forward 936 ;; (i.e. for a closing token), need to step one character forward
937 ;; first, or the regexp will match the opening token. 937 ;; first, or the regexp will match the opening token.
938 (if (eq search-direction 'forward) (forward-char 1)) 938 (when (eq search-direction 'forward) (forward-char 1))
939 (catch 'found 939 (catch 'found ; 03e991
940 ;; If we are attempting to find a matching token for a terminating token 940 ;; If we are attempting to find a matching token for a terminating token
941 ;; (i.e. a token that starts a statement when searching back, or a token 941 ;; (i.e. a token that starts a statement when searching back, or a token
942 ;; that ends a statement when searching forward), then we don't need to look 942 ;; that ends a statement when searching forward), then we don't need to look
943 ;; any further. 943 ;; any further.
944 (if (or (and (eq search-direction 'forward) 944 (when (or (and (eq search-direction 'forward)
945 (eq match-type 'close)) 945 (eq match-type 'close))
946 (and (eq search-direction 'backward) 946 (and (eq search-direction 'backward)
947 (eq match-type 'open))) 947 (eq match-type 'open)))
948 (throw 'found nil)) 948 (throw 'found nil))
949 (while (lua-find-regexp search-direction lua-indentation-modifier-regexp) 949 (while (lua-find-regexp search-direction lua-indentation-modifier-regexp) ; 03e991
950 ;; have we found a valid matching token? 950 ;; have we found a valid matching token?
951 (let ((found-token (match-string 0)) 951 (let ((found-token (match-string 0))
952 (found-pos (match-beginning 0))) 952 (found-pos (match-beginning 0)))
@@ -958,18 +958,18 @@ DIRECTION has to be either \\='forward or \\='backward."
958 ;; token; likewise, if we were looking for a block end token, 958 ;; token; likewise, if we were looking for a block end token,
959 ;; found-token must be a block begin token, otherwise there 959 ;; found-token must be a block begin token, otherwise there
960 ;; is a grammatical error in the code. 960 ;; is a grammatical error in the code.
961 (if (not (and 961 (when (not (and ; 03e991
962 (or (eq match-type 'middle) 962 (or (eq match-type 'middle)
963 (eq found-type 'middle) 963 (eq found-type 'middle)
964 (eq match-type 'middle-or-open) 964 (eq match-type 'middle-or-open)
965 (eq found-type 'middle-or-open) 965 (eq found-type 'middle-or-open)
966 (eq match-type found-type)) 966 (eq match-type found-type))
967 (goto-char found-pos) 967 (goto-char found-pos)
968 (lua-find-matching-token-word found-token 968 (lua-find-matching-token-word found-token
969 search-direction))) 969 search-direction)))
970 (when maybe-found-pos 970 (when maybe-found-pos
971 (goto-char maybe-found-pos) 971 (goto-char maybe-found-pos)
972 (throw 'found maybe-found-pos))) 972 (throw 'found maybe-found-pos)))
973 ;; yes. 973 ;; yes.
974 ;; if it is a not a middle kind, report the location 974 ;; if it is a not a middle kind, report the location
975 (when (not (or (eq found-type 'middle) 975 (when (not (or (eq found-type 'middle)
@@ -995,13 +995,13 @@ the matching token if successful, nil otherwise.
995 995
996Optional PARSE-START is a position to which the point should be moved first. 996Optional PARSE-START is a position to which the point should be moved first.
997DIRECTION has to be \\='forward or \\='backward (\\='forward by default)." 997DIRECTION has to be \\='forward or \\='backward (\\='forward by default)."
998 (if parse-start (goto-char parse-start)) 998 (when parse-start (goto-char parse-start))
999 (let ((case-fold-search nil)) 999 (let ((case-fold-search nil))
1000 (if (looking-at lua-indentation-modifier-regexp) 1000 (when (looking-at lua-indentation-modifier-regexp) ; 03e991
1001 (let ((position (lua-find-matching-token-word (match-string 0) 1001 (let ((position (lua-find-matching-token-word (match-string 0) ; 03e991
1002 direction))) 1002 direction)))
1003 (and position 1003 (and position ; 03e991
1004 (goto-char position)))))) 1004 (goto-char position)))))) ; 03e991
1005 1005
1006(defun lua-goto-matching-block (&optional noreport) 1006(defun lua-goto-matching-block (&optional noreport)
1007 "Go to the keyword balancing the one under the point. 1007 "Go to the keyword balancing the one under the point.
@@ -1135,25 +1135,25 @@ previous one even though it looked like an end-of-statement.")
1135 (setq return-value (and (re-search-backward lua-cont-eol-regexp line-begin t) 1135 (setq return-value (and (re-search-backward lua-cont-eol-regexp line-begin t)
1136 (or (match-beginning 1) 1136 (or (match-beginning 1)
1137 (match-beginning 2)))) 1137 (match-beginning 2))))
1138 (if (and return-value 1138 (when (and return-value
1139 (string-equal (match-string-no-properties 0) "return")) 1139 (string-equal (match-string-no-properties 0) "return"))
1140 ;; "return" keyword is ambiguous and depends on next token 1140 ;; "return" keyword is ambiguous and depends on next token
1141 (unless (save-excursion 1141 (unless (save-excursion
1142 (goto-char (match-end 0)) 1142 (goto-char (match-end 0))
1143 (forward-comment (point-max)) 1143 (forward-comment (point-max))
1144 (and 1144 (and
1145 ;; Not continuing: at end of file 1145 ;; Not continuing: at end of file
1146 (not (eobp)) 1146 (not (eobp))
1147 (or 1147 (or
1148 ;; "function" keyword: it is a continuation, e.g. 1148 ;; "function" keyword: it is a continuation, e.g.
1149 ;; 1149 ;;
1150 ;; return 1150 ;; return
1151 ;; function() return 123 end 1151 ;; function() return 123 end
1152 ;; 1152 ;;
1153 (looking-at (lua-rx (symbol "function"))) 1153 (looking-at (lua-rx (symbol "function")))
1154 ;; Looking at semicolon or any other keyword: not continuation 1154 ;; Looking at semicolon or any other keyword: not continuation
1155 (not (looking-at (lua-rx (or ";" lua-keyword))))))) 1155 (not (looking-at (lua-rx (or ";" lua-keyword)))))))
1156 (setq return-value nil))) 1156 (setq return-value nil)))
1157 return-value))) 1157 return-value)))
1158 1158
1159(defun lua-first-token-continues-p () 1159(defun lua-first-token-continues-p ()
@@ -1261,7 +1261,7 @@ This true is when the line :
1261* starts with a 1+ block-closer tokens, an top-most block opener is on a continuation line 1261* starts with a 1+ block-closer tokens, an top-most block opener is on a continuation line
1262" 1262"
1263 (save-excursion 1263 (save-excursion
1264 (if parse-start (goto-char parse-start)) 1264 (when parse-start (goto-char parse-start)) ; 03e991
1265 1265
1266 ;; If line starts with a series of closer tokens, whether or not the line 1266 ;; If line starts with a series of closer tokens, whether or not the line
1267 ;; is a continuation line is decided by the opener line, e.g. 1267 ;; is a continuation line is decided by the opener line, e.g.
@@ -1594,7 +1594,7 @@ left-shifter expression. "
1594(defun lua--goto-line-beginning-rightmost-closer (&optional parse-start) 1594(defun lua--goto-line-beginning-rightmost-closer (&optional parse-start)
1595 (let (case-fold-search pos line-end-pos return-val) 1595 (let (case-fold-search pos line-end-pos return-val)
1596 (save-excursion 1596 (save-excursion
1597 (if parse-start (goto-char parse-start)) 1597 (when parse-start (goto-char parse-start))
1598 (setq line-end-pos (line-end-position)) 1598 (setq line-end-pos (line-end-position))
1599 (back-to-indentation) 1599 (back-to-indentation)
1600 (unless (lua-comment-or-string-p) 1600 (unless (lua-comment-or-string-p)
@@ -1805,8 +1805,8 @@ When called interactively, switch to the process buffer."
1805 (lua-send-string lua-process-init-code))) 1805 (lua-send-string lua-process-init-code)))
1806 1806
1807 ;; when called interactively, switch to process buffer 1807 ;; when called interactively, switch to process buffer
1808 (if (called-interactively-p 'any) 1808 (when (called-interactively-p 'any)
1809 (switch-to-buffer lua-process-buffer))) 1809 (switch-to-buffer lua-process-buffer)))
1810 1810
1811(defun lua-get-create-process () 1811(defun lua-get-create-process ()
1812 "Return active Lua process creating one if necessary." 1812 "Return active Lua process creating one if necessary."
@@ -1902,8 +1902,8 @@ Otherwise, return START."
1902 (save-excursion 1902 (save-excursion
1903 (save-match-data 1903 (save-match-data
1904 (forward-line 0) 1904 (forward-line 0)
1905 (if (looking-at comint-prompt-regexp) 1905 (when (looking-at comint-prompt-regexp)
1906 (match-end 0))))) 1906 (match-end 0)))))
1907 1907
1908(defun lua-send-lua-region () 1908(defun lua-send-lua-region ()
1909 "Send preset Lua region to Lua process." 1909 "Send preset Lua region to Lua process."