all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* use pdf-tools in Emacs.
@ 2023-04-25 14:50 Hongyi Zhao
  2023-04-25 15:09 ` Rudolf Schlatte
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-25 14:50 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

Hi here,

I try to use pdf-tools [1] in Emacs, but meet the following problem:

```shell
$ git log -1
commit 7ff6293a25baaae65651b3e1c54b61208279a7ef (HEAD -> master,
origin/master, origin/HEAD)
Author: Davide Masserut <dm@mssdvd.com>
Date:   Sun Apr 2 21:48:25 2023 +0200

    Ensure pixel-scroll-precision-mode deactivation

    Setting `pixel-scroll-precision-mode` to nil is not sufficient to disable
    the mode locally.

    Updates: #124

$ make -s
Using Emacs 30.0
make: cask: No such file or directory
make: *** [Makefile:49: .cask/30.0] Error 127
```

Then I run the steps here [2], but see the following chaos in pdf
buffer, as shown in the attached file.

How to fix it?

[1] https://github.com/vedang/pdf-tools
[2] https://www.emacswiki.org/emacs/init-pdf-tools.el
-- 
Assoc. Prof. Hongsheng 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 #2: image.png --]
[-- Type: image/png, Size: 422174 bytes --]

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

* Re: use pdf-tools in Emacs.
  2023-04-25 14:50 use pdf-tools in Emacs Hongyi Zhao
@ 2023-04-25 15:09 ` Rudolf Schlatte
  2023-04-26  2:01   ` Hongyi Zhao
  2023-05-18 14:51   ` use pdf-tools in Emacs Björn Bidar
  0 siblings, 2 replies; 40+ messages in thread
From: Rudolf Schlatte @ 2023-04-25 15:09 UTC (permalink / raw)
  To: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> I try to use pdf-tools [1] in Emacs, but meet the following problem:

Have you tried M-x pdf-tools-install RET ?  That command compiles the
helper program that pdf-tools needs to display pdfs.  Also see the
documentation of `pdf-loader-install`, which is another function
provided by pdf-tools that I think is meant to be added to the user's
init.el file.






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

* Re: use pdf-tools in Emacs.
  2023-04-25 15:09 ` Rudolf Schlatte
@ 2023-04-26  2:01   ` Hongyi Zhao
  2023-04-27 11:23     ` stefan-husmann
  2023-05-18 14:51   ` use pdf-tools in Emacs Björn Bidar
  1 sibling, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-26  2:01 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: help-gnu-emacs

On Tue, Apr 25, 2023 at 11:10 PM Rudolf Schlatte <rudi@constantly.at> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I try to use pdf-tools [1] in Emacs, but meet the following problem:
>
> Have you tried M-x pdf-tools-install RET ?

Yes. This way works.

> That command compiles the
> helper program that pdf-tools needs to display pdfs.  Also see the
> documentation of `pdf-loader-install`, which is another function
> provided by pdf-tools that I think is meant to be added to the user's
> init.el file.

In fact, I already have the following configuration in my init.el
file, but it doesn't seem to automatically compile and install
pdf-tools:

(use-package pdf-tools
  ;;https://github.com/jwiegley/use-package#magic-handlers
  :magic ("%PDF" . pdf-view-mode)
  :config
  (pdf-tools-install :no-query)
  ;; C-h o pdf-loader-install RET
  ;; This function acts as a replacement for ‘pdf-tools-install’ and
  ;; makes Emacs load and use PDF Tools as soon as a PDF file is
  ;; opened, but not sooner.
  ;;(pdf-loader-install)
  )

Regards,
Zhao



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

* Re: use pdf-tools in Emacs.
  2023-04-26  2:01   ` Hongyi Zhao
@ 2023-04-27 11:23     ` stefan-husmann
  2023-04-27 15:02       ` Tassilo Horn
  0 siblings, 1 reply; 40+ messages in thread
From: stefan-husmann @ 2023-04-27 11:23 UTC (permalink / raw)
  To: help-gnu-emacs


Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>
> In fact, I already have the following configuration in my init.el
> file, but it doesn't seem to automatically compile and install
> pdf-tools:
>
> (use-package pdf-tools
>   ;;https://github.com/jwiegley/use-package#magic-handlers
>   :magic ("%PDF" . pdf-view-mode)
>   :config
>   (pdf-tools-install :no-query)
>   ;; C-h o pdf-loader-install RET
>   ;; This function acts as a replacement for ‘pdf-tools-install’ and
>   ;; makes Emacs load and use PDF Tools as soon as a PDF file is
>   ;; opened, but not sooner.
>   ;;(pdf-loader-install)
>   )
>
> Regards,
> Zhao

Indeed this does notinstall anything. use-package is about loading, not installing.
Use package.el or straight.el (or any other package manager) for
installing.

Best Regards



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

* Re: use pdf-tools in Emacs.
  2023-04-27 11:23     ` stefan-husmann
@ 2023-04-27 15:02       ` Tassilo Horn
  2023-04-27 15:27         ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Tassilo Horn @ 2023-04-27 15:02 UTC (permalink / raw)
  To: stefan-husmann; +Cc: help-gnu-emacs

stefan-husmann@t-online.de writes:

>> In fact, I already have the following configuration in my init.el
>> file, but it doesn't seem to automatically compile and install
>> pdf-tools:
>>
>> (use-package pdf-tools
>>   ;;https://github.com/jwiegley/use-package#magic-handlers
>>   :magic ("%PDF" . pdf-view-mode)
>>   :config
>>   (pdf-tools-install :no-query)
>>   ;; C-h o pdf-loader-install RET
>>   ;; This function acts as a replacement for ‘pdf-tools-install’ and
>>   ;; makes Emacs load and use PDF Tools as soon as a PDF file is
>>   ;; opened, but not sooner.
>>   ;;(pdf-loader-install)
>>   )
>>
>
> Indeed this does notinstall anything. use-package is about loading,
> not installing.  Use package.el or straight.el (or any other package
> manager) for installing.

Well, you can add a :ensure t clause to the use-package recipe and it
will tell package.el to install the package.

Bye,
Tassilo



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

* Re: use pdf-tools in Emacs.
  2023-04-27 15:02       ` Tassilo Horn
@ 2023-04-27 15:27         ` Hongyi Zhao
  2023-04-27 15:53           ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-04-27 18:30           ` Tassilo Horn
  0 siblings, 2 replies; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-27 15:27 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

On Thu, Apr 27, 2023 at 11:03 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> stefan-husmann@t-online.de writes:
>
> >> In fact, I already have the following configuration in my init.el
> >> file, but it doesn't seem to automatically compile and install
> >> pdf-tools:
> >>
> >> (use-package pdf-tools
> >>   ;;https://github.com/jwiegley/use-package#magic-handlers
> >>   :magic ("%PDF" . pdf-view-mode)
> >>   :config
> >>   (pdf-tools-install :no-query)
> >>   ;; C-h o pdf-loader-install RET
> >>   ;; This function acts as a replacement for ‘pdf-tools-install’ and
> >>   ;; makes Emacs load and use PDF Tools as soon as a PDF file is
> >>   ;; opened, but not sooner.
> >>   ;;(pdf-loader-install)
> >>   )
> >>
> >
> > Indeed this does notinstall anything. use-package is about loading,
> > not installing.  Use package.el or straight.el (or any other package
> > manager) for installing.
>
> Well, you can add a :ensure t clause to the use-package recipe and it
> will tell package.el to install the package.

It seems that this is not true. In my testing, I've already set the
following option for straight, which ensures that every package
specified with `straight-use-package` is automatically installed
(ensured) during Emacs startup:

(setq straight-use-package-by-default t) ; straight's equivalent of
`use-package-always-ensure'.

But the problem discussed here still exists.

> Bye,
> Tassilo

Best,
Zhao



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

* Re: use pdf-tools in Emacs.
  2023-04-27 15:27         ` Hongyi Zhao
@ 2023-04-27 15:53           ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-04-27 23:54             ` Hongyi Zhao
  2023-04-27 18:30           ` Tassilo Horn
  1 sibling, 1 reply; 40+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-04-27 15:53 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: Tassilo Horn, stefan-husmann, help-gnu-emacs


Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> On Thu, Apr 27, 2023 at 11:03 PM Tassilo Horn <tsdh@gnu.org> wrote:

> It seems that this is not true. In my testing, I've already set the
> following option for straight, which ensures that every package
> specified with `straight-use-package` is automatically installed
> (ensured) during Emacs startup:
>
> (setq straight-use-package-by-default t) ; straight's equivalent of
> `use-package-always-ensure'.
>
> But the problem discussed here still exists.
>
>> Bye,
>> Tassilo
>
> Best,
> Zhao

Try adding `:demand t' in the `use-package' form.  It ensures that the
package is loaded right away (installing it if necessary), instead of
defering it later.

