help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to `start-process' in different terminal?


From: Thorsten Jolitz
Subject: Re: How to `start-process' in different terminal?
Date: Tue, 24 Jun 2014 12:41:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

"Pascal J. Bourguignon" <address@hidden> writes:

> Thorsten Jolitz <address@hidden> writes:
>

>> Quite a lot of Emacs libs use start-process to display generated pdfs
>> with an OS dependent executable, for example "evince"

>> I would like to fallback to "fbgs" if it is nil on GNU/Linux,
>> normally from an Emacs running inside a tmux session e.g. on tty.
>
> It depends on the frame, nowadays emacs can work BOTH on a terminal and
> a X window at the same time:
>
> (frame-list) --> (#<frame PGM 0x39cff98> 
>                   #<frame gnus at kuiper.lan.informatimago.com
> 0x1172ab0>)
>
> So calling display-graphic-p is meaningless.

hmm ... right now I try to live without X11, but before when I had one
Emacs server running and several Emacsclients open, on the console and
under X11, I used `display-graphic-p' successfully to determine
background-color.

>> How can I `start-process' in a different terminal (e.g. tty1) and switch
>> to that terminal in an Emacs Lisp program?
>>
>> When I call `(terminal-list)' from Emacs instances on two different
>> tty's I get
>> the same result:
>>
>> ,----
>> | (#<terminal 1 on /dev/tty>)
>> `----
>
> I don't observe that:
>
> (terminal-list) --> (#<terminal 1 on :0.0> 
>                      #<terminal 2 on /dev/pts/3> 
>                      #<terminal 4 on /dev/pts/5>)
>
> (frame-list)  --> (#<frame PGM 0xe18b00> 
>                    #<frame PGM 0x39cff98> 
>                    #<frame   gnus at kuiper.lan.informatimago.com 0x1172ab0>)


,----
| (terminal-list) --> (#<terminal 1 on /dev/tty>)
| 
| (frame-list) --> (#<frame F1 0xbc5c20>)
`----

even when I switch from tty1 to tty2 and start Emacs -Q I get

,----
| (terminal-list) --> (#<terminal 1 on /dev/tty>)
`----

again.

>> and I don't find a function for switching terminal or calling cmd on
>> another terminal. 
>
> You can use:
>
>    (make-terminal-frame '((tty . "/dev/pts/5")
>                          (tty-type . "xterm")))5)
>
> to make a frame on a new terminal.

seems to work

,----
| (make-terminal-frame '((tty2 . "/dev/pts/5")
|                        (tty-type . "xterm")))
| 
| -> #<frame F2 0x4d834f0>
`----

and I get

,----
| (frame-configuration (#<frame F2 0x4d834f0> ((menu-bar-lines . 0)
| (buried-buffer-list) (buffer-list *Ibuffer* *Minibuf-1* *unsent followup
| to Pascal J. Bourguignon on gmane.emacs.help*) ...)
| 
| (#<frame F1 0xbc5c20> ((buried-buffer-list *Backtrace* *Completions*
| *sent followup to Stefan Monnier on gmane.emacs.help* .newsrc-dribble)
| (buffer-list *unsent followup to Pascal J. Bourguignon on
| gmane.emacs.help* ...))
`----

but `frame-terminal' returns the same in both frames:
(#<terminal 1 on /dev/tty>). 

I'm probably confused wrt console, terminal, shell ...

This is what ps shows me right now (I'm on Archlinux):

,----
|   182 root     1:name=systemd:/user.slice/ login -- tj
|   188 tj       1:name=systemd:/user.slice/  \_ -bash
|   219 tj       1:name=systemd:/user.slice/      \_ tmux
|   221 tj       1:name=systemd:/user.slice/ tmux
|   267 tj       1:name=systemd:/user.slice/  \_ bash
|   270 tj       1:name=systemd:/user.slice/  |   \_ emacs --debug-init
|   283 tj       1:name=systemd:/user.slice/  |       \_ /usr/bin/idn
|   --quiet --idna-to-ascii --usestd3asciirules
|  1473 root     1:name=systemd:/user.slice/ login -- tj
|  1475 tj       1:name=systemd:/user.slice/  \_ -bash
`----

I just logged in, started tmux, then started emacs. Then I switched
terminals with M-<right> going from tty1 to tty2 and logged in again
(thats what I thought at least, and thats what I'm told at the login
shell prompt). 

But it seems I'm on the same terminal all the time? When I start Emacs
-Q from the bash with pid 1475 I would assume its on another terminal
than the one I started from bash with pid 267, but apparently it isn't. 

> But to run a function in the context of another terminal, you need to
> select a frame running on that terminal.
>
> To find a frame running on a given terminal device:
>
>     (first (remove* "/dev/pts/3" (frame-list)
>                     :test (function string/=)
>                     :key (lambda (frame) (terminal-name (frame-terminal 
> frame)))))
>     --> (#<frame PGM 0x39cff98>)
>
> then you can use with-selected-frame to run your code on that frame.

 (first (remove* "/dev/pts/3" (frame-list)
                 :test (function string=)
                 :key (lambda (frame) (terminal-name (frame-terminal
                 frame)))))

--> #<frame F2 0x4d834f0>

ok ...

> To switch automatically to that terminal will depend on the multiplexer
> you use.
>
> You can use chvt(1) to switch to the linux console you want.  When you
> run a multiplexer in the terminal, you need to use whatever is provided
> by the multiplexer to switch to another view.

,----
| address@hidden ~]$ chvt 2
| Couldn't get a file descriptor referring to the console
`----

I have to figure that out for tmux

> For example, with screen, you could print ESC ]83;select 1 BEL
> to select the view 1.  I don't know tmux.  But the difficulty here would
> be to have emacs send the escape sequence unchanged.   With message or
> insert, screen doesn't seem to catch it, I guess we'd have to do that at
> a lower level.

... this too.

> Finally if you're on X window, you would have to use window manager
> commands to move the X window containing the terminal emulator you want
> on the front.  With ratpoison it's done with:
>
>    (shell-command "ratpoison -c 'select 1'")
>
> but it depends on the window manager.  Perhaps there's some
> common (ICCCM) command, and it should be possible to send it, since
> emacs itself can be used as a X window manager (cf. xwem).

Well, my question was more about the situation without X11, since
otherwise I don't see a reason not to use e.g. evince to display
generated pdfs.

The use-case I had in mind is:
 
 - Emacs on the console with terminal-multiplexer (tmux), no Xorg server
   running

 - Emacs libraries (org, auctex ...) produce pdf output

 - pdf can be viewed without X11 using frame-buffer tools like fbgs

 - but these tools don't work with terminal-multiplexer like tmux, thus
   I have to manually switch from tty1 (with tmux) to tty2 (without
   tmux) and call fbgs from there.

The question was if its possible to e.g. make org-export instruction

,----
| Export to LaTeX as PDF file and open
`----

work in such a scenario too. 

>From your answer I would say 'yes', I only need to figure out the very
last tmux-specific steps. I'll try ...

Thanks a lot.

-- 
cheers,
Thorsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]