* mu4e: use (user-error ..), not (error ..) for user errors

This commit is contained in:
djcb 2012-09-06 10:33:53 +03:00
parent 4508417e34
commit e342f9a5c4
6 changed files with 29 additions and 22 deletions

View File

@ -89,10 +89,10 @@ forwarded or edited) in `mu4e-compose-pre-hook.")
"Insert the last captured message file as an attachment." "Insert the last captured message file as an attachment."
(interactive) (interactive)
(unless mu4e-captured-message (unless mu4e-captured-message
(mu4e-error "No message has been captured")) (mu4e-warn "No message has been captured"))
(let ((path (plist-get mu4e-captured-message :path))) (let ((path (plist-get mu4e-captured-message :path)))
(unless (file-exists-p path) (unless (file-exists-p path)
(mu4e-error "Captured message file not found")) (mu4e-warn "Captured message file not found"))
(mml-attach-file (mml-attach-file
path path
"application/octet-stream" "application/octet-stream"
@ -689,7 +689,7 @@ for draft messages."
(mu4e-error "Invalid compose type '%S'" compose-type)) (mu4e-error "Invalid compose type '%S'" compose-type))
(when (and (eq compose-type 'edit) (when (and (eq compose-type 'edit)
(not (member 'draft (mu4e-field-at-point :flags)))) (not (member 'draft (mu4e-field-at-point :flags))))
(mu4e-error "Editing is only allowed for draft messages")) (mu4e-warn "Editing is only allowed for draft messages"))
;; run the hooks ;; run the hooks
(mu4e~compose-run-hooks compose-type) (mu4e~compose-run-hooks compose-type)

View File

@ -964,11 +964,11 @@ to get it from; it's a symbol, either 'future or 'past."
(case whence (case whence
(past (past
(unless mu4e~headers-query-past (unless mu4e~headers-query-past
(mu4e-error "No more previous queries")) (mu4e-warn "No more previous queries"))
(pop mu4e~headers-query-past)) (pop mu4e~headers-query-past))
(future (future
(unless mu4e~headers-query-future (unless mu4e~headers-query-future
(mu4e-error "No more next queries")) (mu4e-warn "No more next queries"))
(pop mu4e~headers-query-future)))) (pop mu4e~headers-query-future))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -1029,7 +1029,7 @@ the last search expression."
nil 'mu4e~headers-search-hist nil t))) nil 'mu4e~headers-search-hist nil t)))
(list filter))) (list filter)))
(unless mu4e~headers-last-query (unless mu4e~headers-last-query
(mu4e-error "There's nothing to filter")) (mu4e-warn "There's nothing to filter"))
(mu4e-headers-search (mu4e-headers-search
(format "(%s) AND %s" mu4e~headers-last-query filter))) (format "(%s) AND %s" mu4e~headers-last-query filter)))
@ -1106,7 +1106,7 @@ current window. "
(unless (eq major-mode 'mu4e-headers-mode) (unless (eq major-mode 'mu4e-headers-mode)
(mu4e-error "Must be in mu4e-headers-mode (%S)" major-mode)) (mu4e-error "Must be in mu4e-headers-mode (%S)" major-mode))
(let* ((docid (or (mu4e~headers-docid-at-point) (let* ((docid (or (mu4e~headers-docid-at-point)
(mu4e-error "No message at point"))) (mu4e-warn "No message at point")))
(viewwin (mu4e~headers-redraw-get-view-window))) (viewwin (mu4e~headers-redraw-get-view-window)))
(unless (window-live-p viewwin) (unless (window-live-p viewwin)
(mu4e-error "Cannot get a message view")) (mu4e-error "Cannot get a message view"))
@ -1208,13 +1208,13 @@ N. Otherwise, don't do anything."
(horizontal (horizontal
(let ((newval (+ (or n 1) mu4e-headers-visible-lines))) (let ((newval (+ (or n 1) mu4e-headers-visible-lines)))
(unless (> newval 0) (unless (> newval 0)
(mu4e-error (mu4e-warn
"Cannot make the number of visible lines any smaller")) "Cannot make the number of visible lines any smaller"))
(setq mu4e-headers-visible-lines newval))) (setq mu4e-headers-visible-lines newval)))
(vertical (vertical
(let ((newval (+ (or n 1) mu4e-headers-visible-columns))) (let ((newval (+ (or n 1) mu4e-headers-visible-columns)))
(unless (> newval 0) (unless (> newval 0)
(mu4e-error (mu4e-warn
"Cannot make the number of visible columns any smaller")) "Cannot make the number of visible columns any smaller"))
(setq mu4e-headers-visible-columns newval)))) (setq mu4e-headers-visible-columns newval))))
(let ((viewwin (mu4e~headers-redraw-get-view-window))) (let ((viewwin (mu4e~headers-redraw-get-view-window)))

View File

@ -28,7 +28,7 @@
(require 'mu4e-utils) ;; utility functions (require 'mu4e-utils) ;; utility functions
(defconst mu4e~main-buffer-name "*mu4e-main*" (defconst mu4e~main-buffer-name " *mu4e-main*"
"*internal* Name of the mu4e main view buffer.") "*internal* Name of the mu4e main view buffer.")
(defvar mu4e-main-mode-map (defvar mu4e-main-mode-map

View File

@ -119,7 +119,7 @@ The following marks are available, and the corresponding props:
(otherwise (mu4e-error "Invalid mark %S" mark)))) (otherwise (mu4e-error "Invalid mark %S" mark))))
(markkar (car markcell)) (markkar (car markcell))
(target (cdr markcell))) (target (cdr markcell)))
(unless docid (mu4e-error "No message on this line")) (unless docid (mu4e-warn "No message on this line"))
(unless (eq major-mode 'mu4e-headers-mode) (unless (eq major-mode 'mu4e-headers-mode)
(mu4e-error "Not in headers-mode")) (mu4e-error "Not in headers-mode"))
(save-excursion (save-excursion
@ -272,7 +272,7 @@ If NO-CONFIRMATION is non-nil, don't ask user for confirmation."
"Unmark all marked messages." "Unmark all marked messages."
(interactive) (interactive)
(when (or (null mu4e~mark-map) (zerop (hash-table-count mu4e~mark-map))) (when (or (null mu4e~mark-map) (zerop (hash-table-count mu4e~mark-map)))
(mu4e-error "Nothing is marked")) (mu4e-warn "Nothing is marked"))
(maphash (maphash
(lambda (docid val) (lambda (docid val)
(save-excursion (save-excursion

View File

@ -103,10 +103,17 @@ user-input, don't show anyhting."
nil)) nil))
(defun mu4e-error (frm &rest args) (defun mu4e-error (frm &rest args)
"Create [mu4e]-prefixed error based on format FRM and ARGS." "Create [mu4e]-prefixed error based on format FRM and ARGS. Does
a local-exit and does not return."
(mu4e-log 'error (apply 'mu4e-format frm args)) (mu4e-log 'error (apply 'mu4e-format frm args))
(error "%s" (apply 'mu4e-format frm args))) (error "%s" (apply 'mu4e-format frm args)))
(defun mu4e-warn (frm &rest args)
"Create [mu4e]-prefixed warning based on format FRM and
ARGS. Does a local-exit and does not return."
(mu4e-log 'error (apply 'mu4e-format frm args))
(user-error "%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."
@ -166,7 +173,7 @@ Function will return the cdr of the list element."
options))) options)))
(if chosen (if chosen
(cdr chosen) (cdr chosen)
(mu4e-error "Unknown shortcut '%c'" response)))) (mu4e-warn "Unknown shortcut '%c'" response))))
(defun mu4e~get-maildirs-1 (path mdir) (defun mu4e~get-maildirs-1 (path mdir)
@ -229,7 +236,7 @@ maildirs under `mu4e-maildir."
(ido-completing-read prompt (mu4e-get-maildirs)) (ido-completing-read prompt (mu4e-get-maildirs))
(or (car-safe (or (car-safe
(find-if (lambda (item) (= kar (cdr item))) mu4e-maildir-shortcuts)) (find-if (lambda (item) (= kar (cdr item))) mu4e-maildir-shortcuts))
(mu4e-error "Unknown shortcut '%c'" kar))))))) (mu4e-warn "Unknown shortcut '%c'" kar)))))))
(defun mu4e-ask-maildir-check-exists (prompt) (defun mu4e-ask-maildir-check-exists (prompt)
@ -250,7 +257,7 @@ the region, for moving to maildir TARGET. If target is not
provided, function asks for it." provided, function asks for it."
(interactive) (interactive)
(unless (mu4e~headers-docid-at-point) (unless (mu4e~headers-docid-at-point)
(mu4e-error "No message at point.")) (mu4e-warn "No message at point."))
(let* ((target (or target (mu4e-ask-maildir "Move message to: "))) (let* ((target (or target (mu4e-ask-maildir "Move message to: ")))
(target (if (string= (substring target 0 1) "/") (target (if (string= (substring target 0 1) "/")
target target
@ -291,7 +298,7 @@ KAR, or raise an error if none is found."
mu4e-bookmarks))) mu4e-bookmarks)))
(if chosen-bm (if chosen-bm
(nth 0 chosen-bm) (nth 0 chosen-bm)
(mu4e-error "Unknown shortcut '%c'" kar)))) (mu4e-warn "Unknown shortcut '%c'" kar))))
;;; converting flags->string and vice-versa ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; converting flags->string and vice-versa ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -476,7 +483,7 @@ there is no message at point."
((eq major-mode 'mu4e-view-mode) ((eq major-mode 'mu4e-view-mode)
mu4e~view-msg)))) mu4e~view-msg))))
(if (and (null msg) raise-err) (if (and (null msg) raise-err)
(mu4e-error "No message at point") (mu4e-warn "No message at point")
msg))) msg)))
(defun mu4e-field-at-point (field) (defun mu4e-field-at-point (field)
@ -545,7 +552,7 @@ process."
"Handler function for showing an error." "Handler function for showing an error."
;; don't use mu4e-error here; it's running in the process filter ctx ;; don't use mu4e-error here; it's running in the process filter ctx
(case errcode (case errcode
(4 (error "No matches for this search query.")) (4 (user-error "No matches for this search query."))
(t (error "Error %d: %s" errcode errmsg)))) (t (error "Error %d: %s" errcode errmsg))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -855,9 +862,9 @@ This includes expanding e.g. 3-5 into 3,4,5. If the letter
#'(lambda (x) #'(lambda (x)
(cond (cond
((> x n) ((> x n)
(mu4e-error "Attachment %d bigger than maximum (%d)" x n)) (mu4e-warn "Attachment %d bigger than maximum (%d)" x n))
((< x 1) ((< x 1)
(mu4e-error "Attachment number must be greater than 0 (%d)" x)))) (mu4e-warn "Attachment number must be greater than 0 (%d)" x))))
list))) list)))

View File

@ -1121,7 +1121,7 @@ user that unmarking only works in the header list."
"Go to a numbered url." "Go to a numbered url."
(interactive "n[mu4e] Visit url with number: ") (interactive "n[mu4e] Visit url with number: ")
(let ((url (gethash num mu4e~view-link-map))) (let ((url (gethash num mu4e~view-link-map)))
(unless url (mu4e-error "Invalid number for URL")) (unless url (mu4e-warn "Invalid number for URL"))
(funcall (mu4e~view-browse-url-func url)))) (funcall (mu4e~view-browse-url-func url))))
(defconst mu4e~view-raw-buffer-name "*mu4e-raw-view*" (defconst mu4e~view-raw-buffer-name "*mu4e-raw-view*"