From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Nicolas Richard" Subject: Re: An org-attach link type [7.9.1 (7.9.1-elpa @ /home/youngfrog/.emacs.d/elpa/org-20120903/)] Date: Thu, 27 Sep 2012 18:27:15 +0200 Message-ID: <87626za0t8.fsf@yahoo.fr> References: <5059DC5B.3080203@yahoo.fr> <87sjaawh1a.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:47586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THGyS-0003Cd-TT for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 12:30:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THGyP-00022w-2c for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 12:30:02 -0400 Received: from plane.gmane.org ([80.91.229.3]:41092) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THGyO-00022l-RI for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 12:30:00 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1THGyR-0003og-Qp for emacs-orgmode@gnu.org; Thu, 27 Sep 2012 18:30:03 +0200 Received: from geodiff-mac3.ulb.ac.be ([164.15.131.113]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 27 Sep 2012 18:30:03 +0200 Received: from theonewiththeevillook by geodiff-mac3.ulb.ac.be with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 27 Sep 2012 18:30:03 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Bastien 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)" 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