[PATCH] emacs: Allow tuning of the tag/saved search layout.
[notmuch-archives.git] / 0d / db55b021427986d974ec4841f3b44aa5d51186
1 Return-Path: <dme@dme.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 79C744196F0\r
6         for <notmuch@notmuchmail.org>; Thu, 29 Apr 2010 01:28:07 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id YdOaJIMXqSgO for <notmuch@notmuchmail.org>;\r
16         Thu, 29 Apr 2010 01:28:06 -0700 (PDT)\r
17 Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com\r
18         [74.125.82.181])\r
19         by olra.theworths.org (Postfix) with ESMTP id 62700431FC1\r
20         for <notmuch@notmuchmail.org>; Thu, 29 Apr 2010 01:28:06 -0700 (PDT)\r
21 Received: by wyj26 with SMTP id 26so2874369wyj.26\r
22         for <notmuch@notmuchmail.org>; Thu, 29 Apr 2010 01:28:05 -0700 (PDT)\r
23 Received: by 10.216.154.206 with SMTP id h56mr5087860wek.94.1272529685406;\r
24         Thu, 29 Apr 2010 01:28:05 -0700 (PDT)\r
25 Received: from ut.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1])\r
26         by mx.google.com with ESMTPS id z3sm5366595wbs.22.2010.04.29.01.28.03\r
27         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
28         Thu, 29 Apr 2010 01:28:04 -0700 (PDT)\r
29 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
30         id 0420459411F; Thu, 29 Apr 2010 09:28:24 +0100 (BST)\r
31 From: David Edmondson <dme@dme.org>\r
32 To: notmuch@notmuchmail.org\r
33 Subject: [PATCH] emacs: Allow tuning of the tag/saved search layout.\r
34 Date: Thu, 29 Apr 2010 09:28:23 +0100\r
35 Message-Id: <1272529703-29092-1-git-send-email-dme@dme.org>\r
36 X-Mailer: git-send-email 1.7.0\r
37 In-Reply-To: <87d3xknc1w.fsf@yoom.home.cworth.org>\r
38 References: <87d3xknc1w.fsf@yoom.home.cworth.org>\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.13\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43         <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Thu, 29 Apr 2010 08:28:07 -0000\r
52 \r
53 Add `notmuch-column-control', which has three potential sets of\r
54 values:\r
55 \r
56 - t: automatically calculate the number of columns per line based on\r
57   the tags to be shown and the window width,\r
58 - an integer: a lower bound on the number of characters that will be\r
59   used to display each column,\r
60 - a float: a fraction of the window width that is the lower bound on\r
61   the number of characters that should be used for each column.\r
62 \r
63 So:\r
64 - if you would like two columns of tags, set this to 0.5.\r
65 - if you would like a single column of tags, set this to 1.0.\r
66 - if you would like tags to be 30 characters wide, set this to\r
67   30.\r
68 - if you don't want to worry about all of this nonsense, leave\r
69   this set to `t'.\r
70 ---\r
71 \r
72 `notmuch-hello-tag-width' is now `notmuch-column-control', given that\r
73 your proposed first sentence is a better explanation of the purpose.\r
74 \r
75  emacs/notmuch-hello.el |   63 +++++++++++++++++++++++++++++++++++++++++++----\r
76  1 files changed, 57 insertions(+), 6 deletions(-)\r
77 \r
78 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
79 index 1358387..acf40bc 100644\r
80 --- a/emacs/notmuch-hello.el\r
81 +++ b/emacs/notmuch-hello.el\r
82 @@ -65,6 +65,32 @@\r
83    "Background colour for the notmuch logo."\r
84    :group 'notmuch)\r
85  \r
86 +(defcustom notmuch-column-control t\r
87 +  "Controls the number of columns for saved searches/tags in notmuch view.\r
88 +\r
89 +This variable has three potential sets of values:\r
90 +\r
91 +- t: automatically calculate the number of columns possible based\r
92 +  on the tags to be shown and the window width,\r
93 +- an integer: a lower bound on the number of characters that will\r
94 +  be used to display each column,\r
95 +- a float: a fraction of the window width that is the lower bound\r
96 +  on the number of characters that should be used for each\r
97 +  column.\r
98 +\r
99 +So:\r
100 +- if you would like two columns of tags, set this to 0.5.\r
101 +- if you would like a single column of tags, set this to 1.0.\r
102 +- if you would like tags to be 30 characters wide, set this to\r
103 +  30.\r
104 +- if you don't want to worry about all of this nonsense, leave\r
105 +  this set to `t'."\r
106 +  :group 'notmuch\r
107 +  :type '(choice\r
108 +         (const :tag "Automatically calculated" t)\r
109 +         (integer :tag "Number of characters")\r
110 +         (float :tag "Fraction of window")))\r
111 +\r
112  (defvar notmuch-hello-url "http://notmuchmail.org"\r
113    "The `notmuch' web site.")\r
114  \r
115 @@ -146,13 +172,38 @@ diagonal."\r
116  (defun notmuch-saved-search-count (search)\r
117    (car (process-lines notmuch-command "count" search)))\r
118  \r
119 +(defun notmuch-hello-tags-per-line (widest)\r
120 +  "Determine how many tags to show per line and how wide they\r
121 +should be. Returns a cons cell `(tags-per-line width)'."\r
122 +  (let ((tags-per-line\r
123 +        (cond\r
124 +         ((integerp notmuch-column-control)\r
125 +          (max 1\r
126 +               (/ (- (window-width) notmuch-hello-indent)\r
127 +                  ;; Count is 7 wide (6 digits plus space), 1 for the space\r
128 +                  ;; after the name.\r
129 +                  (+ 7 1 (max notmuch-column-control widest)))))\r
130 +\r
131 +         ((floatp notmuch-column-control)\r
132 +          (let* ((available-width (- (window-width) notmuch-hello-indent))\r
133 +                 (proposed-width (max (* available-width notmuch-column-control) widest)))\r
134 +            (floor available-width proposed-width)))\r
135 +\r
136 +         (t\r
137 +          (max 1\r
138 +               (/ (- (window-width) notmuch-hello-indent)\r
139 +                  ;; Count is 7 wide (6 digits plus space), 1 for the space\r
140 +                  ;; after the name.\r
141 +                  (+ 7 1 widest)))))))\r
142 +\r
143 +    (cons tags-per-line (/ (- (window-width) notmuch-hello-indent\r
144 +                             (* tags-per-line (+ 7 1)))\r
145 +                          tags-per-line))))\r
146 +\r
147  (defun notmuch-hello-insert-tags (tag-alist widest target)\r
148 -  (let* ((tags-per-line (max 1\r
149 -                            (/ (- (window-width) notmuch-hello-indent)\r
150 -                               ;; Count is 7 wide (6 digits plus\r
151 -                               ;; space), 1 for the space after the\r
152 -                               ;; name.\r
153 -                               (+ 7 1 widest))))\r
154 +  (let* ((tags-and-width (notmuch-hello-tags-per-line widest))\r
155 +        (tags-per-line (car tags-and-width))\r
156 +        (widest (cdr tags-and-width))\r
157          (count 0)\r
158          (reordered-list (notmuch-hello-reflect tag-alist tags-per-line))\r
159          ;; Hack the display of the buttons used.\r
160 -- \r
161 1.7.0\r
162 \r