From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id iFwwMZMrJmA7RQAA0tVLHw (envelope-from ) for ; Fri, 12 Feb 2021 07:17:39 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id gMHrLJMrJmCTLAAAbx9fmQ (envelope-from ) for ; Fri, 12 Feb 2021 07:17:39 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 213079402B3 for ; Fri, 12 Feb 2021 07:17:39 +0000 (UTC) Received: from localhost ([::1]:34010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAShu-0007V0-38 for larch@yhetil.org; Fri, 12 Feb 2021 02:17:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAShB-0007UR-3v for emacs-orgmode@gnu.org; Fri, 12 Feb 2021 02:16:53 -0500 Received: from out0.migadu.com ([2001:41d0:2:267::]:55237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lASh7-0008Jx-UV for emacs-orgmode@gnu.org; Fri, 12 Feb 2021 02:16:52 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1613114206; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=O0UkVnoFttpic+KT8pjwmNHkuQmtnaNgiC4xpsZgSjA=; b=eh9vTdno72b52KlVUwxBgdg+ARcV99ZzqowOlJZfnFP+CJ5vSs5NSR/ij65CvZh32YgtWP VQDqi9a1sLZdHmZ9cnCUK/7rMvl49EO5LWxSgdlMEiFcXBwmVG/jVXjfxGBZJM3OqJfcxY mWmo3dBZG4+opb4uwuuRWC/6X1qKud6HDgWM5PS2rLB1h084cAygZsH0icJR0Y6xM/zK3L JzYjtzNIUyXb2p/8E6b+LQEPADXSWpzpRAl1eiDTgodB6wcOVGUx69VMsQdQWcFNU9VkA1 VPooiC/nKDkYy0a85WKl/es7H31f5QwTUnW8kKRX9Mci7Ak2xeew4rhNA74JLQ== From: Kyle Meyer To: Maxim Nikulin Subject: Re: greedy substitution in org-open-file In-Reply-To: References: Date: Fri, 12 Feb 2021 02:16:40 -0500 Message-ID: <874kih92nb.fsf@kyleam.com> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Auth-User: kyle@kyleam.com Received-SPF: pass client-ip=2001:41d0:2:267::; envelope-from=kyle@kyleam.com; helo=out0.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.56 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=kyleam.com header.s=key1 header.b=eh9vTdno; dmarc=none; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 213079402B3 X-Spam-Score: -2.56 X-Migadu-Scanner: scn1.migadu.com X-TUID: dgFxGb1y9jf4 Maxim Nikulin writes: > Looking into the code related to 'pty problem with > start-process-shell-command, I have realized that the following case is > not handled correctly: > > #+begin_src elisp > (setq org-file-apps '(("\\.pdf::\\([0-9]+\\)\\'" . "xpdf %s %1"))) > #+end_src Not relevant for the underlying issue, but doesn't xpdf require a colon before the page number (i.e. ":%1")? > I hope, I adapted an example from [[help:org-file-apps]] correctly. When > I try to open the following link using C-c C-o > > [[file:test-%1f.pdf::42]] > > I get > > Running xpdf /home/ubuntu/examples/org/test-\42f.pdf 42...done > > I believe, it should be > > Running xpdf /home/ubuntu/examples/org/test-%1f.pdf 42...done > > Or > > Running xpdf /home/ubuntu/examples/org/test-\%1f.pdf 42...done Yep, it should show up as "Running xpdf /tmp/test-\%1f.pdf :42...done", with the backslash coming from shell-quote-argument. > The source of the problem is that %s substitution is expanded at first > and regexp groups are replaced later. Ideally, it should be performed in > a single pass. I have found format-spec function but I am unsure > concerning it, maybe it is avoided intentionally. I believe format-spec requires the placeholder to be A-z: (format-spec "xpdf %s" '((?s . "a"))) => "xpdf a" (format-spec "xpdf %s %1" '((?s . "a") (?1 . "b"))) ;; Invalid format string What about flipping the processing, handling the %N placeholders first and then formatting the file name? Seems to work on my end, though I haven't tested it thoroughly. diff --git a/lisp/org.el b/lisp/org.el index c61b8fb56..31dbe352a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8714,12 +8714,6 @@ (defun org-open-file (path &optional in-emacs line search) ;; Remove quotes around the file name - we'll use shell-quote-argument. (while (string-match "['\"]%s['\"]" cmd) (setq cmd (replace-match "%s" t t cmd))) - (setq cmd (replace-regexp-in-string - "%s" - (shell-quote-argument (convert-standard-filename file)) - cmd - nil t)) - ;; Replace "%1", "%2" etc. in command with group matches from regex (save-match-data (let ((match-index 1) @@ -8731,7 +8725,11 @@ (defun org-open-file (path &optional in-emacs line search) (while (string-match regex cmd) (setq cmd (replace-match replace-with t t cmd)))) (setq match-index (+ match-index 1))))) - + (setq cmd (replace-regexp-in-string + "%s" + (shell-quote-argument (convert-standard-filename file)) + cmd + nil t)) (save-window-excursion (message "Running %s...done" cmd) (start-process-shell-command cmd nil cmd)