changeset 94186:7870d07a291c

* tooltip.el (tooltip-previous-message): New var. (tooltip-show-help-non-mode): Rewrite to better follow the behavior of the C code (avoid overwriting a minibuffer, restore previous echo message, ...). (tooltip-delay, tooltip-process-prompt-regexp, tooltip-strip-prompt): Simplify. * keyboard.c (Vpre_help_message): Remove. (show_help_echo): Remove default C code.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 19 Apr 2008 19:30:53 +0000
parents 580129e092d0
children 72eb648a4690
files lisp/ChangeLog lisp/tooltip.el src/ChangeLog src/keyboard.c
diffstat 4 files changed, 52 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Apr 19 06:41:23 2008 +0000
+++ b/lisp/ChangeLog	Sat Apr 19 19:30:53 2008 +0000
@@ -1,3 +1,12 @@
+2008-04-19  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* tooltip.el (tooltip-previous-message): New var.
+	(tooltip-show-help-non-mode): Rewrite to better follow the behavior of
+	the C code (avoid overwriting a minibuffer, restore previous echo
+	message, ...).
+	(tooltip-delay, tooltip-process-prompt-regexp, tooltip-strip-prompt):
+	Simplify.
+
 2008-04-19  Nick Roberts  <nickrob@snap.net.nz>
 
 	* progmodes/gdb-ui.el (gdb-thread-indicator): New variable.
