How to fontify PATCH mail

49 views
Skip to first unread message

coldnew

unread,
Oct 7, 2012, 10:59:18 AM10/7/12
to mu-di...@googlegroups.com
Hello:

        I use mu4e to read mailing-list, is there a elegant way to fontify those [PATCH] mail ?

       following is my code, but it can not work when I enter the mu4e-view-mode, I must use it manually

  (defun mu4e~view-fontify-diff ()
    "Colorize diff message."
    (interactive)
    (let ((inhibit-read-only t))
      (save-excursion
        (goto-char (point-min))
        (while (re-search-forward "^\\(\\(\\+\\)[^+]\\|\\(-\\)[^-]\\)" nil t)
          (let ((cur-point (or (match-beginning 2) (match-beginning 3)))
                (color (if (match-beginning 2)
                           "green"
                         "deep pink")))
            (end-of-line)
            (add-text-properties cur-point (point)
                                 `(face ((foreground-color . ,color))))))
        (goto-char (point-min))
        (while (re-search-forward "^\\(\\+\\+\\+\\|---\\)" nil t)
          (let ((cur-point (match-beginning 1)))
            (end-of-line)
            (add-text-properties cur-point (point)
                                 '(face ((weight . bold)))))))))

  (add-hook 'mu4e-view-mode-hook 'mu4e~view-fontify-diff)

Dirk-Jan C. Binnema

unread,
Oct 7, 2012, 2:43:34 PM10/7/12
to mu-di...@googlegroups.com
Hi,

On Sun, Oct 07 2012, coldnew wrote:

> Hello:
>
> I use mu4e to read mailing-list, is there a elegant way to fontify
> those [PATCH] mail ?
>
> following is my code, but it can not work when I enter the
> mu4e-view-mode, I must use it manually

<snip>

Ah, cool idea! I think it'd be nice if mu4e had some way to deal with
patches (and hopefully let ediff-mode deal with the fontification), and
there may be more inline-text things that would be nice to handle
specially, I'll have to think about how to handle that.

For now, the reason your function doesn't work is that the buffer is set
to mu4e-view-mode before the message text is insert -- so your hook is
called to early. I'll try if I can move the mode-activation until after
the contents are there. If it works, should appear in git in the next
days...

Best wishes,
Dirk.

--
Dirk-Jan C. Binnema Helsinki, Finland
e:dj...@djcbsoftware.nl w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C

Dave Barker

unread,
Oct 20, 2016, 1:50:42 PM10/20/16
to mu-discuss
On Sunday, October 7, 2012 at 8:43:34 PM UTC+2, djcb wrote:
Ah, cool idea! I think it'd be nice if mu4e had some way to deal with
patches (and hopefully let ediff-mode deal with the fontification), and
there may be more inline-text things that would be nice to handle
specially, I'll have to think about how to handle that.

Did you ever get a chance to look into this? Something like this function for notmuch mail would be really useful.

Cheers, Dave.

Dave Barker

unread,
Oct 21, 2016, 2:26:20 PM10/21/16
to mu-discuss
On Thursday, October 20, 2016 at 7:50:42 PM UTC+2, Dave Barker wrote:
Did you ever get a chance to look into this? Something like this function for notmuch mail would be really useful.

Well I just hacked together a bastardised version of that example, seems to work OK!

(defun kzar/mu4e-patch-view (msg)
  (let* ((body (mu4e-message-field msg :body-txt))
         (id (mu4e-message-field msg :message-id))
         (subject (mu4e-message-field msg :subject))
         (buffer (get-buffer-create (concat "*mu4e-patch-" id "*"))))
    (switch-to-buffer buffer)
    (erase-buffer)
    (insert subject)
    (insert "\n\n")
    (insert body))
    (set-buffer-modified-p nil)
    (diff-mode)
    (read-only-mode)
    (goto-char (point-min)))
(add-to-list 'mu4e-view-actions '("patch view" . kzar/mu4e-patch-view))
Reply all
Reply to author
Forward
0 new messages