Add some Org lint checkers for bookmark links
Code taken from `org-lint-invalid-id-link` and suitably modified.
This commit is contained in:
parent
3dbc9604d4
commit
a522f48dc5
22
init.el
22
init.el
@ -574,7 +574,9 @@
|
||||
db/org-clock-goto-first-open-checkbox
|
||||
org-password-manager-get-password-by-id
|
||||
db/org-bookmark-open
|
||||
db/org-bookmark-store-link))
|
||||
db/org-bookmark-store-link
|
||||
db/org-lint-invalid-bookmark-link
|
||||
db/org-lint-possible-bookmark-link))
|
||||
|
||||
;; This is to make the byte-compiler happy about setting some variables later on
|
||||
;; that are defined in those packages.
|
||||
@ -816,15 +818,29 @@
|
||||
:init (setq org-cycle-include-plain-lists 'integrate))
|
||||
|
||||
(use-package org-lint
|
||||
:autoload (org-lint-checker-name)
|
||||
:autoload (org-lint-checker-name
|
||||
org-lint-add-checker)
|
||||
:config (progn
|
||||
|
||||
;; Yes, this is ugly, but I would like to get rid of checking for
|
||||
;; obsolete percentage encoding in URLs without loosing the other
|
||||
;; checkers.
|
||||
(setq org-lint--checkers (cl-remove-if #'(lambda (c)
|
||||
(eq (org-lint-checker-name c)
|
||||
'percent-encoding-link-escape))
|
||||
org-lint--checkers))))
|
||||
org-lint--checkers))
|
||||
|
||||
(org-lint-add-checker 'link-to-bookmark
|
||||
"Report links to non-existing bookmarks"
|
||||
#'db/org-lint-invalid-bookmark-link
|
||||
:categories '(link)
|
||||
:trust 'low)
|
||||
|
||||
(org-lint-add-checker 'link-replacable-by-bookmark
|
||||
"Report links that can be replaced by bookmarks"
|
||||
#'db/org-lint-possible-bookmark-link
|
||||
:categories '(link)
|
||||
:trust 'low)))
|
||||
|
||||
;; Drag-and-Drop images into org-mode buffer
|
||||
(use-package org-download
|
||||
|
||||
@ -2242,6 +2242,32 @@ PARAMS may contain the following values:
|
||||
(org-link-store-props :link (concat "bookmark:" bookmark)
|
||||
:description bookmark))))
|
||||
|
||||
(defun db/org-lint-invalid-bookmark-link (ast)
|
||||
"Org lint checker to verify bookmark links in AST point to known bookmarks."
|
||||
(bookmark-maybe-load-default-file)
|
||||
(org-element-map ast 'link
|
||||
(lambda (link)
|
||||
(let ((bmk (org-element-property :path link)))
|
||||
(and (equal (org-element-property :type link) "bookmark")
|
||||
(not (assoc-string bmk bookmark-alist))
|
||||
(list (org-element-begin link)
|
||||
(format "Unknown bookmark link \"%s\"" bmk)))))))
|
||||
|
||||
(defun db/org-lint-possible-bookmark-link (ast)
|
||||
"Org lint checker to point out links in AST that could be replaced by bookmarks."
|
||||
(bookmark-maybe-load-default-file)
|
||||
(org-element-map ast 'link
|
||||
(lambda (link)
|
||||
(when-let* ((link-path (org-element-property :raw-link link))
|
||||
(known-bookmark (-find #'(lambda (bmk)
|
||||
(string= (bookmark-get-filename bmk)
|
||||
link-path))
|
||||
bookmark-alist)))
|
||||
(list (org-element-begin link)
|
||||
(format "Link to \"%s\" can be replaced by bookmark \"%s\""
|
||||
link-path
|
||||
(car known-bookmark)))))))
|
||||
|
||||
|
||||
;;; End
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user