unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#7730: 24.0.50; `image-mode-fit-frame': add optional FRAME arg
@ 2010-12-24 23:45 Drew Adams
  2013-01-19 10:36 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Drew Adams @ 2010-12-24 23:45 UTC (permalink / raw)
  To: 7730

Here's a possible enhancement to `image-mode-fit-frame'.
These are the differences:
 
1. Added an optional FRAME arg.
 
2. The command only toggles if called interactively (actually, if the
first arg is non-nil).
 
#1 means you can use it for another frame.  #2 means that only
 interactive calls save the previous frame size and alternate between
 fitting and restoring the old size.
 
Also, at the end of the function I changed the separate calls to
`set-frame-width' and `set-frame-height' to a single call to
`set-frame-size'.  I did that because I was seeing that the frame was
not getting resized to fit in some cases.  Dunno if there is a bug
associated with that.

FWIW, in my own use of this, my general command `fit-frame' calls it
for Emacs 23+ if the FRAME is in `image-mode' or `image-minor-mode':

(if (and (fboundp 'image-mode-fit-frame) ; Emacs 23+
         (if (or (null frame) (eq frame (selected-frame)))
             (or (eq major-mode 'image-mode) image-minor-mode)
           (save-window-excursion
             (select-frame frame)
             (or (eq major-mode 'image-mode) image-minor-mode))))
      (fit-frame-to-image (interactive-p) frame)
  ...)

(I also use a different name for the command.)
 
(defun fit-frame-to-image (interactivep &optional frame)
  "Fit FRAME to the current image.
If FRAME is not the selected frame, fit it to its first image.
Interactively, if frame has already been fit to the image, then
 restore the size from before it was fit.
This function assumes that FRAME has only one window."
  ;; FIXME: This does not take into account decorations
  ;; like mode-line, minibuffer, header-line, ...
  (interactive "p")
  (let* ((saved    (frame-parameter frame 'image-mode-saved-size))
         (display  (if (or (null frame) (equal frame (selected-frame)))
                       (image-get-display-property)
                     (save-selected-window (select-frame frame)
                                           (image-get-display-property))))
         (size     (image-display-size display nil frame)))
    (setq frame  (or frame (selected-frame)))
    (if (and interactivep saved
             (eq (caar saved) (frame-width frame))
             (eq (cdar saved) (frame-height frame)))
        (progn ; Restore previous size, before it was fit.
          (set-frame-parameter frame '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
       frame 'image-mode-saved-size
       (cons size (cons (frame-width frame) (frame-height frame)))))
    (set-frame-size frame (car size) (cdr size))))
 

In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
 of 2010-12-20 on 3249CTO
Windowing system distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-gcc (4.4) --no-opt --cflags
-Ic:/imagesupport/include'
 






^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#7730: 24.0.50; `image-mode-fit-frame': add optional FRAME arg
  2010-12-24 23:45 bug#7730: 24.0.50; `image-mode-fit-frame': add optional FRAME arg Drew Adams
@ 2013-01-19 10:36 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2013-01-19 10:36 UTC (permalink / raw)
  To: Drew Adams; +Cc: 7730-done

"Drew Adams" <drew.adams@oracle.com> writes:

> Here's a possible enhancement to `image-mode-fit-frame'.
>  
> 1. Added an optional FRAME arg.
>  
> 2. The command only toggles if called interactively (actually, if the
> first arg is non-nil).

Thanks.  I've committed something similar.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-01-19 10:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-24 23:45 bug#7730: 24.0.50; `image-mode-fit-frame': add optional FRAME arg Drew Adams
2013-01-19 10:36 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).