If that doesn't work, also try to move the install part from `:config'
to `:init'.  I used to have something about pdf-tools in my config, but
that has long gone.

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]



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

* Re: use pdf-tools in Emacs.
  2023-04-27 15:27         ` Hongyi Zhao
  2023-04-27 15:53           ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-04-27 18:30           ` Tassilo Horn
  2023-04-27 23:55             ` Hongyi Zhao
  2023-05-01 10:09             ` where to get "use-package"? [was: Re: use pdf-tools in Emacs] gebser
  1 sibling, 2 replies; 40+ messages in thread
From: Tassilo Horn @ 2023-04-27 18:30 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> >> (use-package pdf-tools
>> >>   ;;https://github.com/jwiegley/use-package#magic-handlers
>> >>   :magic ("%PDF" . pdf-view-mode)
>> >>   :config
>> >>   (pdf-tools-install :no-query)
>> >>   ;; C-h o pdf-loader-install RET
>> >>   ;; This function acts as a replacement for ‘pdf-tools-install’ and
>> >>   ;; makes Emacs load and use PDF Tools as soon as a PDF file is
>> >>   ;; opened, but not sooner.
>> >>   ;;(pdf-loader-install)
>> >>   )
>> >>
>> >
>> > Indeed this does notinstall anything. use-package is about loading,
>> > not installing.  Use package.el or straight.el (or any other package
>> > manager) for installing.
>>
>> Well, you can add a :ensure t clause to the use-package recipe and it
>> will tell package.el to install the package.
>
> It seems that this is not true.

I can assure you that I have

(use-package pdf-tools
  :ensure t
  :init
  (pdf-tools-install))

in my user-init-file, and that with this and just this, PDFs are opened
automatically using its `pdf-view-mode' (instead of `doc-view-mode').

When I do `M-x package-delete RET pdf-tools RET' and restart emacs, it
will automatically install it again which is the task of :ensure, see
(info "(use-package) Install package").  After installing the package
automatically, I'm also asked

  Need to (re)build the epdfinfo program, do it now ? (y or n) y

which is then built and the output shown in a *compilation* buffer.

Bye,
Tassilo



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

* Re: use pdf-tools in Emacs.
  2023-04-27 15:53           ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-04-27 23:54             ` Hongyi Zhao
  0 siblings, 0 replies; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-27 23:54 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Tassilo Horn, stefan-husmann, help-gnu-emacs

On Thu, Apr 27, 2023 at 11:57 PM Ruijie Yu <ruijie@netyu.xyz> wrote:
>
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > On Thu, Apr 27, 2023 at 11:03 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> > It seems that this is not true. In my testing, I've already set the
> > following option for straight, which ensures that every package
> > specified with `straight-use-package` is automatically installed
> > (ensured) during Emacs startup:
> >
> > (setq straight-use-package-by-default t) ; straight's equivalent of
> > `use-package-always-ensure'.
> >
> > But the problem discussed here still exists.
> >
> >> Bye,
> >> Tassilo
> >
> > Best,
> > Zhao
>
> Try adding `:demand t' in the `use-package' form.  It ensures that the
> package is loaded right away (installing it if necessary), instead of
> defering it later.

Here, `:ensure t` should be used, as explained below:

The line `:demand t` is an option that can be passed to the
"use-package" macro to ensure that the package is loaded immediately,
rather than being loaded lazily. This is useful when you want to make
sure a package is loaded before using any of its features.

The line `:ensure t` is another option that tells "use-package" to
install the package if it is not already installed. This is useful
when you want to automatically download and install packages from a
package repository like MELPA or ELPA.

> If that doesn't work, also try to move the install part from `:config'
> to `:init'.  I used to have something about pdf-tools in my config, but
> that has long gone.

This change is also necessary. Thank you for pointing this out.

> --
> Best,
>
>
> RY

Zhao

> [Please note that this mail might go to spam due to some
> misconfiguration in my mail server -- still investigating.]



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

* Re: use pdf-tools in Emacs.
  2023-04-27 18:30           ` Tassilo Horn
@ 2023-04-27 23:55             ` Hongyi Zhao
  2023-04-28  7:15               ` Tassilo Horn
  2023-05-01 10:09             ` where to get "use-package"? [was: Re: use pdf-tools in Emacs] gebser
  1 sibling, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-27 23:55 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

On Fri, Apr 28, 2023 at 2:37 AM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> >> >> (use-package pdf-tools
> >> >>   ;;https://github.com/jwiegley/use-package#magic-handlers
> >> >>   :magic ("%PDF" . pdf-view-mode)
> >> >>   :config
> >> >>   (pdf-tools-install :no-query)
> >> >>   ;; C-h o pdf-loader-install RET
> >> >>   ;; This function acts as a replacement for ‘pdf-tools-install’ and
> >> >>   ;; makes Emacs load and use PDF Tools as soon as a PDF file is
> >> >>   ;; opened, but not sooner.
> >> >>   ;;(pdf-loader-install)
> >> >>   )
> >> >>
> >> >
> >> > Indeed this does notinstall anything. use-package is about loading,
> >> > not installing.  Use package.el or straight.el (or any other package
> >> > manager) for installing.
> >>
> >> Well, you can add a :ensure t clause to the use-package recipe and it
> >> will tell package.el to install the package.
> >
> > It seems that this is not true.
>
> I can assure you that I have
>
> (use-package pdf-tools
>   :ensure t
>   :init
>   (pdf-tools-install))
>
> in my user-init-file, and that with this and just this, PDFs are opened
> automatically using its `pdf-view-mode' (instead of `doc-view-mode').
>
> When I do `M-x package-delete RET pdf-tools RET' and restart emacs, it
> will automatically install it again which is the task of :ensure, see
> (info "(use-package) Install package").  After installing the package
> automatically, I'm also asked
>
>   Need to (re)build the epdfinfo program, do it now ? (y or n) y
>
> which is then built and the output shown in a *compilation* buffer.

I confirm that the above configuration can solve the problem.

> Bye,
> Tassilo

Best,
Zhao



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

* Re: use pdf-tools in Emacs.
  2023-04-27 23:55             ` Hongyi Zhao
@ 2023-04-28  7:15               ` Tassilo Horn
  2023-04-28 10:48                 ` christian de larrinaga via Users list for the GNU Emacs text editor
  2023-04-28 12:43                 ` Hongyi Zhao
  0 siblings, 2 replies; 40+ messages in thread
From: Tassilo Horn @ 2023-04-28  7:15 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> (use-package pdf-tools
>>   :ensure t
>>   :init
>>   (pdf-tools-install))
>
> I confirm that the above configuration can solve the problem.

There you go.  So the issue was that you've put (pdf-tools-install) in
the :config rather than the :init clause.  That would have called it
when pdf-tools is loaded which never happened because pdf-tools-install
arranges that it will be used when finding a pdf file.

Bye,
Tassilo



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

* Re: use pdf-tools in Emacs.
  2023-04-28  7:15               ` Tassilo Horn
@ 2023-04-28 10:48                 ` christian de larrinaga via Users list for the GNU Emacs text editor
  2023-04-28 12:43                 ` Hongyi Zhao
  1 sibling, 0 replies; 40+ messages in thread
From: christian de larrinaga via Users list for the GNU Emacs text editor @ 2023-04-28 10:48 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Hongyi Zhao, stefan-husmann, help-gnu-emacs

thank you for this pointer. I had reconfigured emacs a while back and hadn't
got round to improving pdf performance to match the increasing number of
pdf docs I need to reference. I installed I thought pdf-tools
but it wasn't behaving. The :init did the trick

great list! Christian


Tassilo Horn <tsdh@gnu.org> writes:

> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
>>> (use-package pdf-tools
>>>   :ensure t
>>>   :init
>>>   (pdf-tools-install))
>>
>> I confirm that the above configuration can solve the problem.
>
> There you go.  So the issue was that you've put (pdf-tools-install) in
> the :config rather than the :init clause.  That would have called it
> when pdf-tools is loaded which never happened because pdf-tools-install
> arranges that it will be used when finding a pdf file.
>
> Bye,
> Tassilo


-- 
christian de larrinaga 
https://firsthand.net



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

* Re: use pdf-tools in Emacs.
  2023-04-28  7:15               ` Tassilo Horn
  2023-04-28 10:48                 ` christian de larrinaga via Users list for the GNU Emacs text editor
@ 2023-04-28 12:43                 ` Hongyi Zhao
  2023-04-28 13:11                   ` Tassilo Horn
  1 sibling, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-28 12:43 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

On Fri, Apr 28, 2023 at 3:18 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> >> (use-package pdf-tools
> >>   :ensure t
> >>   :init
> >>   (pdf-tools-install))
> >
> > I confirm that the above configuration can solve the problem.
>
> There you go.  So the issue was that you've put (pdf-tools-install) in
> the :config rather than the :init clause.  That would have called it
> when pdf-tools is loaded which never happened because pdf-tools-install
> arranges that it will be used when finding a pdf file.

