|
From: | Dimitri Minaev |
Subject: | Re: [STUMP] Stump, Emacs and X selection. |
Date: | Mon, 23 May 2016 16:13:22 +0400 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 |
On 05/21/2016 07:52 PM, David Bjergaard wrote:
Milan Zamazal <address@hidden> writes:"DM" == Dimitri Minaev <address@hidden> writes:DM> I don't understand how the app side is supposed to work, except DM> for the obvious cases, like web browsers. Is it possible to DM> trigger org-protocol requests from Okular, LibreOffice, xterm or DM> another arbitrary application, like CoolReader? I don't know, basically the application must be able to run emacsclient. But I assume your idea was to use X selection instead and then you can simply invoke emacsclient from Stumpwm, right?I'm not sure if this is how the firefox plugin does it, but remember that you can do:emacsclient -e "(elisp expr)"so from the stumpwm side, you just have to construct the right elisp expressions and send them to emacsclient for their side-effects. This might be a bit cleaner than using stumpwm to send emacs the key presses. Then you just have to used stumpwm for interacting with non-extension aware apps (like skype converstations). You should be able to pull metadata out of the windows from stumpwm. This idea has a lot of potential! I hope you pursue it.
I've played a little bit with org-protocol, hoping that I could understand how it works and imitate it in Stumpwm. No way :) The best I could do was to call emacsclient from Stumpwm like this:
(run-shell-command(format nil "/usr/bin/emacsclient org-protocol:/capture:/s/~s/~s/~s" (urlencode url) (urlencode current-window-name) (urlencode sel)) nil)
`urlencode' function may be found, for example, in do-urlencode (available in Quicklisp).
The good news is that even non-Latin characters are now passed to Emacs. The bad news is that my original question is still valid -- when the new command is run for the first time, the selected text is inserted instead of the URL. On the second time, the command works as intended. I'm missing something important about how X selections work.
(defcommand emacs-capture () () "Send selection into emacs using org-protocol"(let ((current-window-name (if (current-window) (window-title (current-window)) "No current window")) (current-window-class (if (current-window) (window-class (current-window)) "No window class"))
(copy-from-firefox (equal (window-class (current-window)) "Firefox")) (sel (get-x-selection)) (url "")) (when copy-from-firefox (send-meta-key (current-screen) (kbd "F6")) (send-meta-key (current-screen) (kbd "C-c")) (setf url (get-x-selection)) (send-meta-key (current-screen) (kbd "F6"))) (run-shell-command(format nil "/usr/bin/emacsclient org-protocol:/capture:/s/~s/~s/~s" (do-urlencode:urlencode url) (do-urlencode:urlencode current-window-name) (do-urlencode:urlencode sel)) nil)))
The org-mode template was defined as: ("s" "Stump clip" entry (file+headline "~/org/capture.org" "Notes") "* %a\n\n Source: %l\n\n %:initial") Of course, org-protocol must be enabled in Emacs.On the one hand, indeed, org-protocol looks cleaner than simulated keypresses. On the other hand, it brings new dependencies -- do-urlencode and org-protocol in Emacs. I'm not sure if it's a step in the right direction :) But then again, the non-Latin characters...
[Prev in Thread] | Current Thread | [Next in Thread] |