From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: Post-Advice for file-move (rename-file()) but not upon save-buffer Date: Sun, 06 May 2007 21:00:08 +1000 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <873b2adxon.fsf@lion.rapttech.com.au> References: <1178441879.660722.212060@p77g2000hsh.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1178451210 26133 80.91.229.12 (6 May 2007 11:33:30 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 6 May 2007 11:33:30 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun May 06 13:33:29 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HkezY-0006Se-Ki for geh-help-gnu-emacs@m.gmane.org; Sun, 06 May 2007 13:33:28 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hkf6P-0006qh-6o for geh-help-gnu-emacs@m.gmane.org; Sun, 06 May 2007 07:40:33 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!multikabel.net!feed20.multikabel.net!sn-xt-ams-06!sn-xt-ams-08!sn-xt-ams-03!sn-post-ams-01!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.99 (gnu/linux) Cancel-Lock: sha1:sQf9Jc3oINcZXzkMB0+JMHEhm/Q= Original-X-Complaints-To: abuse@supernews.com Original-Lines: 46 Original-Xref: shelby.stanford.edu gnu.emacs.help:148163 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:43764 Archived-At: Nordlöw writes: > 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? > You cannot make it run solely when you rename a file because it is used by other functions, such as save-buffer etc. So, what you need to do is make it only do what you want using some other criteria. Maybe regquire both files to be ending in .h (because I suspect the rename-file called when saving a buffer is probably related to temporary files and/or backup files etc and they *may* not both end in .h, even when saving a .h file for the first time. In the end, it is likely you won't be able to use defadvice here. I love defadvice and use it all the time, but in your case, you may be better off writing a specific function that does what you want and binding that to a key etc. Tim -- tcross (at) rapttech dot com dot au