Stump, Emacs and X selection.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Stump, Emacs and X selection.

Dimitri Minaev
Hello,

I'm trying to write a Stumpwm command that would create a note in
Org-mode and paste the current selection and some other info taken
from Firefox -- the URL and the tab title. While trying to implement
the command I met a couple of problems.

First, it doesn't work with non-Latin characters. I'm not sure whether
this is related to Stumpwm or Emacs. Stump's get-x-selection yields
correct result, but window-send-string seemingly drops all Cyrillic
characters from that string.

Then the other problem appeared. To avoid confusion between the
primary selection and the URL, I save the selection content in a
variable before putting the URL to another variable, but it seems that
these two variables are in the state of quantum entanglement. When one
of them is changed, the other one changes, too. I thought that the two
calls of (get-x-selection) might return the same object, which would
result in 'url' being replaced by 'sel'. So, I tried to copy the
string using copy-seq before assigning it to 'sel', but it didn't
help. Now I'm completely lost :)

Finally, I came up with the version that works correctly when it is
run two times :). After the first execution, it pastes two selections
and no URL. If you re-select the area in Firefox and run the same
command, the expected output will appear. What is wrong here?

(defcommand emacs-remember () ()
  "Send selection into emacs org-mode"
  (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 ""))
      (setf sel (get-x-selection))
    (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-or-raise "emacs" '(:class "Emacs"))
    (send-meta-key (current-screen) (kbd "M-x"))
    (window-send-string "org-capture")
    (send-meta-key (current-screen) (kbd "RET"))
    (window-send-string "f")
    (window-send-string (format nil "~a~%~a~%~%" current-window-name url))
    (window-send-string sel)))

Thanks.

--
With best regards,
Dimitri Minaev

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Patricio Martinez
Amazing, I'll probe it soon and I'll see how work. 

Thank you very much

Sent from Nylas N1, the extensible, open source mail client.
On may. 13 2016, at 1:27 pm, Dimitri Minaev <[hidden email]> wrote:

Hello,

I'm trying to write a Stumpwm command that would create a note in
Org-mode and paste the current selection and some other info taken
from Firefox -- the URL and the tab title. While trying to implement
the command I met a couple of problems.

First, it doesn't work with non-Latin characters. I'm not sure whether
this is related to Stumpwm or Emacs. Stump's get-x-selection yields
correct result, but window-send-string seemingly drops all Cyrillic
characters from that string.

Then the other problem appeared. To avoid confusion between the
primary selection and the URL, I save the selection content in a
variable before putting the URL to another variable, but it seems that
these two variables are in the state of quantum entanglement. When one
of them is changed, the other one changes, too. I thought that the two
calls of (get-x-selection) might return the same object, which would
result in 'url' being replaced by 'sel'. So, I tried to copy the
string using copy-seq before assigning it to 'sel', but it didn't
help. Now I'm completely lost :)

Finally, I came up with the version that works correctly when it is
run two times :). After the first execution, it pastes two selections
and no URL. If you re-select the area in Firefox and run the same
command, the expected output will appear. What is wrong here?

(defcommand emacs-remember () ()
  "Send selection into emacs org-mode"
  (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 ""))
      (setf sel (get-x-selection))
    (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-or-raise "emacs" '(:class "Emacs"))
    (send-meta-key (current-screen) (kbd "M-x"))
    (window-send-string "org-capture")
    (send-meta-key (current-screen) (kbd "RET"))
    (window-send-string "f")
    (window-send-string (format nil "~a~%~a~%~%" current-window-name url))
    (window-send-string sel)))

Thanks.

--
With best regards,
Dimitri Minaev

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel


_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Dany Haddad
Dimitri,

Cool snippet!

I have not tried to run your code, but just looking over it brielfy:
- Why are you setting `sel` in the `let` expression and immediately after using `setf`?
- I believe copy-seq does a shallow copy, so the elements will still be aliased, causing `quantum entanglement`
- I haven't looked into the `get-x-selection` routine, but it could be stateful. Try looking into the source and maybe doing a deep copy on its return value.

