unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: Allow tuning of the tag/saved search layout.
@ 2010-04-27 14:58 dme
  2010-04-27 15:35 ` Carl Worth
  0 siblings, 1 reply; 4+ messages in thread
From: dme @ 2010-04-27 14:58 UTC (permalink / raw)
  To: notmuch

From: David Edmondson <dme@dme.org>

Add `notmuch-hello-tag-width', which has three potential sets of
values:

- t: automatically calculate the number of tags per line possible
  based on the tags to be shown and the window width,
- an integer: a lower bound on the number of characters that will
  be used to display each tag,
- a float: a fraction of the window width that is the lower bound
  on the number of characters that should be used for each tag.

So:
- if you would like two columns of tags, set this to 0.5.
- if you would like a single column of tags, set this to 1.0.
- if you would like tags to be 30 characters wide, set this to
  30.
- if you don't want to worry about all of this nonsense, leave
  this set to `t'.
---

Carl, for 0.4. You mentioned that you might like to have a single
column of tags/saved searches, but others appear to like multiple
columns. So, make it configurable.

 emacs/notmuch-hello.el |   62 +++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 56 insertions(+), 6 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 378d41c..f7703d9 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -141,13 +141,63 @@ diagonal."
 (defun notmuch-saved-search-count (search)
   (car (process-lines notmuch-command "count" search)))
 
+(defcustom notmuch-hello-tag-width t
+  "How wide should a tag be?
+
+This variable has three potential sets of values:
+
+- t: automatically calculate the number of tags per line possible
+  based on the tags to be shown and the window width,
+- an integer: a lower bound on the number of characters that will
+  be used to display each tag,
+- a float: a fraction of the window width that is the lower bound
+  on the number of characters that should be used for each tag.
+
+So:
+- if you would like two columns of tags, set this to 0.5.
+- if you would like a single column of tags, set this to 1.0.
+- if you would like tags to be 30 characters wide, set this to
+  30.
+- if you don't want to worry about all of this nonsense, leave
+  this set to `t'."
+  :group 'notmuch
+  :type '(choice
+	  (const :tag "Automatically calculated" t)
+	  (integer :tag "Number of characters")
+	  (float :tag "Fraction of window")))
+
+(defun notmuch-hello-tags-per-line (widest)
+  "Determine how many tags to show per line and how wide they
+should be. Returns a cons cell `(tags-per-line width)'."
+  (let ((tags-per-line
+	 (cond
+	  ((integerp notmuch-hello-tag-width)
+	   (max 1
+		(/ (- (window-width) notmuch-hello-indent)
+		   ;; Count is 7 wide (6 digits plus space), 1 for the space
+		   ;; after the name.
+		   (+ 7 1 (max notmuch-hello-tag-width widest)))))
+
+	  ((floatp notmuch-hello-tag-width)
+	   (let* ((available-width (- (window-width) notmuch-hello-indent))
+		  (proposed-width (max (* available-width notmuch-hello-tag-width) widest)))
+	     (floor available-width proposed-width)))
+
+	  (t
+	   (max 1
+		(/ (- (window-width) notmuch-hello-indent)
+		   ;; Count is 7 wide (6 digits plus space), 1 for the space
+		   ;; after the name.
+		   (+ 7 1 widest)))))))
+
+    (cons tags-per-line (/ (- (window-width) notmuch-hello-indent
+			      (* tags-per-line (+ 7 1)))
+			   tags-per-line))))
+
 (defun notmuch-hello-insert-tags (tag-alist widest target)
-  (let* ((tags-per-line (max 1
-			     (/ (- (window-width) notmuch-hello-indent)
-				;; Count is 7 wide (6 digits plus
-				;; space), 1 for the space after the
-				;; name.
-				(+ 7 1 widest))))
+  (let* ((tags-and-width (notmuch-hello-tags-per-line widest))
+	 (tags-per-line (car tags-and-width))
+	 (widest (cdr tags-and-width))
 	 (count 0)
 	 (reordered-list (notmuch-hello-reflect tag-alist tags-per-line))
 	 ;; Hack the display of the buttons used.
-- 
1.7.0

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

end of thread, other threads:[~2010-06-04  0:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-27 14:58 [PATCH] emacs: Allow tuning of the tag/saved search layout dme
2010-04-27 15:35 ` Carl Worth
2010-04-29  8:28   ` David Edmondson
2010-06-04  0:04     ` Carl Worth

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