all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Post-Advice for file-move (rename-file()) but not upon save-buffer
Date: Tue, 15 May 2007 21:40:03 -0600	[thread overview]
Message-ID: <f2due8$2da$1@sea.gmane.org> (raw)
In-Reply-To: <1178441879.660722.212060@p77g2000hsh.googlegroups.com>

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

      parent reply	other threads:[~2007-05-16  3:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-06  8:57 Post-Advice for file-move (rename-file()) but not upon save-buffer Nordlöw
2007-05-06 11:00 ` Tim X
2007-05-16  3:40 ` Kevin Rodgers [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='f2due8$2da$1@sea.gmane.org' \
    --to=kevin.d.rodgers@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.