* [PATCH] WIP/emacs: replace use of indent-rigidly in notmuch-show
@ 2021-12-14 12:17 David Bremner
2021-12-16 13:58 ` David Bremner
0 siblings, 1 reply; 2+ messages in thread
From: David Bremner @ 2021-12-14 12:17 UTC (permalink / raw)
To: notmuch
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] WIP/emacs: replace use of indent-rigidly in notmuch-show
2021-12-14 12:17 [PATCH] WIP/emacs: replace use of indent-rigidly in notmuch-show David Bremner
@ 2021-12-16 13:58 ` David Bremner
0 siblings, 0 replies; 2+ messages in thread
From: David Bremner @ 2021-12-16 13:58 UTC (permalink / raw)
To: notmuch
David Bremner <david@tethera.net> writes:
> 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.
There is at least one bug still. If you open a thread with a matched
message that is not the first message, the cursor is positioned after
the matched message, sometimes causing the wanted message to scroll off
the top of the screen.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-16 13:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 12:17 [PATCH] WIP/emacs: replace use of indent-rigidly in notmuch-show David Bremner
2021-12-16 13:58 ` David Bremner
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).