all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "WJ" <w_a_x_man@yahoo.com>
To: help-gnu-emacs@gnu.org
Subject: Re: emacs lisp. Is there a rassoc-default for getting ALL elementsmatching a VALUE?
Date: Fri, 26 Dec 2014 09:57:38 +0000 (UTC)	[thread overview]
Message-ID: <m7jbeg$u0j$1@dont-email.me> (raw)
In-Reply-To: jj5ouk02i3c@enews4.newsguy.com

WJ wrote:

> Xah Lee wrote:
> 
> > 
> > emacs lisp. Is there a rassoc-default for getting ALL elements
> > matching a VALUE?
> > 
> > emas lisp. Is there a rassoc-default function? i.e. similar to assoc-
> > default but get all items of a alist of a give value.
> > 
> > i want to be able to properly setup cperl-mode to load instead of perl-
> > mode. Here's detail.
> > 
> > easy way is just
> >  (defalias 'perl-mode 'cperl-mode)
> > 
> > but the problem with that is you can't call perl-mode anymore, if you
> > still want it on occasion.
> > 
> > So, i went to set the auto-mode-alist. Like this:
> > 
> >  (setq auto-mode-alist (rassq-delete-all 'perl-mode auto-mode-alist))
> >  (add-to-list 'auto-mode-alist '("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al
> > \\)\\'" . cperl-mode))
> > 
> > that turns out doesn't do it, because there's also interpreter-mode-
> > alist. So i wrote:
> > 
> > (when
> >     (rassoc 'perl-mode interpreter-mode-alist)
> >   (let ((mykey (car (rassoc 'perl-mode interpreter-mode-alist)) ))
> >     (setq interpreter-mode-alist (rassq-delete-all 'perl-mode
> > interpreter-mode-alist))
> >     (add-to-list 'interpreter-mode-alist (mykey . 'cperl-mode))
> >     )
> >   )
> > 
> > but i discovered there are actually several elements for perl in that
> > alist:
> > 
> >  ("perl" . perl-mode)
> >  ("perl5" . perl-mode)
> >  ("miniperl" . perl-mode)
> > 
> > So my code above won't work.
> > 
> > So, the proper way is to query for the value 'perl-mode, get ALL
> > results, then remove them all, then add them all back with 'cperl-
> > mode.

elisp:

(mapcar
  (lambda (x)
    (let ((k (car x)) (v (cdr x)))
      (if (eq 'perl-mode v)
        (cons k 'cperl-mode)
        x)))
  '(("foo" . bar)
    ("perl" . perl-mode)
    ("perl5" . perl-mode)
    ("miniperl" . perl-mode)
    ("whiz" . bang)))

 ===>
(("foo" . bar) ("perl" . cperl-mode) ("perl5" . cperl-mode)
 ("miniperl" . cperl-mode) ("whiz" . bang))


           reply	other threads:[~2014-12-26  9:57 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <jj5ouk02i3c@enews4.newsguy.com>]

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='m7jbeg$u0j$1@dont-email.me' \
    --to=w_a_x_man@yahoo.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.