doomemacs / doomemacs/core

+mu4e/attach-files: two minor quirks

Open
#5,892 0 comments 0 reactions 0 assignees View on GitHub
is:bug needs-triage
Dominant language
Emacs Lisp
Stars
22.7k
Forks
3.1k
Avg merge
10h 46m
Merged PRs (30d)
4

Description

### What did you expect to happen?

1. When I call `+mu4e/attach-files` and immediately exit with `Enter`, a `dired` buffer opens.
2. Attachments are always inserted at the end of the message.

### What actually happened?

1. When I call `+mu4e/attach-files` and immediately exit with `Enter`, the message draft itself is inserted as attachment.
2. When attachments are selected using `dired-mu4e-attach-ctrl-c-ctrl-c`, they are inserted at point.

### Describe your attempts to resolve the issue

This seems to resolve both issues:
1. let `read-file-name` return `default-directory` if nothing was entered
2. go to the end of the message before inserting the attachments from `files-to-attach`

Code below.

```elisp
(defun +mu4e/attach-files (&optional files-to-attach)
"When called in a dired buffer, ask for a message to attach the marked files to.
When called in a mu4e:compose or org-msg buffer, `read-file-name'to either
attach a file, or select a folder to open dired in and select file attachments
(using `dired-mu4e-attach-ctrl-c-ctrl-c').

When otherwise called, open a dired buffer and enable `dired-mu4e-attach-ctrl-c-ctrl-c'."
;; TODO add ability to attach files (+dirs) as a single (named) archive
(interactive "p")
(+mu4e-compose-org-msg-handle-toggle (/= 1 files-to-attach))
(pcase major-mode
((or 'mu4e-compose-mode 'org-msg-edit-mode)
(let ((mail-buffer (current-buffer))
(location (read-file-name "Attach: " nil default-directory)))
(if (not (file-directory-p location))
(pcase major-mode
('mu4e-compose-mode
(save-excursion
(goto-char (point-max))
(unless (eq (current-column) 0)
(insert "\n\n")
(forward-line 2))
(mail-add-attachment location)))
('org-msg-edit-mode (org-msg-attach-attach location)))
(split-window-sensibly)
(with-current-buffer (dired location)
(setq-local dired-mail-buffer mail-buffer)
(dired-mu4e-attach-ctrl-c-ctrl-c 1)))))
('dired-mode
(unless (and files-to-attach (/= 1 files-to-attach))
(setq files-to-attach
(delq nil
(mapcar
;; don't attach directories
(lambda (f) (if (file-directory-p f) nil f))
(nreverse (dired-map-over-marks (dired-get-filename) nil))))))
(if (not files-to-attach)
(progn
(message "No files marked, aborting.")
(kill-buffer-and-window))
(if-let ((mail-target-buffer (bound-and-true-p dired-mail-buffer)))
(progn (kill-buffer-and-window)
(switch-to-buffer mail-target-buffer))
(if (and (+mu4e-current-buffers)
(y-or-n-p "Attach files to existing mail composition buffer? "))
(progn (setf mail-target-buffer
(completing-read "Message: " (+mu4e-current-buffers)))
(kill-buffer-and-window)
(switch-to-buffer mail-target-buffer))
(kill-buffer-and-window)
(mu4e-compose 'new)))
(pcase major-mode
('mu4e-compose-mode
(save-excursion
(goto-char (point-max))
(unless (eq (current-column) 0)
(insert "\n\n")
(forward-line 2))
(mapcar #'mail-add-attachment files-to-attach)))
('org-msg-edit-mode (mapcar #'org-msg-attach-attach files-to-attach)))))
(_
(split-window-sensibly)
(with-current-buffer (call-interactively #'find-file)
(dired-mu4e-attach-ctrl-c-ctrl-c 1)))))
```

### Steps to reproduce

1. Call `+mu4e/attach-files` and immediately exit with `Enter`.
2. Insert attachments using `dired-mu4e-attach-ctrl-c-ctrl-c`.

### System Information

latest doom

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.