--- a/lisp/tooltip.el	Sat Apr 19 06:41:23 2008 +0000
+++ b/lisp/tooltip.el	Sat Apr 19 19:30:53 2008 +0000
@@ -178,12 +178,10 @@
 
 (defun tooltip-delay ()
   "Return the delay in seconds for the next tooltip."
-  (let ((delay tooltip-delay)
-	(now (float-time)))
-    (when (and tooltip-hide-time
-	       (< (- now tooltip-hide-time) tooltip-recent-seconds))
-      (setq delay tooltip-short-delay))
-    delay))
+  (if (and tooltip-hide-time
+           (< (- (float-time) tooltip-hide-time) tooltip-recent-seconds))
+      tooltip-short-delay
+    tooltip-delay))
 
 (defun tooltip-cancel-delayed-tip ()
   "Disable the tooltip timeout."
@@ -280,8 +278,7 @@
 If a region is active and the mouse is inside the region, print
 the region.  Otherwise, figure out the identifier around the point
 where the mouse is."
-  (save-excursion
-    (set-buffer (tooltip-event-buffer event))
+  (with-current-buffer (tooltip-event-buffer event)
     (let ((point (posn-point (event-end event))))
       (if (tooltip-region-active-p)
 	  (when (and (<= (region-beginning) point) (<= point (region-end)))
@@ -292,23 +289,22 @@
   "Return regexp matching the prompt of PROCESS at the end of a string.
 The prompt is taken from the value of `comint-prompt-regexp' in
 the buffer of PROCESS."
-  (let ((prompt-regexp (save-excursion
-			 (set-buffer (process-buffer process))
+  (let ((prompt-regexp (with-current-buffer (process-buffer process)
 			 comint-prompt-regexp)))
-    ;; Most start with `^' but the one for `sdb' cannot be easily
-    ;; stripped.  Code the prompt for `sdb' fixed here.
-    (if (= (aref prompt-regexp 0) ?^)
-	(setq prompt-regexp (substring prompt-regexp 1))
-      (setq prompt-regexp "\\*"))
-    (concat "\n*" prompt-regexp "$")))
+    (concat "\n*"
+            ;; Most start with `^' but the one for `sdb' cannot be easily
+            ;; stripped.  Code the prompt for `sdb' fixed here.
+            (if (= (aref prompt-regexp 0) ?^)
+                (substring prompt-regexp 1)
+              "\\*")
+            "$")))
 
 (defun tooltip-strip-prompt (process output)
   "Return OUTPUT with any prompt of PROCESS stripped from its end."
-  (let ((prompt-regexp (tooltip-process-prompt-regexp process)))
-    (save-match-data
-      (when (string-match prompt-regexp output)
-	(setq output (substring output 0 (match-beginning 0)))))
-    output))
+  (save-match-data
+    (if (string-match (tooltip-process-prompt-regexp process) output)
+        (substring output 0 (match-beginning 0))
+      output)))
 
 
 ;;; Tooltip help.
@@ -316,12 +312,30 @@
 (defvar tooltip-help-message nil
   "The last help message received via `tooltip-show-help'.")
 
-(defun tooltip-show-help-non-mode (msg)
+(defvar tooltip-previous-message nil
+  "The previous content of the echo area.")
+
+(defun tooltip-show-help-non-mode (help)
   "Function installed as `show-help-function' when tooltip is off."
-  (let ((message-truncate-lines t))
-    (message "%s" (if msg
-		      (replace-regexp-in-string "\n" ", " msg)
-		    ""))))
+  (when (and (not (window-minibuffer-p)) ;Don't overwrite minibuffer contents.
+             ;; Don't know how to reproduce it in Elisp:
+             ;; Don't overwrite a keystroke echo.
+             ;; (NILP (echo_message_buffer) || ok_to_overwrite_keystroke_echo)
+             (not cursor-in-echo-area)) ;Don't overwrite a prompt.
+    (cond
+     ((stringp help)
+      (unless tooltip-previous-message
+        (setq tooltip-previous-message (current-message)))
+      (let ((message-truncate-lines t)
+            (message-log-max nil))
+        (message "%s" (replace-regexp-in-string "\n" ", " help))))
+     ((stringp tooltip-previous-message)
+      (let ((message-log-max nil))
+        (message "%s" tooltip-previous-message)
+        (setq tooltip-previous-message nil)))
+     (t
+      (message nil)))))
+      
 
 (defun tooltip-show-help (msg)
   "Function installed as `show-help-function'.
--- a/src/ChangeLog	Sat Apr 19 06:41:23 2008 +0000
+++ b/src/ChangeLog	Sat Apr 19 19:30:53 2008 +0000
@@ -1,5 +1,8 @@
 2008-04-19  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* keyboard.c (Vpre_help_message): Remove.
+	(show_help_echo): Remove default C code.
+
 	* dired.c (directory_files_internal, file_name_completion):
 	Only call ENCODE_FILE if the string is indeed decoded.
 
--- a/src/keyboard.c	Sat Apr 19 06:41:23 2008 +0000
+++ b/src/keyboard.c	Sat Apr 19 19:30:53 2008 +0000
@@ -157,11 +157,6 @@
 
 Lisp_Object Vshow_help_function;
 
-/* If a string, the message displayed before displaying a help-echo
-   in the echo area.  */
-
-Lisp_Object Vpre_help_message;
-
 /* Nonzero means do menu prompting.  */
 
 static int menu_prompting;
@@ -2458,37 +2453,6 @@
     {
       if (!NILP (Vshow_help_function))
 	call1 (Vshow_help_function, help);
-      else if (/* Don't overwrite minibuffer contents.  */
-	       !MINI_WINDOW_P (XWINDOW (selected_window))
-	       /* Don't overwrite a keystroke echo.  */
-	       && (NILP (echo_message_buffer)
-		   || ok_to_overwrite_keystroke_echo)
-	       /* Don't overwrite a prompt.  */
-	       && !cursor_in_echo_area)
-	{
-	  if (STRINGP (help))
-	    {
-	      int count = SPECPDL_INDEX ();
-
-	      if (!help_echo_showing_p)
-		Vpre_help_message = current_message ();
-
-	      specbind (Qmessage_truncate_lines, Qt);
-	      message3_nolog (help, SBYTES (help),
-			      STRING_MULTIBYTE (help));
-	      unbind_to (count, Qnil);
-	    }
-	  else if (STRINGP (Vpre_help_message))
-	    {
-	      message3_nolog (Vpre_help_message,
-			      SBYTES (Vpre_help_message),
-			      STRING_MULTIBYTE (Vpre_help_message));
-	      Vpre_help_message = Qnil;
-	    }
-	  else
-	    message (0);
-	}
-
       help_echo_showing_p = STRINGP (help);
     }
 }
@@ -11753,9 +11717,6 @@
 {
   pending_funcalls = Qnil;
 
-  Vpre_help_message = Qnil;
-  staticpro (&Vpre_help_message);
-
   Vlispy_mouse_stem = build_string ("mouse");
   staticpro (&Vlispy_mouse_stem);