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

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

Re: Change a symbol's plist member with (let ...)?


From: Nicolas Richard
Subject: Re: Change a symbol's plist member with (let ...)?
Date: Fri, 14 Mar 2014 22:37:29 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Thorsten Jolitz <address@hidden> writes:
> #+begin_src emacs-lisp
>   (plist-get (symbol-plist 'outline-mode)
>              'derived-mode-parent) 
> #+end_src
>

(get 'outline-mode 'derived-mode-parent) looks better to me.

> For the sake of this example, say I want to "con" the function
> `derived-mode-p' and make it believe outline-mode is actually derived
> from lisp-mode (or so ...).
>
> How to do this with working code (not pseudo-code)?

I'm in message-mode right now, and :
  (derived-mode-p 'text-mode)
returns: text-mode

But
(letf (((get major-mode 'derived-mode-parent) 'special-mode))
           (derived-mode-p 'text-mode))
returns nil.

You could also let-bind major-mode to whatever the code you're calling
expects.

> Or do I have to do it the pedestrian way: do plist-get first, store the
> original value, do plist-put with the new value, call ad-do-it, and then
> restore the original value again with plist-put?

If you already know what you want the function to return, you could simply make
the advice return that value and not call ad-do-it at all.

-- 
Nico.



reply via email to

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