[Top][All Lists]

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

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

From: Pascal J. Bourguignon
Subject: Re: How to `start-process' in different terminal?
Date: Sun, 22 Jun 2014 17:03:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Thorsten Jolitz <address@hidden> writes:

> Hi List, 
> when running Emacs on the console (without X) I use 'fbgs' to display
> pdf files (converted to .tiff actally). This does not work with a
> terminal multiplexer like tmux (running on e.g. tty), I have to switch
> manually to e.g. tty1 to make it work.
> Quite a lot of Emacs libs use start-process to display generated pdfs
> with an OS dependent executable, for example "evince", always assuming 
> ,----[ C-h f display-graphic-p RET ]
> | display-graphic-p is a compiled Lisp function in `frame.el'.
> | 
> | (display-graphic-p &optional DISPLAY)
> | 
> | Return non-nil if DISPLAY is a graphic display.
> `----
> is non-nil. 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 0x1172ab0>)

So calling display-graphic-p is meaningless.

> 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 0x1172ab0>)

> 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.

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 PGM 0x39cff98>)

then you can use with-selected-frame to run your code on that frame.

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.

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.

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).

__Pascal Bourguignon__
"Le mercure monte ?  C'est le moment d'acheter !"

reply via email to

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