emacs-devel
[Top][All Lists]
Advanced

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

Insert `help-char' when pressed twice.


From: Matthew Leach
Subject: Insert `help-char' when pressed twice.
Date: Tue, 14 Apr 2015 14:35:19 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Hi all,

I recently came across a small annoyance when I was working in sh-mode.
If we open a temporary .sh file and attempts to insert a conditional
with C-TAB, we are presented with a minibuffer prompt to insert the
conditional.  Now, Suppose we wanted to insert `[ $? -ne 0 ]'.  This is
next to impossible as pressing `?' will constantly open the temporary
help buffer.

Attached is a patch to help remedy this.  If the help message is already
visible to the user, insert the `help-char' that the user pressed into
the minibuffer.

Any feedback would be appreciated.
-- 
Matt

>From 4b42e24835a76d625f865c67622143c0f58c55a4 Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Tue, 14 Apr 2015 14:17:08 +0100
Subject: [PATCH] Insert `help-char' if the help buffer is already shown

* src/keyboard.c (read_char): Call `help-form-show' with the character
  that caused the function to be called.
* lisp/help.el (help-form-show): If the temporary help window is
  already visible when called, insert the `help-char' that the user
  pressed.
---
 lisp/help.el   | 15 +++++++++++----
 src/keyboard.c |  2 +-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lisp/help.el b/lisp/help.el
index fb1719a..cf134d5 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -1339,11 +1339,18 @@ the help window if the current value of the user option
 
 ;; Called from C, on encountering `help-char' when reading a char.
 ;; Don't print to *Help*; that would clobber Help history.
-(defun help-form-show ()
-  "Display the output of a non-nil `help-form'."
-  (let ((msg (eval help-form)))
+(defun help-form-show (char)
+  "Display the output of a non-nil `help-form'.  If called while
+`help-form' is being displayed, insert the help char."
+  (let* ((msg (eval help-form))
+         (tmp-help-buf-name " *Char Help*")
+         (tmp-help-buf (get-buffer tmp-help-buf-name))
+         (should-insert-char (and tmp-help-buf
+                                  (get-buffer-window tmp-help-buf))))
+    (when should-insert-char
+      (insert-char char))
     (if (stringp msg)
-       (with-output-to-temp-buffer " *Char Help*"
+       (with-output-to-temp-buffer tmp-help-buf-name
          (princ msg)))))
 
 
diff --git a/src/keyboard.c b/src/keyboard.c
index 068a47c..08c74e1 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3188,7 +3188,7 @@ read_char (int commandflag, Lisp_Object map,
        = Fcons (Fcurrent_window_configuration (Qnil),
                 help_form_saved_window_configs);
       record_unwind_protect_void (read_char_help_form_unwind);
-      call0 (Qhelp_form_show);
+      call1 (Qhelp_form_show, c);
 
       cancel_echoing ();
       do
-- 
2.3.5


reply via email to

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