From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH] WIP/emacs: replace use of indent-rigidly in notmuch-show
Date: Tue, 14 Dec 2021 08:17:26 -0400 [thread overview]
Message-ID: <20211214121726.2631714-1-david@tethera.net> (raw)
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
next reply other threads:[~2021-12-14 12:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-14 12:17 David Bremner [this message]
2021-12-16 13:58 ` [PATCH] WIP/emacs: replace use of indent-rigidly in notmuch-show 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=20211214121726.2631714-1-david@tethera.net \
--to=david@tethera.net \
--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).