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

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

Re: Can Emacs started with `-nw' option view pdf with pdf-tools?


From: Hongyi Zhao
Subject: Re: Can Emacs started with `-nw' option view pdf with pdf-tools?
Date: Wed, 21 Jul 2021 09:56:04 +0800

On Wed, Jul 21, 2021 at 6:37 AM Felix Dietrich
<felix.dietrich@sperrhaken.name> wrote:
>
> Thibaut Verron <thibaut.verron@gmail.com> writes:
>
> > Le sam. 17 juil. 2021 à 12:38, Hongyi Zhao <hongyi.zhao@gmail.com> a écrit :
> >>
> >> On Sat, Jul 17, 2021 at 3:00 PM Arthur Miller <arthur.miller@live.com> 
> >> wrote:
> >> >
> >> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >> >
> >> > > I'm using auctex and pdf-tools with Emacs,  and find that if I start
> >> > > Emacs with `emacs -nw`, the pdf-tools won't let me preview pdf.
> >> > >
> >> > > Any hints?
> >> > >
> >> > > Regards
> >> >
> >> > Yes you need a GUI window to display images (which is what pdf-tools
> >> > does).
> >>
> >> Basically, if I start emacs without `-nw' option, the `C-c C-v' will
> >> do the job described here automatically. But how to let `C-c C-v' open
> >> a GUI window for this case?
> >
> > Emacs with -nw has no concept of "GUI window", so I don't think that
> > it is possible.
>
> Emacs can handle (info "(elisp) Multiple Terminals") and can display
> text terminal and graphical terminal frames at the same time.
>
> > If you use emacs as a daemon and start a terminal client with
> > emacsclient -t, there might be a way to have C-c C-v open a gui client
> > with pdf-view, but that would be tricky.
>
> For the X Display Server, use (make-frame-on-display (getenv "DISPLAY"))
> to create a graphical frame.  If Emacs was started with the “-nw”
> options, this will run the necessary initialisation steps (according to
> the manual).  The environment variable “DISPLAY” should already be set
> in your terminal emulator and, therefore, in the Emacs instance you
> started in the terminal emulator.  For single user systems its value is
> commonly “:0”.
>
> When running Emacs remotely via ssh, you may allow remote X client
> applications to create their windows on your local desktop by passing
> the “-X” option (or setting “ForwardX11” in your “~/.ssh/config”).  This
> will create a tunnel for X11 applications from the remote system to your
> local X Server and set the “DISPLAY” variable accordingly.  Performance
> may be lagging, though.
>
> Here is a sketch for a function that creates a graphical terminal frame
> before it calls the command that “C-c C-v” runs.  You need to fill in
> the command.  You can find it with “C-h c C-c C-v”.  Beware: the code is
> untested.
>
>
>     (defun view-pdf-in-graphical-frame ()
>       (interactive)
>       (unless window-system
>         ;; Create a graphical frame first.
>         (let ((display (getenv "DISPLAY")))
>           (when (seq-empty-p display)
>             (user-error "No DISPLAY environment variable set"))
>           (select-frame (make-frame-on-display display))))
>       ;; Replace ‘C-c_C-v_command’ with the actual name of the command.
>       (call-interactively 'C-c_C-v_command))

I tried with the following code in init file:

(defun view-pdf-in-graphical-frame ()
  (interactive)
  (unless window-system
    ;; Create a graphical frame first.
    (let ((display (getenv "DISPLAY")))
      (when (seq-empty-p display)
        (user-error "No DISPLAY environment variable set"))
      (select-frame (make-frame-on-display display))))
  ;; Replace ‘C-c_C-v_command’ with the actual name of the command.
  (call-interactively 'TeX-view))

Then I run `M-x view-pdf-in-graphical-frame', but this will open a
second Emacs GUI instance instead of create a new GUI frame in the
original one. See the attachment fore more detailed info.

Regards,
HY
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province

Attachment: 2021-07-21_09-52.png
Description: PNG image


reply via email to

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