refactor(org): move doom-docs link defs to :lang org
Where they will be further generalized, later. This also prevents an issue where org was loaded while the profile init files are generated, which caused a warning about org-loaddefs which introduces a noticable delay.
This commit is contained in:
parent
511f0ca38f
commit
ab9896c526
3 changed files with 198 additions and 235 deletions
|
@ -182,14 +182,6 @@ Is relative to `org-directory', unless it is absolute. Is used in Doom's default
|
|||
("NO" . +org-todo-cancel)
|
||||
("KILL" . +org-todo-cancel)))
|
||||
|
||||
(defadvice! +org-display-link-in-eldoc-a (&rest _)
|
||||
"Display full link in minibuffer when cursor/mouse is over it."
|
||||
:before-until #'org-eldoc-documentation-function
|
||||
(when-let* ((context (org-element-context))
|
||||
(path (org-element-property :path context)))
|
||||
(pcase (org-element-property :type context)
|
||||
(type (format "Link: %s" (org-element-property :raw-link context))))))
|
||||
|
||||
;; Automatic indent detection in org files is meaningless
|
||||
(add-to-list 'doom-detect-indentation-excluded-modes 'org-mode)
|
||||
|
||||
|
@ -510,15 +502,13 @@ relative to `org-directory', unless it is an absolute path."
|
|||
(defun +org-init-custom-links-h ()
|
||||
;; Modify default file: links to colorize broken file links red
|
||||
(org-link-set-parameters
|
||||
"file"
|
||||
:face (lambda (path)
|
||||
(if (or (file-remote-p path)
|
||||
;; filter out network shares on windows (slow)
|
||||
(and IS-WINDOWS
|
||||
(string-prefix-p "\\\\" path))
|
||||
(file-exists-p path))
|
||||
'org-link
|
||||
'(warning org-link))))
|
||||
"file" :face (lambda (path)
|
||||
(if (or (file-remote-p path)
|
||||
;; filter out network shares on windows (slow)
|
||||
(if IS-WINDOWS (string-prefix-p "\\\\" path))
|
||||
(file-exists-p path))
|
||||
'org-link
|
||||
'(warning org-link))))
|
||||
|
||||
;; Additional custom links for convenience
|
||||
(pushnew! org-link-abbrev-alist
|
||||
|
@ -530,7 +520,7 @@ relative to `org-directory', unless it is an absolute path."
|
|||
'("duckduckgo" . "https://duckduckgo.com/?q=%s")
|
||||
'("wikipedia" . "https://en.wikipedia.org/wiki/%s")
|
||||
'("wolfram" . "https://wolframalpha.com/input/?i=%s")
|
||||
'("doom" . "https://github.com/hlissner/doom-emacs/%s")
|
||||
'("doom-repo" . "https://github.com/doomemacs/doomemacs/%s")
|
||||
`("emacsdir" . ,(doom-path doom-emacs-dir "%s"))
|
||||
`("doomdir" . ,(doom-path doom-user-dir "%s")))
|
||||
|
||||
|
@ -539,6 +529,112 @@ relative to `org-directory', unless it is an absolute path."
|
|||
(+org-define-basic-link "doom-docs" 'doom-docs-dir)
|
||||
(+org-define-basic-link "doom-modules" 'doom-modules-dir)
|
||||
|
||||
(defadvice! +org-display-link-in-eldoc-a (&rest _)
|
||||
"Display full link in minibuffer when cursor/mouse is over it."
|
||||
:before-until #'org-eldoc-documentation-function
|
||||
(when-let (context (org-element-context))
|
||||
(if-let ((type (org-element-property :type context))
|
||||
(eldocfn (org-link-get-parameter type :eldoc)))
|
||||
(funcall eldocfn context)
|
||||
(format "Link: %s" (org-element-property :raw-link context)))))
|
||||
|
||||
;; Add "lookup" links for packages and keystrings; useful for Emacs
|
||||
;; documentation -- especially Doom's!
|
||||
(letf! ((defun -call-interactively (fn)
|
||||
(lambda (link)
|
||||
(let ((desc (+org-link-read-desc-at-point link)))
|
||||
(funcall
|
||||
fn (or (intern-soft desc)
|
||||
(user-error "Can't find documentation for %S" desc))))))
|
||||
(defun -eldoc-fn (label face)
|
||||
(lambda (context)
|
||||
(format "%s %s"
|
||||
(propertize (format "%s:" label) 'face 'bold)
|
||||
(propertize (+org-link-read-desc-at-point
|
||||
(org-element-property :path context) context)
|
||||
'face face)))))
|
||||
(org-link-set-parameters
|
||||
"kbd"
|
||||
:follow (lambda (_) (minibuffer-message "%s" (+org-display-link-in-eldoc-a)))
|
||||
:help-echo #'+org-link-read-kbd-at-point
|
||||
:face 'help-key-binding
|
||||
:eldoc (-eldoc-fn "Key sequence" 'help-key-binding))
|
||||
(org-link-set-parameters
|
||||
"var"
|
||||
:follow (-call-interactively #'helpful-variable)
|
||||
:face '(font-lock-variable-name-face underline))
|
||||
(org-link-set-parameters
|
||||
"fn"
|
||||
:follow (-call-interactively #'helpful-callable)
|
||||
:face '(font-lock-function-name-face underline))
|
||||
(org-link-set-parameters
|
||||
"face"
|
||||
:follow (-call-interactively #'describe-face)
|
||||
:face '(font-lock-type-face underline))
|
||||
(org-link-set-parameters
|
||||
"doom-package"
|
||||
:follow #'+org-link-follow-doom-package-fn
|
||||
:face (lambda (_) '(:inherit org-priority :slant italic))
|
||||
:eldoc (-eldoc-fn "Doom package" 'org-priority))
|
||||
(org-link-set-parameters
|
||||
"doom-module"
|
||||
:follow #'+org-link-follow-doom-module-fn
|
||||
:face #'+org-link--doom-module-link-face-fn
|
||||
:eldoc (-eldoc-fn "Doom module" 'org-priority))
|
||||
(org-link-set-parameters
|
||||
"doom-ref"
|
||||
:follow (lambda (link)
|
||||
(let ((link (+org-link-read-desc-at-point link))
|
||||
(url "https://github.com")
|
||||
(doom-repo "doomemacs/doomemacs"))
|
||||
(save-match-data
|
||||
(browse-url
|
||||
(cond ((string-match "^\\([^/]+\\(?:/[^/]+\\)?\\)?#\\([0-9]+\\(?:#.*\\)?\\)" link)
|
||||
(format "%s/%s/issues/%s" url
|
||||
(or (match-string 1 link)
|
||||
doom-repo)
|
||||
(match-string 2 link)))
|
||||
((string-match "^\\([^/]+\\(?:/[^/]+\\)?@\\)?\\([a-z0-9]\\{7,\\}\\(?:#.*\\)?\\)" link)
|
||||
(format "%s/%s/commit/%s" url
|
||||
(or (match-string 1 link)
|
||||
doom-repo)
|
||||
(match-string 2 link)))
|
||||
((user-error "Invalid doom-ref link: %S" link)))))))
|
||||
:face (lambda (link)
|
||||
(let ((link (+org-link-read-desc-at-point link)))
|
||||
(if (or (string-match "^\\([^/]+\\(?:/[^/]+\\)?\\)?#\\([0-9]+\\(?:#.*\\)?\\)" link)
|
||||
(string-match "^\\([^/]+\\(?:/[^/]+\\)?@\\)?\\([a-z0-9]\\{7,\\}\\(?:#.*\\)?\\)" link))
|
||||
'org-link
|
||||
'error))))
|
||||
(org-link-set-parameters
|
||||
"doom-user"
|
||||
:follow (lambda (link)
|
||||
(browse-url
|
||||
(format "https://github.com/%s"
|
||||
(string-remove-prefix
|
||||
"@" (+org-link-read-desc-at-point link)))))
|
||||
:face (lambda (_) 'org-priority))
|
||||
(org-link-set-parameters
|
||||
"doom-source"
|
||||
:follow (lambda (link)
|
||||
(user-error "-- %S %S %S" source url link)
|
||||
(cl-destructuring-bind (source . url)
|
||||
(save-match-data
|
||||
(and (string-match "^\\([^:]+\\):\\(.+\\)$" link)
|
||||
(cons (match-string 1) (match-string 2))))
|
||||
(pcase source
|
||||
("doom"
|
||||
(org-link-open (expand-file-name url doom-modules-dir)))
|
||||
("contrib"
|
||||
(browse-url (format "https://docs.doomemacs.org/modules/"
|
||||
(replace-regexp-in-string "::\\(.+\\)$" "#\\1" url))))
|
||||
(_ (user-error "%s is not a valid module source" source))))))
|
||||
(org-link-set-parameters
|
||||
"doom-changelog"
|
||||
:follow (lambda (link)
|
||||
(find-file (doom-path doom-docs-dir "changelog.org"))
|
||||
(org-match-sparse-tree nil link))))
|
||||
|
||||
;; TODO PR this upstream
|
||||
(defadvice! +org--follow-search-string-a (fn link &optional arg)
|
||||
"Support ::SEARCH syntax for id: links."
|
||||
|
@ -564,19 +660,6 @@ relative to `org-directory', unless it is an absolute path."
|
|||
|
||||
;; Add "lookup" links for packages and keystrings; useful for Emacs
|
||||
;; documentation -- especially Doom's!
|
||||
(org-link-set-parameters
|
||||
"kbd"
|
||||
:follow (lambda (_) (minibuffer-message "%s" (+org-display-link-in-eldoc-a)))
|
||||
:help-echo #'+org-read-kbd-at-point
|
||||
:face 'help-key-binding)
|
||||
(org-link-set-parameters
|
||||
"doom-package"
|
||||
:follow #'+org-link--doom-package-follow-fn
|
||||
:face (lambda (_) '(:inherit org-priority :slant italic)))
|
||||
(org-link-set-parameters
|
||||
"doom-module"
|
||||
:follow #'+org-link--doom-module-follow-fn
|
||||
:face #'+org-link--doom-module-face-fn)
|
||||
|
||||
;; Allow inline image previews of http(s)? urls or data uris.
|
||||
;; `+org-http-image-data-fn' will respect `org-display-remote-inline-images'.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue