From: Eric Danan <eric.danan@u-cergy.fr>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org-attach: Allow attaching file from visited buffer
Date: Thu, 21 Jun 2018 16:27:12 +0200 [thread overview]
Message-ID: <CAMBH+RZ7KkA0ws_uC5csMMmjXEH47a+nSjOs4JbALNm1E0a2vw@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 296 bytes --]
Hello,
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.
Regards,
Eric
[-- Attachment #2: 0001-org-attach-Allow-attaching-file-from-visited-buffer.patch --]
[-- Type: application/octet-stream, Size: 3492 bytes --]
From 5985548736b3907a9d2d6fdd70bd9a7c2607ef4b 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: Allow attaching file from visited buffer
* lisp/org-attach.el (org-attach-attach): Add a new method `'buf' to
write attachment file from a buffer.
(org-attach-buffer): New function calling `org-attach-attach' to
create attachment from buffer.
(org-attach): Allow attaching from buffer by selecting `b' from the
dispatcher (in passing, add missing `y', `u', and `n' in the
dispatcher message).
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. Also, this allows attaching buffers that are not
visiting a file.
---
lisp/org-attach.el | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index 192815f4..0e52526f 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -177,6 +177,7 @@ (defun org-attach ()
a Select a file and attach it to the task, using `org-attach-method'.
c/m/l/y Attach a file using copy/move/link/symbolic-link method.
u Attach a file from URL (downloading it).
+b Attach a file fron a currently visited buffer.
n Create a new attachment, as an Emacs buffer.
z Synchronize the current task with its attachment
directory, in case you added attachments yourself.
@@ -193,7 +194,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: [acmlyubnzoOfFdD]")
(setq c (read-char-exclusive))
(and (get-buffer "*Org Attach*") (kill-buffer "*Org Attach*"))))
(cond
@@ -208,6 +209,8 @@ (defun org-attach ()
(let ((org-attach-method 'lns)) (call-interactively 'org-attach-attach)))
((memq c '(?u ?\C-u))
(let ((org-attach-method 'url)) (call-interactively 'org-attach-url)))
+ ((memq c '(?b ?\C-b))
+ (let ((org-attach-method 'buf)) (call-interactively 'org-attach-buffer)))
((memq c '(?n ?\C-n)) (call-interactively 'org-attach-new))
((memq c '(?z ?\C-z)) (call-interactively 'org-attach-sync))
((memq c '(?o ?\C-o)) (call-interactively 'org-attach-open))
@@ -390,6 +393,10 @@ (defun org-attach-url (url)
(interactive "MURL of the file to attach: \n")
(org-attach-attach url))
+(defun org-attach-buffer (buffer)
+ (interactive "bBuffer to keep as an attachment:")
+ (org-attach-attach buffer))
+
(defun org-attach-attach (file &optional visit-dir method)
"Move/copy/link FILE into the attachment directory of the current task.
If VISIT-DIR is non-nil, visit the directory with dired.
@@ -416,7 +423,9 @@ (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)
--
2.17.0
next reply other threads:[~2018-06-21 14:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-21 14:27 Eric Danan [this message]
2018-06-21 15:47 ` [PATCH] org-attach: Allow attaching file from visited buffer Nicolas Goaziou
2018-06-25 13:04 ` Eric Danan
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+RZ7KkA0ws_uC5csMMmjXEH47a+nSjOs4JbALNm1E0a2vw@mail.gmail.com \
--to=eric.danan@u-cergy.fr \
--cc=emacs-orgmode@gnu.org \
/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.