all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Insert `help-char' when pressed twice.
@ 2015-04-14 13:35 Matthew Leach
  2015-04-14 16:52 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Leach @ 2015-04-14 13:35 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 580 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Insert-help-char-if-the-help-buffer-is-already-shown.patch --]
[-- Type: text/x-diff, Size: 2080 bytes --]

From 4b42e24835a76d625f865c67622143c0f58c55a4 Mon Sep 17 00:00:00 2001
From: Matthew Leach <matthew@mattleach.net>
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)))))
 
 \f
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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Insert `help-char' when pressed twice.
  2015-04-14 16:52 ` Stefan Monnier
@ 2015-04-14 16:43   ` Matthew Leach
  0 siblings, 0 replies; 3+ messages in thread
From: Matthew Leach @ 2015-04-14 16:43 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> conditional.  Now, Suppose we wanted to insert `[ $? -ne 0 ]'.  This is
>> next to impossible as pressing `?' will constantly open the temporary
>> help buffer.
>
> Welcome to C-q which solves this problem once and for all.

Ah.  Thanks for the tip!
-- 
Matt



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Insert `help-char' when pressed twice.
  2015-04-14 13:35 Insert `help-char' when pressed twice Matthew Leach
@ 2015-04-14 16:52 ` Stefan Monnier
  2015-04-14 16:43   ` Matthew Leach
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2015-04-14 16:52 UTC (permalink / raw)
  To: Matthew Leach; +Cc: emacs-devel

> conditional.  Now, Suppose we wanted to insert `[ $? -ne 0 ]'.  This is
> next to impossible as pressing `?' will constantly open the temporary
> help buffer.

Welcome to C-q which solves this problem once and for all.


        Stefan



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-14 16:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-14 13:35 Insert `help-char' when pressed twice Matthew Leach
2015-04-14 16:52 ` Stefan Monnier
2015-04-14 16:43   ` Matthew Leach

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.