Improve the compatibility of desktop-save-mode' and eww'

This commit is contained in:
Gerard Vermeulen 2024-06-17 12:26:23 +02:00
parent 966aa9e91e
commit 9117f3b779

View File

@ -5739,22 +5739,19 @@ Listing [[lst:configure-browse-url]] configures =browse-url=.
:CUSTOM_ID: sec:emacs-web-wowser :CUSTOM_ID: sec:emacs-web-wowser
:END: :END:
#+caption[Rename =eww= buffers and display =pdf= links properly]: #+caption[Display =pdf= links properly in =eww=]:
#+caption: Rename =eww= buffers and display =pdf= links properly. #+caption: Display =pdf= links properly in =eww=.
#+name: lst:rename-eww-buffer-display-pdf-links #+name: lst:display-pdf-links-in-eww
#+begin_src emacs-lisp -n :results silent #+begin_src emacs-lisp -n :results silent
(with-eval-after-load 'eww (with-eval-after-load 'eww
;; GAV: Renaming `eww' buffers conflicts with `desktop-save-mode'.
;; GAV: Setting `eww-restore-desktop' to something else fails too.
(setopt eww-restore-desktop nil)
(defun eww-display-pdf-as-binary (fn &rest args) (defun eww-display-pdf-as-binary (fn &rest args)
(let ((buffer-file-coding-system 'binary)) (let ((buffer-file-coding-system 'binary))
(apply fn args))) (apply fn args)))
(defun eww-rename-buffer ()
"Rename the buffer using title or url."
(let* ((title (plist-get eww-data :title))
(name (or (and (eq "" title) (plist-get eww-data :url)) title)))
(rename-buffer (format "*%s # eww*" name) t)))
(add-hook 'eww-after-render-hook #'eww-rename-buffer)
(advice-add 'eww-display-pdf :around #'eww-display-pdf-as-binary)) (advice-add 'eww-display-pdf :around #'eww-display-pdf-as-binary))
#+end_src #+end_src