org: Allow spaces in #+LINK abbreviation definitions

* lisp/org.el (org-set-regexps-and-options): Allow spaces when
defining link abbreviations via #+LINK keyword.
* testing/lisp/test-org-element.el (test-org-element/link-parser): Add
a new test.
* doc/org-manual.org (Link Abbreviations): Add example demonstrating
link abbreviation with spaces.

Reported-by: Rudolf Adamkovič <salutis@me.com>
Link: https://orgmode.org/list/87zgf7zujc.fsf@localhost
This commit is contained in:
Ihor Radchenko 2022-11-04 15:14:44 +08:00
parent 0737112852
commit 4c40fc3d4d
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
3 changed files with 17 additions and 1 deletions

View File

@ -3652,8 +3652,11 @@ can define them in the file with
#+begin_example
,#+LINK: bugzilla https://10.1.2.9/bugzilla/show_bug.cgi?id=
,#+LINK: duckduckgo https://duckduckgo.com/?q=%s
,#+LINK: "Nu Html Checker" https://validator.w3.org/nu/?doc=%h
#+end_example
The abbreviations containing spaces must be quoted.
In-buffer completion (see [[*Completion]]) can be used after =[= to
complete link abbreviations. You may also define a Lisp function that
implements special (e.g., completion) support for inserting such a

View File

@ -4227,7 +4227,11 @@ related expressions."
(delq nil
(mapcar
(lambda (value)
(and (string-match "\\`\\(\\S-+\\)[ \t]+\\(.+\\)" value)
(and (or
;; "abbrev with spaces" spec
(string-match "\\`\"\\(.+[^\\]\\)\"[ \t]+\\(.+\\)" value)
;; abbrev spec
(string-match "\\`\\(\\S-+\\)[ \t]+\\(.+\\)" value))
(cons (match-string-no-properties 1 value)
(match-string-no-properties 2 value))))
(cdr (assoc "LINK" alist))))))

View File

@ -2007,6 +2007,15 @@ e^{i\\pi}+1=0
(progn (org-mode-restart)
(goto-char (1- (point-max)))
(org-element-property :type (org-element-context))))))
;; Link abbreviation with spaces.
(should
(equal "https"
(org-test-with-temp-text
"#+LINK: \"Nu Html Checker\" https://validator.w3.org/nu/?doc=%h
[[Nu Html Checker:test]]"
(progn (org-mode-restart)
(goto-char (1- (point-max)))
(org-element-property :type (org-element-context))))))
;; Link abbreviation in a secondary string.
(should
(equal "https"