From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Help needed to simplify code for customisation Date: Mon, 9 Mar 2009 23:44:45 -0700 (PDT) Organization: http://groups.google.com Message-ID: <46c6811e-771a-4162-a0c7-967b788793e1@v35g2000pro.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1236672827 476 80.91.229.12 (10 Mar 2009 08:13:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Mar 2009 08:13:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 10 09:15:04 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Lgx79-0000uR-Vl for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Mar 2009 09:15:04 +0100 Original-Received: from localhost ([127.0.0.1]:47256 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Lgx5n-00058N-SC for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Mar 2009 04:13:39 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!v35g2000pro.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs,comp.lang.lisp Original-Lines: 64 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1236667485 3754 127.0.0.1 (10 Mar 2009 06:44:45 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 10 Mar 2009 06:44:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v35g2000pro.googlegroups.com; posting-host=24.6.175.142; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:167495 comp.emacs:97978 comp.lang.lisp:262558 X-Mailman-Approved-At: Tue, 10 Mar 2009 04:13:15 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:62806 Archived-At: On Mar 9, 7:14 pm, Richard Riley wrote: > Could someone please recommend the best way to remove the 3 similar lines > doing string-match on the "account" assign and iterate a variable list to > which I can "add-to-list" in other .el libraries for example? > > ,---- > | (if (message-mail-p) > | (save-excursion > | (let* ((from > | (save-restriction > | (message-narrow-to-headers) > | (message-fetch-field "from"))) > | (account > | (cond > | ((string-match ".*root.*" from)"richardriley") > | ((string-match ".*richardriley.*" from)"richardriley") > | ((string-match ".*rileyrgdev.*" from)"rileyrgdev") > | )) > | ) > | (setq message-sendmail-extra-arguments (list "-a" account)) > | ))) > | ) > `---- perhaps something like the following. The code is tested. (defun canonicalString (from pairs) "Returns the canonical string of FROM, determined by the pairs in PAIRS. The PAIRS should be a nested vector of the form: =E2=80=9C[[\"a\" \"=CE=B1\"] [\"b\" \"=CE=B2\"] [\"=CE=B3\" \"g\"] ...]=E2= =80=9D where the first element is a regex string to be matched with FROM. If match, then the second element is returned. If no match is found, nil is returned. Example: (canonicalString \"b\" [[\"a\" \"=CE=B1\"] [\"b\" \"=CE=B2\"] [\"=CE=B3\" = \"g\"]]) returns \"=CE=B2\". " (let (totalItems matchFound i result) (setq totalItems (length pairs)) (setq foundMatch nil) (setq i 0) (while (and (not matchFound) (not (=3D i totalItems))) (if (string-match (elt (elt pairs i) 0) from) (progn (setq result (elt (elt pairs i) 1)) (setq matchFound t))) (setq i (1+ i))) result)) ; testing (canonicalString "b" [["a" "=CE=B1"] ["b" "=CE=B2"] ["=CE=B3" "g"]]) Xah =E2=88=91 http://xahlee.org/ =E2=98=84