mu4e: use mu4e-determine-attachment-dir

Make the old internal mu4e~get-attachment-dir a public function,
improve documentation. Update callers.
This commit is contained in:
Dirk-Jan C. Binnema 2023-07-16 10:43:00 +03:00
parent 66e113ef2a
commit 3b93863f15
3 changed files with 20 additions and 14 deletions

View File

@ -359,7 +359,7 @@ buffers; lets remap its faces so it uses the ones for mu4e."
;; set the attachment dir to something more reasonable than the draft ;; set the attachment dir to something more reasonable than the draft
;; directory. ;; directory.
(setq default-directory (mu4e~get-attachment-dir)) (setq default-directory (mu4e-determine-attachment-dir))
(let ((keymap (lookup-key message-mode-map [menu-bar text]))) (let ((keymap (lookup-key message-mode-map [menu-bar text])))
(when keymap (when keymap

View File

@ -154,7 +154,7 @@ the attachment dir. See Info node `(mu4e) Attachments' for
details. details.
When this called for composing a message, both filename and When this called for composing a message, both filename and
mime-type are nill." mime-type are nil."
:type 'directory :type 'directory
:group 'mu4e-folders :group 'mu4e-folders
:safe 'stringp) :safe 'stringp)
@ -330,9 +330,14 @@ Offer to create it if it does not exist yet."
;; filename and the mime-type as argument, either (or both) which can ;; filename and the mime-type as argument, either (or both) which can
;; be nil ;; be nil
(defun mu4e~get-attachment-dir (&optional fname mimetype) (defun mu4e-determine-attachment-dir (&optional fname mimetype)
"Get the directory for saving attachments from `mu4e-attachment-dir'. "Get the target-directory for attachments.
This is optionally based on the file-name FNAME and its MIMETYPE."
This is based on the variable `mu4e-attachment-dir', which is either:
- if is a string, used it as-is
- a function taking two string parameters, both of which can be nil:
(1) a filename or a URL
(2) a mime-type (such as \"text/plain\"."
(let ((dir (let ((dir
(cond (cond
((stringp mu4e-attachment-dir) ((stringp mu4e-attachment-dir)
@ -340,7 +345,7 @@ This is optionally based on the file-name FNAME and its MIMETYPE."
((functionp mu4e-attachment-dir) ((functionp mu4e-attachment-dir)
(funcall mu4e-attachment-dir fname mimetype)) (funcall mu4e-attachment-dir fname mimetype))
(t (t
(mu4e-error "Unsupported type for mu4e-attachment-dir" ))))) (mu4e-error "Unsupported type for mu4e-attachment-dir" )))))
(if dir (if dir
(expand-file-name dir) (expand-file-name dir)
(mu4e-error "Mu4e-attachment-dir evaluates to nil")))) (mu4e-error "Mu4e-attachment-dir evaluates to nil"))))

View File

@ -73,8 +73,8 @@ might want to add soemthing like the following in your configuration.
If nil, use the value of `mu4e-completing-read-function', integrated If nil, use the value of `mu4e-completing-read-function', integrated
into mu4e. into mu4e.
Many of the third-party completion frameworks such as Helm, Ivy Many of the third-party completion frameworks - such as Helm, Ivy
and Vertico influence `completion-read', so to have mu4e follow and Vertico - influence `completion-read', so to have mu4e follow
your overall settings, try the equivalent of your overall settings, try the equivalent of
(setq mu4e-read-option-use-builtin nil (setq mu4e-read-option-use-builtin nil
@ -85,7 +85,6 @@ Emacs `completing-read' is rather Spartan."
:type 'boolean :type 'boolean
:group 'mu4e) :group 'mu4e)
(defcustom mu4e-use-fancy-chars nil (defcustom mu4e-use-fancy-chars nil
"When set, allow fancy (Unicode) characters for marks/threads. "When set, allow fancy (Unicode) characters for marks/threads.
You can customize the exact fancy characters used with You can customize the exact fancy characters used with
@ -121,7 +120,8 @@ marked as read-only, or non-nil otherwise."
(mu4e-get-headers-buffer)) (mu4e-get-headers-buffer))
((mu4e-current-buffer-type-p 'headers) ((mu4e-current-buffer-type-p 'headers)
(mu4e-get-view-buffer)) (mu4e-get-view-buffer))
(t (mu4e-error "This window is neither the headers nor the view window.")))) (t (mu4e-error
"This window is neither the headers nor the view window."))))
(other-win (and other-buf (get-buffer-window other-buf)))) (other-win (and other-buf (get-buffer-window other-buf))))
(if (window-live-p other-win) (if (window-live-p other-win)
(select-window other-win) (select-window other-win)
@ -206,7 +206,7 @@ Return the cdr (value) of the matching cell, if any."
"Read and return one of CHOICES, prompting for PROMPT. "Read and return one of CHOICES, prompting for PROMPT.
PROMPT describes a multiple-choice question to the user. CHOICES PROMPT describes a multiple-choice question to the user. CHOICES
is an alist of the fiorm is an alist of the form
( ( <display-string> ( <shortcut> . <value> )) ( ( <display-string> ( <shortcut> . <value> ))
... ) ... )
Any input that is not one of CHOICES is ignored. This is mu4e's Any input that is not one of CHOICES is ignored. This is mu4e's
@ -227,7 +227,8 @@ Return the matching choice value (cdr of the cell)."
(let ((prefix (minibuffer-contents-no-properties))) (let ((prefix (minibuffer-contents-no-properties)))
(unless (string-empty-p prefix) (unless (string-empty-p prefix)
(setq quick-result (setq quick-result
(mu4e--matching-choice choices (string-to-char prefix))) (mu4e--matching-choice
choices (string-to-char prefix)))
(when quick-result (when quick-result
(exit-minibuffer))))) (exit-minibuffer)))))
-1 'local)) -1 'local))
@ -474,7 +475,6 @@ If there is not e-mail address at point, do nothing."
(format "%d" size)) (format "%d" size))
(t "?"))) (t "?")))
(defun mu4e-split-ranges-to-numbers (str n) (defun mu4e-split-ranges-to-numbers (str n)
"Convert STR containing attachment numbers into a list of numbers. "Convert STR containing attachment numbers into a list of numbers.
@ -542,7 +542,8 @@ Or go to the top level if there is none."
(date (if date (format-time-string "%F: " date) "")) (date (if date (format-time-string "%F: " date) ""))
(title (format "%s%s" date subject)) (title (format "%s%s" date subject))
(msgid (or (plist-get msg :message-id) (msgid (or (plist-get msg :message-id)
(mu4e-error "Cannot bookmark message without message-id")))) (mu4e-error
"Cannot bookmark message without message-id"))))
`(,title `(,title
,@(bookmark-make-record-default 'no-file 'no-context) ,@(bookmark-make-record-default 'no-file 'no-context)
(message-id . ,msgid) (message-id . ,msgid)