Pārlūkot izejas kodu

Implement inline display of linked images

Carsten Dominik 15 gadi atpakaļ
vecāks
revīzija
7147508d81
5 mainītis faili ar 73 papildinājumiem un 6 dzēšanām
  1. 6 0
      doc/ChangeLog
  2. 11 3
      doc/org.texi
  3. 1 0
      doc/orgcard.tex
  4. 7 0
      lisp/ChangeLog
  5. 48 3
      lisp/org.el

+ 6 - 0
doc/ChangeLog

@@ -1,3 +1,9 @@
+2010-05-08  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* orgcard.tex: Document inline image toggling.
+
+	* org.texi (Handling links): Document inline image toggling.
+
 2010-05-07  Carsten Dominik  <carsten.dominik@gmail.com>
 2010-05-07  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org.texi (Updating the table): Document new buffer-wide
 	* org.texi (Updating the table): Document new buffer-wide

+ 11 - 3
doc/org.texi

@@ -2983,14 +2983,14 @@ to the current directory using @samp{../}.  Otherwise an absolute path
 is used, if possible with @samp{~/} for your home directory.  You can
 is used, if possible with @samp{~/} for your home directory.  You can
 force an absolute path with two @kbd{C-u} prefixes.
 force an absolute path with two @kbd{C-u} prefixes.
 @c
 @c
-@item C-c C-l @r{(with cursor on existing link)}
+@item C-c C-l @ @r{(with cursor on existing link)}
 When the cursor is on an existing link, @kbd{C-c C-l} allows you to edit the
 When the cursor is on an existing link, @kbd{C-c C-l} allows you to edit the
 link and description parts of the link.
 link and description parts of the link.
 @c
 @c
 @cindex following links
 @cindex following links
 @kindex C-c C-o
 @kindex C-c C-o
