aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorMartin Rudalics2011-06-07 11:26:21 +0200
committerMartin Rudalics2011-06-07 11:26:21 +0200
commitabde8f8c7b14b0a851dc0dec23e7444550a148cf (patch)
tree5c7a5ac601f71f165fc3361bda5583d28dbaf196 /src/window.c
parent81eafe297773904d0a532328d27d658dde29be99 (diff)
downloademacs-abde8f8c7b14b0a851dc0dec23e7444550a148cf.tar.gz
emacs-abde8f8c7b14b0a851dc0dec23e7444550a148cf.zip
Install some window-size related functions and window-list-1.
* window.c (Fwindow_total_size, Fwindow_left_column) (Fwindow_top_line, window_body_lines, Fwindow_body_size) (Fwindow_list_1): New functions. (window_box_text_cols): Replace with window_body_cols. (Fwindow_width, Fscroll_left, Fscroll_right): Use window_body_cols instead of window_box_text_cols. * window.h: Extern window_body_cols instead of window_box_text_cols. * indent.c (compute_motion, Fcompute_motion): Use window_body_cols instead of window_box_text_cols.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c236
1 files changed, 176 insertions, 60 deletions
diff --git a/src/window.c b/src/window.c
index 4e8b98a3237..43635fe5a6b 100644
--- a/src/window.c
+++ b/src/window.c
@@ -691,9 +691,115 @@ Return nil if window display is not up-to-date. In that case, use
691 make_number (row->y), 691 make_number (row->y),
692 make_number (crop)); 692 make_number (crop));
693} 693}
694
695DEFUN ("window-total-size", Fwindow_total_size, Swindow_total_size, 0, 2, 0,
696 doc: /* Return the total number of lines of WINDOW.
697WINDOW can be any window and defaults to the selected one. The return
698value includes WINDOW's mode line and header line, if any. If WINDOW
699is internal, the return value is the sum of the total number of lines
700of WINDOW's child windows if these are vertically combined and the
701height of WINDOW's first child otherwise.
702
703Optional argument HORIZONTAL non-nil means return the total number of
704columns of WINDOW. In this case the return value includes any vertical
705dividers or scrollbars of WINDOW. If WINDOW is internal, the return
706value is the sum of the total number of columns of WINDOW's child
707windows if they are horizontally combined and the width of WINDOW's
708first child otherwise. */)
709 (Lisp_Object window, Lisp_Object horizontal)
710{
711 if (NILP (horizontal))
712 return decode_any_window (window)->total_lines;
713 else
714 return decode_any_window (window)->total_cols;
715}
694 716
717DEFUN ("window-left-column", Fwindow_left_column, Swindow_left_column, 0, 1, 0,
718 doc: /* Return left column of WINDOW.
719WINDOW can be any window and defaults to the selected one. */)
720 (Lisp_Object window)
721{
722 return decode_any_window (window)->left_col;
723}
724
725DEFUN ("window-top-line", Fwindow_top_line, Swindow_top_line, 0, 1, 0,
726 doc: /* Return top line of WINDOW.
727WINDOW can be any window and defaults to the selected one. */)
728 (Lisp_Object window)
729{
730 return decode_any_window (window)->top_line;
731}
732
733/* Return the number of lines of W's body. Don't count any mode or
734 header line of W. */
735
736int
737window_body_lines (struct window *w)
738{
739 int height = XFASTINT (w->total_lines);
740
741 if (!MINI_WINDOW_P (w))
742 {
743 if (WINDOW_WANTS_MODELINE_P (w))
744 --height;
745 if (WINDOW_WANTS_HEADER_LINE_P (w))
746 --height;
747 }
748
749 return height;
750}
751
752/* Return the number of columns of W's body. Don't count columns
753 occupied by the scroll bar or the vertical bar separating W from its
754 right sibling. On window-systems don't count fringes or display
755 margins either. */
756
757int
758window_body_cols (struct window *w)
759{
760 struct frame *f = XFRAME (WINDOW_FRAME (w));
761 int width = XINT (w->total_cols);
762
763 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
764 /* Scroll bars occupy a few columns. */
765 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
766 else if (!FRAME_WINDOW_P (f)
767 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
768 /* The column of `|' characters separating side-by-side windows
769 occupies one column only. */
770 width -= 1;
771
772 if (FRAME_WINDOW_P (f))
773 /* On window-systems, fringes and display margins cannot be
774 used for normal text. */
775 width -= (WINDOW_FRINGE_COLS (w)
776 + WINDOW_LEFT_MARGIN_COLS (w)
777 + WINDOW_RIGHT_MARGIN_COLS (w));
778
779 return width;
780}
781
782DEFUN ("window-body-size", Fwindow_body_size, Swindow_body_size, 0, 2, 0,
783 doc: /* Return the number of lines of WINDOW's body.
784WINDOW must be a live window and defaults to the selected one. The
785return value does not include WINDOW's mode line and header line, if
786any.
787
788Optional argument HORIZONTAL non-nil means return the number of columns
789of WINDOW's body. In this case, the return value does not include any
790vertical dividers or scroll bars owned by WINDOW. On a window-system
791the return value does not include the number of columns used for
792WINDOW's fringes or display margins either. */)
793 (Lisp_Object window, Lisp_Object horizontal)
794{
795 struct window *w = decode_any_window (window);
796
797 if (NILP (horizontal))
798 return make_number (window_body_lines (w));
799 else
800 return make_number (window_body_cols (w));
801}
695 802
696
697DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0, 803DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0,
698 doc: /* Return the number of lines in WINDOW. 804 doc: /* Return the number of lines in WINDOW.
699WINDOW defaults to the selected window. 805WINDOW defaults to the selected window.
@@ -716,7 +822,7 @@ WINDOW. If you want to find out how many columns WINDOW takes up, use
716(let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */) 822(let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
717 (Lisp_Object window) 823 (Lisp_Object window)
718{ 824{
719 return make_number (window_box_text_cols (decode_any_window (window))); 825 return make_number (window_body_cols (decode_any_window (window)));
720} 826}
721 827
722DEFUN ("window-full-width-p", Fwindow_full_width_p, Swindow_full_width_p, 0, 1, 0, 828DEFUN ("window-full-width-p", Fwindow_full_width_p, Swindow_full_width_p, 0, 1, 0,
@@ -2248,6 +2354,43 @@ reverse order. */)
2248} 2354}
2249 2355
2250 2356
2357DEFUN ("window-list-1", Fwindow_list_1, Swindow_list_1, 0, 3, 0,
2358 doc: /* Return a list of all live windows.
2359WINDOW specifies the first window to list and defaults to the selected
2360window.
2361
2362Optional argument MINIBUF nil or omitted means consider the minibuffer
2363window only if the minibuffer is active. MINIBUF t means consider the
2364minibuffer window even if the minibuffer is not active. Any other value
2365means do not consider the minibuffer window even if the minibuffer is
2366active.
2367
2368Optional argument ALL-FRAMES nil or omitted means consider all windows
2369on WINDOW's frame, plus the minibuffer window if specified by the
2370MINIBUF argument. If the minibuffer counts, consider all windows on all
2371frames that share that minibuffer too. The following non-nil values of
2372ALL-FRAMES have special meanings:
2373
2374- t means consider all windows on all existing frames.
2375
2376- `visible' means consider all windows on all visible frames.
2377
2378- 0 (the number zero) means consider all windows on all visible and
2379 iconified frames.
2380
2381- A frame means consider all windows on that frame only.
2382
2383Anything else means consider all windows on WINDOW's frame and no
2384others.
2385
2386If WINDOW is not on the list of windows returned, some other window will
2387be listed first but no error is signalled. */)
2388 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2389{
2390 return window_list_1 (window, minibuf, all_frames);
2391}
2392
2393
2251DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p", 2394DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p",
2252 doc: /* Select another window in cyclic ordering of windows. 2395 doc: /* Select another window in cyclic ordering of windows.
2253COUNT specifies the number of windows to skip, starting with the 2396COUNT specifies the number of windows to skip, starting with the
@@ -2279,29 +2422,6 @@ nil. */)
2279} 2422}
2280 2423
2281 2424
2282DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
2283 doc: /* Return a list of windows on FRAME, starting with WINDOW.
2284FRAME nil or omitted means use the selected frame.
2285WINDOW nil or omitted means use the selected window.
2286MINIBUF t means include the minibuffer window, even if it isn't active.
2287MINIBUF nil or omitted means include the minibuffer window only
2288if it's active.
2289MINIBUF neither nil nor t means never include the minibuffer window. */)
2290 (Lisp_Object frame, Lisp_Object minibuf, Lisp_Object window)
2291{
2292 if (NILP (window))
2293 window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window;
2294 CHECK_WINDOW (window);
2295 if (NILP (frame))
2296 frame = selected_frame;
2297
2298 if (!EQ (frame, XWINDOW (window)->frame))
2299 error ("Window is on a different frame");
2300
2301 return window_list_1 (window, minibuf, frame);
2302}
2303
2304
2305/* Return a list of windows in cyclic ordering. Arguments are like 2425/* Return a list of windows in cyclic ordering. Arguments are like
2306 for `next-window'. */ 2426 for `next-window'. */
2307 2427
@@ -2331,6 +2451,29 @@ window_list_1 (Lisp_Object window, Lisp_Object minibuf, Lisp_Object all_frames)
2331} 2451}
2332 2452
2333 2453
2454DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
2455 doc: /* Return a list of windows on FRAME, starting with WINDOW.
2456FRAME nil or omitted means use the selected frame.
2457WINDOW nil or omitted means use the selected window.
2458MINIBUF t means include the minibuffer window, even if it isn't active.
2459MINIBUF nil or omitted means include the minibuffer window only
2460if it's active.
2461MINIBUF neither nil nor t means never include the minibuffer window. */)
2462 (Lisp_Object frame, Lisp_Object minibuf, Lisp_Object window)
2463{
2464 if (NILP (window))
2465 window = FRAMEP (frame) ? XFRAME (frame)->selected_window : selected_window;
2466 CHECK_WINDOW (window);
2467 if (NILP (frame))
2468 frame = selected_frame;
2469
2470 if (!EQ (frame, XWINDOW (window)->frame))
2471 error ("Window is on a different frame");
2472
2473 return window_list_1 (window, minibuf, frame);
2474}
2475
2476
2334 2477
2335/* Look at all windows, performing an operation specified by TYPE 2478/* Look at all windows, performing an operation specified by TYPE
2336 with argument OBJ. 2479 with argument OBJ.
@@ -4808,37 +4951,6 @@ window_internal_height (struct window *w)
4808 4951
4809 return ht; 4952 return ht;
4810} 4953}
4811
4812
4813/* Return the number of columns in W.
4814 Don't count columns occupied by scroll bars or the vertical bar
4815 separating W from the sibling to its right. */
4816
4817int
4818window_box_text_cols (struct window *w)
4819{
4820 struct frame *f = XFRAME (WINDOW_FRAME (w));
4821 int width = XINT (w->total_cols);
4822
4823 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
4824 /* Scroll bars occupy a few columns. */
4825 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
4826 else if (!FRAME_WINDOW_P (f)
4827 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
4828 /* The column of `|' characters separating side-by-side windows
4829 occupies one column only. */
4830 width -= 1;
4831
4832 if (FRAME_WINDOW_P (f))
4833 /* On window-systems, fringes and display margins cannot be
4834 used for normal text. */
4835 width -= (WINDOW_FRINGE_COLS (w)
4836 + WINDOW_LEFT_MARGIN_COLS (w)
4837 + WINDOW_RIGHT_MARGIN_COLS (w));
4838
4839 return width;
4840}
4841
4842 4954
4843/************************************************************************ 4955/************************************************************************
4844 Window Scrolling 4956 Window Scrolling
@@ -5547,7 +5659,7 @@ by this function. This happens in an interactive call. */)
5547 struct window *w = XWINDOW (selected_window); 5659 struct window *w = XWINDOW (selected_window);
5548 5660
5549 if (NILP (arg)) 5661 if (NILP (arg))
5550 XSETFASTINT (arg, window_box_text_cols (w) - 2); 5662 XSETFASTINT (arg, window_body_cols (w) - 2);
5551 else 5663 else
5552 arg = Fprefix_numeric_value (arg); 5664 arg = Fprefix_numeric_value (arg);
5553 5665
@@ -5576,7 +5688,7 @@ by this function. This happens in an interactive call. */)
5576 struct window *w = XWINDOW (selected_window); 5688 struct window *w = XWINDOW (selected_window);
5577 5689
5578 if (NILP (arg)) 5690 if (NILP (arg))
5579 XSETFASTINT (arg, window_box_text_cols (w) - 2); 5691 XSETFASTINT (arg, window_body_cols (w) - 2);
5580 else 5692 else
5581 arg = Fprefix_numeric_value (arg); 5693 arg = Fprefix_numeric_value (arg);
5582 5694
@@ -7280,6 +7392,11 @@ frame to be redrawn only if it is a tty frame. */);
7280 defsubr (&Swindow_hchild); 7392 defsubr (&Swindow_hchild);
7281 defsubr (&Swindow_next); 7393 defsubr (&Swindow_next);
7282 defsubr (&Swindow_prev); 7394 defsubr (&Swindow_prev);
7395 defsubr (&Swindow_use_time);
7396 defsubr (&Swindow_top_line);
7397 defsubr (&Swindow_left_column);
7398 defsubr (&Swindow_total_size);
7399 defsubr (&Swindow_body_size);
7283 defsubr (&Swindow_height); 7400 defsubr (&Swindow_height);
7284 defsubr (&Swindow_width); 7401 defsubr (&Swindow_width);
7285 defsubr (&Swindow_full_width_p); 7402 defsubr (&Swindow_full_width_p);
@@ -7308,7 +7425,6 @@ frame to be redrawn only if it is a tty frame. */);
7308 defsubr (&Sprevious_window); 7425 defsubr (&Sprevious_window);
7309 defsubr (&Sother_window); 7426 defsubr (&Sother_window);
7310 defsubr (&Sget_lru_window); 7427 defsubr (&Sget_lru_window);
7311 defsubr (&Swindow_use_time);
7312 defsubr (&Sget_largest_window); 7428 defsubr (&Sget_largest_window);
7313 defsubr (&Sget_buffer_window); 7429 defsubr (&Sget_buffer_window);
7314 defsubr (&Sdelete_other_windows); 7430 defsubr (&Sdelete_other_windows);
@@ -7348,10 +7464,10 @@ frame to be redrawn only if it is a tty frame. */);
7348 defsubr (&Sset_window_vscroll); 7464 defsubr (&Sset_window_vscroll);
7349 defsubr (&Scompare_window_configurations); 7465 defsubr (&Scompare_window_configurations);
7350 defsubr (&Swindow_list); 7466 defsubr (&Swindow_list);
7467 defsubr (&Swindow_list_1);
7351 defsubr (&Swindow_parameters); 7468 defsubr (&Swindow_parameters);
7352 defsubr (&Swindow_parameter); 7469 defsubr (&Swindow_parameter);
7353 defsubr (&Sset_window_parameter); 7470 defsubr (&Sset_window_parameter);
7354
7355} 7471}
7356 7472
7357void 7473void