help-gnu-emacs
[Top][All Lists]
Advanced

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

Post-Advice for file-move (rename-file()) but not upon save-buffer


From: Nordlöw
Subject: Post-Advice for file-move (rename-file()) but not upon save-buffer
Date: 6 May 2007 01:57:59 -0700
User-agent: G2/1.0

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?


Thanks in advance,
Nordlöw



reply via email to

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