0

After installing pdf-tools the dired mode opens the pdf file with PDFView mode as major mode.

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

How does the pdf-tools package be able to accomplish this?

The Help for RET key in dried buffer says it is bound to dired-find-file

RET (translated from ) runs the command dired-find-file (found in dired-mode-map), which is an interactive compiled Lisp function.

I searched for dired-find-file in pdf-tools installed elisp files and could not find any advice-add's?

Also please explain how can one go about finding arbitrary key bindings like this one?

Drew
  • 29,895
  • 7
  • 74
  • 104
Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135
  • I don't have/use `pdftools`. Maybe check your values of `dired-guess-shell-alist-user` and `dired-guess-shell-alist-default`. (The former should be reserved for you to modify, but perhaps `pdftools` modifies the latter.) – Drew Feb 06 '23 at 03:09

1 Answers1

3

What it modified is not directly related to dired, but to how Emacs decides to open files in general. The part of the code that is responsible for that is in pdf-tools-install-noverify, itself called by pdf-tools-install. The first two lines of the function are:

(add-to-list 'auto-mode-alist pdf-tools-auto-mode-alist-entry)
(add-to-list 'magic-mode-alist pdf-tools-magic-mode-alist-entry)

the relevant variables pdf-tools-<auto/magic>-mode-alist-entry being constants defined earlier in the file pdf-tools.el.

You can check the relevant documentation for auto-mode-alist and magic-mode-alist, but to sum up, the former is a mapping from "filenames" (or more precisely, file patterns -- typically, regexps matching file extensions) to major modes, and the latter is a mapping from "beginning of a buffer" to a major mode (see also this wikipedia page on magic numbers/file signatures).

As to how one can determine that: because it is not directly related to key bindings/advices/redefinition of functions, the only "general" option is to explore the "call stack" ! The package tells you to put (pdf-tools-install) somewhere in your init file to activate the package, so you can try to see what this function actually does -- and going a bit further, you see that it is essentially a wrapper around pdf-tools-install-noverify, which does the real job of setting everything up.

Numbra
  • 620
  • 4
  • 8