emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] org.el: Preserve case for link subgroups from `org-file-apps'
Date: Mon, 5 Sep 2022 14:15:46 +0700	[thread overview]
Message-ID: <tf47n3$15l4$1@ciao.gmane.io> (raw)

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


Debugging `org-file-apps' and `org-open-file' regexp subgroups I noticed 
an issue: the code distorts case of the link components making them 
invalid. The patch to fix the bug is attached, the commit message 
contains an example of the problem.

Maybe I break some use case, but I am unaware when namely downcased link 
must be used.

[-- Attachment #2: 0001-org.el-Preserve-case-for-link-subgroups-from-org-fil.patch --]
[-- Type: text/x-patch, Size: 2551 bytes --]

From c7c514d62a8b2150cfbc1bfa927422790bb617cf Mon Sep 17 00:00:00 2001
From: Max Nikulin <manikulin@gmail.com>
Date: Mon, 5 Sep 2022 13:54:25 +0700
Subject: [PATCH] org.el: Preserve case for link subgroups from `org-file-apps'

* lisp/org.el (org-open-file): Avoid matching of `org-file-apps' records
against the link converted to downcase since it caused incorrect
substitutions to the command.

Consider the following entry

      . "okular --find %2 %s%1"))

and the link
Without the patch

    okular --find before /usr/share/doc/bash/bashref.pdf\#redirections

command is executed and the application can not resolve internal
cross-reference anchor.

In https://list.orgmode.org/4B51D104.9090502@jboecker.de/T/#u
the purpose of `dlink' is not clarified, so I assume that the only
purpose is to allow matching file suffixes, e.g. ".pdf" vs ".PDF".
 lisp/org.el | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index f317053c4..67721cc8d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8134,7 +8134,6 @@ If the file does not exist, throw an error."
 	 (link (cond (line (concat file "::" (number-to-string line)))
 		     (search (concat file "::" search))
 		     (t file)))
-	 (dlink (downcase link))
 	  (and (string-match "\\`.*?\\.\\([a-zA-Z0-9]+\\(\\.gz\\)?\\)\\'" dfile)
 	       (match-string 1 dfile)))
@@ -8159,8 +8158,9 @@ If the file does not exist, throw an error."
 		    ;; First, try matching against apps-dlink if we
 		    ;; get a match here, store the match data for
 		    ;; later.
-		    (let ((match (assoc-default dlink apps-dlink
-						'string-match)))
+		    (let* ((case-fold-search t)
+                           (match (assoc-default link apps-dlink
+                                                 'string-match)))
 		      (if match
 			  (progn (setq link-match-data (match-data))
@@ -8191,7 +8191,7 @@ If the file does not exist, throw an error."
       (user-error "No such file: %s" file))
      ((org-string-nw-p cmd)
-      (setq cmd (org--open-file-format-command cmd file dlink link-match-data))
+      (setq cmd (org--open-file-format-command cmd file link link-match-data))
 	(message "Running %s...done" cmd)

             reply	other threads:[~2022-09-05  7:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-05  7:15 Max Nikulin [this message]
2022-09-06 12:07 ` [PATCH] org.el: Preserve case for link subgroups from `org-file-apps' Ihor Radchenko
2022-09-08 14:37   ` [PATCH v2] " Max Nikulin
2022-09-09 11:10     ` Ihor Radchenko

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:

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to='tf47n3$15l4$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* 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 public inbox


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