unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* defadvice question.
@ 2009-09-16 13:52 Michal
  2009-09-17  0:16 ` Andreas Politz
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Michal @ 2009-09-16 13:52 UTC (permalink / raw)
  To: help-gnu-emacs

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?

best regards,
Michal


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
  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>
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Andreas Politz @ 2009-09-17  0:16 UTC (permalink / raw)
  To: help-gnu-emacs

Michal <rabbitko@tenbit.pl> writes:

> 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?
>
> best regards,
> Michal

I suspect that it does work, just not the way you expect it :
`add-to-list' does not insert duplicate elements into a list. That
means, if CVSROOT is already at some position in the
`minibuffer-history', this advice does nothing.

On the other hand, is this even necessary ? Peeking at the
`cvs-get-cvsroot' suggests, that CVSROOT is the default value anyway
(when calling `cvs-checkout' w/o prefix), unless you are already in a
cvs directory or the `cvs-root' variable is set.

-ap





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
       [not found] ` <mailman.6832.1253146594.2239.help-gnu-emacs@gnu.org>
@ 2009-09-17  9:09   ` Michal
  0 siblings, 0 replies; 9+ messages in thread
From: Michal @ 2009-09-17  9:09 UTC (permalink / raw)
  To: help-gnu-emacs


hallo Adreas

Andreas Politz <politza@fh-trier.de> writes:

> I suspect that it does work, just not the way you expect it :
> `add-to-list' does not insert duplicate elements into a list. That
> means, if CVSROOT is already at some position in the
> `minibuffer-history', this advice does nothing.

this is not on the list yet.

>
> On the other hand, is this even necessary ? Peeking at the
> `cvs-get-cvsroot' suggests, that CVSROOT is the default value anyway
> (when calling `cvs-checkout' w/o prefix), unless you are already in a
> cvs directory or the `cvs-root' variable is set.

I am calling cvs-checkout with prefix, because I need to add some
parameters to cvs ( -r BRANCH_NAME), so it also asks about the cvs root.

best regards,
MIchal


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
  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-22  3:01 ` Kevin Rodgers
       [not found] ` <mailman.7167.1253588521.2239.help-gnu-emacs@gnu.org>
  3 siblings, 0 replies; 9+ messages in thread
From: Kevin Rodgers @ 2009-09-22  3:01 UTC (permalink / raw)
  To: help-gnu-emacs

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





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
       [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>
  0 siblings, 2 replies; 9+ messages in thread
From: Michal @ 2009-09-22 16:05 UTC (permalink / raw)
  To: help-gnu-emacs


Hallo Kevin.
Thank You very much for the answer.
Unfortunately I have problems with both solutions.

Did You check if it works on YOur site, or this is rather Your suggestion?

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

>
> (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:

I C-u M-x cvs-checkout

call-interactively: Symbol's value as variable is void: \.\.\.


>
> (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)))))

While this does not produce any error message, but my cvs root is not
put to minibuffer history.

best regards


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
  2009-09-22 16:05   ` Michal
@ 2009-09-23  2:21     ` Kevin Rodgers
       [not found]     ` <mailman.7257.1253672525.2239.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Kevin Rodgers @ 2009-09-23  2:21 UTC (permalink / raw)
  To: help-gnu-emacs

Michal wrote:
> Hallo Kevin.
> Thank You very much for the answer.
> Unfortunately I have problems with both solutions.
> 
> Did You check if it works on YOur site, or this is rather Your suggestion?

I actually tested this suggestion.

> Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
> 
>> (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:
> 
> I C-u M-x cvs-checkout
> 
> call-interactively: Symbol's value as variable is void: \.\.\.

... was not meant to be evaluated literally.  Also, I did not attempt to handle
a prefix argument -- to do that, just add this binding to the let form:

	(prefix-arg current-prefix-arg)

>> (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)))))
> 
> While this does not produce any error message, but my cvs root is not
> put to minibuffer history.

What does M-: (getenv "CVSROOT") display?

cvs-checkout reads several arguments interactively, with different functions
that use different history variables.  Which prompt are you interested in,
"CVS Root: ", "Module(s): ", or "CVS Checkout Directory: "?

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
       [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>
  0 siblings, 2 replies; 9+ messages in thread
From: Michal @ 2009-09-24 16:42 UTC (permalink / raw)
  To: help-gnu-emacs


Hallo Kevin!

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

>>> 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:

then You rather meant just to copy these parameters by hand, didn't You?
sorry for my misunderstanding

> What does M-: (getenv "CVSROOT") display?
"michal@cvs.repository:/var/local/cvsroot"
>
> cvs-checkout reads several arguments interactively, with different functions
> that use different history variables.  Which prompt are you interested in,
> "CVS Root: ", "Module(s): ", or "CVS Checkout Directory: "?

"CVS Root:" one

best regards,
Michal


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
  2009-09-24 16:42       ` Michal
@ 2009-09-25  2:48         ` Kevin Rodgers
       [not found]         ` <mailman.7485.1253846932.2239.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Kevin Rodgers @ 2009-09-25  2:48 UTC (permalink / raw)
  To: help-gnu-emacs

Michal wrote:
> Hallo Kevin!
> 
> Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:
> 
>>>> 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:
> 
> then You rather meant just to copy these parameters by hand, didn't You?
> sorry for my misunderstanding

No problem, Michal.

>> What does M-: (getenv "CVSROOT") display?
> "michal@cvs.repository:/var/local/cvsroot"
>> cvs-checkout reads several arguments interactively, with different functions
>> that use different history variables.  Which prompt are you interested in,
>> "CVS Root: ", "Module(s): ", or "CVS Checkout Directory: "?
> 
> "CVS Root:" one

That is read with read-string, which uses minibuffer-history, so we got that
part right.

The problem is that I forgot to include this from your original post:
(ad-activate 'cvs-checkout)

I prefer to use the activate flag:
(defadvice cvs-checkout (before minibuffer-history activate)
   ...)

-- 
Kevin Rodgers
Denver, Colorado, USA





^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: defadvice question.
       [not found]         ` <mailman.7485.1253846932.2239.help-gnu-emacs@gnu.org>
@ 2009-09-28 16:24           ` Michal
  0 siblings, 0 replies; 9+ messages in thread
From: Michal @ 2009-09-28 16:24 UTC (permalink / raw)
  To: help-gnu-emacs


> I prefer to use the activate flag:
> (defadvice cvs-checkout (before minibuffer-history activate)
>   ...)

The thing I like most in emacs is that it is also used by people that do not know
the word "impossible".

Kevin, thank You very much for Your help.
Best regards,
Michal


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-09-28 16:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
     [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

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).