unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Nicolas Richard <theonewiththeevillook@yahoo.fr>
To: Thorsten Jolitz <tjolitz@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Change a symbol's plist member with (let ...)?
Date: Fri, 14 Mar 2014 22:37:29 +0100	[thread overview]
Message-ID: <87iorg31ie.fsf@yahoo.fr> (raw)
In-Reply-To: <87wqfwo4yp.fsf@gmail.com> (Thorsten Jolitz's message of "Fri, 14 Mar 2014 22:17:18 +0100")

Thorsten Jolitz <tjolitz@gmail.com> 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	other threads:[~2014-03-14 21:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-14 21:17 Change a symbol's plist member with (let ...)? Thorsten Jolitz
2014-03-14 21:37 ` Nicolas Richard [this message]
2014-03-14 22:25   ` Thorsten Jolitz
2014-03-15 21:28     ` Nicolas Richard
2014-03-16 16:01       ` Thorsten Jolitz
2014-03-16 18:10 ` Stefan
2014-03-17  0:49   ` Thorsten Jolitz

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=87iorg31ie.fsf@yahoo.fr \
    --to=theonewiththeevillook@yahoo.fr \
    --cc=help-gnu-emacs@gnu.org \
    --cc=tjolitz@gmail.com \
    /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).