Hope that helps!

Dany

On Fri, May 13, 2016 at 5:23 AM Patricio Martinez <[hidden email]> wrote:
Amazing, I'll probe it soon and I'll see how work. 

Thank you very much

Sent from Nylas N1, the extensible, open source mail client.
On may. 13 2016, at 1:27 pm, Dimitri Minaev <[hidden email]> wrote:

Hello,

I'm trying to write a Stumpwm command that would create a note in
Org-mode and paste the current selection and some other info taken
from Firefox -- the URL and the tab title. While trying to implement
the command I met a couple of problems.

First, it doesn't work with non-Latin characters. I'm not sure whether
this is related to Stumpwm or Emacs. Stump's get-x-selection yields
correct result, but window-send-string seemingly drops all Cyrillic
characters from that string.

Then the other problem appeared. To avoid confusion between the
primary selection and the URL, I save the selection content in a
variable before putting the URL to another variable, but it seems that
these two variables are in the state of quantum entanglement. When one
of them is changed, the other one changes, too. I thought that the two
calls of (get-x-selection) might return the same object, which would
result in 'url' being replaced by 'sel'. So, I tried to copy the
string using copy-seq before assigning it to 'sel', but it didn't
help. Now I'm completely lost :)

Finally, I came up with the version that works correctly when it is
run two times :). After the first execution, it pastes two selections
and no URL. If you re-select the area in Firefox and run the same
command, the expected output will appear. What is wrong here?

(defcommand emacs-remember () ()
  "Send selection into emacs org-mode"
  (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 ""))
      (setf sel (get-x-selection))
    (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-or-raise "emacs" '(:class "Emacs"))
    (send-meta-key (current-screen) (kbd "M-x"))
    (window-send-string "org-capture")
    (send-meta-key (current-screen) (kbd "RET"))
    (window-send-string "f")
    (window-send-string (format nil "~a~%~a~%~%" current-window-name url))
    (window-send-string sel)))

Thanks.

--
With best regards,
Dimitri Minaev

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Bugzilla from pdm@zamazal.org
In reply to this post by Dimitri Minaev
>>>>> "DM" == Dimitri Minaev <[hidden email]> writes:

    DM> that would create a note in Org-mode and paste the current
    DM> selection and some other info taken from Firefox -- the URL and
    DM> the tab title.

Off-topic, but maybe still useful for someone here: This can be done
without StumpWM, just with Emacs and Firefox:

https://github.com/alphapapa/org-protocol-capture-html



