emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Link-words with spaces, allowed or not?
@ 2022-09-09 14:15 Rudolf Adamkovič
  2022-09-10  5:07 ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Rudolf Adamkovič @ 2022-09-09 14:15 UTC (permalink / raw)
  To: emacs-orgmode

The documentation at

https://orgmode.org/manual/Link-Abbreviations.html

says that the link-word

"[...] must be a word, starting with a letter, followed by letters,
numbers, ‘-’, and ‘_’."

Below, the documentation gives an example that defines a link-word

"Nu Html Checker"

that contains multiple words and invalid characters (spaces).

That makes me wonder:

- Does Org need updated to disallow spaces in link-words?
- Does Org documentation need updated to remove the "Nu Html Checker"?

Alternatively, if Org allows spaces in link-words, then I wonder

- How to define a link-word with spaces using #+link?

Rudy
-- 
"Genius is 1% inspiration and 99% perspiration."
-- Thomas Alva Edison, 1932

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Link-words with spaces, allowed or not?
  2022-09-09 14:15 Link-words with spaces, allowed or not? Rudolf Adamkovič
@ 2022-09-10  5:07 ` Ihor Radchenko
  2022-11-04  7:17   ` [PATCH] " Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-09-10  5:07 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: emacs-orgmode

Rudolf Adamkovič <salutis@me.com> writes:

> Below, the documentation gives an example that defines a link-word
>
> "Nu Html Checker"
>
> that contains multiple words and invalid characters (spaces).
>
> That makes me wonder:
>
> - Does Org need updated to disallow spaces in link-words?

Strictly speaking, Org does allow spaced in link-words, but only for
bracketed [[links]]. Plain links like http: cannot have spaces.

> - Does Org documentation need updated to remove the "Nu Html Checker"?

The documentation example is valid, though we should indeed clarify that
spaces are only allowed in bracketed links.

> Alternatively, if Org allows spaces in link-words, then I wonder
>
> - How to define a link-word with spaces using #+link?

AFAIK, you cannot. The #+LINK keywords are matched against
"\\`\\(\\S-+\\)[ \t]+\\(.+\\)" regexp.

We may allow something like
#+LINK: "this is a link with spaces" http://replacement

Patches are welcome!

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Re: Link-words with spaces, allowed or not?
  2022-09-10  5:07 ` Ihor Radchenko
@ 2022-11-04  7:17   ` Ihor Radchenko
  2022-11-19 13:41     ` Rudolf Adamkovič
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2022-11-04  7:17 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Rudolf Adamkovič, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]

Ihor Radchenko <yantar92@gmail.com> writes:

> We may allow something like
> #+LINK: "this is a link with spaces" http://replacement

See the attached patch allowing the above syntax in #+LINK keywords.


[-- Attachment #2: 0001-org-Allow-spaces-in-LINK-abbreviation-definitions.patch --]
[-- Type: text/x-patch, Size: 3300 bytes --]

From 0b81f2d4cc9f6dd5f8d38f9a6550387c93b15435 Mon Sep 17 00:00:00 2001
Message-Id: <0b81f2d4cc9f6dd5f8d38f9a6550387c93b15435.1667546163.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Fri, 4 Nov 2022 15:14:44 +0800
Subject: [PATCH] org: Allow spaces in #+LINK abbreviation definitions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* 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
---
 doc/org-manual.org               | 3 +++
 lisp/org.el                      | 6 +++++-
 testing/lisp/test-org-element.el | 9 +++++++++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index dc2fc57cd..47710466a 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -3652,8 +3652,11 @@ ** Link Abbreviations
 #+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
diff --git a/lisp/org.el b/lisp/org.el
index d8708f8f2..0036b189a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4184,7 +4184,11 @@ (defun org-set-regexps-and-options (&optional tags-only)
 	       (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))))))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index eb5b95e86..78a735efe 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -2007,6 +2007,15 @@ (ert-deftest test-org-element/link-parser ()
 	    (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"
-- 
2.35.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Re: Link-words with spaces, allowed or not?
  2022-11-04  7:17   ` [PATCH] " Ihor Radchenko
@ 2022-11-19 13:41     ` Rudolf Adamkovič
  2022-11-20  5:09       ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Rudolf Adamkovič @ 2022-11-19 13:41 UTC (permalink / raw)
  To: Ihor Radchenko, Ihor Radchenko; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> See the attached patch allowing the above syntax in #+LINK keywords.

I finally got to test the patch (against the current `main' at commit
0b124d796) and it works perfectly.  Thank you, also, for the inclusion
of the automated test which makes it possible for me (and us all) to
rely on this functionality working in the future!

Can we install the patch to main?

Rudy
-- 
"The introduction of suitable abstractions is our only mental aid to
organize and master complexity."
-- Edsger Wybe Dijkstra, 1930-2002

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Re: Link-words with spaces, allowed or not?
  2022-11-19 13:41     ` Rudolf Adamkovič
@ 2022-11-20  5:09       ` Ihor Radchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2022-11-20  5:09 UTC (permalink / raw)
  To: Rudolf Adamkovič; +Cc: Ihor Radchenko, emacs-orgmode

Rudolf Adamkovič <salutis@me.com> writes:

> Ihor Radchenko <yantar92@posteo.net> writes:
>
>> See the attached patch allowing the above syntax in #+LINK keywords.
>
> I finally got to test the patch (against the current `main' at commit
> 0b124d796) and it works perfectly.  Thank you, also, for the inclusion
> of the automated test which makes it possible for me (and us all) to
> rely on this functionality working in the future!
>
> Can we install the patch to main?

Thanks for testing!
Applied onto main now.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=b2c805f3c
Fixed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-20  5:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09 14:15 Link-words with spaces, allowed or not? Rudolf Adamkovič
2022-09-10  5:07 ` Ihor Radchenko
2022-11-04  7:17   ` [PATCH] " Ihor Radchenko
2022-11-19 13:41     ` Rudolf Adamkovič
2022-11-20  5:09       ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).