diff options
| author | Chong Yidong | 2013-01-19 18:34:07 +0800 |
|---|---|---|
| committer | Chong Yidong | 2013-01-19 18:34:07 +0800 |
| commit | 2a43515aaa0d15eba867947340340f9e4fb5d116 (patch) | |
| tree | dec8ef10e44f9488e52284cc5e1274c60442563e | |
| parent | b3fbb3956cda29770670ac02d04804cee0c74f86 (diff) | |
| download | emacs-2a43515aaa0d15eba867947340340f9e4fb5d116.tar.gz emacs-2a43515aaa0d15eba867947340340f9e4fb5d116.zip | |
* image-mode.el (image-mode-fit-frame): Add a frame argument.
Suggested by Drew Adams. Handle window decorations;
save and restore the old window configuration.
Fixes: debbugs:7730
| -rw-r--r-- | etc/NEWS | 7 | ||||
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/image-mode.el | 64 |
3 files changed, 56 insertions, 21 deletions
| @@ -109,6 +109,13 @@ amounts of data into the ERC input. | |||
| 109 | *** The icomplete-separator is customizable, and its default has changed. | 109 | *** The icomplete-separator is customizable, and its default has changed. |
| 110 | *** Removed icomplete-show-key-bindings. | 110 | *** Removed icomplete-show-key-bindings. |
| 111 | 111 | ||
| 112 | ** Image mode | ||
| 113 | --- | ||
| 114 | *** The command `image-mode-fit-frame' deletes other windows. | ||
| 115 | When toggling, it restores the frame's previous window configuration. | ||
| 116 | It also has an optional frame argument, which can be used by Lisp | ||
| 117 | callers to fit the image to a frame other than the selected frame. | ||
| 118 | |||
| 112 | ** Isearch | 119 | ** Isearch |
| 113 | 120 | ||
| 114 | *** `C-x 8 RET' in Isearch mode reads a character by its Unicode name | 121 | *** `C-x 8 RET' in Isearch mode reads a character by its Unicode name |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 0905c20381a..f63e9ecafe8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2013-01-19 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * image-mode.el (image-mode-fit-frame): Add a frame argument. | ||
| 4 | Suggested by Drew Adams (Bug#7730). Handle window decorations; | ||
| 5 | save and restore the old window configuration. | ||
| 6 | |||
| 1 | 2013-01-18 Leo Liu <sdl.web@gmail.com> | 7 | 2013-01-18 Leo Liu <sdl.web@gmail.com> |
| 2 | 8 | ||
| 3 | * progmodes/js.el: Tweak autoload cookie for alias. | 9 | * progmodes/js.el: Tweak autoload cookie for alias. |
diff --git a/lisp/image-mode.el b/lisp/image-mode.el index a95dde1d999..bbb72335aa3 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el | |||
| @@ -278,28 +278,50 @@ stopping if the top or bottom edge of the image is reached." | |||
| 278 | 278 | ||
| 279 | ;; Adjust frame and image size. | 279 | ;; Adjust frame and image size. |
| 280 | 280 | ||
| 281 | (defun image-mode-fit-frame () | 281 | (defun image-mode-fit-frame (&optional frame toggle) |
| 282 | "Toggle whether to fit the frame to the current image. | 282 | "Fit FRAME to the current image. |
| 283 | This function assumes the current frame has only one window." | 283 | If FRAME is omitted or nil, it defaults to the selected frame. |
| 284 | ;; FIXME: This does not take into account decorations like mode-line, | 284 | All other windows on the frame are deleted. |
| 285 | ;; minibuffer, header-line, ... | 285 | |
| 286 | (interactive) | 286 | If called interactively, or if TOGGLE is non-nil, toggle between |
| 287 | (let* ((saved (frame-parameter nil 'image-mode-saved-size)) | 287 | fitting FRAME to the current image and restoring the size and |
| 288 | window configuration prior to the last `image-mode-fit-frame' | ||
| 289 | call." | ||
| 290 | (interactive (list nil t)) | ||
| 291 | (let* ((buffer (current-buffer)) | ||
| 288 | (display (image-get-display-property)) | 292 | (display (image-get-display-property)) |
| 289 | (size (image-display-size display))) | 293 | (size (image-display-size display)) |
| 290 | (if (and saved | 294 | (saved (frame-parameter frame 'image-mode-saved-params)) |
| 291 | (eq (caar saved) (frame-width)) | 295 | (window-configuration (current-window-configuration frame)) |
| 292 | (eq (cdar saved) (frame-height))) | 296 | (width (frame-width frame)) |
| 293 | (progn ;; Toggle back to previous non-fitted size. | 297 | (height (frame-height frame))) |
| 294 | (set-frame-parameter nil 'image-mode-saved-size nil) | 298 | (with-selected-frame (or frame (selected-frame)) |
| 295 | (setq size (cdr saved))) | 299 | (if (and toggle saved |
| 296 | ;; Round up size, and save current size so we can toggle back to it. | 300 | (= (caar saved) width) |
| 297 | (setcar size (ceiling (car size))) | 301 | (= (cdar saved) height)) |
| 298 | (setcdr size (ceiling (cdr size))) | 302 | (progn |
| 299 | (set-frame-parameter nil 'image-mode-saved-size | 303 | (set-frame-width frame (car (nth 1 saved))) |
| 300 | (cons size (cons (frame-width) (frame-height))))) | 304 | (set-frame-height frame (cdr (nth 1 saved))) |
| 301 | (set-frame-width (selected-frame) (car size)) | 305 | (set-window-configuration (nth 2 saved)) |
| 302 | (set-frame-height (selected-frame) (cdr size)))) | 306 | (set-frame-parameter frame 'image-mode-saved-params nil)) |
| 307 | (delete-other-windows) | ||
| 308 | (switch-to-buffer buffer t t) | ||
| 309 | (let* ((edges (window-inside-edges)) | ||
| 310 | (inner-width (- (nth 2 edges) (nth 0 edges))) | ||
| 311 | (inner-height (- (nth 3 edges) (nth 1 edges)))) | ||
| 312 | (set-frame-width frame (+ (ceiling (car size)) | ||
| 313 | width (- inner-width))) | ||
| 314 | (set-frame-height frame (+ (ceiling (cdr size)) | ||
| 315 | height (- inner-height))) | ||
| 316 | ;; The frame size after the above `set-frame-*' calls may | ||
| 317 | ;; differ from what we specified, due to window manager | ||
| 318 | ;; interference. We have to call `frame-width' and | ||
| 319 | ;; `frame-height' to get the actual results. | ||
| 320 | (set-frame-parameter frame 'image-mode-saved-params | ||
| 321 | (list (cons (frame-width) | ||
| 322 | (frame-height)) | ||
| 323 | (cons width height) | ||
| 324 | window-configuration))))))) | ||
| 303 | 325 | ||
| 304 | ;;; Image Mode setup | 326 | ;;; Image Mode setup |
| 305 | 327 | ||