]> code.delx.au - gnu-emacs/commitdiff
(image-mode-fit-frame): New command.
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 3 Apr 2008 02:19:23 +0000 (02:19 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Thu, 3 Apr 2008 02:19:23 +0000 (02:19 +0000)
lisp/ChangeLog
lisp/image-mode.el

index 2ad26207d6df2df1cad0b1d6018ac8733c8220d3..4bb89f6bc21c1aac9f9010581d77710a789f9bd0 100644 (file)
@@ -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.
index fc38f045ff9e42675a0079df1299125934ce1a02..2fe1cdc88e6a515b9550dc906f8ebe86e0164b4a 100644 (file)
@@ -244,6 +244,31 @@ stopping if the top or bottom edge of the image is reached."
     (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