summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustav Wikström <gustav@whil.se>2020-02-06 22:01:08 +0100
committerGustav Wikström <gustav@whil.se>2020-02-06 22:09:18 +0100
commita24c8c481f63113215e66a70382d93cce82c9c7e (patch)
treece715b9613c96391c69ac6840a83e665550a179b
parent7d74b5b7697908017e71dc91c8e8bcd6cb010493 (diff)
downloadorg-mode-a24c8c481f63113215e66a70382d93cce82c9c7e.tar.gz
Refactor attachment path expansion
* lisp/org-attach.el (org-attach-link-expand): New function for link element expansion. * lisp/org-element.el (org-element-link-parser): Remove info about expanded attachment paths from link elements. * lisp/ol.el (org-link-open) * lisp/ox-texinfo.el (org-texinfo-link) * lisp/ox-odt.el (org-odt-link) * lisp/ox-md.el (org-md-link) * lisp/ox-man.el (org-man-link) * lisp/ox-latex.el (org-latex--inline-image, org-latex-link) * lisp/ox-html.el (org-html-link) * lisp/ox-ascii.el (org-ascii-link): Refactor to use new link expansion function from org-attach.el instead of (now removed) custom link property from org-element.el.
-rw-r--r--lisp/ol.el3
-rw-r--r--lisp/org-attach.el16
-rw-r--r--lisp/org-element.el39
-rw-r--r--lisp/ox-ascii.el3
-rw-r--r--lisp/ox-html.el3
-rw-r--r--lisp/ox-latex.el6
-rw-r--r--lisp/ox-man.el4
-rw-r--r--lisp/ox-md.el4
-rw-r--r--lisp/ox-odt.el4
-rw-r--r--lisp/ox-texinfo.el4
10 files changed, 51 insertions, 35 deletions
diff --git a/lisp/ol.el b/lisp/ol.el
index 31c34ec..10ce83f 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -75,6 +75,7 @@
(declare-function org-src-source-type "org-src" ())
(declare-function org-time-stamp-format "org" (&optional long inactive))
(declare-function outline-next-heading "outline" ())
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
;;; Customization
@@ -934,7 +935,7 @@ a \"file\" link."
(cond
((member type '("file" "attachment"))
(when (string= type "attachment")
- (setq path (org-element-property :attachment-path link)))
+ (setq path (org-attach-link-expand link)))
(if (string-match "[*?{]" (file-name-nondirectory path))
(dired path)
;; Look into `org-link-parameters' in order to find
diff --git a/lisp/org-attach.el b/lisp/org-attach.el
index c2aa5c3..0fac627 100644
--- a/lisp/org-attach.el
+++ b/lisp/org-attach.el
@@ -40,6 +40,7 @@
(require 'org-id)
(declare-function dired-dwim-target-directory "dired-aux")
+(declare-function org-element-property "org-element" (property element))
(defgroup org-attach nil
"Options concerning attachments in Org mode."
@@ -650,6 +651,21 @@ See `org-attach-open'."
Basically, this adds the path to the attachment directory."
(expand-file-name file (org-attach-dir)))
+(defun org-attach-link-expand (link &optional buffer-or-name)
+ "Return the full path to the attachment in the LINK element.
+Takes LINK which is a link element, as defined by
+`org-element-link-parser'. If LINK `:type' is attachment the
+full path to the attachment is expanded and returned. Otherwise,
+return nil. If BUFFER-OR-NAME is specified, LINK is expanded in
+that buffer, otherwise current buffer is assumed."
+ (let ((type (org-element-property :type link))
+ (file (org-element-property :path link))
+ (pos (org-element-property :begin link)))
+ (when (string= type "attachment")
+ (with-current-buffer (or buffer-or-name (current-buffer))
+ (goto-char pos)
+ (org-attach-expand file)))))
+
(org-link-set-parameters "attachment"
:complete #'org-attach-complete-link)
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 4fde27e..5c46f37 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -3116,11 +3116,7 @@ When at a link, return a list whose car is `link' and cdr a plist
with `:type', `:path', `:format', `:raw-link', `:application',
`:search-option', `:begin', `:end', `:contents-begin',
`:contents-end' and `:post-blank' as keywords. Otherwise, return
-nil. Additionally, in the context of attachment links one
-further property, `:attachment-path' is set. That property
-contains the attachment link expanded into a full filesystem
-path.
-
+nil.
Assume point is at the beginning of the link."
(catch 'no-object
@@ -3229,27 +3225,18 @@ Assume point is at the beginning of the link."
(when trans
(setq type (car trans))
(setq path (cdr trans))))
- (let ((link
- (list 'link
- (list :type type
- :path path
- :format format
- :raw-link (or raw-link path)
- :application application
- :search-option search-option
- :begin begin
- :end end
- :contents-begin contents-begin
- :contents-end contents-end
- :post-blank post-blank))))
- ;; Add additional type specific properties for link types that
- ;; need it
- (when (string= type "attachment")
- (org-element-put-property
- link :attachment-path
- (file-relative-name
- (org-attach-expand path))))
- link))))
+ (list 'link
+ (list :type type
+ :path path
+ :format format
+ :raw-link (or raw-link path)
+ :application application
+ :search-option search-option
+ :begin begin
+ :end end
+ :contents-begin contents-begin
+ :contents-end contents-end
+ :post-blank post-blank)))))
(defun org-element-link-interpreter (link contents)
"Interpret LINK object as Org syntax.
diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el
index 019c26c..4ffb44a 100644
--- a/lisp/ox-ascii.el
+++ b/lisp/ox-ascii.el
@@ -34,6 +34,7 @@
;;; Function Declarations
(declare-function aa2u "ext:ascii-art-to-unicode" ())
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
;;; Define Back-End
;;
@@ -1573,7 +1574,7 @@ INFO is a plist holding contextual information."
(raw-path (org-element-property :path link))
(path (cond
((string= type "attachment")
- (setq raw-path (org-element-property :attachment-path link))
+ (setq raw-path (org-attach-link-expand link))
(concat type ":" raw-path))
(t (concat type ":" raw-path)))))
(cond
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 39ccae3..fa30bde 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -42,6 +42,7 @@
(declare-function org-id-find-id-file "org-id" (id))
(declare-function htmlize-region "ext:htmlize" (beg end))
(declare-function mm-url-decode-entities "mm-url" ())
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
(defvar htmlize-css-name-prefix)
(defvar htmlize-output-type)
@@ -3074,7 +3075,7 @@ INFO is a plist holding contextual information. See
(url-encode-url (concat type ":" raw-path)))
((member type '("file" "attachment"))
(when (string= type "attachment")
- (setq raw-path (org-element-property :attachment-path link)))
+ (setq raw-path (org-attach-link-expand link)))
;; During publishing, turn absolute file names belonging
;; to base directory into relative file names. Otherwise,
;; append "file" protocol to absolute file name.
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index b307ff4..1bc15a8 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -32,6 +32,8 @@
;;; Function Declarations
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
+
(defvar org-latex-default-packages-alist)
(defvar org-latex-packages-alist)
(defvar orgtbl-exp-regexp)
@@ -2360,7 +2362,7 @@ LINK is the link pointing to the inline image. INFO is a plist
used as a communication channel."
(let* ((parent (org-export-get-parent-element link))
(path (let ((raw-path (if (string= (org-element-property :type link) "attachment")
- (org-element-property :attachment-path link)
+ (org-attach-link-expand link)
(org-element-property :path link))))
(if (not (file-name-absolute-p raw-path)) raw-path
(expand-file-name raw-path))))
@@ -2528,7 +2530,7 @@ INFO is a plist holding contextual information. See
(concat type ":" raw-path))
((member type '("file" "attachment"))
(when (string= type "attachment")
- (setq raw-path (org-element-property :attachment-path link)))
+ (setq raw-path (org-attach-link-expand link)))
(org-export-file-uri raw-path))
(t
raw-path)))))
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index 5de4c5e..b6925c6 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -42,6 +42,8 @@
;;; Function Declarations
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
+
(defvar org-export-man-default-packages-alist)
(defvar org-export-man-packages-alist)
(defvar orgtbl-exp-regexp)
@@ -616,7 +618,7 @@ INFO is a plist holding contextual information. See
(concat type ":" raw-path))
((member type '("file" "attachment"))
(when (string= type "attachment")
- (setq raw-path (org-element-property :attachment-path link)))
+ (setq raw-path (org-attach-link-expand link)))
(org-export-file-uri raw-path))
(t raw-path))))
(cond
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 61b31f9..7515df3 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -35,6 +35,8 @@
;;; Function Declarations
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
+
;;; User-Configurable Variables
(defgroup org-export-md nil
@@ -405,7 +407,7 @@ INFO is a plist holding contextual information. See
(concat type ":" raw-path))
((member type '("file" "attachment"))
(when (string= type "attachment")
- (setq raw-path (org-element-property :attachment-path link)))
+ (setq raw-path (org-attach-link-expand link)))
(org-export-file-uri (funcall link-org-files-as-md raw-path)))
(t raw-path))))
(cond
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 140323c..49e37cc 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -34,6 +34,8 @@
;;; Function Declarations
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
+
;;; Define Back-End
(org-export-define-backend 'odt
@@ -2706,7 +2708,7 @@ INFO is a plist holding contextual information. See
(concat type ":" raw-path))
((member type '("file" "attachment"))
(when (string= type "attachment")
- (setq raw-path (org-element-property :attachment-path link)))
+ (setq raw-path (org-attach-link-expand link)))
(org-export-file-uri raw-path))
(t raw-path)))
;; Convert & to &amp; for correct XML representation
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index 22ea86e..89c6746 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -30,6 +30,8 @@
;;; Function Declarations
+(declare-function org-attach-link-expand "org-attach" (link &optional buffer-or-name))
+
(defvar orgtbl-exp-regexp)
@@ -1058,7 +1060,7 @@ INFO is a plist holding contextual information. See
(concat type ":" raw-path))
((member type '("file" "attachment"))
(when (string= type "attachment")
- (setq raw-path (org-element-property :attachment-path link)))
+ (setq raw-path (org-attach-link-expand link)))
(org-export-file-uri raw-path))
(t raw-path))))
(cond