[Patch 2/3] Respect window margins in notmuch-hello.el
Ivy Foster
joyfulgirl at archlinux.us
Sat Oct 29 09:30:48 PDT 2011
Hello again, folks,
The following patch makes notmuch take window margins into
account when calculating the width of the notmuch-hello
window in Emacs. As a side benefit (so that I only had to
write the code once), I've added a named function to return
said width.
Folks using linum-mode should still probably get a copy of
linum-off.el and disable linum for notmuch-hello, though,
since it doesn't set the margin until after the buffer is
done being created, causing text to overflow across the
edge. Alternately, take a look at my next message, with yet
another patch.
Enjoy!
iff
Signed-off-by: Ivy Foster <joyfulgirl at archlinux.us>
>From 0c1a0fa0858e3c22b416ce6bd9ad623198217d34 Mon Sep 17 00:00:00 2001
From: Ivy Foster <joyfulgirl at archlinux.us>
Date: Fri, 28 Oct 2011 23:18:14 -0400
Subject: [PATCH 2/3] Respect margins in new named window-width function
This patch removes a function which is duplicated
several times in notmuch-hello.el, improving
readability. Also, factors in window margins
when calculating width.
---
emacs/notmuch-hello.el | 28 ++++++++++++++++++----------
1 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 65fde75..1a213f0 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -213,25 +213,27 @@ should be. Returns a cons cell `(tags-per-line width)'."
(cond
((integerp notmuch-column-control)
(max 1
- (/ (- (window-width) notmuch-hello-indent)
+ (/ (notmuch-hello-available-width)
;; 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))
- (proposed-width (max (* available-width notmuch-column-control) widest)))
- (floor available-width proposed-width)))
+ (let ((proposed-width (max
+ (* (notmuch-hello-available-width)
+ notmuch-column-control)
+ widest)))
+ (floor (notmuch-hello-available-width) proposed-width)))
(t
(max 1
- (/ (- (window-width) notmuch-hello-indent)
+ (/ (notmuch-hello-available-width)
;; 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
+ (- (notmuch-hello-available-width)
;; Count is 9 wide (8 digits plus
;; space), 1 for the space after the
;; name.
@@ -458,7 +460,7 @@ 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 (- (notmuch-hello-available-width)
(length "Search: ")))
:action (lambda (widget &rest ignore)
(notmuch-hello-search (widget-value widget))))
@@ -481,12 +483,13 @@ Complete list of currently available key bindings:
;; Don't let the search boxes be
;; less than 8 characters wide.
:size (max 8
- (- (window-width)
+ (-
+ (notmuch-hello-available-width)
;; Leave some space
;; at the start and
;; end of the
;; boxes.
- (* 2 notmuch-hello-indent)
+ notmuch-hello-indent
;; 1 for the space
;; before the
;; `[save]' button. 6
@@ -540,7 +543,7 @@ Complete list of currently available key bindings:
(widget-insert "Edit saved searches with the `edit' button.\n"))
(widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")
(widget-insert "`=' refreshes this screen. `s' jumps to the search box. `q' to quit.\n")
- (let ((fill-column (- (window-width) notmuch-hello-indent)))
+ (let ((fill-column (notmuch-hello-available-width)))
(center-region start (point))))
(widget-setup)
@@ -558,6 +561,11 @@ Complete list of currently available key bindings:
(interactive)
(notmuch-hello))
+(defun notmuch-hello-available-width ()
+ (let ((left-margin (or (car (window-margins)) 0))
+ (right-margin (or (cadr (window-margins)) 0)))
+ (- (window-width) left-margin right-margin notmuch-hello-indent)))
+
;;
(provide 'notmuch-hello)
--
1.7.7.1
More information about the notmuch
mailing list