But I wonder how to do the following things when using pdf-tools:

1. How to skip to a specific page by page number quickly?
2. How to show PDF in a separate window?

> Bye,
> Tassilo

Regards,
Zhao



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

* Re: use pdf-tools in Emacs.
  2023-04-28 12:43                 ` Hongyi Zhao
@ 2023-04-28 13:11                   ` Tassilo Horn
  2023-04-28 13:37                     ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Tassilo Horn @ 2023-04-28 13:11 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> But I wonder how to do the following things when using pdf-tools:
>
> 1. How to skip to a specific page by page number quickly?

M-x apropos-command RET pdf page RET quickly revealed pdf-view-goto-page
which is bound do M-g g by default.

> 2. How to show PDF in a separate window?

The pdf is shown in a buffer so the same commands apply as for any other
buffer.  E.g., you can split the current window with C-x 2 or C-x 3.  Or
if you mean you want to show the pdf in a separate frame, then C-x 5 2.

If you always want to spawn a new frame when finding a PDF document, I
guess you have to add a rule to display-buffer-alist.

Bye,
Tassilo



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

* Re: use pdf-tools in Emacs.
  2023-04-28 13:11                   ` Tassilo Horn
@ 2023-04-28 13:37                     ` Hongyi Zhao
  2023-04-28 13:58                       ` Tassilo Horn
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-28 13:37 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

On Fri, Apr 28, 2023 at 9:15 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > But I wonder how to do the following things when using pdf-tools:
> >
> > 1. How to skip to a specific page by page number quickly?
>
> M-x apropos-command RET pdf page RET quickly revealed pdf-view-goto-page
> which is bound do M-g g by default.

Yes. This does the trick. But the corresponding menu item description
is not so nice: "GoTo Line" is misleading in this case.

> > 2. How to show PDF in a separate window?
>
> The pdf is shown in a buffer so the same commands apply as for any other
> buffer.  E.g., you can split the current window with C-x 2 or C-x 3.  Or
> if you mean you want to show the pdf in a separate frame, then C-x 5 2.
>
> If you always want to spawn a new frame when finding a PDF document, I
> guess you have to add a rule to display-buffer-alist.

I want to use a new frame to show the PDF document with the LaTeX code
in another frame, and at the same time keeping the forward and reverse
searching work by skipping between these two frames backward and
forward accordingly.

> Bye,
> Tassilo

Regards,
Zhao



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

* Re: use pdf-tools in Emacs.
  2023-04-28 13:37                     ` Hongyi Zhao
@ 2023-04-28 13:58                       ` Tassilo Horn
  2023-04-29  2:17                         ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Tassilo Horn @ 2023-04-28 13:58 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> If you always want to spawn a new frame when finding a PDF document, I
>> guess you have to add a rule to display-buffer-alist.
>
> I want to use a new frame to show the PDF document with the LaTeX code
> in another frame, and at the same time keeping the forward and reverse
> searching work by skipping between these two frames backward and
> forward accordingly.

If the pdf is shown in a buffer of another frame makes no difference to
forward/inverse search as long its the same emacs instance.  This should
work for you:

(add-to-list 'display-buffer-alist
             '((derived-mode . pdf-view-mode)
               display-buffer-pop-up-frame))

It tells emacs to open buffers where pdf-view-mode is the major-mode to
be opened in a separate frame.

Bye,
Tassilo



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

* Re: use pdf-tools in Emacs.
  2023-04-28 13:58                       ` Tassilo Horn
@ 2023-04-29  2:17                         ` Hongyi Zhao
  2023-04-29  8:30                           ` How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.) Tassilo Horn
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-29  2:17 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1443 bytes --]

On Fri, Apr 28, 2023 at 10:00 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> >> If you always want to spawn a new frame when finding a PDF document, I
> >> guess you have to add a rule to display-buffer-alist.
> >
> > I want to use a new frame to show the PDF document with the LaTeX code
> > in another frame, and at the same time keeping the forward and reverse
> > searching work by skipping between these two frames backward and
> > forward accordingly.
>
> If the pdf is shown in a buffer of another frame makes no difference to
> forward/inverse search as long its the same emacs instance.  This should
> work for you:
>
> (add-to-list 'display-buffer-alist
>              '((derived-mode . pdf-view-mode)
>                display-buffer-pop-up-frame))
>
> It tells emacs to open buffers where pdf-view-mode is the major-mode to
> be opened in a separate frame.

I tried the following configuration:

(use-package pdf-tools
  :ensure t
  :init
  (pdf-tools-install)
  :config
  (add-to-list 'display-buffer-alist
               '((derived-mode . pdf-view-mode)
         display-buffer-pop-up-frame))

  )

See the attached screenshot for the effect. In short, frame 1 will
open frame 2, and 2 will open 3. But I just want to open frames 1 and
2 and automatically switch between them for forward and backward
search.

> Bye,
> Tassilo

Best,
Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 454366 bytes --]

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

* How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-29  2:17                         ` Hongyi Zhao
@ 2023-04-29  8:30                           ` Tassilo Horn
  2023-04-29  9:25                             ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Tassilo Horn @ 2023-04-29  8:30 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> I tried the following configuration:
>
> (use-package pdf-tools
>   :ensure t
>   :init
>   (pdf-tools-install)
>   :config
>   (add-to-list 'display-buffer-alist
>                '((derived-mode . pdf-view-mode)
>          display-buffer-pop-up-frame))
>
>   )
>
> See the attached screenshot for the effect. In short, frame 1 will
> open frame 2, and 2 will open 3. But I just want to open frames 1 and
> 2 and automatically switch between them for forward and backward
> search.

Ok, if I understand correctly, you basically want one "normal" emacs
frame and one for viewing pdfs and you want that this separate frame is
reused.  The below code does the job but probably there's a better
solution for the "the dedicated frame already exists" part which I
didn't find during my testing...

My trick is to add a parameter th/pdf-frame to the decicated frame and
search for that.

--8<---------------cut here---------------start------------->8---
(defun th/display-buffer-in-my-pdf-frame (buffer alist)
  (if-let ((frame (car (seq-filter
                        (lambda (f) (frame-parameter f 'th/pdf-frame))
                        (frame-list)))))
      ;; TODO: I guess there's a better way for this case, i.e., something with
      ;; invoking display-buffer with reusable-frames parameter or something.
      (progn
        (select-frame frame)
        (switch-to-buffer buffer))
    (display-buffer-pop-up-frame
     buffer (cons
             '(pop-up-frame-parameters (th/pdf-frame . t))
             alist))))

(add-to-list 'display-buffer-alist
             `((derived-mode . pdf-view-mode)
               th/display-buffer-in-my-pdf-frame))
--8<---------------cut here---------------end--------------->8---

I've changed the subject because this has nothing to do with pdf-tools
anymore but could be applied to any kind of buffers, e.g., others might
want a separate dericated frame for dired or gnus or whatever.  If you
are lucky, the new subject catches the attention of Martin.

Bye,
Tassilo



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-29  8:30                           ` How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.) Tassilo Horn
@ 2023-04-29  9:25                             ` Hongyi Zhao
  2023-04-29  9:35                               ` Tassilo Horn
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-29  9:25 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 3929 bytes --]

On Sat, Apr 29, 2023 at 4:38 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I tried the following configuration:
> >
> > (use-package pdf-tools
> >   :ensure t
> >   :init
> >   (pdf-tools-install)
> >   :config
> >   (add-to-list 'display-buffer-alist
> >                '((derived-mode . pdf-view-mode)
> >          display-buffer-pop-up-frame))
> >
> >   )
> >
> > See the attached screenshot for the effect. In short, frame 1 will
> > open frame 2, and 2 will open 3. But I just want to open frames 1 and
> > 2 and automatically switch between them for forward and backward
> > search.
>
> Ok, if I understand correctly, you basically want one "normal" emacs
> frame and one for viewing pdfs and you want that this separate frame is
> reused.

Yes.

