Fix #2429: replace defunct attach: links w/ download:

Forgot that support for attach: links were removed some time ago, but I
still want short org-download links, so I've added 'download:' links.
This commit is contained in:
Henrik Lissner 2020-01-26 02:20:39 -05:00
parent 871201dad6
commit 827225e331
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 49 additions and 40 deletions

View file

@ -64,30 +64,30 @@
* General * General
** Why is it called Doom? ** Why is it called Doom?
An homage to idsoftware's classic game, whose open sourced code was my first It's an homage to idsoftware's classic game, whose open sourced code was
exposure to programming. Henrik's (Doom's maintainer) first exposure to programming.
Also, if you're obsessed enough with a text editor that you write a community And if you're obsessed enough with a text editor that you write a community
config for it, you're doomed from the get go. config for it, you're doomed from the start.
** Does Doom work on Windows? ** Does Doom work on Windows?
Windows support is weak and will generally lag behind Linux/MacOS support, so Windows support is weak and generally lags behind Linux/MacOS support, so your
your mileage will vary. However, many have reported success installing Doom mileage will vary. However, some have reported success using Doom Emacs on
Emacs on Windows (using WSL, WSL2 or scoop/chocolatey). You'll find install Windows (using WSL, WSL2 or scoop/chocolatey). You'll find install instructions
instructions for Windows in the [[file:getting_started.org::On Windows][Getting Starting guide]]. in the [[file:getting_started.org::On Windows][Getting Starting guide]].
If you're a Windows user, help us improve our documentation on Windows support! If you're a Windows user, help us improve our documentation!
** Is Doom only for vimmers? ** Is Doom only for vimmers?
Henrik is a dyed-in-the-wool vimmer with more than a decade of vim muscle No, but it is Doom's primary audience. Its maintainer is a dyed-in-the-wool
memory. Vim's is the only paradigm he truly knows, so vimmers will always be his vimmer with almost two decades of vim muscle memory, and he came to Emacs to
primary audience. find a better vim.
That's not to say Doom won't work without evil, only that it is less polished in Although Doom is less polished without evil, its growing non-evil user base is
that respect. Our growing non-evil userbase are slowly improving the situation slowly improving the situation. We welcome suggestions and PRs to help
however. We welcome suggestions and PRs to help accommodate a non-evil workflow. accommodate a non-evil workflow.
If you'd still like a go at it, see the [[file:../modules/editor/evil/README.org::Removing%20evil-mode][Removing evil-mode]] section in the If you'd still like a go at it, see the [[file:../modules/editor/evil/README.org::Removing%20evil-mode][removing evil-mode]] section in the
[[file:../modules/editor/evil/README.org][:editor evil]] module's documentation. [[file:../modules/editor/evil/README.org][:editor evil]] module's documentation.
** I am a beginner. Can I use Doom? ** I am a beginner. Can I use Doom?

View file

@ -1,5 +1,21 @@
;;; lang/org/autoload/org-link.el -*- lexical-binding: t; -*- ;;; lang/org/autoload/org-link.el -*- lexical-binding: t; -*-
(defun +org--relpath (path root)
(if (and buffer-file-name (file-in-directory-p buffer-file-name root))
(file-relative-name path)
path))
;;;###autoload
(defun +org-def-link (key dir)
(org-link-set-parameters
key
:complete (lambda () (+org--relpath (+org-link-read-file key dir) dir))
:follow (lambda (link) (find-file (expand-file-name link dir)))
:face (lambda (link)
(if (file-exists-p (expand-file-name link dir))
'org-link
'error))))
;;;###autoload ;;;###autoload
(defun +org-link-read-file (key dir) (defun +org-link-read-file (key dir)
(let ((file (read-file-name (format "%s: " (capitalize key)) dir))) (let ((file (read-file-name (format "%s: " (capitalize key)) dir)))

View file

@ -387,21 +387,6 @@ file isn't in `org-directory'."
(defun +org-init-custom-links-h () (defun +org-init-custom-links-h ()
(defun +org--relpath (path root)
(if (and buffer-file-name (file-in-directory-p buffer-file-name root))
(file-relative-name path)
path))
(defun +org-def-link (key dir)
(org-link-set-parameters
key
:complete (lambda () (+org--relpath (+org-link-read-file key dir) dir))
:follow (lambda (link) (find-file (expand-file-name link dir)))
:face (lambda (link)
(if (file-exists-p (expand-file-name link dir))
'org-link
'error))))
;; Highlight broken file links ;; Highlight broken file links
(org-link-set-parameters (org-link-set-parameters
"file" "file"

View file

@ -11,6 +11,7 @@
(advice-add #'org-download-enable :override #'ignore) (advice-add #'org-download-enable :override #'ignore)
:config :config
(setq org-download-image-dir org-attach-id-dir (setq org-download-image-dir org-attach-id-dir
org-download-link-format "[[download:%s]]\n"
org-download-method 'attach org-download-method 'attach
org-download-heading-lvl nil org-download-heading-lvl nil
org-download-timestamp "_%Y%m%d_%H%M%S" org-download-timestamp "_%Y%m%d_%H%M%S"
@ -20,6 +21,11 @@
(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")))))
;; A shorter link to attachments
(+org-def-link "download" org-attach-id-dir)
(setf (alist-get "download" org-link-abbrev-alist nil nil #'equal)
(abbreviate-file-name org-attach-id-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.
@ -34,15 +40,17 @@ an file icon produced by `+org-attach-icon-for')."
(newline)) (newline))
(cond ((image-type-from-file-name filename) (cond ((image-type-from-file-name filename)
(insert (insert
(concat (if (= org-download-image-html-width 0) "" (concat
(format "#+attr_html: :width %dpx\n" org-download-image-html-width)) (if (= org-download-image-html-width 0) ""
(if (= org-download-image-latex-width 0) "" (format "#+attr_html: :width %dpx\n" org-download-image-html-width))
(format "#+attr_latex: :width %dcm\n" org-download-image-latex-width)) (if (= org-download-image-latex-width 0) ""
(cond ((file-in-directory-p filename org-attach-directory) (format "#+attr_latex: :width %dcm\n" org-download-image-latex-width))
(format "[[attach:%s]]" (file-relative-name filename org-attach-directory))) (format org-download-link-format
((file-in-directory-p filename org-directory) (cond ((file-in-directory-p filename org-attach-directory)
(format org-download-link-format (file-relative-name filename org-directory))) (file-relative-name filename org-download-image-dir))
((format org-download-link-format filename))))) ((file-in-directory-p filename org-directory)
(file-relative-name filename org-directory))
(filename)))))
(org-display-inline-images)) (org-display-inline-images))
((insert ((insert
(format "%s [[./%s][%s]] " (format "%s [[./%s][%s]] "