changeset 93562:01f16f0a9645

(image-mode-fit-frame): New command.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Thu, 03 Apr 2008 02:19:23 +0000
parents e39e5bb86d6b
children c505d070db06
files lisp/ChangeLog lisp/image-mode.el
diffstat 2 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Thu Apr 03 02:16:17 2008 +0000
+++ b/lisp/ChangeLog	Thu Apr 03 02:19:23 2008 +0000
@@ -1,5 +1,7 @@
 2008-04-03  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* image-mode.el (image-mode-fit-frame): New command.
+
 	* simple.el (beginning-of-buffer, end-of-buffer, goto-line, undo)
 	(copy-region-as-kill, kill-ring-save, use-region-p, mark-word)
 	(keyboard-escape-quit): Check region-active-p i.s.o transient-mark-mode.
--- a/lisp/image-mode.el	Thu Apr 03 02:16:17 2008 +0000
+++ b/lisp/image-mode.el	Thu Apr 03 02:19:23 2008 +0000
@@ -244,6 +244,31 @@
     (image-set-window-hscroll (max 0 (- img-width win-width)))
     (image-set-window-vscroll (max 0 (- img-height win-height)))))
 
+;; Adjust frame and image size.
+
+(defun image-mode-fit-frame ()
+  "Fit the frame to the current image.
+This function assumes the current frame has only one window."
+  ;; FIXME: This does not take into account decorations like mode-line,
+  ;; minibuffer, header-line, ...
+  (interactive)
+  (let* ((saved (frame-parameter nil 'image-mode-saved-size))
+         (display (image-get-display-property))
+         (size (image-size display)))
+    (if (and saved
+             (eq (caar saved) (frame-width))
+             (eq (cdar saved) (frame-height)))
+        (progn ;; Toggle back to previous non-fitted size.
+          (set-frame-parameter nil 'image-mode-saved-size nil)
+          (setq size (cdr saved)))
+      ;; Round up size, and save current size so we can toggle back to it.
+      (setcar size (ceiling (car size)))
+      (setcdr size (ceiling (cdr size)))
+      (set-frame-parameter nil 'image-mode-saved-size
+                           (cons size (cons (frame-width) (frame-height)))))
+    (set-frame-width  (selected-frame) (car size))
+    (set-frame-height (selected-frame) (cdr size))))
+
 ;;; Image Mode setup
 
 (defvar image-type nil