From: Daimrod <daimrod@gmail.com>
To: Rick Frankel <rick@rickster.com>
Cc: Org-Mode <emacs-orgmode@gnu.org>
Subject: Re: [Bug] org-startup-with-inline-images
Date: Wed, 01 May 2013 19:28:28 +0200 [thread overview]
Message-ID: <871u9qehj7.fsf@tanger.home> (raw)
In-Reply-To: <23e22687eaae8dff1bfd56306ef41b17@mail.rickster.com> (Rick Frankel's message of "Tue, 30 Apr 2013 13:39:28 -0400")
[-- Attachment #1.1: Type: text/plain, Size: 1409 bytes --]
Rick Frankel <rick@rickster.com> writes:
Hello Rick,
> `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:
>
> (defun org-display-inline-images (&optional include-linked refresh
> beg end)
> "..."
> (interactive "P")
> (when (display-graphic-p)
> ^^^^^^^^^^^^^^^^^^^^^^^^
> [...])
Thanks for the report, I've attached a patch that fixes this problem (in
both `org-display-inline-images' and `org-preview-latex-fragment').
However I don't know if it is the right approach or if I should try to
narrow this to lower-level functions.
I know that `clear-image-cache' raise this error but I haven't tried to
see if it the only one. Should I try to look more at it and add a
`org-clear-image-cache' which will check if a graphic display is
available or is the current solution fine?
Regards,
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-lisp-org.el-Do-not-inline-images-when-no-graphic-dis.patch --]
[-- Type: text/x-diff, Size: 8550 bytes --]
From db2c62c07b9e1a61db4930fc8252b96f3d6bc0b8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9goire=20Jadi?= <gregoire.jadi@gmail.com>
Date: Wed, 1 May 2013 19:19:57 +0200
Subject: [PATCH] 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:
---
lisp/org.el | 158 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 80 insertions(+), 78 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index d1c4c9a..ae0110f 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18195,37 +18195,38 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
(interactive "P")
(unless buffer-file-name
(user-error "Can't preview LaTeX fragment in a non-file buffer"))
- (org-remove-latex-fragment-image-overlays)
- (save-excursion
- (save-restriction
- (let (beg end at msg)
- (cond
- ((or (equal subtree '(16))
- (not (save-excursion
- (re-search-backward org-outline-regexp-bol nil t))))
- (setq beg (point-min) end (point-max)
- msg "Creating images for buffer...%s"))
- ((equal subtree '(4))
- (org-back-to-heading)
- (setq beg (point) end (org-end-of-subtree t)
- msg "Creating images for subtree...%s"))
- (t
- (if (setq at (org-inside-LaTeX-fragment-p))
- (goto-char (max (point-min) (- (cdr at) 2)))
- (org-back-to-heading))
- (setq beg (point) end (progn (outline-next-heading) (point))
- msg (if at "Creating image...%s"
- "Creating images for entry...%s"))))
- (message msg "")
- (narrow-to-region beg end)
- (goto-char beg)
- (org-format-latex
- (concat org-latex-preview-ltxpng-directory (file-name-sans-extension
- (file-name-nondirectory
- buffer-file-name)))
- default-directory 'overlays msg at 'forbuffer
- org-latex-create-formula-image-program)
- (message msg "done. Use `C-c C-c' to remove images.")))))
+ (when (display-graphic-p)
+ (org-remove-latex-fragment-image-overlays)
+ (save-excursion
+ (save-restriction
+ (let (beg end at msg)
+ (cond
+ ((or (equal subtree '(16))
+ (not (save-excursion
+ (re-search-backward org-outline-regexp-bol nil t))))
+ (setq beg (point-min) end (point-max)
+ msg "Creating images for buffer...%s"))
+ ((equal subtree '(4))
+ (org-back-to-heading)
+ (setq beg (point) end (org-end-of-subtree t)
+ msg "Creating images for subtree...%s"))
+ (t
+ (if (setq at (org-inside-LaTeX-fragment-p))
+ (goto-char (max (point-min) (- (cdr at) 2)))
+ (org-back-to-heading))
+ (setq beg (point) end (progn (outline-next-heading) (point))
+ msg (if at "Creating image...%s"
+ "Creating images for entry...%s"))))
+ (message msg "")
+ (narrow-to-region beg end)
+ (goto-char beg)
+ (org-format-latex
+ (concat org-latex-preview-ltxpng-directory (file-name-sans-extension
+ (file-name-nondirectory
+ buffer-file-name)))
+ default-directory 'overlays msg at 'forbuffer
+ org-latex-create-formula-image-program)
+ (message msg "done. Use `C-c C-c' to remove images."))))))
(defun org-format-latex (prefix &optional dir overlays msg at
forbuffer processing-type)
@@ -18747,53 +18748,54 @@ When REFRESH is set, refresh existing images between BEG and END.
This will create new image displays only if necessary.
BEG and END default to the buffer boundaries."
(interactive "P")
- (unless refresh
- (org-remove-inline-images)
- (if (fboundp 'clear-image-cache) (clear-image-cache)))
- (save-excursion
- (save-restriction
- (widen)
- (setq beg (or beg (point-min)) end (or end (point-max)))
- (goto-char beg)
- (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
- (substring (org-image-file-name-regexp) 0 -2)
- "\\)\\]" (if include-linked "" "\\]")))
- (case-fold-search t)
- old file ov img type attrwidth width)
- (while (re-search-forward re end t)
- (setq old (get-char-property-and-overlay (match-beginning 1)
- 'org-image-overlay)
- file (expand-file-name
- (concat (or (match-string 3) "") (match-string 4))))
- (when (image-type-available-p 'imagemagick)
- (setq attrwidth (if (or (listp org-image-actual-width)
- (null org-image-actual-width))
- (save-excursion
- (save-match-data
- (when (re-search-backward
- "#\\+attr.*:width[ \t]+\\([^ ]+\\)"
- (save-excursion
- (re-search-backward "^[ \t]*$\\|\\`" nil t)) t)
- (string-to-number (match-string 1))))))
- width (cond ((eq org-image-actual-width t) nil)
- ((null org-image-actual-width) attrwidth)
- ((numberp org-image-actual-width)
- org-image-actual-width)
- ((listp org-image-actual-width)
- (or attrwidth (car org-image-actual-width))))
- type (if width 'imagemagick)))
- (when (file-exists-p file)
- (if (and (car-safe old) refresh)
- (image-refresh (overlay-get (cdr old) 'display))
- (setq img (save-match-data (create-image file type nil :width width)))
- (when img
- (setq ov (make-overlay (match-beginning 0) (match-end 0)))
- (overlay-put ov 'display img)
- (overlay-put ov 'face 'default)
- (overlay-put ov 'org-image-overlay t)
- (overlay-put ov 'modification-hooks
- (list 'org-display-inline-remove-overlay))
- (push ov org-inline-image-overlays)))))))))
+ (when (display-graphic-p)
+ (unless refresh
+ (org-remove-inline-images)
+ (if (fboundp 'clear-image-cache) (clear-image-cache)))
+ (save-excursion
+ (save-restriction
+ (widen)
+ (setq beg (or beg (point-min)) end (or end (point-max)))
+ (goto-char beg)
+ (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+?"
+ (substring (org-image-file-name-regexp) 0 -2)
+ "\\)\\]" (if include-linked "" "\\]")))
+ (case-fold-search t)
+ old file ov img type attrwidth width)
+ (while (re-search-forward re end t)
+ (setq old (get-char-property-and-overlay (match-beginning 1)
+ 'org-image-overlay)
+ file (expand-file-name
+ (concat (or (match-string 3) "") (match-string 4))))
+ (when (image-type-available-p 'imagemagick)
+ (setq attrwidth (if (or (listp org-image-actual-width)
+ (null org-image-actual-width))
+ (save-excursion
+ (save-match-data
+ (when (re-search-backward
+ "#\\+attr.*:width[ \t]+\\([^ ]+\\)"
+ (save-excursion
+ (re-search-backward "^[ \t]*$\\|\\`" nil t)) t)
+ (string-to-number (match-string 1))))))
+ width (cond ((eq org-image-actual-width t) nil)
+ ((null org-image-actual-width) attrwidth)
+ ((numberp org-image-actual-width)
+ org-image-actual-width)
+ ((listp org-image-actual-width)
+ (or attrwidth (car org-image-actual-width))))
+ type (if width 'imagemagick)))
+ (when (file-exists-p file)
+ (if (and (car-safe old) refresh)
+ (image-refresh (overlay-get (cdr old) 'display))
+ (setq img (save-match-data (create-image file type nil :width width)))
+ (when img
+ (setq ov (make-overlay (match-beginning 0) (match-end 0)))
+ (overlay-put ov 'display img)
+ (overlay-put ov 'face 'default)
+ (overlay-put ov 'org-image-overlay t)
+ (overlay-put ov 'modification-hooks
+ (list 'org-display-inline-remove-overlay))
+ (push ov org-inline-image-overlays))))))))))
(define-obsolete-function-alias
'org-display-inline-modification-hook 'org-display-inline-remove-overlay "24.3")
--
1.7.10.4
[-- Attachment #1.3: Type: text/plain, Size: 21 bytes --]
--
Daimrod/Greg
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
next prev parent reply other threads:[~2013-05-01 17:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-30 17:39 [Bug] org-startup-with-inline-images Rick Frankel
2013-05-01 17:28 ` Daimrod [this message]
2013-05-01 17:42 ` Rick Frankel
2013-05-02 8:09 ` Daimrod
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871u9qehj7.fsf@tanger.home \
--to=daimrod@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=rick@rickster.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).