[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Post-Advice for file-move (rename-file()) but not upon save-buffer
From: |
Kevin Rodgers |
Subject: |
Re: Post-Advice for file-move (rename-file()) but not upon save-buffer |
Date: |
Tue, 15 May 2007 21:40:03 -0600 |
User-agent: |
Thunderbird 1.5.0.10 (Macintosh/20070221) |
Nordlöw wrote:
Hey there again, Emacs Hackers!
I want to make Emacs run a command every time a file is moved/renamed
(from Emacs)
Here is the essential part of my code:
(defadvice rename-file (after update-c-includes activate)
"Update C include statements upon rename of file."
(let ((file (file-name-nondirectory (ad-get-arg 0)))
(newname (file-name-nondirectory (ad-get-arg 1))))
(if (or (file-is-C-header file)
(file-is-C-header newname))
(if (y-or-n-p "Update C,C++ #includes accordingly ")
;; TODO: We need to strip parts of the path from file and newname
(c-rename-includes file newname))
)))
This works as intended for rename-file but it also gets called when I
save a buffer to file, using save-buffer(), which is *not* what I
want. I guess it's because save-file() is implemented using rename-
file().
How can I make it run *solely* when I rename a file?
,----[ C-h f interactive-p RET ]
| interactive-p is a built-in function in `C source code'.
| (interactive-p)
|
| Return t if the function was run directly by user input.
| This means that the function was called with `call-interactively'
| (which includes being called as the binding of a key)
| and input is currently coming from the keyboard (not in keyboard macro),
| and Emacs is not running in batch mode (`noninteractive' is nil).
|
| The only known proper use of `interactive-p' is in deciding whether to
| display a helpful message, or how to display it. If you're thinking
| of using it for any other purpose, it is quite likely that you're
| making a mistake. Think: what do you want to do when the command is
| called from a keyboard macro?
|
| If you want to test whether your function was called with
| `call-interactively', the way to do that is by adding an extra
| optional argument, and making the `interactive' spec specify non-nil
| unconditionally for that argument. (`p' is a good way to do this.)
|
| [back]
`----
--
Kevin Rodgers
Denver, Colorado, USA