aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Porter2022-06-02 21:12:04 -0700
committerEli Zaretskii2022-06-09 10:08:15 +0300
commit43f8690ebf3439af90cf72c619e75afb4cff1a83 (patch)
tree9572243dd76216782e643fc4ccba8411f5cc4713 /src
parentd18e60fef172cf38b92108144f54ed10ddf67488 (diff)
downloademacs-43f8690ebf3439af90cf72c619e75afb4cff1a83.tar.gz
emacs-43f8690ebf3439af90cf72c619e75afb4cff1a83.zip
Account for remapped faces in $COLUMNS and $LINES in Eshell
* src/window.h (window_body_unit): New enum... (window_body_width): ... use it. * src/window.c (window_body_unit_from_symbol): New function. (window_body_height, window_body_width): Make PIXELWISE a 'window_body_unit'. (window-body-height, window-body-width): Accept 'remap' for PIXELWISE. (window-lines-pixel-dimensions, window_change_record_windows) (run_window_change_functions, resize_frame_windows, grow_mini_window) (shrink_mini_window, scroll-left, scroll-right): Update calls to 'window_body_height' and 'window_body_width'. * src/indent.c (compute_motion): Update calls to 'window_body_width'. * lisp/eshell/em-ls.el (eshell-ls-find-column-widths) (eshell-ls-find-column-lengths): Use 'window-body-width'. * lisp/eshell/esh-var.el (eshell-variable-aliases-list): Use 'window-body-width' and 'window-body-height'. * test/lisp/eshell/esh-var-tests.el (esh-var-test/window-height) (esh-var-test/window-width): Rename to... (esh-var-test/lines-var, esh-var-test/columns-var): ... and update expected value. * doc/lispref/windows.texi (Window Sizes): Document new behavior of PIXELWISE argument for 'window-body-width' and 'window-body-height'. * etc/NEWS: Announce this change (bug#55696).
Diffstat (limited to 'src')
-rw-r--r--src/indent.c4
-rw-r--r--src/window.c150
-rw-r--r--src/window.h8
3 files changed, 114 insertions, 48 deletions
diff --git a/src/indent.c b/src/indent.c
index acbb9dc9723..51f6f414de3 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -1204,7 +1204,7 @@ compute_motion (ptrdiff_t from, ptrdiff_t frombyte, EMACS_INT fromvpos,
1204 /* Negative width means use all available text columns. */ 1204 /* Negative width means use all available text columns. */
1205 if (width < 0) 1205 if (width < 0)
1206 { 1206 {
1207 width = window_body_width (win, 0); 1207 width = window_body_width (win, WINDOW_BODY_IN_CANONICAL_CHARS);
1208 /* We must make room for continuation marks if we don't have fringes. */ 1208 /* We must make room for continuation marks if we don't have fringes. */
1209#ifdef HAVE_WINDOW_SYSTEM 1209#ifdef HAVE_WINDOW_SYSTEM
1210 if (!FRAME_WINDOW_P (XFRAME (win->frame))) 1210 if (!FRAME_WINDOW_P (XFRAME (win->frame)))
@@ -1814,7 +1814,7 @@ visible section of the buffer, and pass LINE and COL as TOPOS. */)
1814 ? window_internal_height (w) 1814 ? window_internal_height (w)
1815 : XFIXNUM (XCDR (topos))), 1815 : XFIXNUM (XCDR (topos))),
1816 (NILP (topos) 1816 (NILP (topos)
1817 ? (window_body_width (w, 0) 1817 ? (window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS)
1818 - ( 1818 - (
1819#ifdef HAVE_WINDOW_SYSTEM 1819#ifdef HAVE_WINDOW_SYSTEM
1820 FRAME_WINDOW_P (XFRAME (w->frame)) ? 0 : 1820 FRAME_WINDOW_P (XFRAME (w->frame)) ? 0 :
diff --git a/src/window.c b/src/window.c
index eba1390fed2..e5666ce38e2 100644
--- a/src/window.c
+++ b/src/window.c
@@ -1014,11 +1014,20 @@ WINDOW must be a valid window and defaults to the selected one. */)
1014 return make_fixnum (decode_valid_window (window)->top_line); 1014 return make_fixnum (decode_valid_window (window)->top_line);
1015} 1015}
1016 1016
1017static enum window_body_unit
1018window_body_unit_from_symbol (Lisp_Object unit)
1019{
1020 return
1021 (unit == Qremap ? WINDOW_BODY_IN_REMAPPED_CHARS
1022 : NILP (unit) ? WINDOW_BODY_IN_CANONICAL_CHARS
1023 : WINDOW_BODY_IN_PIXELS);
1024}
1025
1017/* Return the number of lines/pixels of W's body. Don't count any mode 1026/* Return the number of lines/pixels of W's body. Don't count any mode
1018 or header line or horizontal divider of W. Rounds down to nearest 1027 or header line or horizontal divider of W. Rounds down to nearest
1019 integer when not working pixelwise. */ 1028 integer when not working pixelwise. */
1020static int 1029static int
1021window_body_height (struct window *w, bool pixelwise) 1030window_body_height (struct window *w, enum window_body_unit pixelwise)
1022{ 1031{
1023 int height = (w->pixel_height 1032 int height = (w->pixel_height
1024 - WINDOW_TAB_LINE_HEIGHT (w) 1033 - WINDOW_TAB_LINE_HEIGHT (w)
@@ -1029,11 +1038,27 @@ window_body_height (struct window *w, bool pixelwise)
1029 - WINDOW_MODE_LINE_HEIGHT (w) 1038 - WINDOW_MODE_LINE_HEIGHT (w)
1030 - WINDOW_BOTTOM_DIVIDER_WIDTH (w)); 1039 - WINDOW_BOTTOM_DIVIDER_WIDTH (w));
1031 1040
1041 int denom = 1;
1042 if (pixelwise == WINDOW_BODY_IN_REMAPPED_CHARS)
1043 {
1044 if (!NILP (Vface_remapping_alist))
1045 {
1046 struct frame *f = XFRAME (WINDOW_FRAME (w));
1047 int face_id = lookup_named_face (NULL, f, Qdefault, true);
1048 struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
1049 if (face && face->font && face->font->height)
1050 denom = face->font->height;
1051 }
1052 /* For performance, use canonical chars if no face remapping. */
1053 else
1054 pixelwise = WINDOW_BODY_IN_CANONICAL_CHARS;
1055 }
1056
1057 if (pixelwise == WINDOW_BODY_IN_CANONICAL_CHARS)
1058 denom = FRAME_LINE_HEIGHT (WINDOW_XFRAME (w));
1059
1032 /* Don't return a negative value. */ 1060 /* Don't return a negative value. */
1033 return max (pixelwise 1061 return max (height / denom, 0);
1034 ? height
1035 : height / FRAME_LINE_HEIGHT (WINDOW_XFRAME (w)),
1036 0);
1037} 1062}
1038 1063
1039/* Return the number of columns/pixels of W's body. Don't count columns 1064/* Return the number of columns/pixels of W's body. Don't count columns
@@ -1042,7 +1067,7 @@ window_body_height (struct window *w, bool pixelwise)
1042 fringes either. Round down to nearest integer when not working 1067 fringes either. Round down to nearest integer when not working
1043 pixelwise. */ 1068 pixelwise. */
1044int 1069int
1045window_body_width (struct window *w, bool pixelwise) 1070window_body_width (struct window *w, enum window_body_unit pixelwise)
1046{ 1071{
1047 struct frame *f = XFRAME (WINDOW_FRAME (w)); 1072 struct frame *f = XFRAME (WINDOW_FRAME (w));
1048 1073
@@ -1059,24 +1084,46 @@ window_body_width (struct window *w, bool pixelwise)
1059 ? WINDOW_FRINGES_WIDTH (w) 1084 ? WINDOW_FRINGES_WIDTH (w)
1060 : 0)); 1085 : 0));
1061 1086
1087 int denom = 1;
1088 if (pixelwise == WINDOW_BODY_IN_REMAPPED_CHARS)
1089 {
1090 if (!NILP (Vface_remapping_alist))
1091 {
1092 int face_id = lookup_named_face (NULL, f, Qdefault, true);
1093 struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);
1094 if (face && face->font)
1095 {
1096 if (face->font->average_width)
1097 denom = face->font->average_width;
1098 else if (face->font->space_width)
1099 denom = face->font->space_width;
1100 }
1101 }
1102 /* For performance, use canonical chars if no face remapping. */
1103 else
1104 pixelwise = WINDOW_BODY_IN_CANONICAL_CHARS;
1105 }
1106
1107 if (pixelwise == WINDOW_BODY_IN_CANONICAL_CHARS)
1108 denom = FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w));
1109
1062 /* Don't return a negative value. */ 1110 /* Don't return a negative value. */
1063 return max (pixelwise 1111 return max (width / denom, 0);
1064 ? width
1065 : width / FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w)),
1066 0);
1067} 1112}
1068 1113
1069DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 2, 0, 1114DEFUN ("window-body-width", Fwindow_body_width, Swindow_body_width, 0, 2, 0,
1070 doc: /* Return the width of WINDOW's text area. 1115 doc: /* Return the width of WINDOW's text area.
1071WINDOW must be a live window and defaults to the selected one. Optional 1116WINDOW must be a live window and defaults to the selected one. The
1072argument PIXELWISE non-nil means return the width in pixels. The return 1117return value does not include any vertical dividers, fringes or
1073value does not include any vertical dividers, fringes or marginal areas, 1118marginal areas, or scroll bars.
1074or scroll bars.
1075 1119
1076If PIXELWISE is nil, return the largest integer smaller than WINDOW's 1120The optional argument PIXELWISE defines the units to use for the
1077pixel width divided by the character width of WINDOW's frame. This 1121width. If nil, return the largest integer smaller than WINDOW's pixel
1078means that if a column at the right of the text area is only partially 1122width in units of the character width of WINDOW's frame. If PIXELWISE
1079visible, that column is not counted. 1123is `remap' and the default face is remapped (see
1124`face-remapping-alist'), use the remapped face to determine the
1125character width. For any other non-nil value, return the width in
1126pixels.
1080 1127
1081Note that the returned value includes the column reserved for the 1128Note that the returned value includes the column reserved for the
1082continuation glyph. 1129continuation glyph.
@@ -1084,25 +1131,29 @@ continuation glyph.
1084Also see `window-max-chars-per-line'. */) 1131Also see `window-max-chars-per-line'. */)
1085 (Lisp_Object window, Lisp_Object pixelwise) 1132 (Lisp_Object window, Lisp_Object pixelwise)
1086{ 1133{
1087 return make_fixnum (window_body_width (decode_live_window (window), 1134 return (make_fixnum
1088 !NILP (pixelwise))); 1135 (window_body_width (decode_live_window (window),
1136 window_body_unit_from_symbol (pixelwise))));
1089} 1137}
1090 1138
1091DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 2, 0, 1139DEFUN ("window-body-height", Fwindow_body_height, Swindow_body_height, 0, 2, 0,
1092 doc: /* Return the height of WINDOW's text area. 1140 doc: /* Return the height of WINDOW's text area.
1093WINDOW must be a live window and defaults to the selected one. Optional 1141WINDOW must be a live window and defaults to the selected one. The
1094argument PIXELWISE non-nil means return the height of WINDOW's text area 1142return value does not include the mode line or header line or any
1095in pixels. The return value does not include the mode line or header 1143horizontal divider.
1096line or any horizontal divider. 1144
1097 1145The optional argument PIXELWISE defines the units to use for the
1098If PIXELWISE is nil, return the largest integer smaller than WINDOW's 1146height. If nil, return the largest integer smaller than WINDOW's
1099pixel height divided by the character height of WINDOW's frame. This 1147pixel height in units of the character height of WINDOW's frame. If
1100means that if a line at the bottom of the text area is only partially 1148PIXELWISE is `remap' and the default face is remapped (see
1101visible, that line is not counted. */) 1149`face-remapping-alist'), use the remapped face to determine the
1150character height. For any other non-nil value, return the height in
1151pixels. */)
1102 (Lisp_Object window, Lisp_Object pixelwise) 1152 (Lisp_Object window, Lisp_Object pixelwise)
1103{ 1153{
1104 return make_fixnum (window_body_height (decode_live_window (window), 1154 return (make_fixnum
1105 !NILP (pixelwise))); 1155 (window_body_height (decode_live_window (window),
1156 window_body_unit_from_symbol (pixelwise))));
1106} 1157}
1107 1158
1108DEFUN ("window-old-body-pixel-width", 1159DEFUN ("window-old-body-pixel-width",
@@ -2124,7 +2175,8 @@ though when run from an idle timer with a delay of zero seconds. */)
2124 struct glyph_row *row, *end_row; 2175 struct glyph_row *row, *end_row;
2125 int max_y = NILP (body) ? WINDOW_PIXEL_HEIGHT (w) : window_text_bottom_y (w); 2176 int max_y = NILP (body) ? WINDOW_PIXEL_HEIGHT (w) : window_text_bottom_y (w);
2126 Lisp_Object rows = Qnil; 2177 Lisp_Object rows = Qnil;
2127 int window_width = NILP (body) ? w->pixel_width : window_body_width (w, true); 2178 int window_width = NILP (body)
2179 ? w->pixel_width : window_body_width (w, WINDOW_BODY_IN_PIXELS);
2128 int tab_line_height = WINDOW_TAB_LINE_HEIGHT (w); 2180 int tab_line_height = WINDOW_TAB_LINE_HEIGHT (w);
2129 int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w); 2181 int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w);
2130 int subtract = NILP (body) ? 0 : (tab_line_height + header_line_height); 2182 int subtract = NILP (body) ? 0 : (tab_line_height + header_line_height);
@@ -3657,8 +3709,10 @@ window_change_record_windows (Lisp_Object window, int stamp, ptrdiff_t number)
3657 wset_old_buffer (w, w->contents); 3709 wset_old_buffer (w, w->contents);
3658 w->old_pixel_width = w->pixel_width; 3710 w->old_pixel_width = w->pixel_width;
3659 w->old_pixel_height = w->pixel_height; 3711 w->old_pixel_height = w->pixel_height;
3660 w->old_body_pixel_width = window_body_width (w, true); 3712 w->old_body_pixel_width
3661 w->old_body_pixel_height = window_body_height (w, true); 3713 = window_body_width (w, WINDOW_BODY_IN_PIXELS);
3714 w->old_body_pixel_height
3715 = window_body_height (w, WINDOW_BODY_IN_PIXELS);
3662 } 3716 }
3663 3717
3664 w = NILP (w->next) ? 0 : XWINDOW (w->next); 3718 w = NILP (w->next) ? 0 : XWINDOW (w->next);
@@ -3903,8 +3957,10 @@ run_window_change_functions (void)
3903 && (window_buffer_change 3957 && (window_buffer_change
3904 || w->pixel_width != w->old_pixel_width 3958 || w->pixel_width != w->old_pixel_width
3905 || w->pixel_height != w->old_pixel_height 3959 || w->pixel_height != w->old_pixel_height
3906 || window_body_width (w, true) != w->old_body_pixel_width 3960 || (window_body_width (w, WINDOW_BODY_IN_PIXELS)
3907 || window_body_height (w, true) != w->old_body_pixel_height)); 3961 != w->old_body_pixel_width)
3962 || (window_body_height (w, WINDOW_BODY_IN_PIXELS)
3963 != w->old_body_pixel_height)));
3908 3964
3909 /* The following two are needed when running the default 3965 /* The following two are needed when running the default
3910 values for this frame below. */ 3966 values for this frame below. */
@@ -4768,7 +4824,8 @@ resize_frame_windows (struct frame *f, int size, bool horflag)
4768 Lisp_Object mini = f->minibuffer_window; 4824 Lisp_Object mini = f->minibuffer_window;
4769 struct window *m = WINDOWP (mini) ? XWINDOW (mini) : NULL; 4825 struct window *m = WINDOWP (mini) ? XWINDOW (mini) : NULL;
4770 int mini_height = ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f)) 4826 int mini_height = ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
4771 ? unit + m->pixel_height - window_body_height (m, true) 4827 ? (unit + m->pixel_height
4828 - window_body_height (m, WINDOW_BODY_IN_PIXELS))
4772 : 0); 4829 : 0);
4773 4830
4774 new_pixel_size = max (horflag ? size : size - mini_height, unit); 4831 new_pixel_size = max (horflag ? size : size - mini_height, unit);
@@ -5255,7 +5312,7 @@ void
5255grow_mini_window (struct window *w, int delta) 5312grow_mini_window (struct window *w, int delta)
5256{ 5313{
5257 struct frame *f = XFRAME (w->frame); 5314 struct frame *f = XFRAME (w->frame);
5258 int old_height = window_body_height (w, true); 5315 int old_height = window_body_height (w, WINDOW_BODY_IN_PIXELS);
5259 int min_height = FRAME_LINE_HEIGHT (f); 5316 int min_height = FRAME_LINE_HEIGHT (f);
5260 5317
5261 eassert (MINI_WINDOW_P (w)); 5318 eassert (MINI_WINDOW_P (w));
@@ -5289,7 +5346,8 @@ void
5289shrink_mini_window (struct window *w) 5346shrink_mini_window (struct window *w)
5290{ 5347{
5291 struct frame *f = XFRAME (w->frame); 5348 struct frame *f = XFRAME (w->frame);
5292 int delta = window_body_height (w, true) - FRAME_LINE_HEIGHT (f); 5349 int delta = (window_body_height (w, WINDOW_BODY_IN_PIXELS)
5350 - FRAME_LINE_HEIGHT (f));
5293 5351
5294 eassert (MINI_WINDOW_P (w)); 5352 eassert (MINI_WINDOW_P (w));
5295 5353
@@ -6356,9 +6414,10 @@ by this function. This happens in an interactive call. */)
6356 (register Lisp_Object arg, Lisp_Object set_minimum) 6414 (register Lisp_Object arg, Lisp_Object set_minimum)
6357{ 6415{
6358 struct window *w = XWINDOW (selected_window); 6416 struct window *w = XWINDOW (selected_window);
6359 EMACS_INT requested_arg = (NILP (arg) 6417 EMACS_INT requested_arg =
6360 ? window_body_width (w, 0) - 2 6418 (NILP (arg)
6361 : XFIXNUM (Fprefix_numeric_value (arg))); 6419 ? window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS) - 2
6420 : XFIXNUM (Fprefix_numeric_value (arg)));
6362 Lisp_Object result = set_window_hscroll (w, w->hscroll + requested_arg); 6421 Lisp_Object result = set_window_hscroll (w, w->hscroll + requested_arg);
6363 6422
6364 if (!NILP (set_minimum)) 6423 if (!NILP (set_minimum))
@@ -6381,9 +6440,10 @@ by this function. This happens in an interactive call. */)
6381 (register Lisp_Object arg, Lisp_Object set_minimum) 6440 (register Lisp_Object arg, Lisp_Object set_minimum)
6382{ 6441{
6383 struct window *w = XWINDOW (selected_window); 6442 struct window *w = XWINDOW (selected_window);
6384 EMACS_INT requested_arg = (NILP (arg) 6443 EMACS_INT requested_arg =
6385 ? window_body_width (w, 0) - 2 6444 (NILP (arg)
6386 : XFIXNUM (Fprefix_numeric_value (arg))); 6445 ? window_body_width (w, WINDOW_BODY_IN_CANONICAL_CHARS) - 2
6446 : XFIXNUM (Fprefix_numeric_value (arg)));
6387 Lisp_Object result = set_window_hscroll (w, w->hscroll - requested_arg); 6447 Lisp_Object result = set_window_hscroll (w, w->hscroll - requested_arg);
6388 6448
6389 if (!NILP (set_minimum)) 6449 if (!NILP (set_minimum))
diff --git a/src/window.h b/src/window.h
index 7f7de588463..298a80a5366 100644
--- a/src/window.h
+++ b/src/window.h
@@ -1186,7 +1186,13 @@ extern bool window_wants_mode_line (struct window *);
1186extern bool window_wants_header_line (struct window *); 1186extern bool window_wants_header_line (struct window *);
1187extern bool window_wants_tab_line (struct window *); 1187extern bool window_wants_tab_line (struct window *);
1188extern int window_internal_height (struct window *); 1188extern int window_internal_height (struct window *);
1189extern int window_body_width (struct window *w, bool); 1189enum window_body_unit
1190 {
1191 WINDOW_BODY_IN_CANONICAL_CHARS,
1192 WINDOW_BODY_IN_PIXELS,
1193 WINDOW_BODY_IN_REMAPPED_CHARS
1194 };
1195extern int window_body_width (struct window *w, enum window_body_unit);
1190enum margin_unit { MARGIN_IN_LINES, MARGIN_IN_PIXELS }; 1196enum margin_unit { MARGIN_IN_LINES, MARGIN_IN_PIXELS };
1191extern int window_scroll_margin (struct window *, enum margin_unit); 1197extern int window_scroll_margin (struct window *, enum margin_unit);
1192extern void temp_output_buffer_show (Lisp_Object); 1198extern void temp_output_buffer_show (Lisp_Object);