From: Eric Danan <eric.danan@u-cergy.fr>
To: mail@nicolasgoaziou.fr
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-attach: Allow attaching file from visited buffer
Date: Mon, 25 Jun 2018 15:04:11 +0200 [thread overview]
Message-ID: <CAMBH+RYziD2iT37Ac1_1_ODYDWso2JdXDD761FsKM1FU2BPVqA@mail.gmail.com> (raw)
In-Reply-To: <87y3f8cfal.fsf@nicolasgoaziou.fr>
[-- Attachment #1: Type: text/plain, Size: 3692 bytes --]
Sorry for the slow reply.
I tried something similar to your second proposal (mimicking
`org-attach-dired-to-subtree'), but more convenient in my opinion and
not losing the method choice. It mimicks the mechanism to store links:
there is a new command `org-store-attachment' (to which one could give
a global keybinding such as `C-c a`) that stores an attachment to the
current buffer in a new variable `org-stored-attachments', and
`org-attach-attach', when called interactively, prompts to select an
attachment from this variable if it is non nil (the attachment is then
removed from the variable). See attached patch (yes I've signed the
FSF papers).
"Storing an attachment" simply means storing the buffer file name or,
if there is none, the buffer name, to the variable (there may be a
better terminology for that). Then `org-attach-attach' detects if the
"file" is actually the name of a non-file-visiting buffer and uses
`write-file' rather than the specified or default method in that case.
So we keep the method choice and don't need to add a specific command
for buffers to the dispatcher. If you think it's not worth introducing
complications for allowing to attach non-file-visiting buffers, we
could simply prevent this in `org-store-attachment'. I also made it so
that if `org-store-attachment' is called from a dired buffer, then the
file at point is stored rather than the dired buffer itself.
This can certainly be improved, but I hope it is sufficient for you to
judge whether you think it is a good idea or not. Possible
improvements I thought about:
- When `org-store-attachment' is called from a dired buffer and there
are marked files, we could store these rather than the file at point
(similar to `org-attach-dired-to-subtree').
- We could add a mechanism for making `org-attach-attach'
unconditionally read a file name, ignoring `org-stored-attachments'
(i.e. a prefix argument, distinct from the one to visit the attachment
directory). We could also add a command to clear
`org-stored-attachments' from the dispatcher.
- We could check whether the file to attach is modified and prompt the
user to save it in that case (this is actually independent from the
present discussion).
I understand that other users may not like this mechanism and prefer
different solutions (or leaving things as they are). There was a
recent suggestion to make the list of commands in the attachment
dispatcher customizable:
http://lists.gnu.org/archive/html/emacs-orgmode/2018-06/msg00139.html
Do you think it would make sense to do so?
Thank you for your attention.
On Thu, Jun 21, 2018 at 5:47 PM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>
> Hello,
>
> Eric Danan <eric.danan@u-cergy.fr> writes:
>
> > When the file to attach is already open in emacs, it is generally
> > faster to select it from the buffer list than navigating to it through
> > the file system. This patch adds a `b' command to the attach
> > dispatcher that reads a buffer and writes it in the attachment
> > directory.
>
> Thank you.
>
> One issue is that we're losing the method choice (symlink, copy,
> hardlink).
>
> However, `org-attach-attach' already offers to start file system
> navigation from a Dired side buffer, if any. We may extend this idea: if
> there is a buffer currently displayed in another window, but no Dired
> buffer, offer its default directory as a start for completion.
>
> Another idea is to create a new function that will attach the current
> file to the subtree in another window. See
> `org-attach-dired-to-subtree', for example.
>
> If you haven't signed FSF papers, you need to add TINYCHANGE at the end
> of the commit message.
>
> Regards,
>
> --
> Nicolas Goaziou
[-- Attachment #2: 0001-org-attach-Add-mechanism-to-store-attachment-to-curr.patch --]
[-- Type: application/octet-stream, Size: 4509 bytes --]
From 3bafeda53c52c6b9fc3a611cbcb23bfb4594ca64 Mon Sep 17 00:00:00 2001
From: Eric Danan <eric.danan@u-cergy.fr>
Date: Thu, 21 Jun 2018 15:45:32 +0200
Subject: [PATCH] org-attach: Add mechanism to store attachment to current
buffer
* lisp/org-attach.el (org-stored-attachments): New variable.
(org-store-attachment): New autoloaded, interactive command to store
an attachment to the current buffer in the above variable.
(org-attach-attach): If called interactively and there are stored
attachments, prompt to select one of them. Also if the attachment is
to a buffer not visiting a file, fallback to writing the buffer rather
than using the specified or default attachment method.
---
lisp/org-attach.el | 47 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 39 insertions(+), 8 deletions(-)
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 192815f4..df8e458d 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -152,6 +152,9 @@ (defcustom org-attach-annex-auto-get 'ask
(const :tag "always get from annex if necessary" t)
(const :tag "never get from annex" nil)))
+(defvar org-stored-attachments nil
+ "Contains the attachments stored with `org-store-attachment'.")
+
;;;###autoload
(defun org-attach ()
"The dispatcher for attachment commands.
@@ -193,7 +196,7 @@ (defun org-attach ()
s Set a specific attachment directory for this entry or reset to default.
i Make children of the current entry inherit its attachment directory.")))
(org-fit-window-to-buffer (get-buffer-window "*Org Attach*"))
- (message "Select command: [acmlzoOfFdD]")
+ (message "Select command: [acmlyunzoOfFdD]")
(setq c (read-char-exclusive))
(and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*"))))
(cond
@@ -397,14 +400,22 @@ (defun org-attach-attach (file &optional visit-dir method)
`org-attach-method'."
(interactive
(list
- (read-file-name "File to keep as an attachment:"
- (or (progn
- (require 'dired-aux)
- (dired-dwim-target-directory))
- default-directory))
+ (if org-stored-attachments
+ (let ((file (org-completing-read "Attachment: "
+ org-stored-attachments)))
+ (setq org-stored-attachments
+ (remove file org-stored-attachments))
+ file)
+ (read-file-name "File to keep as an attachment:"
+ (or (progn
+ (require 'dired-aux)
+ (dired-dwim-target-directory))
+ default-directory)))
current-prefix-arg
nil))
- (setq method (or method org-attach-method))
+ (setq method (if (file-exists-p file)
+ (or method org-attach-method)
+ 'buf))
(let ((basename (file-name-nondirectory file)))
(when (and org-attach-file-list-property (not org-attach-inherited))
(org-entry-add-to-multivalued-property
@@ -416,12 +427,15 @@ (defun org-attach-attach (file &optional visit-dir method)
((eq method 'cp) (copy-file file fname))
((eq method 'ln) (add-name-to-file file fname))
((eq method 'lns) (make-symbolic-link file fname))
- ((eq method 'url) (url-copy-file file fname)))
+ ((eq method 'url) (url-copy-file file fname))
+ ((eq method 'buf) (with-current-buffer file
+ (write-file fname t))))
(when org-attach-commit
(org-attach-commit))
(org-attach-tag)
(cond ((eq org-attach-store-link-p 'attached)
(org-attach-store-link fname))
+ ((eq method 'buf))
((eq org-attach-store-link-p t)
(org-attach-store-link file)))
(if visit-dir
@@ -613,6 +627,23 @@ (defun org-attach-dired-to-subtree (files)
(org-attach-attach file))
(select-window start-win)))
+;;;###autoload
+(defun org-store-attachment (file)
+ "Store an attachment to the current buffer.
+\\<org-mode-map>
+This attachment is added to `org-stored-attachments' and can later be inserted
+into an Org buffer with `org-attach' (`\\[org-attach]').
+
+If the current buffer is a dired buffer, store an attachments to
+the file at point instead."
+ (interactive
+ (list (if (derived-mode-p 'dired-mode)
+ (ignore-errors (dired-get-filename))
+ (or (buffer-file-name (buffer-base-buffer))
+ (buffer-name (buffer-base-buffer))))))
+ (when file
+ (push file org-stored-attachments)))
+
\f
(add-hook 'org-archive-hook 'org-attach-archive-delete-maybe)
--
2.17.0
next prev parent reply other threads:[~2018-06-25 13:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-21 14:27 [PATCH] org-attach: Allow attaching file from visited buffer Eric Danan
2018-06-21 15:47 ` Nicolas Goaziou
2018-06-25 13:04 ` Eric Danan [this message]
2018-11-02 9:24 ` Nicolas Goaziou
2018-11-02 13:14 ` Eric Danan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMBH+RYziD2iT37Ac1_1_ODYDWso2JdXDD761FsKM1FU2BPVqA@mail.gmail.com \
--to=eric.danan@u-cergy.fr \
--cc=emacs-orgmode@gnu.org \
--cc=mail@nicolasgoaziou.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.