diff --git a/lisp/org.el b/lisp/org.el index 5b1443c4e..299f39949 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -8743,29 +8743,34 @@ If the file does not exist, throw an error." (cond ((and (stringp cmd) (not (string-match "^\\s-*$" cmd))) ;; 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) - (number-of-groups (- (/ (length link-match-data) 2) 1))) - (set-match-data link-match-data) - (while (<= match-index number-of-groups) - (let ((regex (concat "%" (number-to-string match-index))) - (replace-with (match-string match-index dlink))) - (while (string-match regex cmd) - (setq cmd (replace-match replace-with t t cmd)))) - (setq match-index (+ match-index 1))))) - - (save-window-excursion - (message "Running %s...done" cmd) - (start-process-shell-command cmd nil cmd) + (let* ((command (split-string-and-unquote cmd)) + (command (mapcar (lambda (arg) + (while (string-match "['\"]%s['\"]" arg) + (setq arg (replace-match "%s" t t arg))) + arg) + command))) + ;; Replace "%1", "%2" etc. in command with group matches from regex + (save-match-data + (let ((match-index 1) + (number-of-groups (- (/ (length link-match-data) 2) 1))) + (set-match-data link-match-data) + (while (<= match-index number-of-groups) + (let ((regex (concat "%" (number-to-string match-index))) + (replace-with (match-string match-index dlink))) + (setq command + (mapcar (lambda (arg) + (while (string-match regex arg) + (setq arg (replace-match replace-with t t arg))) + arg) + command))) + (setq match-index (+ match-index 1))))) + (setq command (mapcar (lambda (arg) (format-spec arg (list (cons ?s file)))) command)) + (save-window-excursion + (message "Running %S...done" command) + (make-process :name "org-open-file" :connection-type 'pipe + :buffer "*Messages*" + :filter (lambda (proc string) (message "org-open-file: %s" string)) + :noquery 't :command command)) (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait)))) ((or (stringp cmd) (eq cmd 'emacs))