1

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
    Commented Apr 29, 2021 at 2:06
  • This happens for PDF files I have built locally with LaTeX. It does not happen with externally-built PDFs. Commented May 1, 2021 at 4:12
  • And what about the other two questions?
    – phils
    Commented May 1, 2021 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. Commented May 3, 2021 at 6:33

2 Answers 2

1

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

0
0

As pointed out by dalanicolai, the problem is git-gutter in this case.

This is what my configuration looks like now:

(use-package git-gutter
  :ensure
  :config
  (setq git-gutter:update-interval 0.25)

  (defun rpo/git-gutter-mode ()
    "Enable git-gutter mode if current buffer's file is under version control."
    (if (and (buffer-file-name)
        (vc-backend (buffer-file-name))
            (not (cl-some (lambda (suffix) (string-suffix-p suffix (buffer-file-name)))
                        '(".pdf" ".svg" ".png"))))
        (git-gutter-mode 1))))
(add-hook 'find-file-hook #'rpo/git-gutter-mode)

(use-package git-gutter-fringe
  :ensure
  :config
  (set-face-attribute 'git-gutter-fr:added nil :foreground "#99cc99" :inherit 'fringe)
  (set-face-attribute 'git-gutter-fr:modified nil :foreground "#9999cc" :inherit 'fringe)
  (set-face-attribute 'git-gutter-fr:deleted nil :foreground "#cc9999" :inherit 'fringe)
  (define-fringe-bitmap 'git-gutter-fr:added [224] nil nil '(center repeated))
  (define-fringe-bitmap 'git-gutter-fr:modified [224] nil nil '(center repeated))
  (define-fringe-bitmap 'git-gutter-fr:deleted [128 192 224 240] nil nil 'bottom))

This way, git-gutter is only activated for file types which have not been blacklisted (.pdf, .svg, and .png here) before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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