diff options
| author | Lars Ingebrigtsen | 2021-01-24 23:25:52 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2021-01-24 23:25:52 +0100 |
| commit | 9503f8d96cc89fa89bb68e183c79f0d9cb1b4d32 (patch) | |
| tree | 388dfdc0f72603de08b26a3df64151227e25c4a5 | |
| parent | 196be2bf12e1018335e4261cd4d6f25d6d16c415 (diff) | |
| download | emacs-9503f8d96cc89fa89bb68e183c79f0d9cb1b4d32.tar.gz emacs-9503f8d96cc89fa89bb68e183c79f0d9cb1b4d32.zip | |
Rewrite lisp--el-funcall-position-p to be inverse of the -not function
* lisp/emacs-lisp/lisp-mode.el (lisp--el-funcall-position-p):
Rename and rewrite to return the inverse value. Non-inverted
predicate functions are easier to reason about.
(lisp--el-non-funcall-position-p): Make obsolete.
| -rw-r--r-- | lisp/emacs-lisp/lisp-mode.el | 81 |
1 files changed, 43 insertions, 38 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el index 9c2b0dbe200..22435d59659 100644 --- a/lisp/emacs-lisp/lisp-mode.el +++ b/lisp/emacs-lisp/lisp-mode.el | |||
| @@ -201,47 +201,53 @@ | |||
| 201 | 201 | ||
| 202 | (defun lisp--el-non-funcall-position-p (pos) | 202 | (defun lisp--el-non-funcall-position-p (pos) |
| 203 | "Heuristically determine whether POS is an evaluated position." | 203 | "Heuristically determine whether POS is an evaluated position." |
| 204 | (declare (obsolete lisp--el-funcall-position-p "28.1")) | ||
| 205 | (not (lisp--el-funcall-position-p pos))) | ||
| 206 | |||
| 207 | (defun lisp--el-funcall-position-p (pos) | ||
| 208 | "Heuristically determine whether POS is an evaluated position." | ||
| 204 | (save-match-data | 209 | (save-match-data |
| 205 | (save-excursion | 210 | (save-excursion |
| 206 | (ignore-errors | 211 | (ignore-errors |
| 207 | (goto-char pos) | 212 | (goto-char pos) |
| 208 | ;; '(lambda ..) is not a funcall position, but #'(lambda ...) is. | 213 | ;; '(lambda ..) is not a funcall position, but #'(lambda ...) is. |
| 209 | (or (and (eql (char-before) ?\') | 214 | (if (eql (char-before) ?\') |
| 210 | (not (eql (char-before (1- (point))) ?#))) | 215 | (eql (char-before (1- (point))) ?#) |
| 211 | (let* ((ppss (syntax-ppss)) | 216 | (let* ((ppss (syntax-ppss)) |
| 212 | (paren-posns (nth 9 ppss)) | 217 | (paren-posns (nth 9 ppss)) |
| 213 | (parent | 218 | (parent |
| 214 | (when paren-posns | 219 | (when paren-posns |
| 215 | (goto-char (car (last paren-posns))) ;(up-list -1) | 220 | (goto-char (car (last paren-posns))) ;(up-list -1) |
| 216 | (cond | 221 | (cond |
| 217 | ((ignore-errors | 222 | ((ignore-errors |
| 218 | (and (eql (char-after) ?\() | 223 | (and (eql (char-after) ?\() |
| 219 | (when (cdr paren-posns) | 224 | (when (cdr paren-posns) |
| 220 | (goto-char (car (last paren-posns 2))) | 225 | (goto-char (car (last paren-posns 2))) |
| 221 | (looking-at "(\\_<let\\*?\\_>")))) | 226 | (looking-at "(\\_<let\\*?\\_>")))) |
| 222 | (goto-char (match-end 0)) | 227 | (goto-char (match-end 0)) |
| 223 | 'let) | 228 | 'let) |
| 224 | ((looking-at | 229 | ((looking-at |
| 225 | (rx "(" | 230 | (rx "(" |
| 226 | (group-n 1 (+ (or (syntax w) (syntax _)))) | 231 | (group-n 1 (+ (or (syntax w) (syntax _)))) |
| 227 | symbol-end)) | 232 | symbol-end)) |
| 228 | (prog1 (intern-soft (match-string-no-properties 1)) | 233 | (prog1 (intern-soft (match-string-no-properties 1)) |
| 229 | (goto-char (match-end 1)))))))) | 234 | (goto-char (match-end 1)))))))) |
| 230 | (or (eq parent 'declare) | 235 | (pcase parent |
| 231 | (and (eq parent 'let) | 236 | ('declare nil) |
| 232 | (progn | 237 | ('let |
| 233 | (forward-sexp 1) | 238 | (forward-sexp 1) |
| 234 | (< pos (point)))) | 239 | (>= pos (point))) |
| 235 | (and (eq parent 'condition-case) | 240 | ('condition-case |
| 236 | ;; If (cdr paren-posns), then we're in the BODY | 241 | ;; If (cdr paren-posns), then we're in the BODY |
| 237 | ;; of HANDLERS. | 242 | ;; of HANDLERS. |
| 238 | (and (not (cdr paren-posns)) | 243 | (or (cdr paren-posns) |
| 239 | (progn | 244 | (progn |
| 240 | (forward-sexp 1) | 245 | (forward-sexp 1) |
| 241 | ;; If we're in the second form, then we're in | 246 | ;; If we're in the second form, then we're in |
| 242 | ;; a funcall position. | 247 | ;; a funcall position. |
| 243 | (not (< (point) pos (progn (forward-sexp 1) | 248 | (< (point) pos (progn (forward-sexp 1) |
| 244 | (point)))))))))))))) | 249 | (point)))))) |
| 250 | (_ t)))))))) | ||
| 245 | 251 | ||
| 246 | (defun lisp--el-match-keyword (limit) | 252 | (defun lisp--el-match-keyword (limit) |
| 247 | ;; FIXME: Move to elisp-mode.el. | 253 | ;; FIXME: Move to elisp-mode.el. |
| @@ -254,8 +260,7 @@ | |||
| 254 | (when (or (special-form-p sym) | 260 | (when (or (special-form-p sym) |
| 255 | (and (macrop sym) | 261 | (and (macrop sym) |
| 256 | (not (get sym 'no-font-lock-keyword)) | 262 | (not (get sym 'no-font-lock-keyword)) |
| 257 | (not (lisp--el-non-funcall-position-p | 263 | (lisp--el-funcall-position-p (match-beginning 0)))) |
| 258 | (match-beginning 0))))) | ||
| 259 | (throw 'found t)))))) | 264 | (throw 'found t)))))) |
| 260 | 265 | ||
| 261 | (defmacro let-when-compile (bindings &rest body) | 266 | (defmacro let-when-compile (bindings &rest body) |