org-capture-extension: broken when using xdg-open

Hi there,

I had to change the URI to var uri = 'org-protocol:///';(note the three /) in order to make the extension work on Linux where it calls xdg-open. This seems to be a known problem, cf. https://github.com/alphapapa/org-protocol-capture-html#chrome

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Update: This is outdated. Turns out gio also shares the same “bug”!


I too am witnessing the second colon getting eaten.

tl;dr To the best I can surmise, the culprit is actually KDE.

NOT this extension; NOT xdg-open.


Here’s what I can see. Rather than debugging on emacs directly, here’s a script that just prints its arguments.

argdebug

#!/bin/sh
for x in "$@"; do
        echo >&2 "'$x'"
done

~/.local/share/applications/emacs-capture.desktop

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Emacs Client
Exec=argdebug "%u"
Icon=emacs-icon
Type=Application
Terminal=false
MimeType=x-scheme-handler/org-protocol;

a direct call, of course, works fine…

$ argdebug "org-protocol://capture://L/aa/bb/cc"
'org-protocol://capture://L/aa/bb/cc'

xdg-open eats a colon…

$ xdg-open "org-protocol://capture://L/aa/bb/cc"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "org-protocol"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "org-protocol"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "org-protocol"
kf5.kio.core: "preferred service for x-scheme-handler/org-protocol" "emacs-capture"
'org-protocol://capture//L/aa/bb/cc'

but there’s more to the story than just that. If I trace xdg-open using bash -x, I find that it very quickly delegates its job to another program:

$ kde-open5 "org-protocol://capture://L/aa/bb/cc"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "org-protocol"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "org-protocol"
kf5.kio.core: Refilling KProtocolInfoFactory cache in the hope to find "org-protocol"
kf5.kio.core: "preferred service for x-scheme-handler/org-protocol" "emacs-capture"
'org-protocol://capture//L/aa/bb/cc'

kde-open5 is eating the colon!

What is kde-open5? As far as I can tell, it’s part of a CLI front end to various features of kio, which appears to be KDE’s own magical url-handling system that tries to abstract file operations over “file://”, “http://”, “ssh://”, zip files, radio transmissions from mars, and etc., etc.,

I tried looking further into it, but kde has a large and heavily factored C++ codebase that would take a while to digest.


aside: It’s also very picky about what colons it eats. It’s actually quite amusing. I have no cohesive explanation that can describe all of its output.

$ kde-open5 "org-protocol://capture://:L:/:a:a:/:b:b:/:c:c:"
'org-protocol://capture//:L:/:a:a:/:b:b:/:c:c:'
$ kde-open5 "org-protocol://capture//:L:/:a:a:/:b:b:/:c:c:"
'org-protocol://capture//:L:/:a:a:/:b:b:/:c:c:'
$ kde-open5 "org-protocol://:cap:ture://:L:/:a:a:/:b:b:/:c:c:"
(opens web browser to 'http://org-protocol//:cap:ture://:L:/:a:a:/:b:b:/:c:c:')
$ kde-open5 "org-protocol://capture://L://aa://bb://cc:"
'org-protocol://capture//L://aa://bb://cc:'
$ kde-open5 "org-protocol:///capture://L/aa/bb/cc"
'org-protocol:///capture://L/aa/bb/cc'

(the last example shows why #17 works as a workaround for KDE users; the extra slash somehow protects the colon)


$ uname -r
4.10.13-1-ARCH
$ xdg-open --version
xdg-open 1.1.2
$ kde-open5 --version
kioclient 5.9.5