_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Dimitri Minaev
In reply to this post by Dany Haddad
Ah, that `setf'... :) It was just a leftover of one of my panicky
experiments when I tried to get rid of all possible delayed
evaluations.

On 13 May 2016 at 21:12, Dany Haddad <[hidden email]> wrote:

> Dimitri,
>
> Cool snippet!
>
> I have not tried to run your code, but just looking over it brielfy:
> - Why are you setting `sel` in the `let` expression and immediately after
> using `setf`?
> - I believe copy-seq does a shallow copy, so the elements will still be
> aliased, causing `quantum entanglement`
> - I haven't looked into the `get-x-selection` routine, but it could be
> stateful. Try looking into the source and maybe doing a deep copy on its
> return value.
>
> Hope that helps!
>
> Dany
>
> On Fri, May 13, 2016 at 5:23 AM Patricio Martinez <[hidden email]> wrote:
>>
>> Amazing, I'll probe it soon and I'll see how work.
>>
>> Thank you very much
>>
>> Sent from Nylas N1, the extensible, open source mail client.
>> On may. 13 2016, at 1:27 pm, Dimitri Minaev <[hidden email]> wrote:
>>>
>>> Hello,
>>>
>>> I'm trying to write a Stumpwm command that would create a note in
>>> Org-mode and paste the current selection and some other info taken
>>> from Firefox -- the URL and the tab title. While trying to implement
>>> the command I met a couple of problems.
>>>
>>> First, it doesn't work with non-Latin characters. I'm not sure whether
>>> this is related to Stumpwm or Emacs. Stump's get-x-selection yields
>>> correct result, but window-send-string seemingly drops all Cyrillic
>>> characters from that string.
>>>
>>> Then the other problem appeared. To avoid confusion between the
>>> primary selection and the URL, I save the selection content in a
>>> variable before putting the URL to another variable, but it seems that
>>> these two variables are in the state of quantum entanglement. When one
>>> of them is changed, the other one changes, too. I thought that the two
>>> calls of (get-x-selection) might return the same object, which would
>>> result in 'url' being replaced by 'sel'. So, I tried to copy the
>>> string using copy-seq before assigning it to 'sel', but it didn't
>>> help. Now I'm completely lost :)
>>>
>>> Finally, I came up with the version that works correctly when it is
>>> run two times :). After the first execution, it pastes two selections
>>> and no URL. If you re-select the area in Firefox and run the same
>>> command, the expected output will appear. What is wrong here?
>>>
>>> (defcommand emacs-remember () ()
>>>   "Send selection into emacs org-mode"
>>>   (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 ""))
>>>       (setf sel (get-x-selection))
>>>     (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-or-raise "emacs" '(:class "Emacs"))
>>>     (send-meta-key (current-screen) (kbd "M-x"))
>>>     (window-send-string "org-capture")
>>>     (send-meta-key (current-screen) (kbd "RET"))
>>>     (window-send-string "f")
>>>     (window-send-string (format nil "~a~%~a~%~%" current-window-name
>>> url))
>>>     (window-send-string sel)))
>>>
>>> Thanks.
>>>
>>> --
>>> With best regards,
>>> Dimitri Minaev
>>>
>>> _______________________________________________
>>> Stumpwm-devel mailing list
>>> [hidden email]
>>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
>>
>> _______________________________________________
>> Stumpwm-devel mailing list
>> [hidden email]
>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel



--
With best regards,
Dimitri Minaev

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

David Bjergaard
Hi Dimitri,

I'm not sure why you have to run it twice.  I tried the snippet, and I didn't
see the text pop up until the second time I wrote it.  As for dropping non-latin
characters: this is a known issue with StumpWM, and one that I'm slowly trying
to address.

If you can get the bugs worked out (or not) you should put this on the wiki
since its a great example of using stumpwm to automate window actions that may
be tedious.  

    David

Dimitri Minaev <[hidden email]> writes:

> Ah, that `setf'... :) It was just a leftover of one of my panicky
> experiments when I tried to get rid of all possible delayed
> evaluations.
>
> On 13 May 2016 at 21:12, Dany Haddad <[hidden email]> wrote:
>> Dimitri,
>>
>> Cool snippet!
>>
>> I have not tried to run your code, but just looking over it brielfy:
>> - Why are you setting `sel` in the `let` expression and immediately after
>> using `setf`?
>> - I believe copy-seq does a shallow copy, so the elements will still be
>> aliased, causing `quantum entanglement`
>> - I haven't looked into the `get-x-selection` routine, but it could be
>> stateful. Try looking into the source and maybe doing a deep copy on its
>> return value.
>>
>> Hope that helps!
>>
>> Dany
>>
>> On Fri, May 13, 2016 at 5:23 AM Patricio Martinez <[hidden email]> wrote:
>>>
>>> Amazing, I'll probe it soon and I'll see how work.
>>>
>>> Thank you very much
>>>
>>> Sent from Nylas N1, the extensible, open source mail client.
>>> On may. 13 2016, at 1:27 pm, Dimitri Minaev <[hidden email]> wrote:
>>>>
>>>> Hello,
>>>>
>>>> I'm trying to write a Stumpwm command that would create a note in
>>>> Org-mode and paste the current selection and some other info taken
>>>> from Firefox -- the URL and the tab title. While trying to implement
>>>> the command I met a couple of problems.
>>>>
>>>> First, it doesn't work with non-Latin characters. I'm not sure whether
>>>> this is related to Stumpwm or Emacs. Stump's get-x-selection yields
>>>> correct result, but window-send-string seemingly drops all Cyrillic
>>>> characters from that string.
>>>>
>>>> Then the other problem appeared. To avoid confusion between the
>>>> primary selection and the URL, I save the selection content in a
>>>> variable before putting the URL to another variable, but it seems that
>>>> these two variables are in the state of quantum entanglement. When one
>>>> of them is changed, the other one changes, too. I thought that the two
>>>> calls of (get-x-selection) might return the same object, which would
>>>> result in 'url' being replaced by 'sel'. So, I tried to copy the
>>>> string using copy-seq before assigning it to 'sel', but it didn't
>>>> help. Now I'm completely lost :)
>>>>
>>>> Finally, I came up with the version that works correctly when it is
>>>> run two times :). After the first execution, it pastes two selections
>>>> and no URL. If you re-select the area in Firefox and run the same
>>>> command, the expected output will appear. What is wrong here?
>>>>
>>>> (defcommand emacs-remember () ()
>>>>   "Send selection into emacs org-mode"
>>>>   (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 ""))
>>>>       (setf sel (get-x-selection))
>>>>     (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-or-raise "emacs" '(:class "Emacs"))
>>>>     (send-meta-key (current-screen) (kbd "M-x"))
>>>>     (window-send-string "org-capture")
>>>>     (send-meta-key (current-screen) (kbd "RET"))
>>>>     (window-send-string "f")
>>>>     (window-send-string (format nil "~a~%~a~%~%" current-window-name
>>>> url))
>>>>     (window-send-string sel)))
>>>>
>>>> Thanks.
>>>>
>>>> --
>>>> With best regards,
>>>> Dimitri Minaev
>>>>
>>>> _______________________________________________
>>>> Stumpwm-devel mailing list
>>>> [hidden email]
>>>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
>>>
>>> _______________________________________________
>>> Stumpwm-devel mailing list
>>> [hidden email]
>>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Dimitri Minaev
David,

