lang/org: use link abbrev for relative image attachment paths
This commit is contained in:
parent
0d04afa63a
commit
39f519cdb8
2 changed files with 14 additions and 24 deletions
|
@ -42,9 +42,6 @@
|
||||||
(cond ((executable-find "maim") "maim -s %s")
|
(cond ((executable-find "maim") "maim -s %s")
|
||||||
((executable-find "scrot") "scrot -s %s")))))
|
((executable-find "scrot") "scrot -s %s")))))
|
||||||
|
|
||||||
;; Ensure that relative inline image paths are relative to the attachment folder.
|
|
||||||
(advice-add #'org-display-inline-images :around #'+org-attach*relative-to-attach-dir)
|
|
||||||
|
|
||||||
;; Handle non-image files a little differently. Images should be inserted
|
;; Handle non-image files a little differently. Images should be inserted
|
||||||
;; as-is, as image previews. Other files, like pdfs or zips, should be linked
|
;; as-is, as image previews. Other files, like pdfs or zips, should be linked
|
||||||
;; to, with an icon indicating the type of file.
|
;; to, with an icon indicating the type of file.
|
||||||
|
@ -64,6 +61,8 @@
|
||||||
;;
|
;;
|
||||||
(defun +org|init-attach ()
|
(defun +org|init-attach ()
|
||||||
(setq org-attach-directory (expand-file-name +org-attach-dir +org-dir))
|
(setq org-attach-directory (expand-file-name +org-attach-dir +org-dir))
|
||||||
|
;; A shorter link to attachments
|
||||||
|
(push (cons "attach" (abbreviate-file-name org-attach-directory)) org-link-abbrev-alist)
|
||||||
|
|
||||||
(push (car (last (split-string +org-attach-dir "/" t)))
|
(push (car (last (split-string +org-attach-dir "/" t)))
|
||||||
projectile-globally-ignored-directories)
|
projectile-globally-ignored-directories)
|
||||||
|
|
|
@ -93,22 +93,25 @@ the cursor."
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +org-attach*insert-link (_link filename)
|
(defun +org-attach*insert-link (_link filename)
|
||||||
"TODO"
|
"Produces and inserts a link to FILENAME into the document.
|
||||||
|
|
||||||
|
If FILENAME is an image, produce an attach:%s path, otherwise use file:%s (with
|
||||||
|
an file icon produced by `+org-attach--icon')."
|
||||||
(if (looking-back "^[ \t]+" (line-beginning-position))
|
(if (looking-back "^[ \t]+" (line-beginning-position))
|
||||||
(delete-region (match-beginning 0) (match-end 0))
|
(delete-region (match-beginning 0) (match-end 0))
|
||||||
(newline))
|
(newline))
|
||||||
(cond ((image-type-from-file-name filename)
|
(cond ((image-type-from-file-name filename)
|
||||||
(when (file-in-directory-p filename org-attach-directory)
|
|
||||||
(setq filename (file-relative-name filename +org-dir)))
|
|
||||||
(insert
|
(insert
|
||||||
(concat (if (= org-download-image-html-width 0)
|
(concat (if (= org-download-image-html-width 0) ""
|
||||||
""
|
|
||||||
(format "#+attr_html: :width %dpx\n" org-download-image-html-width))
|
(format "#+attr_html: :width %dpx\n" org-download-image-html-width))
|
||||||
(if (= org-download-image-latex-width 0)
|
(if (= org-download-image-latex-width 0) ""
|
||||||
""
|
|
||||||
(format "#+attr_latex: :width %dcm\n" org-download-image-latex-width))
|
(format "#+attr_latex: :width %dcm\n" org-download-image-latex-width))
|
||||||
(format org-download-link-format
|
(cond ((file-in-directory-p filename org-attach-directory)
|
||||||
(file-relative-name filename (file-name-directory buffer-file-name)))))
|
(format "[[attach:%s]]" (file-relative-name filename org-attach-directory)))
|
||||||
|
((file-in-directory-p filename +org-dir)
|
||||||
|
(format org-download-link-format (file-relative-name filename +org-dir)))
|
||||||
|
(t
|
||||||
|
(format org-download-link-format filename)))))
|
||||||
(org-display-inline-images))
|
(org-display-inline-images))
|
||||||
(t
|
(t
|
||||||
(insert
|
(insert
|
||||||
|
@ -117,15 +120,3 @@ the cursor."
|
||||||
(file-relative-name filename (file-name-directory buffer-file-name))
|
(file-relative-name filename (file-name-directory buffer-file-name))
|
||||||
(file-name-nondirectory (directory-file-name filename)))))))
|
(file-name-nondirectory (directory-file-name filename)))))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +org-attach*relative-to-attach-dir (orig-fn &rest args)
|
|
||||||
"TODO"
|
|
||||||
(if (file-in-directory-p buffer-file-name +org-dir)
|
|
||||||
(let* ((context (save-match-data (org-element-context)))
|
|
||||||
(file (org-link-unescape (org-element-property :path context)))
|
|
||||||
(default-directory
|
|
||||||
(if (file-in-directory-p file org-attach-directory)
|
|
||||||
+org-dir
|
|
||||||
default-directory)))
|
|
||||||
(apply orig-fn args))
|
|
||||||
(apply orig-fn args)))
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue