lisp/org.el: Do not inline images when no graphic display is available

* lisp/org.el (org-preview-latex-fragment)
(org-display-inline-images): Detect whether a graphic display is
available before inlining images to prevent an error.

Thanks to Rick Frankel for the report and the solution.

> `org-startup-with-inline-images' is a customizable variable. The
> problem is that if an org file is visited in a non-graphics buffer (or
> batch), `org-display-inline-images' is called an throws an error
> ("Non-X frame used").
>
> This problem also occurs when e.g., `org-babel-after-execute-hook' is
> set to 'org-display-inline-images (which can be mitigated by not
> setting the hook in a non-x frame).
>
> Since the startup variable is a customization, and causes problems if
> not set programatically, IMHO, the best solution would be to wrap the
> `org-display-inline-images' function in a test so that is is a no-op
> on non graphic displays:
This commit is contained in:
Grégoire Jadi 2013-05-01 19:19:57 +02:00
parent 73ce77f991
commit 168c5584f5
1 changed files with 80 additions and 78 deletions

View File

@ -18195,6 +18195,7 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
(interactive "P") (interactive "P")
(unless buffer-file-name (unless buffer-file-name
(user-error "Can't preview LaTeX fragment in a non-file buffer")) (user-error "Can't preview LaTeX fragment in a non-file buffer"))
(when (display-graphic-p)
(org-remove-latex-fragment-image-overlays) (org-remove-latex-fragment-image-overlays)
(save-excursion (save-excursion
(save-restriction (save-restriction
@ -18225,7 +18226,7 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
buffer-file-name))) buffer-file-name)))
default-directory 'overlays msg at 'forbuffer default-directory 'overlays msg at 'forbuffer
org-latex-create-formula-image-program) org-latex-create-formula-image-program)
(message msg "done. Use `C-c C-c' to remove images."))))) (message msg "done. Use `C-c C-c' to remove images."))))))
(defun org-format-latex (prefix &optional dir overlays msg at (defun org-format-latex (prefix &optional dir overlays msg at
forbuffer processing-type) forbuffer processing-type)
@ -18747,6 +18748,7 @@ When REFRESH is set, refresh existing images between BEG and END.
This will create new image displays only if necessary. This will create new image displays only if necessary.
BEG and END default to the buffer boundaries." BEG and END default to the buffer boundaries."
(interactive "P") (interactive "P")
(when (display-graphic-p)
(unless refresh (unless refresh
(org-remove-inline-images) (org-remove-inline-images)
(if (fboundp 'clear-image-cache) (clear-image-cache))) (if (fboundp 'clear-image-cache) (clear-image-cache)))
@ -18793,7 +18795,7 @@ BEG and END default to the buffer boundaries."
(overlay-put ov 'org-image-overlay t) (overlay-put ov 'org-image-overlay t)
(overlay-put ov 'modification-hooks (overlay-put ov 'modification-hooks
(list 'org-display-inline-remove-overlay)) (list 'org-display-inline-remove-overlay))
(push ov org-inline-image-overlays))))))))) (push ov org-inline-image-overlays))))))))))
(define-obsolete-function-alias (define-obsolete-function-alias
'org-display-inline-modification-hook 'org-display-inline-remove-overlay "24.3") 'org-display-inline-modification-hook 'org-display-inline-remove-overlay "24.3")