From 4cffcfa440ce52df088616d119b8957a521338a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sun, 22 Nov 2015 22:32:05 +0100 Subject: [PATCH] mu4e-{view,headers}: Refactor a (lamba) kbd-bound function into a named function Because this was a lambda C-h m would just show "??" instead of the function name, and the documentation would be really confusing since it showed the deparsed lambda function instead of the function name being called. Fix this by refactoring both the view & headers [ and ] functions into named functions, and make their shared logic new internal mu4u~{headers,view}-* functions. --- mu4e/mu4e-headers.el | 18 ++++++++++++++---- mu4e/mu4e-view.el | 21 ++++++++++++++++----- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 5fcd55ce..0aefd1f8 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -616,9 +616,8 @@ after the end of the search results." (define-key map (kbd "") 'mu4e-headers-prev) (define-key map (kbd "") 'mu4e-headers-next) + (define-key map (kbd "[") 'mu4e-headers-prev-unread) (define-key map (kbd "]") 'mu4e-headers-next-unread) - (define-key map (kbd "[") - (lambda() (interactive) (mu4e-headers-next-unread t))) ;; change the number of headers (define-key map (kbd "C-+") 'mu4e-headers-split-view-grow) @@ -1472,10 +1471,10 @@ previous header." (interactive "P") (mu4e~headers-move (- (or n 1)))) -(defun mu4e-headers-next-unread (&optional backwards) +(defun mu4e~headers-prev-or-next-unread (backwards) "Move point to the next message that is unread (and untrashed). If BACKWARDS is non-`nil', move backwards." - (interactive "P") + (interactive) (or (mu4e-headers-find-if-next (lambda (msg) (let ((flags (mu4e-message-field msg :flags))) @@ -1484,6 +1483,17 @@ untrashed). If BACKWARDS is non-`nil', move backwards." (mu4e-message (format "No %s unread message found" (if backwards "previous" "next"))))) +(defun mu4e-headers-prev-unread () + "Move point to the previous message that is unread (and +untrashed)." + (interactive) + (mu4e~headers-prev-or-next-unread t)) + +(defun mu4e-headers-next-unread () + "Move point to the next message that is unread (and +untrashed)." + (interactive) + (mu4e~headers-prev-or-next-unread nil)) (defun mu4e~headers-jump-to-maildir (maildir) "Show the messages in maildir (user is prompted to ask what diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index c5afcbf8..7e2ba575 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -601,9 +601,8 @@ FUNC should be a function taking two arguments: (define-key map (kbd "") 'mu4e-view-headers-next) (define-key map (kbd "") 'mu4e-view-headers-prev) + (define-key map (kbd "[") 'mu4e-view-headers-prev-unread) (define-key map (kbd "]") 'mu4e-view-headers-next-unread) - (define-key map (kbd "[") - (lambda() (interactive) (mu4e-view-headers-next-unread t))) ;; switching to view mode (if it's visible) (define-key map "y" 'mu4e-select-other-view) @@ -878,17 +877,29 @@ N (prefix argument), to the Nth previous header." (mu4e~view-in-headers-context (mu4e~headers-move (- (or n 1))))) -(defun mu4e-view-headers-next-unread (&optional backwards) +(defun mu4e~view-prev-or-next-unread (backwards) "Move point to the next or previous (when BACKWARDS is non-`nil') unread message header in the headers buffer connected with this message view. If this succeeds, return the new docid. Otherwise, return nil." - (interactive "P") (mu4e~view-in-headers-context - (mu4e-headers-next-unread backwards)) + (mu4e~headers-prev-or-next-unread backwards)) (mu4e-select-other-view) (mu4e-headers-view-message)) +(defun mu4e-view-headers-prev-unread () +"Move point to the previous unread message header in the headers +buffer connected with this message view. If this succeeds, return +the new docid. Otherwise, return nil." + (interactive) + (mu4e~view-prev-or-next-unread t)) + +(defun mu4e-view-headers-next-unread () + "Move point to the next unread message header in the headers +buffer connected with this message view. If this succeeds, return +the new docid. Otherwise, return nil." + (interactive) + (mu4e~view-prev-or-next-unread nil)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;