unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* problems with some external org-mode shell links which make emacs stuck
@ 2024-02-01  9:05 Gregor Zattler
  2024-02-01 12:18 ` Bruno Barbier
  0 siblings, 1 reply; 4+ messages in thread
From: Gregor Zattler @ 2024-02-01  9:05 UTC (permalink / raw)
  To: help-gnu-emacs

Dear Emacs users, I use org-mode's external links to
establish ssh portforwarding to several servers, like
so:

[[shell:ssh -N -F /etc/ssh/ssh_config -L localport:hostname:hostport -p port user@server& # comment1][comment2]]

If I do C-c  C-o (org-open-at-point) on such a link,
the ssh portforwarding command is executed
successfully, but:

1. I'm asked every time if I want to execute the
   command.  This is annoying, is there a possibility
   to stop this?

2. Emacs then shows "Executing ssh -N ..." in the echo
   area and while I still see the active cursor on the
   link I'm not able to move the point or switch
   between windows, till I hit C-g.  (In a terminal
   emulator under bash command returns successfully,
   it's exit code is 0.)

   The problem does not stem from the "# comment1"
   part, since the same does not happen with this link:
   [[shell:/usr/bin/echo hund & # hund][hund]]

   Any idea what's happening here?

   If I instead use an external link of type elisp,
   like so:

   [[elisp:(shell-command "ssh -N -F /etc/ssh/ssh_config -L 30001:xxxxxxxx:8006   -p 2220 xxxx@xxxxxxxxxx & # comment1")][comment2]]

   Problems are the same.  I also experimented with
   start-process, but with even less success.


The value of sh-shell-file is "/bin/bash".  This is on Debian/Bookworm.


Emacs  : GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, cairo version 1.16.0)
 of 2024-01-25
Package: Org mode version 9.7-pre (release_9.6.17-1091-gea5290 @ /home/grfz/src/org-mode/lisp/)

But this also happens with emacs 28.2 and -Q.

Thanks for pointers, Gregor



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with some external org-mode shell links which make emacs stuck
  2024-02-01  9:05 problems with some external org-mode shell links which make emacs stuck Gregor Zattler
@ 2024-02-01 12:18 ` Bruno Barbier
  2024-02-01 22:15   ` Gregor Zattler
  0 siblings, 1 reply; 4+ messages in thread
From: Bruno Barbier @ 2024-02-01 12:18 UTC (permalink / raw)
  To: Gregor Zattler, help-gnu-emacs


Hi Gregor,

Gregor Zattler <telegraph@gmx.net> writes:

>
> 1. I'm asked every time if I want to execute the
>    command.  This is annoying, is there a possibility
>    to stop this?

See https://orgmode.org/manual/Code-Evaluation-Security.html.
   
>
> 2. Emacs then shows "Executing ssh -N ..." in the echo
>    area and while I still see the active cursor on the
>    link I'm not able to move the point or switch
>    between windows, till I hit C-g.  (In a terminal
>    emulator under bash command returns successfully,
>    it's exit code is 0.)
>
>    The problem does not stem from the "# comment1"
>    part, since the same does not happen with this link:
>    [[shell:/usr/bin/echo hund & # hund][hund]]


Are you sure the problem doesn't come from the comment at the end ?
(isn't "echo" command instantaneous?).

Org passes the command to: `shell-command'. The documentation of `shell-command' says:

    If COMMAND ends in ‘&’, execute it asynchronously.
    

I've tested with simpler commands using a recent Org:

