From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Tory S. Anderson" Newsgroups: gmane.emacs.help Subject: elisp newbie: simplifying from cl structures? Date: Sat, 7 Feb 2015 17:39:35 -0500 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1423348817 10100 80.91.229.3 (7 Feb 2015 22:40:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 7 Feb 2015 22:40:17 +0000 (UTC) To: emacs list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 07 23:40:13 2015 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 1YKE2v-0003s6-J3 for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Feb 2015 23:40:13 +0100 Original-Received: from localhost ([::1]:54755 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKE2u-00033H-Us for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Feb 2015 17:40:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKE2g-00032t-Cr for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 17:40:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKE2e-0006Tn-Br for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 17:39:58 -0500 Original-Received: from mail-ig0-x229.google.com ([2607:f8b0:4001:c05::229]:59110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKE2e-0006Th-3X for help-gnu-emacs@gnu.org; Sat, 07 Feb 2015 17:39:56 -0500 Original-Received: by mail-ig0-f169.google.com with SMTP id hl2so9111497igb.0 for ; Sat, 07 Feb 2015 14:39:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=DvBxNt4/RKUOWTRXpaUObhsOsIF+vKfvnbrdhEmRl08=; b=tj3e5XlkIC9khUWtwPbt7xHDk4NvFd51n8jU6g9k36aVm7fpvkpxrJFzhqZDJ27P4O OF1xira7LIj/oZf8jKW+31nWWsjqtqJ1Me/K4n+cuhCh4U0hdCQMeG1Z61jzSJrm3X/D 2mioX1kwZN48fzMu+oUt84auj1adJ/HlIjW6AVT73JIdNtoAF+yzsJXjhvQVF6baNO/M eTaN40f93E0VCvKTwx7KG9bBywxO4/wWn+q4RYG0x9PcBFOH+tBWJowM3HqBenq+kjKo shOAxVonQw5SMeXdDrcWwYjzKlYZ3KIGbKU156MTz0k4PApQPB/HDRW4n9enVd5oyfWJ iVLw== X-Received: by 10.50.143.38 with SMTP id sb6mr9485205igb.40.1423348795324; Sat, 07 Feb 2015 14:39:55 -0800 (PST) Original-Received: by 10.107.34.130 with HTTP; Sat, 7 Feb 2015 14:39:35 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c05::229 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 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:102567 Archived-At: This is a simple code question: I've got myself a little turned around and Practical Common Lisp just isn't coming to my mind right now (if it would apply anyway). Here's the situation: I've vastly simplified a set of functions, no longer needing various variables and assuming things (like the use of SSL). But I've gotten myself tangled up trying to simplify the old functions; now I get errors about expecting cl-list functions. I'm sure an experienced elisper will be able to set me straight with a glance. The purpose of this function is to look at my "From:" line in an email, compare it against a table, and use that to set the smtp variables that will be needed to grab the right info from my .authinfo. Here's the original, which I grabbed from someone's site[1] and have used successfully in older versions of emacs for years (note: it's mostly just the control structure that's confused me): --8<---------------cut here---------------start------------->8--- ;; (defun change-smtp () ;; "Change the SMTP server according to the current from line." ;; (save-excursion ;; (loop with from = (save-restriction ;; (message-narrow-to-headers) ;; (message-fetch-field "from")) ;; for (auth-mech address . auth-spec) in smtp-accounts ;; when (string-match address from) do (cond ;; ((memq auth-mech '(cram-md5 plain login)) ;; (return (apply 'set-smtp (cons auth-mech auth-spec)))) ;; ((eql auth-mech 'ssl) ;; (return (apply 'set-smtp-ssl auth-spec))) ;; (t (error "Unrecognized SMTP auth. mechanism: ;; `%s'." auth-mech))) finally (error "Cannot infer SMTP information.")))) --8<---------------cut here---------------end--------------->8--- Here is the not-quite working (won't evaluate) version I'm trying to build, now that I assume ssl and have dropped the variables in auth-spec: --8<---------------cut here---------------start------------->8--- (defun change-smtp () "Change the SMTP server according to the current from line." (save-excursion (loop with from = (save-restriction (message-narrow-to-headers) (message-fetch-field "from")) for (address server . port) in smtp-accounts if (string-match address from) (return (apply 'set-smtp server port address))) (error "Cannot infer SMTP information."))) --8<---------------cut here---------------end--------------->8--- And, to be complete, here is the data and function backing the problem function above, although they should be fine: --8<---------------cut here---------------start------------->8--- (defvar smtp-accounts "Accounts to be matched against outgoing messages' 'from' field. Assumes SSL. Of format `%address' `%server' `%port'. This will be used to match against the .authinfo file." '( ("me@mine.com" "mail.mine.com" 26);; Personal ("mail@me.com" "mail.mine3.com" 26);; Professional ("me2@mine.com" "mail.mine2.com" 26) ;; Web development ("mine@gmail.com" "smtp.gmail.com" 587) ;; Public )) (defun set-smtp (server port user) "Set related SMTP variables for supplied parameters. String `user' will not be evaluated." (setq smtpmail-smtp-server server smtpmail-smtp-service port) (message "Setting SMTP server to `%s:%s' for user `%s'." server port user)) --8<---------------cut here---------------end--------------->8--- A little help (with brief explanation) with the change-smtp function would be much appreciated. Footnotes: [1] http://www.mostlymaths.net/2010/12/emacs-30-day-challenge-using-gnus-to.html