* Extending GUD tooltips
@ 2005-04-27 3:47 Nick Roberts
2005-04-27 6:46 ` Jérôme Marant
2005-04-27 18:36 ` Richard Stallman
0 siblings, 2 replies; 14+ messages in thread
From: Nick Roberts @ 2005-04-27 3:47 UTC (permalink / raw)
This patch extends GUD tooltips to display #define directives over relevant
identifiers when a C program is under the control of GDB but has no child
process i.e the program has either not started, been signalled or exited.
Such tooltips could be displayed even if GDB has not been invoked but it
was easier to integrate them with the existing GUD tooltips and such
information is a natural part of the debugging process. I seem to recall
that Visual Studio has something similar.
The patch is for three files: gdb-ui.el, tooltip.el and cc-mode.el. Clearly
the changes for cc-mode.el need to be ratified by the maintainers of that file
(I use /lib/cpp but this should be more general). I have sent an e-mail to the
appropriate list (bug-cc-mode@gnu.org) over a week ago but not had a reply
yet.
Nick
*** /home/nick/emacs/lisp/tooltip.el.~1.52.~ 2005-04-20 21:46:08.000000000 +1200
--- /home/nick/emacs/lisp/tooltip.el 2005-04-27 14:55:17.000000000 +1200
***************
*** 453,481 ****
"Show tip for identifier or selection under the mouse.
The mouse must either point at an identifier or inside a selected
region for the tip window to be shown. If tooltip-gud-dereference is t,
! add a `*' in front of the printed expression.
This function must return nil if it doesn't handle EVENT."
(let (process)
(when (and (eventp event)
tooltip-gud-tips-p
(boundp 'gud-comint-buffer)
(setq process (get-buffer-process gud-comint-buffer))
(posn-point (event-end event))
! (progn (setq tooltip-gud-event event)
! (eval (cons 'and tooltip-gud-display))))
(let ((expr (tooltip-expr-to-print event)))
(when expr
! (let ((cmd (tooltip-gud-print-command expr)))
! (unless (null cmd) ; CMD can be nil if unknown debugger
! (case gud-minor-mode
! (gdba (gdb-enqueue-input
! (list (concat cmd "\n") 'gdb-tooltip-print)))
! (t
! (setq tooltip-gud-original-filter (process-filter process))
! (set-process-filter process 'tooltip-gud-process-output)
! (gud-basic-call cmd)))
! expr)))))))
(defun gdb-tooltip-print ()
(tooltip-show
--- 453,498 ----
"Show tip for identifier or selection under the mouse.
The mouse must either point at an identifier or inside a selected
region for the tip window to be shown. If tooltip-gud-dereference is t,
! add a `*' in front of the printed expression. In the case of a C program
! controlled by GDB, show the associated #define directives when program is
! not executing.
This function must return nil if it doesn't handle EVENT."
(let (process)
(when (and (eventp event)
tooltip-gud-tips-p
(boundp 'gud-comint-buffer)
+ gud-comint-buffer
+ (buffer-name gud-comint-buffer); gud-comint-buffer might be killed
(setq process (get-buffer-process gud-comint-buffer))
(posn-point (event-end event))
! (or (eq gud-minor-mode 'gdba)
! (progn (setq tooltip-gud-event event)
! (eval (cons 'and tooltip-gud-display)))))
(let ((expr (tooltip-expr-to-print event)))
(when expr
! (if (and (eq gud-minor-mode 'gdba)
! (not gdb-active-process))
! (progn
! (with-current-buffer
! (window-buffer (let ((mouse (mouse-position)))
! (window-at (cadr mouse)
! (cddr mouse))))
! (when (boundp 'cc-define-alist) ; might be a Fortran program
! (let ((define-elt (assoc expr cc-define-alist)))
! (unless (null define-elt)
! (tooltip-show (cdr define-elt))
! expr)))))
! (let ((cmd (tooltip-gud-print-command expr)))
! (unless (null cmd) ; CMD can be nil if unknown debugger
! (case gud-minor-mode
! (gdba (gdb-enqueue-input
! (list (concat cmd "\n") 'gdb-tooltip-print)))
! (t
! (setq tooltip-gud-original-filter (process-filter process))
! (set-process-filter process 'tooltip-gud-process-output)
! (gud-basic-call cmd)))
! expr))))))))
(defun gdb-tooltip-print ()
(tooltip-show
*** /home/nick/emacs/lisp/progmodes/gdb-ui.el.~1.61.~ 2005-04-21 23:52:47.000000000 +1200
--- /home/nick/emacs/lisp/progmodes/gdb-ui.el 2005-04-27 15:10:24.000000000 +1200
***************
*** 82,87 ****
--- 82,89 ----
(defvar gdb-location-alist nil
"Alist of breakpoint numbers and full filenames.")
(defvar gdb-find-file-unhook nil)
+ (defvar gdb-active-process nil "GUD tooltips display variable values when t, \
+ and #define directives otherwise.")
(defvar gdb-buffer-type nil
"One of the symbols bound in `gdb-buffer-rules'.")
***************
*** 776,783 ****
("post-prompt" gdb-post-prompt)
("source" gdb-source)
("starting" gdb-starting)
! ("exited" gdb-stopping)
! ("signalled" gdb-stopping)
("signal" gdb-stopping)
("breakpoint" gdb-stopping)
("watchpoint" gdb-stopping)
--- 778,785 ----
("post-prompt" gdb-post-prompt)
("source" gdb-source)
("starting" gdb-starting)
! ("exited" gdb-exited)
! ("signalled" gdb-exited)
("signal" gdb-stopping)
("breakpoint" gdb-stopping)
("watchpoint" gdb-stopping)
***************
*** 853,858 ****
--- 855,861 ----
"An annotation handler for `starting'.
This says that I/O for the subprocess is now the program being debugged,
not GDB."
+ (setq gdb-active-process t)
(let ((sink gdb-output-sink))
(cond
((eq sink 'user)
***************
*** 865,871 ****
(error "Unexpected `starting' annotation")))))
(defun gdb-stopping (ignored)
! "An annotation handler for `exited' and other annotations.
They say that I/O for the subprocess is now GDB, not the program
being debugged."
(if gdb-use-inferior-io-buffer
--- 868,874 ----
(error "Unexpected `starting' annotation")))))
(defun gdb-stopping (ignored)
! "An annotation handler for `breakpoint' and other annotations.
They say that I/O for the subprocess is now GDB, not the program
being debugged."
(if gdb-use-inferior-io-buffer
***************
*** 877,882 ****
--- 880,895 ----
(gdb-resync)
(error "Unexpected stopping annotation"))))))
+ (defun gdb-exited (ignored)
+ "An annotation handler for `exited' and `signalled'.
+ They say that I/O for the subprocess is now GDB, not the program
+ being debugged and that the program is no longer running. This
+ function is used to change the focus of GUD tooltips to #define
+ directives."
+ (setq gdb-active-process nil)
+ (gdb-stopping ignored))
+
+
(defun gdb-frame-begin (ignored)
(let ((sink gdb-output-sink))
(cond
***************
*** 2140,2146 ****
(gdb-remove-breakpoint-icons (point-min) (point-max) t)
(setq gud-minor-mode nil)
(kill-local-variable 'tool-bar-map)
! (setq gud-running nil))))))
(when (markerp gdb-overlay-arrow-position)
(move-marker gdb-overlay-arrow-position nil)
(setq gdb-overlay-arrow-position nil))
--- 2153,2160 ----
(gdb-remove-breakpoint-icons (point-min) (point-max) t)
(setq gud-minor-mode nil)
(kill-local-variable 'tool-bar-map)
! (setq gud-running nil)
! (setq gdb-active-process nil))))))
(when (markerp gdb-overlay-arrow-position)
(move-marker gdb-overlay-arrow-position nil)
(setq gdb-overlay-arrow-position nil))
*** /home/nick/emacs/lisp/progmodes/cc-mode.el.~1.33.~ 2005-01-01 19:31:19.000000000 +1300
--- /home/nick/emacs/lisp/progmodes/cc-mode.el 2005-04-27 14:15:54.000000000 +1200
***************
*** 639,644 ****
--- 639,659 ----
;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
+ (defvar cc-define-alist nil "Alist of #define directives for GUD tooltips.")
+
+ (defun cc-create-define-alist ()
+ (let* ((file (buffer-file-name))
+ (output
+ (with-output-to-string
+ (with-current-buffer standard-output
+ (call-process "/lib/cpp"
+ file t nil "-dM"))))
+ (define-list (split-string output "\n" t))
+ (name))
+ (dolist (define define-list)
+ (setq name (nth 1 (split-string define "[( ]")))
+ (push (cons name define) cc-define-alist))))
+
;;;###autoload
(defun c-mode ()
"Major mode for editing K&R and ANSI C code.
***************
*** 662,672 ****
--- 677,689 ----
mode-name "C"
local-abbrev-table c-mode-abbrev-table
abbrev-mode t)
+ (make-local-variable 'cc-define-alist)
(use-local-map c-mode-map)
(c-init-language-vars-for 'c-mode)
(c-common-init 'c-mode)
(easy-menu-add c-c-menu)
(cc-imenu-init cc-imenu-c-generic-expression)
+ (cc-create-define-alist)
(run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
(c-update-modeline))
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-04-27 3:47 Extending GUD tooltips Nick Roberts
@ 2005-04-27 6:46 ` Jérôme Marant
2005-04-27 23:00 ` Nick Roberts
2005-04-27 18:36 ` Richard Stallman
1 sibling, 1 reply; 14+ messages in thread
From: Jérôme Marant @ 2005-04-27 6:46 UTC (permalink / raw)
Cc: emacs-devel
Quoting Nick Roberts <nickrob@snap.net.nz>:
>
> This patch extends GUD tooltips to display #define directives over relevant
> identifiers when a C program is under the control of GDB but has no child
> process i.e the program has either not started, been signalled or exited.
Btw, I have a question not directly related to your patch: why do you
absolutely need to put gud-specific code within tooltip.el?
IMHO, tooltip.el shall only provide some generic code that can be used
by other modes, externaly. AFAIK, this what other modes do.
Cheers,
--
Jérôme Marant
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-04-27 3:47 Extending GUD tooltips Nick Roberts
2005-04-27 6:46 ` Jérôme Marant
@ 2005-04-27 18:36 ` Richard Stallman
1 sibling, 0 replies; 14+ messages in thread
From: Richard Stallman @ 2005-04-27 18:36 UTC (permalink / raw)
Cc: emacs-devel
This change in cc-mode.el is pretty simple and harmless, so please
install it. If the CC mode maintainer objects, he can say so
when he gets around to dealing with the issue.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-04-27 6:46 ` Jérôme Marant
@ 2005-04-27 23:00 ` Nick Roberts
2005-04-28 9:05 ` Jérôme Marant
2005-04-29 0:13 ` Richard Stallman
0 siblings, 2 replies; 14+ messages in thread
From: Nick Roberts @ 2005-04-27 23:00 UTC (permalink / raw)
Cc: emacs-devel
> Btw, I have a question not directly related to your patch: why do you
> absolutely need to put gud-specific code within tooltip.el?
Well, I didn't put them there, but it certainly makes coding easier because
GUD tooltips use a lot of the generic code.
> IMHO, tooltip.el shall only provide some generic code that can be used
> by other modes, externaly. AFAIK, this what other modes do.
Maybe thats a general rule but one needs to be quantitative. tooltip.el is
about 500 lines and about half that code is for GUD. So maybe 250 lines get
loaded in Emacs through loadup.el but I'm not sure that it amounts to much in
memory. On the other hand, gud.el is about 3000 lines, so moving GUD tooltips
there would make the file over ten times larger than tooltip.el. Can you see
any practical benefit in doing this?
Nick
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-04-27 23:00 ` Nick Roberts
@ 2005-04-28 9:05 ` Jérôme Marant
2005-04-29 0:13 ` Richard Stallman
1 sibling, 0 replies; 14+ messages in thread
From: Jérôme Marant @ 2005-04-28 9:05 UTC (permalink / raw)
Cc: emacs-devel
Quoting Nick Roberts <nickrob@snap.net.nz>:
> > Btw, I have a question not directly related to your patch: why do you
> > absolutely need to put gud-specific code within tooltip.el?
>
> Well, I didn't put them there, but it certainly makes coding easier because
> GUD tooltips use a lot of the generic code.
You mean you did put them there I guess or I misunderstood the first
part of your sentence.
> > IMHO, tooltip.el shall only provide some generic code that can be used
> > by other modes, externaly. AFAIK, this what other modes do.
>
> Maybe thats a general rule but one needs to be quantitative. tooltip.el is
> about 500 lines and about half that code is for GUD. So maybe 250 lines get
> loaded in Emacs through loadup.el but I'm not sure that it amounts to much in
I think it is a general rule of software design (I don't pretend to give
software design lessons though).
Are other modes likely to use those gud tooltip functions? If not,
they should not be put in the same module.
How id GUD different from other modes in this respect?
> memory. On the other hand, gud.el is about 3000 lines, so moving GUD tooltips
> there would make the file over ten times larger than tooltip.el. Can you see
> any practical benefit in doing this?
I fail to understand the problem from the the gud POV.
gud-specific tooltip code would only be loaded for anyone using gud anyway,
right?
Cheers,
--
Jérôme Marant
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-04-27 23:00 ` Nick Roberts
2005-04-28 9:05 ` Jérôme Marant
@ 2005-04-29 0:13 ` Richard Stallman
2005-05-03 10:45 ` Nick Roberts
1 sibling, 1 reply; 14+ messages in thread
From: Richard Stallman @ 2005-04-29 0:13 UTC (permalink / raw)
Cc: jerome.marant, emacs-devel
Maybe thats a general rule but one needs to be
quantitative. tooltip.el is about 500 lines and about half that
code is for GUD. So maybe 250 lines get loaded in Emacs through
loadup.el but I'm not sure that it amounts to much in memory. On
the other hand, gud.el is about 3000 lines, so moving GUD tooltips
there would make the file over ten times larger than
tooltip.el. Can you see any practical benefit in doing this?
If this means moving 250 lines into a file of 3000 lines, I don't see
how that would create a problem. I am not sure what is the best thing
to do here, but one possible benefit from moving the code and making
tooltip.el generic would be modularity and clarity.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-04-29 0:13 ` Richard Stallman
@ 2005-05-03 10:45 ` Nick Roberts
[not found] ` <20050503233230.B47179F50F@mirror.positive-internet.com>
0 siblings, 1 reply; 14+ messages in thread
From: Nick Roberts @ 2005-05-03 10:45 UTC (permalink / raw)
Cc: jerome.marant, emacs-devel
> Maybe thats a general rule but one needs to be
> quantitative. tooltip.el is about 500 lines and about half that
> code is for GUD. So maybe 250 lines get loaded in Emacs through
> loadup.el but I'm not sure that it amounts to much in memory. On
> the other hand, gud.el is about 3000 lines, so moving GUD tooltips
> there would make the file over ten times larger than
> tooltip.el. Can you see any practical benefit in doing this?
>
> If this means moving 250 lines into a file of 3000 lines, I don't see
> how that would create a problem. I am not sure what is the best thing
> to do here, but one possible benefit from moving the code and making
> tooltip.el generic would be modularity and clarity.
GUD tooltips need some disentangling from the normal tooltips. They're coded
differently and GUD tooltips shouldn't need tooltip-mode enabled to work: it
should be possble to toggle them independently. After that is done, it
should be straightforward to put the code for GUD tooltips into gud.el.
I might try this one day, after the release, but would be more than happy
if someone else wants to do it.
Nick
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
[not found] ` <20050503233230.B47179F50F@mirror.positive-internet.com>
@ 2005-05-04 16:57 ` Jérôme Marant
2005-05-05 19:45 ` Richard Stallman
2005-05-05 23:45 ` Nick Roberts
1 sibling, 1 reply; 14+ messages in thread
From: Jérôme Marant @ 2005-05-04 16:57 UTC (permalink / raw)
Cc: Nick Roberts, emacs-devel
Richard Stallman <rms@gnu.org> writes:
> GUD tooltips need some disentangling from the normal tooltips. They're coded
> differently and GUD tooltips shouldn't need tooltip-mode enabled to work: it
> should be possble to toggle them independently. After that is done, it
> should be straightforward to put the code for GUD tooltips into gud.el.
>
> I might try this one day, after the release, but would be more than happy
> if someone else wants to do it.
>
> Indeed, if this is complex, it should wait.
How about adding an entry to etc/TODO?
--
Jérôme Marant
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-05-04 16:57 ` Jérôme Marant
@ 2005-05-05 19:45 ` Richard Stallman
0 siblings, 0 replies; 14+ messages in thread
From: Richard Stallman @ 2005-05-05 19:45 UTC (permalink / raw)
Cc: nickrob, emacs-devel
How about adding an entry to etc/TODO?
Please do.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
[not found] ` <20050503233230.B47179F50F@mirror.positive-internet.com>
2005-05-04 16:57 ` Jérôme Marant
@ 2005-05-05 23:45 ` Nick Roberts
2005-05-06 18:51 ` Richard Stallman
2005-05-10 20:25 ` Jérôme Marant
1 sibling, 2 replies; 14+ messages in thread
From: Nick Roberts @ 2005-05-05 23:45 UTC (permalink / raw)
Cc: jerome.marant, emacs-devel
> GUD tooltips need some disentangling from the normal tooltips. They're
> coded differently and GUD tooltips shouldn't need tooltip-mode enabled
> to work: it should be possble to toggle them independently. After that
> is done, it should be straightforward to put the code for GUD tooltips
> into gud.el.
>
> I might try this one day, after the release, but would be more than
> happy if someone else wants to do it.
>
> Indeed, if this is complex, it should wait.
I have actually done this now. I found it compelling for several reasons:
1) It was a lot easier to do than I thought it would be.
2) Normal tooltips and GUD tooltips can be toggled independently.
3) The define lists for macro expansion need only be generated when GUD
tooltips is enabled as a minor mode (as Stefan suggested).
4) The arrangement is more modular (as Jérôme suggested).
5) Only normal tooltips get loaded into Emacs through loadup.el
I attach reduced tooltip.el file below. I also have the changes for
GUD tooltips ready to include in gud.el.
Is it OK to install these changes?
;;; tooltip.el --- show tooltip windows
;; Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005
;; Free Software Foundation, Inc.
;; Author: Gerd Moellmann <gerd@acm.org>
;; Keywords: help c mouse tools
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;;; Code:
;;; Customizable settings
(defgroup tooltip nil
"Customization group for the `tooltip' package."
:group 'help
:group 'mouse
:group 'tools
:version "21.1"
:tag "Tool Tips")
(defcustom tooltip-delay 0.7
"Seconds to wait before displaying a tooltip the first time."
:tag "Delay"
:type 'number
:group 'tooltip)
(defcustom tooltip-short-delay 0.1
"Seconds to wait between subsequent tooltips on different items."
:tag "Short delay"
:type 'number
:group 'tooltip)
(defcustom tooltip-recent-seconds 1
"Display tooltips if changing tip items within this many seconds.
Do so after `tooltip-short-delay'."
:tag "Recent seconds"
:type 'number
:group 'tooltip)
(defcustom tooltip-hide-delay 10
"Hide tooltips automatically after this many seconds."
:tag "Hide delay"
:type 'number
:group 'tooltip)
(defcustom tooltip-x-offset nil
"X offset, in pixels, for the display of tooltips.
The offset is relative to the position of the mouse. It must
be chosen so that the tooltip window doesn't contain the mouse
when it pops up. If the value is nil, the default offset is 5
pixels.
If `tooltip-frame-parameters' includes the `left' parameter,
the value of `tooltip-x-offset' is ignored."
:tag "X offset"
:type '(choice (const :tag "Default" nil)
(integer :tag "Offset" :value 1))
:group 'tooltip)
(defcustom tooltip-y-offset nil
"Y offset, in pixels, for the display of tooltips.
The offset is relative to the position of the mouse. It must
be chosen so that the tooltip window doesn't contain the mouse
when it pops up. If the value is nil, the default offset is -10
pixels.
If `tooltip-frame-parameters' includes the `top' parameter,
the value of `tooltip-y-offset' is ignored."
:tag "Y offset"
:type '(choice (const :tag "Default" nil)
(integer :tag "Offset" :value 1))
:group 'tooltip)
(defcustom tooltip-frame-parameters
'((name . "tooltip")
(internal-border-width . 5)
(border-width . 1))
"Frame parameters used for tooltips.
If `left' or `top' parameters are included, they specify the absolute
position to pop up the tooltip."
:type 'sexp
:tag "Frame Parameters"
:group 'tooltip)
(defface tooltip
'((((class color))
:background "lightyellow"
:foreground "black"
:inherit variable-pitch)
(t
:inherit variable-pitch))
"Face for tooltips."
:group 'tooltip)
\f
;;; Variables that are not customizable.
(defvar tooltip-hook nil
"Functions to call to display tooltips.
Each function is called with one argument EVENT which is a copy of
the last mouse movement event that occurred.")
(defvar tooltip-timeout-id nil
"The id of the timeout started when Emacs becomes idle.")
(defvar tooltip-last-mouse-motion-event nil
"A copy of the last mouse motion event seen.")
(defvar tooltip-hide-time nil
"Time when the last tooltip was hidden.")
;;; Event accessors
(defun tooltip-event-buffer (event)
"Return the buffer over which event EVENT occurred.
This might return nil if the event did not occur over a buffer."
(let ((window (posn-window (event-end event))))
(and window (window-buffer window))))
;;; Switching tooltips on/off
;; We don't set track-mouse globally because this is a big redisplay
;; problem in buffers having a pre-command-hook or such installed,
;; which does a set-buffer, like the summary buffer of Gnus. Calling
;; set-buffer prevents redisplay optimizations, so every mouse motion
;; would be accompanied by a full redisplay.
;;;###autoload
(define-minor-mode tooltip-mode
"Toggle Tooltip display.
With ARG, turn tooltip mode on if and only if ARG is positive."
:global t
;; If you change the :init-value below, you also need to change the
;; corresponding code in startup.el.
:init-value (not (or noninteractive
(and (boundp 'emacs-quick-startup) emacs-quick-startup)
(not (and (fboundp 'display-graphic-p)
(display-graphic-p)))
(not (fboundp 'x-show-tip))))
:group 'tooltip
(unless (or (null tooltip-mode) (fboundp 'x-show-tip))
(error "Sorry, tooltips are not yet available on this system"))
(if tooltip-mode
(progn
(add-hook 'pre-command-hook 'tooltip-hide)
(add-hook 'tooltip-hook 'tooltip-help-tips))
(unless (and (boundp 'gud-tooltip-mode) gud-tooltip-mode)
(remove-hook 'pre-command-hook 'tooltip-hide))
(remove-hook 'tooltip-hook 'tooltip-help-tips))
(setq show-help-function
(if tooltip-mode 'tooltip-show-help-function nil)))
\f
;;; Timeout for tooltip display
(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))
(defun tooltip-cancel-delayed-tip ()
"Disable the tooltip timeout."
(when tooltip-timeout-id
(disable-timeout tooltip-timeout-id)
(setq tooltip-timeout-id nil)))
(defun tooltip-start-delayed-tip ()
"Add a one-shot timeout to call function tooltip-timeout."
(setq tooltip-timeout-id
(add-timeout (tooltip-delay) 'tooltip-timeout nil)))
(defun tooltip-timeout (object)
"Function called when timer with id tooltip-timeout-id fires."
(run-hook-with-args-until-success 'tooltip-hook
tooltip-last-mouse-motion-event))
\f
;;; Displaying tips
(defun tooltip-set-param (alist key value)
"Change the value of KEY in alist ALIST to VALUE.
If there's no association for KEY in ALIST, add one, otherwise
change the existing association. Value is the resulting alist."
(let ((param (assq key alist)))
(if (consp param)
(setcdr param value)
(push (cons key value) alist))
alist))
(defun tooltip-show (text &optional use-echo-area)
"Show a tooltip window displaying TEXT.
Text larger than `x-max-tooltip-size' is clipped.
If the alist in `tooltip-frame-parameters' includes `left' and `top'
parameters, they determine the x and y position where the tooltip
is displayed. Otherwise, the tooltip pops at offsets specified by
`tooltip-x-offset' and `tooltip-y-offset' from the current mouse
position.
Optional second arg USE-ECHO-AREA non-nil means to show tooltip
in echo area."
(if use-echo-area
(message "%s" text)
(condition-case error
(let ((params (copy-sequence tooltip-frame-parameters))
(fg (face-attribute 'tooltip :foreground))
(bg (face-attribute 'tooltip :background)))
(when (stringp fg)
(setq params (tooltip-set-param params 'foreground-color fg))
(setq params (tooltip-set-param params 'border-color fg)))
(when (stringp bg)
(setq params (tooltip-set-param params 'background-color bg)))
(x-show-tip (propertize text 'face 'tooltip)
(selected-frame)
params
tooltip-hide-delay
tooltip-x-offset
tooltip-y-offset))
(error
(message "Error while displaying tooltip: %s" error)
(sit-for 1)
(message "%s" text)))))
(defun tooltip-hide (&optional ignored-arg)
"Hide a tooltip, if one is displayed.
Value is non-nil if tooltip was open."
(tooltip-cancel-delayed-tip)
(when (x-hide-tip)
(setq tooltip-hide-time (float-time))))
\f
;;; Debugger-related functions
(defun tooltip-identifier-from-point (point)
"Extract the identifier at POINT, if any.
Value is nil if no identifier exists at point. Identifier extraction
is based on the current syntax table."
(save-excursion
(goto-char point)
(let ((start (progn (skip-syntax-backward "w_") (point))))
(unless (looking-at "[0-9]")
(skip-syntax-forward "w_")
(when (> (point) start)
(buffer-substring start (point)))))))
(defmacro tooltip-region-active-p ()
"Value is non-nil if the region is currently active."
(if (string-match "^GNU" (emacs-version))
`(and transient-mark-mode mark-active)
`(region-active-p)))
(defun tooltip-expr-to-print (event)
"Return an expression that should be printed for EVENT.
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))
(let ((point (posn-point (event-end event))))
(if (tooltip-region-active-p)
(when (and (<= (region-beginning) point) (<= point (region-end)))
(buffer-substring (region-beginning) (region-end)))
(tooltip-identifier-from-point point)))))
(defun tooltip-process-prompt-regexp (process)
"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))
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 "$")))
(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))
\f
;;; Tooltip help.
(defvar tooltip-help-message nil
"The last help message received via `tooltip-show-help-function'.")
(defun tooltip-show-help-function (msg)
"Function installed as `show-help-function'.
MSG is either a help string to display, or nil to cancel the display."
(let ((previous-help tooltip-help-message))
(setq tooltip-help-message msg)
(cond ((null msg)
;; Cancel display. This also cancels a delayed tip, if
;; there is one.
(tooltip-hide))
((equal previous-help msg)
;; Same help as before (but possibly the mouse has moved).
;; Keep what we have.
)
(t
;; A different help. Remove a previous tooltip, and
;; display a new one, with some delay.
(tooltip-hide)
(tooltip-start-delayed-tip)))))
(defun tooltip-help-tips (event)
"Hook function to display a help tooltip.
This is installed on the hook `tooltip-hook', which is run when
the timer with ID `tooltip-timeout-id' fires.
Value is non-nil if this function handled the tip."
(when (stringp tooltip-help-message)
(tooltip-show tooltip-help-message)
t))
(provide 'tooltip)
;; arch-tag: 3d61135e-4618-4a78-af28-183f6df5636f
;;; tooltip.el ends here
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-05-05 23:45 ` Nick Roberts
@ 2005-05-06 18:51 ` Richard Stallman
2005-05-07 0:28 ` Nick Roberts
2005-05-10 20:25 ` Jérôme Marant
1 sibling, 1 reply; 14+ messages in thread
From: Richard Stallman @ 2005-05-06 18:51 UTC (permalink / raw)
Cc: jerome.marant, emacs-devel
This solves enough problems that I think it can be installed now.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-05-06 18:51 ` Richard Stallman
@ 2005-05-07 0:28 ` Nick Roberts
2005-05-07 18:35 ` Richard Stallman
0 siblings, 1 reply; 14+ messages in thread
From: Nick Roberts @ 2005-05-07 0:28 UTC (permalink / raw)
Cc: jerome.marant, emacs-devel
> This solves enough problems that I think it can be installed now.
I've installed these changes. I've added an entry in NEWS and partly updated
the Emacs manual.
GUD tooltips are now toggled by the minor mode gud-tooltip-mode independenttly
of normal tooltips. However, in the manual it may still look as if they depend
on tooltip-mode being enabled. You might want to change this.
Nick
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-05-07 0:28 ` Nick Roberts
@ 2005-05-07 18:35 ` Richard Stallman
0 siblings, 0 replies; 14+ messages in thread
From: Richard Stallman @ 2005-05-07 18:35 UTC (permalink / raw)
Cc: jerome.marant, emacs-devel
GUD tooltips are now toggled by the minor mode gud-tooltip-mode independenttly
of normal tooltips. However, in the manual it may still look as if they depend
on tooltip-mode being enabled. You might want to change this.
Would you please change this in the manual?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Extending GUD tooltips
2005-05-05 23:45 ` Nick Roberts
2005-05-06 18:51 ` Richard Stallman
@ 2005-05-10 20:25 ` Jérôme Marant
1 sibling, 0 replies; 14+ messages in thread
From: Jérôme Marant @ 2005-05-10 20:25 UTC (permalink / raw)
Cc: rms, emacs-devel
Nick Roberts <nickrob@snap.net.nz> writes:
> I have actually done this now. I found it compelling for several reasons:
>
> 1) It was a lot easier to do than I thought it would be.
> 2) Normal tooltips and GUD tooltips can be toggled independently.
> 3) The define lists for macro expansion need only be generated when GUD
> tooltips is enabled as a minor mode (as Stefan suggested).
> 4) The arrangement is more modular (as Jérôme suggested).
> 5) Only normal tooltips get loaded into Emacs through loadup.el
>
> I attach reduced tooltip.el file below. I also have the changes for
> GUD tooltips ready to include in gud.el.
Thanks a lot, Nick, for improving the quality of Emacs code that way!
Cheers,
--
Jérôme Marant
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-05-10 20:25 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-27 3:47 Extending GUD tooltips Nick Roberts
2005-04-27 6:46 ` Jérôme Marant
2005-04-27 23:00 ` Nick Roberts
2005-04-28 9:05 ` Jérôme Marant
2005-04-29 0:13 ` Richard Stallman
2005-05-03 10:45 ` Nick Roberts
[not found] ` <20050503233230.B47179F50F@mirror.positive-internet.com>
2005-05-04 16:57 ` Jérôme Marant
2005-05-05 19:45 ` Richard Stallman
2005-05-05 23:45 ` Nick Roberts
2005-05-06 18:51 ` Richard Stallman
2005-05-07 0:28 ` Nick Roberts
2005-05-07 18:35 ` Richard Stallman
2005-05-10 20:25 ` Jérôme Marant
2005-04-27 18:36 ` Richard Stallman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).