On Tue, 20 Dec 2011 16:52:52 -0500, Austin Clements <amdragon at MIT.EDU> wrote:
> Seems like a definite improvement, but perhaps a let* instead of all
> of the setq's?

What would be a lispy approach? I tried:

(defun notmuch-subject-to-patch-filename (subject)
  "Convert a typical patch mail subject line into a suitable filename."
  (concat 
   (let ((filename subject)
         (transforms
          '(("^ *\\(\\[[^]]*\\]\\)? *" . "")
            ("[. ]*$" . "")
            ("[^A-Za-z0-9._-]+" . "-")
            ("\\.+" . "."))))
     (mapc (lambda (transform)
             (setq filename (replace-regexp-in-string (car transform) (cdr 
transform) filename)))
           transforms)
     (substring filename 0 (min (length filename) 50)))
   ".patch"))

...but that seems a bit unwieldy. `let*' looks best, but still feels a
bit odd:

(defun notmuch-subject-to-patch-filename (subject)
  "Convert a typical patch mail subject line into a suitable filename."
  (concat 
   (let* ((filename (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" 
subject))
          (filename (replace-regexp-in-string "[. ]*$" "" filename))
          (filename (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" filename))
          (filename (replace-regexp-in-string "\\.+" "." filename)))
     (substring filename 0 (min (length filename) 50)))
   ".patch"))

dme.
-- 
David Edmondson, http://dme.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20111221/f9b88266/attachment-0001.pgp>

Reply via email to