Ping! :)

-------------------- Start of forwarded message --------------------
From: Rudolf Adamkovič <salu...@me.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] improve notmuch-hello layout
Date: Thu, 25 May 2023 17:30:26 +0200

Howdy, howdy fellow e-mail hackers. :)

The attached patches are my first-cut attempt to:

(1) Make notmuch-hello play nicely with display-line-numbers-mode.
(2) Make notmuch-hello re-layout when window width changes.

WDYT?

Rudy
>From 278017d06bb986f4ec99118bfcfdec8dab970f2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salu...@me.com>
Date: Thu, 25 May 2023 16:22:08 +0200
Subject: [PATCH 1/2] emacs: fix notmuch-hello layout when
 display-line-numbers-mode is on

---
 emacs/notmuch-hello.el | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 4662e704..3235f555 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -412,6 +412,7 @@ supported for \"Customized queries section\" items."
 (defun notmuch-search-item-field-width ()
   (max 8 ; Don't let the search boxes be less than 8 characters wide.
        (- (window-width)
+	  (line-number-display-width)
 	  notmuch-hello-indent ; space at bol
 	  notmuch-hello-indent ; space at eol
 	  1    ; for the space before the [save] button
@@ -508,23 +509,31 @@ should be. Returns a cons cell `(tags-per-line width)'."
 	 (cond
 	  ((integerp notmuch-column-control)
 	   (max 1
-		(/ (- (window-width) notmuch-hello-indent)
+		(/ (- (window-width)
+		      (line-number-display-width)
+		      notmuch-hello-indent)
 		   ;; Count is 9 wide (8 digits plus space), 1 for the space
 		   ;; after the name.
 		   (+ 9 1 (max notmuch-column-control widest)))))
 	  ((floatp notmuch-column-control)
-	   (let* ((available-width (- (window-width) notmuch-hello-indent))
+	   (let* ((available-width (- (window-width)
+				      (line-number-display-width)
+				      notmuch-hello-indent))
 		  (proposed-width (max (* available-width notmuch-column-control)
 				       widest)))
 	     (floor available-width proposed-width)))
 	  (t
 	   (max 1
-		(/ (- (window-width) notmuch-hello-indent)
+		(/ (- (window-width)
+		      (line-number-display-width)
+		      notmuch-hello-indent)
 		   ;; Count is 9 wide (8 digits plus space), 1 for the space
 		   ;; after the name.
 		   (+ 9 1 widest)))))))
     (cons tags-per-line (/ (max 1
-				(- (window-width) notmuch-hello-indent
+				(- (window-width)
+				   (line-number-display-width)
+				   notmuch-hello-indent
 				   ;; Count is 9 wide (8 digits plus
 				   ;; space), 1 for the space after the
 				   ;; name.
@@ -824,7 +833,9 @@ Complete list of currently available key bindings:
   (widget-create 'editable-field
 		 ;; Leave some space at the start and end of the
 		 ;; search boxes.
-		 :size (max 8 (- (window-width) notmuch-hello-indent
+		 :size (max 8 (- (window-width)
+				 (line-number-display-width)
+				 notmuch-hello-indent
 				 (length "Search: ")))
 		 :action #'notmuch-hello-search)
   ;; Add an invisible dot to make `widget-end-of-line' ignore
@@ -947,7 +958,9 @@ following:
 			     (customize-variable 'notmuch-hello-sections))
 		   :button-prefix "" :button-suffix ""
 		   "this page.")
-    (let ((fill-column (- (window-width) notmuch-hello-indent)))
+    (let ((fill-column (- (window-width)
+			  (line-number-display-width)
+			  notmuch-hello-indent)))
       (center-region start (point)))))
 
 ;;; Hello!
-- 
2.37.1 (Apple Git-137.1)

>From 4964ac4a656521a0e84615ea718c81fb4e95bedf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salu...@me.com>
Date: Thu, 25 May 2023 17:21:38 +0200
Subject: [PATCH 2/2] emacs: re-layout notmuch-hello when window width changes

---
 emacs/notmuch-hello.el | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 3235f555..f245a7dd 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -383,6 +383,10 @@ supported for \"Customized queries section\" items."
 (defvar notmuch-hello-first-run t
   "True if `notmuch-hello' is run for the first time, set to nil afterwards.")
 
+(defvar notmuch-hello-scheduled-to-run nil
+  "True if `notmuch-hello' is scheduled to run during the next
+re-display, and set to nil afterwards.")
+
 ;;; Widgets for inserters
 
 (define-widget 'notmuch-search-item 'item
@@ -701,12 +705,23 @@ with `notmuch-hello-query-counts'."
 	    ;; The user just switched to hello in this window (hello
 	    ;; is currently visible, was not visible on the last
 	    ;; configuration change, and this is not a new window)
-	    (setq do-refresh t)))))
-    (when (and do-refresh notmuch-hello-auto-refresh)
+	    (setq do-refresh t)))
+	(when (eq cur-buf hello-buf)
+	  ;; This is the hello buffer, so check its last and current width.
+	  (let ((last-width (window-parameter window 'notmuch-hello-last-width))
+		(cur-width (window-width window)))
+	    (unless (equal last-width cur-width)
+	      ;; The with of the window has changed, so do refresh.
+	      (set-window-parameter window 'notmuch-hello-last-width cur-width)
+	      (setq do-refresh t))))))
+    (when (and do-refresh
+	       notmuch-hello-auto-refresh
+	       (not notmuch-hello-scheduled-to-run))
       ;; Refresh hello as soon as we get back to redisplay.  On Emacs
       ;; 24, we can't do it right here because something in this
       ;; hook's call stack overrides hello's point placement.
       ;; FIXME And on Emacs releases that we still support?
+      (setq notmuch-hello-scheduled-to-run t)
       (run-at-time nil nil #'notmuch-hello t))
     (unless hello-buf
       ;; Clean up hook
@@ -1014,7 +1029,8 @@ following:
     (forward-line (1- target-line))
     (move-to-column target-column))
   (run-hooks 'notmuch-hello-refresh-hook)
-  (setq notmuch-hello-first-run nil))
+  (setq notmuch-hello-first-run nil
+	notmuch-hello-scheduled-to-run nil))
 
 ;;; _
 
-- 
2.37.1 (Apple Git-137.1)

-- 
"Thinking is a momentary dismissal of irrelevancies."
-- Richard Buckminster Fuller, 1969

Rudolf Adamkovič <salu...@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org
-------------------- End of forwarded message --------------------

-- 
"All you have to do is write one true sentence.  Write the truest sentence that
you know."
--- Ernest Miller Hemingway (1899-1961)

Rudolf Adamkovič <salu...@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org

Reply via email to