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

2011-12-21 Thread Jani Nikula
On Wed, 21 Dec 2011 09:40:08 -0500, Austin Clements  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



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

2011-12-21 Thread Jani Nikula
On Wed, 21 Dec 2011 09:40:08 -0500, Austin Clements  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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-12-21 Thread Austin Clements
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  
> 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.


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

2011-12-21 Thread David Edmondson
On Tue, 20 Dec 2011 16:52:52 -0500, Austin Clements  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: 



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

2011-12-21 Thread Austin Clements
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  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.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-12-21 Thread David Edmondson
On Tue, 20 Dec 2011 16:52:52 -0500, Austin Clements  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


pgpAXhHNPcNya.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-12-21 Thread Dmitry Kurochkin
Hi Jani.

On Tue, 20 Dec 2011 22:05:31 +0200, Jani Nikula  wrote:
> 
> Shameless promotion of own patches... I suppose not many use the
> notmuch-wash-convert-inline-patch-to-part option, but with this patch
> I've actually started to like it better. An actual patch name from
> subject instead of "inline patch".
> 
> As I said, the lisp is less than perfect here, but this is still better
> than what's existing.
> 
> Any comments?
> 

I do not use the option but the patch sounds useful to me.  I would try
to review it soon.

I think a simple test would be useful here BTW.

Regards,
  Dmitry

