[PATCH] emacs: create patch filename from subject for inline patch fake parts

Jani Nikula jani at nikula.org
Wed Dec 21 12:21:27 PST 2011


On Wed, 21 Dec 2011 09:40:08 -0500, Austin Clements <amdragon at MIT.EDU> wrote:
> 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.

The regexps should definitely have some explanation. I tried to mimic
the 'git format-patch' behaviour [1] using as simple and straightforward
regexps as possible. For simplicity, there's no creation of patch
sequence numbers. The max length is the same as in git, excluding the
sequence number.

If the patch was sent using git format-patch/send-email, this should
result in re-creation of the same filename as the sender had (apart from
the sequence number, obviously).

I seem to be missing the trimming of any trailing '.' and '-' after
truncating the string to max length, though.


BR,
Jani.

[1] https://github.com/gitster/git/blob/master/pretty.c#L712



More information about the notmuch mailing list