emacs-diffs
[Top][All Lists]
Advanced

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

master 805d821: Avoid spamming view-mode-enter help message


From: Basil L. Contovounesios
Subject: master 805d821: Avoid spamming view-mode-enter help message
Date: Thu, 3 Dec 2020 10:22:37 -0500 (EST)

branch: master
commit 805d82197f050d1aba8fb796e604c55ce3d6333a
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Avoid spamming view-mode-enter help message
    
    By default, entering view-mode echoes a usage message.  This is
    particularly helpful with non-nil view-read-only, to notify the user
    that view-mode has been enabled.  It is less useful and more spammy,
    however, if view-mode is (possibly inadvertently) entered from some
    non-interactive code running in the background, such as when a major
    mode is enabled in a temporary buffer for text formatting
    purposes (bug#44629).
    
    * lisp/jsonrpc.el (jsonrpc-events-buffer, initialize-instance): Use
    buffer-read-only in place of read-only-mode for non-interactive use.
    * lisp/view.el (view-mode-enter): Inhibit help message if either
    view-inhibit-help-message is non-nil, or view-mode-enter was called
    from an interactive command.  Suggested by João Távora
    <joaotavora@gmail.com>.
---
 lisp/jsonrpc.el | 27 +++++++++++++--------------
 lisp/view.el    |  9 +++++++--
 2 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/lisp/jsonrpc.el b/lisp/jsonrpc.el
index 0b33940..1aebeae 100644
--- a/lisp/jsonrpc.el
+++ b/lisp/jsonrpc.el
@@ -138,18 +138,15 @@ immediately."
 
 (defun jsonrpc-events-buffer (connection)
   "Get or create JSONRPC events buffer for CONNECTION."
-  (let* ((probe (jsonrpc--events-buffer connection))
-         (buffer (or (and (buffer-live-p probe)
-                          probe)
-                     (let ((buffer (get-buffer-create
-                                    (format "*%s events*"
-                                            (jsonrpc-name connection)))))
-                       (with-current-buffer buffer
-                         (buffer-disable-undo)
-                         (read-only-mode t)
-                         (setf (jsonrpc--events-buffer connection) buffer))
-                       buffer))))
-    buffer))
+  (let ((probe (jsonrpc--events-buffer connection)))
+    (if (buffer-live-p probe)
+        probe
+      (with-current-buffer
+          (get-buffer-create (format "*%s events*" (jsonrpc-name connection)))
+        (buffer-disable-undo)
+        (setq buffer-read-only t)
+        (setf (jsonrpc--events-buffer connection)
+              (current-buffer))))))
 
 (defun jsonrpc-forget-pending-continuations (connection)
   "Stop waiting for responses from the current JSONRPC CONNECTION."
@@ -406,7 +403,7 @@ connection object, called when the process dies .")
           (ignore-errors (kill-buffer hidden-name))
           (rename-buffer hidden-name)
           (process-put proc 'jsonrpc-stderr (current-buffer))
-          (read-only-mode t))))
+          (setq buffer-read-only t))))
     (setf (jsonrpc--process conn) proc)
     (set-process-buffer proc (get-buffer-create (format " *%s output*" name)))
     (set-process-filter proc #'jsonrpc--process-filter)
@@ -414,7 +411,9 @@ connection object, called when the process dies .")
     (with-current-buffer (process-buffer proc)
       (buffer-disable-undo)
       (set-marker (process-mark proc) (point-min))
-      (let ((inhibit-read-only t)) (erase-buffer) (read-only-mode t)))
+      (let ((inhibit-read-only t))
+        (erase-buffer))
+      (setq buffer-read-only t))
     (process-put proc 'jsonrpc-connection conn)))
 
 (cl-defmethod jsonrpc-connection-send ((connection jsonrpc-process-connection)
diff --git a/lisp/view.el b/lisp/view.el
index 204e28c..6f576f8 100644
--- a/lisp/view.el
+++ b/lisp/view.el
@@ -88,7 +88,9 @@ the selected window is considered for restoring."
   :group 'view)
 
 (defcustom view-inhibit-help-message nil
-  "Non-nil inhibits the help message shown upon entering View mode."
+  "Non-nil inhibits the help message shown upon entering View mode.
+This setting takes effect only when View mode is entered via an
+interactive command; otherwise the help message is not shown."
   :type 'boolean
   :group 'view
   :version "22.1")
@@ -559,7 +561,10 @@ This function runs the normal hook `view-mode-hook'."
 
   (unless view-mode
     (view-mode 1)
-    (unless view-inhibit-help-message
+    (when (and (not view-inhibit-help-message)
+               ;; Avoid spamming the echo area if `view-mode' is entered
+               ;; non-interactively, e.g., in a temporary buffer (bug#44629).
+               this-command)
       (message "%s"
               (substitute-command-keys "\
 View mode: type \\[help-command] for help, \\[describe-mode] for commands, 
\\[View-quit] to quit.")))))



reply via email to

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