emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org.el: use only link descriptions in indirect buffer names
@ 2021-05-22 14:12 Juan Manuel Macías
  2021-05-23 10:41 ` Ihor Radchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Juan Manuel Macías @ 2021-05-22 14:12 UTC (permalink / raw)
  To: orgmode

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

Hi,

When a heading contains a link with a description,
`org-tree-to-indirect-buffer' can produce in the name of the indirect
buffer strings like this:

"streaming.org-[[url-media:http://192.168.1.36:8888/Radiohead%20-%20Studio%20Discography/OK%20Computer%20%281997%29/recurse.m3u][Radiohead
-- OK Computer (1997)]]-1"

I would like to propose the attached patch, so that only the link
description is used in the indirect buffer name:

"streaming.org-Radiohead -- OK Computer (1997)-1"

Best regards,

Juan Manuel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-el-use-only-link-descriptions-in-indirect-buffer.patch --]
[-- Type: text/x-patch, Size: 1228 bytes --]

From b859f45abaa94e546e625b7b8c9f47ed64d6b4b4 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Sat, 22 May 2021 15:33:15 +0200
Subject: [PATCH] org.el: use only link descriptions in indirect buffer names

* lisp/org.el (org-tree-to-indirect-buffer): If the variable `heading'
contains a link with a description, it is replaced by the description string.
---
 lisp/org.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 1bd9e02eb..ca87cac67 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6895,8 +6895,13 @@ frame is not changed."
 	(while (> (setq level (org-outline-level)) arg)
 	  (org-up-heading-safe)))
       (setq beg (point)
-	    heading (org-get-heading 'no-tags))
+	    heading (replace-regexp-in-string
+                      org-link-bracket-re
+                       (lambda (x)
+                         (pcase (match-string 2 x)
+                           (`nil (match-string 1 x))
+                           ((pred stringp) (match-string 2 x))))
+                     (org-get-heading 'no-tags)))
       (org-end-of-subtree t t)
       (when (org-at-heading-p) (backward-char 1))
       (setq end (point)))
--
2.26.0


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

* Re: [PATCH] org.el: use only link descriptions in indirect buffer names
  2021-05-22 14:12 [PATCH] org.el: use only link descriptions in indirect buffer names Juan Manuel Macías
@ 2021-05-23 10:41 ` Ihor Radchenko
  2021-05-23 11:25   ` Juan Manuel Macías
  0 siblings, 1 reply; 4+ messages in thread
From: Ihor Radchenko @ 2021-05-23 10:41 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode

Juan Manuel Macías <maciaschain@posteo.net> writes:

> +	    heading (replace-regexp-in-string
> +                      org-link-bracket-re
> +                       (lambda (x)
> +                         (pcase (match-string 2 x)
> +                           (`nil (match-string 1 x))
> +                           ((pred stringp) (match-string 2 x))))
> +                     (org-get-heading 'no-tags)))

You can simply do (org-link-display-format (org-get-heading 'no-tags))

Best,
Ihor


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

* Re: [PATCH] org.el: use only link descriptions in indirect buffer names
  2021-05-23 10:41 ` Ihor Radchenko
@ 2021-05-23 11:25   ` Juan Manuel Macías
  2021-09-26  7:40     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Juan Manuel Macías @ 2021-05-23 11:25 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: orgmode

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

Ihor Radchenko writes:

> You can simply do (org-link-display-format (org-get-heading 'no-tags))
>
> Best,
> Ihor

Oh!! I see that with my code I just reinvented the wheel :-D:

---
org-link-display-format is a compiled Lisp function in ‘ol.el’.

(org-link-display-format S)

Replace links in string S with their description.
If there is no description, use the link target.
---

Thank you very much for the suggestion, Ihor!

(new patch attached)

Best regards,

Juan Manuel


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-el-use-only-link-descriptions-in-indirect-buffer.patch --]
[-- Type: text/x-patch, Size: 953 bytes --]

From b859f45abaa94e546e625b7b8c9f47ed64d6b4b4 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Sat, 22 May 2021 15:33:15 +0200
Subject: [PATCH] org.el: use only link descriptions in indirect buffer names

* lisp/org.el (org-tree-to-indirect-buffer): If the variable `heading'
contains a link with a description, it is replaced by the description string.
---
 lisp/org.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index 1bd9e02eb..ca87cac67 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6895,8 +6895,7 @@ frame is not changed."
 	(while (> (setq level (org-outline-level)) arg)
 	  (org-up-heading-safe)))
       (setq beg (point)
-	    heading (org-get-heading 'no-tags))
+	    heading (org-link-display-format (org-get-heading 'no-tags)))
       (org-end-of-subtree t t)
       (when (org-at-heading-p) (backward-char 1))
       (setq end (point)))
--
2.26.0


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

* Re: [PATCH] org.el: use only link descriptions in indirect buffer names
  2021-05-23 11:25   ` Juan Manuel Macías
@ 2021-09-26  7:40     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2021-09-26  7:40 UTC (permalink / raw)
  To: Juan Manuel Macías; +Cc: orgmode, Ihor Radchenko

Hi Juan,

Juan Manuel Macías <maciaschain@posteo.net> writes:

> (new patch attached)

I see this patch has been applied, thanks to both of you.

I'm marking it as applied for updates.orgmode.org.

-- 
 Bastien


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

end of thread, other threads:[~2021-09-26  7:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-22 14:12 [PATCH] org.el: use only link descriptions in indirect buffer names Juan Manuel Macías
2021-05-23 10:41 ` Ihor Radchenko
2021-05-23 11:25   ` Juan Manuel Macías
2021-09-26  7:40     ` Bastien

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).