all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] ol-info: Enable :insert-description feature
Date: Sun, 4 Sep 2022 22:05:17 +0700	[thread overview]
Message-ID: <tf2ere$11jr$1@ciao.gmane.io> (raw)
In-Reply-To: <87a68hn9es.fsf@localhost>

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

On 06/08/2022 14:00, Ihor Radchenko wrote:
> Max Nikulin writes:
> 
>> To get impression of the new feature in action, I modified ol-info.el.
>> First patch does not depend on :insert-description and might be useful
>> per se. Second one just enables the feature.
> 
> Thanks! The patches look useful.
> You should also add an entry to ORG-NEWS. Otherwise, I just have two
> minor comments.

I have realized that I did not address this comment. See the first 
attachment.

I have noticed `org-trim' function, so second attached patch replaces 
`string-trim' in the newly added code to this function native to Org. 
Unfortunately `org-unbracket-string' can not handle empty suffix, but 
the fix is rather simple, so `string-remove-prefix' becomes unnecessary 
as well. The only reason of this patch is that earlier subr-x was 
avoided, see e.g. https://list.orgmode.org/87sg0onfrw.fsf@nicolasgoaziou.fr/

Patches are independent and neither of them is strictly necessary, I do 
not mind if they would be ignored.

[-- Attachment #2: 0001-ORG-NEWS-org-info-description-as-command.patch --]
[-- Type: text/x-patch, Size: 1430 bytes --]

From 7fffacdda6015cee895e8eddb554bce1b82da6d2 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Wed, 31 Aug 2022 09:15:17 +0700
Subject: [PATCH 1/2] ORG-NEWS: `org-info-description-as-command'

* etc/ORG-NEWS: Mention that `org-info' uses `:insert-description',
a new feature of `org-link-parameters'.
---
 etc/ORG-NEWS | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index d6d99a64b..713a850f6 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -455,6 +455,17 @@ prompting for a link description.  It can be a string (used as-is) or
 a function (called with the same arguments as
 ~org-make-link-description-function~ to return a string to use).
 
+An example of a such function for =info:= links is
+~org-info-description-as-command~.  To access a manual section outside
+of Org, description may be pasted to shell prompt or evaluated withing
+Emacs using =M-:= (wrapped into parenthesis).  For example,
+description of the =info:org#Tags= link is =info "(org) Tags"=.  To
+restore earlier behavior add to your Emacs init file the following:
+#+begin_src elisp :results silent :eval never-export
+  (with-eval-after-load 'ol-info
+    (org-link-set-parameters "info" :insert-description nil))
+#+end_src
+
 *** New list of languages for LaTeX export: ~org-latex-language-alist~ 
 
 ~org-latex-language-alist~ unifies into a single list the old language
-- 
2.25.1


[-- Attachment #3: 0002-ol-info-Use-org-function-instead-of-subr-x.patch --]
[-- Type: text/x-patch, Size: 2710 bytes --]

From ef29e143545b4c1806abfb8ca072f7c98842fff2 Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Wed, 31 Aug 2022 09:21:47 +0700
Subject: [PATCH 2/2] ol-info: Use org function instead of subr-x

* lisp/org-macs.el (org-unbracket-string): Handle empty suffix string.
* lisp/ol-info.el (org-info--link-file-node):
(org-info-description-as-command): Use `org-trim' and
`org-unbracket-string' instead of `string-trim' and
`string-remove-prefix' from the subr-x package.
---
 lisp/ol-info.el  | 9 ++++-----
 lisp/org-macs.el | 3 ++-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/lisp/ol-info.el b/lisp/ol-info.el
index e54fedc06..d332b2837 100644
--- a/lisp/ol-info.el
+++ b/lisp/ol-info.el
@@ -30,7 +30,6 @@
 
 ;;; Code:
 
-(require 'subr-x) ; `string-trim', `string-remove-prefix'
 (require 'org-macs)
 (org-assert-version)
 
@@ -78,11 +77,11 @@ File may be a virtual one, see `Info-virtual-files'."
       '("dir" . "Top")
     (string-match "\\`\\([^#:]*\\)\\(?:[#:]:?\\(.*\\)\\)?\\'" path)
     (let* ((node (match-string 2 path))
-           ;; Do not reorder, `string-trim' modifies match.
-           (file (string-trim (match-string 1 path))))
+           ;; Do not reorder, `org-trim' modifies match.
+           (file (org-trim (match-string 1 path))))
       (cons
        (if (org-string-nw-p file) file "dir")
-       (if (org-string-nw-p node) (string-trim node) "Top")))))
+       (if (org-string-nw-p node) (org-trim node) "Top")))))
 
 (defun org-info-description-as-command (link desc)
   "Info link description that can be pasted as command.
@@ -106,7 +105,7 @@ If LINK is not an info link then DESC is returned."
          (need-file-node (and (not (org-string-nw-p desc))
                               (string-prefix-p prefix link))))
     (pcase (and need-file-node
-                (org-info--link-file-node (string-remove-prefix prefix link)))
+                (org-info--link-file-node (org-unbracket-string prefix "" link)))
       ;; Unlike (info "dir"), "info dir" shell command opens "(coreutils)dir invocation".
       (`("dir" . "Top") "info \"(dir)\"")
       (`(,file . "Top") (format "info %s" file))
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index 13d872a82..2e4590e93 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -1101,7 +1101,8 @@ removed.  Return the new string.  If STRING is nil, return nil."
   (and string
        (if (and (string-prefix-p pre string)
 		(string-suffix-p post string))
-	   (substring string (length pre) (- (length post)))
+	   (substring string (length pre)
+                      (and (not (string-equal "" post)) (- (length post))))
 	 string)))
 
 (defun org-strip-quotes (string)
-- 
2.25.1


  parent reply	other threads:[~2022-09-04 15:06 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-28 23:15 ol.el: add description format parameter to org-link-parameters Hugo Heagren
2022-03-28 23:15 ` [PATCH] " Hugo Heagren
2022-04-04  9:49   ` Ihor Radchenko
2022-04-05 19:29     ` [PATCH v2] " Hugo Heagren
2022-04-07  5:13       ` Ihor Radchenko
2022-06-21 12:03         ` [PATCH v3] " Hugo Heagren
2022-06-21 13:41           ` Robert Pluim
2022-07-07 19:57             ` [PATCH v4] " Hugo Heagren
2022-07-09  3:31               ` Ihor Radchenko
2022-07-14 13:08                 ` [PATCH v5] " Hugo Heagren
2022-07-16  9:09                   ` Ihor Radchenko
2022-07-16 21:20                     ` Hugo Heagren
2022-07-17  6:11                       ` Max Nikulin
2022-07-17 10:27                         ` Ihor Radchenko
2022-07-17 10:18                       ` Ihor Radchenko
2022-07-17 20:59                         ` [PATCH v6] " Hugo Heagren
2022-07-18 10:55                           ` Max Nikulin
2022-07-23  7:48                             ` [PATCH v7] " Hugo Heagren
2022-07-23  7:59                               ` Max Nikulin
2022-07-23 13:06                                 ` Ihor Radchenko
2022-07-23 15:46                                   ` Max Nikulin
2022-07-24 10:34                                   ` Max Nikulin
2022-07-24 13:15                                     ` Ihor Radchenko
2022-07-25 11:55                                       ` [PATCH v8] " Hugo Heagren
2022-07-29 12:54                                         ` Max Nikulin
2022-07-29 19:05                                           ` [PATCH v9] " Hugo Heagren
2022-07-30  6:29                                             ` Ihor Radchenko
     [not found]                                               ` <87tu6zf2o1.fsf@heagren.com>
2022-07-30  8:02                                                 ` Ihor Radchenko
2022-07-30 12:34                                                   ` [PATCH] ol-info: Enable :insert-description feature Max Nikulin
2022-08-06  7:00                                                     ` Ihor Radchenko
2022-08-14 16:41                                                       ` [PATCH v2] ol-info: Define :insert-description function Max Nikulin
2022-08-19  4:28                                                         ` Ihor Radchenko
2022-08-19 12:26                                                           ` Max Nikulin
2022-08-20  7:29                                                             ` Ihor Radchenko
2022-08-21 14:49                                                               ` Max Nikulin
2022-08-22  4:10                                                                 ` Ihor Radchenko
2022-08-24 14:37                                                                   ` [PATCH v3] " Max Nikulin
2022-08-26 13:15                                                                     ` Ihor Radchenko
2022-09-04 15:05                                                       ` Max Nikulin [this message]
2022-09-05  6:36                                                         ` [PATCH] ol-info: Enable :insert-description feature Ihor Radchenko
2022-08-06  6:06                                             ` [PATCH v9] ol.el: add description format parameter to org-link-parameters Ihor Radchenko
2022-07-29  1:47                               ` [PATCH v7] " Ihor Radchenko
2022-07-29  7:05                                 ` Bastien Guerry
2022-07-10 10:26               ` [PATCH v4] " Max Nikulin
2022-06-21 15:01           ` [PATCH v3] " Max Nikulin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='tf2ere$11jr$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.