emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/git-commit 2bc6aaf527 02/11: Avoid using called-interactiv


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 2bc6aaf527 02/11: Avoid using called-interactively-p
Date: Mon, 13 Mar 2023 14:00:24 -0400 (EDT)

branch: elpa/git-commit
commit 2bc6aaf5277e762c1a71ee36d1e2c2ded17a20dd
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Avoid using called-interactively-p
    
    This function is very brittle, as described in its docstring.
---
 lisp/magit-blame.el   |  4 +++-
 lisp/magit-section.el | 13 +++++++------
 lisp/magit-wip.el     |  9 ++-------
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/lisp/magit-blame.el b/lisp/magit-blame.el
index 1b9ea262dc..9048c71a05 100644
--- a/lisp/magit-blame.el
+++ b/lisp/magit-blame.el
@@ -319,8 +319,10 @@ in `magit-blame-read-only-mode-map' instead."
 (define-minor-mode magit-blame-mode
   "Display blame information inline."
   :lighter magit-blame-mode-lighter
+  :interactive nil
   (cond (magit-blame-mode
-         (when (called-interactively-p 'any)
+         (unless arg
+           ;; Emacs < 28.1 doesn't support `:interactive'.
            (setq magit-blame-mode nil)
            (user-error
             (concat "Don't call `magit-blame-mode' directly; "
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index a955603e69..3844e13780 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -1064,11 +1064,12 @@ silently ignored."
 
 ;;;; Auxiliary
 
-(defun magit-describe-section-briefly (section &optional ident)
+(defun magit-describe-section-briefly (section &optional ident interactive)
   "Show information about the section at point.
 With a prefix argument show the section identity instead of the
-section lineage.  This command is intended for debugging purposes."
-  (interactive (list (magit-current-section) current-prefix-arg))
+section lineage.  This command is intended for debugging purposes.
+\n(fn SECTION &optional IDENT)"
+  (interactive (list (magit-current-section) current-prefix-arg t))
   (let ((str (format "#<%s %S %S %s-%s%s>"
                      (eieio-object-class section)
                      (let ((val (oref section value)))
@@ -1089,9 +1090,9 @@ section lineage.  This command is intended for debugging 
purposes."
                        "")
                      (and-let* ((m (oref section end)))
                        (marker-position m)))))
-    (if (called-interactively-p 'any)
-        (message "%s" str)
-      str)))
+    (when interactive
+      (message "%s" str))
+    str))
 
 (cl-defmethod cl-print-object ((section magit-section) stream)
   "Print `magit-describe-section' result of SECTION."
diff --git a/lisp/magit-wip.el b/lisp/magit-wip.el
index cf494e1c33..6f9642c996 100644
--- a/lisp/magit-wip.el
+++ b/lisp/magit-wip.el
@@ -159,18 +159,13 @@ variant `magit-wip-after-save-mode'."
 
 Also see `magit-wip-after-save-mode' which calls this function
 automatically whenever a buffer visiting a tracked file is saved."
-  (interactive)
+  (interactive (list "wip-save %s after save"))
   (--when-let (magit-wip-get-ref)
     (magit-with-toplevel
       (let ((file (file-relative-name buffer-file-name)))
         (magit-wip-commit-worktree
          it (list file)
-         (format (cond (msg)
-                       ((called-interactively-p 'any)
-                        "wip-save %s after save")
-                       (t
-                        "autosave %s after save"))
-                 file))))))
+         (format (or msg "autosave %s after save") file))))))
 
 ;;;###autoload
 (define-minor-mode magit-wip-after-apply-mode



reply via email to

[Prev in Thread] Current Thread [Next in Thread]