emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Nicolas Richard" <theonewiththeevillook@yahoo.fr>
To: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <87626za0t8.fsf@yahoo.fr> (raw)
In-Reply-To: 87sjaawh1a.fsf@bzg.ath.cx

Bastien <bzg@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)" <nrichard@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

      parent reply	other threads:[~2012-09-27 16:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-19 14:53 An org-attach link type [7.9.1 (7.9.1-elpa @ /home/youngfrog/.emacs.d/elpa/org-20120903/)] Nicolas Richard
2012-09-22  7:14 ` Viktor Rosenfeld
2012-09-22  8:58   ` Nicolas Richard
2012-09-22 17:52     ` Viktor Rosenfeld
2012-09-22  9:20 ` Bastien
2012-09-27 16:25   ` Nicolas Richard
2012-09-28  6:43     ` Bastien
2012-09-27 16:27   ` Nicolas Richard [this message]

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87626za0t8.fsf@yahoo.fr \
    --to=theonewiththeevillook@yahoo.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 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).