Re: ido-mode and saving attachments
Erik Hetzner <[email protected]> Wed, 05 Dec 2018 18:22:13 -0800
| Newsgroups | gmane.mail.wanderlust.general |
|---|---|
| Message-ID | <5c0887d7.1c69fb81.caecb.bce1__10608.6488267922$1544062931$gmane$org@mx.google.com> |
Hi Greg,
I’ve seen similar behavior in the past.
The short answer is: does C-j work for you?
Slightly longer answer:
Can you use `e` to extract attachment, then choose a directory, then
use C-j to select a directory *only*?
By default this works for me with `mime-save-content' (but not
`wl-mime-save-content').
The long answer:
WL calls `read-file-name' with the options `directory' and `initial':
e.g., something like:
(read-file-name "what? " "/tmp/" nil nil "foo")
With the `mime-save-content' method, if the user chooses a directory
only, the function will use the MIME supplied filename with the
directory you choose. (With `wl-mime-save-content' it will error if
you select a directory, which makes selecting a different directory
with a default filename awkward in ido or ivy). This works fine with
the built-in `read-file-name' and ivy, which allow pretty easy
selection of a directory name. But ido makes you use C-j to select the
directory only - by default it will choose the first existing file in
the directory.
Saving an attachment is slightly odd because the user is allowed to
either choose a directory and use the default filename, or choose the
filename itself within a directory. ido doesn’t seem to support
selection of a directory from `read-file-name' very well. If you never
want to override the filename you could write your own extract method,
e.g.
(defun mime-save-content-to-directory (entity situation)
(let ((name (or (mime-entity-safe-filename entity)
(format "%s" (mime-entity-media-type entity))))
(dir (if (eq t mime-save-directory)
default-directory
mime-save-directory))
filename)
(setq filename (expand-file-name (file-name-nondirectory name)
(read-directory-name "Directory: " dir)))
(if (file-exists-p filename)
(or (yes-or-no-p (format "File %s exists. Save anyway? " filename))
(error "")))
(mime-write-entity-content entity (expand-file-name filename))
filename))
;; Force use of mime-save-content-to-directory always
(defun mime-preview-extract-current-entity (&optional ignore-examples)
"Extract current entity into file (maybe).
It decodes current entity to call internal or external method as
\"extract\" mode. The method is selected from variable
`mime-acting-condition'."
(interactive "P")
(cl-letf (((symbol-function #'mime-play-entity)
(lambda (entity &optional situation ignored-method)
(mime-save-content-to-directory entity situation))))
(mime-preview-play-current-entity ignore-examples "extract")))
best, Erik
On Mon, 03 Dec 2018 14:27:06 -0800,
Greg Bognar <[email protected]> wrote:
>
> Hi,
>
> When I enable ido.el (which is part of Emacs) in my init.el with
>
> (ido-mode 'both)
> (ido-everywhere)
>
> it can't handle saving attachments. It saves the attachment with the file name
> that's on top of the completion list, prompting you to overwrite it; and it
> won't save in the directory that you choose with the ido prompt. If I comment
> out ido-everywhere and use only
>
> (ido-mode 'both)
>
> then I get the expected behavior, but ido does not work for attachment saving.
>
> Is there any way to get ido work with WL?
>
> Note: I'm using mime-preview-extract-current-entity
> (https://www.emacswiki.org/emacs/WlFaq#toc4)3 to save attachments. But I can't
> see anything in its definition that would cause the problem.
>
> All the best,
> Greg
>
--
Sent from my free software system <http://fsf.org/>.