]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.el
make a nice function for generating invisibility toggle buttons
[notmuch] / notmuch.el
index 8aee2864047ef455ff3e7eb1e83693ee9e557829..23a07cca2efbbcf6355e642199063799d466aa55 100644 (file)
@@ -62,8 +62,6 @@
     (define-key map "a" 'notmuch-show-archive-thread)
     (define-key map "A" 'notmuch-show-mark-read-then-archive-thread)
     (define-key map "b" 'notmuch-show-toggle-body-read-visible)
-    (define-key map "c" 'notmuch-show-toggle-citations-visible)
-    (define-key map "h" 'notmuch-show-toggle-headers-visible)
     (define-key map "m" 'message-mail)
     (define-key map "n" 'notmuch-show-next-message)
     (define-key map "N" 'notmuch-show-mark-read-then-next-open-message)
@@ -72,7 +70,6 @@
     (define-key map (kbd "C-p") 'notmuch-show-previous-line)
     (define-key map "q" 'kill-this-buffer)
     (define-key map "r" 'notmuch-show-reply)
-    (define-key map "s" 'notmuch-show-toggle-signatures-visible)
     (define-key map "v" 'notmuch-show-view-all-mime-parts)
     (define-key map "w" 'notmuch-show-view-raw-message)
     (define-key map "x" 'kill-this-buffer)
@@ -500,6 +497,13 @@ which this thread was originally shown."
   (force-window-update)
   (redisplay t))
 
+(defun notmuch-configure-invisibility-button (btn invis-spec help-msg)
+  (button-put btn 'invisibility-spec invis-spec)
+  (button-put btn 'action 'notmuch-toggle-invisible-action)
+  (button-put btn 'follow-link t)
+  (button-put btn 'help-echo (concat "mouse-1, RET: " help-msg))
+)
+
 (defun notmuch-show-markup-citations-region (beg end depth)
   (goto-char beg)
   (beginning-of-line)
@@ -515,22 +519,13 @@ which this thread was originally shown."
                   (invis-spec (make-symbol "notmuch-citation-region")))
               (add-to-invisibility-spec invis-spec)
              (overlay-put overlay 'invisible invis-spec)
-              (let (
-                    (p (point))
+              (let ((p (point))
                     (cite-button-text
                      (concat "["  (number-to-string (count-lines beg-sub (point)))
-                             "-line citation.]"))
-                    )
+                             "-line citation.]")))
                 (goto-char (- beg-sub 1))
                 (insert (concat "\n" indent))
-                (let ((cite-button (insert-button cite-button-text)))
-                  (button-put cite-button 'invisibility-spec invis-spec)
-                  (button-put cite-button 'action 'notmuch-toggle-invisible-action)
-                  (button-put cite-button 'follow-link t)
-                  (button-put cite-button 'help-echo
-                              "mouse-1, RET: Show citation")
-
-                  )
+                (notmuch-configure-invisibility-button (insert-button cite-button-text) invis-spec "Show citation")
                 (insert "\n")
                 (goto-char (+ (length cite-button-text) p))
               ))))
@@ -546,16 +541,9 @@ which this thread was originally shown."
                   
                     (goto-char (- beg-sub 1))
                     (insert (concat "\n" indent))
-                    (let ((sig-button (insert-button 
-                                       (concat "[" (number-to-string sig-lines)
-                                         "-line signature.]"))))
-                      (button-put sig-button 'invisibility-spec invis-spec)
-                      (button-put sig-button 'action
-                                  'notmuch-toggle-invisible-action)
-                      (button-put sig-button 'follow-link t)
-                      (button-put sig-button 'help-echo
-                                  "mouse-1, RET: Show signature")
-                      )
+                    (notmuch-configure-invisibility-button
+                     (insert-button (concat "[" (number-to-string sig-lines)
+                                            "-line signature.]"))  invis-spec "Show signature")
                     (insert "\n")
                     (goto-char end))))))
       (forward-line))))
@@ -626,13 +614,9 @@ which this thread was originally shown."
                        'invisible invis-spec)
           (goto-char beg)
           (forward-line)
-          (let ((header-button (make-button (line-beginning-position) (line-end-position))))
-            (button-put header-button 'invisibility-spec (cons invis-spec t))
-            (button-put header-button 'action 'notmuch-toggle-invisible-action)
-            (button-put header-button 'follow-link t)
-            (button-put header-button 'help-echo
-                        "mouse-1, RET: Show headers")
-          ))
+          (notmuch-configure-invisibility-button
+           (make-button (line-beginning-position) (line-end-position))
+           (cons invis-spec t) "Show headers"))
         (goto-char end)
         (insert "\n")
        (set-marker beg nil)
@@ -666,39 +650,6 @@ which this thread was originally shown."
       (notmuch-show-markup-message)))
   (notmuch-show-hide-markers))
 
-(defun notmuch-show-toggle-citations-visible ()
-  "Toggle visibility of citations"
-  (interactive)
-  (if notmuch-show-citations-visible
-      (add-to-invisibility-spec 'notmuch-show-citation)
-    (remove-from-invisibility-spec 'notmuch-show-citation))
-  (set 'notmuch-show-citations-visible (not notmuch-show-citations-visible))
-  ; Need to force the redisplay for some reason
-  (force-window-update)
-  (redisplay t))
-
-(defun notmuch-show-toggle-signatures-visible ()
-  "Toggle visibility of signatures"
-  (interactive)
-  (if notmuch-show-signatures-visible
-      (add-to-invisibility-spec 'notmuch-show-signature)
-    (remove-from-invisibility-spec 'notmuch-show-signature))
-  (set 'notmuch-show-signatures-visible (not notmuch-show-signatures-visible))
-  ; Need to force the redisplay for some reason
-  (force-window-update)
-  (redisplay t))
-
-(defun notmuch-show-toggle-headers-visible ()
-  "Toggle visibility of header fields"
-  (interactive)
-  (if notmuch-show-headers-visible
-      (add-to-invisibility-spec 'notmuch-show-header)
-    (remove-from-invisibility-spec 'notmuch-show-header))
-  (set 'notmuch-show-headers-visible (not notmuch-show-headers-visible))
-  ; Need to force the redisplay for some reason
-  (force-window-update)
-  (redisplay t))
-
 (defun notmuch-show-toggle-body-read-visible ()
   "Toggle visibility of message bodies of read messages"
   (interactive)