From: Austin Clements <amdragon@MIT.EDU>
To: David Edmondson <dme@dme.org>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH] emacs: create patch filename from subject for inline patch fake parts
Date: Wed, 21 Dec 2011 09:40:08 -0500 [thread overview]
Message-ID: <20111221144008.GG10376@mit.edu> (raw)
In-Reply-To: <cun4nwuxota.fsf@hotblack-desiato.hh.sledj.net>
I would definitely go with the latter.
It might feel less unwieldy with a shorter variable name than
"filename", since that has to be repeated so many times. (It's also
not really a filename in the middle of the replace process.)
This is splitting hairs, but in my original suggestion, I was thinking
something like
(let* ((s subject)
(s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
(s (replace-regexp-in-string "[. ]*$" "" s))
(s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
(s (replace-regexp-in-string "\\.+" "." s))
(s (substring s 0 (min (length s) 50))))
(concat s ".patch"))
Out of curiosity, where'd the regexps come from? They all seem
reasonable, but some of them seem somewhat arbitrary.
Quoth David Edmondson on Dec 21 at 9:21 am:
> On Tue, 20 Dec 2011 16:52:52 -0500, Austin Clements <amdragon@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.
next prev parent reply other threads:[~2011-12-21 14:39 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-18 23:02 [PATCH] emacs: create patch filename from subject for inline patch fake parts Jani Nikula
2011-12-20 20:05 ` Jani Nikula
2011-12-20 20:11 ` Dmitry Kurochkin
2011-12-20 21:52 ` Austin Clements
2011-12-21 9:21 ` David Edmondson
2011-12-21 14:40 ` Austin Clements [this message]
2011-12-21 20:21 ` Jani Nikula
2011-12-25 22:00 ` [PATCH v2 0/2] emacs: patch filename from subject Jani Nikula
2011-12-25 22:00 ` [PATCH v2 1/2] emacs: create patch filename from subject for inline patch fake parts Jani Nikula
2011-12-26 12:06 ` David Edmondson
2011-12-26 12:24 ` Jani Nikula
2011-12-26 20:38 ` Jameson Graef Rollins
2011-12-26 21:52 ` Jani Nikula
2011-12-26 22:05 ` David Edmondson
2011-12-25 22:00 ` [PATCH v2 2/2] test: emacs: test notmuch-wash-subject-to-* functions Jani Nikula
2011-12-27 16:04 ` [PATCH v3 0/3] emacs: patch filename from subject Jani Nikula
2011-12-27 16:04 ` [PATCH v3 1/3] emacs: add inline patch fake parts through a special handler Jani Nikula
2011-12-27 16:04 ` [PATCH v3 2/3] emacs: create patch filename from subject for inline patch fake parts Jani Nikula
2011-12-27 16:04 ` [PATCH v3 3/3] test: emacs: test notmuch-wash-subject-to-* functions Jani Nikula
2011-12-28 12:22 ` [PATCH v3 0/3] emacs: patch filename from subject David Bremner
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
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111221144008.GG10376@mit.edu \
--to=amdragon@mit.edu \
--cc=dme@dme.org \
--cc=notmuch@notmuchmail.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 public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).