[Top][All Lists]

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

Re: Mode for files visited by GUD

From: Juanma
Subject: Re: Mode for files visited by GUD
Date: Fri, 18 Jul 2008 03:08:34 +0200
User-agent: KMail/1.9.6 (enterprise 0.20070907.709405)

>  > documented on a user level, while the variable was not. Maybe the variable
>  > was created by my mistake only, as I hooked my function on it?
> What variable?  There is no variable gdb-find-file-hook and the variable
> find-file-hook is documented in the Elisp manual.

What I thought: there *was* no such variable, until I did
 (add-hook 'gdb-find-file-hook 'my-stuff)
Of course, it didn't help with anything  :-)
The thing is, I did it before realizing that it wasn't a hook variable, but
a function. I had overlooked that you said "You could advise that function".

>  > So, yes, I can advice that function, but, anything against using a hook
>  > variable instead?
> I'm not sure what you mean.

Oh, never mind. I was curious as to why making 'gdb-find-file-hook' a
function instead of a hook variable, but you already explained that it was a
design decision.

> gdb-find-file-hook is added to find-file-hook which _is_ a hook variable

Yes, I noticed it. And I don't understand the whole procedure. With this
mechanism, is there any difference between advising 'gdb-find-file-hook',
and directly hooking my functions in 'find-file-hook'? The result seems to
be the same in the end, and it's not what I wanted. I did not want my
functions to be run for every file loaded into Emacs (at least, loaded in
any way that would cause the execution of 'find-file-hook').

> Advising functions has it's own problems as described in the Elisp manual.
> What is it you are trying to do?  If your changes are of general interest,
> maybe we could include them in Emacs.

I want to turn on a minor mode for source code files visited during
debugging. I want to make them read-only and have many commands bound to
single keys (I use View mode in addition to my minor mode).

The minor mode is this:


(define-minor-mode source-guding-mode
  "Toggle source-GUDing minor mode.
With prefix ARG, turn source-GUDing mode on if ARG is positive,
off otherwise.

When source-GUDing mode is on for a buffer, View mode is
activated (so the buffer is turned read-only) and GUD commands
are assigned to very simple keystrokes (typically one key). Here
is the list of those:


  ;; Initial value for the minor mode variable (off)
  ;; Indicator for the mode line
  " *GUDing*"
  ;; We can provide a keymap for the minor mode or we can better to
  ;; provide the key bindings in a list (better in this case)
  '(([return] . gud-go)          ; start or continue execution
    ("b" . gud-break)            ; set a breakpoint
    ("D" . gud-remove)           ; delete breakpoint in current line, if any
    ("n" . gud-next)             ; execute next expression, but don't enter any 
    ("s" . gud-step)             ; execute next expression, stepping into 
    ("c" . gud-cont)             ; continue execution
    ("u" . gud-until)            ; run until cursor
    ("J" . gud-jump)             ; move execution point to current line
    (">" . gud-down)             ; go down N stack frames (needs num. arg.)
    ("<" . gud-up)               ; go up N stack frames (needs num. arg.)
    ("t" . gud-tbreak)           ; set temporary breakpoint
    ("p" . gud-print)            ; print expression at point
    ("d" . gud-pstar)            ; print C-dereferenced expression at point
    ([f5] . gud-refresh)         ; show current execution point (and re-draw 
    ("q" . source-guding-mode))  ; quit this mode (also toggle View mode)
  ;; Customization group
  :group gud
  ;; Body of the mode
  (view-mode source-guding-mode)) ; the value of the minor mode var. will
                                  ; determine whether to turn on or off the
                                  ; associated View mode


Then I have this in my .emacs:

(autoload 'source-guding-mode "source-guding.el")
(defadvice gdb-find-file-hook (after activate-guding activate)
  (source-guding-mode 1))

"Having a smoking section in a restaurant is like
 having a peeing section in a swimming pool."
       -- Edward Burr

reply via email to

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