From d6d1e600c0b22ce323558002eccdaac6edbcf2b2 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 21 Jun 2022 03:02:27 +0200 Subject: [PATCH] fix(org): org-protocol not triggering for its uris A more elegant solution will have to wait until the CLI rewrite (where modules can supply patches for its packages, then I could hoist org-protocol-check-filename-for-protocol into the autoloads file using autoload cookie magic). Fix: #6481 Fix: #5997 --- modules/lang/org/config.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index ac29e423a..28e8d9025 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -1302,8 +1302,24 @@ between the two." (defadvice! +org--server-visit-files-a (fn files &rest args) "Advise `server-visit-files' to load `org-protocol' lazily." :around #'server-visit-files - (if (not (cl-loop for var in files - if (string-match-p "://" (car var)) + (if (not (cl-loop with protocol = + (if IS-WINDOWS + ;; On Windows, the file arguments for `emacsclient' + ;; get funnelled through `expand-file-path' by + ;; `server-process-filter'. This substitutes + ;; backslashes with forward slashes and converts each + ;; path to an absolute one. However, *all* absolute + ;; paths on Windows will match the regexp ":/+", so we + ;; need a more discerning regexp. + (regexp-quote + (or (bound-and-true-p org-protocol-the-protocol) + "org-protocol")) + ;; ...but since there is a miniscule possibility users + ;; have changed `org-protocol-the-protocol' I don't want + ;; this behavior for macOS/Linux users. + "") + for var in files + if (string-match-p (format "%s:/+" protocol) (car var)) return t)) (apply fn files args) (require 'org-protocol)