> 
> BR,
> Jani.
> 
> 
> On Sat, 19 Nov 2011 01:02:48 +0200, Jani Nikula  wrote:
> > Use the mail subject line for creating a descriptive filename for the wash
> > generated inline patch fake parts. The names are similar to the ones
> > created by 'git format-patch', just without the leading numbers.
> > 
> > Signed-off-by: Jani Nikula 
> > 
> > ---
> > 
> > I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
> > welcome on how to make it lispy and keep it somewhat readable.
> > 
> > If we later want to have a '>' counterpart to '|' to save messages to files
> > rather than pipe, then this could be generalized and re-used for creating
> > the suggested filename for that.
> > 
> > I don't even use the notmuch-wash-convert-inline-patch-to-part option that
> > much, but having it suggest "inline patch" as filename is just ugly...
> > ---
> >  emacs/notmuch-wash.el |   16 +++-
> >  1 files changed, 15 insertions(+), 1 deletions(-)
> > 
> > diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
> > index 1f420b2..755d64a 100644
> > --- a/emacs/notmuch-wash.el
> > +++ b/emacs/notmuch-wash.el
> > @@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the 
> > wrapped text."
> >  
> >  (defvar diff-file-header-re) ; From `diff-mode.el'.
> >  
> > +(defun notmuch-subject-to-patch-filename (str)
> > +  "Convert a typical patch mail subject line into a suitable filename."
> > +  (let ((s str))
> > +(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
> > +(setq s (replace-regexp-in-string "[. ]*$" "" s))
> > +(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
> > +(setq s (replace-regexp-in-string "\\.+" "." s))
> > +(when (> (length s) 52)
> > +  (setq s (substring s 0 52)))
> > +(concat s ".patch")))
> > +
> >  (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
> >"Convert an inline patch into a fake 'text/x-diff' attachment.
> >  
> > @@ -316,7 +327,10 @@ for error."
> > (setq part (plist-put part :content-type "text/x-diff"))
> > (setq part (plist-put part :content (buffer-string)))
> > (setq part (plist-put part :id -1))
> > -   (setq part (plist-put part :filename "inline patch"))
> > +   (setq part (plist-put part :filename
> > + (notmuch-subject-to-patch-filename
> > +  (plist-get
> > +   (plist-get msg :headers) :Subject
> > (delete-region (point-min) (point-max))
> > (notmuch-show-insert-bodypart nil part depth))
> >  
> > -- 
> > 1.7.5.4
> > 
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-12-20 Thread Jani Nikula

Shameless promotion of own patches... I suppose not many use the
notmuch-wash-convert-inline-patch-to-part option, but with this patch
I've actually started to like it better. An actual patch name from
subject instead of "inline patch".

As I said, the lisp is less than perfect here, but this is still better
than what's existing.

Any comments?


BR,
Jani.


On Sat, 19 Nov 2011 01:02:48 +0200, Jani Nikula  wrote:
> Use the mail subject line for creating a descriptive filename for the wash
> generated inline patch fake parts. The names are similar to the ones
> created by 'git format-patch', just without the leading numbers.
> 
> Signed-off-by: Jani Nikula 
> 
> ---
> 
> I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
> welcome on how to make it lispy and keep it somewhat readable.
> 
> If we later want to have a '>' counterpart to '|' to save messages to files
> rather than pipe, then this could be generalized and re-used for creating
> the suggested filename for that.
> 
> I don't even use the notmuch-wash-convert-inline-patch-to-part option that
> much, but having it suggest "inline patch" as filename is just ugly...
> ---
>  emacs/notmuch-wash.el |   16 +++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
> 
> diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
> index 1f420b2..755d64a 100644
> --- a/emacs/notmuch-wash.el
> +++ b/emacs/notmuch-wash.el
> @@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the 
> wrapped text."
>  
>  (defvar diff-file-header-re) ; From `diff-mode.el'.
>  
> +(defun notmuch-subject-to-patch-filename (str)
> +  "Convert a typical patch mail subject line into a suitable filename."
> +  (let ((s str))
> +(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
> +(setq s (replace-regexp-in-string "[. ]*$" "" s))
> +(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
> +(setq s (replace-regexp-in-string "\\.+" "." s))
> +(when (> (length s) 52)
> +  (setq s (substring s 0 52)))
> +(concat s ".patch")))
> +
>  (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
>"Convert an inline patch into a fake 'text/x-diff' attachment.
>  
> @@ -316,7 +327,10 @@ for error."
>   (setq part (plist-put part :content-type "text/x-diff"))
>   (setq part (plist-put part :content (buffer-string)))
>   (setq part (plist-put part :id -1))
> - (setq part (plist-put part :filename "inline patch"))
> + (setq part (plist-put part :filename
> +   (notmuch-subject-to-patch-filename
> +(plist-get
> + (plist-get msg :headers) :Subject
>   (delete-region (point-min) (point-max))
>   (notmuch-show-insert-bodypart nil part depth))
>  
> -- 
> 1.7.5.4
> 


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

2011-12-20 Thread Austin Clements
Seems like a definite improvement, but perhaps a let* instead of all
of the setq's?

Quoth Jani Nikula on Dec 20 at 10:05 pm:
> 
> Shameless promotion of own patches... I suppose not many use the
> notmuch-wash-convert-inline-patch-to-part option, but with this patch
> I've actually started to like it better. An actual patch name from
> subject instead of "inline patch".
> 
> As I said, the lisp is less than perfect here, but this is still better
> than what's existing.
> 
> Any comments?
> 
> 
> BR,
> Jani.
> 
> 
> On Sat, 19 Nov 2011 01:02:48 +0200, Jani Nikula  wrote:
> > Use the mail subject line for creating a descriptive filename for the wash
> > generated inline patch fake parts. The names are similar to the ones
> > created by 'git format-patch', just without the leading numbers.
> > 
> > Signed-off-by: Jani Nikula 
> > 
> > ---
> > 
> > I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
> > welcome on how to make it lispy and keep it somewhat readable.
> > 
> > If we later want to have a '>' counterpart to '|' to save messages to files
> > rather than pipe, then this could be generalized and re-used for creating
> > the suggested filename for that.
> > 
> > I don't even use the notmuch-wash-convert-inline-patch-to-part option that
> > much, but having it suggest "inline patch" as filename is just ugly...
> > ---
> >  emacs/notmuch-wash.el |   16 +++-
> >  1 files changed, 15 insertions(+), 1 deletions(-)
> > 
> > diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
> > index 1f420b2..755d64a 100644
> > --- a/emacs/notmuch-wash.el
> > +++ b/emacs/notmuch-wash.el
> > @@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the 
> > wrapped text."
> >  
> >  (defvar diff-file-header-re) ; From `diff-mode.el'.
> >  
> > +(defun notmuch-subject-to-patch-filename (str)
> > +  "Convert a typical patch mail subject line into a suitable filename."
> > +  (let ((s str))
> > +(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
> > +(setq s (replace-regexp-in-string "[. ]*$" "" s))
> > +(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
> > +(setq s (replace-regexp-in-string "\\.+" "." s))
> > +(when (> (length s) 52)
> > +  (setq s (substring s 0 52)))
> > +(concat s ".patch")))
> > +
> >  (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
> >"Convert an inline patch into a fake 'text/x-diff' attachment.
> >  
> > @@ -316,7 +327,10 @@ for error."
> > (setq part (plist-put part :content-type "text/x-diff"))
> > (setq part (plist-put part :content (buffer-string)))
> > (setq part (plist-put part :id -1))
> > -   (setq part (plist-put part :filename "inline patch"))
> > +   (setq part (plist-put part :filename
> > + (notmuch-subject-to-patch-filename
> > +  (plist-get
> > +   (plist-get msg :headers) :Subject
> > (delete-region (point-min) (point-max))
> > (notmuch-show-insert-bodypart nil part depth))


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

2011-12-20 Thread Austin Clements
Seems like a definite improvement, but perhaps a let* instead of all
of the setq's?

Quoth Jani Nikula on Dec 20 at 10:05 pm:
> 
> Shameless promotion of own patches... I suppose not many use the
> notmuch-wash-convert-inline-patch-to-part option, but with this patch
> I've actually started to like it better. An actual patch name from
> subject instead of "inline patch".
> 
> As I said, the lisp is less than perfect here, but this is still better
> than what's existing.
> 
> Any comments?
> 
> 
> BR,
> Jani.
> 
> 
> On Sat, 19 Nov 2011 01:02:48 +0200, Jani Nikula  wrote:
> > Use the mail subject line for creating a descriptive filename for the wash
> > generated inline patch fake parts. The names are similar to the ones
> > created by 'git format-patch', just without the leading numbers.
> > 
> > Signed-off-by: Jani Nikula 
> > 
> > ---
> > 
> > I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
> > welcome on how to make it lispy and keep it somewhat readable.
> > 
> > If we later want to have a '>' counterpart to '|' to save messages to files
> > rather than pipe, then this could be generalized and re-used for creating
> > the suggested filename for that.
> > 
> > I don't even use the notmuch-wash-convert-inline-patch-to-part option that
> > much, but having it suggest "inline patch" as filename is just ugly...
> > ---
> >  emacs/notmuch-wash.el |   16 +++-
> >  1 files changed, 15 insertions(+), 1 deletions(-)
> > 
> > diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
> > index 1f420b2..755d64a 100644
> > --- a/emacs/notmuch-wash.el
> > +++ b/emacs/notmuch-wash.el
> > @@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the 
> > wrapped text."
> >  
> >  (defvar diff-file-header-re) ; From `diff-mode.el'.
> >  
> > +(defun notmuch-subject-to-patch-filename (str)
> > +  "Convert a typical patch mail subject line into a suitable filename."
> > +  (let ((s str))
> > +(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
> > +(setq s (replace-regexp-in-string "[. ]*$" "" s))
> > +(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
> > +(setq s (replace-regexp-in-string "\\.+" "." s))
> > +(when (> (length s) 52)
> > +  (setq s (substring s 0 52)))
> > +(concat s ".patch")))
> > +
> >  (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
> >"Convert an inline patch into a fake 'text/x-diff' attachment.
> >  
> > @@ -316,7 +327,10 @@ for error."
> > (setq part (plist-put part :content-type "text/x-diff"))
> > (setq part (plist-put part :content (buffer-string)))
> > (setq part (plist-put part :id -1))
> > -   (setq part (plist-put part :filename "inline patch"))
> > +   (setq part (plist-put part :filename
> > + (notmuch-subject-to-patch-filename
> > +  (plist-get
> > +   (plist-get msg :headers) :Subject
> > (delete-region (point-min) (point-max))
> > (notmuch-show-insert-bodypart nil part depth))
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-12-20 Thread Dmitry Kurochkin
Hi Jani.

On Tue, 20 Dec 2011 22:05:31 +0200, Jani Nikula  wrote:
> 
> Shameless promotion of own patches... I suppose not many use the
> notmuch-wash-convert-inline-patch-to-part option, but with this patch
> I've actually started to like it better. An actual patch name from
> subject instead of "inline patch".
> 
> As I said, the lisp is less than perfect here, but this is still better
> than what's existing.
> 
> Any comments?
> 

I do not use the option but the patch sounds useful to me.  I would try
to review it soon.

I think a simple test would be useful here BTW.

Regards,
  Dmitry

> 
> BR,
> Jani.
> 
> 
> On Sat, 19 Nov 2011 01:02:48 +0200, Jani Nikula  wrote:
> > Use the mail subject line for creating a descriptive filename for the wash
> > generated inline patch fake parts. The names are similar to the ones
> > created by 'git format-patch', just without the leading numbers.
> > 
> > Signed-off-by: Jani Nikula 
> > 
> > ---
> > 
> > I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
> > welcome on how to make it lispy and keep it somewhat readable.
> > 
> > If we later want to have a '>' counterpart to '|' to save messages to files
> > rather than pipe, then this could be generalized and re-used for creating
> > the suggested filename for that.
> > 
> > I don't even use the notmuch-wash-convert-inline-patch-to-part option that
> > much, but having it suggest "inline patch" as filename is just ugly...
> > ---
> >  emacs/notmuch-wash.el |   16 +++-
> >  1 files changed, 15 insertions(+), 1 deletions(-)
> > 
> > diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
> > index 1f420b2..755d64a 100644
> > --- a/emacs/notmuch-wash.el
> > +++ b/emacs/notmuch-wash.el
> > @@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the 
> > wrapped text."
> >  
> >  (defvar diff-file-header-re) ; From `diff-mode.el'.
> >  
> > +(defun notmuch-subject-to-patch-filename (str)
> > +  "Convert a typical patch mail subject line into a suitable filename."
> > +  (let ((s str))
> > +(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
> > +(setq s (replace-regexp-in-string "[. ]*$" "" s))
> > +(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
> > +(setq s (replace-regexp-in-string "\\.+" "." s))
> > +(when (> (length s) 52)
> > +  (setq s (substring s 0 52)))
> > +(concat s ".patch")))
> > +
> >  (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
> >"Convert an inline patch into a fake 'text/x-diff' attachment.
> >  
> > @@ -316,7 +327,10 @@ for error."
> > (setq part (plist-put part :content-type "text/x-diff"))
> > (setq part (plist-put part :content (buffer-string)))
> > (setq part (plist-put part :id -1))
> > -   (setq part (plist-put part :filename "inline patch"))
> > +   (setq part (plist-put part :filename
> > + (notmuch-subject-to-patch-filename
> > +  (plist-get
> > +   (plist-get msg :headers) :Subject
> > (delete-region (point-min) (point-max))
> > (notmuch-show-insert-bodypart nil part depth))
> >  
> > -- 
> > 1.7.5.4
> > 
> ___
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-12-20 Thread Jani Nikula

Shameless promotion of own patches... I suppose not many use the
notmuch-wash-convert-inline-patch-to-part option, but with this patch
I've actually started to like it better. An actual patch name from
subject instead of "inline patch".

As I said, the lisp is less than perfect here, but this is still better
than what's existing.

Any comments?


BR,
Jani.


On Sat, 19 Nov 2011 01:02:48 +0200, Jani Nikula  wrote:
> Use the mail subject line for creating a descriptive filename for the wash
> generated inline patch fake parts. The names are similar to the ones
> created by 'git format-patch', just without the leading numbers.
> 
> Signed-off-by: Jani Nikula 
> 
> ---
> 
> I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
> welcome on how to make it lispy and keep it somewhat readable.
> 
> If we later want to have a '>' counterpart to '|' to save messages to files
> rather than pipe, then this could be generalized and re-used for creating
> the suggested filename for that.
> 
> I don't even use the notmuch-wash-convert-inline-patch-to-part option that
> much, but having it suggest "inline patch" as filename is just ugly...
> ---
>  emacs/notmuch-wash.el |   16 +++-
>  1 files changed, 15 insertions(+), 1 deletions(-)
> 
> diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
> index 1f420b2..755d64a 100644
> --- a/emacs/notmuch-wash.el
> +++ b/emacs/notmuch-wash.el
> @@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the 
> wrapped text."
>  
>  (defvar diff-file-header-re) ; From `diff-mode.el'.
>  
> +(defun notmuch-subject-to-patch-filename (str)
> +  "Convert a typical patch mail subject line into a suitable filename."
> +  (let ((s str))
> +(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
> +(setq s (replace-regexp-in-string "[. ]*$" "" s))
> +(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
> +(setq s (replace-regexp-in-string "\\.+" "." s))
> +(when (> (length s) 52)
> +  (setq s (substring s 0 52)))
> +(concat s ".patch")))
> +
>  (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
>"Convert an inline patch into a fake 'text/x-diff' attachment.
>  
> @@ -316,7 +327,10 @@ for error."
>   (setq part (plist-put part :content-type "text/x-diff"))
>   (setq part (plist-put part :content (buffer-string)))
>   (setq part (plist-put part :id -1))
> - (setq part (plist-put part :filename "inline patch"))
> + (setq part (plist-put part :filename
> +   (notmuch-subject-to-patch-filename
> +(plist-get
> + (plist-get msg :headers) :Subject
>   (delete-region (point-min) (point-max))
>   (notmuch-show-insert-bodypart nil part depth))
>  
> -- 
> 1.7.5.4
> 
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


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

2011-11-19 Thread Jani Nikula
Use the mail subject line for creating a descriptive filename for the wash
generated inline patch fake parts. The names are similar to the ones
created by 'git format-patch', just without the leading numbers.

Signed-off-by: Jani Nikula 

---

I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
welcome on how to make it lispy and keep it somewhat readable.

If we later want to have a '>' counterpart to '|' to save messages to files
rather than pipe, then this could be generalized and re-used for creating
the suggested filename for that.

I don't even use the notmuch-wash-convert-inline-patch-to-part option that
much, but having it suggest "inline patch" as filename is just ugly...
---
 emacs/notmuch-wash.el |   16 +++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 1f420b2..755d64a 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the wrapped 
text."

 (defvar diff-file-header-re) ; From `diff-mode.el'.

+(defun notmuch-subject-to-patch-filename (str)
+  "Convert a typical patch mail subject line into a suitable filename."
+  (let ((s str))
+(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
+(setq s (replace-regexp-in-string "[. ]*$" "" s))
+(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
+(setq s (replace-regexp-in-string "\\.+" "." s))
+(when (> (length s) 52)
+  (setq s (substring s 0 52)))
+(concat s ".patch")))
+
 (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
   "Convert an inline patch into a fake 'text/x-diff' attachment.

@@ -316,7 +327,10 @@ for error."
(setq part (plist-put part :content-type "text/x-diff"))
(setq part (plist-put part :content (buffer-string)))
(setq part (plist-put part :id -1))
-   (setq part (plist-put part :filename "inline patch"))
+   (setq part (plist-put part :filename
+ (notmuch-subject-to-patch-filename
+  (plist-get
+   (plist-get msg :headers) :Subject
(delete-region (point-min) (point-max))
(notmuch-show-insert-bodypart nil part depth))

-- 
1.7.5.4



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

2011-11-18 Thread Jani Nikula
Use the mail subject line for creating a descriptive filename for the wash
generated inline patch fake parts. The names are similar to the ones
created by 'git format-patch', just without the leading numbers.

Signed-off-by: Jani Nikula 

---

I know notmuch-subject-to-patch-filename is totally un-lispy. Suggestions
welcome on how to make it lispy and keep it somewhat readable.

If we later want to have a '>' counterpart to '|' to save messages to files
rather than pipe, then this could be generalized and re-used for creating
the suggested filename for that.

I don't even use the notmuch-wash-convert-inline-patch-to-part option that
much, but having it suggest "inline patch" as filename is just ugly...
---
 emacs/notmuch-wash.el |   16 +++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 1f420b2..755d64a 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -290,6 +290,17 @@ When doing so, maintaining citation leaders in the wrapped 
text."
 
 (defvar diff-file-header-re) ; From `diff-mode.el'.
 
+(defun notmuch-subject-to-patch-filename (str)
+  "Convert a typical patch mail subject line into a suitable filename."
+  (let ((s str))
+(setq s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s))
+(setq s (replace-regexp-in-string "[. ]*$" "" s))
+(setq s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s))
+(setq s (replace-regexp-in-string "\\.+" "." s))
+(when (> (length s) 52)
+  (setq s (substring s 0 52)))
+(concat s ".patch")))
+
 (defun notmuch-wash-convert-inline-patch-to-part (msg depth)
   "Convert an inline patch into a fake 'text/x-diff' attachment.
 
@@ -316,7 +327,10 @@ for error."
(setq part (plist-put part :content-type "text/x-diff"))
(setq part (plist-put part :content (buffer-string)))
(setq part (plist-put part :id -1))
-   (setq part (plist-put part :filename "inline patch"))
+   (setq part (plist-put part :filename
+ (notmuch-subject-to-patch-filename
+  (plist-get
+   (plist-get msg :headers) :Subject
(delete-region (point-min) (point-max))
(notmuch-show-insert-bodypart nil part depth))
 
-- 
1.7.5.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch