From 03e75b0f5f279f166db895ba4245bda6fa2f1ffe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Mon, 19 Dec 2022 17:42:33 +0100 Subject: called-interactively-p: cut broken comparison * lisp/subr.el (called-interactively-p): Remove attempt to detect `byte-code` frames; it wasn't done right but also does not seem to be necessary. Adjust comment that was out of date. --- lisp/subr.el | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index e142eaa8104..4fa63a1f3cd 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -6084,14 +6084,8 @@ command is called from a keyboard macro?" ;; Skip special forms (from non-compiled code). (and frame (null (car frame))) ;; Skip also `interactive-p' (because we don't want to know if - ;; interactive-p was called interactively but if it's caller was) - ;; and `byte-code' (idem; this appears in subexpressions of things - ;; like condition-case, which are wrapped in a separate bytecode - ;; chunk). - ;; FIXME: For lexical-binding code, this is much worse, - ;; because the frames look like "byte-code -> funcall -> #[...]", - ;; which is not a reliable signature. - (memq (nth 1 frame) '(interactive-p 'byte-code)) + ;; interactive-p was called interactively but if it's caller was). + (eq (nth 1 frame) 'interactive-p) ;; Skip package-specific stack-frames. (let ((skip (run-hook-with-args-until-success 'called-interactively-p-functions -- cgit v1.2.1 From eccb813a943f4b6898cbe241c636c2ba5e63d271 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 23 Dec 2022 16:41:08 +0200 Subject: Fix "C-h k" in recursive minibuffers * lisp/subr.el (event--posn-at-point): Leave POSN alone if it doesn't have at least 6 members. This follows more faithfully what 'event-start' and 'event-end' did before they started using this function, see commit c1cead89f5f. Call posn-at-point with the minibuffer-window when in the minibuffer. (Bug#60252) --- lisp/subr.el | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index e142eaa8104..a5e66de27de 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -1576,16 +1576,18 @@ in the current Emacs session, then this function may return nil." ;; Use `window-point' for the case when the current buffer ;; is temporarily switched to some other buffer (bug#50256) (let* ((pos (window-point)) - (posn (posn-at-point pos))) - (if (null posn) ;; `pos' is "out of sight". - (list (selected-window) pos '(0 . 0) 0) - ;; If `pos' is inside a chunk of text hidden by an `invisible' - ;; or `display' property, `posn-at-point' returns the position - ;; that *is* visible, whereas `event--posn-at-point' is used - ;; when we have a keyboard event, whose position is `point' even - ;; if that position is invisible. - (setf (nth 5 posn) pos) - posn))) + (posn (posn-at-point pos (if (minibufferp (current-buffer)) + (minibuffer-window))))) + (cond ((null posn) ;; `pos' is "out of sight". + (setq posn (list (selected-window) pos '(0 . 0) 0))) + ;; If `pos' is inside a chunk of text hidden by an `invisible' + ;; or `display' property, `posn-at-point' returns the position + ;; that *is* visible, whereas `event--posn-at-point' is used + ;; when we have a keyboard event, whose position is `point' even + ;; if that position is invisible. + ((> (length posn) 5) + (setf (nth 5 posn) pos))) + posn)) (defun event-start (event) "Return the starting position of EVENT. -- cgit v1.2.1 From 082fc6e3088354f16ab8293725cc727a9855359b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Sun, 25 Dec 2022 15:32:06 +0100 Subject: Fix 'json-available-p' on MS-Windows * src/json.c (json_available_p, ensure_json_available) (Fjson__available_p): New functions. (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): Use ensure_json_available. (syms_of_json): Defsubr json--available-p. * lisp/subr.el (json-available-p): Rewrite. --- lisp/subr.el | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index a5e66de27de..701c26f8cd8 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -6911,11 +6911,11 @@ sentence (see Info node `(elisp) Documentation Tips')." (defun json-available-p () "Return non-nil if Emacs has libjansson support." - (and (fboundp 'json-serialize) - (condition-case nil - (json-serialize t) - (:success t) - (json-unavailable nil)))) + (declare (side-effect-free error-free)) + (and (eval-when-compile (fboundp 'json-serialize)) + ;; If `json--available-p' is present, we need to call it at run-time. + (or (not (eval-when-compile (fboundp 'json--available-p))) + (json--available-p)))) (defun ensure-list (object) "Return OBJECT as a list. -- cgit v1.2.1 From 26b2ec7cb8c81db7d8705cb87579b325901ed303 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 26 Dec 2022 15:26:48 +0200 Subject: Simplify last change (bug#60311) * src/json.c (json_available_p): Use original code. Always return true for !WINDOWSNT. (ensure_json_available): Now defined only on WINDOWSNT. (Fjson_serialize, Fjson_insert, Fjson_parse_string) (Fjson_parse_buffer): Call ensure_json_available only on WINDOWSNT. * lisp/subr.el (json-available-p): Simplify. --- lisp/subr.el | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index 701c26f8cd8..2fcdc7addf1 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -6911,11 +6911,8 @@ sentence (see Info node `(elisp) Documentation Tips')." (defun json-available-p () "Return non-nil if Emacs has libjansson support." - (declare (side-effect-free error-free)) - (and (eval-when-compile (fboundp 'json-serialize)) - ;; If `json--available-p' is present, we need to call it at run-time. - (or (not (eval-when-compile (fboundp 'json--available-p))) - (json--available-p)))) + (and (fboundp 'json--available-p) + (json--available-p))) (defun ensure-list (object) "Return OBJECT as a list. -- cgit v1.2.1 From 1a88a28ace24c8b4fb1e4780948b50dd37ada539 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Wed, 28 Dec 2022 13:10:35 +0100 Subject: * lisp/subr.el (with-demoted-errors): Better message and location. --- lisp/subr.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index d24169276a5..f0081de0619 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4850,6 +4850,7 @@ but that should be robust in the unexpected case that an error is signaled." (declare (debug t) (indent 1)) (let* ((err (make-symbol "err")) (orig-body body) + (orig-format format) (format (if (and (stringp format) body) format (prog1 "Error: %S" (if format (push format body))))) @@ -4860,7 +4861,9 @@ but that should be robust in the unexpected case that an error is signaled." (if (eq orig-body body) exp ;; The use without `format' is obsolete, let's warn when we bump ;; into any such remaining uses. - (macroexp-warn-and-return "Missing format argument" exp nil nil format)))) + (macroexp-warn-and-return + "Missing format argument in `with-demote-errors'" exp nil nil + orig-format)))) (defmacro combine-after-change-calls (&rest body) "Execute BODY, but don't call the after-change functions till the end. -- cgit v1.2.1 From 1480865e641b06d570f5ab56011f8e3e5481da7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Wed, 28 Dec 2022 14:40:19 +0100 Subject: Warn about `ignore-error` with quoted condition argument * lisp/subr.el (ignore-error): Clarify condition argument in doc string and add warning. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-warn-quoted-condition): New test. --- lisp/subr.el | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index f0081de0619..5e8f3c82a2a 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -380,9 +380,18 @@ without silencing all errors." "Execute BODY; if the error CONDITION occurs, return nil. Otherwise, return result of last form in BODY. -CONDITION can also be a list of error conditions." +CONDITION can also be a list of error conditions. +The CONDITION argument is not evaluated. Do not quote it." (declare (debug t) (indent 1)) - `(condition-case nil (progn ,@body) (,condition nil))) + (if (and (eq (car-safe condition) 'quote) + (cdr condition) (null (cddr condition))) + (macroexp-warn-and-return + (format "`ignore-error' condition argument should not be quoted: %S" + condition) + `(condition-case nil (progn ,@body) (,(cadr condition) nil)) + nil t condition) + `(condition-case nil (progn ,@body) (,condition nil)))) + ;;;; Basic Lisp functions. -- cgit v1.2.1 From 7c63b632e4e2241a28f08015cc981a72e18d7867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= Date: Thu, 29 Dec 2022 13:01:47 +0100 Subject: Add empty-body warning for when, unless etc Warn about code like (when SOME-CONDITION) because these may indicate bugs. Warnings currently apply to `when`, `unless`, `ignore-error`, `with-suppressed-warnings` and (as before) `let` and `let*`. * lisp/emacs-lisp/byte-run.el (with-suppressed-warnings): Update doc string. * lisp/emacs-lisp/bytecomp.el: (byte-compile-warning-types) (byte-compile-warnings): Add empty-body. (byte-compile-initial-macro-environment): Add empty-body warning for with-suppressed-warnings. * lisp/emacs-lisp/macroexp.el (macroexp--expand-all): Use the empty-body category for let and let*. * lisp/subr.el (when, unless, ignore-error): Add empty-body warning. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-test--with-suppressed-warnings): Add test cases. --- lisp/subr.el | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'lisp/subr.el') diff --git a/lisp/subr.el b/lisp/subr.el index 5e8f3c82a2a..69e6198e1bd 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -280,14 +280,20 @@ change the list." When COND yields non-nil, eval BODY forms sequentially and return value of last one, or nil if there are none." (declare (indent 1) (debug t)) - (list 'if cond (cons 'progn body))) + (if body + (list 'if cond (cons 'progn body)) + (macroexp-warn-and-return "`when' with empty body" + cond '(empty-body when) t))) (defmacro unless (cond &rest body) "If COND yields nil, do BODY, else return nil. When COND yields nil, eval BODY forms sequentially and return value of last one, or nil if there are none." (declare (indent 1) (debug t)) - (cons 'if (cons cond (cons nil body)))) + (if body + (cons 'if (cons cond (cons nil body))) + (macroexp-warn-and-return "`unless' with empty body" + cond '(empty-body unless) t))) (defsubst subr-primitive-p (object) "Return t if OBJECT is a built-in primitive function." @@ -383,14 +389,19 @@ Otherwise, return result of last form in BODY. CONDITION can also be a list of error conditions. The CONDITION argument is not evaluated. Do not quote it." (declare (debug t) (indent 1)) - (if (and (eq (car-safe condition) 'quote) - (cdr condition) (null (cddr condition))) - (macroexp-warn-and-return - (format "`ignore-error' condition argument should not be quoted: %S" - condition) - `(condition-case nil (progn ,@body) (,(cadr condition) nil)) - nil t condition) - `(condition-case nil (progn ,@body) (,condition nil)))) + (cond + ((and (eq (car-safe condition) 'quote) + (cdr condition) (null (cddr condition))) + (macroexp-warn-and-return + (format "`ignore-error' condition argument should not be quoted: %S" + condition) + `(condition-case nil (progn ,@body) (,(cadr condition) nil)) + nil t condition)) + (body + `(condition-case nil (progn ,@body) (,condition nil))) + (t + (macroexp-warn-and-return "`ignore-error' with empty body" + nil '(empty-body ignore-error) t condition)))) ;;;; Basic Lisp functions. -- cgit v1.2.1