unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] improve notmuch-hello layout
@ 2023-05-25 15:30 Rudolf Adamkovič
  2023-07-03 17:45 ` Fwd: " Rudolf Adamkovič
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rudolf Adamkovič @ 2023-05-25 15:30 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-emacs-fix-notmuch-hello-layout-when-display-line-num.patch --]
[-- Type: text/x-patch, Size: 3086 bytes --]

From 278017d06bb986f4ec99118bfcfdec8dab970f2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@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)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-emacs-re-layout-notmuch-hello-when-window-width-chan.patch --]
[-- Type: text/x-patch, Size: 2519 bytes --]

From 4964ac4a656521a0e84615ea718c81fb4e95bedf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@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)


[-- Attachment #4: Type: text/plain, Size: 191 bytes --]

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

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

[-- Attachment #5: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Fwd: [PATCH] improve notmuch-hello layout
  2023-05-25 15:30 [PATCH] improve notmuch-hello layout Rudolf Adamkovič
@ 2023-07-03 17:45 ` Rudolf Adamkovič
  2023-07-09 17:57 ` David Bremner
  2023-07-22 18:19 ` David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: Rudolf Adamkovič @ 2023-07-03 17:45 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 241 bytes --]

Ping! :)

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


[-- Attachment #2.1: Type: text/plain, Size: 231 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.2: 0001-emacs-fix-notmuch-hello-layout-when-display-line-num.patch --]
[-- Type: text/x-patch, Size: 3086 bytes --]

From 278017d06bb986f4ec99118bfcfdec8dab970f2b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@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)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.3: 0002-emacs-re-layout-notmuch-hello-when-window-width-chan.patch --]
[-- Type: text/x-patch, Size: 2519 bytes --]

From 4964ac4a656521a0e84615ea718c81fb4e95bedf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@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)


[-- Attachment #2.4: Type: text/plain, Size: 191 bytes --]

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

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

[-- Attachment #2.5: Type: text/plain, Size: 158 bytes --]

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

[-- Attachment #3: Type: text/plain, Size: 303 bytes --]

-------------------- 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č <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

[-- Attachment #4: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] improve notmuch-hello layout
  2023-05-25 15:30 [PATCH] improve notmuch-hello layout Rudolf Adamkovič
  2023-07-03 17:45 ` Fwd: " Rudolf Adamkovič
@ 2023-07-09 17:57 ` David Bremner
  2023-07-22 18:19 ` David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2023-07-09 17:57 UTC (permalink / raw)
  To: Rudolf Adamkovič, notmuch

Rudolf Adamkovič <salutis@me.com> writes:
>
> Rudy
> From 278017d06bb986f4ec99118bfcfdec8dab970f2b Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@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)

This seems like a harmless change, except that we claim to support emacs
25.1. The function #'line-number-display-width is apparently from emacs
26.1. I don't honestly know if the code even works in emacs 25 anymore,
perhaps we should bump the minimum version requirement. Or you could
make this change conditional on version somehow. The fact that you have
to update 7 places in the code makes me wonder if the calculation should
be collected into a function, so that the next change can be done more easily.\r

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] improve notmuch-hello layout
  2023-05-25 15:30 [PATCH] improve notmuch-hello layout Rudolf Adamkovič
  2023-07-03 17:45 ` Fwd: " Rudolf Adamkovič
  2023-07-09 17:57 ` David Bremner
@ 2023-07-22 18:19 ` David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2023-07-22 18:19 UTC (permalink / raw)
  To: Rudolf Adamkovič, notmuch

Rudolf Adamkovič <salutis@me.com> writes:

> ---
>  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.")

The control flow here is already pretty complicaed. I hope that we can
simplify it (drop use run-at-time) before adding any more features.\r

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-22 18:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-25 15:30 [PATCH] improve notmuch-hello layout Rudolf Adamkovič
2023-07-03 17:45 ` Fwd: " Rudolf Adamkovič
2023-07-09 17:57 ` David Bremner
2023-07-22 18:19 ` 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).