From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id MIYSAGyLuGHhtwAAgWs5BA (envelope-from ) for ; Tue, 14 Dec 2021 13:17:48 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 4ACIN2uLuGGSBAAA1q6Kng (envelope-from ) for ; Tue, 14 Dec 2021 12:17:47 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AA15935C32 for ; Tue, 14 Dec 2021 13:17:47 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id CD71029778; Tue, 14 Dec 2021 07:17:36 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 228EE29773 for ; Tue, 14 Dec 2021 07:17:33 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id B60EE5FC42; Tue, 14 Dec 2021 07:17:32 -0500 (EST) Received: (nullmailer pid 2631760 invoked by uid 1000); Tue, 14 Dec 2021 12:17:31 -0000 From: David Bremner 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 Message-Id: <20211214121726.2631714-1-david@tethera.net> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Message-ID-Hash: OFWE4BMTNUM3AFSKOGZMO4XOPOLV2VIE X-Message-ID-Hash: OFWE4BMTNUM3AFSKOGZMO4XOPOLV2VIE X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1639484267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=LOcYd5QwEXoEa4jzh35Dx0XkGdVAVKdUSzY5DrNX4YI=; b=X456Kbdkd/c9Kff6v3szGZHjKt86p+0/lREaw8QQ8F7JK6QxQP8PHBztpA0Go8gmJ4NETk w8gm2iSF+6NMrRNBT42QWD7KRssnEUQgaVgRHvMbHfzTAwDI7QoykJslihaFyY9UY/LOVp 9wVJHLCHFLYGTvBn9IST3wSK4ngh/EEaeGYQkybA9MWTWtxnxaLZ0tbia3+QFBF54+ZSbn v8+SXt+L7UwKwLv3I7z/JwxUZYhtncfpv9nIFqztlQNn/vIq9/5sl0/eIYXr2aWUbRvIV5 D9oyzDBEkG2qi4MGlZIs4w3s9cv5BWGFOIv85ZdN1F7EpZzx8oFlbmmEfC+VRQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1639484267; a=rsa-sha256; cv=none; b=JLB9k5vpXfkGEGUrcML7Doz4136hpx+VI8R0OlJ21oRnwzCUQiXBzvpis73rS08TstLAzw W0NvlcGR7CRpTzx20udbV3JXKaad+L93Cxy7YPnsc1ux6b1n7QF130ayiu4CO5cinGdxyy Wm9fB6KDkm4XFNTI8z3AQRueuZzGhvrhXf7IZ3XzXtde0yBgEVe/+FEHB86BsiAEpXNU9z yFyeb0nfcg6jqjzwVZ2buajME1nMdRT+29loS3T9gn3FIA+4D2IVh40FSv4DYtMpXbfYaZ kM53hVMsfdIUgE6zJbjmyz+qmw3ftObRwkxKxWZ4P0V98bBGtfs3wdTXdV+n4g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 1.40 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: AA15935C32 X-Spam-Score: 1.40 X-Migadu-Scanner: scn1.migadu.com X-TUID: uDolbgvW6kqK 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