From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daimrod Subject: Re: [Bug] org-startup-with-inline-images Date: Wed, 01 May 2013 19:28:28 +0200 Message-ID: <871u9qehj7.fsf@tanger.home> References: <23e22687eaae8dff1bfd56306ef41b17@mail.rickster.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([208.118.235.92]:32775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXan8-0004k1-3L for emacs-orgmode@gnu.org; Wed, 01 May 2013 13:26:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UXan1-00081K-O1 for emacs-orgmode@gnu.org; Wed, 01 May 2013 13:26:06 -0400 Received: from mail-we0-x22b.google.com ([2a00:1450:400c:c03::22b]:58029) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UXan1-00080u-Dq for emacs-orgmode@gnu.org; Wed, 01 May 2013 13:25:59 -0400 Received: by mail-we0-f171.google.com with SMTP id t57so1422576wey.30 for ; Wed, 01 May 2013 10:25:58 -0700 (PDT) In-Reply-To: <23e22687eaae8dff1bfd56306ef41b17@mail.rickster.com> (Rick Frankel's message of "Tue, 30 Apr 2013 13:39:28 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rick Frankel Cc: Org-Mode --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Rick Frankel 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, --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-lisp-org.el-Do-not-inline-images-when-no-graphic-dis.patch Content-Transfer-Encoding: quoted-printable From=20db2c62c07b9e1a61db4930fc8252b96f3d6bc0b8 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Gr=3DC3=3DA9goire=3D20Jadi?=3D 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: =2D-- 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 =2D-- 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")) =2D (org-remove-latex-fragment-image-overlays) =2D (save-excursion =2D (save-restriction =2D (let (beg end at msg) =2D (cond =2D ((or (equal subtree '(16)) =2D (not (save-excursion =2D (re-search-backward org-outline-regexp-bol nil t)))) =2D (setq beg (point-min) end (point-max) =2D msg "Creating images for buffer...%s")) =2D ((equal subtree '(4)) =2D (org-back-to-heading) =2D (setq beg (point) end (org-end-of-subtree t) =2D msg "Creating images for subtree...%s")) =2D (t =2D (if (setq at (org-inside-LaTeX-fragment-p)) =2D (goto-char (max (point-min) (- (cdr at) 2))) =2D (org-back-to-heading)) =2D (setq beg (point) end (progn (outline-next-heading) (point)) =2D msg (if at "Creating image...%s" =2D "Creating images for entry...%s")))) =2D (message msg "") =2D (narrow-to-region beg end) =2D (goto-char beg) =2D (org-format-latex =2D (concat org-latex-preview-ltxpng-directory (file-name-sans-extension =2D (file-name-nondirectory =2D buffer-file-name))) =2D default-directory 'overlays msg at 'forbuffer =2D org-latex-create-formula-image-program) =2D (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.")))))) =20 (defun org-format-latex (prefix &optional dir overlays msg at forbuffer processing-type) @@ -18747,53 +18748,54 @@ When REFRESH is set, refresh existing images betw= een BEG and END. This will create new image displays only if necessary. BEG and END default to the buffer boundaries." (interactive "P") =2D (unless refresh =2D (org-remove-inline-images) =2D (if (fboundp 'clear-image-cache) (clear-image-cache))) =2D (save-excursion =2D (save-restriction =2D (widen) =2D (setq beg (or beg (point-min)) end (or end (point-max))) =2D (goto-char beg) =2D (let ((re (concat "\\[\\[\\(\\(file:\\)\\|\\([./~]\\)\\)\\([^]\n]+= ?" =2D (substring (org-image-file-name-regexp) 0 -2) =2D "\\)\\]" (if include-linked "" "\\]"))) =2D (case-fold-search t) =2D old file ov img type attrwidth width) =2D (while (re-search-forward re end t) =2D (setq old (get-char-property-and-overlay (match-beginning 1) =2D 'org-image-overlay) =2D file (expand-file-name =2D (concat (or (match-string 3) "") (match-string 4)))) =2D (when (image-type-available-p 'imagemagick) =2D (setq attrwidth (if (or (listp org-image-actual-width) =2D (null org-image-actual-width)) =2D (save-excursion =2D (save-match-data =2D (when (re-search-backward =2D "#\\+attr.*:width[ \t]+\\([^ ]+\\)" =2D (save-excursion =2D (re-search-backward "^[ \t]*$\\|\\`" nil t)) t) =2D (string-to-number (match-string 1)))))) =2D width (cond ((eq org-image-actual-width t) nil) =2D ((null org-image-actual-width) attrwidth) =2D ((numberp org-image-actual-width) =2D org-image-actual-width) =2D ((listp org-image-actual-width) =2D (or attrwidth (car org-image-actual-width)))) =2D type (if width 'imagemagick))) =2D (when (file-exists-p file) =2D (if (and (car-safe old) refresh) =2D (image-refresh (overlay-get (cdr old) 'display)) =2D (setq img (save-match-data (create-image file type nil :width wid= th))) =2D (when img =2D (setq ov (make-overlay (match-beginning 0) (match-end 0))) =2D (overlay-put ov 'display img) =2D (overlay-put ov 'face 'default) =2D (overlay-put ov 'org-image-overlay t) =2D (overlay-put ov 'modification-hooks =2D (list 'org-display-inline-remove-overlay)) =2D (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)))))))))) =20 (define-obsolete-function-alias 'org-display-inline-modification-hook 'org-display-inline-remove-overlay= "24.3") =2D-=20 1.7.10.4 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =2D-=20 Daimrod/Greg --=-=-=-- --==-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iQIcBAEBAgAGBQJRgVC/AAoJEBNzVHcrZRiUhGkP/0UPSJO1IcUl3xpwQnuHNd7Z ge2HyKmT2KxP75ZkgfY6he+j2qsS4i6sMTkYDJoGlhrby8mQMOBPb+cIDfKuwVt0 Rs3JjRCEc8prsgkMZ4NG1wRF3cRXWkVwvwXiLTtSlNkRBJScaJIfNONPMRT208+/ Fp4aEfP00Ol2CmyNfI2YsInyJtH0bLsKuDlIZ3iataVZqBfewQbkx74ssH4O0MYN psdiTJY9fqi9tCqpaJ5y/I0c83p+q1vlyGppHarzp+TQgdDFNuG9nZgtYLeTxr5J /gx2kUDLls8in/LD8QzIjsWKLSWDOhgBP261uCdwjROPMOuc5CgiSo5RJHN4F183 iyx1TkOrsno5wz34nB3MW9HP3z1rnCG1tQNjMiEoqjk6DlD5KH1WHtwXfbAOaUcv 16GUjra6lnipaEUhnc0xj2gRWUOxvw/8CVGTaPhFGsOSN3vLiHuRMqDIJC70foge cTB2xfdS+qYrWlWpemFN+nPcYkHb9s85h4XhFrFPhGTkac6hQPCi59c23m9Qa/pU 5UN2ESyYWPs1R+1An2HzYUd3AVxx79p48um0trVwKpyyKaryXCYIbJMyg5Qu+eK+ 689oRYWQna4e9Li+9+H1JKyNT7IhGUTWF77mmrMHBm24jyHnIHZztiLxzUuUEi49 mvvdwSDzfSAC0eacE2fM =YESd -----END PGP SIGNATURE----- --==-=-=--