Several people have observed that the display of patches in notmuch-emacs is less than ideal because context lines do not line up properly with changed lines. The underlying cause is that indent-rigidly adds space in different places for those lines. In this commit, indent-rigidly is replaced with a more simple-minded function that always adds spaces to the beginning of the line. ---
This is not really well tested, and somewhat copy-pasta-ed together code. Looking at this mail, I see the indentation of the call sites is not great either. emacs/notmuch-show.el | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 4de3e423..50ed6f28 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -29,6 +29,8 @@ (require 'mailcap) (require 'icalendar) (require 'goto-addr) +(require 'rect) +(require 'cl-lib) (require 'notmuch-lib) (require 'notmuch-tag) @@ -272,6 +274,23 @@ position of the message in the thread." ;;; Utilities +;; force all indentation to be spaces at BOL +;; Based on apply-on-rectangle, from rect.el +(defun notmuch--indent-rigidly (start end count) + (if (<= count 0) + (indent-rigidly start end count) + (save-excursion + (let ((startpt (progn (goto-char start) (line-beginning-position))) + (endpt (progn (goto-char end) (line-end-position))) + (spaces (spaces-string count))) + (goto-char startpt) + (while + (progn + (insert spaces) + (cl-incf endpt count) + (and (zerop (forward-line 1)) (bolp) + (<= (point) endpt)))))))) + (defmacro with-current-notmuch-show-message (&rest body) "Evaluate body with current buffer set to the text of current message." `(save-excursion @@ -354,7 +373,7 @@ operation on the contents of the current buffer." (with-temp-buffer (insert all) (when indenting - (indent-rigidly (point-min) + (notmuch--indent-rigidly (point-min) (point-max) (- (* notmuch-show-indent-messages-width depth)))) ;; Remove the original header. @@ -654,7 +673,7 @@ will return nil if the CID is unknown or cannot be retrieved." inner-parts) (when notmuch-show-indent-multipart - (indent-rigidly start (point) 1))) + (notmuch--indent-rigidly start (point) 1))) t) (defun notmuch-show-insert-part-multipart/related (msg part _content-type _nth depth _button) @@ -667,7 +686,7 @@ will return nil if the CID is unknown or cannot be retrieved." (notmuch-show-insert-bodypart msg inner-part depth t)) (cdr inner-parts)) (when notmuch-show-indent-multipart - (indent-rigidly start (point) 1))) + (notmuch--indent-rigidly start (point) 1))) t) (defun notmuch-show-insert-part-multipart/signed (msg part _content-type _nth depth button) @@ -683,7 +702,7 @@ will return nil if the CID is unknown or cannot be retrieved." (notmuch-show-insert-bodypart msg inner-part depth)) inner-parts) (when notmuch-show-indent-multipart - (indent-rigidly start (point) 1))) + (notmuch--indent-rigidly start (point) 1))) t) (defun notmuch-show-insert-part-multipart/encrypted (msg part _content-type _nth depth button) @@ -701,7 +720,7 @@ will return nil if the CID is unknown or cannot be retrieved." (notmuch-show-insert-bodypart msg inner-part depth)) inner-parts) (when notmuch-show-indent-multipart - (indent-rigidly start (point) 1))) + (notmuch--indent-rigidly start (point) 1))) t) (defun notmuch-show-insert-part-application/pgp-encrypted (_msg _part _content-type _nth _depth _button) @@ -715,7 +734,7 @@ will return nil if the CID is unknown or cannot be retrieved." (notmuch-show-insert-bodypart msg inner-part depth)) inner-parts) (when notmuch-show-indent-multipart - (indent-rigidly start (point) 1))) + (notmuch--indent-rigidly start (point) 1))) t) (defun notmuch-show-insert-part-message/rfc822 (msg part _content-type _nth depth _button) @@ -734,7 +753,7 @@ will return nil if the CID is unknown or cannot be retrieved." ;; Show the body (notmuch-show-insert-bodypart msg body depth) (when notmuch-show-indent-multipart - (indent-rigidly start (point) 1)) + (notmuch--indent-rigidly start (point) 1)) t)))) (defun notmuch-show-insert-part-text/plain (msg part _content-type _nth depth button) @@ -942,7 +961,7 @@ will return nil if the CID is unknown or cannot be retrieved." (narrow-to-region part-beg part-end) (delete-region part-beg part-end) (apply #'notmuch-show-insert-bodypart-internal part-args) - (indent-rigidly part-beg + (notmuch--indent-rigidly part-beg part-end (* notmuch-show-indent-messages-width depth))) (goto-char part-end) @@ -1095,7 +1114,7 @@ is t, hide the part initially and show the button." (setq content-end (point-marker)) ;; Indent according to the depth in the thread. (when notmuch-show-indent-content - (indent-rigidly content-start + (notmuch--indent-rigidly content-start content-end (* notmuch-show-indent-messages-width depth))) (setq message-end (point-max-marker)) -- 2.33.0 _______________________________________________ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-le...@notmuchmail.org