unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <kevin.d.rodgers@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: defadvice question.
Date: Mon, 21 Sep 2009 21:01:30 -0600	[thread overview]
Message-ID: <h99em7$p1q$1@ger.gmane.org> (raw)
In-Reply-To: <m2fxanro80.fsf@tenbit.pl>

Michal wrote:
> Hallo group members.
> when doing C-u M-x cvs-checkout 
> I wanted to always have in minibuffer history ring, my cvs root, just to
> use up arrow key to get it. So I did:
> 
> (setenv "CVSROOT" "/my/cvs/root")
> 
> (defadvice cvs-checkout
>   (before cvs-checkout-cvs-root-add-to-history-ring)
>   (add-to-list 'minibuffer-history (getenv "CVSROOT")))
> 
> (ad-activate 'cvs-checkout)
> 
> 
> but it does not work. Have You an idea why?

`before' advice runs after the interactive arguments are read.  See the
"Combined Definition" node of the Elisp manual (under "Advising Functions").

You can modify the interactive form, like this:

(defadvice cvs-checkout (before minibuffer-history)
   "Add CVSROOT environment variable to `minibuffer-history'."
   (interactive (let ((minibuffer-history
		      (cons (getenv "CVSROOT") minibuffer-history)))
		 ...)))

The tricky part is the "...".  You could copy the entire interactive form from
cvs-checkout source in pcvs.el, but that defeats the whole purpose of using
advice.  You might be able to work around it like this:

(defvar cvs-checkout-interactive-form
   (interactive-form 'cvs-checkout))

(defadvice cvs-checkout (before minibuffer-history)
   "Add CVSROOT environment variable to `minibuffer-history'."
   (interactive (let ((minibuffer-history
		      (cons (getenv "CVSROOT") minibuffer-history)))
		 (call-interactively `(lambda (&rest cvs-checkout-args)
					,cvs-checkout-interactive-form
					cvs-checkout-args)))))

-- 
Kevin Rodgers
Denver, Colorado, USA





  parent reply	other threads:[~2009-09-22  3:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-16 13:52 defadvice question Michal
2009-09-17  0:16 ` Andreas Politz
     [not found] ` <mailman.6832.1253146594.2239.help-gnu-emacs@gnu.org>
2009-09-17  9:09   ` Michal
2009-09-22  3:01 ` Kevin Rodgers [this message]
     [not found] ` <mailman.7167.1253588521.2239.help-gnu-emacs@gnu.org>
2009-09-22 16:05   ` Michal
2009-09-23  2:21     ` Kevin Rodgers
     [not found]     ` <mailman.7257.1253672525.2239.help-gnu-emacs@gnu.org>
2009-09-24 16:42       ` Michal
2009-09-25  2:48         ` Kevin Rodgers
     [not found]         ` <mailman.7485.1253846932.2239.help-gnu-emacs@gnu.org>
2009-09-28 16:24           ` Michal

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to='h99em7$p1q$1@ger.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).