Bastien <b...@altern.org> writes: > If you feel like adding the attach link type to org-attach.el
Second part, which is the actual "attach link" part. -- N. -- 8> -- >From 85f5c10d8d448e56458377f166413f7de6458563 Mon Sep 17 00:00:00 2001 From: "nrichard (geodiff-mac3)" <nrich...@ulb.ac.be> Date: Thu, 27 Sep 2012 17:38:43 +0200 Subject: [PATCH 2/2] (org-attach) Add an /attach/ link type, with completion * org-attach.el (org-attach-complete-how): new variable for link completion (org-attach-complete-link): new function for link completion. --- lisp/org-attach.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lisp/org-attach.el b/lisp/org-attach.el index 4a4c195..3a1e273 100644 --- a/lisp/org-attach.el +++ b/lisp/org-attach.el @@ -132,6 +132,18 @@ lns create a symbol link. Note that this is not supported (const :tag "Link to origin location" t) (const :tag "Link to the attach-dir location" attached))) +(defcustom org-attach-complete-how 'attach + "Determine how `org-attach-complete-link' completes links to attachments. + +It can be one of the symbols : +- `file' :: a \"file:\" link is returned (the exact path inserted + depends on `org-link-file-path-type'), +- `attach' :: an \"attach:\" link is returned (default)." + :group 'org-attach + :type '(choice + (const :tag "File" file) + (const :tag "Attach (default)" attach))) + ;;;###autoload (defun org-attach () "The dispatcher for attachment commands. @@ -490,6 +502,22 @@ Basically, this adds the path to the attachment directory, and a \"file:\" prefix." (concat "file:" (org-attach-expand file))) +(defun org-attach-complete-link () + "Read a filename from the attachment directory, with completion. + +This provides link completion for the \"attach\" type. The exact +behaviour depends on the variable `org-attach-complete-how'." + (let* ((attach-dir (or (org-attach-dir nil) (error "No attachment dir"))) + (files (org-attach-file-list)) ; names relative to attach dir. + (file (org-icompleting-read "Find attachment: " files nil t))) + (cond + ((eq org-attach-complete-how 'file) (org-attach-expand-link file)) + ((eq org-attach-complete-how 'attach) (concat "attach:" file))))) + +(org-add-link-type "attach" 'org-attach-open-link) +(defun org-attach-open-link (file) + (org-open-file (org-attach-expand file))) + (provide 'org-attach) ;;; org-attach.el ends here -- 1.7.12