* mu4e-utils.el: improve mu4e-quit-buffer (bury-buffer)

This commit is contained in:
djcb 2012-06-12 00:15:06 +03:00
parent 46a6b445b3
commit a4bef96620
1 changed files with 19 additions and 15 deletions

View File

@ -69,7 +69,7 @@ dir already existed, or has been created, nil otherwise."
"Like `message', but prefixed with mu4e." "Like `message', but prefixed with mu4e."
(message "%s" (apply 'mu4e-format frm args))) (message "%s" (apply 'mu4e-format frm args)))
(defun mu4e~read-char-choice (prompt choices) (defun mu4e~read-char-choice (prompt choices)
"Compatiblity wrapper for `read-char-choice', which is emacs-24 "Compatiblity wrapper for `read-char-choice', which is emacs-24
only." only."
@ -92,13 +92,13 @@ options. Cells have the following structure:
option. The first character of OPTIONSTRING is used as the option. The first character of OPTIONSTRING is used as the
shortcut, and obviously all shortcuts must be different, so you shortcut, and obviously all shortcuts must be different, so you
can prefix the string with an uniquifying character. can prefix the string with an uniquifying character.
The options are provided as a list for the user to choose from; The options are provided as a list for the user to choose from;
user can then choose by typing CHAR. Example: user can then choose by typing CHAR. Example:
(mu4e-read-option \"Choose an animal: \" (mu4e-read-option \"Choose an animal: \"
'((\"Monkey\" ?m) (\"Gnu\" ?g) (\"platipus\"))) '((\"Monkey\" ?m) (\"Gnu\" ?g) (\"platipus\")))
User now will be presented with a list: User now will be presented with a list:
\"Choose an animal: [m]Monkey, [g]Gnu, [p]latipus\"." \"Choose an animal: [m]Monkey, [g]Gnu, [p]latipus\"."
(let* ((prompt (mu4e-format "%s" prompt)) (let* ((prompt (mu4e-format "%s" prompt))
(chosen) (chosen)
(optionsstr (optionsstr
@ -118,7 +118,7 @@ User now will be presented with a list:
(concat prompt optionsstr (concat prompt optionsstr
" [" (propertize "C-g" 'face 'mu4e-highlight-face) " to quit]") " [" (propertize "C-g" 'face 'mu4e-highlight-face) " to quit]")
;; the allowable chars ;; the allowable chars
(map 'list (lambda(elm) (string-to-char (car elm))) options))) (map 'list (lambda(elm) (string-to-char (car elm))) options)))
(chosen (chosen
(find-if (find-if
(lambda (option) (eq response (string-to-char (car option)))) (lambda (option) (eq response (string-to-char (car option))))
@ -611,7 +611,7 @@ FUNC (if non-nil) afterwards."
(when (member major-mode '(mu4e-headers-mode mu4e-view-mode mu4e-main-mode)) (when (member major-mode '(mu4e-headers-mode mu4e-view-mode mu4e-main-mode))
(kill-buffer)))) (kill-buffer))))
(buffer-list))) (buffer-list)))
(defvar mu4e-update-timer nil (defvar mu4e-update-timer nil
"*internal* The mu4e update timer.") "*internal* The mu4e update timer.")
@ -775,18 +775,22 @@ is ignored."
(newline) (newline)
(insert-image img imgpath nil t)))) (insert-image img imgpath nil t))))
(defun mu4e-quit-buffer () (defun mu4e-quit-buffer ()
"Bury the current buffer (and delete all windows displaying it)." "Bury the current buffer (and delete all windows displaying it)."
(interactive) (interactive)
(walk-windows (let ((buf (current-buffer)))
;; kill any window that: (walk-windows
;; a) displays the current buffer ;; kill any window that:
;; b) is not the only win ;; a) displays the current buffer
(lambda (win) ;; b) is not the only win
(when (eq (window-buffer win) (current-buffer)) (lambda (win)
(unless (one-window-p t) (when (eq (window-buffer win) (current-buffer))
(delete-window win)))) nil t)) (unless (one-window-p t)
(delete-window win)))) nil t)
;; if current buffer is still here, bury it
(when (eq buf (current-buffer))
(bury-buffer))))
(defun mu4e-hide-other-mu4e-buffers () (defun mu4e-hide-other-mu4e-buffers ()
@ -801,7 +805,7 @@ displaying it). Do _not_ bury the current buffer, though."
(when (member major-mode '(mu4e-headers-mode mu4e-view-mode mu4e-main-mode)) (when (member major-mode '(mu4e-headers-mode mu4e-view-mode mu4e-main-mode))
(unless (one-window-p t) (unless (one-window-p t)
(delete-window win)))))) nil t))) (delete-window win)))))) nil t)))
(provide 'mu4e-utils) (provide 'mu4e-utils)
;;; End of mu4e-utils.el ;;; End of mu4e-utils.el