> The below code does the job but probably there's a better
> solution for the "the dedicated frame already exists" part which I
> didn't find during my testing...
>
> My trick is to add a parameter th/pdf-frame to the decicated frame and
> search for that.
>
> --8<---------------cut here---------------start------------->8---
> (defun th/display-buffer-in-my-pdf-frame (buffer alist)
>   (if-let ((frame (car (seq-filter
>                         (lambda (f) (frame-parameter f 'th/pdf-frame))
>                         (frame-list)))))
>       ;; TODO: I guess there's a better way for this case, i.e., something with
>       ;; invoking display-buffer with reusable-frames parameter or something.
>       (progn
>         (select-frame frame)
>         (switch-to-buffer buffer))
>     (display-buffer-pop-up-frame
>      buffer (cons
>              '(pop-up-frame-parameters (th/pdf-frame . t))
>              alist))))
>
> (add-to-list 'display-buffer-alist
>              `((derived-mode . pdf-view-mode)
>                th/display-buffer-in-my-pdf-frame))
> --8<---------------cut here---------------end--------------->8---

I tried with the following configuration, but it still creates 3
frames, as shown in the attchment:

(use-package pdf-tools
  :ensure t
  :init
  (pdf-tools-install)
  :config
  (defun th/display-buffer-in-my-pdf-frame (buffer alist)
    (if-let ((frame (car (seq-filter
                          (lambda (f) (frame-parameter f 'th/pdf-frame))
                          (frame-list)))))
    ;; TODO: I guess there's a better way for this case, i.e., something with
    ;; invoking display-buffer with reusable-frames parameter or something.
    (progn
          (select-frame frame)
          (switch-to-buffer buffer))
      (display-buffer-pop-up-frame
       buffer (cons
               '(pop-up-frame-parameters (th/pdf-frame . t))
               alist))))

  (add-to-list 'display-buffer-alist
               `((derived-mode . pdf-view-mode)
         th/display-buffer-in-my-pdf-frame))


  )

> I've changed the subject because this has nothing to do with pdf-tools
> anymore but could be applied to any kind of buffers, e.g., others might
> want a separate dericated frame for dired or gnus or whatever.  If you
> are lucky, the new subject catches the attention of Martin.

Which Martin? I checked as follows and there are many:

werner@X10DAi:~/Public/repo/git.savannah.gnu.org/git/emacs.git$ git
log --format='%an <%ae>' | grep -i martin | awk '!a[$0]++'
Martin Rudalics <rudalics@gmx.at>
martin rudalics <rudalics@gmx.at>
Martin Jerabek <om@mailservice.ms>
Martin Carlson <spearalot@gmail.com>
Martin Joerg <martin.joerg@gmail.com>
Kapuze Martin <m.s.p@posteo.de>
Martin Kletzander <nert.pinx@gmail.com>
Ricardo Martins <ricardo@scarybox.net>
Ricardo Martins <1706+meqif@users.noreply.github.com>
Martin Jesper Low Madsen <martin@martinjlowm.dk>
Agustin Martin Domingo <agustin6martin@gmail.com>
“Martin <“rudalics@gmx.atâ€

> Bye,
> Tassilo

Regards,
Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 466349 bytes --]

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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-29  9:25                             ` Hongyi Zhao
@ 2023-04-29  9:35                               ` Tassilo Horn
  2023-04-29 10:08                                 ` Hongyi Zhao
  2023-04-30  1:05                                 ` Hongyi Zhao
  0 siblings, 2 replies; 40+ messages in thread
From: Tassilo Horn @ 2023-04-29  9:35 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> I tried with the following configuration, but it still creates 3
> frames, as shown in the attchment:

There are only two frames in the screenshot, what you have numbered are
emacs windows.  But yes, the 2nd pdf buffer should have been displayed
in the other frame where a pdf is already displayed.  You might have to
edebug the function and check M-: (frame-parameter nil 'th/pdf-frame)
RET in both frames.  Only the one spawned by the first "show this pdf
buffer" should have this parameter set.

BTW, I wouldn't put the function and display-buffer-alist setting in the
:config section of (use-package pdf-tools ...) but top-level.  It might
have been loaded too late.  Maybe try that and restart emacs.

> Which Martin? I checked as follows and there are many:
>
> werner@X10DAi:~/Public/repo/git.savannah.gnu.org/git/emacs.git$ git
> log --format='%an <%ae>' | grep -i martin | awk '!a[$0]++'
> Martin Rudalics <rudalics@gmx.at>
> martin rudalics <rudalics@gmx.at>

These two Martins. :-)

Bye,
Tassilo



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-29  9:35                               ` Tassilo Horn
@ 2023-04-29 10:08                                 ` Hongyi Zhao
  2023-04-29 19:37                                   ` Tassilo Horn
  2023-04-30  1:05                                 ` Hongyi Zhao
  1 sibling, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-29 10:08 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2240 bytes --]

