• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/

Lines Matching +defs:shrink +defs:window

0 ;;; window.el --- GNU Emacs window commands aside from those written in C
32 (defvar window-size-fixed nil
34 If the value is `height', then only the window's height is fixed.
35 If the value is `width', then only the window's width is fixed.
37 Emacs won't change the size of any window displaying that buffer,
39 (make-variable-buffer-local 'window-size-fixed)
41 (defmacro save-selected-window (&rest body)
42 "Execute BODY, then select the window that was selected before BODY.
49 This macro saves and restores the selected window, as well as
50 the selected window in each frame. If the previously selected
51 window of some frame is no longer live at the end of BODY, that
52 frame's selected window is left alone. If the selected window is
53 no longer live, then whatever window is selected at the end of
55 `(let ((save-selected-window-window (selected-window))
57 ;; select-window changes frame-selected-window for whatever
58 ;; frame that window is in.
59 (save-selected-window-alist
60 (mapcar (lambda (frame) (list frame (frame-selected-window frame)))
65 (dolist (elt save-selected-window-alist)
67 (window-live-p (cadr elt))
68 (set-frame-selected-window (car elt) (cadr elt))))
69 (if (window-live-p save-selected-window-window)
70 (select-window save-selected-window-window))))))
72 (defun window-body-height (&optional window)
73 "Return number of lines in window WINDOW for actual buffer text.
75 (or window (setq window (selected-window)))
76 (if (window-minibuffer-p window)
77 (window-height window)
78 (with-current-buffer (window-buffer window)
79 (max 1 (- (window-height window)
83 (defun one-window-p (&optional nomini all-frames)
84 "Return non-nil if the selected window is the only window.
95 (let ((base-window (selected-window)))
96 (if (and nomini (eq base-window (minibuffer-window)))
97 (setq base-window (next-window base-window)))
98 (eq base-window
99 (next-window base-window (if nomini 'arg) all-frames))))
101 (defun window-current-scroll-bars (&optional window)
102 "Return the current scroll-bar settings in window WINDOW.
107 (let ((vert (nth 2 (window-scroll-bars window)))
111 (window-frame (or window (selected-window))))))
120 PROC is called with a window as argument.
122 Optional second arg MINIBUF t means count the minibuffer window even
132 entered the minibuffer, as well as the minibuffer window.
141 ;; If we start from the minibuffer window, don't fail to come back to it.
142 (if (window-minibuffer-p (selected-window))
144 (save-selected-window
146 (select-window (frame-first-window all-frames)))
148 (walk-windows-current (selected-window)))
151 (next-window walk-windows-current minibuf all-frames))
157 (defun get-window-with-predicate (predicate &optional minibuf
159 "Return a window satisfying PREDICATE.
162 calling PREDICATE on each one. PREDICATE is called with a window as
163 argument. The first window for which PREDICATE returns a non-nil
164 value is returned. If no window satisfies PREDICATE, DEFAULT is
167 Optional second arg MINIBUF t means count the minibuffer window even
177 entered the minibuffer, as well as the minibuffer window.
187 (walk-windows #'(lambda (window)
188 (when (funcall predicate window)
189 (throw 'found window)))
193 (defalias 'some-window 'get-window-with-predicate)
196 (defun get-buffer-window-list (buffer &optional minibuf frame)
201 (walk-windows (function (lambda (window)
202 (if (eq (window-buffer window) buffer)
203 (setq windows (cons window windows)))))
207 (defun minibuffer-window-active-p (window)
208 "Return t if WINDOW (a minibuffer window) is now active."
209 (eq window (active-minibuffer-window)))
224 (defun window-safely-shrinkable-p (&optional window)
226 If WINDOW is nil or omitted, it defaults to the currently selected window."
227 (with-selected-window (or window (selected-window))
228 (let ((edges (window-edges)))
229 (or (= (nth 2 edges) (nth 2 (window-edges (previous-window))))
230 (= (nth 0 edges) (nth 0 (window-edges (next-window))))))))
235 ;;; `balance-windows' subroutines using `window-tree'
237 ;;; Translate from internal window tree format
239 (defun bw-get-tree (&optional window-or-frame)
240 "Get a window split tree in our format.
242 WINDOW-OR-FRAME must be nil, a frame, or a window. If it is nil,
243 then the whole window split tree for `selected-frame' is returned.
244 If it is a frame, then this is used instead. If it is a window,
245 then the smallest tree containing that window is returned."
246 (when window-or-frame
247 (unless (or (framep window-or-frame)
248 (windowp window-or-frame))
249 (error "Not a frame or window: %s" window-or-frame)))
250 (let ((subtree (bw-find-tree-sub window-or-frame)))
270 (defun bw-find-tree-sub (window-or-frame &optional get-parent)
271 (let* ((window (when (windowp window-or-frame) window-or-frame))
272 (frame (when (windowp window) (window-frame window)))
273 (wt (car (window-tree frame))))
274 (when (< 1 (length (window-list frame 0)))
275 (if window
276 (bw-find-tree-sub-1 wt window get-parent)
280 (unless (windowp win) (error "Not a window: %s" win))
305 (if (windowp obj) (nth 0 (window-edges obj)) (cdr (assq 'l obj))))
308 (if (windowp obj) (nth 1 (window-edges obj)) (cdr (assq 't obj))))
311 (if (windowp obj) (nth 2 (window-edges obj)) (cdr (assq 'r obj))))
314 (if (windowp obj) (nth 3 (window-edges obj)) (cdr (assq 'b obj))))
319 "Return window split tree direction if OBJ.
320 If OBJ is a window return 'both. If it is a window split tree
332 "Return t if window split tree directions are equal.
333 OBJ1 and OBJ2 should be either windows or window split trees in
370 (defun balance-windows (&optional window-or-frame)
371 "Make windows the same heights or widths in window split subtrees.
374 window or a frame. It then balances the windows on the implied
375 frame. If the parameter is a window only the corresponding window
379 (wt (bw-get-tree window-or-frame))
384 (windows (window-list nil 0))
390 (window-edges w))
398 (defun bw-adjust-window (window delta horizontal)
399 "Wrapper around `adjust-window-trailing-edge' with error checking.
402 (adjust-window-trailing-edge window delta horizontal)
416 (bw-adjust-window wt dw t))))
420 (bw-adjust-window wt dh nil)))))
432 (defcustom split-window-keep-point t
433 "*If non-nil, \\[split-window-vertically] keeps the original point \
439 This option applies only to `split-window-vertically' and
440 functions that call it. `split-window' always keeps the original
445 (defun split-window-vertically (&optional arg)
446 "Split current window into two windows, one above the other.
447 The uppermost window gets ARG lines and the other gets the rest.
448 Negative ARG means select the size of the lowermost window instead.
452 If the variable `split-window-keep-point' is non-nil, both new windows
453 will get the same value of point as the current window. This is often
454 more convenient for editing. The upper window is the selected window.
456 Otherwise, we choose window starts so as to minimize the amount of
458 window is the one that the current value of point appears in. The
462 Regardless of the value of `split-window-keep-point', the upper
463 window is the original one and the return value is the new, lower
464 window."
466 (let ((old-w (selected-window))
469 (window-full-p nil)
471 (and size (< size 0) (setq size (+ (window-height) size)))
472 (setq new-w (split-window nil size))
473 (or split-window-keep-point
476 (set-buffer (window-buffer))
477 (goto-char (window-start))
478 (setq moved (vertical-motion (window-height)))
479 (set-window-start new-w (point))
480 (if (> (point) (window-point new-w))
481 (set-window-point new-w (point)))
482 (and (= moved (window-height))
484 (setq window-full-p t)
487 (and window-full-p
489 (set-window-point old-w (1- bottom)))
490 (and window-full-p
491 (<= (window-start new-w) old-point)
493 (set-window-point new-w old-point)
494 (select-window new-w)))))
495 (split-window-save-restore-data new-w old-w)))
500 (defun split-window-save-restore-data (new-w old-w)
501 (with-current-buffer (window-buffer)
509 (defun split-window-horizontally (&optional arg)
510 "Split current window into two windows side by side.
511 This window becomes the leftmost of the two, and gets ARG columns.
512 Negative ARG means select the size of the rightmost window instead.
513 The argument includes the width of the window's scroll bar; if there
515 to the window's right, if any. No ARG means split equally.
517 The original, leftmost window remains selected.
518 The return value is the new, rightmost window."
520 (let ((old-w (selected-window))
523 (setq size (+ (window-width) size)))
524 (split-window-save-restore-data (split-window nil size t) old-w)))
528 (defun set-window-text-height (window height)
533 If WINDOW is nil, the selected window is used.
538 (let ((delta (- height (window-text-height window))))
540 ;; Setting window-min-height to a value like 1 can lead to very
544 (let ((window-min-height (min 2 height))) ;One text line plus a modeline.
545 (if (and window (not (eq window (selected-window))))
546 (save-selected-window
547 (select-window window)
548 (enlarge-window delta))
549 (enlarge-window delta))))))
553 (defun enlarge-window-horizontally (arg)
554 "Make current window ARG columns wider."
556 (enlarge-window arg t))
558 (defun shrink-window-horizontally (arg)
559 "Make current window ARG columns narrower."
561 (shrink-window arg t))
563 (defun window-buffer-height (window)
565 (with-current-buffer (window-buffer window)
571 window))))
573 (defun count-screen-lines (&optional beg end count-final-newline window)
584 The optional fourth argument WINDOW specifies the window used for obtaining
586 to use the selected window's parameters.
591 in some window."
607 (1+ (vertical-motion (buffer-size) window))))))
609 (defun fit-window-to-buffer (&optional window max-height min-height)
611 If WINDOW is omitted or nil, it defaults to the selected window.
613 the window is allowed to be, defaulting to the frame height.
615 height the window is allowed to be, defaulting to `window-min-height'.
621 (when (null window)
622 (setq window (selected-window)))
624 (setq max-height (frame-height (window-frame window))))
628 (window-buffer window))
629 (window-height
631 (window-height window))
643 (if (and (not (window-minibuffer-p window))
649 ;; Calculate how much the window height has to change to show
652 (or min-height window-min-height))
653 window-height))
655 ;; window-min-height.
656 (window-min-height 1))
662 (set-window-point window (1- (window-point window))))
664 (save-selected-window
665 (select-window window)
670 (enlarge-window delta))
673 ;; enlarge the window.
685 ;; the edge of the window.
688 (set-window-vscroll window 0)
690 (= desired-height (window-height window))
691 (not (pos-visible-in-window-p end window)))
692 (enlarge-window 1)
695 (defun shrink-window-if-larger-than-buffer (&optional window)
697 If WINDOW is omitted or nil, it defaults to the selected window.
698 Do not shrink to less than `window-min-height' lines.
699 Do nothing if the buffer contains more lines than the present window height,
700 or if some of the window's contents are scrolled out of view,
701 or if shrinking this window would also shrink another window,
702 or if the window is the only window of its frame."
704 (when (null window)
705 (setq window (selected-window)))
706 (let* ((frame (window-frame window))
708 (edges (window-edges window)))
709 (if (and (not (eq window (frame-root-window frame)))
710 (window-safely-shrinkable-p)
711 (pos-visible-in-window-p (point-min) window)
714 (let ((mini-window (minibuffer-window frame)))
715 (or (null mini-window)
716 (not (eq frame (window-frame mini-window)))
718 (nth 1 (window-edges mini-window)))
721 (fit-window-to-buffer window (window-height window)))))
723 (defun kill-buffer-and-window ()
724 "Kill the current buffer and delete the selected window."
726 (let ((window-to-delete (selected-window))
728 (delete-window-hook (lambda ()
730 (delete-window)
734 (add-hook 'kill-buffer-hook delete-window-hook t t)
736 ;; If `delete-window' failed before, we rerun it to regenerate
738 (when (eq (selected-window) window-to-delete)
739 (delete-window))))
744 (remove-hook 'kill-buffer-hook delete-window-hook t))
747 (defun quit-window (&optional kill window)
749 \(The frame is deleted if it contains a dedicated window for the buffer.)
755 If WINDOW is non-nil, it specifies a window; we delete that window,
756 and the buffer that is killed or buried is the one in that window."
758 (let ((buffer (window-buffer window))
759 (frame (window-frame (or window (selected-window))))
760 (window-solitary
761 (save-selected-window
762 (if window
763 (select-window window))
764 (one-window-p t)))
765 window-handled)
767 (save-selected-window
768 (if window
769 (select-window window))
770 (or (window-minibuffer-p)
771 (window-dedicated-p (selected-window))
774 ;; Get rid of the frame, if it has just one dedicated window
776 (and (or (window-minibuffer-p) (window-dedicated-p window))
778 window-solitary
781 (setq window nil)
783 (setq window-handled t)))
790 ;; Maybe get rid of the window.
791 (and window (not window-handled) (not window-solitary)
792 (delete-window window))))
795 (defvar mouse-autoselect-window-timer nil
796 "Timer used by delayed window autoselection.")
798 (defvar mouse-autoselect-window-position nil
799 "Last mouse position recorded by delayed window autoselection.")
801 (defvar mouse-autoselect-window-window nil
802 "Last window recorded by delayed window autoselection.")
804 (defvar mouse-autoselect-window-state nil
805 "When non-nil, special state of delayed window autoselection.
808 'handle-select-window' shall select the window immediately\).")
810 (defun mouse-autoselect-window-cancel (&optional force)
811 "Cancel delayed window autoselection.
818 (setq mouse-autoselect-window-state nil)
819 (when (timerp mouse-autoselect-window-timer)
820 (cancel-timer mouse-autoselect-window-timer))
821 (remove-hook 'pre-command-hook 'mouse-autoselect-window-cancel)))
823 (defun mouse-autoselect-window-start (mouse-position &optional window suspend)
824 "Start delayed window autoselection.
827 window where the mouse was seen. Optional argument SUSPEND non-nil
830 (setq mouse-autoselect-window-position mouse-position)
831 (when window (setq mouse-autoselect-window-window window))
832 (setq mouse-autoselect-window-state (when suspend 'suspend))
833 ;; Install timer which runs `mouse-autoselect-window-select' after
834 ;; `mouse-autoselect-window' seconds.
835 (setq mouse-autoselect-window-timer
837 (abs mouse-autoselect-window) nil 'mouse-autoselect-window-select)))
839 (defun mouse-autoselect-window-select ()
840 "Select window with delayed window autoselection.
841 If the mouse position has stabilized in a non-selected window, select
842 that window. The minibuffer window is selected iff the minibuffer is
843 active. This function is run by `mouse-autoselect-window-timer'."
846 (window
848 (window-at (cadr mouse-position) (cddr mouse-position)
853 (and window
854 (not (coordinates-in-window-p (cdr mouse-position) window))))
857 (mouse-autoselect-window-start mouse-position nil t))
858 ((eq mouse-autoselect-window-state 'suspend)
860 (mouse-autoselect-window-start mouse-position))
861 ((and window (not (eq window (selected-window)))
862 (or (not (numberp mouse-autoselect-window))
863 (and (> mouse-autoselect-window 0)
864 ;; If `mouse-autoselect-window' is positive, select
865 ;; window if the window is the same as before.
866 (eq window mouse-autoselect-window-window))
867 ;; Otherwise select window iff the mouse is at the same
870 ;; `mouse-autoselect-window-position' recorded there is the
871 ;; position where the mouse has entered the new window and
873 (equal mouse-position mouse-autoselect-window-position))
874 ;; The minibuffer is a candidate window iff it's active.
875 (or (not (window-minibuffer-p window))
876 (eq window (active-minibuffer-window))))
877 ;; Mouse position has stabilized in non-selected window: Cancel
878 ;; delayed autoselection and try to select that window.
879 (mouse-autoselect-window-cancel t)
880 ;; Select window where mouse appears unless the selected window is the
883 ;; autoselection again, set `mouse-autoselect-window-state'."
884 (unless (window-minibuffer-p (selected-window))
885 (setq mouse-autoselect-window-state 'select)
887 (cons (list 'select-window (list window))
889 ((or (and window (eq window (selected-window)))
890 (not (numberp mouse-autoselect-window))
891 (equal mouse-position mouse-autoselect-window-position))
892 ;; Mouse position has either stabilized in the selected window or at
893 ;; `mouse-autoselect-window-position': Cancel delayed autoselection.
894 (mouse-autoselect-window-cancel t))
898 (mouse-autoselect-window-start mouse-position window))))
901 (defun handle-select-window (event)
902 "Handle select-window events."
904 (let ((window (posn-window (event-start event))))
905 (when (and (window-live-p window)
910 (not (window-minibuffer-p (selected-window)))
911 ;; Don't switch to a minibuffer window unless it's active.
912 (or (not (window-minibuffer-p window))
913 (minibuffer-window-active-p window)))
914 (unless (and (numberp mouse-autoselect-window)
915 (not (zerop mouse-autoselect-window))
916 (not (eq mouse-autoselect-window-state 'select))
919 (mouse-autoselect-window-cancel t)
921 ;; and window.
922 (mouse-autoselect-window-start (mouse-position) window)
925 'pre-command-hook 'mouse-autoselect-window-cancel)))
927 (setq mouse-autoselect-window-state nil)
928 (when mouse-autoselect-window
929 ;; Run `mouse-leave-buffer-hook' when autoselecting window.
931 (select-window window)))))
933 (define-key ctl-x-map "2" 'split-window-vertically)
934 (define-key ctl-x-map "3" 'split-window-horizontally)
935 (define-key ctl-x-map "}" 'enlarge-window-horizontally)
936 (define-key ctl-x-map "{" 'shrink-window-horizontally)
937 (define-key ctl-x-map "-" 'shrink-window-if-larger-than-buffer)
939 (define-key ctl-x-4-map "0" 'kill-buffer-and-window)
942 ;;; window.el ends here