mirror of https://github.com/djcb/mu.git
* refactor search / search-editing a bit
This commit is contained in:
parent
c7c823d0ce
commit
602e857dc3
|
@ -106,42 +106,6 @@ are of the form:
|
|||
(erase-buffer)
|
||||
(mu4e~mark-clear)))))
|
||||
|
||||
|
||||
(defvar mu4e~headers-search-hist nil
|
||||
"History list of searches.")
|
||||
|
||||
|
||||
(defun mu4e-headers-search (expr search-all)
|
||||
"Search in the mu database for EXPR, and switch to the output
|
||||
buffer for the results. If SEARCH-ALL is non-nil return all
|
||||
results, otherwise, limit number of results to
|
||||
`mu4e-search-results-limit'. This is an interactive function which
|
||||
ask user for EXPR, and SEARCH-ALL as prefix-argument."
|
||||
(interactive
|
||||
(let ((expr (read-string
|
||||
(mu4e-format "Search for: ")
|
||||
nil
|
||||
'mu4e~headers-search-hist nil t))
|
||||
(search-all current-prefix-arg))
|
||||
(list expr search-all)))
|
||||
(let ((buf (get-buffer-create mu4e~headers-buffer-name))
|
||||
(inhibit-read-only t))
|
||||
(mu4e-mark-handle-when-leaving)
|
||||
(with-current-buffer buf
|
||||
(mu4e-headers-mode)
|
||||
(setq
|
||||
global-mode-string (propertize expr 'face 'mu4e-title-face)
|
||||
mu4e~headers-query expr
|
||||
mu4e~headers-buffer buf
|
||||
mode-name "mu4e-headers"))
|
||||
(switch-to-buffer buf)
|
||||
(mu4e~proc-find
|
||||
(replace-regexp-in-string "\"" "\\\\\"" expr) ;; escape "\"
|
||||
(unless search-all mu4e-search-results-limit))
|
||||
;;; when we're starting a new search, we also kill the
|
||||
;;; view buffer, if any
|
||||
(mu4e-view-kill-buffer-and-window)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; handler functions
|
||||
;;
|
||||
|
@ -331,7 +295,7 @@ after the end of the search results."
|
|||
(define-key map "s" 'mu4e-headers-search)
|
||||
|
||||
(define-key map "b" 'mu4e-headers-search-bookmark)
|
||||
(define-key map "B" 'mu4e-headers-search-bookmark-edit-first)
|
||||
(define-key map "B" 'mu4e-headers-search-bookmark-edit)
|
||||
|
||||
(define-key map "q" 'mu4e~headers-kill-buffer-and-window)
|
||||
(define-key map "z" 'mu4e~headers-kill-buffer-and-window)
|
||||
|
@ -608,6 +572,27 @@ non-nill, don't raise an error when the docid is not found."
|
|||
(error "Cannot find message with docid %S" docid)))))
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun mu4e~headers-search-execute (expr search-all)
|
||||
"Search in the mu database for EXPR, and switch to the output
|
||||
buffer for the results. If SEARCH-ALL is non-nil return all
|
||||
results, otherwise, limit number of results to
|
||||
`mu4e-search-results-limit'."
|
||||
(let ((buf (get-buffer-create mu4e~headers-buffer-name))
|
||||
(inhibit-read-only t))
|
||||
(with-current-buffer buf
|
||||
(mu4e-headers-mode)
|
||||
(setq
|
||||
global-mode-string (propertize expr 'face 'mu4e-title-face)
|
||||
mu4e~headers-query expr
|
||||
mu4e~headers-buffer buf
|
||||
mode-name "mu4e-headers"))
|
||||
(switch-to-buffer buf)
|
||||
(mu4e~proc-find
|
||||
(replace-regexp-in-string "\"" "\\\\\"" expr) ;; escape "\"
|
||||
(unless search-all mu4e-search-results-limit))
|
||||
;;; when we're starting a new search, we also kill the
|
||||
;;; view buffer, if any
|
||||
(mu4e-view-kill-buffer-and-window)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; search-based marking
|
||||
|
@ -726,30 +711,45 @@ limited to the message at point and its descendants."
|
|||
|
||||
|
||||
;;; interactive functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun mu4e-headers-search-bookmark (query search-all)
|
||||
"Search using some bookmarked query. when search-all (prefix
|
||||
argument) is non-nil, show /all/ results, otherwise, limit to up to
|
||||
`mu4e-search-results-limit'."
|
||||
(interactive
|
||||
(let ((query (mu4e-ask-bookmark "Bookmark: ")))
|
||||
(list query current-prefix-arg)))
|
||||
(when query
|
||||
(mu4e-headers-search query search-all)))
|
||||
(defvar mu4e~headers-search-hist nil
|
||||
"History list of searches.")
|
||||
|
||||
(defvar mu4e~headers-bookmark-hist nil
|
||||
"History list for bookmarks used.")
|
||||
(defun mu4e-headers-search (&optional expr search-all prompt edit)
|
||||
"Search in the mu database for EXPR, and switch to the output
|
||||
buffer for the results. If SEARCH-ALL is non-nil return all
|
||||
results, otherwise, limit number of results to
|
||||
`mu4e-search-results-limit'. This is an interactive function which
|
||||
ask user for EXPR, and SEARCH-ALL as prefix-argument. PROMPT, if
|
||||
non-nil, is the prompt used by this function (default is \"Search
|
||||
for:\"). If EDIT is non-nil, instead of executing the query for
|
||||
EXPR, let the user edit the query before executing it."
|
||||
(interactive)
|
||||
(let* ((prompt (mu4e-format (or prompt "Search for: ")))
|
||||
(expr
|
||||
(if edit
|
||||
(read-string prompt expr)
|
||||
(or expr
|
||||
(read-string prompt nil 'mu4e~headers-search-hist)))))
|
||||
(mu4e-mark-handle-when-leaving)
|
||||
(mu4e~headers-search-execute expr (or search-all current-prefix-arg))))
|
||||
|
||||
(defun mu4e-headers-search-bookmark-edit-first (expr search-all)
|
||||
"Search using some bookmarked query, but allow for editing the
|
||||
bookmark before submitting it. With C-u prefix, show /all/ results,
|
||||
otherwise, limit to up to `mu4e-search-results-limit'."
|
||||
(interactive
|
||||
(list (read-string
|
||||
(concat (or (mu4e-ask-bookmark "Edit bookmark: ") "") " ")
|
||||
'mu4e~headers-bookmark-hist)
|
||||
current-prefix-arg))
|
||||
(when expr
|
||||
(mu4e-headers-search expr search-all)))
|
||||
|
||||
(defun mu4e-headers-search-bookmark (&optional expr search-all edit)
|
||||
"Search using some bookmarked query EXPR. When SEARCH-ALL (prefix
|
||||
argument) is non-nil, show *all* results, otherwise, limit to up to
|
||||
`mu4e-search-results-limit'. If EDIT is non-nil, let the user edit
|
||||
the bookmark before starting the search."
|
||||
(interactive)
|
||||
(let ((expr
|
||||
(or expr
|
||||
(mu4e-ask-bookmark (if edit "Select bookmark: " "Bookmark: ")))))
|
||||
(mu4e-headers-search expr (or search-all current-prefix-arg)
|
||||
(when edit "Edit bookmark: ") edit)))
|
||||
|
||||
(defun mu4e-headers-search-bookmark-edit ()
|
||||
"Edit an existing bookmark before executing it."
|
||||
(interactive)
|
||||
(mu4e-headers-search-bookmark nil current-prefix-arg t))
|
||||
|
||||
|
||||
(defun mu4e-headers-view-message ()
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
(let ((map (make-sparse-keymap)))
|
||||
|
||||
(define-key map "b" 'mu4e-headers-search-bookmark)
|
||||
(define-key map "B" 'mu4e-headers-search-bookmark-edit-first)
|
||||
(define-key map "B" 'mu4e-headers-search-bookmark-edit)
|
||||
|
||||
(define-key map "s" 'mu4e-headers-search)
|
||||
(define-key map "q" 'mu4e-quit)
|
||||
|
|
|
@ -313,7 +313,7 @@ is nil, and otherwise open it."
|
|||
(define-key map "s" 'mu4e-headers-search)
|
||||
|
||||
(define-key map "b" 'mu4e-headers-search-bookmark)
|
||||
(define-key map "B" 'mu4e-headers-search-bookmark-edit-first)
|
||||
(define-key map "B" 'mu4e-headers-search-bookmark-edit)
|
||||
|
||||
(define-key map "%" 'mu4e-view-mark-matches)
|
||||
(define-key map "t" 'mu4e-view-mark-subthread)
|
||||
|
|
Loading…
Reference in New Issue