On Sat, Apr 29, 2023 at 5:41 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I tried with the following configuration, but it still creates 3
> > frames, as shown in the attchment:
>
> There are only two frames in the screenshot, what you have numbered are
> emacs windows.  But yes, the 2nd pdf buffer should have been displayed
> in the other frame where a pdf is already displayed.  You might have to
> edebug the function and check M-: (frame-parameter nil 'th/pdf-frame)
> RET in both frames.  Only the one spawned by the first "show this pdf
> buffer" should have this parameter set.
>
> BTW, I wouldn't put the function and display-buffer-alist setting in the
> :config section of (use-package pdf-tools ...) but top-level.  It might
> have been loaded too late.  Maybe try that and restart emacs.

Tried as follows:

(use-package pdf-tools
  :ensure t
  :init
  (pdf-tools-install)
  (defun th/display-buffer-in-my-pdf-frame (buffer alist)
    (if-let ((frame (car (seq-filter
                          (lambda (f) (frame-parameter f 'th/pdf-frame))
                          (frame-list)))))
    ;; TODO: I guess there's a better way for this case, i.e., something with
    ;; invoking display-buffer with reusable-frames parameter or something.
    (progn
          (select-frame frame)
          (switch-to-buffer buffer))
      (display-buffer-pop-up-frame
       buffer (cons
               '(pop-up-frame-parameters (th/pdf-frame . t))
               alist))))

  (add-to-list 'display-buffer-alist
               `((derived-mode . pdf-view-mode)
         th/display-buffer-in-my-pdf-frame))

)

And this time the 3rd circle numbered window will be used to display
the LaTeX code and PDF alternately when I do the forward and backward
searching. This is not the result we hope to see.

> > Which Martin? I checked as follows and there are many:
> >
> > werner@X10DAi:~/Public/repo/git.savannah.gnu.org/git/emacs.git$ git
> > log --format='%an <%ae>' | grep -i martin | awk '!a[$0]++'
> > Martin Rudalics <rudalics@gmx.at>
> > martin rudalics <rudalics@gmx.at>
>
> These two Martins. :-)
>
> Bye,
> Tassilo

Best,
Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 470579 bytes --]

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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-29 10:08                                 ` Hongyi Zhao
@ 2023-04-29 19:37                                   ` Tassilo Horn
  2023-04-30  0:42                                     ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Tassilo Horn @ 2023-04-29 19:37 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> And this time the 3rd circle numbered window will be used to display
> the LaTeX code and PDF alternately when I do the forward and backward
> searching. This is not the result we hope to see.

Here's a slightly improved version:

(defun th/display-buffer-in-my-pdf-frame (buffer alist)
  (if-let ((frame (car (seq-filter
                        (lambda (f) (frame-parameter f 'th/pdf-frame))
                        (frame-list)))))
      (display-buffer-use-some-frame
       buffer `((frame-predicate . ,(lambda (f)
                                      (frame-parameter f 'th/pdf-frame)))))
    (display-buffer-pop-up-frame
     buffer (cons
             '(pop-up-frame-parameters (th/pdf-frame . t))
             alist))))

;; PDFs in a dedicated pdf frame.
(add-to-list 'display-buffer-alist
             `((derived-mode . pdf-view-mode)
               th/display-buffer-in-my-pdf-frame))

The problem remains that when double-clicking in the pdf-view-mode
buffer to jump to the corresponding position in the tex file, the tex
file buffer appears in a new window of the pdf frame.  The issue is that
pdf-tools uses pop-to-buffer here:

(defun pdf-sync-backward-search (x y)
  "Go to the source corresponding to image coordinates X, Y.

Try to find the exact position, if
`pdf-sync-backward-use-heuristic' is non-nil."
  (cl-destructuring-bind (source finder)
      (pdf-sync-backward-correlate x y)
    (pop-to-buffer (or (find-buffer-visiting source)
                       (find-file-noselect source))
                   pdf-sync-backward-display-action)
    (push-mark)
    (funcall finder)
    (run-hooks 'pdf-sync-backward-hook)))

But there you go!  You can define a pdf-sync-backward-display-action to
make it work.

(setq pdf-sync-backward-display-action
      '(display-buffer-reuse-window (reusable-frames . t)))

You can read up how that all works in (info "(elisp) Displaying
Buffers").

Bye,
Tassilo



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-29 19:37                                   ` Tassilo Horn
@ 2023-04-30  0:42                                     ` Hongyi Zhao
  2023-04-30  0:52                                       ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-30  0:42 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 3550 bytes --]

On Sun, Apr 30, 2023 at 4:08 AM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > And this time the 3rd circle numbered window will be used to display
> > the LaTeX code and PDF alternately when I do the forward and backward
> > searching. This is not the result we hope to see.
>
> Here's a slightly improved version:
>
> (defun th/display-buffer-in-my-pdf-frame (buffer alist)
>   (if-let ((frame (car (seq-filter
>                         (lambda (f) (frame-parameter f 'th/pdf-frame))
>                         (frame-list)))))
>       (display-buffer-use-some-frame
>        buffer `((frame-predicate . ,(lambda (f)
>                                       (frame-parameter f 'th/pdf-frame)))))
>     (display-buffer-pop-up-frame
>      buffer (cons
>              '(pop-up-frame-parameters (th/pdf-frame . t))
>              alist))))
>
> ;; PDFs in a dedicated pdf frame.
> (add-to-list 'display-buffer-alist
>              `((derived-mode . pdf-view-mode)
>                th/display-buffer-in-my-pdf-frame))
>
> The problem remains that when double-clicking in the pdf-view-mode
> buffer to jump to the corresponding position in the tex file, the tex
> file buffer appears in a new window of the pdf frame.  The issue is that
> pdf-tools uses pop-to-buffer here:
>
> (defun pdf-sync-backward-search (x y)
>   "Go to the source corresponding to image coordinates X, Y.
>
> Try to find the exact position, if
> `pdf-sync-backward-use-heuristic' is non-nil."
>   (cl-destructuring-bind (source finder)
>       (pdf-sync-backward-correlate x y)
>     (pop-to-buffer (or (find-buffer-visiting source)
>                        (find-file-noselect source))
>                    pdf-sync-backward-display-action)
>     (push-mark)
>     (funcall finder)
>     (run-hooks 'pdf-sync-backward-hook)))
>
> But there you go!  You can define a pdf-sync-backward-display-action to
> make it work.
>
> (setq pdf-sync-backward-display-action
>       '(display-buffer-reuse-window (reusable-frames . t)))

Thank you for your wonderful tricks/tips/codes once more. This time,
it can work perfectly according to the intention discussed here using
the following configuration:

(use-package pdf-tools
  :ensure t
  :init
  (pdf-tools-install)

  (setq pdf-sync-backward-display-action
    '(display-buffer-reuse-window (reusable-frames . t)))
  (defun th/display-buffer-in-my-pdf-frame (buffer alist)
    (if-let ((frame (car (seq-filter
                          (lambda (f) (frame-parameter f 'th/pdf-frame))
                          (frame-list)))))
    (display-buffer-use-some-frame
     buffer `((frame-predicate . ,(lambda (f)
                    (frame-parameter f 'th/pdf-frame)))))
      (display-buffer-pop-up-frame
       buffer (cons
               '(pop-up-frame-parameters (th/pdf-frame . t))
               alist))))

  ;; PDFs in a dedicated pdf frame.
  (add-to-list 'display-buffer-alist
               `((derived-mode . pdf-view-mode)
         th/display-buffer-in-my-pdf-frame))
  )

> You can read up how that all works in (info "(elisp) Displaying
> Buffers").

Thank you for hints. But the Elisp code you mentioned requires a
significant level of proficiency in Elisp programming. Even if I
understand the underlying mechanics of the problem being discussed, it
may still be challenging to write the corresponding code
implementation without a strong foundation in Elisp.

> Bye,
> Tassilo

Best,
Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 389862 bytes --]

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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-30  0:42                                     ` Hongyi Zhao
@ 2023-04-30  0:52                                       ` Hongyi Zhao
  2023-04-30 18:59                                         ` Tassilo Horn
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-30  0:52 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 4021 bytes --]

On Sun, Apr 30, 2023 at 8:42 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Sun, Apr 30, 2023 at 4:08 AM Tassilo Horn <tsdh@gnu.org> wrote:
> >
> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >
> > > And this time the 3rd circle numbered window will be used to display
> > > the LaTeX code and PDF alternately when I do the forward and backward
> > > searching. This is not the result we hope to see.
> >
> > Here's a slightly improved version:
> >
> > (defun th/display-buffer-in-my-pdf-frame (buffer alist)
> >   (if-let ((frame (car (seq-filter
> >                         (lambda (f) (frame-parameter f 'th/pdf-frame))
> >                         (frame-list)))))
> >       (display-buffer-use-some-frame
> >        buffer `((frame-predicate . ,(lambda (f)
> >                                       (frame-parameter f 'th/pdf-frame)))))
> >     (display-buffer-pop-up-frame
> >      buffer (cons
> >              '(pop-up-frame-parameters (th/pdf-frame . t))
> >              alist))))
> >
> > ;; PDFs in a dedicated pdf frame.
> > (add-to-list 'display-buffer-alist
> >              `((derived-mode . pdf-view-mode)
> >                th/display-buffer-in-my-pdf-frame))
> >
> > The problem remains that when double-clicking in the pdf-view-mode
> > buffer to jump to the corresponding position in the tex file, the tex
> > file buffer appears in a new window of the pdf frame.  The issue is that
> > pdf-tools uses pop-to-buffer here:
> >
> > (defun pdf-sync-backward-search (x y)
> >   "Go to the source corresponding to image coordinates X, Y.
> >
> > Try to find the exact position, if
> > `pdf-sync-backward-use-heuristic' is non-nil."
> >   (cl-destructuring-bind (source finder)
> >       (pdf-sync-backward-correlate x y)
> >     (pop-to-buffer (or (find-buffer-visiting source)
> >                        (find-file-noselect source))
> >                    pdf-sync-backward-display-action)
> >     (push-mark)
> >     (funcall finder)
> >     (run-hooks 'pdf-sync-backward-hook)))
> >
> > But there you go!  You can define a pdf-sync-backward-display-action to
> > make it work.
> >
> > (setq pdf-sync-backward-display-action
> >       '(display-buffer-reuse-window (reusable-frames . t)))
>
> Thank you for your wonderful tricks/tips/codes once more. This time,
> it can work perfectly according to the intention discussed here using
> the following configuration:

But I found a further problem: If I first opened the PDF file, then it
still won't be able to create a new frame dedicated to buffers of
LaTeX code, as shown in the attached screenshot.

Regards,
Zhao

> (use-package pdf-tools
>   :ensure t
>   :init
>   (pdf-tools-install)
>
>   (setq pdf-sync-backward-display-action
>     '(display-buffer-reuse-window (reusable-frames . t)))
>   (defun th/display-buffer-in-my-pdf-frame (buffer alist)
>     (if-let ((frame (car (seq-filter
>                           (lambda (f) (frame-parameter f 'th/pdf-frame))
>                           (frame-list)))))
>     (display-buffer-use-some-frame
>      buffer `((frame-predicate . ,(lambda (f)
>                     (frame-parameter f 'th/pdf-frame)))))
>       (display-buffer-pop-up-frame
>        buffer (cons
>                '(pop-up-frame-parameters (th/pdf-frame . t))
>                alist))))
>
>   ;; PDFs in a dedicated pdf frame.
>   (add-to-list 'display-buffer-alist
>                `((derived-mode . pdf-view-mode)
>          th/display-buffer-in-my-pdf-frame))
>   )
>
> > You can read up how that all works in (info "(elisp) Displaying
> > Buffers").
>
> Thank you for hints. But the Elisp code you mentioned requires a
> significant level of proficiency in Elisp programming. Even if I
> understand the underlying mechanics of the problem being discussed, it
> may still be challenging to write the corresponding code
> implementation without a strong foundation in Elisp.
>
> > Bye,
> > Tassilo
>
> Best,
> Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 215461 bytes --]

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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-29  9:35                               ` Tassilo Horn
  2023-04-29 10:08                                 ` Hongyi Zhao
@ 2023-04-30  1:05                                 ` Hongyi Zhao
  1 sibling, 0 replies; 40+ messages in thread
From: Hongyi Zhao @ 2023-04-30  1:05 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

On Sat, Apr 29, 2023 at 5:41 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I tried with the following configuration, but it still creates 3
> > frames, as shown in the attchment:
>
> There are only two frames in the screenshot, what you have numbered are
> emacs windows.  But yes, the 2nd pdf buffer should have been displayed
> in the other frame where a pdf is already displayed.  You might have to
> edebug the function and check M-: (frame-parameter nil 'th/pdf-frame)
> RET in both frames.  Only the one spawned by the first "show this pdf
> buffer" should have this parameter set.
>
> BTW, I wouldn't put the function and display-buffer-alist setting in the
> :config section of (use-package pdf-tools ...) but top-level.  It might
> have been loaded too late.  Maybe try that and restart emacs.
>
> > Which Martin? I checked as follows and there are many:
> >
> > werner@X10DAi:~/Public/repo/git.savannah.gnu.org/git/emacs.git$ git
> > log --format='%an <%ae>' | grep -i martin | awk '!a[$0]++'
> > Martin Rudalics <rudalics@gmx.at>
> > martin rudalics <rudalics@gmx.at>
>
> These two Martins. :-)

Nice. OpenAI's GPT-4 gives me the following explanations:

You:
martin rudalics <rudalics@gmx.at>

emacs

Chatbot:
Martin Rudalics is an Emacs developer and contributor. He is known for
his work on Emacs Lisp and his contributions to various Emacs
packages, including Dired, Calendar, and Eshell. He has been involved
in the development of Emacs for over two decades and has contributed
numerous patches and improvements to the codebase. Martin is also a
member of the Emacs development team and has been a key figure in the
Emacs community for many years.

> Bye,
> Tassilo

Best,
Zhao



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-30  0:52                                       ` Hongyi Zhao
@ 2023-04-30 18:59                                         ` Tassilo Horn
  2023-05-01  0:28                                           ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Tassilo Horn @ 2023-04-30 18:59 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> But I found a further problem: If I first opened the PDF file, then it
> still won't be able to create a new frame dedicated to buffers of
> LaTeX code, as shown in the attached screenshot.

True.  I didn't know this was a requirement.  Basically you could just
copy&paste&adapt this code to dedicate a special frame to anything you'd
like.  But that's left as an excercise to the reader. ;-)

Bye,
Tassilo



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-04-30 18:59                                         ` Tassilo Horn
@ 2023-05-01  0:28                                           ` Hongyi Zhao
  2023-05-01  6:15                                             ` Tassilo Horn
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-05-01  0:28 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

On Mon, May 1, 2023 at 3:02 AM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > But I found a further problem: If I first opened the PDF file, then it
> > still won't be able to create a new frame dedicated to buffers of
> > LaTeX code, as shown in the attached screenshot.
>
> True.  I didn't know this was a requirement.  Basically you could just
> copy&paste&adapt this code to dedicate a special frame to anything you'd
> like.  But that's left as an excercise to the reader. ;-)

I tried as follows, but still can't achieve the goal:

(use-package pdf-tools
  :ensure t
  :init
  (pdf-tools-install)

  (setq pdf-sync-backward-display-action
    '(display-buffer-reuse-window (reusable-frames . t)))

  (defun th/display-buffer-in-my-pdf-frame (buffer alist)
    (if-let ((frame (car (seq-filter
                          (lambda (f) (frame-parameter f 'th/pdf-frame))
                          (frame-list)))))
    (display-buffer-use-some-frame
     buffer `((frame-predicate . ,(lambda (f)
                    (frame-parameter f 'th/pdf-frame)))))
      (display-buffer-pop-up-frame
       buffer (cons
               '(pop-up-frame-parameters (th/pdf-frame . t))
               alist))))

  (defun th/display-buffer-in-my-tex-frame (buffer alist)
    (if-let ((frame (car (seq-filter
                          (lambda (f) (frame-parameter f 'th/tex-frame))
                          (frame-list)))))
    (display-buffer-use-some-frame
     buffer `((frame-predicate . ,(lambda (f)
                    (frame-parameter f 'th/tex-frame)))))
      (display-buffer-pop-up-frame
       buffer (cons
               '(pop-up-frame-parameters (th/tex-frame . t))
               alist))))

  (add-to-list 'display-buffer-alist
               `((derived-mode . pdf-view-mode)
         th/display-buffer-in-my-pdf-frame))
  (add-to-list 'display-buffer-alist
               `((derived-mode . LaTeX-mode)
         th/display-buffer-in-my-tex-frame))
  )


> Bye,
> Tassilo

Best,
Zhao



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-01  0:28                                           ` Hongyi Zhao
@ 2023-05-01  6:15                                             ` Tassilo Horn
  2023-05-01  7:21                                               ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Tassilo Horn @ 2023-05-01  6:15 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> > But I found a further problem: If I first opened the PDF file, then
>> > it still won't be able to create a new frame dedicated to buffers
>> > of LaTeX code, as shown in the attached screenshot.
>>
>> True.  I didn't know this was a requirement.  Basically you could just
>> copy&paste&adapt this code to dedicate a special frame to anything you'd
>> like.  But that's left as an excercise to the reader. ;-)
>
> I tried as follows, but still can't achieve the goal:

Hm, I think a problem might be that when you open the PDF first (and
this actually starts emacs itself), the th/pdf-frame frame parameter
might not be assigned to that frame.  Please verify using M-:
(frame-parameter nil 'th/pdf-frame) RET in that frame.  If it doesn't
return t, then that's the case.  Then you'd somehow need to ensure that
this initial frame gets the parameter, e.g., by adding a function like
this to some reasonable hook:

(defun th/pdf-frame-ensure ()
  (when (and (derived-mode-p 'pdf-view-mode)
             (zerop (length (seq-filter
                             (lambda (f)
                               (frame-parameter f 'th/pdf-frame))
                             (frame-list)))))
    (set-frame-parameter nil 'th/pdf-frame t)))

Unfortunately, I don't know which hook.  pdf-view-mode-hook might run
too early, i.e., the buffer might be set up before displaying it which
eventually will create the frame.  So maybe after-make-frame-functions
is better (but then you'd need to use the frame given as parameter).  I
guess you'll need to do some testing here.

BTW, I wonder if you really want to have a dedicated tex frame or just a
dedicated pdf frame + one editing/normal frame.  If it's actually the
latter, I wouldn't introduce another th/tex-frame parameter but simply
test for (null (frame-parameter frame 'th/pdf-frame)) everywhere.

Bye,
Tassilo



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-01  6:15                                             ` Tassilo Horn
@ 2023-05-01  7:21                                               ` Hongyi Zhao
  2023-05-02 18:38                                                 ` Tassilo Horn
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-05-01  7:21 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

On Mon, May 1, 2023 at 2:33 PM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> >> > But I found a further problem: If I first opened the PDF file, then
> >> > it still won't be able to create a new frame dedicated to buffers
> >> > of LaTeX code, as shown in the attached screenshot.
> >>
> >> True.  I didn't know this was a requirement.  Basically you could just
> >> copy&paste&adapt this code to dedicate a special frame to anything you'd
> >> like.  But that's left as an excercise to the reader. ;-)
> >
> > I tried as follows, but still can't achieve the goal:
>
> Hm, I think a problem might be that when you open the PDF first (and
> this actually starts emacs itself), the th/pdf-frame frame parameter
> might not be assigned to that frame.  Please verify using M-:
> (frame-parameter nil 'th/pdf-frame) RET in that frame.  If it doesn't
> return t, then that's the case.  Then you'd somehow need to ensure that
> this initial frame gets the parameter, e.g., by adding a function like
> this to some reasonable hook:
>
> (defun th/pdf-frame-ensure ()
>   (when (and (derived-mode-p 'pdf-view-mode)
>              (zerop (length (seq-filter
>                              (lambda (f)
>                                (frame-parameter f 'th/pdf-frame))
>                              (frame-list)))))
>     (set-frame-parameter nil 'th/pdf-frame t)))
>
> Unfortunately, I don't know which hook.  pdf-view-mode-hook might run
> too early, i.e., the buffer might be set up before displaying it which
> eventually will create the frame.  So maybe after-make-frame-functions
> is better (but then you'd need to use the frame given as parameter).  I
> guess you'll need to do some testing here.
>
> BTW, I wonder if you really want to have a dedicated tex frame or just a
> dedicated pdf frame + one editing/normal frame.  If it's actually the
> latter, I wouldn't introduce another th/tex-frame parameter but simply
> test for (null (frame-parameter frame 'th/pdf-frame)) everywhere.

Please go ahead with the latter and let me test it.

> Bye,
> Tassilo

Best,
Zhao



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

* where to get "use-package"? [was: Re: use pdf-tools in Emacs]
  2023-04-27 18:30           ` Tassilo Horn
  2023-04-27 23:55             ` Hongyi Zhao
@ 2023-05-01 10:09             ` gebser
  2023-05-01 10:30               ` Philip Kaludercic
  1 sibling, 1 reply; 40+ messages in thread
From: gebser @ 2023-05-01 10:09 UTC (permalink / raw)
  To: help-gnu-emacs

On 4/27/23 2:30 PM, Tassilo Horn wrote:
> (use-package pdf-tools
>    :ensure t
>    :init
>    (pdf-tools-install))

Executing the above yields error:

Debugger entered--Lisp error: (void-function use-package)
   (use-package pdf-tools :ensure t :init (pdf-tools-install))
   elisp--eval-last-sexp(nil)
   eval-last-sexp(nil)
   funcall-interactively(eval-last-sexp nil)
   command-execute(eval-last-sexp)

Then "C-h f use-package RET" shows it absent.  So installed 
"emacs-devel" but that didn't provide "use-package".  So what needs to 
be installed to acquire "use-package"?

Thanks much.




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

* Re: where to get "use-package"? [was: Re: use pdf-tools in Emacs]
  2023-05-01 10:09             ` where to get "use-package"? [was: Re: use pdf-tools in Emacs] gebser
@ 2023-05-01 10:30               ` Philip Kaludercic
  2023-05-02  0:46                 ` gebser
  0 siblings, 1 reply; 40+ messages in thread
From: Philip Kaludercic @ 2023-05-01 10:30 UTC (permalink / raw)
  To: gebser; +Cc: help-gnu-emacs

"gebser@mousecar.com" <gebser@mousecar.com> writes:

> On 4/27/23 2:30 PM, Tassilo Horn wrote:
>> (use-package pdf-tools
>>    :ensure t
>>    :init
>>    (pdf-tools-install))
>
> Executing the above yields error:
>
> Debugger entered--Lisp error: (void-function use-package)
>   (use-package pdf-tools :ensure t :init (pdf-tools-install))
>   elisp--eval-last-sexp(nil)
>   eval-last-sexp(nil)
>   funcall-interactively(eval-last-sexp nil)
>   command-execute(eval-last-sexp)
>
> Then "C-h f use-package RET" shows it absent.  So installed
> "emacs-devel" but that didn't provide "use-package".  So what needs to
> be installed to acquire "use-package"?

The package is available on ELPA, so you need a M-x package-install RET
use-package RET before evaluating the expression.  From Emacs 29
onwards, it will be bundled in the default Emacs release.

> Thanks much.



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

* Re: where to get "use-package"? [was: Re: use pdf-tools in Emacs]
  2023-05-01 10:30               ` Philip Kaludercic
@ 2023-05-02  0:46                 ` gebser
  0 siblings, 0 replies; 40+ messages in thread
From: gebser @ 2023-05-02  0:46 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: help-gnu-emacs

On 5/1/23 6:30 AM, Philip Kaludercic wrote:
> "gebser@mousecar.com" <gebser@mousecar.com> writes:
> 
>> On 4/27/23 2:30 PM, Tassilo Horn wrote:
>>> (use-package pdf-tools
>>>     :ensure t
>>>     :init
>>>     (pdf-tools-install))
>>
>> Executing the above yields error:
>>
>> Debugger entered--Lisp error: (void-function use-package)
>>    (use-package pdf-tools :ensure t :init (pdf-tools-install))
>>    elisp--eval-last-sexp(nil)
>>    eval-last-sexp(nil)
>>    funcall-interactively(eval-last-sexp nil)
>>    command-execute(eval-last-sexp)
>>
>> Then "C-h f use-package RET" shows it absent.  So installed
>> "emacs-devel" but that didn't provide "use-package".  So what needs to
>> be installed to acquire "use-package"?
> 
> The package is available on ELPA, so you need a M-x package-install RET
> use-package RET before evaluating the expression.  From Emacs 29
> onwards, it will be bundled in the default Emacs release.
> 
>> Thanks much.

Wow!  Yeah, that installed quite a few packages.  No error now.  Thanks 
much!




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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-01  7:21                                               ` Hongyi Zhao
@ 2023-05-02 18:38                                                 ` Tassilo Horn
  2023-05-03  1:45                                                   ` Hongyi Zhao
  2023-05-09  0:03                                                   ` Hongyi Zhao
  0 siblings, 2 replies; 40+ messages in thread
From: Tassilo Horn @ 2023-05-02 18:38 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

Hi Zhao,

>> BTW, I wonder if you really want to have a dedicated tex frame or
>> just a dedicated pdf frame + one editing/normal frame.  If it's
>> actually the latter, I wouldn't introduce another th/tex-frame
>> parameter but simply test for (null (frame-parameter frame
>> 'th/pdf-frame)) everywhere.
>
> Please go ahead with the latter and let me test it.

It's attached to this mail.  I've tested these three scenarios:

1. Start emacs, find tex source and then view it using AUCTeX View
   command where the last step creates a new pdf-dedicated frame.
2. Start emacs, find pdf document which opens the pdf in a new
   pdf-dedicated frame.  Double-click in the pdf finds the tex source
   in the other (non-pdf) frame.
3. Start "emacs foo.pdf" which shows the pdf in the initial frame and
   the code makes sure this frame has the th/pdf-frame parameter.
   Double-click in the pdf which spawns a new frame showing the tex
   source.

In all three cases I tested forward/backward synctex search which seems
to work as you like.

But that's the last code for this topic from me.  I like helping and
giving hints but my spare time is too limited to write ready-made
solutions to problems that don't scratch an itch of my own. :-)

Also note that my solution or maybe your requirements have their
problems: now it's hard to add more rules to display-buffer-alist
because for all of them you have to encode the "but, please, not in the
pdf-frame" stuff.  It's pretty complicated.  FWIW, I simply use a large
wide frame with a side-by-site split where the tex source is displayed
in the left window and the pdf in the right window.  That works without
any special configuration and isn't less convenient, IMHO.

Bye,
Tassilo


[-- Attachment #2: my-pdf-frame.el --]
[-- Type: application/emacs-lisp, Size: 1989 bytes --]

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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-02 18:38                                                 ` Tassilo Horn
@ 2023-05-03  1:45                                                   ` Hongyi Zhao
  2023-05-03  2:37                                                     ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-05-03  7:48                                                     ` Tassilo Horn
  2023-05-09  0:03                                                   ` Hongyi Zhao
  1 sibling, 2 replies; 40+ messages in thread
From: Hongyi Zhao @ 2023-05-03  1:45 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

This is great, thank you so much!

On Wed, May 3, 2023 at 3:00 AM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> Hi Zhao,
>
> >> BTW, I wonder if you really want to have a dedicated tex frame or
> >> just a dedicated pdf frame + one editing/normal frame.  If it's
> >> actually the latter, I wouldn't introduce another th/tex-frame
> >> parameter but simply test for (null (frame-parameter frame
> >> 'th/pdf-frame)) everywhere.
> >
> > Please go ahead with the latter and let me test it.
>
> It's attached to this mail.  I've tested these three scenarios:
>
> 1. Start emacs, find tex source and then view it using AUCTeX View
>    command where the last step creates a new pdf-dedicated frame.
> 2. Start emacs, find pdf document which opens the pdf in a new
>    pdf-dedicated frame.  Double-click in the pdf finds the tex source
>    in the other (non-pdf) frame.
> 3. Start "emacs foo.pdf" which shows the pdf in the initial frame and
>    the code makes sure this frame has the th/pdf-frame parameter.
>    Double-click in the pdf which spawns a new frame showing the tex
>    source.
>
> In all three cases I tested forward/backward synctex search which seems
> to work as you like.
>
> But that's the last code for this topic from me.  I like helping and
> giving hints but my spare time is too limited to write ready-made
> solutions to problems that don't scratch an itch of my own. :-)
>
> Also note that my solution or maybe your requirements have their
> problems: now it's hard to add more rules to display-buffer-alist
> because for all of them you have to encode the "but, please, not in the
> pdf-frame" stuff.  It's pretty complicated.  FWIW, I simply use a large
> wide frame with a side-by-site split where the tex source is displayed
> in the left window and the pdf in the right window.  That works without
> any special configuration and isn't less convenient, IMHO.

Agreed. What's your configuration for this simple purpose? What I can
think of is something like the following:

;; Split windows horizontally and display the PDF and TeX source side-by-side
(setq split-width-threshold 1000)
(add-hook 'TeX-after-compilation-finished-functions
          #'(lambda () (pdf-tools-deactivate-strip)))

Any enhancements/comments will be appreciated.

>
> Bye,
> Tassilo

Regards,
Zhao



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-03  1:45                                                   ` Hongyi Zhao
@ 2023-05-03  2:37                                                     ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-05-03  3:24                                                       ` Hongyi Zhao
  2023-05-03  7:48                                                     ` Tassilo Horn
  1 sibling, 1 reply; 40+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-05-03  2:37 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: Tassilo Horn, stefan-husmann, help-gnu-emacs


Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> ;; Split windows horizontally and display the PDF and TeX source side-by-side
> (setq split-width-threshold 1000)
> (add-hook 'TeX-after-compilation-finished-functions
>           #'(lambda () (pdf-tools-deactivate-strip)))

No need for the #'(lambda () ...) wrapping.  In general, you don't need
to #' any lambdas.  In this specific case, just saying
#'pdf-tools-deactivate-strip as the second argument to `add-hook' is
sufficient.

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-03  2:37                                                     ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-05-03  3:24                                                       ` Hongyi Zhao
  2023-05-03  3:38                                                         ` Hongyi Zhao
  0 siblings, 1 reply; 40+ messages in thread
From: Hongyi Zhao @ 2023-05-03  3:24 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Tassilo Horn, stefan-husmann, help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 706 bytes --]

On Wed, May 3, 2023 at 10:40 AM Ruijie Yu <ruijie@netyu.xyz> wrote:
>
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > ;; Split windows horizontally and display the PDF and TeX source side-by-side
> > (setq split-width-threshold 1000)
> > (add-hook 'TeX-after-compilation-finished-functions
> >           #'(lambda () (pdf-tools-deactivate-strip)))
>
> No need for the #'(lambda () ...) wrapping.  In general, you don't need
> to #' any lambdas.  In this specific case, just saying
> #'pdf-tools-deactivate-strip as the second argument to `add-hook' is
> sufficient.

I tried, but all the above methods don't work, as shown in the attached file.

> --
> Best,
>
>
> RY

Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 190984 bytes --]

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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-03  3:24                                                       ` Hongyi Zhao
@ 2023-05-03  3:38                                                         ` Hongyi Zhao
  0 siblings, 0 replies; 40+ messages in thread
From: Hongyi Zhao @ 2023-05-03  3:38 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Tassilo Horn, stefan-husmann, help-gnu-emacs

On Wed, May 3, 2023 at 11:24 AM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Wed, May 3, 2023 at 10:40 AM Ruijie Yu <ruijie@netyu.xyz> wrote:
> >
> >
> > Hongyi Zhao <hongyi.zhao@gmail.com> writes:
> >
> > > ;; Split windows horizontally and display the PDF and TeX source side-by-side
> > > (setq split-width-threshold 1000)
> > > (add-hook 'TeX-after-compilation-finished-functions
> > >           #'(lambda () (pdf-tools-deactivate-strip)))
> >
> > No need for the #'(lambda () ...) wrapping.  In general, you don't need
> > to #' any lambdas.  In this specific case, just saying
> > #'pdf-tools-deactivate-strip as the second argument to `add-hook' is
> > sufficient.
>
> I tried, but all the above methods don't work, as shown in the attached file.

And I also noticed the following errors:

error in process sentinel: run-hook-with-args: Symbol’s function
definition is void: pdf-tools-deactivate-strip
error in process sentinel: Symbol’s function definition is void:
pdf-tools-deactivate-strip

> > --
> > Best,
> >
> >
> > RY
>
> Zhao



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-03  1:45                                                   ` Hongyi Zhao
  2023-05-03  2:37                                                     ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-05-03  7:48                                                     ` Tassilo Horn
  1 sibling, 0 replies; 40+ messages in thread
From: Tassilo Horn @ 2023-05-03  7:48 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: stefan-husmann, help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

>> Also note that my solution or maybe your requirements have their
>> problems: now it's hard to add more rules to display-buffer-alist
>> because for all of them you have to encode the "but, please, not in the
>> pdf-frame" stuff.  It's pretty complicated.  FWIW, I simply use a large
>> wide frame with a side-by-site split where the tex source is displayed
>> in the left window and the pdf in the right window.  That works without
>> any special configuration and isn't less convenient, IMHO.
>
> Agreed. What's your configuration for this simple purpose?

None, I think.  split-window-preferred-function is split-window-sensibly
in recent emacsen and split-width-threshold is 160 by default which fits
my screen resolution and habit to have one fullscreen emacs frame.  So
when emacs splits, I get two side-by-side windows, each about 80 columns
wide.

> What I can think of is something like the following:
>
> ;; Split windows horizontally and display the PDF and TeX source side-by-side
> (setq split-width-threshold 1000)

That tells emacs that split-window-sensibly may only split a window
horizontally (i.e., into two side-by-side windows) if the window being
split is at least 1000 columns wide.  Basically, you ensure that
horizontal splits will never ever occur unless you have a screen that's
5 meters wide. :-)

> (add-hook 'TeX-after-compilation-finished-functions
>           #'(lambda () (pdf-tools-deactivate-strip)))

Instead of the lambda, #'pdf-tools-deactivate-strip will also do.  And
aside from that, this function is undefined in my (the current MELPA)
version of pdf-tools...

Bye,
Tassilo



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

* Re: How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.)
  2023-05-02 18:38                                                 ` Tassilo Horn
  2023-05-03  1:45                                                   ` Hongyi Zhao
@ 2023-05-09  0:03                                                   ` Hongyi Zhao
  1 sibling, 0 replies; 40+ messages in thread
From: Hongyi Zhao @ 2023-05-09  0:03 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: stefan-husmann, help-gnu-emacs

IMHO, the topic discussed here is especially useful, say, when one
works in multi-monitors tiling environment, where the LaTeX source and
PDF can be easily put on different monitors.

Best,
Zhao

On Wed, May 3, 2023 at 3:00 AM Tassilo Horn <tsdh@gnu.org> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> Hi Zhao,
>
> >> BTW, I wonder if you really want to have a dedicated tex frame or
> >> just a dedicated pdf frame + one editing/normal frame.  If it's
> >> actually the latter, I wouldn't introduce another th/tex-frame
> >> parameter but simply test for (null (frame-parameter frame
> >> 'th/pdf-frame)) everywhere.
> >
> > Please go ahead with the latter and let me test it.
>
> It's attached to this mail.  I've tested these three scenarios:
>
> 1. Start emacs, find tex source and then view it using AUCTeX View
>    command where the last step creates a new pdf-dedicated frame.
> 2. Start emacs, find pdf document which opens the pdf in a new
>    pdf-dedicated frame.  Double-click in the pdf finds the tex source
>    in the other (non-pdf) frame.
> 3. Start "emacs foo.pdf" which shows the pdf in the initial frame and
>    the code makes sure this frame has the th/pdf-frame parameter.
>    Double-click in the pdf which spawns a new frame showing the tex
>    source.
>
> In all three cases I tested forward/backward synctex search which seems
> to work as you like.
>
> But that's the last code for this topic from me.  I like helping and
> giving hints but my spare time is too limited to write ready-made
> solutions to problems that don't scratch an itch of my own. :-)
>
> Also note that my solution or maybe your requirements have their
> problems: now it's hard to add more rules to display-buffer-alist
> because for all of them you have to encode the "but, please, not in the
> pdf-frame" stuff.  It's pretty complicated.  FWIW, I simply use a large
> wide frame with a side-by-site split where the tex source is displayed
> in the left window and the pdf in the right window.  That works without
> any special configuration and isn't less convenient, IMHO.
>
> Bye,
> Tassilo



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

* Re: use pdf-tools in Emacs.
  2023-04-25 15:09 ` Rudolf Schlatte
  2023-04-26  2:01   ` Hongyi Zhao
@ 2023-05-18 14:51   ` Björn Bidar
  1 sibling, 0 replies; 40+ messages in thread
From: Björn Bidar @ 2023-05-18 14:51 UTC (permalink / raw)
  To: Rudolf Schlatte; +Cc: help-gnu-emacs


You can also install the package from your distributions package manager
and avoid calling pdf-tools-install.
For OpenSUSE and Arch Linux there's a package for example.



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

end of thread, other threads:[~2023-05-18 14:51 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-25 14:50 use pdf-tools in Emacs Hongyi Zhao
2023-04-25 15:09 ` Rudolf Schlatte
2023-04-26  2:01   ` Hongyi Zhao
2023-04-27 11:23     ` stefan-husmann
2023-04-27 15:02       ` Tassilo Horn
2023-04-27 15:27         ` Hongyi Zhao
2023-04-27 15:53           ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-04-27 23:54             ` Hongyi Zhao
2023-04-27 18:30           ` Tassilo Horn
2023-04-27 23:55             ` Hongyi Zhao
2023-04-28  7:15               ` Tassilo Horn
2023-04-28 10:48                 ` christian de larrinaga via Users list for the GNU Emacs text editor
2023-04-28 12:43                 ` Hongyi Zhao
2023-04-28 13:11                   ` Tassilo Horn
2023-04-28 13:37                     ` Hongyi Zhao
2023-04-28 13:58                       ` Tassilo Horn
2023-04-29  2:17                         ` Hongyi Zhao
2023-04-29  8:30                           ` How to have a frame dedicated to buffers of a certain kind? (was: use pdf-tools in Emacs.) Tassilo Horn
2023-04-29  9:25                             ` Hongyi Zhao
2023-04-29  9:35                               ` Tassilo Horn
2023-04-29 10:08                                 ` Hongyi Zhao
2023-04-29 19:37                                   ` Tassilo Horn
2023-04-30  0:42                                     ` Hongyi Zhao
2023-04-30  0:52                                       ` Hongyi Zhao
2023-04-30 18:59                                         ` Tassilo Horn
2023-05-01  0:28                                           ` Hongyi Zhao
2023-05-01  6:15                                             ` Tassilo Horn
2023-05-01  7:21                                               ` Hongyi Zhao
2023-05-02 18:38                                                 ` Tassilo Horn
2023-05-03  1:45                                                   ` Hongyi Zhao
2023-05-03  2:37                                                     ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-05-03  3:24                                                       ` Hongyi Zhao
2023-05-03  3:38                                                         ` Hongyi Zhao
2023-05-03  7:48                                                     ` Tassilo Horn
2023-05-09  0:03                                                   ` Hongyi Zhao
2023-04-30  1:05                                 ` Hongyi Zhao
2023-05-01 10:09             ` where to get "use-package"? [was: Re: use pdf-tools in Emacs] gebser
2023-05-01 10:30               ` Philip Kaludercic
2023-05-02  0:46                 ` gebser
2023-05-18 14:51   ` use pdf-tools in Emacs Björn Bidar

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.