When I run the command for the first time I get the org-mode capture
buffer that goes, for example, like this:

----------------------------------------------------------------------------------
* GitHub - stumpwm/stumpwm: The Stump Window Manager - Mozilla Firefox
Stumpwm is a window manager written entirely in Common Lisp. It
attempts to be highly customizable while relying entirely on the
keyboard for input. You will not find buttons, icons, title bars, tool
bars, or any of the other conventional GUI widgets.

Stumpwm is a window manager written entirely in Common Lisp. It
attempts to be highly customizable while relying entirely on the
keyboard for input. You will not find buttons, icons, title bars, tool
bars, or any of the other conventional GUI widgets.
----------------------------------------------------------------------------------

Than I kill that buffer, get back to Firefox, reselect the paragraph
(because the primary selection contains the killed buffer now) and
repeat the command, getting the correct output:

----------------------------------------------------------------------------------
* GitHub - stumpwm/stumpwm: The Stump Window Manager - Mozilla Firefox
https://github.com/stumpwm/stumpwm

Stumpwm is a window manager written entirely in Common Lisp. It
attempts to be highly customizable while relying entirely on the
keyboard for input. You will not find buttons, icons, title bars, tool
bars, or any of the other conventional GUI widgets.
----------------------------------------------------------------------------------

Doesn't it work like that for you?


On 16 May 2016 at 21:59, David Bjergaard <[hidden email]> wrote:

