From 949b49226d9606770a46233bb231cf264b6c2a94 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Thu, 9 Jun 2022 19:51:28 +0200 Subject: [PATCH] Add workaround for org-ql to find links with brackets in description This will be tested now and then reported upstream. --- init.el | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index 978ff09..20c8c4e 100644 --- a/init.el +++ b/init.el @@ -950,7 +950,56 @@ :ensure org-ql :commands (org-ql-view org-ql-search - org-dblock-write:org-ql)) + org-dblock-write:org-ql) + + :config (progn + + ;; Redefine the regular expression for link searches to allow + ;; brackets in the description. This function comes straight from + ;; org-ql.el + (cl-defun org-ql--link-regexp (&key description-or-target description target) + "Return a regexp matching Org links according to arguments. +Each argument is treated as a regexp (so non-regexp strings +should be quoted before being passed to this function). If +DESCRIPTION-OR-TARGET, match it in either description or target. +If DESCRIPTION, match it in the description. If TARGET, match it +in the target. If both DESCRIPTION and TARGET, match both, +respectively." + (cl-labels + ((no-desc + (match) (rx-to-string `(seq (or bol (1+ blank)) + "[[" (0+ (not (any "]"))) (regexp ,match) (0+ (not (any "]"))) + "]]"))) + (match-both + (description target) + (rx-to-string `(seq (or bol (1+ blank)) + "[[" (0+ (not (any "]"))) (regexp ,target) (0+ (not (any "]"))) + ;; Added `anything' + "][" (0+ anything) (regexp ,description) (0+ anything) + "]]"))) + ;; Note that these actually allow empty descriptions + ;; or targets, depending on what they are matching. + (match-desc + (match) (rx-to-string `(seq (or bol (1+ blank)) + "[[" (0+ (not (any "]"))) + ;; Added `anything' + "][" (0+ anything) (regexp ,match) (0+ anything) + "]]"))) + (match-target + (match) (rx-to-string `(seq (or bol (1+ blank)) + "[[" (0+ (not (any "]"))) (regexp ,match) (0+ (not (any "]"))) + ;; Added `anything' + "][" (0+ anything) + "]]")))) + (cond (description-or-target + (rx-to-string `(or (regexp ,(no-desc description-or-target)) + (regexp ,(match-desc description-or-target)) + (regexp ,(match-target description-or-target))))) + ((and description target) + (match-both description target)) + (description (match-desc description)) + (target (rx-to-string `(or (regexp ,(no-desc target)) + (regexp ,(match-target target)))))))))) (use-package ol :init (setq org-link-keep-stored-after-insertion t)