emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-attach: Allow attaching file from visited buffer
@ 2018-06-21 14:27 Eric Danan
  2018-06-21 15:47 ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Danan @ 2018-06-21 14:27 UTC (permalink / raw)
  To: emacs-orgmode

[-- 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-11-02 13:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2018-11-02  9:24     ` Nicolas Goaziou
2018-11-02 13:14       ` Eric Danan

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).