0

I am facing an issue when opening PDF files in Emacs. I always get prompted for "Selecting the encoding system (default raw-text)". The prompt comes up twice. The content of the *Warning* buffer is as follows.

These default coding systems were tried to encode text
in the buffer  *temp file*:
  (utf-8-unix (11 . 4194256) (12 . 4194260) (13 . 4194245) (14 . 4194264) (80 . 4194257) (82 .
  4194203) (86 . 4194279) (88 . 4194300) (89 . 4194200) (91 . 4194245) (92 . 4194264))
However, each of them encountered characters it couldnt encode:
  utf-8-unix cannot encode these:           ...

Click on a character (or switch to this window by C-x o
and select the characters by RET) to jump to the place it appears,
where C-u C-x = will give information about it.

Select one of the safe coding systems listed below,
or cancel the writing with C-g and edit the buffer
   to remove or modify the problematic characters,
or specify any other coding system (and risk losing
   the problematic characters).

  raw-text no-conversion

I have the following set in my init.el, so I am unsure as to what more is required.

(setq locale-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment 'utf-8)
(set-selection-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)

I also have pdf-tools set up.

(declare-function pdf-view-mode "pdf-tools")
(declare-function pdf-annot-delete "pdf-tools")
(declare-function pdf-annot-add-highlight-markup-annotation "pdf-tools")
(declare-function pdf-annot-add-text-annotation "pdf-tools")

(unless (fboundp 'pdf-view-mode)
  (autoload #'pdf-view-mode "pdf-tools" nil t))
(unless (fboundp 'isearch-forward)
  (autoload #'isearch-forward "pdf-tools" nil t))
(unless (fboundp 'pdf-annot-delete)
  (autoload #'pdf-annot-delete "pdf-tools" nil t))
(unless (fboundp 'pdf-annot-add-highlight-markup-annotation)
  (autoload #'pdf-annot-add-highlight-markup-annotation "pdf-tools" nil t))
(unless (fboundp 'pdf-annot-add-text-annotation)
  (autoload #'pdf-annot-add-text-annotation "pdf-tools" nil t))
(unless (fboundp 'pdf-tools-install)
  (autoload #'pdf-tools-install "pdf-tools" nil t))
(unless (fboundp 'pdf-loader-install)
  (autoload #'pdf-loader-install "pdf-tools" nil t))

;; Expensive to load
(run-with-idle-timer 2 nil #'require 'pdf-tools nil t)

(add-to-list 'magic-mode-alist '("%PDF" . pdf-view-mode))

(add-to-list 'auto-mode-alist '("\\.pdf\\'" . pdf-view-mode))

(with-eval-after-load 'pdf-tools
  ;; (pdf-tools-install :no-query)
  (pdf-loader-install) ; Expected to be faster than `(pdf-tools-install)'

  (defvar pdf-annot-activate-created-annotations)
  (defvar pdf-view-resize-factor)

  (setq pdf-annot-activate-created-annotations t ; Automatically annotate highlights
        ;; Fine-grained zoom factor of 10%
        pdf-view-resize-factor 1.1)

  (setq-default pdf-view-display-size 'fit-width) ; Buffer-local variable

  (add-hook 'pdf-view-mode #'pdf-links-minor-mode)
  (add-hook 'pdf-view-mode #'pdf-isearch-minor-mode)
  (add-hook 'pdf-view-mode #'pdf-outline-minor-mode)
  (add-hook 'pdf-view-mode #'pdf-history-minor-mode)

  ;; (add-hook 'pdf-view-mode-hook (lambda ()
  ;;                                 (setq header-line-format nil)))

  )

(defvar pdf-view-mode-map)
(bind-keys :package pdf-tools :map pdf-view-mode-map
           ("C-s" . isearch-forward)
           ("d"   . pdf-annot-delete)
           ("h"   . pdf-annot-add-highlight-markup-annotation)
           ("t"   . pdf-annot-add-text-annotation))


(with-eval-after-load 'saveplace
  (with-eval-after-load 'pdf-tools
    (require 'saveplace-pdf-view nil nil)))

My GNU Emacs version is 27.1 on Ubuntu 20.04. Please suggest how can I suppress or resolve the above annoyance.

4
  • Does pdf-tools work otherwise? Do the same prompts/warnings also occur if you run emacs -Q and open the PDF files? Does this happen for all PDFs? (maybe grab some random examples online if all your local examples have a similar source).
    – phils
    Apr 29 '21 at 2:06
  • This happens for PDF files I have built locally with LaTeX. It does not happen with externally-built PDFs. May 1 '21 at 4:12
  • And what about the other two questions?
    – phils
    May 1 '21 at 8:07
  • pdf-tools work by itself. emacs -Q followed by package-initialize() and pdf-tools-install also work, that is, I do not see the "Select coding system". However, Emacs now works with my configuration as well, which is weird. I do not remember having made any related modifications in the last one week, so I am confused. I will follow up with more information when I have it. Thanks for helping. May 3 '21 at 6:33
0

You can try to find out what triggers it by doing M-x debug-on-entry select-safe-coding-system (then read until the debugger gets triggered).

For me the pop-up seems to get triggered by git-gutter-mode. Simply deactivating that mode stops the very annoying behavior.

(Subsequently, the debugger also got triggered by pdf-view-restore, but the problem was already solved by deactivating git-gutter-mode. So after 'fixing' the first trigger, first do M-x cancel-debug-on-entry before you start fixing subsequent triggers. I have no idea why those other triggers do not trigger the pop-up, but that is another mystery...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.