How to in nov.el for Emacs toggle image displaying?
- User
How to in nov.el for Emacs toggle image displaying?
- Assistant
How to in nov.el for Emacs toggle image displaying?
In nov.el, the EPUB reader for Emacs, images are displayed by default when the EPUB file contains them, as nov-mode renders EPUB files as HTML. If you want to toggle image displaying on and off, nov.el does not provide a direct built-in toggle command for images, but you can achieve this by adjusting Emacs’ image display settings or by intercepting the rendering process.
Here are a few approaches you can consider:
image-mode display within HTML renderingnov.el displays EPUB content as rendered HTML without an intermediate web browser—images are displayed as Emacs images embedded inline. Disabling or enabling image display can be controlled by the variable image-display-function or by controlling image rendering backend features.
However, Emacs normally displays images in buffers if images are present, and this behavior is not directly controllable on a per-buffer basis without modifying the rendering process.
nov-render-image to toggle imagesnov.el uses a function called nov-render-image internally to insert images. You could redefine it to do nothing (or conditionally insert images based on a toggle variable).
Example:
(defvar nov-display-images t
"Non-nil means display images in nov buffers.")
nov-render-image to conditionally insert images:(defun my-nov-render-image (image src)
"Render IMAGE only if `nov-display-images` is non-nil."
(when nov-display-images
(funcall image src)))
advice-add:(advice-add 'nov-render-image :around
(lambda (orig-fun &rest args)
(when nov-display-images
(apply orig-fun args))))
(defun my-nov-toggle-images ()
"Toggle image display in nov buffers."
(interactive)
(setq nov-display-images (not nov-display-images))
(nov-refresh)) ;; Refresh to apply the change
Bind this command to a key in nov-mode-map if you want.
You can also disable images for nov-mode buffers using Emacs’ image capabilities by setting the inhibit-images buffer-local variable:
;; This variable can be set buffer-locally to inhibit images display
(setq-local inhibit-images t)
However, inhibit-images is global or per-frame in many cases, so this may not work reliably.
The most practical way to toggle image display is to override or advise nov-render-image to conditionally insert images based on a user toggle variable, then refresh the buffer's rendering.
(defvar nov-display-images t
"Non-nil means display images in nov buffers.")
(defun my-nov-toggle-images ()
"Toggle image display in nov buffers."
(interactive)
(setq nov-display-images (not nov-display-images))
(message "nov images %s" (if nov-display-images "enabled" "disabled"))
(nov-refresh))
;; Advice nov-render-image to respect nov-display-images
(advice-add 'nov-render-image :around
(lambda (orig-fun &rest args)
(when nov-display-images
(apply orig-fun args))))
Then you can call M-x my-nov-toggle-images to toggle images on or off in the current EPUB buffer.
Let me know if you want help setting that up or doing something more advanced!
Not yet included in a published release.