┌────
│ [[shell:sleep 5&][Doesn't hang]]
│ 
│ [[shell:sleep 5& # COMMENT][Hang for 5s]]
└────

First link doesn't hang; second link does.


>    Any idea what's happening here?
>
>    If I instead use an external link of type elisp,
>    like so:
>
>    [[elisp:(shell-command "ssh -N -F /etc/ssh/ssh_config -L 30001:xxxxxxxx:8006   -p 2220 xxxx@xxxxxxxxxx & # comment1")][comment2]]


Note that you may explicitly request an asynchronous execution using
`async-shell-command' instead of `shell-command'.

┌────
│ (shell-command "sleep 5")                  ; Hangs.
│ (shell-command "sleep 5&")                 ; Doesn't hang.
│ (shell-command "sleep 5& # whatever")      ; Hangs.
│ (async-shell-command "sleep 5")            ; Doesn't hang.
│ (async-shell-command "sleep 5 # whaever")  ; Doesn't hang.
└────


Bruno



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with some external org-mode shell links which make emacs stuck
  2024-02-01 12:18 ` Bruno Barbier
@ 2024-02-01 22:15   ` Gregor Zattler
  2024-02-02  9:56     ` Bruno Barbier
  0 siblings, 1 reply; 4+ messages in thread
From: Gregor Zattler @ 2024-02-01 22:15 UTC (permalink / raw)
  To: Bruno Barbier, help-gnu-emacs

Hi Bruno,
* Bruno Barbier <brubar.cs@gmail.com> [2024-02-01; 13:18 +01]:
> Gregor Zattler <telegraph@gmx.net> writes:
>> 1. I'm asked every time if I want to execute the
>>    command.  This is annoying, is there a possibility
>>    to stop this?
>
> See https://orgmode.org/manual/Code-Evaluation-Security.html.

thanks.  I hoped for some less global setting.
Therefore I will cope with this question rather than
disable it.

>> 2. Emacs then shows "Executing ssh -N ..." in the echo
>>    area and while I still see the active cursor on the
>>    link I'm not able to move the point or switch
>>    between windows, till I hit C-g.  (In a terminal
>>    emulator under bash command returns successfully,
>>    it's exit code is 0.)
>>
>>    The problem does not stem from the "# comment1"
>>    part, since the same does not happen with this link:
>>    [[shell:/usr/bin/echo hund & # hund][hund]]
>
>
> Are you sure the problem doesn't come from the comment at the end ?
> (isn't "echo" command instantaneous?).

Yes, now I see, you are right.  With the "&" a buffer
for the result pops up, which I don't want.  The "#"
prohibits that, but for the price of Emacs being
stuck. [At some stage of my experiments I got a "#
wrong reader syntax" messages, which hints to, that the
"#" was somehow interpreted by the lisp interpreter.]

I finally used an "elisp:" link and "start-process":

[[elisp:(start-process "ssh" "*ssh*" "ssh" "-N" "-L xxxx:192.168.xxx.xxx:xxxx" "-p xxxx" root@xx.xxx.xx.xxx")][xxx remote]]

This works as expected.

Thanks for your help.

Regards, Gregor



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: problems with some external org-mode shell links which make emacs stuck
  2024-02-01 22:15   ` Gregor Zattler
@ 2024-02-02  9:56     ` Bruno Barbier
  0 siblings, 0 replies; 4+ messages in thread
From: Bruno Barbier @ 2024-02-02  9:56 UTC (permalink / raw)
  To: Gregor Zattler, help-gnu-emacs


Hi Gregor,

Gregor Zattler <telegraph@gmx.net> writes:

> Hi Bruno,
> * Bruno Barbier <brubar.cs@gmail.com> [2024-02-01; 13:18 +01]:
>> Gregor Zattler <telegraph@gmx.net> writes:
>>> 1. I'm asked every time if I want to execute the
>>>    command.  This is annoying, is there a possibility
>>>    to stop this?
>>
>> See https://orgmode.org/manual/Code-Evaluation-Security.html.
>
> thanks.  I hoped for some less global setting.
> Therefore I will cope with this question rather than
> disable it.

Indeed, I wouldn't either.

You can set these variables per file:

   https://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html

What I usually do, I keep a line:

   # (setq-local org-link-shell-skip-confirm-regexp ".*")
   
With this line, if I need to disable security, I just have to do 'C-x C-e'
at the end of that line.


> Yes, now I see, you are right.  With the "&" a buffer
> for the result pops up, which I don't want.  The "#"
> prohibits that, but for the price of Emacs being
> stuck. [At some stage of my experiments I got a "#
> wrong reader syntax" messages, which hints to, that the
> "#" was somehow interpreted by the lisp interpreter.]
>
> I finally used an "elisp:" link and "start-process":
>
> [[elisp:(start-process "ssh" "*ssh*" "ssh" "-N" "-L xxxx:192.168.xxx.xxx:xxxx" "-p xxxx" root@xx.xxx.xx.xxx")][xxx remote]]


You may be interested by defining your own link type, so that you can
write, for example:

   [[ssh-L::xxxx:192.168.xxx.xxx:xxxx]]
   
You will not get the security question anymore, and you will have full
control in elisp. That's actually relatively easy to do:

   https://orgmode.org/manual/Adding-Hyperlink-Types.html



Bruno




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-02  9:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01  9:05 problems with some external org-mode shell links which make emacs stuck Gregor Zattler
2024-02-01 12:18 ` Bruno Barbier
2024-02-01 22:15   ` Gregor Zattler
2024-02-02  9:56     ` Bruno Barbier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).