> Hi Dimitri,
>
> I'm not sure why you have to run it twice.  I tried the snippet, and I didn't
> see the text pop up until the second time I wrote it.  As for dropping non-latin
> characters: this is a known issue with StumpWM, and one that I'm slowly trying
> to address.
>
> If you can get the bugs worked out (or not) you should put this on the wiki
> since its a great example of using stumpwm to automate window actions that may
> be tedious.
>
>     David
>
> Dimitri Minaev <[hidden email]> writes:
>
>> Ah, that `setf'... :) It was just a leftover of one of my panicky
>> experiments when I tried to get rid of all possible delayed
>> evaluations.
>>
>> On 13 May 2016 at 21:12, Dany Haddad <[hidden email]> wrote:
>>> Dimitri,
>>>
>>> Cool snippet!
>>>
>>> I have not tried to run your code, but just looking over it brielfy:
>>> - Why are you setting `sel` in the `let` expression and immediately after
>>> using `setf`?
>>> - I believe copy-seq does a shallow copy, so the elements will still be
>>> aliased, causing `quantum entanglement`
>>> - I haven't looked into the `get-x-selection` routine, but it could be
>>> stateful. Try looking into the source and maybe doing a deep copy on its
>>> return value.
>>>
>>> Hope that helps!
>>>
>>> Dany
>>>
>>> On Fri, May 13, 2016 at 5:23 AM Patricio Martinez <[hidden email]> wrote:
>>>>
>>>> Amazing, I'll probe it soon and I'll see how work.
>>>>
>>>> Thank you very much
>>>>
>>>> Sent from Nylas N1, the extensible, open source mail client.
>>>> On may. 13 2016, at 1:27 pm, Dimitri Minaev <[hidden email]> wrote:
>>>>>
>>>>> Hello,
>>>>>
>>>>> I'm trying to write a Stumpwm command that would create a note in
>>>>> Org-mode and paste the current selection and some other info taken
>>>>> from Firefox -- the URL and the tab title. While trying to implement
>>>>> the command I met a couple of problems.
>>>>>
>>>>> First, it doesn't work with non-Latin characters. I'm not sure whether
>>>>> this is related to Stumpwm or Emacs. Stump's get-x-selection yields
>>>>> correct result, but window-send-string seemingly drops all Cyrillic
>>>>> characters from that string.
>>>>>
>>>>> Then the other problem appeared. To avoid confusion between the
>>>>> primary selection and the URL, I save the selection content in a
>>>>> variable before putting the URL to another variable, but it seems that
>>>>> these two variables are in the state of quantum entanglement. When one
>>>>> of them is changed, the other one changes, too. I thought that the two
>>>>> calls of (get-x-selection) might return the same object, which would
>>>>> result in 'url' being replaced by 'sel'. So, I tried to copy the
>>>>> string using copy-seq before assigning it to 'sel', but it didn't
>>>>> help. Now I'm completely lost :)
>>>>>
>>>>> Finally, I came up with the version that works correctly when it is
>>>>> run two times :). After the first execution, it pastes two selections
>>>>> and no URL. If you re-select the area in Firefox and run the same
>>>>> command, the expected output will appear. What is wrong here?
>>>>>
>>>>> (defcommand emacs-remember () ()
>>>>>   "Send selection into emacs org-mode"
>>>>>   (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 ""))
>>>>>       (setf sel (get-x-selection))
>>>>>     (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-or-raise "emacs" '(:class "Emacs"))
>>>>>     (send-meta-key (current-screen) (kbd "M-x"))
>>>>>     (window-send-string "org-capture")
>>>>>     (send-meta-key (current-screen) (kbd "RET"))
>>>>>     (window-send-string "f")
>>>>>     (window-send-string (format nil "~a~%~a~%~%" current-window-name
>>>>> url))
>>>>>     (window-send-string sel)))
>>>>>
>>>>> Thanks.
>>>>>
>>>>> --
>>>>> With best regards,
>>>>> Dimitri Minaev
>>>>>
>>>>> _______________________________________________
>>>>> Stumpwm-devel mailing list
>>>>> [hidden email]
>>>>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
>>>>
>>>> _______________________________________________
>>>> Stumpwm-devel mailing list
>>>> [hidden email]
>>>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel



--
With best regards,
Dimitri Minaev

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Dimitri Minaev
In reply to this post by Bugzilla from pdm@zamazal.org
Milan,

Thank you very much for the idea. It doesn't seem to be general
enough, but it might work with Firefox. I planned to extend that
command to support other applications. So, in Thunderbird we can get a
link to the current message with Thunderlink extension. In Okular the
current document and the page number may be obtained via dbus -- an
awkward but sometimes useful contraption. That Stumpwm command works
with any program supporting X selections -- xterm, mutt, vim, Skype,
etc. They may have different ways to get the metadata, if any, but the
selected piece of text will be there, available for any other program.
I'm not yet sure if the same can be done using org-protocol.
Thunderbird does support it, but Okular, from what I can tell, does
not.


On 13 May 2016 at 22:11, Milan Zamazal <[hidden email]> wrote:

>>>>>> "DM" == Dimitri Minaev <[hidden email]> writes:
>
>     DM> that would create a note in Org-mode and paste the current
>     DM> selection and some other info taken from Firefox -- the URL and
>     DM> the tab title.
>
> Off-topic, but maybe still useful for someone here: This can be done
> without StumpWM, just with Emacs and Firefox:
>
> https://github.com/alphapapa/org-protocol-capture-html
>
>
>
> _______________________________________________
> Stumpwm-devel mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel



--
With best regards,
Dimitri Minaev

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

David Bjergaard
Hi Dimitri,

I'm excited to hear that you are going to extend this beyond firefox.  When
you're ready, feel free to open a PR with stumpwm-contrib and we can add it
there.

    David
   

Dimitri Minaev <[hidden email]> writes:

> Milan,
>
> Thank you very much for the idea. It doesn't seem to be general
> enough, but it might work with Firefox. I planned to extend that
> command to support other applications. So, in Thunderbird we can get a
> link to the current message with Thunderlink extension. In Okular the
> current document and the page number may be obtained via dbus -- an
> awkward but sometimes useful contraption. That Stumpwm command works
> with any program supporting X selections -- xterm, mutt, vim, Skype,
> etc. They may have different ways to get the metadata, if any, but the
> selected piece of text will be there, available for any other program.
> I'm not yet sure if the same can be done using org-protocol.
> Thunderbird does support it, but Okular, from what I can tell, does
> not.
>
>
> On 13 May 2016 at 22:11, Milan Zamazal <[hidden email]> wrote:
>>>>>>> "DM" == Dimitri Minaev <[hidden email]> writes:
>>
>>     DM> that would create a note in Org-mode and paste the current
>>     DM> selection and some other info taken from Firefox -- the URL and
>>     DM> the tab title.
>>
>> Off-topic, but maybe still useful for someone here: This can be done
>> without StumpWM, just with Emacs and Firefox:
>>
>> https://github.com/alphapapa/org-protocol-capture-html
>>
>>
>>
>> _______________________________________________
>> Stumpwm-devel mailing list
>> [hidden email]
>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Dimitri Minaev
David,

It's a deal -- I add the code to the contribs, and you fix the problem
with non-latin characters :)

On 17 May 2016 at 17:25, David Bjergaard <[hidden email]> wrote:

> Hi Dimitri,
>
> I'm excited to hear that you are going to extend this beyond firefox.  When
> you're ready, feel free to open a PR with stumpwm-contrib and we can add it
> there.
>
>     David
>
>
> Dimitri Minaev <[hidden email]> writes:
>
>> Milan,
>>
>> Thank you very much for the idea. It doesn't seem to be general
>> enough, but it might work with Firefox. I planned to extend that
>> command to support other applications. So, in Thunderbird we can get a
>> link to the current message with Thunderlink extension. In Okular the
>> current document and the page number may be obtained via dbus -- an
>> awkward but sometimes useful contraption. That Stumpwm command works
>> with any program supporting X selections -- xterm, mutt, vim, Skype,
>> etc. They may have different ways to get the metadata, if any, but the
>> selected piece of text will be there, available for any other program.
>> I'm not yet sure if the same can be done using org-protocol.
>> Thunderbird does support it, but Okular, from what I can tell, does
>> not.
>>
>>
>> On 13 May 2016 at 22:11, Milan Zamazal <[hidden email]> wrote:
>>>>>>>> "DM" == Dimitri Minaev <[hidden email]> writes:
>>>
>>>     DM> that would create a note in Org-mode and paste the current
>>>     DM> selection and some other info taken from Firefox -- the URL and
>>>     DM> the tab title.
>>>
>>> Off-topic, but maybe still useful for someone here: This can be done
>>> without StumpWM, just with Emacs and Firefox:
>>>
>>> https://github.com/alphapapa/org-protocol-capture-html
>>>
>>>
>>>
>>> _______________________________________________
>>> Stumpwm-devel mailing list
>>> [hidden email]
>>> https://lists.nongnu.org/mailman/listinfo/stumpwm-devel



--
With best regards,
Dimitri Minaev

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Bugzilla from pdm@zamazal.org
In reply to this post by Dimitri Minaev
>>>>> "DM" == Dimitri Minaev <[hidden email]> writes:

    DM> I planned to extend that command to support other
    DM> applications. So, in Thunderbird we can get a link to the
    DM> current message with Thunderlink extension. In Okular the
    DM> current document and the page number may be obtained via dbus --
    DM> an awkward but sometimes useful contraption. That Stumpwm
    DM> command works with any program supporting X selections -- xterm,
    DM> mutt, vim, Skype, etc. They may have different ways to get the
    DM> metadata, if any, but the selected piece of text will be there,
    DM> available for any other program.

This looks like a cool idea.

    DM> I'm not yet sure if the same can be done using org-protocol.
    DM> Thunderbird does support it, but Okular, from what I can tell,
    DM> does not.

But Stumpwm could use org-protocol to pass the selection to Emacs,
couldn't it?  It might be better than sending keyboard events.



_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Dimitri Minaev

On 05/20/2016 12:23 AM, Milan Zamazal wrote:
>
>      DM> I'm not yet sure if the same can be done using org-protocol.
>      DM> Thunderbird does support it, but Okular, from what I can tell,
>      DM> does not.
>
> But Stumpwm could use org-protocol to pass the selection to Emacs,
> couldn't it?  It might be better than sending keyboard events.

Milan,

Thanks for the idea. I've skimmed through a couple of articles about
org-mode but I don't quite get the idea behind it. The Emacs side is
relatively clear (as it usually is with everything made in Lisp :), but
I don't understand how the app side is supposed to work, except for the
obvious cases, like web browsers. Is it possible to trigger org-protocol
requests from Okular, LibreOffice, xterm or another arbitrary
application, like CoolReader?

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Bugzilla from pdm@zamazal.org
>>>>> "DM" == Dimitri Minaev <[hidden email]> 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?



_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

David Bjergaard
Milan Zamazal <[hidden email]> writes:

>>>>>> "DM" == Dimitri Minaev <[hidden email]> 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.

    David

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel
Reply | Threaded
Open this post in threaded view
|

Re: Stump, Emacs and X selection.

Dimitri Minaev
On 05/21/2016 07:52 PM, David Bjergaard wrote:

> Milan Zamazal <[hidden email]> writes:
>
>>>>>>> "DM" == Dimitri Minaev <[hidden email]> 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...

_______________________________________________
Stumpwm-devel mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/stumpwm-devel