From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "WJ" Newsgroups: gmane.emacs.help 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) Organization: A noiseless patient Spider Message-ID: References: <75505678-f49c-415b-b682-4461d544820c@t8g2000prm.googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-7 X-Trace: ger.gmane.org 1419588034 23610 80.91.229.3 (26 Dec 2014 10:00:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 26 Dec 2014 10:00:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Dec 26 11:00:28 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y4Rh5-0008Mb-3k for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Dec 2014 11:00:27 +0100 Original-Received: from localhost ([::1]:52867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y4Rh4-0001xA-E4 for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Dec 2014 05:00:26 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!feeds.phibee-telecom.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.lang.lisp Original-Lines: 68 Injection-Date: Fri, 26 Dec 2014 09:57:38 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="457c4918966ac75337bd5bc691637b7b"; logging-data="30739"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Kt3gNpWoxz31tked7Nd1o" User-Agent: XanaNews/1.18.1.6 X-Antivirus-Status: Clean X-Antivirus: avast! (VPS 141225-1, 12/25/2014), Outbound message Cancel-Lock: sha1:5WoqknHbm2nEFC9m8viBlfsAij8= Original-Xref: usenet.stanford.edu gnu.emacs.help:209446 comp.lang.lisp:319974 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:101725 Archived-At: 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))