-@kindex RET
-@item C-c C-o @r{or} @key{RET}
+@kindex @key{RET}
+@item C-c C-o @ @r{(or, if @code{org-return-follows-link} is set, also} @key{RET}
 @vindex org-file-apps
 @vindex org-file-apps
 Open link at point.  This will launch a web browser for URLs (using
 Open link at point.  This will launch a web browser for URLs (using
 @command{browse-url-at-point}), run VM/MH-E/Wanderlust/Rmail/Gnus/BBDB for
 @command{browse-url-at-point}), run VM/MH-E/Wanderlust/Rmail/Gnus/BBDB for
@@ -3021,6 +3021,14 @@ Like @kbd{mouse-2}, but force file links to be opened with Emacs, and
 internal links to be displayed in another window@footnote{See the
 internal links to be displayed in another window@footnote{See the
 variable @code{org-display-internal-link-with-indirect-buffer}}.
 variable @code{org-display-internal-link-with-indirect-buffer}}.
 @c
 @c
+@cindex inlining images
+@cindex images, inlining
+@kindex C-c C-x C-v
+@item C-c C-x C-v
+Toggle the inline display of linked images.  Normally this will only inline
+images that have no description part in the link, i.e. images that will also
+be inlined during export.  When called with a prefix argument, also display
+images that do have a link description.
 @cindex mark ring
 @cindex mark ring
 @kindex C-c %
 @kindex C-c %
 @item C-c %
 @item C-c %

+ 1 - 0
doc/orgcard.tex

@@ -442,6 +442,7 @@ formula, \kbd{:=} a field formula.
 \key{find next link}{C-c C-x C-n}
 \key{find next link}{C-c C-x C-n}
 \key{find previous link}{C-c C-x C-p}
 \key{find previous link}{C-c C-x C-p}
 \key{edit code snippet of file at point}{C-c '}
 \key{edit code snippet of file at point}{C-c '}
+\key{toggle inline display of linked images}{C-c C-x C-v}
 
 
 {\bf Internal Links}
 {\bf Internal Links}
 
 

+ 7 - 0
lisp/ChangeLog

@@ -1,3 +1,10 @@
+2010-05-08  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.el (org-inline-image-overlays): New variable.
+	(org-toggle-inline-images, org-display-inline-images)
+	(org-remove-inline-images): New commands.
+	(org-mode-map): Define a key for `org-toggle-inline-images'.
+
 2010-05-08  David Maus  <dmaus@ictsoc.de>
 2010-05-08  David Maus  <dmaus@ictsoc.de>
 
 
 	* org-wl.el (org-wl-message-field): New function.  Return
 	* org-wl.el (org-wl-message-field): New function.  Return

+ 48 - 3
lisp/org.el

@@ -1295,8 +1295,7 @@ implementation is bad."
   :type 'boolean)
   :type 'boolean)
 
 
 (defcustom org-return-follows-link nil
 (defcustom org-return-follows-link nil
-  "Non-nil means on links RET will follow the link.
-Needs to be set before org.el is loaded."
+  "Non-nil means on links RET will follow the link."
   :group 'org-link-follow
   :group 'org-link-follow
   :type 'boolean)
   :type 'boolean)
 
 
@@ -15463,6 +15462,52 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
   "Return string to be used as color value for an RGB component."
   "Return string to be used as color value for an RGB component."
   (format "%g" (/ value 65535.0)))
   (format "%g" (/ value 65535.0)))
 
 
+;; Image display
+
+
+(defvar org-inline-image-overlays nil)
+(make-variable-buffer-local 'org-inline-image-overlays)
+
+(defun org-toggle-inline-images (&optional include-linked)
+  "Toggle the display of inline images.
+INCLUDE-LINKED is passed to `org-display-inline-images'."
+  (interactive "P")
+  (if org-inline-image-overlays
+      (progn
+	(org-remove-inline-images)
+	(message "Inline image display turned off"))
+    (org-display-inline-images arg)
+    (if org-inline-image-overlays
+	(message "%d images displayed inline"
+		 (length org-inline-image-overlays))
+      (message "No images to display inline"))))
+
+(defun org-display-inline-images (&optional include-linked)
+  "Display inline images.
+Normally only links without a description part are inlined, because this
+is how it will work for export.  When INCLUDE-LINKED is set, also links
+with a description part will be inlined."
+  (interactive "P")
+  (org-remove-inline-images)
+  (goto-char (point-min))
+  (let ((re (concat "\\[\\[\\(file:\\|\\./\\)\\(~?" "[-+./_0-9a-zA-Z]+"
+		    (substring (org-image-file-name-regexp) 0 -2)
+		    "\\)\\]" (if include-linked "" "\\]")))
+	file ov)
+  (while (re-search-forward re nil t)
+    (setq file (expand-file-name (match-string 2)))
+    (when (file-exists-p file)
+      (setq ov (make-overlay (match-beginning 0) (match-end 0)))
+      (overlay-put ov 'display (create-image file))
+      (overlay-put ov 'face 'default)
+      (push ov org-inline-image-overlays)))))
+
+(defun org-remove-inline-images ()
+  "Remove inline display of images."
+  (interactive)
+  (mapc 'delete-overlay org-inline-image-overlays)
+  (setq org-inline-image-overlays nil))
+
 ;;;; Key bindings
 ;;;; Key bindings
 
 
 ;; Make `C-c C-x' a prefix key
 ;; Make `C-c C-x' a prefix key
@@ -15632,6 +15677,7 @@ SNIPPETS-P indicates if this is run to create snippet images for HTML."
 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
 (org-defkey org-mode-map "\C-c\C-x\C-r" 'org-clock-report)
 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
 (org-defkey org-mode-map "\C-c\C-x\C-u" 'org-dblock-update)
 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
 (org-defkey org-mode-map "\C-c\C-x\C-l" 'org-preview-latex-fragment)
+(org-defkey org-mode-map "\C-c\C-x\C-v" 'org-toggle-inline-images)
 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
 (org-defkey org-mode-map "\C-c\C-xp"    'org-set-property)
 (org-defkey org-mode-map "\C-c\C-xp"    'org-set-property)
 (org-defkey org-mode-map "\C-c\C-xe"    'org-set-effort)
 (org-defkey org-mode-map "\C-c\C-xe"    'org-set-effort)
@@ -18636,7 +18682,6 @@ To get rid of the restriction, use \\[org-agenda-remove-restriction-lock]."
      (add-hook 'speedbar-visiting-tag-hook
      (add-hook 'speedbar-visiting-tag-hook
 	       (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
 	       (lambda () (and (org-mode-p) (org-show-context 'org-goto))))))
 
 
-
 ;;; Fixes and Hacks for problems with other packages
 ;;; Fixes and Hacks for problems with other packages
 
 
 ;; Make flyspell not check words in links, to not mess up our keymap
 ;; Make flyspell not check words in links, to not mess up our keymap