Просмотр исходного кода

Introduce function to create links to attachments.

This patch introduces two new functions in org-attach.el,
`org-attach-expand', and `org-attach-expand-link'.  Both take a file
name as an argument, assume that this file is an attachment of the
current entry, and return the full path to this file or a
"file:..." link to it, respectively.

With these functions, it becomes very easy to use link abbreviations
to create a new link type to attachments:

After

(setq org-link-abbrev-alist '(("att" . org-attach-expand-link)))

links like [[att:file.txt]] will work.
Carsten Dominik 16 лет назад
Родитель
Сommit
413264882c
3 измененных файлов с 23 добавлено и 1 удалено
  1. 5 0
      lisp/ChangeLog
  2. 11 0
      lisp/org-attach.el
  3. 7 1
      lisp/org.el

+ 5 - 0
lisp/ChangeLog

@@ -1,5 +1,10 @@
 2008-11-05  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org.el (org-link-abbrev-alist): Improve customization type.
+
+	* org-attach.el (org-attach-expand-link, org-attach-expand): New
+	functions.
+
 	* org-agenda.el (org-agenda-get-progress): Renamed from
 	`org-get-closed'.  Implement searching for state changes as well.
 	(org-agenda-log-mode-items): New option.

+ 11 - 0
lisp/org-attach.el

@@ -334,6 +334,17 @@ See `org-attach-open'."
   (interactive)
   (org-attach-open 'in-emacs))
 
+(defun org-attach-expand (file)
+  "Return the full path to the current entry's attachment file FILE.
+Basically, this adds the path to the attachment directory."
+  (expand-file-name file (org-attach-dir)))
+
+(defun org-attach-expand-link (file)
+  "Return a file link pointing to the current entry's attachment file FILE.
+Basically, this adds the path to the attachment directory, and a \"file:\"
+prefix."
+  (concat "file:" (org-attach-expand file)))
+
 (provide 'org-attach)
 
 ;; arch-tag: fce93c2e-fe07-4fa3-a905-e10dcc7a6248

+ 7 - 1
lisp/org.el

@@ -849,7 +849,12 @@ only argument to create the link, which should be returned as a string.
 
 See the manual for examples."
   :group 'org-link
-  :type 'alist)
+  :type '(repeat
+	  (cons
+	   (string :tag "Protocol")
+	   (choice
+	    (string :tag "Format")
+	    (function)))))
 
 (defcustom org-descriptive-links t
   "Non-nil means, hide link part and only show description of bracket links.
@@ -5957,6 +5962,7 @@ Possible values in the list of contexts are `table', `headline', and `item'."
 
 (defun org-link-expand-abbrev (link)
   "Apply replacements as defined in `org-link-abbrev-alist."
+  (debug)
   (if (string-match "^\\([a-zA-Z][-_a-zA-Z0-9]*\\)\\(::?\\(.*\\)\\)?$" link)
       (let* ((key (match-string 1 link))
 	     (as (or (assoc key org-link-abbrev-alist-local)