From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: Wow -- adding images to an org file Date: Tue, 11 May 2010 17:29:23 -0400 Message-ID: <87eihif7po.fsf@stats.ox.ac.uk> References: <4648D225-BC59-4DB3-8D5B-DD50CD0E05C5@gmail.com> <874oijhnqs.fsf@stats.ox.ac.uk> <4F5FF1A6-BE60-4CC1-9D54-6D32D0FC2EDA@gmail.com> <20100511191424.GF10997@thinkpad.adamsinfoserv.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=49990 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OBx1F-0007Km-Cb for emacs-orgmode@gnu.org; Tue, 11 May 2010 17:29:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OBx16-0007O5-Qp for emacs-orgmode@gnu.org; Tue, 11 May 2010 17:29:37 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:49859) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OBx16-0007NB-C5 for emacs-orgmode@gnu.org; Tue, 11 May 2010 17:29:28 -0400 Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id o4BLTPiW018494 for ; Tue, 11 May 2010 22:29:25 +0100 (BST) In-Reply-To: <20100511191424.GF10997@thinkpad.adamsinfoserv.com> (Russell Adams's message of "Tue, 11 May 2010 14:14:24 -0500") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Russell Adams writes: > On Sat, May 08, 2010 at 12:51:41PM +0200, Carsten Dominik wrote: >> We have now native inline image display in Org-mode, you can toggle it >> with >> >> C-c C-x C-v >> >> This implementation uses overlays instead of text properties and >> therefore does not interfere with font-lock. >> >> - Carsten > > I'm using Org-Babel and R, and when I use C-c C-c to update the output > from a block of code, the image in emacs doesn't change. > > Ideas? v6.36 Hi Russell, I struggled with this when images were text properties, i.e. before Carsten's implementation using overlays (thanks for C-c C-x C-v Carsten!) I think the answer may be clear-image-cache. I just tried that and C-c C-x C-v showed the new image afterwards. I'm not sure whether the following is acceptable in terms of emacs ecology, but it seems to do the trick: --8<---------------cut here---------------start------------->8--- diff --git a/lisp/org.el b/lisp/org.el index c52aeb0..85f1219 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -15507,6 +15507,7 @@ with a description part will be inlined." "Remove inline display of images." (interactive) (mapc 'delete-overlay org-inline-image-overlays) + (clear-image-cache) (setq org-inline-image-overlays nil)) --8<---------------cut here---------------end--------------->8--- Note also that we can make image display happen automatically after executing a babel block: (add-hook 'org-babel-after-execute-hook 'org-display-inline-images) In fact that was what I had in mind when adding that hook; it was just waiting for Carsten's function. So in my mind this gets us some of the way towards org-babel as an "interactive notebook", as discussed in another recent thread. Dan p.s. For what its worth, here is the code I was using to make images appear using text properties and Org font lock. I was intending to post this when I was happy with the image refresh stuff, but it is probably redundant in light of the new functions using overlays. A certain amount of messing about with image redisplay and cache functions is evident. --8<---------------cut here---------------start------------->8--- (defun dan/org-fontify-image-links (limit) "Display links to images as images. If the description part of the link is empty display the image, otherwise do nothing. This function is intended to be called during font-lock fontification." (let ((case-fold-search t) file image) (and dan/org-display-inline-images (re-search-forward (concat "\\[\\[file:\\(" iimage-mode-image-filename-regex "\\)\\]\\]") limit t) (setq file (match-string 1)) (setq file (iimage-locate-file file (list default-directory))) (setq image (create-image file)) (add-text-properties (match-beginning 0) (match-end 0) (list 'display image)) ;; (clear-image-cache) (image-refresh image) ;; (redisplay) ;; (redraw-frame) ;; (redraw-display) ;; (image-refresh image) ))) (setq dan/org-display-inline-images t) (add-hook 'org-font-lock-hook 'dan/org-fontify-image-links) --8<---------------cut here---------------end--------------->8--- > > Thanks. > > ------------------------------------------------------------------ > Russell Adams RLAdams@AdamsInfoServ.com > > PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ > > Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode