1 /* Display generation from window structure and buffer text.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
26 Emacs separates the task of updating the display from code
27 modifying global state, e.g. buffer text. This way functions
28 operating on buffers don't also have to be concerned with updating
31 Updating the display is triggered by the Lisp interpreter when it
32 decides it's time to do it. This is done either automatically for
33 you as part of the interpreter's command loop or as the result of
34 calling Lisp functions like `sit-for'. The C function `redisplay'
35 in xdisp.c is the only entry into the inner redisplay code. (Or,
36 let's say almost---see the the description of direct update
39 The following diagram shows how redisplay code is invoked. As you
40 can see, Lisp calls redisplay and vice versa. Under window systems
41 like X, some portions of the redisplay code are also called
42 asynchronously during mouse movement or expose events. It is very
43 important that these code parts do NOT use the C library (malloc,
44 free) because many C libraries under Unix are not reentrant. They
45 may also NOT call functions of the Lisp interpreter which could
46 change the interpreter's state. If you don't follow these rules,
47 you will encounter bugs which are very hard to explain.
49 (Direct functions, see below)
50 direct_output_for_insert,
51 direct_forward_char (dispnew.c)
52 +---------------------------------+
55 +--------------+ redisplay() +----------------+
56 | Lisp machine |---------------->| Redisplay code |<--+
57 +--------------+ (xdisp.c) +----------------+ |
59 +----------------------------------+ |
60 Don't use this path when called |
63 expose_window (asynchronous) |
65 X expose events -----+
67 What does redisplay? Obviously, it has to figure out somehow what
68 has been changed since the last time the display has been updated,
69 and to make these changes visible. Preferably it would do that in
70 a moderately intelligent way, i.e. fast.
72 Changes in buffer text can be deduced from window and buffer
73 structures, and from some global variables like `beg_unchanged' and
74 `end_unchanged'. The contents of the display are additionally
75 recorded in a `glyph matrix', a two-dimensional matrix of glyph
76 structures. Each row in such a matrix corresponds to a line on the
77 display, and each glyph in a row corresponds to a column displaying
78 a character, an image, or what else. This matrix is called the
79 `current glyph matrix' or `current matrix' in redisplay
82 For buffer parts that have been changed since the last update, a
83 second glyph matrix is constructed, the so called `desired glyph
84 matrix' or short `desired matrix'. Current and desired matrix are
85 then compared to find a cheap way to update the display, e.g. by
86 reusing part of the display by scrolling lines.
91 You will find a lot of of redisplay optimizations when you start
92 looking at the innards of redisplay. The overall goal of all these
93 optimizations is to make redisplay fast because it is done
96 Two optimizations are not found in xdisp.c. These are the direct
97 operations mentioned above. As the name suggests they follow a
98 different principle than the rest of redisplay. Instead of
99 building a desired matrix and then comparing it with the current
100 display, they perform their actions directly on the display and on
103 One direct operation updates the display after one character has
104 been entered. The other one moves the cursor by one position
105 forward or backward. You find these functions under the names
106 `direct_output_for_insert' and `direct_output_forward_char' in
112 Desired matrices are always built per Emacs window. The function
113 `display_line' is the central function to look at if you are
114 interested. It constructs one row in a desired matrix given an
115 iterator structure containing both a buffer position and a
116 description of the environment in which the text is to be
117 displayed. But this is too early, read on.
119 Characters and pixmaps displayed for a range of buffer text depend
120 on various settings of buffers and windows, on overlays and text
121 properties, on display tables, on selective display. The good news
122 is that all this hairy stuff is hidden behind a small set of
123 interface functions taking a iterator structure (struct it)
126 Iteration over things to be be displayed is then simple. It is
127 started by initializing an iterator with a call to init_iterator
128 (or init_string_iterator for that matter). Calls to
129 get_next_display_element fill the iterator structure with relevant
130 information about the next thing to display. Calls to
131 set_iterator_to_next move the iterator to the next thing.
133 Besides this, an iterator also contains information about the
134 display environment in which glyphs for display elements are to be
135 produced. It has fields for the width and height of the display,
136 the information whether long lines are truncated or continued, a
137 current X and Y position, and lots of other stuff you can better
140 Glyphs in a desired matrix are normally constructed in a loop
141 calling get_next_display_element and then produce_glyphs. The call
142 to produce_glyphs will fill the iterator structure with pixel
143 information about the element being displayed and at the same time
144 produce glyphs for it. If the display element fits on the line
145 being displayed, set_iterator_to_next is called next, otherwise the
146 glyphs produced are discarded.
151 That just couldn't be all, could it? What about terminal types not
152 supporting operations on sub-windows of the screen? To update the
153 display on such a terminal, window-based glyph matrices are not
154 well suited. To be able to reuse part of the display (scrolling
155 lines up and down), we must instead have a view of the whole
156 screen. This is what `frame matrices' are for. They are a trick.
158 Frames on terminals like above have a glyph pool. Windows on such
159 a frame sub-allocate their glyph memory from their frame's glyph
160 pool. The frame itself is given its own glyph matrices. By
161 coincidence---or maybe something else---rows in window glyph
162 matrices are slices of corresponding rows in frame matrices. Thus
163 writing to window matrices implicitly updates a frame matrix which
164 provides us with the view of the whole screen that we originally
165 wanted to have without having to move many bytes around. To be
166 honest, there is a little bit more done, but not much more. If you
167 plan to extend that code, take a look at dispnew.c. The function
168 build_frame_matrix is a good starting point. */
175 #include "termchar.h"
176 #include "dispextern.h"
180 #include "commands.h"
183 #include "termhooks.h"
184 #include "intervals.h"
185 #include "keyboard.h"
188 #include "region-cache.h"
190 #ifdef HAVE_X_WINDOWS
197 #define min(a, b) ((a) < (b) ? (a) : (b))
198 #define max(a, b) ((a) > (b) ? (a) : (b))
200 #define INFINITY 10000000
202 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
203 extern void set_frame_menubar ();
204 extern int pending_menu_activation
;
207 extern int interrupt_input
;
208 extern int command_loop_level
;
210 extern int minibuffer_auto_raise
;
212 extern Lisp_Object Qface
;
214 extern Lisp_Object Voverriding_local_map
;
215 extern Lisp_Object Voverriding_local_map_menu_flag
;
216 extern Lisp_Object Qmenu_item
;
218 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
219 Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
220 Lisp_Object Qredisplay_end_trigger_functions
;
221 Lisp_Object Qinhibit_point_motion_hooks
;
222 Lisp_Object QCeval
, Qwhen
, QCfile
, QCdata
;
223 Lisp_Object Qfontified
;
225 /* Functions called to fontify regions of text. */
227 Lisp_Object Vfontification_functions
;
228 Lisp_Object Qfontification_functions
;
230 /* Non-zero means draw tool bar buttons raised when the mouse moves
233 int auto_raise_tool_bar_buttons_p
;
235 /* Margin around tool bar buttons in pixels. */
237 int tool_bar_button_margin
;
239 /* Thickness of shadow to draw around tool bar buttons. */
241 int tool_bar_button_relief
;
243 /* Non-zero means automatically resize tool-bars so that all tool-bar
244 items are visible, and no blank lines remain. */
246 int auto_resize_tool_bars_p
;
248 /* Non-nil means don't actually do any redisplay. */
250 Lisp_Object Vinhibit_redisplay
, Qinhibit_redisplay
;
252 /* Names of text properties relevant for redisplay. */
254 Lisp_Object Qdisplay
, Qrelative_width
, Qalign_to
;
255 extern Lisp_Object Qface
, Qinvisible
, Qimage
, Qwidth
;
257 /* Symbols used in text property values. */
259 Lisp_Object Qspace
, QCalign_to
, QCrelative_width
, QCrelative_height
;
260 Lisp_Object Qleft_margin
, Qright_margin
, Qspace_width
, Qraise
;
262 extern Lisp_Object Qheight
;
264 /* Non-nil means highlight trailing whitespace. */
266 Lisp_Object Vshow_trailing_whitespace
;
268 /* Name of the face used to highlight trailing whitespace. */
270 Lisp_Object Qtrailing_whitespace
;
272 /* The symbol `image' which is the car of the lists used to represent
277 /* Non-zero means print newline to stdout before next mini-buffer
280 int noninteractive_need_newline
;
282 /* Non-zero means print newline to message log before next message. */
284 static int message_log_need_newline
;
287 /* The buffer position of the first character appearing entirely or
288 partially on the line of the selected window which contains the
289 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
290 redisplay optimization in redisplay_internal. */
292 static struct text_pos this_line_start_pos
;
294 /* Number of characters past the end of the line above, including the
295 terminating newline. */
297 static struct text_pos this_line_end_pos
;
299 /* The vertical positions and the height of this line. */
301 static int this_line_vpos
;
302 static int this_line_y
;
303 static int this_line_pixel_height
;
305 /* X position at which this display line starts. Usually zero;
306 negative if first character is partially visible. */
308 static int this_line_start_x
;
310 /* Buffer that this_line_.* variables are referring to. */
312 static struct buffer
*this_line_buffer
;
314 /* Nonzero means truncate lines in all windows less wide than the
317 int truncate_partial_width_windows
;
319 /* A flag to control how to display unibyte 8-bit character. */
321 int unibyte_display_via_language_environment
;
323 /* Nonzero means we have more than one non-mini-buffer-only frame.
324 Not guaranteed to be accurate except while parsing
325 frame-title-format. */
329 Lisp_Object Vglobal_mode_string
;
331 /* Marker for where to display an arrow on top of the buffer text. */
333 Lisp_Object Voverlay_arrow_position
;
335 /* String to display for the arrow. Only used on terminal frames. */
337 Lisp_Object Voverlay_arrow_string
;
339 /* Values of those variables at last redisplay. However, if
340 Voverlay_arrow_position is a marker, last_arrow_position is its
341 numerical position. */
343 static Lisp_Object last_arrow_position
, last_arrow_string
;
345 /* Like mode-line-format, but for the title bar on a visible frame. */
347 Lisp_Object Vframe_title_format
;
349 /* Like mode-line-format, but for the title bar on an iconified frame. */
351 Lisp_Object Vicon_title_format
;
353 /* List of functions to call when a window's size changes. These
354 functions get one arg, a frame on which one or more windows' sizes
357 static Lisp_Object Vwindow_size_change_functions
;
359 Lisp_Object Qmenu_bar_update_hook
;
361 /* Nonzero if overlay arrow has been displayed once in this window. */
363 static int overlay_arrow_seen
;
365 /* Nonzero means highlight the region even in nonselected windows. */
367 int highlight_nonselected_windows
;
369 /* If cursor motion alone moves point off frame, try scrolling this
370 many lines up or down if that will bring it back. */
372 static int scroll_step
;
374 /* Non-0 means scroll just far enough to bring point back on the
375 screen, when appropriate. */
377 static int scroll_conservatively
;
379 /* Recenter the window whenever point gets within this many lines of
380 the top or bottom of the window. This value is translated into a
381 pixel value by multiplying it with CANON_Y_UNIT, which means that
382 there is really a fixed pixel height scroll margin. */
386 /* Number of windows showing the buffer of the selected window (or
387 another buffer with the same base buffer). keyboard.c refers to
392 /* Vector containing glyphs for an ellipsis `...'. */
394 static Lisp_Object default_invis_vector
[3];
396 /* Nonzero means display mode line highlighted. */
398 int mode_line_inverse_video
;
400 /* Prompt to display in front of the mini-buffer contents. */
402 Lisp_Object minibuf_prompt
;
404 /* Width of current mini-buffer prompt. Only set after display_line
405 of the line that contains the prompt. */
407 int minibuf_prompt_width
;
408 int minibuf_prompt_pixel_width
;
410 /* This is the window where the echo area message was displayed. It
411 is always a mini-buffer window, but it may not be the same window
412 currently active as a mini-buffer. */
414 Lisp_Object echo_area_window
;
416 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
417 pushes the current message and the value of
418 message_enable_multibyte on the stack, the function restore_message
419 pops the stack and displays MESSAGE again. */
421 Lisp_Object Vmessage_stack
;
423 /* Nonzero means multibyte characters were enabled when the echo area
424 message was specified. */
426 int message_enable_multibyte
;
428 /* True if we should redraw the mode lines on the next redisplay. */
430 int update_mode_lines
;
432 /* Nonzero if window sizes or contents have changed since last
433 redisplay that finished */
435 int windows_or_buffers_changed
;
437 /* Nonzero after display_mode_line if %l was used and it displayed a
440 int line_number_displayed
;
442 /* Maximum buffer size for which to display line numbers. */
444 static int line_number_display_limit
;
446 /* line width to consider when repostioning for line number display */
448 static int line_number_display_limit_width
;
450 /* Number of lines to keep in the message log buffer. t means
451 infinite. nil means don't log at all. */
453 Lisp_Object Vmessage_log_max
;
455 /* Current, index 0, and last displayed echo area message. Either
456 buffers from echo_buffers, or nil to indicate no message. */
458 Lisp_Object echo_area_buffer
[2];
460 /* The buffers referenced from echo_area_buffer. */
462 static Lisp_Object echo_buffer
[2];
464 /* A vector saved used in with_area_buffer to reduce consing. */
466 static Lisp_Object Vwith_echo_area_save_vector
;
468 /* Non-zero means display_echo_area should display the last echo area
469 message again. Set by redisplay_preserve_echo_area. */
471 static int display_last_displayed_message_p
;
473 /* Nonzero if echo area is being used by print; zero if being used by
476 int message_buf_print
;
478 /* Maximum height for resizing mini-windows. Either a float
479 specifying a fraction of the available height, or an integer
480 specifying a number of lines. */
482 static Lisp_Object Vmax_mini_window_height
;
484 /* Non-zero means we want a hollow cursor in windows that are not
485 selected. Zero means there's no cursor in such windows. */
487 int cursor_in_non_selected_windows
;
489 /* A scratch glyph row with contents used for generating truncation
490 glyphs. Also used in direct_output_for_insert. */
492 #define MAX_SCRATCH_GLYPHS 100
493 struct glyph_row scratch_glyph_row
;
494 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
496 /* Ascent and height of the last line processed by move_it_to. */
498 static int last_max_ascent
, last_height
;
500 /* The maximum distance to look ahead for text properties. Values
501 that are too small let us call compute_char_face and similar
502 functions too often which is expensive. Values that are too large
503 let us call compute_char_face and alike too often because we
504 might not be interested in text properties that far away. */
506 #define TEXT_PROP_DISTANCE_LIMIT 100
508 /* Non-zero means print traces of redisplay if compiled with
512 int trace_redisplay_p
;
515 /* Value returned from text property handlers (see below). */
520 HANDLED_RECOMPUTE_PROPS
,
521 HANDLED_OVERLAY_STRING_CONSUMED
,
525 /* A description of text properties that redisplay is interested
530 /* The name of the property. */
533 /* A unique index for the property. */
536 /* A handler function called to set up iterator IT from the property
537 at IT's current position. Value is used to steer handle_stop. */
538 enum prop_handled (*handler
) P_ ((struct it
*it
));
541 static enum prop_handled handle_face_prop
P_ ((struct it
*));
542 static enum prop_handled handle_invisible_prop
P_ ((struct it
*));
543 static enum prop_handled handle_display_prop
P_ ((struct it
*));
544 static enum prop_handled handle_composition_prop
P_ ((struct it
*));
545 static enum prop_handled handle_overlay_change
P_ ((struct it
*));
546 static enum prop_handled handle_fontified_prop
P_ ((struct it
*));
548 /* Properties handled by iterators. */
550 static struct props it_props
[] =
552 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
553 /* Handle `face' before `display' because some sub-properties of
554 `display' need to know the face. */
555 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
556 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
557 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
558 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
562 /* Value is the position described by X. If X is a marker, value is
563 the marker_position of X. Otherwise, value is X. */
565 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
567 /* Enumeration returned by some move_it_.* functions internally. */
571 /* Not used. Undefined value. */
574 /* Move ended at the requested buffer position or ZV. */
575 MOVE_POS_MATCH_OR_ZV
,
577 /* Move ended at the requested X pixel position. */
580 /* Move within a line ended at the end of a line that must be
584 /* Move within a line ended at the end of a line that would
585 be displayed truncated. */
588 /* Move within a line ended at a line end. */
594 /* Function prototypes. */
596 static void ensure_echo_area_buffers
P_ ((void));
597 static struct glyph_row
*row_containing_pos
P_ ((struct window
*, int,
599 struct glyph_row
*));
600 static Lisp_Object unwind_with_echo_area_buffer
P_ ((Lisp_Object
));
601 static Lisp_Object with_echo_area_buffer_unwind_data
P_ ((struct window
*));
602 static void clear_garbaged_frames
P_ ((void));
603 static int current_message_1
P_ ((Lisp_Object
*));
604 static int truncate_message_1
P_ ((int));
605 static int set_message_1
P_ ((char *s
, Lisp_Object
, int, int));
606 static int display_echo_area
P_ ((struct window
*));
607 static int display_echo_area_1
P_ ((struct window
*));
608 static Lisp_Object unwind_redisplay
P_ ((Lisp_Object
));
609 static int string_char_and_length
P_ ((unsigned char *, int, int *));
610 static struct text_pos display_prop_end
P_ ((struct it
*, Lisp_Object
,
612 static int compute_window_start_on_continuation_line
P_ ((struct window
*));
613 static Lisp_Object eval_handler
P_ ((Lisp_Object
));
614 static Lisp_Object eval_form
P_ ((Lisp_Object
));
615 static void insert_left_trunc_glyphs
P_ ((struct it
*));
616 static struct glyph_row
*get_overlay_arrow_glyph_row
P_ ((struct window
*));
617 static void extend_face_to_end_of_line
P_ ((struct it
*));
618 static int append_space
P_ ((struct it
*, int));
619 static void make_cursor_line_fully_visible
P_ ((struct window
*));
620 static int try_scrolling
P_ ((Lisp_Object
, int, int, int, int));
621 static int trailing_whitespace_p
P_ ((int));
622 static int message_log_check_duplicate
P_ ((int, int, int, int));
623 int invisible_p
P_ ((Lisp_Object
, Lisp_Object
));
624 int invisible_ellipsis_p
P_ ((Lisp_Object
, Lisp_Object
));
625 static void push_it
P_ ((struct it
*));
626 static void pop_it
P_ ((struct it
*));
627 static void sync_frame_with_window_matrix_rows
P_ ((struct window
*));
628 static void redisplay_internal
P_ ((int));
629 static int echo_area_display
P_ ((int));
630 static void redisplay_windows
P_ ((Lisp_Object
));
631 static void redisplay_window
P_ ((Lisp_Object
, int));
632 static void update_menu_bar
P_ ((struct frame
*, int));
633 static int try_window_reusing_current_matrix
P_ ((struct window
*));
634 static int try_window_id
P_ ((struct window
*));
635 static int display_line
P_ ((struct it
*));
636 static void display_mode_lines
P_ ((struct window
*));
637 static void display_mode_line
P_ ((struct window
*, enum face_id
,
639 static int display_mode_element
P_ ((struct it
*, int, int, int, Lisp_Object
));
640 static char *decode_mode_spec
P_ ((struct window
*, int, int, int));
641 static void display_menu_bar
P_ ((struct window
*));
642 static int display_count_lines
P_ ((int, int, int, int, int *));
643 static int display_string
P_ ((unsigned char *, Lisp_Object
, Lisp_Object
,
644 int, int, struct it
*, int, int, int, int));
645 static void compute_line_metrics
P_ ((struct it
*));
646 static void run_redisplay_end_trigger_hook
P_ ((struct it
*));
647 static int get_overlay_strings
P_ ((struct it
*));
648 static void next_overlay_string
P_ ((struct it
*));
649 void set_iterator_to_next
P_ ((struct it
*));
650 static void reseat
P_ ((struct it
*, struct text_pos
, int));
651 static void reseat_1
P_ ((struct it
*, struct text_pos
, int));
652 static void back_to_previous_visible_line_start
P_ ((struct it
*));
653 static void reseat_at_previous_visible_line_start
P_ ((struct it
*));
654 static void reseat_at_next_visible_line_start
P_ ((struct it
*, int));
655 static int next_element_from_display_vector
P_ ((struct it
*));
656 static int next_element_from_string
P_ ((struct it
*));
657 static int next_element_from_c_string
P_ ((struct it
*));
658 static int next_element_from_buffer
P_ ((struct it
*));
659 static int next_element_from_composition
P_ ((struct it
*));
660 static int next_element_from_image
P_ ((struct it
*));
661 static int next_element_from_stretch
P_ ((struct it
*));
662 static void load_overlay_strings
P_ ((struct it
*));
663 static void init_from_display_pos
P_ ((struct it
*, struct window
*,
664 struct display_pos
*));
665 static void reseat_to_string
P_ ((struct it
*, unsigned char *,
666 Lisp_Object
, int, int, int, int));
667 static enum move_it_result move_it_in_display_line_to
P_ ((struct it
*,
669 void move_it_vertically_backward
P_ ((struct it
*, int));
670 static void init_to_row_start
P_ ((struct it
*, struct window
*,
671 struct glyph_row
*));
672 static void init_to_row_end
P_ ((struct it
*, struct window
*,
673 struct glyph_row
*));
674 static void back_to_previous_line_start
P_ ((struct it
*));
675 static void forward_to_next_line_start
P_ ((struct it
*));
676 static struct text_pos string_pos_nchars_ahead
P_ ((struct text_pos
,
678 static struct text_pos string_pos
P_ ((int, Lisp_Object
));
679 static struct text_pos c_string_pos
P_ ((int, unsigned char *, int));
680 static int number_of_chars
P_ ((unsigned char *, int));
681 static void compute_stop_pos
P_ ((struct it
*));
682 static void compute_string_pos
P_ ((struct text_pos
*, struct text_pos
,
684 static int face_before_or_after_it_pos
P_ ((struct it
*, int));
685 static int next_overlay_change
P_ ((int));
686 static int handle_single_display_prop
P_ ((struct it
*, Lisp_Object
,
687 Lisp_Object
, struct text_pos
*));
689 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
690 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
692 #ifdef HAVE_WINDOW_SYSTEM
694 static void update_tool_bar
P_ ((struct frame
*, int));
695 static void build_desired_tool_bar_string
P_ ((struct frame
*f
));
696 static int redisplay_tool_bar
P_ ((struct frame
*));
697 static void display_tool_bar_line
P_ ((struct it
*));
699 #endif /* HAVE_WINDOW_SYSTEM */
702 /***********************************************************************
703 Window display dimensions
704 ***********************************************************************/
706 /* Return the window-relative maximum y + 1 for glyph rows displaying
707 text in window W. This is the height of W minus the height of a
708 mode line, if any. */
711 window_text_bottom_y (w
)
714 struct frame
*f
= XFRAME (w
->frame
);
715 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
717 if (WINDOW_WANTS_MODELINE_P (w
))
718 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
723 /* Return the pixel width of display area AREA of window W. AREA < 0
724 means return the total width of W, not including bitmap areas to
725 the left and right of the window. */
728 window_box_width (w
, area
)
732 struct frame
*f
= XFRAME (w
->frame
);
733 int width
= XFASTINT (w
->width
);
735 if (!w
->pseudo_window_p
)
737 width
-= FRAME_SCROLL_BAR_WIDTH (f
) + FRAME_FLAGS_AREA_COLS (f
);
739 if (area
== TEXT_AREA
)
741 if (INTEGERP (w
->left_margin_width
))
742 width
-= XFASTINT (w
->left_margin_width
);
743 if (INTEGERP (w
->right_margin_width
))
744 width
-= XFASTINT (w
->right_margin_width
);
746 else if (area
== LEFT_MARGIN_AREA
)
747 width
= (INTEGERP (w
->left_margin_width
)
748 ? XFASTINT (w
->left_margin_width
) : 0);
749 else if (area
== RIGHT_MARGIN_AREA
)
750 width
= (INTEGERP (w
->right_margin_width
)
751 ? XFASTINT (w
->right_margin_width
) : 0);
754 return width
* CANON_X_UNIT (f
);
758 /* Return the pixel height of the display area of window W, not
759 including mode lines of W, if any.. */
762 window_box_height (w
)
765 struct frame
*f
= XFRAME (w
->frame
);
766 int height
= XFASTINT (w
->height
) * CANON_Y_UNIT (f
);
768 if (WINDOW_WANTS_MODELINE_P (w
))
769 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
771 if (WINDOW_WANTS_HEADER_LINE_P (w
))
772 height
-= CURRENT_HEADER_LINE_HEIGHT (w
);
778 /* Return the frame-relative coordinate of the left edge of display
779 area AREA of window W. AREA < 0 means return the left edge of the
780 whole window, to the right of any bitmap area at the left side of
784 window_box_left (w
, area
)
788 struct frame
*f
= XFRAME (w
->frame
);
789 int x
= FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
);
791 if (!w
->pseudo_window_p
)
793 x
+= (WINDOW_LEFT_MARGIN (w
) * CANON_X_UNIT (f
)
794 + FRAME_LEFT_FLAGS_AREA_WIDTH (f
));
796 if (area
== TEXT_AREA
)
797 x
+= window_box_width (w
, LEFT_MARGIN_AREA
);
798 else if (area
== RIGHT_MARGIN_AREA
)
799 x
+= (window_box_width (w
, LEFT_MARGIN_AREA
)
800 + window_box_width (w
, TEXT_AREA
));
807 /* Return the frame-relative coordinate of the right edge of display
808 area AREA of window W. AREA < 0 means return the left edge of the
809 whole window, to the left of any bitmap area at the right side of
813 window_box_right (w
, area
)
817 return window_box_left (w
, area
) + window_box_width (w
, area
);
821 /* Get the bounding box of the display area AREA of window W, without
822 mode lines, in frame-relative coordinates. AREA < 0 means the
823 whole window, not including bitmap areas to the left and right of
824 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
825 coordinates of the upper-left corner of the box. Return in
826 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
829 window_box (w
, area
, box_x
, box_y
, box_width
, box_height
)
832 int *box_x
, *box_y
, *box_width
, *box_height
;
834 struct frame
*f
= XFRAME (w
->frame
);
836 *box_width
= window_box_width (w
, area
);
837 *box_height
= window_box_height (w
);
838 *box_x
= window_box_left (w
, area
);
839 *box_y
= (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f
)
840 + XFASTINT (w
->top
) * CANON_Y_UNIT (f
));
841 if (WINDOW_WANTS_HEADER_LINE_P (w
))
842 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
846 /* Get the bounding box of the display area AREA of window W, without
847 mode lines. AREA < 0 means the whole window, not including bitmap
848 areas to the left and right of the window. Return in *TOP_LEFT_X
849 and TOP_LEFT_Y the frame-relative pixel coordinates of the
850 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
851 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
855 window_box_edges (w
, area
, top_left_x
, top_left_y
,
856 bottom_right_x
, bottom_right_y
)
859 int *top_left_x
, *top_left_y
, *bottom_right_x
, *bottom_right_y
;
861 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
863 *bottom_right_x
+= *top_left_x
;
864 *bottom_right_y
+= *top_left_y
;
869 /***********************************************************************
871 ***********************************************************************/
873 /* Return the next character from STR which is MAXLEN bytes long.
874 Return in *LEN the length of the character. This is like
875 STRING_CHAR_AND_LENGTH but never returns an invalid character. If
876 we find one, we return a `?', but with the length of the illegal
880 string_char_and_length (str
, maxlen
, len
)
886 c
= STRING_CHAR_AND_LENGTH (str
, maxlen
, *len
);
887 if (!CHAR_VALID_P (c
, 1))
888 /* We may not change the length here because other places in Emacs
889 don't use this function, i.e. they silently accept illegal
898 /* Given a position POS containing a valid character and byte position
899 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
901 static struct text_pos
902 string_pos_nchars_ahead (pos
, string
, nchars
)
907 xassert (STRINGP (string
) && nchars
>= 0);
909 if (STRING_MULTIBYTE (string
))
911 int rest
= STRING_BYTES (XSTRING (string
)) - BYTEPOS (pos
);
912 unsigned char *p
= XSTRING (string
)->data
+ BYTEPOS (pos
);
917 string_char_and_length (p
, rest
, &len
);
918 p
+= len
, rest
-= len
;
921 BYTEPOS (pos
) += len
;
925 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
931 /* Value is the text position, i.e. character and byte position,
932 for character position CHARPOS in STRING. */
934 static INLINE
struct text_pos
935 string_pos (charpos
, string
)
940 xassert (STRINGP (string
));
941 xassert (charpos
>= 0);
942 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
947 /* Value is a text position, i.e. character and byte position, for
948 character position CHARPOS in C string S. MULTIBYTE_P non-zero
949 means recognize multibyte characters. */
951 static struct text_pos
952 c_string_pos (charpos
, s
, multibyte_p
)
960 xassert (charpos
>= 0);
964 int rest
= strlen (s
), len
;
966 SET_TEXT_POS (pos
, 0, 0);
969 string_char_and_length (s
, rest
, &len
);
970 s
+= len
, rest
-= len
;
973 BYTEPOS (pos
) += len
;
977 SET_TEXT_POS (pos
, charpos
, charpos
);
983 /* Value is the number of characters in C string S. MULTIBYTE_P
984 non-zero means recognize multibyte characters. */
987 number_of_chars (s
, multibyte_p
)
995 int rest
= strlen (s
), len
;
996 unsigned char *p
= (unsigned char *) s
;
998 for (nchars
= 0; rest
> 0; ++nchars
)
1000 string_char_and_length (p
, rest
, &len
);
1001 rest
-= len
, p
+= len
;
1005 nchars
= strlen (s
);
1011 /* Compute byte position NEWPOS->bytepos corresponding to
1012 NEWPOS->charpos. POS is a known position in string STRING.
1013 NEWPOS->charpos must be >= POS.charpos. */
1016 compute_string_pos (newpos
, pos
, string
)
1017 struct text_pos
*newpos
, pos
;
1020 xassert (STRINGP (string
));
1021 xassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1023 if (STRING_MULTIBYTE (string
))
1024 *newpos
= string_pos_nchars_ahead (pos
, string
,
1025 CHARPOS (*newpos
) - CHARPOS (pos
));
1027 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1032 /***********************************************************************
1033 Lisp form evaluation
1034 ***********************************************************************/
1036 /* Error handler for eval_form. */
1046 /* Evaluate SEXPR and return the result, or nil if something went
1053 int count
= specpdl_ptr
- specpdl
;
1055 specbind (Qinhibit_redisplay
, Qt
);
1056 val
= internal_condition_case_1 (Feval
, sexpr
, Qerror
, eval_handler
);
1057 return unbind_to (count
, val
);
1062 /***********************************************************************
1064 ***********************************************************************/
1068 /* Define CHECK_IT to perform sanity checks on iterators.
1069 This is for debugging. It is too slow to do unconditionally. */
1075 if (it
->method
== next_element_from_string
)
1077 xassert (STRINGP (it
->string
));
1078 xassert (IT_STRING_CHARPOS (*it
) >= 0);
1080 else if (it
->method
== next_element_from_buffer
)
1082 /* Check that character and byte positions agree. */
1083 xassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
1087 xassert (it
->current
.dpvec_index
>= 0);
1089 xassert (it
->current
.dpvec_index
< 0);
1092 #define CHECK_IT(IT) check_it ((IT))
1096 #define CHECK_IT(IT) (void) 0
1103 /* Check that the window end of window W is what we expect it
1104 to be---the last row in the current matrix displaying text. */
1107 check_window_end (w
)
1110 if (!MINI_WINDOW_P (w
)
1111 && !NILP (w
->window_end_valid
))
1113 struct glyph_row
*row
;
1114 xassert ((row
= MATRIX_ROW (w
->current_matrix
,
1115 XFASTINT (w
->window_end_vpos
)),
1117 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
1118 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
1122 #define CHECK_WINDOW_END(W) check_window_end ((W))
1124 #else /* not GLYPH_DEBUG */
1126 #define CHECK_WINDOW_END(W) (void) 0
1128 #endif /* not GLYPH_DEBUG */
1132 /***********************************************************************
1133 Iterator initialization
1134 ***********************************************************************/
1136 /* Initialize IT for displaying current_buffer in window W, starting
1137 at character position CHARPOS. CHARPOS < 0 means that no buffer
1138 position is specified which is useful when the iterator is assigned
1139 a position later. BYTEPOS is the byte position corresponding to
1140 CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS.
1142 If ROW is not null, calls to produce_glyphs with IT as parameter
1143 will produce glyphs in that row.
1145 BASE_FACE_ID is the id of a base face to use. It must be one of
1146 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or
1147 HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for
1148 displaying the tool-bar.
1150 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or
1151 HEADER_LINE_FACE_ID, the iterator will be initialized to use the
1152 corresponding mode line glyph row of the desired matrix of W. */
1155 init_iterator (it
, w
, charpos
, bytepos
, row
, base_face_id
)
1158 int charpos
, bytepos
;
1159 struct glyph_row
*row
;
1160 enum face_id base_face_id
;
1162 int highlight_region_p
;
1164 /* Some precondition checks. */
1165 xassert (w
!= NULL
&& it
!= NULL
);
1166 xassert (charpos
< 0 || (charpos
> 0 && charpos
<= ZV
));
1168 /* If face attributes have been changed since the last redisplay,
1169 free realized faces now because they depend on face definitions
1170 that might have changed. */
1171 if (face_change_count
)
1173 face_change_count
= 0;
1174 free_all_realized_faces (Qnil
);
1177 /* Use one of the mode line rows of W's desired matrix if
1181 if (base_face_id
== MODE_LINE_FACE_ID
)
1182 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
1183 else if (base_face_id
== HEADER_LINE_FACE_ID
)
1184 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
1188 bzero (it
, sizeof *it
);
1189 it
->current
.overlay_string_index
= -1;
1190 it
->current
.dpvec_index
= -1;
1191 it
->base_face_id
= base_face_id
;
1193 /* The window in which we iterate over current_buffer: */
1194 XSETWINDOW (it
->window
, w
);
1196 it
->f
= XFRAME (w
->frame
);
1198 /* If realized faces have been removed, e.g. because of face
1199 attribute changes of named faces, recompute them. */
1200 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
1201 recompute_basic_faces (it
->f
);
1203 /* Current value of the `space-width', and 'height' properties. */
1204 it
->space_width
= Qnil
;
1205 it
->font_height
= Qnil
;
1207 /* Are control characters displayed as `^C'? */
1208 it
->ctl_arrow_p
= !NILP (current_buffer
->ctl_arrow
);
1210 /* -1 means everything between a CR and the following line end
1211 is invisible. >0 means lines indented more than this value are
1213 it
->selective
= (INTEGERP (current_buffer
->selective_display
)
1214 ? XFASTINT (current_buffer
->selective_display
)
1215 : (!NILP (current_buffer
->selective_display
)
1217 it
->selective_display_ellipsis_p
1218 = !NILP (current_buffer
->selective_display_ellipses
);
1220 /* Display table to use. */
1221 it
->dp
= window_display_table (w
);
1223 /* Are multibyte characters enabled in current_buffer? */
1224 it
->multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
1226 /* Non-zero if we should highlight the region. */
1228 = (!NILP (Vtransient_mark_mode
)
1229 && !NILP (current_buffer
->mark_active
)
1230 && XMARKER (current_buffer
->mark
)->buffer
!= 0);
1232 /* Set IT->region_beg_charpos and IT->region_end_charpos to the
1233 start and end of a visible region in window IT->w. Set both to
1234 -1 to indicate no region. */
1235 if (highlight_region_p
1236 /* Maybe highlight only in selected window. */
1237 && (/* Either show region everywhere. */
1238 highlight_nonselected_windows
1239 /* Or show region in the selected window. */
1240 || w
== XWINDOW (selected_window
)
1241 /* Or show the region if we are in the mini-buffer and W is
1242 the window the mini-buffer refers to. */
1243 || (MINI_WINDOW_P (XWINDOW (selected_window
))
1244 && w
== XWINDOW (Vminibuf_scroll_window
))))
1246 int charpos
= marker_position (current_buffer
->mark
);
1247 it
->region_beg_charpos
= min (PT
, charpos
);
1248 it
->region_end_charpos
= max (PT
, charpos
);
1251 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
1253 /* Get the position at which the redisplay_end_trigger hook should
1254 be run, if it is to be run at all. */
1255 if (MARKERP (w
->redisplay_end_trigger
)
1256 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
1257 it
->redisplay_end_trigger_charpos
1258 = marker_position (w
->redisplay_end_trigger
);
1259 else if (INTEGERP (w
->redisplay_end_trigger
))
1260 it
->redisplay_end_trigger_charpos
= XINT (w
->redisplay_end_trigger
);
1262 /* Correct bogus values of tab_width. */
1263 it
->tab_width
= XINT (current_buffer
->tab_width
);
1264 if (it
->tab_width
<= 0 || it
->tab_width
> 1000)
1267 /* Are lines in the display truncated? */
1268 it
->truncate_lines_p
1269 = (base_face_id
!= DEFAULT_FACE_ID
1270 || XINT (it
->w
->hscroll
)
1271 || (truncate_partial_width_windows
1272 && !WINDOW_FULL_WIDTH_P (it
->w
))
1273 || !NILP (current_buffer
->truncate_lines
));
1275 /* Get dimensions of truncation and continuation glyphs. These are
1276 displayed as bitmaps under X, so we don't need them for such
1278 if (!FRAME_WINDOW_P (it
->f
))
1280 if (it
->truncate_lines_p
)
1282 /* We will need the truncation glyph. */
1283 xassert (it
->glyph_row
== NULL
);
1284 produce_special_glyphs (it
, IT_TRUNCATION
);
1285 it
->truncation_pixel_width
= it
->pixel_width
;
1289 /* We will need the continuation glyph. */
1290 xassert (it
->glyph_row
== NULL
);
1291 produce_special_glyphs (it
, IT_CONTINUATION
);
1292 it
->continuation_pixel_width
= it
->pixel_width
;
1295 /* Reset these values to zero becaue the produce_special_glyphs
1296 above has changed them. */
1297 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
1298 it
->phys_ascent
= it
->phys_descent
= 0;
1301 /* Set this after getting the dimensions of truncation and
1302 continuation glyphs, so that we don't produce glyphs when calling
1303 produce_special_glyphs, above. */
1304 it
->glyph_row
= row
;
1305 it
->area
= TEXT_AREA
;
1307 /* Get the dimensions of the display area. The display area
1308 consists of the visible window area plus a horizontally scrolled
1309 part to the left of the window. All x-values are relative to the
1310 start of this total display area. */
1311 if (base_face_id
!= DEFAULT_FACE_ID
)
1313 /* Mode lines, menu bar in terminal frames. */
1314 it
->first_visible_x
= 0;
1315 it
->last_visible_x
= XFASTINT (w
->width
) * CANON_X_UNIT (it
->f
);
1320 = XFASTINT (it
->w
->hscroll
) * CANON_X_UNIT (it
->f
);
1321 it
->last_visible_x
= (it
->first_visible_x
1322 + window_box_width (w
, TEXT_AREA
));
1324 /* If we truncate lines, leave room for the truncator glyph(s) at
1325 the right margin. Otherwise, leave room for the continuation
1326 glyph(s). Truncation and continuation glyphs are not inserted
1327 for window-based redisplay. */
1328 if (!FRAME_WINDOW_P (it
->f
))
1330 if (it
->truncate_lines_p
)
1331 it
->last_visible_x
-= it
->truncation_pixel_width
;
1333 it
->last_visible_x
-= it
->continuation_pixel_width
;
1336 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
1337 it
->current_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
1340 /* Leave room for a border glyph. */
1341 if (!FRAME_WINDOW_P (it
->f
)
1342 && !WINDOW_RIGHTMOST_P (it
->w
))
1343 it
->last_visible_x
-= 1;
1345 it
->last_visible_y
= window_text_bottom_y (w
);
1347 /* For mode lines and alike, arrange for the first glyph having a
1348 left box line if the face specifies a box. */
1349 if (base_face_id
!= DEFAULT_FACE_ID
)
1353 it
->face_id
= base_face_id
;
1355 /* If we have a boxed mode line, make the first character appear
1356 with a left box line. */
1357 face
= FACE_FROM_ID (it
->f
, base_face_id
);
1358 if (face
->box
!= FACE_NO_BOX
)
1359 it
->start_of_box_run_p
= 1;
1362 /* If a buffer position was specified, set the iterator there,
1363 getting overlays and face properties from that position. */
1366 it
->end_charpos
= ZV
;
1368 IT_CHARPOS (*it
) = charpos
;
1370 /* Compute byte position if not specified. */
1372 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
1374 IT_BYTEPOS (*it
) = bytepos
;
1376 /* Compute faces etc. */
1377 reseat (it
, it
->current
.pos
, 1);
1384 /* Initialize IT for the display of window W with window start POS. */
1387 start_display (it
, w
, pos
)
1390 struct text_pos pos
;
1392 int start_at_line_beg_p
;
1393 struct glyph_row
*row
;
1394 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
1397 row
= w
->desired_matrix
->rows
+ first_vpos
;
1398 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
1399 first_y
= it
->current_y
;
1401 /* If window start is not at a line start, move back to the line
1402 start. This makes sure that we take continuation lines into
1404 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
1405 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
1406 if (!start_at_line_beg_p
)
1407 reseat_at_previous_visible_line_start (it
);
1409 /* If window start is not at a line start, skip forward to POS to
1410 get the correct continuation_lines_width and current_x. */
1411 if (!start_at_line_beg_p
)
1413 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
1415 /* If lines are continued, this line may end in the middle of a
1416 multi-glyph character (e.g. a control character displayed as
1417 \003, or in the middle of an overlay string). In this case
1418 move_it_to above will not have taken us to the start of
1419 the continuation line but to the end of the continued line. */
1420 if (!it
->truncate_lines_p
&& it
->current_x
> 0)
1422 if (it
->current
.dpvec_index
>= 0
1423 || it
->current
.overlay_string_index
>= 0)
1425 set_iterator_to_next (it
);
1426 move_it_in_display_line_to (it
, -1, -1, 0);
1428 it
->continuation_lines_width
+= it
->current_x
;
1431 it
->current_y
= first_y
;
1433 it
->current_x
= it
->hpos
= 0;
1436 #if 0 /* Don't assert the following because start_display is sometimes
1437 called intentionally with a window start that is not at a
1438 line start. Please leave this code in as a comment. */
1440 /* Window start should be on a line start, now. */
1441 xassert (it
->continuation_lines_width
1442 || IT_CHARPOS (it
) == BEGV
1443 || FETCH_BYTE (IT_BYTEPOS (it
) - 1) == '\n');
1448 /* Initialize IT for stepping through current_buffer in window W,
1449 starting at position POS that includes overlay string and display
1450 vector/ control character translation position information. */
1453 init_from_display_pos (it
, w
, pos
)
1456 struct display_pos
*pos
;
1458 /* Keep in mind: the call to reseat in init_iterator skips invisible
1459 text, so we might end up at a position different from POS. This
1460 is only a problem when POS is a row start after a newline and an
1461 overlay starts there with an after-string, and the overlay has an
1462 invisible property. Since we don't skip invisible text in
1463 display_line and elsewhere immediately after consuming the
1464 newline before the row start, such a POS will not be in a string,
1465 but the call to init_iterator below will move us to the
1467 init_iterator (it
, w
, CHARPOS (pos
->pos
), BYTEPOS (pos
->pos
),
1468 NULL
, DEFAULT_FACE_ID
);
1470 /* If position is within an overlay string, set up IT to
1471 the right overlay string. */
1472 if (pos
->overlay_string_index
>= 0)
1476 /* We already have the first chunk of overlay strings in
1477 IT->overlay_strings. Load more until the one for
1478 pos->overlay_string_index is in IT->overlay_strings. */
1479 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
1481 int n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
1482 it
->current
.overlay_string_index
= 0;
1485 load_overlay_strings (it
);
1486 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
1490 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
1491 relative_index
= (it
->current
.overlay_string_index
1492 % OVERLAY_STRING_CHUNK_SIZE
);
1493 it
->string
= it
->overlay_strings
[relative_index
];
1494 it
->current
.string_pos
= pos
->string_pos
;
1495 it
->method
= next_element_from_string
;
1497 else if (CHARPOS (pos
->string_pos
) >= 0)
1499 /* Recorded position is not in an overlay string, but in another
1500 string. This can only be a string from a `display' property.
1501 IT should already be filled with that string. */
1502 it
->current
.string_pos
= pos
->string_pos
;
1503 xassert (STRINGP (it
->string
));
1506 /* Restore position in display vector translations or control
1507 character translations. */
1508 if (pos
->dpvec_index
>= 0)
1510 /* This fills IT->dpvec. */
1511 get_next_display_element (it
);
1512 xassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
1513 it
->current
.dpvec_index
= pos
->dpvec_index
;
1520 /* Initialize IT for stepping through current_buffer in window W
1521 starting at ROW->start. */
1524 init_to_row_start (it
, w
, row
)
1527 struct glyph_row
*row
;
1529 init_from_display_pos (it
, w
, &row
->start
);
1530 it
->continuation_lines_width
= row
->continuation_lines_width
;
1535 /* Initialize IT for stepping through current_buffer in window W
1536 starting in the line following ROW, i.e. starting at ROW->end. */
1539 init_to_row_end (it
, w
, row
)
1542 struct glyph_row
*row
;
1544 init_from_display_pos (it
, w
, &row
->end
);
1546 if (row
->continued_p
)
1547 it
->continuation_lines_width
= (row
->continuation_lines_width
1548 + row
->pixel_width
);
1555 /***********************************************************************
1557 ***********************************************************************/
1559 /* Called when IT reaches IT->stop_charpos. Handle text property and
1560 overlay changes. Set IT->stop_charpos to the next position where
1567 enum prop_handled handled
;
1568 int handle_overlay_change_p
= 1;
1572 it
->current
.dpvec_index
= -1;
1576 handled
= HANDLED_NORMALLY
;
1578 /* Call text property handlers. */
1579 for (p
= it_props
; p
->handler
; ++p
)
1581 handled
= p
->handler (it
);
1583 if (handled
== HANDLED_RECOMPUTE_PROPS
)
1585 else if (handled
== HANDLED_RETURN
)
1587 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
1588 handle_overlay_change_p
= 0;
1591 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
1593 /* Don't check for overlay strings below when set to deliver
1594 characters from a display vector. */
1595 if (it
->method
== next_element_from_display_vector
)
1596 handle_overlay_change_p
= 0;
1598 /* Handle overlay changes. */
1599 if (handle_overlay_change_p
)
1600 handled
= handle_overlay_change (it
);
1602 /* Determine where to stop next. */
1603 if (handled
== HANDLED_NORMALLY
)
1604 compute_stop_pos (it
);
1607 while (handled
== HANDLED_RECOMPUTE_PROPS
);
1611 /* Compute IT->stop_charpos from text property and overlay change
1612 information for IT's current position. */
1615 compute_stop_pos (it
)
1618 register INTERVAL iv
, next_iv
;
1619 Lisp_Object object
, limit
, position
;
1621 /* If nowhere else, stop at the end. */
1622 it
->stop_charpos
= it
->end_charpos
;
1624 if (STRINGP (it
->string
))
1626 /* Strings are usually short, so don't limit the search for
1628 object
= it
->string
;
1630 XSETFASTINT (position
, IT_STRING_CHARPOS (*it
));
1636 /* If next overlay change is in front of the current stop pos
1637 (which is IT->end_charpos), stop there. Note: value of
1638 next_overlay_change is point-max if no overlay change
1640 charpos
= next_overlay_change (IT_CHARPOS (*it
));
1641 if (charpos
< it
->stop_charpos
)
1642 it
->stop_charpos
= charpos
;
1644 /* If showing the region, we have to stop at the region
1645 start or end because the face might change there. */
1646 if (it
->region_beg_charpos
> 0)
1648 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
1649 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
1650 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
1651 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
1654 /* Set up variables for computing the stop position from text
1655 property changes. */
1656 XSETBUFFER (object
, current_buffer
);
1657 XSETFASTINT (limit
, IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
1658 XSETFASTINT (position
, IT_CHARPOS (*it
));
1662 /* Get the interval containing IT's position. Value is a null
1663 interval if there isn't such an interval. */
1664 iv
= validate_interval_range (object
, &position
, &position
, 0);
1665 if (!NULL_INTERVAL_P (iv
))
1667 Lisp_Object values_here
[LAST_PROP_IDX
];
1670 /* Get properties here. */
1671 for (p
= it_props
; p
->handler
; ++p
)
1672 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
1674 /* Look for an interval following iv that has different
1676 for (next_iv
= next_interval (iv
);
1677 (!NULL_INTERVAL_P (next_iv
)
1679 || XFASTINT (limit
) > next_iv
->position
));
1680 next_iv
= next_interval (next_iv
))
1682 for (p
= it_props
; p
->handler
; ++p
)
1684 Lisp_Object new_value
;
1686 new_value
= textget (next_iv
->plist
, *p
->name
);
1687 if (!EQ (values_here
[p
->idx
], new_value
))
1695 if (!NULL_INTERVAL_P (next_iv
))
1697 if (INTEGERP (limit
)
1698 && next_iv
->position
>= XFASTINT (limit
))
1699 /* No text property change up to limit. */
1700 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
1702 /* Text properties change in next_iv. */
1703 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
1707 xassert (STRINGP (it
->string
)
1708 || (it
->stop_charpos
>= BEGV
1709 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
1713 /* Return the position of the next overlay change after POS in
1714 current_buffer. Value is point-max if no overlay change
1715 follows. This is like `next-overlay-change' but doesn't use
1719 next_overlay_change (pos
)
1724 Lisp_Object
*overlays
;
1728 /* Get all overlays at the given position. */
1730 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1731 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1732 if (noverlays
> len
)
1735 overlays
= (Lisp_Object
*) alloca (len
* sizeof *overlays
);
1736 noverlays
= overlays_at (pos
, 0, &overlays
, &len
, &endpos
, NULL
);
1739 /* If any of these overlays ends before endpos,
1740 use its ending point instead. */
1741 for (i
= 0; i
< noverlays
; ++i
)
1746 oend
= OVERLAY_END (overlays
[i
]);
1747 oendpos
= OVERLAY_POSITION (oend
);
1748 endpos
= min (endpos
, oendpos
);
1756 /***********************************************************************
1758 ***********************************************************************/
1760 /* Handle changes in the `fontified' property of the current buffer by
1761 calling hook functions from Qfontification_functions to fontify
1764 static enum prop_handled
1765 handle_fontified_prop (it
)
1768 Lisp_Object prop
, pos
;
1769 enum prop_handled handled
= HANDLED_NORMALLY
;
1770 struct gcpro gcpro1
;
1772 /* Get the value of the `fontified' property at IT's current buffer
1773 position. (The `fontified' property doesn't have a special
1774 meaning in strings.) If the value is nil, call functions from
1775 Qfontification_functions. */
1776 if (!STRINGP (it
->string
)
1778 && !NILP (Vfontification_functions
)
1779 && (pos
= make_number (IT_CHARPOS (*it
)),
1780 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
1783 Lisp_Object args
[2];
1786 /* Run the hook functions. */
1787 args
[0] = Qfontification_functions
;
1789 Frun_hook_with_args (2, args
);
1791 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
1792 something. This avoids an endless loop if they failed to
1793 fontify the text for which reason ever. */
1794 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
1795 handled
= HANDLED_RECOMPUTE_PROPS
;
1804 /***********************************************************************
1806 ***********************************************************************/
1808 /* Set up iterator IT from face properties at its current position.
1809 Called from handle_stop. */
1811 static enum prop_handled
1812 handle_face_prop (it
)
1815 int new_face_id
, next_stop
;
1817 if (!STRINGP (it
->string
))
1820 = face_at_buffer_position (it
->w
,
1822 it
->region_beg_charpos
,
1823 it
->region_end_charpos
,
1826 + TEXT_PROP_DISTANCE_LIMIT
),
1829 /* Is this a start of a run of characters with box face?
1830 Caveat: this can be called for a freshly initialized
1831 iterator; face_id is -1 is this case. We know that the new
1832 face will not change until limit, i.e. if the new face has a
1833 box, all characters up to limit will have one. But, as
1834 usual, we don't know whether limit is really the end. */
1835 if (new_face_id
!= it
->face_id
)
1837 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1839 /* If new face has a box but old face has not, this is
1840 the start of a run of characters with box, i.e. it has
1841 a shadow on the left side. The value of face_id of the
1842 iterator will be -1 if this is the initial call that gets
1843 the face. In this case, we have to look in front of IT's
1844 position and see whether there is a face != new_face_id. */
1845 it
->start_of_box_run_p
1846 = (new_face
->box
!= FACE_NO_BOX
1847 && (it
->face_id
>= 0
1848 || IT_CHARPOS (*it
) == BEG
1849 || new_face_id
!= face_before_it_pos (it
)));
1850 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1856 = face_at_string_position (it
->w
,
1858 IT_STRING_CHARPOS (*it
),
1859 (it
->current
.overlay_string_index
>= 0
1862 it
->region_beg_charpos
,
1863 it
->region_end_charpos
,
1867 #if 0 /* This shouldn't be neccessary. Let's check it. */
1868 /* If IT is used to display a mode line we would really like to
1869 use the mode line face instead of the frame's default face. */
1870 if (it
->glyph_row
== MATRIX_MODE_LINE_ROW (it
->w
->desired_matrix
)
1871 && new_face_id
== DEFAULT_FACE_ID
)
1872 new_face_id
= MODE_LINE_FACE_ID
;
1875 /* Is this a start of a run of characters with box? Caveat:
1876 this can be called for a freshly allocated iterator; face_id
1877 is -1 is this case. We know that the new face will not
1878 change until the next check pos, i.e. if the new face has a
1879 box, all characters up to that position will have a
1880 box. But, as usual, we don't know whether that position
1881 is really the end. */
1882 if (new_face_id
!= it
->face_id
)
1884 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
1885 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
1887 /* If new face has a box but old face hasn't, this is the
1888 start of a run of characters with box, i.e. it has a
1889 shadow on the left side. */
1890 it
->start_of_box_run_p
1891 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
1892 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
1896 it
->face_id
= new_face_id
;
1897 return HANDLED_NORMALLY
;
1901 /* Compute the face one character before or after the current position
1902 of IT. BEFORE_P non-zero means get the face in front of IT's
1903 position. Value is the id of the face. */
1906 face_before_or_after_it_pos (it
, before_p
)
1911 int next_check_charpos
;
1912 struct text_pos pos
;
1914 xassert (it
->s
== NULL
);
1916 if (STRINGP (it
->string
))
1918 /* No face change past the end of the string (for the case
1919 we are padding with spaces). No face change before the
1921 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
1922 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
1925 /* Set pos to the position before or after IT's current position. */
1927 pos
= string_pos (IT_STRING_CHARPOS (*it
) - 1, it
->string
);
1929 /* For composition, we must check the character after the
1931 pos
= (it
->what
== IT_COMPOSITION
1932 ? string_pos (IT_STRING_CHARPOS (*it
) + it
->cmp_len
, it
->string
)
1933 : string_pos (IT_STRING_CHARPOS (*it
) + 1, it
->string
));
1935 /* Get the face for ASCII, or unibyte. */
1937 = face_at_string_position (it
->w
,
1940 (it
->current
.overlay_string_index
>= 0
1943 it
->region_beg_charpos
,
1944 it
->region_end_charpos
,
1945 &next_check_charpos
,
1948 /* Correct the face for charsets different from ASCII. Do it
1949 for the multibyte case only. The face returned above is
1950 suitable for unibyte text if IT->string is unibyte. */
1951 if (STRING_MULTIBYTE (it
->string
))
1953 unsigned char *p
= XSTRING (it
->string
)->data
+ BYTEPOS (pos
);
1954 int rest
= STRING_BYTES (XSTRING (it
->string
)) - BYTEPOS (pos
);
1956 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
1958 c
= string_char_and_length (p
, rest
, &len
);
1959 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
1964 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
1965 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
1968 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
1969 pos
= it
->current
.pos
;
1972 DEC_TEXT_POS (pos
, it
->multibyte_p
);
1975 if (it
->what
== IT_COMPOSITION
)
1976 /* For composition, we must check the position after the
1978 pos
.charpos
+= it
->cmp_len
, pos
.bytepos
+= it
->len
;
1980 INC_TEXT_POS (pos
, it
->multibyte_p
);
1982 /* Determine face for CHARSET_ASCII, or unibyte. */
1983 face_id
= face_at_buffer_position (it
->w
,
1985 it
->region_beg_charpos
,
1986 it
->region_end_charpos
,
1987 &next_check_charpos
,
1990 /* Correct the face for charsets different from ASCII. Do it
1991 for the multibyte case only. The face returned above is
1992 suitable for unibyte text if current_buffer is unibyte. */
1993 if (it
->multibyte_p
)
1995 int c
= FETCH_MULTIBYTE_CHAR (CHARPOS (pos
));
1996 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
1997 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
);
2006 /***********************************************************************
2008 ***********************************************************************/
2010 /* Set up iterator IT from invisible properties at its current
2011 position. Called from handle_stop. */
2013 static enum prop_handled
2014 handle_invisible_prop (it
)
2017 enum prop_handled handled
= HANDLED_NORMALLY
;
2019 if (STRINGP (it
->string
))
2021 extern Lisp_Object Qinvisible
;
2022 Lisp_Object prop
, end_charpos
, limit
, charpos
;
2024 /* Get the value of the invisible text property at the
2025 current position. Value will be nil if there is no such
2027 XSETFASTINT (charpos
, IT_STRING_CHARPOS (*it
));
2028 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
2032 handled
= HANDLED_RECOMPUTE_PROPS
;
2034 /* Get the position at which the next change of the
2035 invisible text property can be found in IT->string.
2036 Value will be nil if the property value is the same for
2037 all the rest of IT->string. */
2038 XSETINT (limit
, XSTRING (it
->string
)->size
);
2039 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
2042 /* Text at current position is invisible. The next
2043 change in the property is at position end_charpos.
2044 Move IT's current position to that position. */
2045 if (INTEGERP (end_charpos
)
2046 && XFASTINT (end_charpos
) < XFASTINT (limit
))
2048 struct text_pos old
;
2049 old
= it
->current
.string_pos
;
2050 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
2051 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
2055 /* The rest of the string is invisible. If this is an
2056 overlay string, proceed with the next overlay string
2057 or whatever comes and return a character from there. */
2058 if (it
->current
.overlay_string_index
>= 0)
2060 next_overlay_string (it
);
2061 /* Don't check for overlay strings when we just
2062 finished processing them. */
2063 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
2067 struct Lisp_String
*s
= XSTRING (it
->string
);
2068 IT_STRING_CHARPOS (*it
) = s
->size
;
2069 IT_STRING_BYTEPOS (*it
) = STRING_BYTES (s
);
2076 int visible_p
, newpos
, next_stop
;
2077 Lisp_Object pos
, prop
;
2079 /* First of all, is there invisible text at this position? */
2080 XSETFASTINT (pos
, IT_CHARPOS (*it
));
2081 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2083 /* If we are on invisible text, skip over it. */
2084 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
2086 /* Record whether we have to display an ellipsis for the
2088 int display_ellipsis_p
2089 = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop
);
2091 handled
= HANDLED_RECOMPUTE_PROPS
;
2093 /* Loop skipping over invisible text. The loop is left at
2094 ZV or with IT on the first char being visible again. */
2097 /* Try to skip some invisible text. Return value is the
2098 position reached which can be equal to IT's position
2099 if there is nothing invisible here. This skips both
2100 over invisible text properties and overlays with
2101 invisible property. */
2102 newpos
= skip_invisible (IT_CHARPOS (*it
),
2103 &next_stop
, ZV
, it
->window
);
2105 /* If we skipped nothing at all we weren't at invisible
2106 text in the first place. If everything to the end of
2107 the buffer was skipped, end the loop. */
2108 if (newpos
== IT_CHARPOS (*it
) || newpos
>= ZV
)
2112 /* We skipped some characters but not necessarily
2113 all there are. Check if we ended up on visible
2114 text. Fget_char_property returns the property of
2115 the char before the given position, i.e. if we
2116 get visible_p = 1, this means that the char at
2117 newpos is visible. */
2118 XSETFASTINT (pos
, newpos
);
2119 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
2120 visible_p
= !TEXT_PROP_MEANS_INVISIBLE (prop
);
2123 /* If we ended up on invisible text, proceed to
2124 skip starting with next_stop. */
2126 IT_CHARPOS (*it
) = next_stop
;
2130 /* The position newpos is now either ZV or on visible text. */
2131 IT_CHARPOS (*it
) = newpos
;
2132 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
2134 /* Maybe return `...' next for the end of the invisible text. */
2135 if (display_ellipsis_p
)
2138 && VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
2140 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
2141 it
->dpvec
= v
->contents
;
2142 it
->dpend
= v
->contents
+ v
->size
;
2146 /* Default `...'. */
2147 it
->dpvec
= default_invis_vector
;
2148 it
->dpend
= default_invis_vector
+ 3;
2151 /* The ellipsis display does not replace the display of
2152 the character at the new position. Indicate this by
2153 setting IT->dpvec_char_len to zero. */
2154 it
->dpvec_char_len
= 0;
2156 it
->current
.dpvec_index
= 0;
2157 it
->method
= next_element_from_display_vector
;
2167 /***********************************************************************
2169 ***********************************************************************/
2171 /* Set up iterator IT from `display' property at its current position.
2172 Called from handle_stop. */
2174 static enum prop_handled
2175 handle_display_prop (it
)
2178 Lisp_Object prop
, object
;
2179 struct text_pos
*position
;
2180 int space_or_image_found_p
;
2182 if (STRINGP (it
->string
))
2184 object
= it
->string
;
2185 position
= &it
->current
.string_pos
;
2190 position
= &it
->current
.pos
;
2193 /* Reset those iterator values set from display property values. */
2194 it
->font_height
= Qnil
;
2195 it
->space_width
= Qnil
;
2198 /* We don't support recursive `display' properties, i.e. string
2199 values that have a string `display' property, that have a string
2200 `display' property etc. */
2201 if (!it
->string_from_display_prop_p
)
2202 it
->area
= TEXT_AREA
;
2204 prop
= Fget_char_property (make_number (position
->charpos
),
2207 return HANDLED_NORMALLY
;
2209 space_or_image_found_p
= 0;
2211 && CONSP (XCAR (prop
))
2212 && !EQ (Qmargin
, XCAR (XCAR (prop
))))
2214 /* A list of sub-properties. */
2215 while (CONSP (prop
))
2217 if (handle_single_display_prop (it
, XCAR (prop
), object
, position
))
2218 space_or_image_found_p
= 1;
2222 else if (VECTORP (prop
))
2225 for (i
= 0; i
< XVECTOR (prop
)->size
; ++i
)
2226 if (handle_single_display_prop (it
, XVECTOR (prop
)->contents
[i
],
2228 space_or_image_found_p
= 1;
2232 if (handle_single_display_prop (it
, prop
, object
, position
))
2233 space_or_image_found_p
= 1;
2236 return space_or_image_found_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
2240 /* Value is the position of the end of the `display' property starting
2241 at START_POS in OBJECT. */
2243 static struct text_pos
2244 display_prop_end (it
, object
, start_pos
)
2247 struct text_pos start_pos
;
2250 struct text_pos end_pos
;
2252 end
= next_single_char_property_change (make_number (CHARPOS (start_pos
)),
2253 Qdisplay
, object
, Qnil
);
2254 CHARPOS (end_pos
) = XFASTINT (end
);
2255 if (STRINGP (object
))
2256 compute_string_pos (&end_pos
, start_pos
, it
->string
);
2258 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
2264 /* Set up IT from a single `display' sub-property value PROP. OBJECT
2265 is the object in which the `display' property was found. *POSITION
2266 is the position at which it was found.
2268 If PROP is a `space' or `image' sub-property, set *POSITION to the
2269 end position of the `display' property.
2271 Value is non-zero if a `space' or `image' property value was found. */
2274 handle_single_display_prop (it
, prop
, object
, position
)
2278 struct text_pos
*position
;
2281 int space_or_image_found_p
= 0;
2285 /* If PROP is a list of the form `(when FORM . VALUE)', FORM is
2286 evaluated. If the result is nil, VALUE is ignored. */
2288 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
2297 if (!NILP (form
) && !EQ (form
, Qt
))
2299 struct gcpro gcpro1
;
2300 struct text_pos end_pos
, pt
;
2302 end_pos
= display_prop_end (it
, object
, *position
);
2305 /* Temporarily set point to the end position, and then evaluate
2306 the form. This makes `(eolp)' work as FORM. */
2308 BYTEPOS (pt
) = PT_BYTE
;
2309 TEMP_SET_PT_BOTH (CHARPOS (end_pos
), BYTEPOS (end_pos
));
2310 form
= eval_form (form
);
2311 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
2319 && EQ (XCAR (prop
), Qheight
)
2320 && CONSP (XCDR (prop
)))
2322 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2325 /* `(height HEIGHT)'. */
2326 it
->font_height
= XCAR (XCDR (prop
));
2327 if (!NILP (it
->font_height
))
2329 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2330 int new_height
= -1;
2332 if (CONSP (it
->font_height
)
2333 && (EQ (XCAR (it
->font_height
), Qplus
)
2334 || EQ (XCAR (it
->font_height
), Qminus
))
2335 && CONSP (XCDR (it
->font_height
))
2336 && INTEGERP (XCAR (XCDR (it
->font_height
))))
2338 /* `(+ N)' or `(- N)' where N is an integer. */
2339 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
2340 if (EQ (XCAR (it
->font_height
), Qplus
))
2342 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
2344 else if (SYMBOLP (it
->font_height
))
2346 /* Call function with current height as argument.
2347 Value is the new height. */
2348 Lisp_Object form
, height
;
2349 struct gcpro gcpro1
;
2351 height
= face
->lface
[LFACE_HEIGHT_INDEX
];
2352 form
= Fcons (it
->font_height
, Fcons (height
, Qnil
));
2354 height
= eval_form (form
);
2355 if (NUMBERP (height
))
2356 new_height
= XFLOATINT (height
);
2359 else if (NUMBERP (it
->font_height
))
2361 /* Value is a multiple of the canonical char height. */
2364 face
= FACE_FROM_ID (it
->f
, DEFAULT_FACE_ID
);
2365 new_height
= (XFLOATINT (it
->font_height
)
2366 * XINT (face
->lface
[LFACE_HEIGHT_INDEX
]));
2370 /* Evaluate IT->font_height with `height' bound to the
2371 current specified height to get the new height. */
2373 int count
= specpdl_ptr
- specpdl
;
2375 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
2376 value
= eval_form (it
->font_height
);
2377 unbind_to (count
, Qnil
);
2379 if (NUMBERP (value
))
2380 new_height
= XFLOATINT (value
);
2384 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
2387 else if (CONSP (prop
)
2388 && EQ (XCAR (prop
), Qspace_width
)
2389 && CONSP (XCDR (prop
)))
2391 /* `(space_width WIDTH)'. */
2392 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2395 value
= XCAR (XCDR (prop
));
2396 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
2397 it
->space_width
= value
;
2399 else if (CONSP (prop
)
2400 && EQ (XCAR (prop
), Qraise
)
2401 && CONSP (XCDR (prop
)))
2403 /* `(raise FACTOR)'. */
2404 if (FRAME_TERMCAP_P (it
->f
) || FRAME_MSDOS_P (it
->f
))
2407 #ifdef HAVE_WINDOW_SYSTEM
2408 value
= XCAR (XCDR (prop
));
2409 if (NUMBERP (value
))
2411 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
2412 it
->voffset
= - (XFLOATINT (value
)
2413 * (FONT_HEIGHT (face
->font
)));
2415 #endif /* HAVE_WINDOW_SYSTEM */
2417 else if (!it
->string_from_display_prop_p
)
2419 /* `((margin left-margin) VALUE)' or `((margin right-margin)
2420 VALUE) or `((margin nil) VALUE)' or VALUE. */
2421 Lisp_Object location
, value
;
2422 struct text_pos start_pos
;
2425 /* Characters having this form of property are not displayed, so
2426 we have to find the end of the property. */
2427 space_or_image_found_p
= 1;
2428 start_pos
= *position
;
2429 *position
= display_prop_end (it
, object
, start_pos
);
2432 /* Let's stop at the new position and assume that all
2433 text properties change there. */
2434 it
->stop_charpos
= position
->charpos
;
2436 location
= Qunbound
;
2437 if (CONSP (prop
) && CONSP (XCAR (prop
)))
2441 value
= XCDR (prop
);
2443 value
= XCAR (value
);
2446 if (EQ (XCAR (tem
), Qmargin
)
2447 && (tem
= XCDR (tem
),
2448 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
2450 || EQ (tem
, Qleft_margin
)
2451 || EQ (tem
, Qright_margin
))))
2455 if (EQ (location
, Qunbound
))
2461 #ifdef HAVE_WINDOW_SYSTEM
2462 if (FRAME_TERMCAP_P (it
->f
))
2463 valid_p
= STRINGP (value
);
2465 valid_p
= (STRINGP (value
)
2466 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2467 || valid_image_p (value
));
2468 #else /* not HAVE_WINDOW_SYSTEM */
2469 valid_p
= STRINGP (value
);
2470 #endif /* not HAVE_WINDOW_SYSTEM */
2472 if ((EQ (location
, Qleft_margin
)
2473 || EQ (location
, Qright_margin
)
2477 /* Save current settings of IT so that we can restore them
2478 when we are finished with the glyph property value. */
2481 if (NILP (location
))
2482 it
->area
= TEXT_AREA
;
2483 else if (EQ (location
, Qleft_margin
))
2484 it
->area
= LEFT_MARGIN_AREA
;
2486 it
->area
= RIGHT_MARGIN_AREA
;
2488 if (STRINGP (value
))
2491 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2492 it
->current
.overlay_string_index
= -1;
2493 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2494 it
->end_charpos
= it
->string_nchars
2495 = XSTRING (it
->string
)->size
;
2496 it
->method
= next_element_from_string
;
2497 it
->stop_charpos
= 0;
2498 it
->string_from_display_prop_p
= 1;
2500 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
2502 it
->method
= next_element_from_stretch
;
2504 it
->current
.pos
= it
->position
= start_pos
;
2506 #ifdef HAVE_WINDOW_SYSTEM
2509 it
->what
= IT_IMAGE
;
2510 it
->image_id
= lookup_image (it
->f
, value
);
2511 it
->position
= start_pos
;
2512 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
2513 it
->method
= next_element_from_image
;
2515 /* Say that we don't have consumed the characters with
2516 `display' property yet. The call to pop_it in
2517 set_iterator_to_next will clean this up. */
2518 *position
= start_pos
;
2520 #endif /* HAVE_WINDOW_SYSTEM */
2524 return space_or_image_found_p
;
2529 /***********************************************************************
2530 `composition' property
2531 ***********************************************************************/
2533 /* Set up iterator IT from `composition' property at its current
2534 position. Called from handle_stop. */
2536 static enum prop_handled
2537 handle_composition_prop (it
)
2540 Lisp_Object prop
, string
;
2541 int pos
, pos_byte
, end
;
2542 enum prop_handled handled
= HANDLED_NORMALLY
;
2544 if (STRINGP (it
->string
))
2546 pos
= IT_STRING_CHARPOS (*it
);
2547 pos_byte
= IT_STRING_BYTEPOS (*it
);
2548 string
= it
->string
;
2552 pos
= IT_CHARPOS (*it
);
2553 pos_byte
= IT_BYTEPOS (*it
);
2557 /* If there's a valid composition and point is not inside of the
2558 composition (in the case that the composition is from the current
2559 buffer), draw a glyph composed from the composition components. */
2560 if (find_composition (pos
, -1, &pos
, &end
, &prop
, string
)
2561 && COMPOSITION_VALID_P (pos
, end
, prop
)
2562 && (STRINGP (it
->string
) || (PT
<= pos
|| PT
>= end
)))
2564 int id
= get_composition_id (pos
, pos_byte
, end
- pos
, prop
, string
);
2568 it
->method
= next_element_from_composition
;
2570 it
->cmp_len
= COMPOSITION_LENGTH (prop
);
2571 /* For a terminal, draw only the first character of the
2573 it
->c
= COMPOSITION_GLYPH (composition_table
[id
], 0);
2574 it
->len
= (STRINGP (it
->string
)
2575 ? string_char_to_byte (it
->string
, end
)
2576 : CHAR_TO_BYTE (end
)) - pos_byte
;
2577 it
->stop_charpos
= end
;
2578 handled
= HANDLED_RETURN
;
2587 /***********************************************************************
2589 ***********************************************************************/
2591 /* The following structure is used to record overlay strings for
2592 later sorting in load_overlay_strings. */
2594 struct overlay_entry
2602 /* Set up iterator IT from overlay strings at its current position.
2603 Called from handle_stop. */
2605 static enum prop_handled
2606 handle_overlay_change (it
)
2609 /* Overlays are handled in current_buffer only. */
2610 if (STRINGP (it
->string
))
2611 return HANDLED_NORMALLY
;
2613 return (get_overlay_strings (it
)
2614 ? HANDLED_RECOMPUTE_PROPS
2615 : HANDLED_NORMALLY
);
2619 /* Set up the next overlay string for delivery by IT, if there is an
2620 overlay string to deliver. Called by set_iterator_to_next when the
2621 end of the current overlay string is reached. If there are more
2622 overlay strings to display, IT->string and
2623 IT->current.overlay_string_index are set appropriately here.
2624 Otherwise IT->string is set to nil. */
2627 next_overlay_string (it
)
2630 ++it
->current
.overlay_string_index
;
2631 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
2633 /* No more overlay strings. Restore IT's settings to what
2634 they were before overlay strings were processed, and
2635 continue to deliver from current_buffer. */
2637 xassert (it
->stop_charpos
>= BEGV
2638 && it
->stop_charpos
<= it
->end_charpos
);
2640 it
->current
.overlay_string_index
= -1;
2641 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
2642 it
->n_overlay_strings
= 0;
2643 it
->method
= next_element_from_buffer
;
2647 /* There are more overlay strings to process. If
2648 IT->current.overlay_string_index has advanced to a position
2649 where we must load IT->overlay_strings with more strings, do
2651 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
2653 if (it
->current
.overlay_string_index
&& i
== 0)
2654 load_overlay_strings (it
);
2656 /* Initialize IT to deliver display elements from the overlay
2658 it
->string
= it
->overlay_strings
[i
];
2659 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2660 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
2661 it
->method
= next_element_from_string
;
2662 it
->stop_charpos
= 0;
2669 /* Compare two overlay_entry structures E1 and E2. Used as a
2670 comparison function for qsort in load_overlay_strings. Overlay
2671 strings for the same position are sorted so that
2673 1. All after-strings come in front of before-strings.
2675 2. Within after-strings, strings are sorted so that overlay strings
2676 from overlays with higher priorities come first.
2678 2. Within before-strings, strings are sorted so that overlay
2679 strings from overlays with higher priorities come last.
2681 Value is analogous to strcmp. */
2685 compare_overlay_entries (e1
, e2
)
2688 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
2689 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
2692 if (entry1
->after_string_p
!= entry2
->after_string_p
)
2693 /* Let after-strings appear in front of before-strings. */
2694 result
= entry1
->after_string_p
? -1 : 1;
2695 else if (entry1
->after_string_p
)
2696 /* After-strings sorted in order of decreasing priority. */
2697 result
= entry2
->priority
- entry1
->priority
;
2699 /* Before-strings sorted in order of increasing priority. */
2700 result
= entry1
->priority
- entry2
->priority
;
2706 /* Load the vector IT->overlay_strings with overlay strings from IT's
2707 current buffer position. Set IT->n_overlays to the total number of
2708 overlay strings found.
2710 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
2711 a time. On entry into load_overlay_strings,
2712 IT->current.overlay_string_index gives the number of overlay
2713 strings that have already been loaded by previous calls to this
2716 Overlay strings are sorted so that after-string strings come in
2717 front of before-string strings. Within before and after-strings,
2718 strings are sorted by overlay priority. See also function
2719 compare_overlay_entries. */
2722 load_overlay_strings (it
)
2725 extern Lisp_Object Qafter_string
, Qbefore_string
, Qwindow
, Qpriority
;
2726 Lisp_Object ov
, overlay
, window
, str
;
2730 struct overlay_entry
*entries
2731 = (struct overlay_entry
*) alloca (size
* sizeof *entries
);
2733 /* Append the overlay string STRING of overlay OVERLAY to vector
2734 `entries' which has size `size' and currently contains `n'
2735 elements. AFTER_P non-zero means STRING is an after-string of
2737 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
2740 Lisp_Object priority; \
2744 int new_size = 2 * size; \
2745 struct overlay_entry *old = entries; \
2747 (struct overlay_entry *) alloca (new_size \
2748 * sizeof *entries); \
2749 bcopy (old, entries, size * sizeof *entries); \
2753 entries[n].string = (STRING); \
2754 priority = Foverlay_get ((OVERLAY), Qpriority); \
2755 entries[n].priority \
2756 = INTEGERP (priority) ? XFASTINT (priority) : 0; \
2757 entries[n].after_string_p = (AFTER_P); \
2762 /* Process overlay before the overlay center. */
2763 for (ov
= current_buffer
->overlays_before
;
2767 overlay
= XCAR (ov
);
2768 xassert (OVERLAYP (overlay
));
2769 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2770 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2772 if (end
< IT_CHARPOS (*it
))
2775 /* Skip this overlay if it doesn't start or end at IT's current
2777 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2780 /* Skip this overlay if it doesn't apply to IT->w. */
2781 window
= Foverlay_get (overlay
, Qwindow
);
2782 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2785 /* If overlay has a non-empty before-string, record it. */
2786 if (start
== IT_CHARPOS (*it
)
2787 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2788 && XSTRING (str
)->size
)
2789 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2791 /* If overlay has a non-empty after-string, record it. */
2792 if (end
== IT_CHARPOS (*it
)
2793 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2794 && XSTRING (str
)->size
)
2795 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2798 /* Process overlays after the overlay center. */
2799 for (ov
= current_buffer
->overlays_after
;
2803 overlay
= XCAR (ov
);
2804 xassert (OVERLAYP (overlay
));
2805 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
2806 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
2808 if (start
> IT_CHARPOS (*it
))
2811 /* Skip this overlay if it doesn't start or end at IT's current
2813 if (end
!= IT_CHARPOS (*it
) && start
!= IT_CHARPOS (*it
))
2816 /* Skip this overlay if it doesn't apply to IT->w. */
2817 window
= Foverlay_get (overlay
, Qwindow
);
2818 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
2821 /* If overlay has a non-empty before-string, record it. */
2822 if (start
== IT_CHARPOS (*it
)
2823 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
2824 && XSTRING (str
)->size
)
2825 RECORD_OVERLAY_STRING (overlay
, str
, 0);
2827 /* If overlay has a non-empty after-string, record it. */
2828 if (end
== IT_CHARPOS (*it
)
2829 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
2830 && XSTRING (str
)->size
)
2831 RECORD_OVERLAY_STRING (overlay
, str
, 1);
2834 #undef RECORD_OVERLAY_STRING
2837 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
2839 /* Record the total number of strings to process. */
2840 it
->n_overlay_strings
= n
;
2842 /* IT->current.overlay_string_index is the number of overlay strings
2843 that have already been consumed by IT. Copy some of the
2844 remaining overlay strings to IT->overlay_strings. */
2846 j
= it
->current
.overlay_string_index
;
2847 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
2848 it
->overlay_strings
[i
++] = entries
[j
++].string
;
2854 /* Get the first chunk of overlay strings at IT's current buffer
2855 position. Value is non-zero if at least one overlay string was
2859 get_overlay_strings (it
)
2862 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
2863 process. This fills IT->overlay_strings with strings, and sets
2864 IT->n_overlay_strings to the total number of strings to process.
2865 IT->pos.overlay_string_index has to be set temporarily to zero
2866 because load_overlay_strings needs this; it must be set to -1
2867 when no overlay strings are found because a zero value would
2868 indicate a position in the first overlay string. */
2869 it
->current
.overlay_string_index
= 0;
2870 load_overlay_strings (it
);
2872 /* If we found overlay strings, set up IT to deliver display
2873 elements from the first one. Otherwise set up IT to deliver
2874 from current_buffer. */
2875 if (it
->n_overlay_strings
)
2877 /* Make sure we know settings in current_buffer, so that we can
2878 restore meaningful values when we're done with the overlay
2880 compute_stop_pos (it
);
2881 xassert (it
->face_id
>= 0);
2883 /* Save IT's settings. They are restored after all overlay
2884 strings have been processed. */
2885 xassert (it
->sp
== 0);
2888 /* Set up IT to deliver display elements from the first overlay
2890 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
2891 it
->stop_charpos
= 0;
2892 it
->string
= it
->overlay_strings
[0];
2893 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
2894 xassert (STRINGP (it
->string
));
2895 it
->method
= next_element_from_string
;
2900 it
->current
.overlay_string_index
= -1;
2901 it
->method
= next_element_from_buffer
;
2906 /* Value is non-zero if we found at least one overlay string. */
2907 return STRINGP (it
->string
);
2912 /***********************************************************************
2913 Saving and restoring state
2914 ***********************************************************************/
2916 /* Save current settings of IT on IT->stack. Called, for example,
2917 before setting up IT for an overlay string, to be able to restore
2918 IT's settings to what they were after the overlay string has been
2925 struct iterator_stack_entry
*p
;
2927 xassert (it
->sp
< 2);
2928 p
= it
->stack
+ it
->sp
;
2930 p
->stop_charpos
= it
->stop_charpos
;
2931 xassert (it
->face_id
>= 0);
2932 p
->face_id
= it
->face_id
;
2933 p
->string
= it
->string
;
2934 p
->pos
= it
->current
;
2935 p
->end_charpos
= it
->end_charpos
;
2936 p
->string_nchars
= it
->string_nchars
;
2938 p
->multibyte_p
= it
->multibyte_p
;
2939 p
->space_width
= it
->space_width
;
2940 p
->font_height
= it
->font_height
;
2941 p
->voffset
= it
->voffset
;
2942 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
2947 /* Restore IT's settings from IT->stack. Called, for example, when no
2948 more overlay strings must be processed, and we return to delivering
2949 display elements from a buffer, or when the end of a string from a
2950 `display' property is reached and we return to delivering display
2951 elements from an overlay string, or from a buffer. */
2957 struct iterator_stack_entry
*p
;
2959 xassert (it
->sp
> 0);
2961 p
= it
->stack
+ it
->sp
;
2962 it
->stop_charpos
= p
->stop_charpos
;
2963 it
->face_id
= p
->face_id
;
2964 it
->string
= p
->string
;
2965 it
->current
= p
->pos
;
2966 it
->end_charpos
= p
->end_charpos
;
2967 it
->string_nchars
= p
->string_nchars
;
2969 it
->multibyte_p
= p
->multibyte_p
;
2970 it
->space_width
= p
->space_width
;
2971 it
->font_height
= p
->font_height
;
2972 it
->voffset
= p
->voffset
;
2973 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
2978 /***********************************************************************
2980 ***********************************************************************/
2982 /* Set IT's current position to the previous line start. */
2985 back_to_previous_line_start (it
)
2988 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
2989 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
2993 /* Set IT's current position to the next line start. */
2996 forward_to_next_line_start (it
)
2999 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
), 1);
3000 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3004 /* Set IT's current position to the previous visible line start. Skip
3005 invisible text that is so either due to text properties or due to
3006 selective display. Caution: this does not change IT->current_x and
3010 back_to_previous_visible_line_start (it
)
3015 /* Go back one newline if not on BEGV already. */
3016 if (IT_CHARPOS (*it
) > BEGV
)
3017 back_to_previous_line_start (it
);
3019 /* Move over lines that are invisible because of selective display
3020 or text properties. */
3021 while (IT_CHARPOS (*it
) > BEGV
3026 /* If selective > 0, then lines indented more than that values
3028 if (it
->selective
> 0
3029 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3036 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
)),
3037 Qinvisible
, it
->window
);
3038 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
3042 /* Back one more newline if the current one is invisible. */
3044 back_to_previous_line_start (it
);
3047 xassert (IT_CHARPOS (*it
) >= BEGV
);
3048 xassert (IT_CHARPOS (*it
) == BEGV
3049 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3054 /* Reseat iterator IT at the previous visible line start. Skip
3055 invisible text that is so either due to text properties or due to
3056 selective display. At the end, update IT's overlay information,
3057 face information etc. */
3060 reseat_at_previous_visible_line_start (it
)
3063 back_to_previous_visible_line_start (it
);
3064 reseat (it
, it
->current
.pos
, 1);
3069 /* Reseat iterator IT on the next visible line start in the current
3070 buffer. ON_NEWLINE_P non-zero means position IT on the newline
3071 preceding the line start. Skip over invisible text that is so
3072 because of selective display. Compute faces, overlays etc at the
3073 new position. Note that this function does not skip over text that
3074 is invisible because of text properties. */
3077 reseat_at_next_visible_line_start (it
, on_newline_p
)
3081 /* Restore the buffer position when currently not delivering display
3082 elements from the current buffer. This is the case, for example,
3083 when called at the end of a truncated overlay string. */
3086 it
->method
= next_element_from_buffer
;
3088 /* Otherwise, scan_buffer would not work. */
3089 if (IT_CHARPOS (*it
) < ZV
)
3091 /* If on a newline, advance past it. Otherwise, find the next
3092 newline which automatically gives us the position following
3094 if (FETCH_BYTE (IT_BYTEPOS (*it
)) == '\n')
3100 forward_to_next_line_start (it
);
3102 /* We must either have reached the end of the buffer or end up
3104 xassert (IT_CHARPOS (*it
) == ZV
3105 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
3107 /* Skip over lines that are invisible because they are indented
3108 more than the value of IT->selective. */
3109 if (it
->selective
> 0)
3110 while (IT_CHARPOS (*it
) < ZV
3111 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
3113 forward_to_next_line_start (it
);
3115 /* Position on the newline if we should. */
3117 && IT_CHARPOS (*it
) > BEGV
3118 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n')
3121 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
3124 /* Set the iterator there. The 0 as the last parameter of
3125 reseat means don't force a text property lookup. The lookup
3126 is then only done if we've skipped past the iterator's
3127 check_charpos'es. This optimization is important because
3128 text property lookups tend to be expensive. */
3129 reseat (it
, it
->current
.pos
, 0);
3137 /***********************************************************************
3138 Changing an iterator's position
3139 ***********************************************************************/
3141 /* Change IT's current position to POS in current_buffer. If FORCE_P
3142 is non-zero, always check for text properties at the new position.
3143 Otherwise, text properties are only looked up if POS >=
3144 IT->check_charpos of a property. */
3147 reseat (it
, pos
, force_p
)
3149 struct text_pos pos
;
3152 int original_pos
= IT_CHARPOS (*it
);
3154 reseat_1 (it
, pos
, 0);
3156 /* Determine where to check text properties. Avoid doing it
3157 where possible because text property lookup is very expensive. */
3159 || CHARPOS (pos
) > it
->stop_charpos
3160 || CHARPOS (pos
) < original_pos
)
3167 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
3168 IT->stop_pos to POS, also. */
3171 reseat_1 (it
, pos
, set_stop_p
)
3173 struct text_pos pos
;
3176 /* Don't call this function when scanning a C string. */
3177 xassert (it
->s
== NULL
);
3179 /* POS must be a reasonable value. */
3180 xassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
3182 it
->current
.pos
= it
->position
= pos
;
3183 XSETBUFFER (it
->object
, current_buffer
);
3185 it
->current
.dpvec_index
= -1;
3186 it
->current
.overlay_string_index
= -1;
3187 IT_STRING_CHARPOS (*it
) = -1;
3188 IT_STRING_BYTEPOS (*it
) = -1;
3190 it
->method
= next_element_from_buffer
;
3194 it
->stop_charpos
= CHARPOS (pos
);
3198 /* Set up IT for displaying a string, starting at CHARPOS in window W.
3199 If S is non-null, it is a C string to iterate over. Otherwise,
3200 STRING gives a Lisp string to iterate over.
3202 If PRECISION > 0, don't return more then PRECISION number of
3203 characters from the string.
3205 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
3206 characters have been returned. FIELD_WIDTH < 0 means an infinite
3209 MULTIBYTE = 0 means disable processing of multibyte characters,
3210 MULTIBYTE > 0 means enable it,
3211 MULTIBYTE < 0 means use IT->multibyte_p.
3213 IT must be initialized via a prior call to init_iterator before
3214 calling this function. */
3217 reseat_to_string (it
, s
, string
, charpos
, precision
, field_width
, multibyte
)
3222 int precision
, field_width
, multibyte
;
3224 /* No region in strings. */
3225 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
3227 /* No text property checks performed by default, but see below. */
3228 it
->stop_charpos
= -1;
3230 /* Set iterator position and end position. */
3231 bzero (&it
->current
, sizeof it
->current
);
3232 it
->current
.overlay_string_index
= -1;
3233 it
->current
.dpvec_index
= -1;
3234 xassert (charpos
>= 0);
3236 /* Use the setting of MULTIBYTE if specified. */
3238 it
->multibyte_p
= multibyte
> 0;
3242 xassert (STRINGP (string
));
3243 it
->string
= string
;
3245 it
->end_charpos
= it
->string_nchars
= XSTRING (string
)->size
;
3246 it
->method
= next_element_from_string
;
3247 it
->current
.string_pos
= string_pos (charpos
, string
);
3254 /* Note that we use IT->current.pos, not it->current.string_pos,
3255 for displaying C strings. */
3256 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
3257 if (it
->multibyte_p
)
3259 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
3260 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
3264 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
3265 it
->end_charpos
= it
->string_nchars
= strlen (s
);
3268 it
->method
= next_element_from_c_string
;
3271 /* PRECISION > 0 means don't return more than PRECISION characters
3273 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
3274 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
3276 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
3277 characters have been returned. FIELD_WIDTH == 0 means don't pad,
3278 FIELD_WIDTH < 0 means infinite field width. This is useful for
3279 padding with `-' at the end of a mode line. */
3280 if (field_width
< 0)
3281 field_width
= INFINITY
;
3282 if (field_width
> it
->end_charpos
- charpos
)
3283 it
->end_charpos
= charpos
+ field_width
;
3285 /* Use the standard display table for displaying strings. */
3286 if (DISP_TABLE_P (Vstandard_display_table
))
3287 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
3289 it
->stop_charpos
= charpos
;
3295 /***********************************************************************
3297 ***********************************************************************/
3299 /* Load IT's display element fields with information about the next
3300 display element from the current position of IT. Value is zero if
3301 end of buffer (or C string) is reached. */
3304 get_next_display_element (it
)
3307 /* Non-zero means that we found an display element. Zero means that
3308 we hit the end of what we iterate over. Performance note: the
3309 function pointer `method' used here turns out to be faster than
3310 using a sequence of if-statements. */
3311 int success_p
= (*it
->method
) (it
);
3313 if (it
->what
== IT_CHARACTER
)
3315 /* Map via display table or translate control characters.
3316 IT->c, IT->len etc. have been set to the next character by
3317 the function call above. If we have a display table, and it
3318 contains an entry for IT->c, translate it. Don't do this if
3319 IT->c itself comes from a display table, otherwise we could
3320 end up in an infinite recursion. (An alternative could be to
3321 count the recursion depth of this function and signal an
3322 error when a certain maximum depth is reached.) Is it worth
3324 if (success_p
&& it
->dpvec
== NULL
)
3329 && (dv
= DISP_CHAR_VECTOR (it
->dp
, it
->c
),
3332 struct Lisp_Vector
*v
= XVECTOR (dv
);
3334 /* Return the first character from the display table
3335 entry, if not empty. If empty, don't display the
3336 current character. */
3339 it
->dpvec_char_len
= it
->len
;
3340 it
->dpvec
= v
->contents
;
3341 it
->dpend
= v
->contents
+ v
->size
;
3342 it
->current
.dpvec_index
= 0;
3343 it
->method
= next_element_from_display_vector
;
3346 success_p
= get_next_display_element (it
);
3349 /* Translate control characters into `\003' or `^C' form.
3350 Control characters coming from a display table entry are
3351 currently not translated because we use IT->dpvec to hold
3352 the translation. This could easily be changed but I
3353 don't believe that it is worth doing.
3355 Non-printable multibyte characters are also translated
3357 else if ((it
->c
< ' '
3358 && (it
->area
!= TEXT_AREA
3359 || (it
->c
!= '\n' && it
->c
!= '\t')))
3362 || !CHAR_PRINTABLE_P (it
->c
))
3364 /* IT->c is a control character which must be displayed
3365 either as '\003' or as `^C' where the '\\' and '^'
3366 can be defined in the display table. Fill
3367 IT->ctl_chars with glyphs for what we have to
3368 display. Then, set IT->dpvec to these glyphs. */
3371 if (it
->c
< 128 && it
->ctl_arrow_p
)
3373 /* Set IT->ctl_chars[0] to the glyph for `^'. */
3375 && INTEGERP (DISP_CTRL_GLYPH (it
->dp
))
3376 && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it
->dp
))))
3377 g
= XINT (DISP_CTRL_GLYPH (it
->dp
));
3379 g
= FAST_MAKE_GLYPH ('^', 0);
3380 XSETINT (it
->ctl_chars
[0], g
);
3382 g
= FAST_MAKE_GLYPH (it
->c
^ 0100, 0);
3383 XSETINT (it
->ctl_chars
[1], g
);
3385 /* Set up IT->dpvec and return first character from it. */
3386 it
->dpvec_char_len
= it
->len
;
3387 it
->dpvec
= it
->ctl_chars
;
3388 it
->dpend
= it
->dpvec
+ 2;
3389 it
->current
.dpvec_index
= 0;
3390 it
->method
= next_element_from_display_vector
;
3391 get_next_display_element (it
);
3395 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
3396 int len
= CHAR_STRING (it
->c
, str
);
3400 /* Set IT->ctl_chars[0] to the glyph for `\\'. */
3402 && INTEGERP (DISP_ESCAPE_GLYPH (it
->dp
))
3403 && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
))))
3404 escape_glyph
= XFASTINT (DISP_ESCAPE_GLYPH (it
->dp
));
3406 escape_glyph
= FAST_MAKE_GLYPH ('\\', 0);
3408 for (i
= 0; i
< len
; i
++)
3410 XSETINT (it
->ctl_chars
[i
* 4], escape_glyph
);
3411 /* Insert three more glyphs into IT->ctl_chars for
3412 the octal display of the character. */
3413 g
= FAST_MAKE_GLYPH (((str
[i
] >> 6) & 7) + '0', 0);
3414 XSETINT (it
->ctl_chars
[i
* 4 + 1], g
);
3415 g
= FAST_MAKE_GLYPH (((str
[i
] >> 3) & 7) + '0', 0);
3416 XSETINT (it
->ctl_chars
[i
* 4 + 2], g
);
3417 g
= FAST_MAKE_GLYPH ((str
[i
] & 7) + '0', 0);
3418 XSETINT (it
->ctl_chars
[i
* 4 + 3], g
);
3421 /* Set up IT->dpvec and return the first character
3423 it
->dpvec_char_len
= it
->len
;
3424 it
->dpvec
= it
->ctl_chars
;
3425 it
->dpend
= it
->dpvec
+ len
* 4;
3426 it
->current
.dpvec_index
= 0;
3427 it
->method
= next_element_from_display_vector
;
3428 get_next_display_element (it
);
3433 /* Adjust face id for a multibyte character. There are no
3434 multibyte character in unibyte text. */
3437 && FRAME_WINDOW_P (it
->f
))
3439 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3440 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, it
->c
);
3444 /* Is this character the last one of a run of characters with
3445 box? If yes, set IT->end_of_box_run_p to 1. */
3452 it
->end_of_box_run_p
3453 = ((face_id
= face_after_it_pos (it
),
3454 face_id
!= it
->face_id
)
3455 && (face
= FACE_FROM_ID (it
->f
, face_id
),
3456 face
->box
== FACE_NO_BOX
));
3459 /* Value is 0 if end of buffer or string reached. */
3464 /* Move IT to the next display element.
3466 Functions get_next_display_element and set_iterator_to_next are
3467 separate because I find this arrangement easier to handle than a
3468 get_next_display_element function that also increments IT's
3469 position. The way it is we can first look at an iterator's current
3470 display element, decide whether it fits on a line, and if it does,
3471 increment the iterator position. The other way around we probably
3472 would either need a flag indicating whether the iterator has to be
3473 incremented the next time, or we would have to implement a
3474 decrement position function which would not be easy to write. */
3477 set_iterator_to_next (it
)
3480 if (it
->method
== next_element_from_buffer
)
3482 /* The current display element of IT is a character from
3483 current_buffer. Advance in the buffer, and maybe skip over
3484 invisible lines that are so because of selective display. */
3485 if (ITERATOR_AT_END_OF_LINE_P (it
))
3486 reseat_at_next_visible_line_start (it
, 0);
3489 xassert (it
->len
!= 0);
3490 IT_BYTEPOS (*it
) += it
->len
;
3491 IT_CHARPOS (*it
) += 1;
3492 xassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
3495 else if (it
->method
== next_element_from_composition
)
3497 xassert (it
->cmp_id
>= 0 && it
->cmp_id
< n_compositions
);
3498 if (STRINGP (it
->string
))
3500 IT_STRING_BYTEPOS (*it
) += it
->len
;
3501 IT_STRING_CHARPOS (*it
) += it
->cmp_len
;
3502 it
->method
= next_element_from_string
;
3503 goto consider_string_end
;
3507 IT_BYTEPOS (*it
) += it
->len
;
3508 IT_CHARPOS (*it
) += it
->cmp_len
;
3509 it
->method
= next_element_from_buffer
;
3512 else if (it
->method
== next_element_from_c_string
)
3514 /* Current display element of IT is from a C string. */
3515 IT_BYTEPOS (*it
) += it
->len
;
3516 IT_CHARPOS (*it
) += 1;
3518 else if (it
->method
== next_element_from_display_vector
)
3520 /* Current display element of IT is from a display table entry.
3521 Advance in the display table definition. Reset it to null if
3522 end reached, and continue with characters from buffers/
3524 ++it
->current
.dpvec_index
;
3526 /* Restore face of the iterator to what they were before the
3527 display vector entry (these entries may contain faces). */
3528 it
->face_id
= it
->saved_face_id
;
3530 if (it
->dpvec
+ it
->current
.dpvec_index
== it
->dpend
)
3533 it
->method
= next_element_from_c_string
;
3534 else if (STRINGP (it
->string
))
3535 it
->method
= next_element_from_string
;
3537 it
->method
= next_element_from_buffer
;
3540 it
->current
.dpvec_index
= -1;
3542 /* Skip over characters which were displayed via IT->dpvec. */
3543 if (it
->dpvec_char_len
< 0)
3544 reseat_at_next_visible_line_start (it
, 1);
3545 else if (it
->dpvec_char_len
> 0)
3547 it
->len
= it
->dpvec_char_len
;
3548 set_iterator_to_next (it
);
3552 else if (it
->method
== next_element_from_string
)
3554 /* Current display element is a character from a Lisp string. */
3555 xassert (it
->s
== NULL
&& STRINGP (it
->string
));
3556 IT_STRING_BYTEPOS (*it
) += it
->len
;
3557 IT_STRING_CHARPOS (*it
) += 1;
3559 consider_string_end
:
3561 if (it
->current
.overlay_string_index
>= 0)
3563 /* IT->string is an overlay string. Advance to the
3564 next, if there is one. */
3565 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3566 next_overlay_string (it
);
3570 /* IT->string is not an overlay string. If we reached
3571 its end, and there is something on IT->stack, proceed
3572 with what is on the stack. This can be either another
3573 string, this time an overlay string, or a buffer. */
3574 if (IT_STRING_CHARPOS (*it
) == XSTRING (it
->string
)->size
3578 if (!STRINGP (it
->string
))
3579 it
->method
= next_element_from_buffer
;
3583 else if (it
->method
== next_element_from_image
3584 || it
->method
== next_element_from_stretch
)
3586 /* The position etc with which we have to proceed are on
3587 the stack. The position may be at the end of a string,
3588 if the `display' property takes up the whole string. */
3591 if (STRINGP (it
->string
))
3593 it
->method
= next_element_from_string
;
3594 goto consider_string_end
;
3597 it
->method
= next_element_from_buffer
;
3600 /* There are no other methods defined, so this should be a bug. */
3603 /* Reset flags indicating start and end of a sequence of
3604 characters with box. */
3605 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
3607 xassert (it
->method
!= next_element_from_string
3608 || (STRINGP (it
->string
)
3609 && IT_STRING_CHARPOS (*it
) >= 0));
3613 /* Load IT's display element fields with information about the next
3614 display element which comes from a display table entry or from the
3615 result of translating a control character to one of the forms `^C'
3616 or `\003'. IT->dpvec holds the glyphs to return as characters. */
3619 next_element_from_display_vector (it
)
3623 xassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
3625 /* Remember the current face id in case glyphs specify faces.
3626 IT's face is restored in set_iterator_to_next. */
3627 it
->saved_face_id
= it
->face_id
;
3629 if (INTEGERP (*it
->dpvec
)
3630 && GLYPH_CHAR_VALID_P (XFASTINT (*it
->dpvec
)))
3635 g
= XFASTINT (it
->dpvec
[it
->current
.dpvec_index
]);
3636 it
->c
= FAST_GLYPH_CHAR (g
);
3637 it
->len
= CHAR_LEN (it
->c
);
3639 /* The entry may contain a face id to use. Such a face id is
3640 the id of a Lisp face, not a realized face. A face id of
3641 zero means no face. */
3642 lface_id
= FAST_GLYPH_FACE (g
);
3645 int face_id
= ascii_face_of_lisp_face (it
->f
, lface_id
);
3648 it
->face_id
= face_id
;
3653 /* Display table entry is invalid. Return a space. */
3654 it
->c
= ' ', it
->len
= 1;
3656 /* Don't change position and object of the iterator here. They are
3657 still the values of the character that had this display table
3658 entry or was translated, and that's what we want. */
3659 it
->what
= IT_CHARACTER
;
3664 /* Load IT with the next display element from Lisp string IT->string.
3665 IT->current.string_pos is the current position within the string.
3666 If IT->current.overlay_string_index >= 0, the Lisp string is an
3670 next_element_from_string (it
)
3673 struct text_pos position
;
3675 xassert (STRINGP (it
->string
));
3676 xassert (IT_STRING_CHARPOS (*it
) >= 0);
3677 position
= it
->current
.string_pos
;
3679 /* Time to check for invisible text? */
3680 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
3681 && IT_STRING_CHARPOS (*it
) == it
->stop_charpos
)
3685 /* Since a handler may have changed IT->method, we must
3687 return get_next_display_element (it
);
3690 if (it
->current
.overlay_string_index
>= 0)
3692 /* Get the next character from an overlay string. In overlay
3693 strings, There is no field width or padding with spaces to
3695 if (IT_STRING_CHARPOS (*it
) >= XSTRING (it
->string
)->size
)
3700 else if (STRING_MULTIBYTE (it
->string
))
3702 int remaining
= (STRING_BYTES (XSTRING (it
->string
))
3703 - IT_STRING_BYTEPOS (*it
));
3704 unsigned char *s
= (XSTRING (it
->string
)->data
3705 + IT_STRING_BYTEPOS (*it
));
3706 it
->c
= string_char_and_length (s
, remaining
, &it
->len
);
3710 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3716 /* Get the next character from a Lisp string that is not an
3717 overlay string. Such strings come from the mode line, for
3718 example. We may have to pad with spaces, or truncate the
3719 string. See also next_element_from_c_string. */
3720 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
3725 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
3727 /* Pad with spaces. */
3728 it
->c
= ' ', it
->len
= 1;
3729 CHARPOS (position
) = BYTEPOS (position
) = -1;
3731 else if (STRING_MULTIBYTE (it
->string
))
3733 int maxlen
= (STRING_BYTES (XSTRING (it
->string
))
3734 - IT_STRING_BYTEPOS (*it
));
3735 unsigned char *s
= (XSTRING (it
->string
)->data
3736 + IT_STRING_BYTEPOS (*it
));
3737 it
->c
= string_char_and_length (s
, maxlen
, &it
->len
);
3741 it
->c
= XSTRING (it
->string
)->data
[IT_STRING_BYTEPOS (*it
)];
3746 /* Record what we have and where it came from. Note that we store a
3747 buffer position in IT->position although it could arguably be a
3749 it
->what
= IT_CHARACTER
;
3750 it
->object
= it
->string
;
3751 it
->position
= position
;
3756 /* Load IT with next display element from C string IT->s.
3757 IT->string_nchars is the maximum number of characters to return
3758 from the string. IT->end_charpos may be greater than
3759 IT->string_nchars when this function is called, in which case we
3760 may have to return padding spaces. Value is zero if end of string
3761 reached, including padding spaces. */
3764 next_element_from_c_string (it
)
3770 it
->what
= IT_CHARACTER
;
3771 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
3774 /* IT's position can be greater IT->string_nchars in case a field
3775 width or precision has been specified when the iterator was
3777 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3779 /* End of the game. */
3783 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
3785 /* Pad with spaces. */
3786 it
->c
= ' ', it
->len
= 1;
3787 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
3789 else if (it
->multibyte_p
)
3791 /* Implementation note: The calls to strlen apparently aren't a
3792 performance problem because there is no noticeable performance
3793 difference between Emacs running in unibyte or multibyte mode. */
3794 int maxlen
= strlen (it
->s
) - IT_BYTEPOS (*it
);
3795 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
),
3799 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
3805 /* Set up IT to return characters from an ellipsis, if appropriate.
3806 The definition of the ellipsis glyphs may come from a display table
3807 entry. This function Fills IT with the first glyph from the
3808 ellipsis if an ellipsis is to be displayed. */
3811 next_element_from_ellipsis (it
)
3814 if (it
->selective_display_ellipsis_p
)
3816 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
3818 /* Use the display table definition for `...'. Invalid glyphs
3819 will be handled by the method returning elements from dpvec. */
3820 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
3821 it
->dpvec_char_len
= it
->len
;
3822 it
->dpvec
= v
->contents
;
3823 it
->dpend
= v
->contents
+ v
->size
;
3824 it
->current
.dpvec_index
= 0;
3825 it
->method
= next_element_from_display_vector
;
3829 /* Use default `...' which is stored in default_invis_vector. */
3830 it
->dpvec_char_len
= it
->len
;
3831 it
->dpvec
= default_invis_vector
;
3832 it
->dpend
= default_invis_vector
+ 3;
3833 it
->current
.dpvec_index
= 0;
3834 it
->method
= next_element_from_display_vector
;
3838 reseat_at_next_visible_line_start (it
, 1);
3840 return get_next_display_element (it
);
3844 /* Deliver an image display element. The iterator IT is already
3845 filled with image information (done in handle_display_prop). Value
3850 next_element_from_image (it
)
3853 it
->what
= IT_IMAGE
;
3858 /* Fill iterator IT with next display element from a stretch glyph
3859 property. IT->object is the value of the text property. Value is
3863 next_element_from_stretch (it
)
3866 it
->what
= IT_STRETCH
;
3871 /* Load IT with the next display element from current_buffer. Value
3872 is zero if end of buffer reached. IT->stop_charpos is the next
3873 position at which to stop and check for text properties or buffer
3877 next_element_from_buffer (it
)
3882 /* Check this assumption, otherwise, we would never enter the
3883 if-statement, below. */
3884 xassert (IT_CHARPOS (*it
) >= BEGV
3885 && IT_CHARPOS (*it
) <= it
->stop_charpos
);
3887 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
3889 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
3891 int overlay_strings_follow_p
;
3893 /* End of the game, except when overlay strings follow that
3894 haven't been returned yet. */
3895 if (it
->overlay_strings_at_end_processed_p
)
3896 overlay_strings_follow_p
= 0;
3899 it
->overlay_strings_at_end_processed_p
= 1;
3900 overlay_strings_follow_p
= get_overlay_strings (it
);
3903 if (overlay_strings_follow_p
)
3904 success_p
= get_next_display_element (it
);
3908 it
->position
= it
->current
.pos
;
3915 return get_next_display_element (it
);
3920 /* No face changes, overlays etc. in sight, so just return a
3921 character from current_buffer. */
3924 /* Maybe run the redisplay end trigger hook. Performance note:
3925 This doesn't seem to cost measurable time. */
3926 if (it
->redisplay_end_trigger_charpos
3928 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
3929 run_redisplay_end_trigger_hook (it
);
3931 /* Get the next character, maybe multibyte. */
3932 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
3933 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
3935 int maxlen
= ((IT_BYTEPOS (*it
) >= GPT_BYTE
? ZV_BYTE
: GPT_BYTE
)
3936 - IT_BYTEPOS (*it
));
3937 it
->c
= string_char_and_length (p
, maxlen
, &it
->len
);
3940 it
->c
= *p
, it
->len
= 1;
3942 /* Record what we have and where it came from. */
3943 it
->what
= IT_CHARACTER
;;
3944 it
->object
= it
->w
->buffer
;
3945 it
->position
= it
->current
.pos
;
3947 /* Normally we return the character found above, except when we
3948 really want to return an ellipsis for selective display. */
3953 /* A value of selective > 0 means hide lines indented more
3954 than that number of columns. */
3955 if (it
->selective
> 0
3956 && IT_CHARPOS (*it
) + 1 < ZV
3957 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
3958 IT_BYTEPOS (*it
) + 1,
3961 success_p
= next_element_from_ellipsis (it
);
3962 it
->dpvec_char_len
= -1;
3965 else if (it
->c
== '\r' && it
->selective
== -1)
3967 /* A value of selective == -1 means that everything from the
3968 CR to the end of the line is invisible, with maybe an
3969 ellipsis displayed for it. */
3970 success_p
= next_element_from_ellipsis (it
);
3971 it
->dpvec_char_len
= -1;
3976 /* Value is zero if end of buffer reached. */
3977 xassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
3982 /* Run the redisplay end trigger hook for IT. */
3985 run_redisplay_end_trigger_hook (it
)
3988 Lisp_Object args
[3];
3990 /* IT->glyph_row should be non-null, i.e. we should be actually
3991 displaying something, or otherwise we should not run the hook. */
3992 xassert (it
->glyph_row
);
3994 /* Set up hook arguments. */
3995 args
[0] = Qredisplay_end_trigger_functions
;
3996 args
[1] = it
->window
;
3997 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
3998 it
->redisplay_end_trigger_charpos
= 0;
4000 /* Since we are *trying* to run these functions, don't try to run
4001 them again, even if they get an error. */
4002 it
->w
->redisplay_end_trigger
= Qnil
;
4003 Frun_hook_with_args (3, args
);
4005 /* Notice if it changed the face of the character we are on. */
4006 handle_face_prop (it
);
4010 /* Deliver a composition display element. The iterator IT is already
4011 filled with composition information (done in
4012 handle_composition_prop). Value is always 1. */
4015 next_element_from_composition (it
)
4018 it
->what
= IT_COMPOSITION
;
4019 it
->position
= (STRINGP (it
->string
)
4020 ? it
->current
.string_pos
4027 /***********************************************************************
4028 Moving an iterator without producing glyphs
4029 ***********************************************************************/
4031 /* Move iterator IT to a specified buffer or X position within one
4032 line on the display without producing glyphs.
4034 Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X
4035 whichever is reached first.
4037 TO_CHARPOS <= 0 means no TO_CHARPOS is specified.
4039 TO_X < 0 means that no TO_X is specified. TO_X is normally a value
4040 0 <= TO_X <= IT->last_visible_x. This means in particular, that
4041 TO_X includes the amount by which a window is horizontally
4046 MOVE_POS_MATCH_OR_ZV
4047 - when TO_POS or ZV was reached.
4050 -when TO_X was reached before TO_POS or ZV were reached.
4053 - when we reached the end of the display area and the line must
4057 - when we reached the end of the display area and the line is
4061 - when we stopped at a line end, i.e. a newline or a CR and selective
4064 static enum move_it_result
4065 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
)
4067 int to_charpos
, to_x
, op
;
4069 enum move_it_result result
= MOVE_UNDEFINED
;
4070 struct glyph_row
*saved_glyph_row
;
4072 /* Don't produce glyphs in produce_glyphs. */
4073 saved_glyph_row
= it
->glyph_row
;
4074 it
->glyph_row
= NULL
;
4080 /* Stop when ZV or TO_CHARPOS reached. */
4081 if (!get_next_display_element (it
)
4082 || ((op
& MOVE_TO_POS
) != 0
4083 && BUFFERP (it
->object
)
4084 && IT_CHARPOS (*it
) >= to_charpos
))
4086 result
= MOVE_POS_MATCH_OR_ZV
;
4090 /* The call to produce_glyphs will get the metrics of the
4091 display element IT is loaded with. We record in x the
4092 x-position before this display element in case it does not
4095 PRODUCE_GLYPHS (it
);
4097 if (it
->area
!= TEXT_AREA
)
4099 set_iterator_to_next (it
);
4103 /* The number of glyphs we get back in IT->nglyphs will normally
4104 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
4105 character on a terminal frame, or (iii) a line end. For the
4106 second case, IT->nglyphs - 1 padding glyphs will be present
4107 (on X frames, there is only one glyph produced for a
4108 composite character.
4110 The behavior implemented below means, for continuation lines,
4111 that as many spaces of a TAB as fit on the current line are
4112 displayed there. For terminal frames, as many glyphs of a
4113 multi-glyph character are displayed in the current line, too.
4114 This is what the old redisplay code did, and we keep it that
4115 way. Under X, the whole shape of a complex character must
4116 fit on the line or it will be completely displayed in the
4119 Note that both for tabs and padding glyphs, all glyphs have
4123 /* More than one glyph or glyph doesn't fit on line. All
4124 glyphs have the same width. */
4125 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
4128 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
4130 new_x
= x
+ single_glyph_width
;
4132 /* We want to leave anything reaching TO_X to the caller. */
4133 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
4136 result
= MOVE_X_REACHED
;
4139 else if (/* Lines are continued. */
4140 !it
->truncate_lines_p
4141 && (/* And glyph doesn't fit on the line. */
4142 new_x
> it
->last_visible_x
4143 /* Or it fits exactly and we're on a window
4145 || (new_x
== it
->last_visible_x
4146 && FRAME_WINDOW_P (it
->f
))))
4148 if (/* IT->hpos == 0 means the very first glyph
4149 doesn't fit on the line, e.g. a wide image. */
4151 || (new_x
== it
->last_visible_x
4152 && FRAME_WINDOW_P (it
->f
)))
4155 it
->current_x
= new_x
;
4156 if (i
== it
->nglyphs
- 1)
4157 set_iterator_to_next (it
);
4162 result
= MOVE_LINE_CONTINUED
;
4165 else if (new_x
> it
->first_visible_x
)
4167 /* Glyph is visible. Increment number of glyphs that
4168 would be displayed. */
4173 /* Glyph is completely off the left margin of the display
4174 area. Nothing to do. */
4178 if (result
!= MOVE_UNDEFINED
)
4181 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
4183 /* Stop when TO_X specified and reached. This check is
4184 necessary here because of lines consisting of a line end,
4185 only. The line end will not produce any glyphs and we
4186 would never get MOVE_X_REACHED. */
4187 xassert (it
->nglyphs
== 0);
4188 result
= MOVE_X_REACHED
;
4192 /* Is this a line end? If yes, we're done. */
4193 if (ITERATOR_AT_END_OF_LINE_P (it
))
4195 result
= MOVE_NEWLINE_OR_CR
;
4199 /* The current display element has been consumed. Advance
4201 set_iterator_to_next (it
);
4203 /* Stop if lines are truncated and IT's current x-position is
4204 past the right edge of the window now. */
4205 if (it
->truncate_lines_p
4206 && it
->current_x
>= it
->last_visible_x
)
4208 result
= MOVE_LINE_TRUNCATED
;
4213 /* Restore the iterator settings altered at the beginning of this
4215 it
->glyph_row
= saved_glyph_row
;
4220 /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X,
4221 TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See
4222 the description of enum move_operation_enum.
4224 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
4225 screen line, this function will set IT to the next position >
4229 move_it_to (it
, to_charpos
, to_x
, to_y
, to_vpos
, op
)
4231 int to_charpos
, to_x
, to_y
, to_vpos
;
4234 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
4239 if (op
& MOVE_TO_VPOS
)
4241 /* If no TO_CHARPOS and no TO_X specified, stop at the
4242 start of the line TO_VPOS. */
4243 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
4245 if (it
->vpos
== to_vpos
)
4247 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
4251 /* TO_VPOS >= 0 means stop at TO_X in the line at
4252 TO_VPOS, or at TO_POS, whichever comes first. */
4253 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
4255 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
4257 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
4259 /* We have reached TO_X but not in the line we want. */
4260 skip
= move_it_in_display_line_to (it
, to_charpos
,
4262 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4267 else if (op
& MOVE_TO_Y
)
4269 struct it it_backup
;
4272 /* TO_Y specified means stop at TO_X in the line containing
4273 TO_Y---or at TO_CHARPOS if this is reached first. The
4274 problem is that we can't really tell whether the line
4275 contains TO_Y before we have completely scanned it, and
4276 this may skip past TO_X. What we do is to first scan to
4279 If TO_X is not specified, use a TO_X of zero. The reason
4280 is to make the outcome of this function more predictable.
4281 If we didn't use TO_X == 0, we would stop at the end of
4282 the line which is probably not what a caller would expect
4284 skip
= move_it_in_display_line_to (it
, to_charpos
,
4288 | (op
& MOVE_TO_POS
)));
4290 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
4291 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4294 /* If TO_X was reached, we would like to know whether TO_Y
4295 is in the line. This can only be said if we know the
4296 total line height which requires us to scan the rest of
4299 if (skip
== MOVE_X_REACHED
)
4302 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
4306 /* Now, decide whether TO_Y is in this line. */
4307 line_height
= it
->max_ascent
+ it
->max_descent
;
4309 if (to_y
>= it
->current_y
4310 && to_y
< it
->current_y
+ line_height
)
4312 if (skip
== MOVE_X_REACHED
)
4313 /* If TO_Y is in this line and TO_X was reached above,
4314 we scanned too far. We have to restore IT's settings
4315 to the ones before skipping. */
4319 else if (skip
== MOVE_X_REACHED
)
4322 if (skip
== MOVE_POS_MATCH_OR_ZV
)
4330 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
4334 case MOVE_POS_MATCH_OR_ZV
:
4337 case MOVE_NEWLINE_OR_CR
:
4338 set_iterator_to_next (it
);
4339 it
->continuation_lines_width
= 0;
4342 case MOVE_LINE_TRUNCATED
:
4343 it
->continuation_lines_width
= 0;
4344 reseat_at_next_visible_line_start (it
, 0);
4345 if ((op
& MOVE_TO_POS
) != 0
4346 && IT_CHARPOS (*it
) > to_charpos
)
4350 case MOVE_LINE_CONTINUED
:
4351 it
->continuation_lines_width
+= it
->current_x
;
4358 /* Reset/increment for the next run. */
4359 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
4360 it
->current_x
= it
->hpos
= 0;
4361 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
4363 last_height
= it
->max_ascent
+ it
->max_descent
;
4364 last_max_ascent
= it
->max_ascent
;
4365 it
->max_ascent
= it
->max_descent
= 0;
4371 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
4373 If DY > 0, move IT backward at least that many pixels. DY = 0
4374 means move IT backward to the preceding line start or BEGV. This
4375 function may move over more than DY pixels if IT->current_y - DY
4376 ends up in the middle of a line; in this case IT->current_y will be
4377 set to the top of the line moved to. */
4380 move_it_vertically_backward (it
, dy
)
4384 int nlines
, h
, line_height
;
4386 int start_pos
= IT_CHARPOS (*it
);
4390 /* Estimate how many newlines we must move back. */
4391 nlines
= max (1, dy
/ CANON_Y_UNIT (it
->f
));
4393 /* Set the iterator's position that many lines back. */
4394 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
4395 back_to_previous_visible_line_start (it
);
4397 /* Reseat the iterator here. When moving backward, we don't want
4398 reseat to skip forward over invisible text, set up the iterator
4399 to deliver from overlay strings at the new position etc. So,
4400 use reseat_1 here. */
4401 reseat_1 (it
, it
->current
.pos
, 1);
4403 /* We are now surely at a line start. */
4404 it
->current_x
= it
->hpos
= 0;
4406 /* Move forward and see what y-distance we moved. First move to the
4407 start of the next line so that we get its height. We need this
4408 height to be able to tell whether we reached the specified
4411 it2
.max_ascent
= it2
.max_descent
= 0;
4412 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
4413 MOVE_TO_POS
| MOVE_TO_VPOS
);
4414 xassert (IT_CHARPOS (*it
) >= BEGV
);
4415 line_height
= it2
.max_ascent
+ it2
.max_descent
;
4416 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
4417 xassert (IT_CHARPOS (*it
) >= BEGV
);
4418 h
= it2
.current_y
- it
->current_y
;
4419 nlines
= it2
.vpos
- it
->vpos
;
4421 /* Correct IT's y and vpos position. */
4427 /* DY == 0 means move to the start of the screen line. The
4428 value of nlines is > 0 if continuation lines were involved. */
4430 move_it_by_lines (it
, nlines
, 1);
4431 xassert (IT_CHARPOS (*it
) <= start_pos
);
4435 /* The y-position we try to reach. Note that h has been
4436 subtracted in front of the if-statement. */
4437 int target_y
= it
->current_y
+ h
- dy
;
4439 /* If we did not reach target_y, try to move further backward if
4440 we can. If we moved too far backward, try to move forward. */
4441 if (target_y
< it
->current_y
4442 && IT_CHARPOS (*it
) > BEGV
)
4444 move_it_vertically (it
, target_y
- it
->current_y
);
4445 xassert (IT_CHARPOS (*it
) >= BEGV
);
4447 else if (target_y
>= it
->current_y
+ line_height
4448 && IT_CHARPOS (*it
) < ZV
)
4450 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
4451 xassert (IT_CHARPOS (*it
) >= BEGV
);
4457 /* Move IT by a specified amount of pixel lines DY. DY negative means
4458 move backwards. DY = 0 means move to start of screen line. At the
4459 end, IT will be on the start of a screen line. */
4462 move_it_vertically (it
, dy
)
4467 move_it_vertically_backward (it
, -dy
);
4470 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
4471 MOVE_TO_POS
| MOVE_TO_Y
);
4473 /* If buffer ends in ZV without a newline, move to the start of
4474 the line to satisfy the post-condition. */
4475 if (IT_CHARPOS (*it
) == ZV
4476 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
4477 move_it_by_lines (it
, 0, 0);
4482 /* Return non-zero if some text between buffer positions START_CHARPOS
4483 and END_CHARPOS is invisible. IT->window is the window for text
4487 invisible_text_between_p (it
, start_charpos
, end_charpos
)
4489 int start_charpos
, end_charpos
;
4491 Lisp_Object prop
, limit
;
4492 int invisible_found_p
;
4494 xassert (it
!= NULL
&& start_charpos
<= end_charpos
);
4496 /* Is text at START invisible? */
4497 prop
= Fget_char_property (make_number (start_charpos
), Qinvisible
,
4499 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
4500 invisible_found_p
= 1;
4503 limit
= next_single_char_property_change (make_number (start_charpos
),
4505 make_number (end_charpos
));
4506 invisible_found_p
= XFASTINT (limit
) < end_charpos
;
4509 return invisible_found_p
;
4513 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
4514 negative means move up. DVPOS == 0 means move to the start of the
4515 screen line. NEED_Y_P non-zero means calculate IT->current_y. If
4516 NEED_Y_P is zero, IT->current_y will be left unchanged.
4518 Further optimization ideas: If we would know that IT->f doesn't use
4519 a face with proportional font, we could be faster for
4520 truncate-lines nil. */
4523 move_it_by_lines (it
, dvpos
, need_y_p
)
4525 int dvpos
, need_y_p
;
4527 struct position pos
;
4529 if (!FRAME_WINDOW_P (it
->f
))
4531 struct text_pos textpos
;
4533 /* We can use vmotion on frames without proportional fonts. */
4534 pos
= *vmotion (IT_CHARPOS (*it
), dvpos
, it
->w
);
4535 SET_TEXT_POS (textpos
, pos
.bufpos
, pos
.bytepos
);
4536 reseat (it
, textpos
, 1);
4537 it
->vpos
+= pos
.vpos
;
4538 it
->current_y
+= pos
.vpos
;
4540 else if (dvpos
== 0)
4542 /* DVPOS == 0 means move to the start of the screen line. */
4543 move_it_vertically_backward (it
, 0);
4544 xassert (it
->current_x
== 0 && it
->hpos
== 0);
4548 /* If there are no continuation lines, and if there is no
4549 selective display, try the simple method of moving forward
4550 DVPOS newlines, then see where we are. */
4551 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4553 int shortage
= 0, charpos
;
4555 if (FETCH_BYTE (IT_BYTEPOS (*it
) == '\n'))
4556 charpos
= IT_CHARPOS (*it
) + 1;
4558 charpos
= scan_buffer ('\n', IT_CHARPOS (*it
), 0, dvpos
,
4561 if (!invisible_text_between_p (it
, IT_CHARPOS (*it
), charpos
))
4563 struct text_pos pos
;
4564 CHARPOS (pos
) = charpos
;
4565 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4566 reseat (it
, pos
, 1);
4567 it
->vpos
+= dvpos
- shortage
;
4568 it
->hpos
= it
->current_x
= 0;
4573 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
4578 int start_charpos
, i
;
4580 /* If there are no continuation lines, and if there is no
4581 selective display, try the simple method of moving backward
4583 if (!need_y_p
&& it
->truncate_lines_p
&& it
->selective
== 0)
4586 int charpos
= IT_CHARPOS (*it
);
4587 int bytepos
= IT_BYTEPOS (*it
);
4589 /* If in the middle of a line, go to its start. */
4590 if (charpos
> BEGV
&& FETCH_BYTE (bytepos
- 1) != '\n')
4592 charpos
= find_next_newline_no_quit (charpos
, -1);
4593 bytepos
= CHAR_TO_BYTE (charpos
);
4596 if (charpos
== BEGV
)
4598 struct text_pos pos
;
4599 CHARPOS (pos
) = charpos
;
4600 BYTEPOS (pos
) = bytepos
;
4601 reseat (it
, pos
, 1);
4602 it
->hpos
= it
->current_x
= 0;
4607 charpos
= scan_buffer ('\n', charpos
- 1, 0, dvpos
, &shortage
, 0);
4608 if (!invisible_text_between_p (it
, charpos
, IT_CHARPOS (*it
)))
4610 struct text_pos pos
;
4611 CHARPOS (pos
) = charpos
;
4612 BYTEPOS (pos
) = CHAR_TO_BYTE (charpos
);
4613 reseat (it
, pos
, 1);
4614 it
->vpos
+= dvpos
+ (shortage
? shortage
- 1 : 0);
4615 it
->hpos
= it
->current_x
= 0;
4621 /* Go back -DVPOS visible lines and reseat the iterator there. */
4622 start_charpos
= IT_CHARPOS (*it
);
4623 for (i
= -dvpos
; i
&& IT_CHARPOS (*it
) > BEGV
; --i
)
4624 back_to_previous_visible_line_start (it
);
4625 reseat (it
, it
->current
.pos
, 1);
4626 it
->current_x
= it
->hpos
= 0;
4628 /* Above call may have moved too far if continuation lines
4629 are involved. Scan forward and see if it did. */
4631 it2
.vpos
= it2
.current_y
= 0;
4632 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
4633 it
->vpos
-= it2
.vpos
;
4634 it
->current_y
-= it2
.current_y
;
4635 it
->current_x
= it
->hpos
= 0;
4637 /* If we moved too far, move IT some lines forward. */
4638 if (it2
.vpos
> -dvpos
)
4640 int delta
= it2
.vpos
+ dvpos
;
4641 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
4648 /***********************************************************************
4650 ***********************************************************************/
4653 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
4657 add_to_log (format
, arg1
, arg2
)
4659 Lisp_Object arg1
, arg2
;
4661 Lisp_Object args
[3];
4662 Lisp_Object msg
, fmt
;
4665 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4668 GCPRO4 (fmt
, msg
, arg1
, arg2
);
4670 args
[0] = fmt
= build_string (format
);
4673 msg
= Fformat (3, args
);
4675 len
= STRING_BYTES (XSTRING (msg
)) + 1;
4676 buffer
= (char *) alloca (len
);
4677 strcpy (buffer
, XSTRING (msg
)->data
);
4679 message_dolog (buffer
, len
, 1, 0);
4684 /* Output a newline in the *Messages* buffer if "needs" one. */
4687 message_log_maybe_newline ()
4689 if (message_log_need_newline
)
4690 message_dolog ("", 0, 1, 0);
4694 /* Add a string M of length LEN to the message log, optionally
4695 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
4696 nonzero, means interpret the contents of M as multibyte. This
4697 function calls low-level routines in order to bypass text property
4698 hooks, etc. which might not be safe to run. */
4701 message_dolog (m
, len
, nlflag
, multibyte
)
4703 int len
, nlflag
, multibyte
;
4705 if (!NILP (Vmessage_log_max
))
4707 struct buffer
*oldbuf
;
4708 Lisp_Object oldpoint
, oldbegv
, oldzv
;
4709 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4710 int point_at_end
= 0;
4712 Lisp_Object old_deactivate_mark
, tem
;
4713 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4715 old_deactivate_mark
= Vdeactivate_mark
;
4716 oldbuf
= current_buffer
;
4717 Fset_buffer (Fget_buffer_create (build_string ("*Messages*")));
4718 current_buffer
->undo_list
= Qt
;
4720 oldpoint
= Fpoint_marker ();
4721 oldbegv
= Fpoint_min_marker ();
4722 oldzv
= Fpoint_max_marker ();
4723 GCPRO4 (oldpoint
, oldbegv
, oldzv
, old_deactivate_mark
);
4731 BEGV_BYTE
= BEG_BYTE
;
4734 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4736 /* Insert the string--maybe converting multibyte to single byte
4737 or vice versa, so that all the text fits the buffer. */
4739 && NILP (current_buffer
->enable_multibyte_characters
))
4742 unsigned char work
[1];
4744 /* Convert a multibyte string to single-byte
4745 for the *Message* buffer. */
4746 for (i
= 0; i
< len
; i
+= nbytes
)
4748 c
= string_char_and_length (m
+ i
, len
- i
, &nbytes
);
4749 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
4751 : multibyte_char_to_unibyte (c
, Qnil
));
4752 insert_1_both (work
, 1, 1, 1, 0, 0);
4755 else if (! multibyte
4756 && ! NILP (current_buffer
->enable_multibyte_characters
))
4759 unsigned char *msg
= (unsigned char *) m
;
4760 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
4761 /* Convert a single-byte string to multibyte
4762 for the *Message* buffer. */
4763 for (i
= 0; i
< len
; i
++)
4765 c
= unibyte_char_to_multibyte (msg
[i
]);
4766 nbytes
= CHAR_STRING (c
, str
);
4767 insert_1_both (str
, 1, nbytes
, 1, 0, 0);
4771 insert_1 (m
, len
, 1, 0, 0);
4775 int this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
, dup
;
4776 insert_1 ("\n", 1, 1, 0, 0);
4778 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4780 this_bol_byte
= PT_BYTE
;
4784 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
4786 prev_bol_byte
= PT_BYTE
;
4788 dup
= message_log_check_duplicate (prev_bol
, prev_bol_byte
,
4789 this_bol
, this_bol_byte
);
4792 del_range_both (prev_bol
, prev_bol_byte
,
4793 this_bol
, this_bol_byte
, 0);
4799 /* If you change this format, don't forget to also
4800 change message_log_check_duplicate. */
4801 sprintf (dupstr
, " [%d times]", dup
);
4802 duplen
= strlen (dupstr
);
4803 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
4804 insert_1 (dupstr
, duplen
, 1, 0, 1);
4809 if (NATNUMP (Vmessage_log_max
))
4811 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
4812 -XFASTINT (Vmessage_log_max
) - 1, 0);
4813 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
4816 BEGV
= XMARKER (oldbegv
)->charpos
;
4817 BEGV_BYTE
= marker_byte_position (oldbegv
);
4826 ZV
= XMARKER (oldzv
)->charpos
;
4827 ZV_BYTE
= marker_byte_position (oldzv
);
4831 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
4833 /* We can't do Fgoto_char (oldpoint) because it will run some
4835 TEMP_SET_PT_BOTH (XMARKER (oldpoint
)->charpos
,
4836 XMARKER (oldpoint
)->bytepos
);
4839 free_marker (oldpoint
);
4840 free_marker (oldbegv
);
4841 free_marker (oldzv
);
4843 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
4844 set_buffer_internal (oldbuf
);
4846 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4847 message_log_need_newline
= !nlflag
;
4848 Vdeactivate_mark
= old_deactivate_mark
;
4853 /* We are at the end of the buffer after just having inserted a newline.
4854 (Note: We depend on the fact we won't be crossing the gap.)
4855 Check to see if the most recent message looks a lot like the previous one.
4856 Return 0 if different, 1 if the new one should just replace it, or a
4857 value N > 1 if we should also append " [N times]". */
4860 message_log_check_duplicate (prev_bol
, prev_bol_byte
, this_bol
, this_bol_byte
)
4861 int prev_bol
, this_bol
;
4862 int prev_bol_byte
, this_bol_byte
;
4865 int len
= Z_BYTE
- 1 - this_bol_byte
;
4867 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
4868 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
4870 for (i
= 0; i
< len
; i
++)
4872 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.'
4881 if (*p1
++ == ' ' && *p1
++ == '[')
4884 while (*p1
>= '0' && *p1
<= '9')
4885 n
= n
* 10 + *p1
++ - '0';
4886 if (strncmp (p1
, " times]\n", 8) == 0)
4893 /* Display an echo area message M with a specified length of LEN
4894 chars. The string may include null characters. If M is 0, clear
4895 out any existing message, and let the mini-buffer text show through.
4897 The buffer M must continue to exist until after the echo area gets
4898 cleared or some other message gets displayed there. This means do
4899 not pass text that is stored in a Lisp string; do not pass text in
4900 a buffer that was alloca'd. */
4903 message2 (m
, len
, multibyte
)
4908 /* First flush out any partial line written with print. */
4909 message_log_maybe_newline ();
4911 message_dolog (m
, len
, 1, multibyte
);
4912 message2_nolog (m
, len
, multibyte
);
4916 /* The non-logging counterpart of message2. */
4919 message2_nolog (m
, len
, multibyte
)
4923 struct frame
*sf
= SELECTED_FRAME ();
4924 message_enable_multibyte
= multibyte
;
4928 if (noninteractive_need_newline
)
4929 putc ('\n', stderr
);
4930 noninteractive_need_newline
= 0;
4932 fwrite (m
, len
, 1, stderr
);
4933 if (cursor_in_echo_area
== 0)
4934 fprintf (stderr
, "\n");
4937 /* A null message buffer means that the frame hasn't really been
4938 initialized yet. Error messages get reported properly by
4939 cmd_error, so this must be just an informative message; toss it. */
4940 else if (INTERACTIVE
4941 && sf
->glyphs_initialized_p
4942 && FRAME_MESSAGE_BUF (sf
))
4944 Lisp_Object mini_window
;
4947 /* Get the frame containing the mini-buffer
4948 that the selected frame is using. */
4949 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
4950 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
4952 FRAME_SAMPLE_VISIBILITY (f
);
4953 if (FRAME_VISIBLE_P (sf
)
4954 && ! FRAME_VISIBLE_P (f
))
4955 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
4959 set_message (m
, Qnil
, len
, multibyte
);
4960 if (minibuffer_auto_raise
)
4961 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
4964 clear_message (1, 1);
4966 do_pending_window_change (0);
4967 echo_area_display (1);
4968 do_pending_window_change (0);
4969 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
4970 (*frame_up_to_date_hook
) (f
);
4975 /* Display an echo area message M with a specified length of NBYTES
4976 bytes. The string may include null characters. If M is not a
4977 string, clear out any existing message, and let the mini-buffer
4978 text show through. */
4981 message3 (m
, nbytes
, multibyte
)
4986 struct gcpro gcpro1
;
4990 /* First flush out any partial line written with print. */
4991 message_log_maybe_newline ();
4993 message_dolog (XSTRING (m
)->data
, nbytes
, 1, multibyte
);
4994 message3_nolog (m
, nbytes
, multibyte
);
5000 /* The non-logging version of message3. */
5003 message3_nolog (m
, nbytes
, multibyte
)
5005 int nbytes
, multibyte
;
5007 struct frame
*sf
= SELECTED_FRAME ();
5008 message_enable_multibyte
= multibyte
;
5012 if (noninteractive_need_newline
)
5013 putc ('\n', stderr
);
5014 noninteractive_need_newline
= 0;
5016 fwrite (XSTRING (m
)->data
, nbytes
, 1, stderr
);
5017 if (cursor_in_echo_area
== 0)
5018 fprintf (stderr
, "\n");
5021 /* A null message buffer means that the frame hasn't really been
5022 initialized yet. Error messages get reported properly by
5023 cmd_error, so this must be just an informative message; toss it. */
5024 else if (INTERACTIVE
5025 && sf
->glyphs_initialized_p
5026 && FRAME_MESSAGE_BUF (sf
))
5028 Lisp_Object mini_window
;
5032 /* Get the frame containing the mini-buffer
5033 that the selected frame is using. */
5034 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5035 frame
= XWINDOW (mini_window
)->frame
;
5038 FRAME_SAMPLE_VISIBILITY (f
);
5039 if (FRAME_VISIBLE_P (sf
)
5040 && !FRAME_VISIBLE_P (f
))
5041 Fmake_frame_visible (frame
);
5043 if (STRINGP (m
) && XSTRING (m
)->size
)
5045 set_message (NULL
, m
, nbytes
, multibyte
);
5046 if (minibuffer_auto_raise
)
5047 Fraise_frame (frame
);
5050 clear_message (1, 1);
5052 do_pending_window_change (0);
5053 echo_area_display (1);
5054 do_pending_window_change (0);
5055 if (frame_up_to_date_hook
!= 0 && ! gc_in_progress
)
5056 (*frame_up_to_date_hook
) (f
);
5061 /* Display a null-terminated echo area message M. If M is 0, clear
5062 out any existing message, and let the mini-buffer text show through.
5064 The buffer M must continue to exist until after the echo area gets
5065 cleared or some other message gets displayed there. Do not pass
5066 text that is stored in a Lisp string. Do not pass text in a buffer
5067 that was alloca'd. */
5073 message2 (m
, (m
? strlen (m
) : 0), 0);
5077 /* The non-logging counterpart of message1. */
5083 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
5086 /* Display a message M which contains a single %s
5087 which gets replaced with STRING. */
5090 message_with_string (m
, string
, log
)
5099 if (noninteractive_need_newline
)
5100 putc ('\n', stderr
);
5101 noninteractive_need_newline
= 0;
5102 fprintf (stderr
, m
, XSTRING (string
)->data
);
5103 if (cursor_in_echo_area
== 0)
5104 fprintf (stderr
, "\n");
5108 else if (INTERACTIVE
)
5110 /* The frame whose minibuffer we're going to display the message on.
5111 It may be larger than the selected frame, so we need
5112 to use its buffer, not the selected frame's buffer. */
5113 Lisp_Object mini_window
;
5114 struct frame
*f
, *sf
= SELECTED_FRAME ();
5116 /* Get the frame containing the minibuffer
5117 that the selected frame is using. */
5118 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5119 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5121 /* A null message buffer means that the frame hasn't really been
5122 initialized yet. Error messages get reported properly by
5123 cmd_error, so this must be just an informative message; toss it. */
5124 if (FRAME_MESSAGE_BUF (f
))
5128 a
[0] = (char *) XSTRING (string
)->data
;
5130 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5131 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5134 message2 (FRAME_MESSAGE_BUF (f
), len
,
5135 STRING_MULTIBYTE (string
));
5137 message2_nolog (FRAME_MESSAGE_BUF (f
), len
,
5138 STRING_MULTIBYTE (string
));
5140 /* Print should start at the beginning of the message
5141 buffer next time. */
5142 message_buf_print
= 0;
5148 /* Dump an informative message to the minibuf. If M is 0, clear out
5149 any existing message, and let the mini-buffer text show through. */
5153 message (m
, a1
, a2
, a3
)
5155 EMACS_INT a1
, a2
, a3
;
5161 if (noninteractive_need_newline
)
5162 putc ('\n', stderr
);
5163 noninteractive_need_newline
= 0;
5164 fprintf (stderr
, m
, a1
, a2
, a3
);
5165 if (cursor_in_echo_area
== 0)
5166 fprintf (stderr
, "\n");
5170 else if (INTERACTIVE
)
5172 /* The frame whose mini-buffer we're going to display the message
5173 on. It may be larger than the selected frame, so we need to
5174 use its buffer, not the selected frame's buffer. */
5175 Lisp_Object mini_window
;
5176 struct frame
*f
, *sf
= SELECTED_FRAME ();
5178 /* Get the frame containing the mini-buffer
5179 that the selected frame is using. */
5180 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5181 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
5183 /* A null message buffer means that the frame hasn't really been
5184 initialized yet. Error messages get reported properly by
5185 cmd_error, so this must be just an informative message; toss
5187 if (FRAME_MESSAGE_BUF (f
))
5198 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5199 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3, a
);
5201 len
= doprnt (FRAME_MESSAGE_BUF (f
),
5202 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, 3,
5204 #endif /* NO_ARG_ARRAY */
5206 message2 (FRAME_MESSAGE_BUF (f
), len
, 0);
5211 /* Print should start at the beginning of the message
5212 buffer next time. */
5213 message_buf_print
= 0;
5219 /* The non-logging version of message. */
5222 message_nolog (m
, a1
, a2
, a3
)
5224 EMACS_INT a1
, a2
, a3
;
5226 Lisp_Object old_log_max
;
5227 old_log_max
= Vmessage_log_max
;
5228 Vmessage_log_max
= Qnil
;
5229 message (m
, a1
, a2
, a3
);
5230 Vmessage_log_max
= old_log_max
;
5234 /* Display the current message in the current mini-buffer. This is
5235 only called from error handlers in process.c, and is not time
5241 if (!NILP (echo_area_buffer
[0]))
5244 string
= Fcurrent_message ();
5245 message3 (string
, XSTRING (string
)->size
,
5246 !NILP (current_buffer
->enable_multibyte_characters
));
5251 /* Make sure echo area buffers in echo_buffers[] are life. If they
5252 aren't, make new ones. */
5255 ensure_echo_area_buffers ()
5259 for (i
= 0; i
< 2; ++i
)
5260 if (!BUFFERP (echo_buffer
[i
])
5261 || NILP (XBUFFER (echo_buffer
[i
])->name
))
5264 sprintf (name
, " *Echo Area %d*", i
);
5265 echo_buffer
[i
] = Fget_buffer_create (build_string (name
));
5270 /* Call FN with args A1..A5 with either the current or last displayed
5271 echo_area_buffer as current buffer.
5273 WHICH zero means use the current message buffer
5274 echo_area_buffer[0]. If that is nil, choose a suitable buffer
5275 from echo_buffer[] and clear it.
5277 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
5278 suitable buffer from echo_buffer[] and clear it.
5280 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
5281 that the current message becomes the last displayed one, make
5282 choose a suitable buffer for echo_area_buffer[0], and clear it.
5284 Value is what FN returns. */
5287 with_echo_area_buffer (w
, which
, fn
, a1
, a2
, a3
, a4
, a5
)
5291 int a1
, a2
, a3
, a4
, a5
;
5294 int this_one
, the_other
, clear_buffer_p
, rc
;
5295 int count
= specpdl_ptr
- specpdl
;
5297 /* If buffers aren't life, make new ones. */
5298 ensure_echo_area_buffers ();
5303 this_one
= 0, the_other
= 1;
5305 this_one
= 1, the_other
= 0;
5308 this_one
= 0, the_other
= 1;
5311 /* We need a fresh one in case the current echo buffer equals
5312 the one containing the last displayed echo area message. */
5313 if (!NILP (echo_area_buffer
[this_one
])
5314 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
5315 echo_area_buffer
[this_one
] = Qnil
;
5318 /* Choose a suitable buffer from echo_buffer[] is we don't
5320 if (NILP (echo_area_buffer
[this_one
]))
5322 echo_area_buffer
[this_one
]
5323 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
5324 ? echo_buffer
[the_other
]
5325 : echo_buffer
[this_one
]);
5329 buffer
= echo_area_buffer
[this_one
];
5331 record_unwind_protect (unwind_with_echo_area_buffer
,
5332 with_echo_area_buffer_unwind_data (w
));
5334 /* Make the echo area buffer current. Note that for display
5335 purposes, it is not necessary that the displayed window's buffer
5336 == current_buffer, except for text property lookup. So, let's
5337 only set that buffer temporarily here without doing a full
5338 Fset_window_buffer. We must also change w->pointm, though,
5339 because otherwise an assertions in unshow_buffer fails, and Emacs
5341 set_buffer_internal_1 (XBUFFER (buffer
));
5345 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
5347 current_buffer
->truncate_lines
= Qnil
;
5348 current_buffer
->undo_list
= Qt
;
5349 current_buffer
->read_only
= Qnil
;
5351 if (clear_buffer_p
&& Z
> BEG
)
5354 xassert (BEGV
>= BEG
);
5355 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5357 rc
= fn (a1
, a2
, a3
, a4
, a5
);
5359 xassert (BEGV
>= BEG
);
5360 xassert (ZV
<= Z
&& ZV
>= BEGV
);
5362 unbind_to (count
, Qnil
);
5367 /* Save state that should be preserved around the call to the function
5368 FN called in with_echo_area_buffer. */
5371 with_echo_area_buffer_unwind_data (w
)
5377 /* Reduce consing by keeping one vector in
5378 Vwith_echo_area_save_vector. */
5379 vector
= Vwith_echo_area_save_vector
;
5380 Vwith_echo_area_save_vector
= Qnil
;
5383 vector
= Fmake_vector (make_number (7), Qnil
);
5385 XSETBUFFER (XVECTOR (vector
)->contents
[i
], current_buffer
); ++i
;
5386 XVECTOR (vector
)->contents
[i
++] = Vdeactivate_mark
;
5387 XVECTOR (vector
)->contents
[i
++] = make_number (windows_or_buffers_changed
);
5391 XSETWINDOW (XVECTOR (vector
)->contents
[i
], w
); ++i
;
5392 XVECTOR (vector
)->contents
[i
++] = w
->buffer
;
5393 XVECTOR (vector
)->contents
[i
++]
5394 = make_number (XMARKER (w
->pointm
)->charpos
);
5395 XVECTOR (vector
)->contents
[i
++]
5396 = make_number (XMARKER (w
->pointm
)->bytepos
);
5402 XVECTOR (vector
)->contents
[i
++] = Qnil
;
5405 xassert (i
== XVECTOR (vector
)->size
);
5410 /* Restore global state from VECTOR which was created by
5411 with_echo_area_buffer_unwind_data. */
5414 unwind_with_echo_area_buffer (vector
)
5419 set_buffer_internal_1 (XBUFFER (XVECTOR (vector
)->contents
[i
])); ++i
;
5420 Vdeactivate_mark
= XVECTOR (vector
)->contents
[i
]; ++i
;
5421 windows_or_buffers_changed
= XFASTINT (XVECTOR (vector
)->contents
[i
]); ++i
;
5423 if (WINDOWP (XVECTOR (vector
)->contents
[i
]))
5426 Lisp_Object buffer
, charpos
, bytepos
;
5428 w
= XWINDOW (XVECTOR (vector
)->contents
[i
]); ++i
;
5429 buffer
= XVECTOR (vector
)->contents
[i
]; ++i
;
5430 charpos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5431 bytepos
= XVECTOR (vector
)->contents
[i
]; ++i
;
5434 set_marker_both (w
->pointm
, buffer
,
5435 XFASTINT (charpos
), XFASTINT (bytepos
));
5438 Vwith_echo_area_save_vector
= vector
;
5443 /* Set up the echo area for use by print functions. MULTIBYTE_P
5444 non-zero means we will print multibyte. */
5447 setup_echo_area_for_printing (multibyte_p
)
5450 ensure_echo_area_buffers ();
5452 if (!message_buf_print
)
5454 /* A message has been output since the last time we printed.
5455 Choose a fresh echo area buffer. */
5456 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
5457 echo_area_buffer
[0] = echo_buffer
[1];
5459 echo_area_buffer
[0] = echo_buffer
[0];
5461 /* Switch to that buffer and clear it. */
5462 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5465 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5467 /* Set up the buffer for the multibyteness we need. */
5469 != !NILP (current_buffer
->enable_multibyte_characters
))
5470 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
5472 /* Raise the frame containing the echo area. */
5473 if (minibuffer_auto_raise
)
5475 struct frame
*sf
= SELECTED_FRAME ();
5476 Lisp_Object mini_window
;
5477 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5478 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
5481 message_buf_print
= 1;
5483 else if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
5484 /* Someone switched buffers between print requests. */
5485 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
5489 /* Display an echo area message in window W. Value is non-zero if W's
5490 height is changed. If display_last_displayed_message_p is
5491 non-zero, display the message that was last displayed, otherwise
5492 display the current message. */
5495 display_echo_area (w
)
5498 int i
, no_message_p
, window_height_changed_p
, count
;
5500 /* Temporarily disable garbage collections while displaying the echo
5501 area. This is done because a GC can print a message itself.
5502 That message would modify the echo area buffer's contents while a
5503 redisplay of the buffer is going on, and seriously confuse
5505 count
= inhibit_garbage_collection ();
5507 /* If there is no message, we must call display_echo_area_1
5508 nevertheless because it resizes the window. But we will have to
5509 reset the echo_area_buffer in question to nil at the end because
5510 with_echo_area_buffer will sets it to an empty buffer. */
5511 i
= display_last_displayed_message_p
? 1 : 0;
5512 no_message_p
= NILP (echo_area_buffer
[i
]);
5514 window_height_changed_p
5515 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
5516 (int (*) ()) display_echo_area_1
, w
);
5519 echo_area_buffer
[i
] = Qnil
;
5521 unbind_to (count
, Qnil
);
5522 return window_height_changed_p
;
5526 /* Helper for display_echo_area. Display the current buffer which
5527 contains the current echo area message in window W, a mini-window.
5528 Change the height of W so that all of the message is displayed.
5529 Value is non-zero if height of W was changed. */
5532 display_echo_area_1 (w
)
5536 struct text_pos start
;
5537 int window_height_changed_p
= 0;
5539 /* Do this before displaying, so that we have a large enough glyph
5540 matrix for the display. */
5541 window_height_changed_p
= resize_mini_window (w
, 0);
5544 clear_glyph_matrix (w
->desired_matrix
);
5545 XSETWINDOW (window
, w
);
5546 SET_TEXT_POS (start
, BEG
, BEG_BYTE
);
5547 try_window (window
, start
);
5549 return window_height_changed_p
;
5553 /* Resize the echo area window to exactly the size needed for the
5554 currently displayed message, if there is one. */
5557 resize_echo_area_axactly ()
5559 if (BUFFERP (echo_area_buffer
[0])
5560 && WINDOWP (echo_area_window
))
5562 struct window
*w
= XWINDOW (echo_area_window
);
5565 resized_p
= with_echo_area_buffer (w
, 0,
5566 (int (*) ()) resize_mini_window
,
5570 ++windows_or_buffers_changed
;
5571 ++update_mode_lines
;
5572 redisplay_internal (0);
5578 /* Resize mini-window W to fit the size of its contents. EXACT:P
5579 means size the window exactly to the size needed. Otherwise, it's
5580 only enlarged until W's buffer is empty. Value is non-zero if
5581 the window height has been changed. */
5584 resize_mini_window (w
, exact_p
)
5588 struct frame
*f
= XFRAME (w
->frame
);
5589 int window_height_changed_p
= 0;
5591 xassert (MINI_WINDOW_P (w
));
5593 /* Nil means don't try to resize. */
5594 if (NILP (Vmax_mini_window_height
)
5595 || (FRAME_X_P (f
) && f
->output_data
.x
== NULL
))
5598 if (!FRAME_MINIBUF_ONLY_P (f
))
5601 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5602 int total_height
= XFASTINT (root
->height
) + XFASTINT (w
->height
);
5603 int height
, max_height
;
5604 int unit
= CANON_Y_UNIT (f
);
5605 struct text_pos start
;
5607 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
5609 /* Compute the max. number of lines specified by the user. */
5610 if (FLOATP (Vmax_mini_window_height
))
5611 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
5612 else if (INTEGERP (Vmax_mini_window_height
))
5613 max_height
= XINT (Vmax_mini_window_height
);
5615 max_height
= total_height
/ 4;
5617 /* Correct that max. height if it's bogus. */
5618 max_height
= max (1, max_height
);
5619 max_height
= min (total_height
, max_height
);
5621 /* Find out the height of the text in the window. */
5623 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
5624 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
5625 height
= it
.current_y
+ last_height
;
5627 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
5628 height
= (height
+ unit
- 1) / unit
;
5630 /* Compute a suitable window start. */
5631 if (height
> max_height
)
5633 height
= max_height
;
5634 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
5635 move_it_vertically_backward (&it
, (height
- 1) * unit
);
5636 start
= it
.current
.pos
;
5639 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5640 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
5642 /* Let it grow only, until we display an empty message, in which
5643 case the window shrinks again. */
5644 if (height
> XFASTINT (w
->height
))
5646 int old_height
= XFASTINT (w
->height
);
5647 freeze_window_starts (f
, 1);
5648 grow_mini_window (w
, height
- XFASTINT (w
->height
));
5649 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5651 else if (height
< XFASTINT (w
->height
)
5652 && (exact_p
|| BEGV
== ZV
))
5654 int old_height
= XFASTINT (w
->height
);
5655 freeze_window_starts (f
, 0);
5656 shrink_mini_window (w
);
5657 window_height_changed_p
= XFASTINT (w
->height
) != old_height
;
5661 return window_height_changed_p
;
5665 /* Value is the current message, a string, or nil if there is no
5673 if (NILP (echo_area_buffer
[0]))
5677 with_echo_area_buffer (0, 0, (int (*) ()) current_message_1
, &msg
);
5679 echo_area_buffer
[0] = Qnil
;
5687 current_message_1 (msg
)
5691 *msg
= make_buffer_string (BEG
, Z
, 1);
5698 /* Push the current message on Vmessage_stack for later restauration
5699 by restore_message. Value is non-zero if the current message isn't
5700 empty. This is a relatively infrequent operation, so it's not
5701 worth optimizing. */
5707 msg
= current_message ();
5708 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
5709 return STRINGP (msg
);
5713 /* Restore message display from the top of Vmessage_stack. */
5720 xassert (CONSP (Vmessage_stack
));
5721 msg
= XCAR (Vmessage_stack
);
5723 message3_nolog (msg
, STRING_BYTES (XSTRING (msg
)), STRING_MULTIBYTE (msg
));
5725 message3_nolog (msg
, 0, 0);
5729 /* Pop the top-most entry off Vmessage_stack. */
5734 xassert (CONSP (Vmessage_stack
));
5735 Vmessage_stack
= XCDR (Vmessage_stack
);
5739 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
5740 exits. If the stack is not empty, we have a missing pop_message
5744 check_message_stack ()
5746 if (!NILP (Vmessage_stack
))
5751 /* Truncate to NCHARS what will be displayed in the echo area the next
5752 time we display it---but don't redisplay it now. */
5755 truncate_echo_area (nchars
)
5759 echo_area_buffer
[0] = Qnil
;
5760 /* A null message buffer means that the frame hasn't really been
5761 initialized yet. Error messages get reported properly by
5762 cmd_error, so this must be just an informative message; toss it. */
5763 else if (!noninteractive
5765 && !NILP (echo_area_buffer
[0]))
5767 struct frame
*sf
= SELECTED_FRAME ();
5768 if (FRAME_MESSAGE_BUF (sf
))
5769 with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1
, nchars
);
5774 /* Helper function for truncate_echo_area. Truncate the current
5775 message to at most NCHARS characters. */
5778 truncate_message_1 (nchars
)
5781 if (BEG
+ nchars
< Z
)
5782 del_range (BEG
+ nchars
, Z
);
5784 echo_area_buffer
[0] = Qnil
;
5789 /* Set the current message to a substring of S or STRING.
5791 If STRING is a Lisp string, set the message to the first NBYTES
5792 bytes from STRING. NBYTES zero means use the whole string. If
5793 STRING is multibyte, the message will be displayed multibyte.
5795 If S is not null, set the message to the first LEN bytes of S. LEN
5796 zero means use the whole string. MULTIBYTE_P non-zero means S is
5797 multibyte. Display the message multibyte in that case. */
5800 set_message (s
, string
, nbytes
, multibyte_p
)
5805 message_enable_multibyte
5806 = ((s
&& multibyte_p
)
5807 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
5809 with_echo_area_buffer (0, -1, (int (*) ()) set_message_1
,
5810 s
, string
, nbytes
, multibyte_p
);
5811 message_buf_print
= 0;
5815 /* Helper function for set_message. Arguments have the same meaning
5816 as there. This function is called with the echo area buffer being
5820 set_message_1 (s
, string
, nbytes
, multibyte_p
)
5823 int nbytes
, multibyte_p
;
5827 /* Change multibyteness of the echo buffer appropriately. */
5828 if (message_enable_multibyte
5829 != !NILP (current_buffer
->enable_multibyte_characters
))
5830 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
5832 /* Insert new message at BEG. */
5833 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
5835 if (STRINGP (string
))
5840 nbytes
= XSTRING (string
)->size_byte
;
5841 nchars
= string_byte_to_char (string
, nbytes
);
5843 /* This function takes care of single/multibyte conversion. We
5844 just have to ensure that the echo area buffer has the right
5845 setting of enable_multibyte_characters. */
5846 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
5851 nbytes
= strlen (s
);
5853 if (multibyte_p
&& NILP (current_buffer
->enable_multibyte_characters
))
5855 /* Convert from multi-byte to single-byte. */
5857 unsigned char work
[1];
5859 /* Convert a multibyte string to single-byte. */
5860 for (i
= 0; i
< nbytes
; i
+= n
)
5862 c
= string_char_and_length (s
+ i
, nbytes
- i
, &n
);
5863 work
[0] = (SINGLE_BYTE_CHAR_P (c
)
5865 : multibyte_char_to_unibyte (c
, Qnil
));
5866 insert_1_both (work
, 1, 1, 1, 0, 0);
5869 else if (!multibyte_p
5870 && !NILP (current_buffer
->enable_multibyte_characters
))
5872 /* Convert from single-byte to multi-byte. */
5874 unsigned char *msg
= (unsigned char *) s
;
5875 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
5877 /* Convert a single-byte string to multibyte. */
5878 for (i
= 0; i
< nbytes
; i
++)
5880 c
= unibyte_char_to_multibyte (msg
[i
]);
5881 n
= CHAR_STRING (c
, str
);
5882 insert_1_both (str
, 1, n
, 1, 0, 0);
5886 insert_1 (s
, nbytes
, 1, 0, 0);
5893 /* Clear messages. CURRENT_P non-zero means clear the current
5894 message. LAST_DISPLAYED_P non-zero means clear the message
5898 clear_message (current_p
, last_displayed_p
)
5899 int current_p
, last_displayed_p
;
5902 echo_area_buffer
[0] = Qnil
;
5904 if (last_displayed_p
)
5905 echo_area_buffer
[1] = Qnil
;
5907 message_buf_print
= 0;
5910 /* Clear garbaged frames.
5912 This function is used where the old redisplay called
5913 redraw_garbaged_frames which in turn called redraw_frame which in
5914 turn called clear_frame. The call to clear_frame was a source of
5915 flickering. I believe a clear_frame is not necessary. It should
5916 suffice in the new redisplay to invalidate all current matrices,
5917 and ensure a complete redisplay of all windows. */
5920 clear_garbaged_frames ()
5924 Lisp_Object tail
, frame
;
5926 FOR_EACH_FRAME (tail
, frame
)
5928 struct frame
*f
= XFRAME (frame
);
5930 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
5932 clear_current_matrices (f
);
5938 ++windows_or_buffers_changed
;
5943 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
5944 is non-zero update selected_frame. Value is non-zero if the
5945 mini-windows height has been changed. */
5948 echo_area_display (update_frame_p
)
5951 Lisp_Object mini_window
;
5954 int window_height_changed_p
= 0;
5955 struct frame
*sf
= SELECTED_FRAME ();
5957 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
5958 w
= XWINDOW (mini_window
);
5959 f
= XFRAME (WINDOW_FRAME (w
));
5961 /* Don't display if frame is invisible or not yet initialized. */
5962 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
5965 #ifdef HAVE_WINDOW_SYSTEM
5966 /* When Emacs starts, selected_frame may be a visible terminal
5967 frame, even if we run under a window system. If we let this
5968 through, a message would be displayed on the terminal. */
5969 if (EQ (selected_frame
, Vterminal_frame
)
5970 && !NILP (Vwindow_system
))
5972 #endif /* HAVE_WINDOW_SYSTEM */
5974 /* Redraw garbaged frames. */
5976 clear_garbaged_frames ();
5978 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
5980 echo_area_window
= mini_window
;
5981 window_height_changed_p
= display_echo_area (w
);
5982 w
->must_be_updated_p
= 1;
5986 /* Not called from redisplay_internal. If we changed
5987 window configuration, we must redisplay thoroughly.
5988 Otherwise, we can do with updating what we displayed
5990 if (window_height_changed_p
)
5992 ++windows_or_buffers_changed
;
5993 ++update_mode_lines
;
5994 redisplay_internal (0);
5996 else if (FRAME_WINDOW_P (f
))
5998 update_single_window (w
, 1);
5999 rif
->flush_display (f
);
6002 update_frame (f
, 1, 1);
6005 else if (!EQ (mini_window
, selected_window
))
6006 windows_or_buffers_changed
++;
6008 /* Last displayed message is now the current message. */
6009 echo_area_buffer
[1] = echo_area_buffer
[0];
6011 /* Prevent redisplay optimization in redisplay_internal by resetting
6012 this_line_start_pos. This is done because the mini-buffer now
6013 displays the message instead of its buffer text. */
6014 if (EQ (mini_window
, selected_window
))
6015 CHARPOS (this_line_start_pos
) = 0;
6017 return window_height_changed_p
;
6022 /***********************************************************************
6024 ***********************************************************************/
6027 #ifdef HAVE_WINDOW_SYSTEM
6029 /* A buffer for constructing frame titles in it; allocated from the
6030 heap in init_xdisp and resized as needed in store_frame_title_char. */
6032 static char *frame_title_buf
;
6034 /* The buffer's end, and a current output position in it. */
6036 static char *frame_title_buf_end
;
6037 static char *frame_title_ptr
;
6040 /* Store a single character C for the frame title in frame_title_buf.
6041 Re-allocate frame_title_buf if necessary. */
6044 store_frame_title_char (c
)
6047 /* If output position has reached the end of the allocated buffer,
6048 double the buffer's size. */
6049 if (frame_title_ptr
== frame_title_buf_end
)
6051 int len
= frame_title_ptr
- frame_title_buf
;
6052 int new_size
= 2 * len
* sizeof *frame_title_buf
;
6053 frame_title_buf
= (char *) xrealloc (frame_title_buf
, new_size
);
6054 frame_title_buf_end
= frame_title_buf
+ new_size
;
6055 frame_title_ptr
= frame_title_buf
+ len
;
6058 *frame_title_ptr
++ = c
;
6062 /* Store part of a frame title in frame_title_buf, beginning at
6063 frame_title_ptr. STR is the string to store. Do not copy more
6064 than PRECISION number of bytes from STR; PRECISION <= 0 means copy
6065 the whole string. Pad with spaces until FIELD_WIDTH number of
6066 characters have been copied; FIELD_WIDTH <= 0 means don't pad.
6067 Called from display_mode_element when it is used to build a frame
6071 store_frame_title (str
, field_width
, precision
)
6073 int field_width
, precision
;
6077 /* Copy at most PRECISION chars from STR. */
6078 while ((precision
<= 0 || n
< precision
)
6081 store_frame_title_char (*str
++);
6085 /* Fill up with spaces until FIELD_WIDTH reached. */
6086 while (field_width
> 0
6089 store_frame_title_char (' ');
6097 /* Set the title of FRAME, if it has changed. The title format is
6098 Vicon_title_format if FRAME is iconified, otherwise it is
6099 frame_title_format. */
6102 x_consider_frame_title (frame
)
6105 struct frame
*f
= XFRAME (frame
);
6107 if (FRAME_WINDOW_P (f
)
6108 || FRAME_MINIBUF_ONLY_P (f
)
6109 || f
->explicit_name
)
6111 /* Do we have more than one visible frame on this X display? */
6114 struct buffer
*obuf
;
6118 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
6120 struct frame
*tf
= XFRAME (XCAR (tail
));
6123 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
6124 && !FRAME_MINIBUF_ONLY_P (tf
)
6125 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
6129 /* Set global variable indicating that multiple frames exist. */
6130 multiple_frames
= CONSP (tail
);
6132 /* Switch to the buffer of selected window of the frame. Set up
6133 frame_title_ptr so that display_mode_element will output into it;
6134 then display the title. */
6135 obuf
= current_buffer
;
6136 Fset_buffer (XWINDOW (f
->selected_window
)->buffer
);
6137 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
6138 frame_title_ptr
= frame_title_buf
;
6139 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
6140 NULL
, DEFAULT_FACE_ID
);
6141 len
= display_mode_element (&it
, 0, -1, -1, fmt
);
6142 frame_title_ptr
= NULL
;
6143 set_buffer_internal (obuf
);
6145 /* Set the title only if it's changed. This avoids consing in
6146 the common case where it hasn't. (If it turns out that we've
6147 already wasted too much time by walking through the list with
6148 display_mode_element, then we might need to optimize at a
6149 higher level than this.) */
6150 if (! STRINGP (f
->name
)
6151 || STRING_BYTES (XSTRING (f
->name
)) != len
6152 || bcmp (frame_title_buf
, XSTRING (f
->name
)->data
, len
) != 0)
6153 x_implicitly_set_name (f
, make_string (frame_title_buf
, len
), Qnil
);
6157 #else /* not HAVE_WINDOW_SYSTEM */
6159 #define frame_title_ptr ((char *)0)
6160 #define store_frame_title(str, mincol, maxcol) 0
6162 #endif /* not HAVE_WINDOW_SYSTEM */
6167 /***********************************************************************
6169 ***********************************************************************/
6172 /* Prepare for redisplay by updating menu-bar item lists when
6173 appropriate. This can call eval. */
6176 prepare_menu_bars ()
6179 struct gcpro gcpro1
, gcpro2
;
6181 struct frame
*tooltip_frame
;
6183 #ifdef HAVE_X_WINDOWS
6184 tooltip_frame
= tip_frame
;
6186 tooltip_frame
= NULL
;
6189 /* Update all frame titles based on their buffer names, etc. We do
6190 this before the menu bars so that the buffer-menu will show the
6191 up-to-date frame titles. */
6192 #ifdef HAVE_WINDOW_SYSTEM
6193 if (windows_or_buffers_changed
|| update_mode_lines
)
6195 Lisp_Object tail
, frame
;
6197 FOR_EACH_FRAME (tail
, frame
)
6200 if (f
!= tooltip_frame
6201 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
6202 x_consider_frame_title (frame
);
6205 #endif /* HAVE_WINDOW_SYSTEM */
6207 /* Update the menu bar item lists, if appropriate. This has to be
6208 done before any actual redisplay or generation of display lines. */
6209 all_windows
= (update_mode_lines
6210 || buffer_shared
> 1
6211 || windows_or_buffers_changed
);
6214 Lisp_Object tail
, frame
;
6215 int count
= specpdl_ptr
- specpdl
;
6217 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6219 FOR_EACH_FRAME (tail
, frame
)
6223 /* Ignore tooltip frame. */
6224 if (f
== tooltip_frame
)
6227 /* If a window on this frame changed size, report that to
6228 the user and clear the size-change flag. */
6229 if (FRAME_WINDOW_SIZES_CHANGED (f
))
6231 Lisp_Object functions
;
6233 /* Clear flag first in case we get an error below. */
6234 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
6235 functions
= Vwindow_size_change_functions
;
6236 GCPRO2 (tail
, functions
);
6238 while (CONSP (functions
))
6240 call1 (XCAR (functions
), frame
);
6241 functions
= XCDR (functions
);
6247 update_menu_bar (f
, 0);
6248 #ifdef HAVE_WINDOW_SYSTEM
6249 update_tool_bar (f
, 0);
6254 unbind_to (count
, Qnil
);
6258 struct frame
*sf
= SELECTED_FRAME ();
6259 update_menu_bar (sf
, 1);
6260 #ifdef HAVE_WINDOW_SYSTEM
6261 update_tool_bar (sf
, 1);
6265 /* Motif needs this. See comment in xmenu.c. Turn it off when
6266 pending_menu_activation is not defined. */
6267 #ifdef USE_X_TOOLKIT
6268 pending_menu_activation
= 0;
6273 /* Update the menu bar item list for frame F. This has to be done
6274 before we start to fill in any display lines, because it can call
6277 If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */
6280 update_menu_bar (f
, save_match_data
)
6282 int save_match_data
;
6285 register struct window
*w
;
6287 window
= FRAME_SELECTED_WINDOW (f
);
6288 w
= XWINDOW (window
);
6290 if (update_mode_lines
)
6291 w
->update_mode_line
= Qt
;
6293 if (FRAME_WINDOW_P (f
)
6295 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6296 FRAME_EXTERNAL_MENU_BAR (f
)
6298 FRAME_MENU_BAR_LINES (f
) > 0
6300 : FRAME_MENU_BAR_LINES (f
) > 0)
6302 /* If the user has switched buffers or windows, we need to
6303 recompute to reflect the new bindings. But we'll
6304 recompute when update_mode_lines is set too; that means
6305 that people can use force-mode-line-update to request
6306 that the menu bar be recomputed. The adverse effect on
6307 the rest of the redisplay algorithm is about the same as
6308 windows_or_buffers_changed anyway. */
6309 if (windows_or_buffers_changed
6310 || !NILP (w
->update_mode_line
)
6311 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6312 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6313 != !NILP (w
->last_had_star
))
6314 || ((!NILP (Vtransient_mark_mode
)
6315 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6316 != !NILP (w
->region_showing
)))
6318 struct buffer
*prev
= current_buffer
;
6319 int count
= specpdl_ptr
- specpdl
;
6321 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6322 if (save_match_data
)
6323 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6324 if (NILP (Voverriding_local_map_menu_flag
))
6326 specbind (Qoverriding_terminal_local_map
, Qnil
);
6327 specbind (Qoverriding_local_map
, Qnil
);
6330 /* Run the Lucid hook. */
6331 call1 (Vrun_hooks
, Qactivate_menubar_hook
);
6333 /* If it has changed current-menubar from previous value,
6334 really recompute the menu-bar from the value. */
6335 if (! NILP (Vlucid_menu_bar_dirty_flag
))
6336 call0 (Qrecompute_lucid_menubar
);
6338 safe_run_hooks (Qmenu_bar_update_hook
);
6339 FRAME_MENU_BAR_ITEMS (f
) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f
));
6341 /* Redisplay the menu bar in case we changed it. */
6342 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
6343 if (FRAME_WINDOW_P (f
))
6344 set_frame_menubar (f
, 0, 0);
6346 /* On a terminal screen, the menu bar is an ordinary screen
6347 line, and this makes it get updated. */
6348 w
->update_mode_line
= Qt
;
6349 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6350 /* In the non-toolkit version, the menu bar is an ordinary screen
6351 line, and this makes it get updated. */
6352 w
->update_mode_line
= Qt
;
6353 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */
6355 unbind_to (count
, Qnil
);
6356 set_buffer_internal_1 (prev
);
6363 /***********************************************************************
6365 ***********************************************************************/
6367 #ifdef HAVE_WINDOW_SYSTEM
6369 /* Update the tool-bar item list for frame F. This has to be done
6370 before we start to fill in any display lines. Called from
6371 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
6372 and restore it here. */
6375 update_tool_bar (f
, save_match_data
)
6377 int save_match_data
;
6379 if (WINDOWP (f
->tool_bar_window
)
6380 && XFASTINT (XWINDOW (f
->tool_bar_window
)->height
) > 0)
6385 window
= FRAME_SELECTED_WINDOW (f
);
6386 w
= XWINDOW (window
);
6388 /* If the user has switched buffers or windows, we need to
6389 recompute to reflect the new bindings. But we'll
6390 recompute when update_mode_lines is set too; that means
6391 that people can use force-mode-line-update to request
6392 that the menu bar be recomputed. The adverse effect on
6393 the rest of the redisplay algorithm is about the same as
6394 windows_or_buffers_changed anyway. */
6395 if (windows_or_buffers_changed
6396 || !NILP (w
->update_mode_line
)
6397 || ((BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
6398 < BUF_MODIFF (XBUFFER (w
->buffer
)))
6399 != !NILP (w
->last_had_star
))
6400 || ((!NILP (Vtransient_mark_mode
)
6401 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
6402 != !NILP (w
->region_showing
)))
6404 struct buffer
*prev
= current_buffer
;
6405 int count
= specpdl_ptr
- specpdl
;
6407 /* Set current_buffer to the buffer of the selected
6408 window of the frame, so that we get the right local
6410 set_buffer_internal_1 (XBUFFER (w
->buffer
));
6412 /* Save match data, if we must. */
6413 if (save_match_data
)
6414 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
6416 /* Make sure that we don't accidentally use bogus keymaps. */
6417 if (NILP (Voverriding_local_map_menu_flag
))
6419 specbind (Qoverriding_terminal_local_map
, Qnil
);
6420 specbind (Qoverriding_local_map
, Qnil
);
6423 /* Build desired tool-bar items from keymaps. */
6424 f
->desired_tool_bar_items
6425 = tool_bar_items (f
->desired_tool_bar_items
,
6426 &f
->n_desired_tool_bar_items
);
6428 /* Redisplay the tool-bar in case we changed it. */
6429 w
->update_mode_line
= Qt
;
6431 unbind_to (count
, Qnil
);
6432 set_buffer_internal_1 (prev
);
6438 /* Set F->desired_tool_bar_string to a Lisp string representing frame
6439 F's desired tool-bar contents. F->desired_tool_bar_items must have
6440 been set up previously by calling prepare_menu_bars. */
6443 build_desired_tool_bar_string (f
)
6446 int i
, size
, size_needed
, string_idx
;
6447 struct gcpro gcpro1
, gcpro2
, gcpro3
;
6448 Lisp_Object image
, plist
, props
;
6450 image
= plist
= props
= Qnil
;
6451 GCPRO3 (image
, plist
, props
);
6453 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
6454 Otherwise, make a new string. */
6456 /* The size of the string we might be able to reuse. */
6457 size
= (STRINGP (f
->desired_tool_bar_string
)
6458 ? XSTRING (f
->desired_tool_bar_string
)->size
6461 /* Each image in the string we build is preceded by a space,
6462 and there is a space at the end. */
6463 size_needed
= f
->n_desired_tool_bar_items
+ 1;
6465 /* Reuse f->desired_tool_bar_string, if possible. */
6466 if (size
< size_needed
)
6467 f
->desired_tool_bar_string
= Fmake_string (make_number (size_needed
),
6471 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
6472 Fremove_text_properties (make_number (0), make_number (size
),
6473 props
, f
->desired_tool_bar_string
);
6476 /* Put a `display' property on the string for the images to display,
6477 put a `menu_item' property on tool-bar items with a value that
6478 is the index of the item in F's tool-bar item vector. */
6479 for (i
= 0, string_idx
= 0;
6480 i
< f
->n_desired_tool_bar_items
;
6481 ++i
, string_idx
+= 1)
6484 (XVECTOR (f->desired_tool_bar_items) \
6485 ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)])
6487 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
6488 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
6490 extern Lisp_Object QCrelief
, QCmargin
, QCalgorithm
, Qimage
;
6491 extern Lisp_Object Qlaplace
;
6493 /* If image is a vector, choose the image according to the
6495 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
6496 if (VECTORP (image
))
6498 enum tool_bar_item_image idx
;
6502 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
6503 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
6506 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
6507 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
6509 xassert (XVECTOR (image
)->size
>= idx
);
6510 image
= XVECTOR (image
)->contents
[idx
];
6513 /* Ignore invalid image specifications. */
6514 if (!valid_image_p (image
))
6517 /* Display the tool-bar button pressed, or depressed. */
6518 plist
= Fcopy_sequence (XCDR (image
));
6520 /* Compute margin and relief to draw. */
6521 relief
= tool_bar_button_relief
> 0 ? tool_bar_button_relief
: 3;
6522 margin
= relief
+ max (0, tool_bar_button_margin
);
6524 if (auto_raise_tool_bar_buttons_p
)
6526 /* Add a `:relief' property to the image spec if the item is
6530 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
6536 /* If image is selected, display it pressed, i.e. with a
6537 negative relief. If it's not selected, display it with a
6539 plist
= Fplist_put (plist
, QCrelief
,
6541 ? make_number (-relief
)
6542 : make_number (relief
)));
6546 /* Put a margin around the image. */
6548 plist
= Fplist_put (plist
, QCmargin
, make_number (margin
));
6550 /* If button is not enabled, make the image appear disabled by
6551 applying an appropriate algorithm to it. */
6553 plist
= Fplist_put (plist
, QCalgorithm
, Qlaplace
);
6555 /* Put a `display' text property on the string for the image to
6556 display. Put a `menu-item' property on the string that gives
6557 the start of this item's properties in the tool-bar items
6559 image
= Fcons (Qimage
, plist
);
6560 props
= list4 (Qdisplay
, image
,
6561 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
)),
6562 Fadd_text_properties (make_number (string_idx
),
6563 make_number (string_idx
+ 1),
6564 props
, f
->desired_tool_bar_string
);
6572 /* Display one line of the tool-bar of frame IT->f. */
6575 display_tool_bar_line (it
)
6578 struct glyph_row
*row
= it
->glyph_row
;
6579 int max_x
= it
->last_visible_x
;
6582 prepare_desired_row (row
);
6583 row
->y
= it
->current_y
;
6585 while (it
->current_x
< max_x
)
6587 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
6589 /* Get the next display element. */
6590 if (!get_next_display_element (it
))
6593 /* Produce glyphs. */
6594 x_before
= it
->current_x
;
6595 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
6596 PRODUCE_GLYPHS (it
);
6598 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
6603 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
6605 if (x
+ glyph
->pixel_width
> max_x
)
6607 /* Glyph doesn't fit on line. */
6608 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
6614 x
+= glyph
->pixel_width
;
6618 /* Stop at line ends. */
6619 if (ITERATOR_AT_END_OF_LINE_P (it
))
6622 set_iterator_to_next (it
);
6627 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
6628 extend_face_to_end_of_line (it
);
6629 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
6630 last
->right_box_line_p
= 1;
6631 compute_line_metrics (it
);
6633 /* If line is empty, make it occupy the rest of the tool-bar. */
6634 if (!row
->displays_text_p
)
6636 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
6637 row
->ascent
= row
->phys_ascent
= 0;
6640 row
->full_width_p
= 1;
6641 row
->continued_p
= 0;
6642 row
->truncated_on_left_p
= 0;
6643 row
->truncated_on_right_p
= 0;
6645 it
->current_x
= it
->hpos
= 0;
6646 it
->current_y
+= row
->height
;
6652 /* Value is the number of screen lines needed to make all tool-bar
6653 items of frame F visible. */
6656 tool_bar_lines_needed (f
)
6659 struct window
*w
= XWINDOW (f
->tool_bar_window
);
6662 /* Initialize an iterator for iteration over
6663 F->desired_tool_bar_string in the tool-bar window of frame F. */
6664 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6665 it
.first_visible_x
= 0;
6666 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6667 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6669 while (!ITERATOR_AT_END_P (&it
))
6671 it
.glyph_row
= w
->desired_matrix
->rows
;
6672 clear_glyph_row (it
.glyph_row
);
6673 display_tool_bar_line (&it
);
6676 return (it
.current_y
+ CANON_Y_UNIT (f
) - 1) / CANON_Y_UNIT (f
);
6680 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
6681 height should be changed. */
6684 redisplay_tool_bar (f
)
6689 struct glyph_row
*row
;
6690 int change_height_p
= 0;
6692 /* If frame hasn't a tool-bar window or if it is zero-height, don't
6693 do anything. This means you must start with tool-bar-lines
6694 non-zero to get the auto-sizing effect. Or in other words, you
6695 can turn off tool-bars by specifying tool-bar-lines zero. */
6696 if (!WINDOWP (f
->tool_bar_window
)
6697 || (w
= XWINDOW (f
->tool_bar_window
),
6698 XFASTINT (w
->height
) == 0))
6701 /* Set up an iterator for the tool-bar window. */
6702 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
6703 it
.first_visible_x
= 0;
6704 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
6707 /* Build a string that represents the contents of the tool-bar. */
6708 build_desired_tool_bar_string (f
);
6709 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
6711 /* Display as many lines as needed to display all tool-bar items. */
6712 while (it
.current_y
< it
.last_visible_y
)
6713 display_tool_bar_line (&it
);
6715 /* It doesn't make much sense to try scrolling in the tool-bar
6716 window, so don't do it. */
6717 w
->desired_matrix
->no_scrolling_p
= 1;
6718 w
->must_be_updated_p
= 1;
6720 if (auto_resize_tool_bars_p
)
6724 /* If there are blank lines at the end, except for a partially
6725 visible blank line at the end that is smaller than
6726 CANON_Y_UNIT, change the tool-bar's height. */
6727 row
= it
.glyph_row
- 1;
6728 if (!row
->displays_text_p
6729 && row
->height
>= CANON_Y_UNIT (f
))
6730 change_height_p
= 1;
6732 /* If row displays tool-bar items, but is partially visible,
6733 change the tool-bar's height. */
6734 if (row
->displays_text_p
6735 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
6736 change_height_p
= 1;
6738 /* Resize windows as needed by changing the `tool-bar-lines'
6741 && (nlines
= tool_bar_lines_needed (f
),
6742 nlines
!= XFASTINT (w
->height
)))
6744 extern Lisp_Object Qtool_bar_lines
;
6747 XSETFRAME (frame
, f
);
6748 clear_glyph_matrix (w
->desired_matrix
);
6749 Fmodify_frame_parameters (frame
,
6750 Fcons (Fcons (Qtool_bar_lines
,
6751 make_number (nlines
)),
6753 fonts_changed_p
= 1;
6757 return change_height_p
;
6761 /* Get information about the tool-bar item which is displayed in GLYPH
6762 on frame F. Return in *PROP_IDX the index where tool-bar item
6763 properties start in F->current_tool_bar_items. Value is zero if
6764 GLYPH doesn't display a tool-bar item. */
6767 tool_bar_item_info (f
, glyph
, prop_idx
)
6769 struct glyph
*glyph
;
6775 /* Get the text property `menu-item' at pos. The value of that
6776 property is the start index of this item's properties in
6777 F->current_tool_bar_items. */
6778 prop
= Fget_text_property (make_number (glyph
->charpos
),
6779 Qmenu_item
, f
->current_tool_bar_string
);
6780 if (INTEGERP (prop
))
6782 *prop_idx
= XINT (prop
);
6791 #endif /* HAVE_WINDOW_SYSTEM */
6795 /************************************************************************
6796 Horizontal scrolling
6797 ************************************************************************/
6799 static int hscroll_window_tree
P_ ((Lisp_Object
));
6800 static int hscroll_windows
P_ ((Lisp_Object
));
6802 /* For all leaf windows in the window tree rooted at WINDOW, set their
6803 hscroll value so that PT is (i) visible in the window, and (ii) so
6804 that it is not within a certain margin at the window's left and
6805 right border. Value is non-zero if any window's hscroll has been
6809 hscroll_window_tree (window
)
6812 int hscrolled_p
= 0;
6814 while (WINDOWP (window
))
6816 struct window
*w
= XWINDOW (window
);
6818 if (WINDOWP (w
->hchild
))
6819 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
6820 else if (WINDOWP (w
->vchild
))
6821 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
6822 else if (w
->cursor
.vpos
>= 0)
6824 int hscroll_margin
, text_area_x
, text_area_y
;
6825 int text_area_width
, text_area_height
;
6826 struct glyph_row
*current_cursor_row
6827 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
6828 struct glyph_row
*desired_cursor_row
6829 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
6830 struct glyph_row
*cursor_row
6831 = (desired_cursor_row
->enabled_p
6832 ? desired_cursor_row
6833 : current_cursor_row
);
6835 window_box (w
, TEXT_AREA
, &text_area_x
, &text_area_y
,
6836 &text_area_width
, &text_area_height
);
6838 /* Scroll when cursor is inside this scroll margin. */
6839 hscroll_margin
= 5 * CANON_X_UNIT (XFRAME (w
->frame
));
6841 if ((XFASTINT (w
->hscroll
)
6842 && w
->cursor
.x
< hscroll_margin
)
6843 || (cursor_row
->enabled_p
6844 && cursor_row
->truncated_on_right_p
6845 && (w
->cursor
.x
> text_area_width
- hscroll_margin
)))
6849 struct buffer
*saved_current_buffer
;
6852 /* Find point in a display of infinite width. */
6853 saved_current_buffer
= current_buffer
;
6854 current_buffer
= XBUFFER (w
->buffer
);
6856 if (w
== XWINDOW (selected_window
))
6857 pt
= BUF_PT (current_buffer
);
6860 pt
= marker_position (w
->pointm
);
6861 pt
= max (BEGV
, pt
);
6865 /* Move iterator to pt starting at cursor_row->start in
6866 a line with infinite width. */
6867 init_to_row_start (&it
, w
, cursor_row
);
6868 it
.last_visible_x
= INFINITY
;
6869 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
6870 current_buffer
= saved_current_buffer
;
6872 /* Center cursor in window. */
6873 hscroll
= (max (0, it
.current_x
- text_area_width
/ 2)
6874 / CANON_X_UNIT (it
.f
));
6876 /* Don't call Fset_window_hscroll if value hasn't
6877 changed because it will prevent redisplay
6879 if (XFASTINT (w
->hscroll
) != hscroll
)
6881 Fset_window_hscroll (window
, make_number (hscroll
));
6890 /* Value is non-zero if hscroll of any leaf window has been changed. */
6895 /* Set hscroll so that cursor is visible and not inside horizontal
6896 scroll margins for all windows in the tree rooted at WINDOW. See
6897 also hscroll_window_tree above. Value is non-zero if any window's
6898 hscroll has been changed. If it has, desired matrices on the frame
6899 of WINDOW are cleared. */
6902 hscroll_windows (window
)
6905 int hscrolled_p
= hscroll_window_tree (window
);
6907 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
6913 /************************************************************************
6915 ************************************************************************/
6917 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
6918 to a non-zero value. This is sometimes handy to have in a debugger
6923 /* First and last unchanged row for try_window_id. */
6925 int debug_first_unchanged_at_end_vpos
;
6926 int debug_last_unchanged_at_beg_vpos
;
6928 /* Delta vpos and y. */
6930 int debug_dvpos
, debug_dy
;
6932 /* Delta in characters and bytes for try_window_id. */
6934 int debug_delta
, debug_delta_bytes
;
6936 /* Values of window_end_pos and window_end_vpos at the end of
6939 int debug_end_pos
, debug_end_vpos
;
6941 /* Append a string to W->desired_matrix->method. FMT is a printf
6942 format string. A1...A9 are a supplement for a variable-length
6943 argument list. If trace_redisplay_p is non-zero also printf the
6944 resulting string to stderr. */
6947 debug_method_add (w
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
)
6950 int a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
;
6953 char *method
= w
->desired_matrix
->method
;
6954 int len
= strlen (method
);
6955 int size
= sizeof w
->desired_matrix
->method
;
6956 int remaining
= size
- len
- 1;
6958 sprintf (buffer
, fmt
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
6959 if (len
&& remaining
)
6965 strncpy (method
+ len
, buffer
, remaining
);
6967 if (trace_redisplay_p
)
6968 fprintf (stderr
, "%p (%s): %s\n",
6970 ((BUFFERP (w
->buffer
)
6971 && STRINGP (XBUFFER (w
->buffer
)->name
))
6972 ? (char *) XSTRING (XBUFFER (w
->buffer
)->name
)->data
6977 #endif /* GLYPH_DEBUG */
6980 /* This counter is used to clear the face cache every once in a while
6981 in redisplay_internal. It is incremented for each redisplay.
6982 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
6985 #define CLEAR_FACE_CACHE_COUNT 10000
6986 static int clear_face_cache_count
;
6988 /* Record the previous terminal frame we displayed. */
6990 static struct frame
*previous_terminal_frame
;
6992 /* Non-zero while redisplay_internal is in progress. */
6997 /* Value is non-zero if all changes in window W, which displays
6998 current_buffer, are in the text between START and END. START is a
6999 buffer position, END is given as a distance from Z. Used in
7000 redisplay_internal for display optimization. */
7003 text_outside_line_unchanged_p (w
, start
, end
)
7007 int unchanged_p
= 1;
7009 /* If text or overlays have changed, see where. */
7010 if (XFASTINT (w
->last_modified
) < MODIFF
7011 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7013 /* Gap in the line? */
7014 if (GPT
< start
|| Z
- GPT
< end
)
7017 /* Changes start in front of the line, or end after it? */
7019 && (BEG_UNCHANGED
< start
- 1
7020 || END_UNCHANGED
< end
))
7023 /* If selective display, can't optimize if changes start at the
7024 beginning of the line. */
7026 && INTEGERP (current_buffer
->selective_display
)
7027 && XINT (current_buffer
->selective_display
) > 0
7028 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
7036 /* Do a frame update, taking possible shortcuts into account. This is
7037 the main external entry point for redisplay.
7039 If the last redisplay displayed an echo area message and that message
7040 is no longer requested, we clear the echo area or bring back the
7041 mini-buffer if that is in use. */
7046 redisplay_internal (0);
7049 /* Return 1 if point moved out of or into a composition. Otherwise
7050 return 0. PREV_BUF and PREV_PT are the last point buffer and
7051 position. BUF and PT are the current point buffer and position. */
7054 check_point_in_composition (prev_buf
, prev_pt
, buf
, pt
)
7055 struct buffer
*prev_buf
, *buf
;
7062 XSETBUFFER (buffer
, buf
);
7063 /* Check a composition at the last point if point moved within the
7065 if (prev_buf
== buf
)
7068 /* Point didn't move. */
7071 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
7072 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
7073 && COMPOSITION_VALID_P (start
, end
, prop
)
7074 && start
< prev_pt
&& end
> prev_pt
)
7075 /* The last point was within the composition. Return 1 iff
7076 point moved out of the composition. */
7077 return (pt
<= start
|| pt
>= end
);
7080 /* Check a composition at the current point. */
7081 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
7082 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
7083 && COMPOSITION_VALID_P (start
, end
, prop
)
7084 && start
< pt
&& end
> pt
);
7087 /* Reconsider the setting of B->clip_changed which is displayed
7091 reconsider_clip_changes (w
, b
)
7095 if (b
->prevent_redisplay_optimizations_p
)
7096 b
->clip_changed
= 1;
7097 else if (b
->clip_changed
7098 && !NILP (w
->window_end_valid
)
7099 && w
->current_matrix
->buffer
== b
7100 && w
->current_matrix
->zv
== BUF_ZV (b
)
7101 && w
->current_matrix
->begv
== BUF_BEGV (b
))
7102 b
->clip_changed
= 0;
7104 /* If display wasn't paused, and W is not a tool bar window, see if
7105 point has been moved into or out of a composition. In that case,
7106 we set b->clip_changed to 1 to force updating the screen. If
7107 b->clip_changed has already been set to 1, we can skip this
7109 if (!b
->clip_changed
7110 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
7114 if (w
== XWINDOW (selected_window
))
7115 pt
= BUF_PT (current_buffer
);
7117 pt
= marker_position (w
->pointm
);
7119 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
7120 || pt
!= XINT (w
->last_point
))
7121 && check_point_in_composition (w
->current_matrix
->buffer
,
7122 XINT (w
->last_point
),
7123 XBUFFER (w
->buffer
), pt
))
7124 b
->clip_changed
= 1;
7129 /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in
7130 response to any user action; therefore, we should preserve the echo
7131 area. (Actually, our caller does that job.) Perhaps in the future
7132 avoid recentering windows if it is not necessary; currently that
7133 causes some problems. */
7136 redisplay_internal (preserve_echo_area
)
7137 int preserve_echo_area
;
7139 struct window
*w
= XWINDOW (selected_window
);
7140 struct frame
*f
= XFRAME (w
->frame
);
7142 int must_finish
= 0;
7143 struct text_pos tlbufpos
, tlendpos
;
7144 int number_of_visible_frames
;
7146 struct frame
*sf
= SELECTED_FRAME ();
7148 /* Non-zero means redisplay has to consider all windows on all
7149 frames. Zero means, only selected_window is considered. */
7150 int consider_all_windows_p
;
7152 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
7154 /* No redisplay if running in batch mode or frame is not yet fully
7155 initialized, or redisplay is explicitly turned off by setting
7156 Vinhibit_redisplay. */
7158 || !NILP (Vinhibit_redisplay
)
7159 || !f
->glyphs_initialized_p
)
7162 /* The flag redisplay_performed_directly_p is set by
7163 direct_output_for_insert when it already did the whole screen
7164 update necessary. */
7165 if (redisplay_performed_directly_p
)
7167 redisplay_performed_directly_p
= 0;
7168 if (!hscroll_windows (selected_window
))
7172 #ifdef USE_X_TOOLKIT
7173 if (popup_activated ())
7177 /* I don't think this happens but let's be paranoid. */
7181 /* Record a function that resets redisplaying_p to its old value
7182 when we leave this function. */
7183 count
= specpdl_ptr
- specpdl
;
7184 record_unwind_protect (unwind_redisplay
, make_number (redisplaying_p
));
7189 reconsider_clip_changes (w
, current_buffer
);
7191 /* If new fonts have been loaded that make a glyph matrix adjustment
7192 necessary, do it. */
7193 if (fonts_changed_p
)
7195 adjust_glyphs (NULL
);
7196 ++windows_or_buffers_changed
;
7197 fonts_changed_p
= 0;
7200 if (! FRAME_WINDOW_P (sf
)
7201 && previous_terminal_frame
!= sf
)
7203 /* Since frames on an ASCII terminal share the same display
7204 area, displaying a different frame means redisplay the whole
7206 windows_or_buffers_changed
++;
7207 SET_FRAME_GARBAGED (sf
);
7208 XSETFRAME (Vterminal_frame
, sf
);
7210 previous_terminal_frame
= sf
;
7212 /* Set the visible flags for all frames. Do this before checking
7213 for resized or garbaged frames; they want to know if their frames
7214 are visible. See the comment in frame.h for
7215 FRAME_SAMPLE_VISIBILITY. */
7217 Lisp_Object tail
, frame
;
7219 number_of_visible_frames
= 0;
7221 FOR_EACH_FRAME (tail
, frame
)
7223 struct frame
*f
= XFRAME (frame
);
7225 FRAME_SAMPLE_VISIBILITY (f
);
7226 if (FRAME_VISIBLE_P (f
))
7227 ++number_of_visible_frames
;
7228 clear_desired_matrices (f
);
7232 /* Notice any pending interrupt request to change frame size. */
7233 do_pending_window_change (1);
7235 /* Clear frames marked as garbaged. */
7237 clear_garbaged_frames ();
7239 /* Build menubar and tool-bar items. */
7240 prepare_menu_bars ();
7242 if (windows_or_buffers_changed
)
7243 update_mode_lines
++;
7245 /* Detect case that we need to write or remove a star in the mode line. */
7246 if ((SAVE_MODIFF
< MODIFF
) != !NILP (w
->last_had_star
))
7248 w
->update_mode_line
= Qt
;
7249 if (buffer_shared
> 1)
7250 update_mode_lines
++;
7253 /* If %c is in the mode line, update it if needed. */
7254 if (!NILP (w
->column_number_displayed
)
7255 /* This alternative quickly identifies a common case
7256 where no change is needed. */
7257 && !(PT
== XFASTINT (w
->last_point
)
7258 && XFASTINT (w
->last_modified
) >= MODIFF
7259 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
7260 && XFASTINT (w
->column_number_displayed
) != current_column ())
7261 w
->update_mode_line
= Qt
;
7263 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
7265 /* The variable buffer_shared is set in redisplay_window and
7266 indicates that we redisplay a buffer in different windows. See
7268 consider_all_windows_p
= update_mode_lines
|| buffer_shared
> 1;
7270 /* If specs for an arrow have changed, do thorough redisplay
7271 to ensure we remove any arrow that should no longer exist. */
7272 if (! EQ (COERCE_MARKER (Voverlay_arrow_position
), last_arrow_position
)
7273 || ! EQ (Voverlay_arrow_string
, last_arrow_string
))
7274 consider_all_windows_p
= windows_or_buffers_changed
= 1;
7276 /* Normally the message* functions will have already displayed and
7277 updated the echo area, but the frame may have been trashed, or
7278 the update may have been preempted, so display the echo area
7279 again here. Checking both message buffers captures the case that
7280 the echo area should be cleared. */
7281 if (!NILP (echo_area_buffer
[0]) || !NILP (echo_area_buffer
[1]))
7283 int window_height_changed_p
= echo_area_display (0);
7286 if (fonts_changed_p
)
7288 else if (window_height_changed_p
)
7290 consider_all_windows_p
= 1;
7291 ++update_mode_lines
;
7292 ++windows_or_buffers_changed
;
7294 /* If window configuration was changed, frames may have been
7295 marked garbaged. Clear them or we will experience
7296 surprises wrt scrolling. */
7298 clear_garbaged_frames ();
7301 else if (w
== XWINDOW (minibuf_window
)
7302 && (current_buffer
->clip_changed
7303 || XFASTINT (w
->last_modified
) < MODIFF
7304 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
)
7305 && resize_mini_window (w
, 0))
7307 /* Resized active mini-window to fit the size of what it is
7308 showing if its contents might have changed. */
7310 consider_all_windows_p
= 1;
7311 ++windows_or_buffers_changed
;
7312 ++update_mode_lines
;
7314 /* If window configuration was changed, frames may have been
7315 marked garbaged. Clear them or we will experience
7316 surprises wrt scrolling. */
7318 clear_garbaged_frames ();
7322 /* If showing the region, and mark has changed, we must redisplay
7323 the whole window. The assignment to this_line_start_pos prevents
7324 the optimization directly below this if-statement. */
7325 if (((!NILP (Vtransient_mark_mode
)
7326 && !NILP (XBUFFER (w
->buffer
)->mark_active
))
7327 != !NILP (w
->region_showing
))
7328 || (!NILP (w
->region_showing
)
7329 && !EQ (w
->region_showing
,
7330 Fmarker_position (XBUFFER (w
->buffer
)->mark
))))
7331 CHARPOS (this_line_start_pos
) = 0;
7333 /* Optimize the case that only the line containing the cursor in the
7334 selected window has changed. Variables starting with this_ are
7335 set in display_line and record information about the line
7336 containing the cursor. */
7337 tlbufpos
= this_line_start_pos
;
7338 tlendpos
= this_line_end_pos
;
7339 if (!consider_all_windows_p
7340 && CHARPOS (tlbufpos
) > 0
7341 && NILP (w
->update_mode_line
)
7342 && !current_buffer
->clip_changed
7343 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
7344 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
7345 /* Make sure recorded data applies to current buffer, etc. */
7346 && this_line_buffer
== current_buffer
7347 && current_buffer
== XBUFFER (w
->buffer
)
7348 && NILP (w
->force_start
)
7349 /* Point must be on the line that we have info recorded about. */
7350 && PT
>= CHARPOS (tlbufpos
)
7351 && PT
<= Z
- CHARPOS (tlendpos
)
7352 /* All text outside that line, including its final newline,
7353 must be unchanged */
7354 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
7355 CHARPOS (tlendpos
)))
7357 if (CHARPOS (tlbufpos
) > BEGV
7358 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
7359 && (CHARPOS (tlbufpos
) == ZV
7360 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
7361 /* Former continuation line has disappeared by becoming empty */
7363 else if (XFASTINT (w
->last_modified
) < MODIFF
7364 || XFASTINT (w
->last_overlay_modified
) < OVERLAY_MODIFF
7365 || MINI_WINDOW_P (w
))
7367 /* We have to handle the case of continuation around a
7368 wide-column character (See the comment in indent.c around
7371 For instance, in the following case:
7373 -------- Insert --------
7374 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
7375 J_I_ ==> J_I_ `^^' are cursors.
7379 As we have to redraw the line above, we should goto cancel. */
7382 int line_height_before
= this_line_pixel_height
;
7384 /* Note that start_display will handle the case that the
7385 line starting at tlbufpos is a continuation lines. */
7386 start_display (&it
, w
, tlbufpos
);
7388 /* Implementation note: It this still necessary? */
7389 if (it
.current_x
!= this_line_start_x
)
7392 TRACE ((stderr
, "trying display optimization 1\n"));
7393 w
->cursor
.vpos
= -1;
7394 overlay_arrow_seen
= 0;
7395 it
.vpos
= this_line_vpos
;
7396 it
.current_y
= this_line_y
;
7397 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
7400 /* If line contains point, is not continued,
7401 and ends at same distance from eob as before, we win */
7402 if (w
->cursor
.vpos
>= 0
7403 /* Line is not continued, otherwise this_line_start_pos
7404 would have been set to 0 in display_line. */
7405 && CHARPOS (this_line_start_pos
)
7406 /* Line ends as before. */
7407 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
7408 /* Line has same height as before. Otherwise other lines
7409 would have to be shifted up or down. */
7410 && this_line_pixel_height
== line_height_before
)
7412 /* If this is not the window's last line, we must adjust
7413 the charstarts of the lines below. */
7414 if (it
.current_y
< it
.last_visible_y
)
7416 struct glyph_row
*row
7417 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
7418 int delta
, delta_bytes
;
7420 if (Z
- CHARPOS (tlendpos
) == ZV
)
7422 /* This line ends at end of (accessible part of)
7423 buffer. There is no newline to count. */
7425 - CHARPOS (tlendpos
)
7426 - MATRIX_ROW_START_CHARPOS (row
));
7427 delta_bytes
= (Z_BYTE
7428 - BYTEPOS (tlendpos
)
7429 - MATRIX_ROW_START_BYTEPOS (row
));
7433 /* This line ends in a newline. Must take
7434 account of the newline and the rest of the
7435 text that follows. */
7437 - CHARPOS (tlendpos
)
7438 - MATRIX_ROW_START_CHARPOS (row
));
7439 delta_bytes
= (Z_BYTE
7440 - BYTEPOS (tlendpos
)
7441 - MATRIX_ROW_START_BYTEPOS (row
));
7444 increment_glyph_matrix_buffer_positions (w
->current_matrix
,
7446 w
->current_matrix
->nrows
,
7447 delta
, delta_bytes
);
7450 /* If this row displays text now but previously didn't,
7451 or vice versa, w->window_end_vpos may have to be
7453 if ((it
.glyph_row
- 1)->displays_text_p
)
7455 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
7456 XSETINT (w
->window_end_vpos
, this_line_vpos
);
7458 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
7459 && this_line_vpos
> 0)
7460 XSETINT (w
->window_end_vpos
, this_line_vpos
- 1);
7461 w
->window_end_valid
= Qnil
;
7463 /* Update hint: No need to try to scroll in update_window. */
7464 w
->desired_matrix
->no_scrolling_p
= 1;
7467 *w
->desired_matrix
->method
= 0;
7468 debug_method_add (w
, "optimization 1");
7475 else if (/* Cursor position hasn't changed. */
7476 PT
== XFASTINT (w
->last_point
)
7477 /* Make sure the cursor was last displayed
7478 in this window. Otherwise we have to reposition it. */
7479 && 0 <= w
->cursor
.vpos
7480 && XINT (w
->height
) > w
->cursor
.vpos
)
7484 do_pending_window_change (1);
7486 /* We used to always goto end_of_redisplay here, but this
7487 isn't enough if we have a blinking cursor. */
7488 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
7489 goto end_of_redisplay
;
7493 /* If highlighting the region, or if the cursor is in the echo area,
7494 then we can't just move the cursor. */
7495 else if (! (!NILP (Vtransient_mark_mode
)
7496 && !NILP (current_buffer
->mark_active
))
7497 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7498 || highlight_nonselected_windows
)
7499 && NILP (w
->region_showing
)
7500 && NILP (Vshow_trailing_whitespace
)
7501 && !cursor_in_echo_area
)
7504 struct glyph_row
*row
;
7506 /* Skip from tlbufpos to PT and see where it is. Note that
7507 PT may be in invisible text. If so, we will end at the
7508 next visible position. */
7509 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
7510 NULL
, DEFAULT_FACE_ID
);
7511 it
.current_x
= this_line_start_x
;
7512 it
.current_y
= this_line_y
;
7513 it
.vpos
= this_line_vpos
;
7515 /* The call to move_it_to stops in front of PT, but
7516 moves over before-strings. */
7517 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
7519 if (it
.vpos
== this_line_vpos
7520 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
7523 xassert (this_line_vpos
== it
.vpos
);
7524 xassert (this_line_y
== it
.current_y
);
7525 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
7533 /* Text changed drastically or point moved off of line. */
7534 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
7537 CHARPOS (this_line_start_pos
) = 0;
7538 consider_all_windows_p
|= buffer_shared
> 1;
7539 ++clear_face_cache_count
;
7542 /* Build desired matrices. If consider_all_windows_p is non-zero,
7543 do it for all windows on all frames. Otherwise do it for
7544 selected_window, only. */
7546 if (consider_all_windows_p
)
7548 Lisp_Object tail
, frame
;
7550 /* Clear the face cache eventually. */
7551 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
7553 clear_face_cache (0);
7554 clear_face_cache_count
= 0;
7557 /* Recompute # windows showing selected buffer. This will be
7558 incremented each time such a window is displayed. */
7561 FOR_EACH_FRAME (tail
, frame
)
7563 struct frame
*f
= XFRAME (frame
);
7564 if (FRAME_WINDOW_P (f
) || f
== sf
)
7566 /* Mark all the scroll bars to be removed; we'll redeem
7567 the ones we want when we redisplay their windows. */
7568 if (condemn_scroll_bars_hook
)
7569 (*condemn_scroll_bars_hook
) (f
);
7571 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7572 redisplay_windows (FRAME_ROOT_WINDOW (f
));
7574 /* Any scroll bars which redisplay_windows should have
7575 nuked should now go away. */
7576 if (judge_scroll_bars_hook
)
7577 (*judge_scroll_bars_hook
) (f
);
7581 else if (FRAME_VISIBLE_P (sf
)
7582 && !FRAME_OBSCURED_P (sf
))
7583 redisplay_window (selected_window
, 1);
7586 /* Compare desired and current matrices, perform output. */
7590 /* If fonts changed, display again. */
7591 if (fonts_changed_p
)
7594 /* Prevent various kinds of signals during display update.
7595 stdio is not robust about handling signals,
7596 which can cause an apparent I/O error. */
7597 if (interrupt_input
)
7601 if (consider_all_windows_p
)
7610 /* See if we have to hscroll. */
7611 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7612 if (FRAMEP (XCAR (tail
)))
7614 f
= XFRAME (XCAR (tail
));
7616 if ((FRAME_WINDOW_P (f
)
7618 && FRAME_VISIBLE_P (f
)
7619 && !FRAME_OBSCURED_P (f
)
7620 && hscroll_windows (f
->root_window
))
7627 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
7629 if (!FRAMEP (XCAR (tail
)))
7632 f
= XFRAME (XCAR (tail
));
7634 if ((FRAME_WINDOW_P (f
) || f
== sf
)
7635 && FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
7637 /* Mark all windows as to be updated. */
7638 set_window_update_flags (XWINDOW (f
->root_window
), 1);
7639 pause
|= update_frame (f
, 0, 0);
7642 mark_window_display_accurate (f
->root_window
, 1);
7643 if (frame_up_to_date_hook
!= 0)
7644 (*frame_up_to_date_hook
) (f
);
7651 if (FRAME_VISIBLE_P (sf
)
7652 && !FRAME_OBSCURED_P (sf
))
7654 if (hscroll_windows (selected_window
))
7657 XWINDOW (selected_window
)->must_be_updated_p
= 1;
7658 pause
= update_frame (sf
, 0, 0);
7663 /* We may have called echo_area_display at the top of this
7664 function. If the echo area is on another frame, that may
7665 have put text on a frame other than the selected one, so the
7666 above call to update_frame would not have caught it. Catch
7669 Lisp_Object mini_window
;
7670 struct frame
*mini_frame
;
7672 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
7673 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
7675 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
7677 XWINDOW (mini_window
)->must_be_updated_p
= 1;
7678 pause
|= update_frame (mini_frame
, 0, 0);
7679 if (!pause
&& hscroll_windows (mini_window
))
7685 /* If display was paused because of pending input, make sure we do a
7686 thorough update the next time. */
7689 /* Prevent the optimization at the beginning of
7690 redisplay_internal that tries a single-line update of the
7691 line containing the cursor in the selected window. */
7692 CHARPOS (this_line_start_pos
) = 0;
7694 /* Let the overlay arrow be updated the next time. */
7695 if (!NILP (last_arrow_position
))
7697 last_arrow_position
= Qt
;
7698 last_arrow_string
= Qt
;
7701 /* If we pause after scrolling, some rows in the current
7702 matrices of some windows are not valid. */
7703 if (!WINDOW_FULL_WIDTH_P (w
)
7704 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
7705 update_mode_lines
= 1;
7708 /* Now text on frame agrees with windows, so put info into the
7709 windows for partial redisplay to follow. */
7712 register struct buffer
*b
= XBUFFER (w
->buffer
);
7714 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
7715 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
7716 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
7717 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
7719 if (consider_all_windows_p
)
7720 mark_window_display_accurate (FRAME_ROOT_WINDOW (sf
), 1);
7723 XSETFASTINT (w
->last_point
, BUF_PT (b
));
7724 w
->last_cursor
= w
->cursor
;
7725 w
->last_cursor_off_p
= w
->cursor_off_p
;
7727 b
->clip_changed
= 0;
7728 b
->prevent_redisplay_optimizations_p
= 0;
7729 w
->update_mode_line
= Qnil
;
7730 XSETFASTINT (w
->last_modified
, BUF_MODIFF (b
));
7731 XSETFASTINT (w
->last_overlay_modified
, BUF_OVERLAY_MODIFF (b
));
7733 = (BUF_MODIFF (XBUFFER (w
->buffer
)) > BUF_SAVE_MODIFF (XBUFFER (w
->buffer
))
7736 /* Record if we are showing a region, so can make sure to
7737 update it fully at next redisplay. */
7738 w
->region_showing
= (!NILP (Vtransient_mark_mode
)
7739 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7740 || highlight_nonselected_windows
)
7741 && !NILP (XBUFFER (w
->buffer
)->mark_active
)
7742 ? Fmarker_position (XBUFFER (w
->buffer
)->mark
)
7745 w
->window_end_valid
= w
->buffer
;
7746 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7747 last_arrow_string
= Voverlay_arrow_string
;
7748 if (frame_up_to_date_hook
!= 0)
7749 (*frame_up_to_date_hook
) (sf
);
7751 w
->current_matrix
->buffer
= b
;
7752 w
->current_matrix
->begv
= BUF_BEGV (b
);
7753 w
->current_matrix
->zv
= BUF_ZV (b
);
7756 update_mode_lines
= 0;
7757 windows_or_buffers_changed
= 0;
7760 /* Start SIGIO interrupts coming again. Having them off during the
7761 code above makes it less likely one will discard output, but not
7762 impossible, since there might be stuff in the system buffer here.
7763 But it is much hairier to try to do anything about that. */
7764 if (interrupt_input
)
7768 /* If a frame has become visible which was not before, redisplay
7769 again, so that we display it. Expose events for such a frame
7770 (which it gets when becoming visible) don't call the parts of
7771 redisplay constructing glyphs, so simply exposing a frame won't
7772 display anything in this case. So, we have to display these
7773 frames here explicitly. */
7776 Lisp_Object tail
, frame
;
7779 FOR_EACH_FRAME (tail
, frame
)
7781 int this_is_visible
= 0;
7783 if (XFRAME (frame
)->visible
)
7784 this_is_visible
= 1;
7785 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
7786 if (XFRAME (frame
)->visible
)
7787 this_is_visible
= 1;
7789 if (this_is_visible
)
7793 if (new_count
!= number_of_visible_frames
)
7794 windows_or_buffers_changed
++;
7797 /* Change frame size now if a change is pending. */
7798 do_pending_window_change (1);
7800 /* If we just did a pending size change, or have additional
7801 visible frames, redisplay again. */
7802 if (windows_or_buffers_changed
&& !pause
)
7807 unbind_to (count
, Qnil
);
7811 /* Redisplay, but leave alone any recent echo area message unless
7812 another message has been requested in its place.
7814 This is useful in situations where you need to redisplay but no
7815 user action has occurred, making it inappropriate for the message
7816 area to be cleared. See tracking_off and
7817 wait_reading_process_input for examples of these situations. */
7820 redisplay_preserve_echo_area ()
7822 if (!NILP (echo_area_buffer
[1]))
7824 /* We have a previously displayed message, but no current
7825 message. Redisplay the previous message. */
7826 display_last_displayed_message_p
= 1;
7827 redisplay_internal (1);
7828 display_last_displayed_message_p
= 0;
7831 redisplay_internal (1);
7835 /* Function registered with record_unwind_protect in
7836 redisplay_internal. Clears the flag indicating that a redisplay is
7840 unwind_redisplay (old_redisplaying_p
)
7841 Lisp_Object old_redisplaying_p
;
7843 redisplaying_p
= XFASTINT (old_redisplaying_p
);
7848 /* Mark the display of windows in the window tree rooted at WINDOW as
7849 accurate or inaccurate. If FLAG is non-zero mark display of WINDOW
7850 as accurate. If FLAG is zero arrange for WINDOW to be redisplayed
7851 the next time redisplay_internal is called. */
7854 mark_window_display_accurate (window
, accurate_p
)
7860 for (; !NILP (window
); window
= w
->next
)
7862 w
= XWINDOW (window
);
7864 if (BUFFERP (w
->buffer
))
7866 struct buffer
*b
= XBUFFER (w
->buffer
);
7868 XSETFASTINT (w
->last_modified
,
7869 accurate_p
? BUF_MODIFF (b
) : 0);
7870 XSETFASTINT (w
->last_overlay_modified
,
7871 accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0);
7872 w
->last_had_star
= (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
)
7875 #if 0 /* I don't think this is necessary because display_line does it.
7877 /* Record if we are showing a region, so can make sure to
7878 update it fully at next redisplay. */
7880 = (!NILP (Vtransient_mark_mode
)
7881 && (w
== XWINDOW (current_buffer
->last_selected_window
)
7882 || highlight_nonselected_windows
)
7883 && (!NILP (b
->mark_active
)
7884 ? Fmarker_position (b
->mark
)
7890 b
->clip_changed
= 0;
7891 b
->prevent_redisplay_optimizations_p
= 0;
7892 w
->current_matrix
->buffer
= b
;
7893 w
->current_matrix
->begv
= BUF_BEGV (b
);
7894 w
->current_matrix
->zv
= BUF_ZV (b
);
7895 w
->last_cursor
= w
->cursor
;
7896 w
->last_cursor_off_p
= w
->cursor_off_p
;
7897 if (w
== XWINDOW (selected_window
))
7898 w
->last_point
= make_number (BUF_PT (b
));
7900 w
->last_point
= make_number (XMARKER (w
->pointm
)->charpos
);
7904 w
->window_end_valid
= w
->buffer
;
7905 w
->update_mode_line
= Qnil
;
7907 if (!NILP (w
->vchild
))
7908 mark_window_display_accurate (w
->vchild
, accurate_p
);
7909 if (!NILP (w
->hchild
))
7910 mark_window_display_accurate (w
->hchild
, accurate_p
);
7915 last_arrow_position
= COERCE_MARKER (Voverlay_arrow_position
);
7916 last_arrow_string
= Voverlay_arrow_string
;
7920 /* Force a thorough redisplay the next time by setting
7921 last_arrow_position and last_arrow_string to t, which is
7922 unequal to any useful value of Voverlay_arrow_... */
7923 last_arrow_position
= Qt
;
7924 last_arrow_string
= Qt
;
7929 /* Return value in display table DP (Lisp_Char_Table *) for character
7930 C. Since a display table doesn't have any parent, we don't have to
7931 follow parent. Do not call this function directly but use the
7932 macro DISP_CHAR_VECTOR. */
7935 disp_char_vector (dp
, c
)
7936 struct Lisp_Char_Table
*dp
;
7942 if (SINGLE_BYTE_CHAR_P (c
))
7943 return (dp
->contents
[c
]);
7945 SPLIT_NON_ASCII_CHAR (c
, code
[0], code
[1], code
[2]);
7948 else if (code
[2] < 32)
7951 /* Here, the possible range of code[0] (== charset ID) is
7952 128..max_charset. Since the top level char table contains data
7953 for multibyte characters after 256th element, we must increment
7954 code[0] by 128 to get a correct index. */
7956 code
[3] = -1; /* anchor */
7958 for (i
= 0; code
[i
] >= 0; i
++, dp
= XCHAR_TABLE (val
))
7960 val
= dp
->contents
[code
[i
]];
7961 if (!SUB_CHAR_TABLE_P (val
))
7962 return (NILP (val
) ? dp
->defalt
: val
);
7965 /* Here, val is a sub char table. We return the default value of
7967 return (dp
->defalt
);
7972 /***********************************************************************
7974 ***********************************************************************/
7976 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
7979 redisplay_windows (window
)
7982 while (!NILP (window
))
7984 struct window
*w
= XWINDOW (window
);
7986 if (!NILP (w
->hchild
))
7987 redisplay_windows (w
->hchild
);
7988 else if (!NILP (w
->vchild
))
7989 redisplay_windows (w
->vchild
);
7991 redisplay_window (window
, 0);
7998 /* Set cursor position of W. PT is assumed to be displayed in ROW.
7999 DELTA is the number of bytes by which positions recorded in ROW
8000 differ from current buffer positions. */
8003 set_cursor_from_row (w
, row
, matrix
, delta
, delta_bytes
, dy
, dvpos
)
8005 struct glyph_row
*row
;
8006 struct glyph_matrix
*matrix
;
8007 int delta
, delta_bytes
, dy
, dvpos
;
8009 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
8010 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
8012 int pt_old
= PT
- delta
;
8014 /* Skip over glyphs not having an object at the start of the row.
8015 These are special glyphs like truncation marks on terminal
8017 if (row
->displays_text_p
)
8019 && INTEGERP (glyph
->object
)
8020 && glyph
->charpos
< 0)
8022 x
+= glyph
->pixel_width
;
8027 && !INTEGERP (glyph
->object
)
8028 && (!BUFFERP (glyph
->object
)
8029 || glyph
->charpos
< pt_old
))
8031 x
+= glyph
->pixel_width
;
8035 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
8037 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
8038 w
->cursor
.y
= row
->y
+ dy
;
8040 if (w
== XWINDOW (selected_window
))
8042 if (!row
->continued_p
8043 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
8046 this_line_buffer
= XBUFFER (w
->buffer
);
8048 CHARPOS (this_line_start_pos
)
8049 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
8050 BYTEPOS (this_line_start_pos
)
8051 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
8053 CHARPOS (this_line_end_pos
)
8054 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
8055 BYTEPOS (this_line_end_pos
)
8056 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
8058 this_line_y
= w
->cursor
.y
;
8059 this_line_pixel_height
= row
->height
;
8060 this_line_vpos
= w
->cursor
.vpos
;
8061 this_line_start_x
= row
->x
;
8064 CHARPOS (this_line_start_pos
) = 0;
8069 /* Run window scroll functions, if any, for WINDOW with new window
8070 start STARTP. Sets the window start of WINDOW to that position.
8072 We assume that the window's buffer is really current. */
8074 static INLINE
struct text_pos
8075 run_window_scroll_functions (window
, startp
)
8077 struct text_pos startp
;
8079 struct window
*w
= XWINDOW (window
);
8080 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
8082 if (current_buffer
!= XBUFFER (w
->buffer
))
8085 if (!NILP (Vwindow_scroll_functions
))
8087 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
8088 make_number (CHARPOS (startp
)));
8089 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8090 /* In case the hook functions switch buffers. */
8091 if (current_buffer
!= XBUFFER (w
->buffer
))
8092 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8099 /* Modify the desired matrix of window W and W->vscroll so that the
8100 line containing the cursor is fully visible. */
8103 make_cursor_line_fully_visible (w
)
8106 struct glyph_matrix
*matrix
;
8107 struct glyph_row
*row
;
8108 int header_line_height
;
8110 /* It's not always possible to find the cursor, e.g, when a window
8111 is full of overlay strings. Don't do anything in that case. */
8112 if (w
->cursor
.vpos
< 0)
8115 matrix
= w
->desired_matrix
;
8116 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
8118 /* If row->y == top y of window display area, the window isn't tall
8119 enough to display a single line. There is nothing we can do
8121 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
8122 if (row
->y
== header_line_height
)
8125 if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
8127 int dy
= row
->height
- row
->visible_height
;
8130 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8132 else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
))
8134 int dy
= - (row
->height
- row
->visible_height
);
8137 shift_glyph_matrix (w
, matrix
, 0, matrix
->nrows
, dy
);
8140 /* When we change the cursor y-position of the selected window,
8141 change this_line_y as well so that the display optimization for
8142 the cursor line of the selected window in redisplay_internal uses
8143 the correct y-position. */
8144 if (w
== XWINDOW (selected_window
))
8145 this_line_y
= w
->cursor
.y
;
8149 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
8150 non-zero means only WINDOW is redisplayed in redisplay_internal.
8151 TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used
8152 in redisplay_window to bring a partially visible line into view in
8153 the case that only the cursor has moved.
8157 1 if scrolling succeeded
8159 0 if scrolling didn't find point.
8161 -1 if new fonts have been loaded so that we must interrupt
8162 redisplay, adjust glyph matrices, and try again. */
8165 try_scrolling (window
, just_this_one_p
, scroll_conservatively
,
8166 scroll_step
, temp_scroll_step
)
8168 int just_this_one_p
;
8169 int scroll_conservatively
, scroll_step
;
8170 int temp_scroll_step
;
8172 struct window
*w
= XWINDOW (window
);
8173 struct frame
*f
= XFRAME (w
->frame
);
8174 struct text_pos scroll_margin_pos
;
8175 struct text_pos pos
;
8176 struct text_pos startp
;
8178 Lisp_Object window_end
;
8179 int this_scroll_margin
;
8182 int line_height
, rc
;
8183 int amount_to_scroll
= 0;
8184 Lisp_Object aggressive
;
8188 debug_method_add (w
, "try_scrolling");
8191 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8193 /* Compute scroll margin height in pixels. We scroll when point is
8194 within this distance from the top or bottom of the window. */
8195 if (scroll_margin
> 0)
8197 this_scroll_margin
= min (scroll_margin
, XINT (w
->height
) / 4);
8198 this_scroll_margin
*= CANON_Y_UNIT (f
);
8201 this_scroll_margin
= 0;
8203 /* Compute how much we should try to scroll maximally to bring point
8206 scroll_max
= scroll_step
;
8207 else if (scroll_conservatively
)
8208 scroll_max
= scroll_conservatively
;
8209 else if (temp_scroll_step
)
8210 scroll_max
= temp_scroll_step
;
8211 else if (NUMBERP (current_buffer
->scroll_down_aggressively
)
8212 || NUMBERP (current_buffer
->scroll_up_aggressively
))
8213 /* We're trying to scroll because of aggressive scrolling
8214 but no scroll_step is set. Choose an arbitrary one. Maybe
8215 there should be a variable for this. */
8219 scroll_max
*= CANON_Y_UNIT (f
);
8221 /* Decide whether we have to scroll down. Start at the window end
8222 and move this_scroll_margin up to find the position of the scroll
8224 window_end
= Fwindow_end (window
, Qt
);
8225 CHARPOS (scroll_margin_pos
) = XINT (window_end
);
8226 BYTEPOS (scroll_margin_pos
) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos
));
8227 if (this_scroll_margin
)
8229 start_display (&it
, w
, scroll_margin_pos
);
8230 move_it_vertically (&it
, - this_scroll_margin
);
8231 scroll_margin_pos
= it
.current
.pos
;
8234 if (PT
>= CHARPOS (scroll_margin_pos
))
8238 /* Point is in the scroll margin at the bottom of the window, or
8239 below. Compute a new window start that makes point visible. */
8241 /* Compute the distance from the scroll margin to PT.
8242 Give up if the distance is greater than scroll_max. */
8243 start_display (&it
, w
, scroll_margin_pos
);
8245 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8246 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8247 line_height
= (it
.max_ascent
+ it
.max_descent
8248 ? it
.max_ascent
+ it
.max_descent
8250 dy
= it
.current_y
+ line_height
- y0
;
8251 if (dy
> scroll_max
)
8254 /* Move the window start down. If scrolling conservatively,
8255 move it just enough down to make point visible. If
8256 scroll_step is set, move it down by scroll_step. */
8257 start_display (&it
, w
, startp
);
8259 if (scroll_conservatively
)
8260 amount_to_scroll
= dy
;
8261 else if (scroll_step
|| temp_scroll_step
)
8262 amount_to_scroll
= scroll_max
;
8265 aggressive
= current_buffer
->scroll_down_aggressively
;
8266 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8267 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8268 if (NUMBERP (aggressive
))
8269 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8272 if (amount_to_scroll
<= 0)
8275 move_it_vertically (&it
, amount_to_scroll
);
8276 startp
= it
.current
.pos
;
8280 /* See if point is inside the scroll margin at the top of the
8282 scroll_margin_pos
= startp
;
8283 if (this_scroll_margin
)
8285 start_display (&it
, w
, startp
);
8286 move_it_vertically (&it
, this_scroll_margin
);
8287 scroll_margin_pos
= it
.current
.pos
;
8290 if (PT
< CHARPOS (scroll_margin_pos
))
8292 /* Point is in the scroll margin at the top of the window or
8293 above what is displayed in the window. */
8296 /* Compute the vertical distance from PT to the scroll
8297 margin position. Give up if distance is greater than
8299 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
8300 start_display (&it
, w
, pos
);
8302 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
8303 it
.last_visible_y
, -1,
8304 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8305 dy
= it
.current_y
- y0
;
8306 if (dy
> scroll_max
)
8309 /* Compute new window start. */
8310 start_display (&it
, w
, startp
);
8312 if (scroll_conservatively
)
8313 amount_to_scroll
= dy
;
8314 else if (scroll_step
|| temp_scroll_step
)
8315 amount_to_scroll
= scroll_max
;
8318 aggressive
= current_buffer
->scroll_up_aggressively
;
8319 height
= (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w
)
8320 - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
));
8321 if (NUMBERP (aggressive
))
8322 amount_to_scroll
= XFLOATINT (aggressive
) * height
;
8325 if (amount_to_scroll
<= 0)
8328 move_it_vertically (&it
, - amount_to_scroll
);
8329 startp
= it
.current
.pos
;
8333 /* Run window scroll functions. */
8334 startp
= run_window_scroll_functions (window
, startp
);
8336 /* Display the window. Give up if new fonts are loaded, or if point
8338 if (!try_window (window
, startp
))
8340 else if (w
->cursor
.vpos
< 0)
8342 clear_glyph_matrix (w
->desired_matrix
);
8347 /* Maybe forget recorded base line for line number display. */
8348 if (!just_this_one_p
8349 || current_buffer
->clip_changed
8350 || BEG_UNCHANGED
< CHARPOS (startp
))
8351 w
->base_line_number
= Qnil
;
8353 /* If cursor ends up on a partially visible line, shift display
8354 lines up or down. */
8355 make_cursor_line_fully_visible (w
);
8363 /* Compute a suitable window start for window W if display of W starts
8364 on a continuation line. Value is non-zero if a new window start
8367 The new window start will be computed, based on W's width, starting
8368 from the start of the continued line. It is the start of the
8369 screen line with the minimum distance from the old start W->start. */
8372 compute_window_start_on_continuation_line (w
)
8375 struct text_pos pos
, start_pos
;
8376 int window_start_changed_p
= 0;
8378 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
8380 /* If window start is on a continuation line... Window start may be
8381 < BEGV in case there's invisible text at the start of the
8382 buffer (M-x rmail, for example). */
8383 if (CHARPOS (start_pos
) > BEGV
8384 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
8387 struct glyph_row
*row
;
8389 /* Handle the case that the window start is out of range. */
8390 if (CHARPOS (start_pos
) < BEGV
)
8391 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
8392 else if (CHARPOS (start_pos
) > ZV
)
8393 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
8395 /* Find the start of the continued line. This should be fast
8396 because scan_buffer is fast (newline cache). */
8397 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
8398 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
8399 row
, DEFAULT_FACE_ID
);
8400 reseat_at_previous_visible_line_start (&it
);
8402 /* If the line start is "too far" away from the window start,
8403 say it takes too much time to compute a new window start. */
8404 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
8405 < XFASTINT (w
->height
) * XFASTINT (w
->width
))
8407 int min_distance
, distance
;
8409 /* Move forward by display lines to find the new window
8410 start. If window width was enlarged, the new start can
8411 be expected to be > the old start. If window width was
8412 decreased, the new window start will be < the old start.
8413 So, we're looking for the display line start with the
8414 minimum distance from the old window start. */
8415 pos
= it
.current
.pos
;
8416 min_distance
= INFINITY
;
8417 while ((distance
= abs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
8418 distance
< min_distance
)
8420 min_distance
= distance
;
8421 pos
= it
.current
.pos
;
8422 move_it_by_lines (&it
, 1, 0);
8425 /* Set the window start there. */
8426 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
8427 window_start_changed_p
= 1;
8431 return window_start_changed_p
;
8435 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
8436 selected_window is redisplayed. */
8439 redisplay_window (window
, just_this_one_p
)
8441 int just_this_one_p
;
8443 struct window
*w
= XWINDOW (window
);
8444 struct frame
*f
= XFRAME (w
->frame
);
8445 struct buffer
*buffer
= XBUFFER (w
->buffer
);
8446 struct buffer
*old
= current_buffer
;
8447 struct text_pos lpoint
, opoint
, startp
;
8448 int update_mode_line
;
8451 /* Record it now because it's overwritten. */
8452 int current_matrix_up_to_date_p
= 0;
8453 int really_switched_buffer
= 0;
8454 int temp_scroll_step
= 0;
8455 int count
= specpdl_ptr
- specpdl
;
8457 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8460 /* W must be a leaf window here. */
8461 xassert (!NILP (w
->buffer
));
8463 *w
->desired_matrix
->method
= 0;
8466 specbind (Qinhibit_point_motion_hooks
, Qt
);
8468 reconsider_clip_changes (w
, buffer
);
8470 /* Has the mode line to be updated? */
8471 update_mode_line
= (!NILP (w
->update_mode_line
)
8472 || update_mode_lines
8473 || buffer
->clip_changed
);
8475 if (MINI_WINDOW_P (w
))
8477 if (w
== XWINDOW (echo_area_window
)
8478 && !NILP (echo_area_buffer
[0]))
8480 if (update_mode_line
)
8481 /* We may have to update a tty frame's menu bar or a
8482 tool-bar. Example `M-x C-h C-h C-g'. */
8483 goto finish_menu_bars
;
8485 /* We've already displayed the echo area glyphs in this window. */
8486 goto finish_scroll_bars
;
8488 else if (w
!= XWINDOW (minibuf_window
))
8490 /* W is a mini-buffer window, but it's not the currently
8491 active one, so clear it. */
8492 int yb
= window_text_bottom_y (w
);
8493 struct glyph_row
*row
;
8496 for (y
= 0, row
= w
->desired_matrix
->rows
;
8498 y
+= row
->height
, ++row
)
8499 blank_row (w
, row
, y
);
8500 goto finish_scroll_bars
;
8504 /* Otherwise set up data on this window; select its buffer and point
8506 if (update_mode_line
)
8508 /* Really select the buffer, for the sake of buffer-local
8510 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8511 really_switched_buffer
= 1;
8514 set_buffer_temp (XBUFFER (w
->buffer
));
8515 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
8517 current_matrix_up_to_date_p
8518 = (!NILP (w
->window_end_valid
)
8519 && !current_buffer
->clip_changed
8520 && XFASTINT (w
->last_modified
) >= MODIFF
8521 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
);
8523 /* When windows_or_buffers_changed is non-zero, we can't rely on
8524 the window end being valid, so set it to nil there. */
8525 if (windows_or_buffers_changed
)
8527 /* If window starts on a continuation line, maybe adjust the
8528 window start in case the window's width changed. */
8529 if (XMARKER (w
->start
)->buffer
== current_buffer
)
8530 compute_window_start_on_continuation_line (w
);
8532 w
->window_end_valid
= Qnil
;
8535 /* Some sanity checks. */
8536 CHECK_WINDOW_END (w
);
8537 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
8539 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
8542 /* If %c is in mode line, update it if needed. */
8543 if (!NILP (w
->column_number_displayed
)
8544 /* This alternative quickly identifies a common case
8545 where no change is needed. */
8546 && !(PT
== XFASTINT (w
->last_point
)
8547 && XFASTINT (w
->last_modified
) >= MODIFF
8548 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)
8549 && XFASTINT (w
->column_number_displayed
) != current_column ())
8550 update_mode_line
= 1;
8552 /* Count number of windows showing the selected buffer. An indirect
8553 buffer counts as its base buffer. */
8554 if (!just_this_one_p
)
8556 struct buffer
*current_base
, *window_base
;
8557 current_base
= current_buffer
;
8558 window_base
= XBUFFER (XWINDOW (selected_window
)->buffer
);
8559 if (current_base
->base_buffer
)
8560 current_base
= current_base
->base_buffer
;
8561 if (window_base
->base_buffer
)
8562 window_base
= window_base
->base_buffer
;
8563 if (current_base
== window_base
)
8567 /* Point refers normally to the selected window. For any other
8568 window, set up appropriate value. */
8569 if (!EQ (window
, selected_window
))
8571 int new_pt
= XMARKER (w
->pointm
)->charpos
;
8572 int new_pt_byte
= marker_byte_position (w
->pointm
);
8576 new_pt_byte
= BEGV_BYTE
;
8577 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
8579 else if (new_pt
> (ZV
- 1))
8582 new_pt_byte
= ZV_BYTE
;
8583 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
8586 /* We don't use SET_PT so that the point-motion hooks don't run. */
8587 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
8590 /* If any of the character widths specified in the display table
8591 have changed, invalidate the width run cache. It's true that
8592 this may be a bit late to catch such changes, but the rest of
8593 redisplay goes (non-fatally) haywire when the display table is
8594 changed, so why should we worry about doing any better? */
8595 if (current_buffer
->width_run_cache
)
8597 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
8599 if (! disptab_matches_widthtab (disptab
,
8600 XVECTOR (current_buffer
->width_table
)))
8602 invalidate_region_cache (current_buffer
,
8603 current_buffer
->width_run_cache
,
8605 recompute_width_table (current_buffer
, disptab
);
8609 /* If window-start is screwed up, choose a new one. */
8610 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
8613 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
8615 /* If someone specified a new starting point but did not insist,
8616 check whether it can be used. */
8617 if (!NILP (w
->optional_new_start
)
8618 && CHARPOS (startp
) >= BEGV
8619 && CHARPOS (startp
) <= ZV
)
8621 w
->optional_new_start
= Qnil
;
8622 /* This takes a mini-buffer prompt into account. */
8623 start_display (&it
, w
, startp
);
8624 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
8625 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
8626 if (IT_CHARPOS (it
) == PT
)
8627 w
->force_start
= Qt
;
8630 /* Handle case where place to start displaying has been specified,
8631 unless the specified location is outside the accessible range. */
8632 if (!NILP (w
->force_start
)
8633 || w
->frozen_window_start_p
)
8635 w
->force_start
= Qnil
;
8637 w
->window_end_valid
= Qnil
;
8639 /* Forget any recorded base line for line number display. */
8640 if (!current_matrix_up_to_date_p
8641 || current_buffer
->clip_changed
)
8642 w
->base_line_number
= Qnil
;
8644 /* Redisplay the mode line. Select the buffer properly for that.
8645 Also, run the hook window-scroll-functions
8646 because we have scrolled. */
8647 /* Note, we do this after clearing force_start because
8648 if there's an error, it is better to forget about force_start
8649 than to get into an infinite loop calling the hook functions
8650 and having them get more errors. */
8651 if (!update_mode_line
8652 || ! NILP (Vwindow_scroll_functions
))
8654 if (!really_switched_buffer
)
8656 set_buffer_temp (old
);
8657 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8658 really_switched_buffer
= 1;
8661 update_mode_line
= 1;
8662 w
->update_mode_line
= Qt
;
8663 startp
= run_window_scroll_functions (window
, startp
);
8666 XSETFASTINT (w
->last_modified
, 0);
8667 XSETFASTINT (w
->last_overlay_modified
, 0);
8668 if (CHARPOS (startp
) < BEGV
)
8669 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
8670 else if (CHARPOS (startp
) > ZV
)
8671 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
8673 /* Redisplay, then check if cursor has been set during the
8674 redisplay. Give up if new fonts were loaded. */
8675 if (!try_window (window
, startp
))
8677 w
->force_start
= Qt
;
8678 clear_glyph_matrix (w
->desired_matrix
);
8679 goto restore_buffers
;
8682 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
8684 /* If point does not appear, or on a line that is not fully
8685 visible, move point so it does appear. The desired
8686 matrix has been built above, so we can use it. */
8687 int height
= window_box_height (w
) / 2;
8688 struct glyph_row
*row
= MATRIX_ROW (w
->desired_matrix
, 0);
8690 while (row
->y
< height
)
8693 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
8694 MATRIX_ROW_START_BYTEPOS (row
));
8696 if (w
!= XWINDOW (selected_window
))
8697 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
8698 else if (current_buffer
== old
)
8699 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
8701 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
8703 /* If we are highlighting the region, then we just changed
8704 the region, so redisplay to show it. */
8705 if (!NILP (Vtransient_mark_mode
)
8706 && !NILP (current_buffer
->mark_active
))
8708 clear_glyph_matrix (w
->desired_matrix
);
8709 if (!try_window (window
, startp
))
8710 goto restore_buffers
;
8714 make_cursor_line_fully_visible (w
);
8716 debug_method_add (w
, "forced window start");
8721 /* Handle case where text has not changed, only point, and it has
8722 not moved off the frame. */
8723 if (current_matrix_up_to_date_p
8724 /* Point may be in this window. */
8725 && PT
>= CHARPOS (startp
)
8726 /* If we don't check this, we are called to move the cursor in a
8727 horizontally split window with a current matrix that doesn't
8729 && !windows_or_buffers_changed
8730 /* Selective display hasn't changed. */
8731 && !current_buffer
->clip_changed
8732 /* If force-mode-line-update was called, really redisplay;
8733 that's how redisplay is forced after e.g. changing
8734 buffer-invisibility-spec. */
8735 && NILP (w
->update_mode_line
)
8736 /* Can't use this case if highlighting a region. When a
8737 region exists, cursor movement has to do more than just
8739 && !(!NILP (Vtransient_mark_mode
)
8740 && !NILP (current_buffer
->mark_active
))
8741 && NILP (w
->region_showing
)
8742 && NILP (Vshow_trailing_whitespace
)
8743 /* Right after splitting windows, last_point may be nil. */
8744 && INTEGERP (w
->last_point
)
8745 /* This code is not used for mini-buffer for the sake of the case
8746 of redisplaying to replace an echo area message; since in
8747 that case the mini-buffer contents per se are usually
8748 unchanged. This code is of no real use in the mini-buffer
8749 since the handling of this_line_start_pos, etc., in redisplay
8750 handles the same cases. */
8751 && !EQ (window
, minibuf_window
)
8752 /* When splitting windows or for new windows, it happens that
8753 redisplay is called with a nil window_end_vpos or one being
8754 larger than the window. This should really be fixed in
8755 window.c. I don't have this on my list, now, so we do
8756 approximately the same as the old redisplay code. --gerd. */
8757 && INTEGERP (w
->window_end_vpos
)
8758 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
8759 && (FRAME_WINDOW_P (f
)
8760 || !MARKERP (Voverlay_arrow_position
)
8761 || current_buffer
!= XMARKER (Voverlay_arrow_position
)->buffer
))
8763 int this_scroll_margin
;
8764 struct glyph_row
*row
;
8768 debug_method_add (w
, "cursor movement");
8771 /* Scroll if point within this distance from the top or bottom
8772 of the window. This is a pixel value. */
8773 this_scroll_margin
= max (0, scroll_margin
);
8774 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
8775 this_scroll_margin
*= CANON_Y_UNIT (f
);
8777 /* Start with the row the cursor was displayed during the last
8778 not paused redisplay. Give up if that row is not valid. */
8779 if (w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
8781 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
8782 if (row
->mode_line_p
)
8784 if (!row
->enabled_p
)
8788 if (PT
> XFASTINT (w
->last_point
))
8790 /* Point has moved forward. */
8791 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
8793 while ((MATRIX_ROW_END_CHARPOS (row
) < PT
8794 /* The end position of a row equals the start
8795 position of the next row. If PT is there, we
8796 would rather display it in the next line, except
8797 when this line ends in ZV. */
8798 || (MATRIX_ROW_END_CHARPOS (row
) == PT
8799 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
8800 || !row
->ends_at_zv_p
)))
8801 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
8803 xassert (row
->enabled_p
);
8807 /* If within the scroll margin, scroll. Note that
8808 MATRIX_ROW_BOTTOM_Y gives the pixel position at which the
8809 next line would be drawn, and that this_scroll_margin can
8811 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
8812 || PT
> MATRIX_ROW_END_CHARPOS (row
)
8813 /* Line is completely visible last line in window and PT
8814 is to be set in the next line. */
8815 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
8816 && PT
== MATRIX_ROW_END_CHARPOS (row
)
8817 && !row
->ends_at_zv_p
8818 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
8821 else if (PT
< XFASTINT (w
->last_point
))
8823 /* Cursor has to be moved backward. Note that PT >=
8824 CHARPOS (startp) because of the outer if-statement. */
8825 while (!row
->mode_line_p
8826 && (MATRIX_ROW_START_CHARPOS (row
) > PT
8827 || (MATRIX_ROW_START_CHARPOS (row
) == PT
8828 && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)))
8829 && (row
->y
> this_scroll_margin
8830 || CHARPOS (startp
) == BEGV
))
8832 xassert (row
->enabled_p
);
8836 /* Consider the following case: Window starts at BEGV, there
8837 is invisible, intangible text at BEGV, so that display
8838 starts at some point START > BEGV. It can happen that
8839 we are called with PT somewhere between BEGV and START.
8840 Try to handle that case. */
8841 if (row
< w
->current_matrix
->rows
8842 || row
->mode_line_p
)
8844 row
= w
->current_matrix
->rows
;
8845 if (row
->mode_line_p
)
8849 /* Due to newlines in overlay strings, we may have to skip
8850 forward over overlay strings. */
8851 while (MATRIX_ROW_END_CHARPOS (row
) == PT
8852 && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row
)
8853 && !row
->ends_at_zv_p
)
8856 /* If within the scroll margin, scroll. */
8857 if (row
->y
< this_scroll_margin
8858 && CHARPOS (startp
) != BEGV
)
8862 /* if PT is not in the glyph row, give up. */
8863 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
8864 || PT
> MATRIX_ROW_END_CHARPOS (row
))
8867 /* If we end up in a partially visible line, let's make it fully
8868 visible. This can be done most easily by using the existing
8870 if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row
))
8872 temp_scroll_step
= 1;
8878 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
8882 /* If current starting point was originally the beginning of a line
8883 but no longer is, find a new starting point. */
8884 else if (!NILP (w
->start_at_line_beg
)
8885 && !(CHARPOS (startp
) <= BEGV
8886 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
8889 debug_method_add (w
, "recenter 1");
8894 /* Try scrolling with try_window_id. */
8895 else if (/* Windows and buffers haven't changed. */
8896 !windows_or_buffers_changed
8897 /* Window must be either use window-based redisplay or
8899 && (FRAME_WINDOW_P (f
)
8900 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)))
8901 && !MINI_WINDOW_P (w
)
8902 /* Point is not known NOT to appear in window. */
8903 && PT
>= CHARPOS (startp
)
8904 && XFASTINT (w
->last_modified
)
8905 /* Window is not hscrolled. */
8906 && XFASTINT (w
->hscroll
) == 0
8907 /* Selective display has not changed. */
8908 && !current_buffer
->clip_changed
8909 /* Current matrix is up to date. */
8910 && !NILP (w
->window_end_valid
)
8911 /* Can't use this case if highlighting a region because
8912 a cursor movement will do more than just set the cursor. */
8913 && !(!NILP (Vtransient_mark_mode
)
8914 && !NILP (current_buffer
->mark_active
))
8915 && NILP (w
->region_showing
)
8916 && NILP (Vshow_trailing_whitespace
)
8917 /* Overlay arrow position and string not changed. */
8918 && EQ (last_arrow_position
, COERCE_MARKER (Voverlay_arrow_position
))
8919 && EQ (last_arrow_string
, Voverlay_arrow_string
)
8920 /* Value is > 0 if update has been done, it is -1 if we
8921 know that the same window start will not work. It is 0
8922 if unsuccessful for some other reason. */
8923 && (tem
= try_window_id (w
)) != 0)
8926 debug_method_add (w
, "try_window_id");
8929 if (fonts_changed_p
)
8930 goto restore_buffers
;
8933 /* Otherwise try_window_id has returned -1 which means that we
8934 don't want the alternative below this comment to execute. */
8936 else if (CHARPOS (startp
) >= BEGV
8937 && CHARPOS (startp
) <= ZV
8938 && PT
>= CHARPOS (startp
)
8939 && (CHARPOS (startp
) < ZV
8940 /* Avoid starting at end of buffer. */
8941 || CHARPOS (startp
) == BEGV
8942 || (XFASTINT (w
->last_modified
) >= MODIFF
8943 && XFASTINT (w
->last_overlay_modified
) >= OVERLAY_MODIFF
)))
8946 debug_method_add (w
, "same window start");
8949 /* Try to redisplay starting at same place as before.
8950 If point has not moved off frame, accept the results. */
8951 if (!current_matrix_up_to_date_p
8952 /* Don't use try_window_reusing_current_matrix in this case
8953 because a window scroll function can have changed the
8955 || !NILP (Vwindow_scroll_functions
)
8956 || MINI_WINDOW_P (w
)
8957 || !try_window_reusing_current_matrix (w
))
8959 IF_DEBUG (debug_method_add (w
, "1"));
8960 try_window (window
, startp
);
8963 if (fonts_changed_p
)
8964 goto restore_buffers
;
8966 if (w
->cursor
.vpos
>= 0)
8968 if (!just_this_one_p
8969 || current_buffer
->clip_changed
8970 || BEG_UNCHANGED
< CHARPOS (startp
))
8971 /* Forget any recorded base line for line number display. */
8972 w
->base_line_number
= Qnil
;
8974 make_cursor_line_fully_visible (w
);
8978 clear_glyph_matrix (w
->desired_matrix
);
8983 XSETFASTINT (w
->last_modified
, 0);
8984 XSETFASTINT (w
->last_overlay_modified
, 0);
8986 /* Redisplay the mode line. Select the buffer properly for that. */
8987 if (!update_mode_line
)
8989 if (!really_switched_buffer
)
8991 set_buffer_temp (old
);
8992 set_buffer_internal_1 (XBUFFER (w
->buffer
));
8993 really_switched_buffer
= 1;
8995 update_mode_line
= 1;
8996 w
->update_mode_line
= Qt
;
8999 /* Try to scroll by specified few lines. */
9000 if ((scroll_conservatively
9003 || NUMBERP (current_buffer
->scroll_up_aggressively
)
9004 || NUMBERP (current_buffer
->scroll_down_aggressively
))
9005 && !current_buffer
->clip_changed
9006 && CHARPOS (startp
) >= BEGV
9007 && CHARPOS (startp
) <= ZV
)
9009 /* The function returns -1 if new fonts were loaded, 1 if
9010 successful, 0 if not successful. */
9011 int rc
= try_scrolling (window
, just_this_one_p
,
9012 scroll_conservatively
,
9018 goto restore_buffers
;
9021 /* Finally, just choose place to start which centers point */
9026 debug_method_add (w
, "recenter");
9029 /* w->vscroll = 0; */
9031 /* Forget any previously recorded base line for line number display. */
9032 if (!current_matrix_up_to_date_p
9033 || current_buffer
->clip_changed
)
9034 w
->base_line_number
= Qnil
;
9036 /* Move backward half the height of the window. */
9037 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9038 it
.current_y
= it
.last_visible_y
;
9039 move_it_vertically_backward (&it
, it
.last_visible_y
/ 2);
9040 xassert (IT_CHARPOS (it
) >= BEGV
);
9042 /* The function move_it_vertically_backward may move over more
9043 than the specified y-distance. If it->w is small, e.g. a
9044 mini-buffer window, we may end up in front of the window's
9045 display area. Start displaying at the start of the line
9046 containing PT in this case. */
9047 if (it
.current_y
<= 0)
9049 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
9050 move_it_vertically (&it
, 0);
9051 xassert (IT_CHARPOS (it
) <= PT
);
9055 it
.current_x
= it
.hpos
= 0;
9057 /* Set startp here explicitly in case that helps avoid an infinite loop
9058 in case the window-scroll-functions functions get errors. */
9059 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
9061 /* Run scroll hooks. */
9062 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
9064 /* Redisplay the window. */
9065 if (!current_matrix_up_to_date_p
9066 || windows_or_buffers_changed
9067 /* Don't use try_window_reusing_current_matrix in this case
9068 because it can have changed the buffer. */
9069 || !NILP (Vwindow_scroll_functions
)
9071 || MINI_WINDOW_P (w
)
9072 || !try_window_reusing_current_matrix (w
))
9073 try_window (window
, startp
);
9075 /* If new fonts have been loaded (due to fontsets), give up. We
9076 have to start a new redisplay since we need to re-adjust glyph
9078 if (fonts_changed_p
)
9079 goto restore_buffers
;
9081 /* If cursor did not appear assume that the middle of the window is
9082 in the first line of the window. Do it again with the next line.
9083 (Imagine a window of height 100, displaying two lines of height
9084 60. Moving back 50 from it->last_visible_y will end in the first
9086 if (w
->cursor
.vpos
< 0)
9088 if (!NILP (w
->window_end_valid
)
9089 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
9091 clear_glyph_matrix (w
->desired_matrix
);
9092 move_it_by_lines (&it
, 1, 0);
9093 try_window (window
, it
.current
.pos
);
9095 else if (PT
< IT_CHARPOS (it
))
9097 clear_glyph_matrix (w
->desired_matrix
);
9098 move_it_by_lines (&it
, -1, 0);
9099 try_window (window
, it
.current
.pos
);
9103 /* Not much we can do about it. */
9107 /* Consider the following case: Window starts at BEGV, there is
9108 invisible, intangible text at BEGV, so that display starts at
9109 some point START > BEGV. It can happen that we are called with
9110 PT somewhere between BEGV and START. Try to handle that case. */
9111 if (w
->cursor
.vpos
< 0)
9113 struct glyph_row
*row
= w
->current_matrix
->rows
;
9114 if (row
->mode_line_p
)
9116 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
9119 make_cursor_line_fully_visible (w
);
9123 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
9124 w
->start_at_line_beg
= ((CHARPOS (startp
) == BEGV
9125 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n')
9128 /* Display the mode line, if we must. */
9129 if ((update_mode_line
9130 /* If window not full width, must redo its mode line
9131 if (a) the window to its side is being redone and
9132 (b) we do a frame-based redisplay. This is a consequence
9133 of how inverted lines are drawn in frame-based redisplay. */
9134 || (!just_this_one_p
9135 && !FRAME_WINDOW_P (f
)
9136 && !WINDOW_FULL_WIDTH_P (w
))
9137 /* Line number to display. */
9138 || INTEGERP (w
->base_line_pos
)
9139 /* Column number is displayed and different from the one displayed. */
9140 || (!NILP (w
->column_number_displayed
)
9141 && XFASTINT (w
->column_number_displayed
) != current_column ()))
9142 /* This means that the window has a mode line. */
9143 && (WINDOW_WANTS_MODELINE_P (w
)
9144 || WINDOW_WANTS_HEADER_LINE_P (w
)))
9146 display_mode_lines (w
);
9148 /* If mode line height has changed, arrange for a thorough
9149 immediate redisplay using the correct mode line height. */
9150 if (WINDOW_WANTS_MODELINE_P (w
)
9151 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
9153 fonts_changed_p
= 1;
9154 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
9155 = DESIRED_MODE_LINE_HEIGHT (w
);
9158 /* If top line height has changed, arrange for a thorough
9159 immediate redisplay using the correct mode line height. */
9160 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9161 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
9163 fonts_changed_p
= 1;
9164 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
9165 = DESIRED_HEADER_LINE_HEIGHT (w
);
9168 if (fonts_changed_p
)
9169 goto restore_buffers
;
9172 if (!line_number_displayed
9173 && !BUFFERP (w
->base_line_pos
))
9175 w
->base_line_pos
= Qnil
;
9176 w
->base_line_number
= Qnil
;
9181 /* When we reach a frame's selected window, redo the frame's menu bar. */
9182 if (update_mode_line
9183 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
9185 int redisplay_menu_p
= 0;
9187 if (FRAME_WINDOW_P (f
))
9189 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
9190 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
9192 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9196 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
9198 if (redisplay_menu_p
)
9199 display_menu_bar (w
);
9201 #ifdef HAVE_WINDOW_SYSTEM
9202 if (WINDOWP (f
->tool_bar_window
)
9203 && (FRAME_TOOL_BAR_LINES (f
) > 0
9204 || auto_resize_tool_bars_p
))
9205 redisplay_tool_bar (f
);
9211 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9213 int start
, end
, whole
;
9215 /* Calculate the start and end positions for the current window.
9216 At some point, it would be nice to choose between scrollbars
9217 which reflect the whole buffer size, with special markers
9218 indicating narrowing, and scrollbars which reflect only the
9221 Note that mini-buffers sometimes aren't displaying any text. */
9222 if (!MINI_WINDOW_P (w
)
9223 || (w
== XWINDOW (minibuf_window
)
9224 && NILP (echo_area_buffer
[0])))
9227 start
= marker_position (w
->start
) - BEGV
;
9228 /* I don't think this is guaranteed to be right. For the
9229 moment, we'll pretend it is. */
9230 end
= (Z
- XFASTINT (w
->window_end_pos
)) - BEGV
;
9234 if (whole
< (end
- start
))
9235 whole
= end
- start
;
9238 start
= end
= whole
= 0;
9240 /* Indicate what this scroll bar ought to be displaying now. */
9241 (*set_vertical_scroll_bar_hook
) (w
, end
- start
, whole
, start
);
9243 /* Note that we actually used the scroll bar attached to this
9244 window, so it shouldn't be deleted at the end of redisplay. */
9245 (*redeem_scroll_bar_hook
) (w
);
9250 /* Restore current_buffer and value of point in it. */
9251 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
9252 if (really_switched_buffer
)
9253 set_buffer_internal_1 (old
);
9255 set_buffer_temp (old
);
9256 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
9258 unbind_to (count
, Qnil
);
9262 /* Build the complete desired matrix of WINDOW with a window start
9263 buffer position POS. Value is non-zero if successful. It is zero
9264 if fonts were loaded during redisplay which makes re-adjusting
9265 glyph matrices necessary. */
9268 try_window (window
, pos
)
9270 struct text_pos pos
;
9272 struct window
*w
= XWINDOW (window
);
9274 struct glyph_row
*last_text_row
= NULL
;
9276 /* Make POS the new window start. */
9277 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
9279 /* Mark cursor position as unknown. No overlay arrow seen. */
9280 w
->cursor
.vpos
= -1;
9281 overlay_arrow_seen
= 0;
9283 /* Initialize iterator and info to start at POS. */
9284 start_display (&it
, w
, pos
);
9286 /* Display all lines of W. */
9287 while (it
.current_y
< it
.last_visible_y
)
9289 if (display_line (&it
))
9290 last_text_row
= it
.glyph_row
- 1;
9291 if (fonts_changed_p
)
9295 /* If bottom moved off end of frame, change mode line percentage. */
9296 if (XFASTINT (w
->window_end_pos
) <= 0
9297 && Z
!= IT_CHARPOS (it
))
9298 w
->update_mode_line
= Qt
;
9300 /* Set window_end_pos to the offset of the last character displayed
9301 on the window from the end of current_buffer. Set
9302 window_end_vpos to its row number. */
9305 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
9306 w
->window_end_bytepos
9307 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9308 XSETFASTINT (w
->window_end_pos
,
9309 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9310 XSETFASTINT (w
->window_end_vpos
,
9311 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9312 xassert (MATRIX_ROW (w
->desired_matrix
, XFASTINT (w
->window_end_vpos
))
9317 w
->window_end_bytepos
= 0;
9318 XSETFASTINT (w
->window_end_pos
, 0);
9319 XSETFASTINT (w
->window_end_vpos
, 0);
9322 /* But that is not valid info until redisplay finishes. */
9323 w
->window_end_valid
= Qnil
;
9329 /************************************************************************
9330 Window redisplay reusing current matrix when buffer has not changed
9331 ************************************************************************/
9333 /* Try redisplay of window W showing an unchanged buffer with a
9334 different window start than the last time it was displayed by
9335 reusing its current matrix. Value is non-zero if successful.
9336 W->start is the new window start. */
9339 try_window_reusing_current_matrix (w
)
9342 struct frame
*f
= XFRAME (w
->frame
);
9343 struct glyph_row
*row
, *bottom_row
;
9346 struct text_pos start
, new_start
;
9347 int nrows_scrolled
, i
;
9348 struct glyph_row
*last_text_row
;
9349 struct glyph_row
*last_reused_text_row
;
9350 struct glyph_row
*start_row
;
9351 int start_vpos
, min_y
, max_y
;
9353 /* Right now this function doesn't handle terminal frames. */
9354 if (!FRAME_WINDOW_P (f
))
9357 /* Can't do this if region may have changed. */
9358 if ((!NILP (Vtransient_mark_mode
)
9359 && !NILP (current_buffer
->mark_active
))
9360 || !NILP (w
->region_showing
)
9361 || !NILP (Vshow_trailing_whitespace
))
9364 /* If top-line visibility has changed, give up. */
9365 if (WINDOW_WANTS_HEADER_LINE_P (w
)
9366 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
9369 /* Give up if old or new display is scrolled vertically. We could
9370 make this function handle this, but right now it doesn't. */
9371 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9372 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row
))
9375 /* The variable new_start now holds the new window start. The old
9376 start `start' can be determined from the current matrix. */
9377 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
9378 start
= start_row
->start
.pos
;
9379 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
9381 /* Clear the desired matrix for the display below. */
9382 clear_glyph_matrix (w
->desired_matrix
);
9384 if (CHARPOS (new_start
) <= CHARPOS (start
))
9388 IF_DEBUG (debug_method_add (w
, "twu1"));
9390 /* Display up to a row that can be reused. The variable
9391 last_text_row is set to the last row displayed that displays
9393 start_display (&it
, w
, new_start
);
9394 first_row_y
= it
.current_y
;
9395 w
->cursor
.vpos
= -1;
9396 last_text_row
= last_reused_text_row
= NULL
;
9397 while (it
.current_y
< it
.last_visible_y
9398 && IT_CHARPOS (it
) < CHARPOS (start
)
9399 && !fonts_changed_p
)
9400 if (display_line (&it
))
9401 last_text_row
= it
.glyph_row
- 1;
9403 /* A value of current_y < last_visible_y means that we stopped
9404 at the previous window start, which in turn means that we
9405 have at least one reusable row. */
9406 if (it
.current_y
< it
.last_visible_y
)
9408 nrows_scrolled
= it
.vpos
;
9410 /* Find PT if not already found in the lines displayed. */
9411 if (w
->cursor
.vpos
< 0)
9413 int dy
= it
.current_y
- first_row_y
;
9415 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9416 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9418 if (PT
>= MATRIX_ROW_START_CHARPOS (row
)
9419 && PT
< MATRIX_ROW_END_CHARPOS (row
))
9421 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
9422 dy
, nrows_scrolled
);
9426 if (MATRIX_ROW_BOTTOM_Y (row
) + dy
>= it
.last_visible_y
)
9432 /* Give up if point was not found. This shouldn't
9433 happen often; not more often than with try_window
9435 if (w
->cursor
.vpos
< 0)
9437 clear_glyph_matrix (w
->desired_matrix
);
9442 /* Scroll the display. Do it before the current matrix is
9443 changed. The problem here is that update has not yet
9444 run, i.e. part of the current matrix is not up to date.
9445 scroll_run_hook will clear the cursor, and use the
9446 current matrix to get the height of the row the cursor is
9448 run
.current_y
= first_row_y
;
9449 run
.desired_y
= it
.current_y
;
9450 run
.height
= it
.last_visible_y
- it
.current_y
;
9452 && run
.current_y
!= run
.desired_y
)
9455 rif
->update_window_begin_hook (w
);
9456 rif
->scroll_run_hook (w
, &run
);
9457 rif
->update_window_end_hook (w
, 0);
9461 /* Shift current matrix down by nrows_scrolled lines. */
9462 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9463 rotate_matrix (w
->current_matrix
,
9465 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9468 /* Disable lines not reused. */
9469 for (i
= 0; i
< it
.vpos
; ++i
)
9470 MATRIX_ROW (w
->current_matrix
, i
)->enabled_p
= 0;
9472 /* Re-compute Y positions. */
9473 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
) + nrows_scrolled
;
9474 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9475 max_y
= it
.last_visible_y
;
9476 while (row
< bottom_row
)
9478 row
->y
= it
.current_y
;
9481 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9482 else if (row
->y
+ row
->height
> max_y
)
9484 = row
->height
- (row
->y
+ row
->height
- max_y
);
9486 row
->visible_height
= row
->height
;
9488 it
.current_y
+= row
->height
;
9491 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9492 last_reused_text_row
= row
;
9493 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
9499 /* Update window_end_pos etc.; last_reused_text_row is the last
9500 reused row from the current matrix containing text, if any.
9501 The value of last_text_row is the last displayed line
9503 if (last_reused_text_row
)
9505 w
->window_end_bytepos
9506 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
9507 XSETFASTINT (w
->window_end_pos
,
9508 Z
- MATRIX_ROW_END_CHARPOS (last_reused_text_row
));
9509 XSETFASTINT (w
->window_end_vpos
,
9510 MATRIX_ROW_VPOS (last_reused_text_row
,
9511 w
->current_matrix
));
9513 else if (last_text_row
)
9515 w
->window_end_bytepos
9516 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9517 XSETFASTINT (w
->window_end_pos
,
9518 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9519 XSETFASTINT (w
->window_end_vpos
,
9520 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9524 /* This window must be completely empty. */
9525 w
->window_end_bytepos
= 0;
9526 XSETFASTINT (w
->window_end_pos
, 0);
9527 XSETFASTINT (w
->window_end_vpos
, 0);
9529 w
->window_end_valid
= Qnil
;
9531 /* Update hint: don't try scrolling again in update_window. */
9532 w
->desired_matrix
->no_scrolling_p
= 1;
9535 debug_method_add (w
, "try_window_reusing_current_matrix 1");
9539 else if (CHARPOS (new_start
) > CHARPOS (start
))
9541 struct glyph_row
*pt_row
, *row
;
9542 struct glyph_row
*first_reusable_row
;
9543 struct glyph_row
*first_row_to_display
;
9545 int yb
= window_text_bottom_y (w
);
9547 IF_DEBUG (debug_method_add (w
, "twu2"));
9549 /* Find the row starting at new_start, if there is one. Don't
9550 reuse a partially visible line at the end. */
9551 first_reusable_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9552 while (first_reusable_row
->enabled_p
9553 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
9554 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9555 < CHARPOS (new_start
)))
9556 ++first_reusable_row
;
9558 /* Give up if there is no row to reuse. */
9559 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
9560 || !first_reusable_row
->enabled_p
9561 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
9562 != CHARPOS (new_start
)))
9565 /* We can reuse fully visible rows beginning with
9566 first_reusable_row to the end of the window. Set
9567 first_row_to_display to the first row that cannot be reused.
9568 Set pt_row to the row containing point, if there is any. */
9569 first_row_to_display
= first_reusable_row
;
9571 while (MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
)
9573 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
9574 && PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
))
9575 pt_row
= first_row_to_display
;
9577 ++first_row_to_display
;
9580 /* Start displaying at the start of first_row_to_display. */
9581 xassert (first_row_to_display
->y
< yb
);
9582 init_to_row_start (&it
, w
, first_row_to_display
);
9583 nrows_scrolled
= MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
);
9584 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
9586 it
.current_y
= first_row_to_display
->y
- first_reusable_row
->y
;
9588 /* Display lines beginning with first_row_to_display in the
9589 desired matrix. Set last_text_row to the last row displayed
9590 that displays text. */
9591 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
9593 w
->cursor
.vpos
= -1;
9594 last_text_row
= NULL
;
9595 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
9596 if (display_line (&it
))
9597 last_text_row
= it
.glyph_row
- 1;
9599 /* Give up If point isn't in a row displayed or reused. */
9600 if (w
->cursor
.vpos
< 0)
9602 clear_glyph_matrix (w
->desired_matrix
);
9606 /* If point is in a reused row, adjust y and vpos of the cursor
9610 w
->cursor
.vpos
-= MATRIX_ROW_VPOS (first_reusable_row
,
9612 w
->cursor
.y
-= first_reusable_row
->y
;
9615 /* Scroll the display. */
9616 run
.current_y
= first_reusable_row
->y
;
9617 run
.desired_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9618 run
.height
= it
.last_visible_y
- run
.current_y
;
9621 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9623 rif
->update_window_begin_hook (w
);
9624 rif
->scroll_run_hook (w
, &run
);
9625 rif
->update_window_end_hook (w
, 0);
9629 /* Adjust Y positions of reused rows. */
9630 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
9631 row
= first_reusable_row
;
9632 dy
= first_reusable_row
->y
;
9633 min_y
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w
);
9634 max_y
= it
.last_visible_y
;
9635 while (row
< first_row_to_display
)
9639 row
->visible_height
= row
->height
- (min_y
- row
->y
);
9640 else if (row
->y
+ row
->height
> max_y
)
9642 = row
->height
- (row
->y
+ row
->height
- max_y
);
9644 row
->visible_height
= row
->height
;
9648 /* Disable rows not reused. */
9649 while (row
< bottom_row
)
9655 /* Scroll the current matrix. */
9656 xassert (nrows_scrolled
> 0);
9657 rotate_matrix (w
->current_matrix
,
9659 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
9662 /* Adjust window end. A null value of last_text_row means that
9663 the window end is in reused rows which in turn means that
9664 only its vpos can have changed. */
9667 w
->window_end_bytepos
9668 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
9669 XSETFASTINT (w
->window_end_pos
,
9670 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
9671 XSETFASTINT (w
->window_end_vpos
,
9672 MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
));
9676 XSETFASTINT (w
->window_end_vpos
,
9677 XFASTINT (w
->window_end_vpos
) - nrows_scrolled
);
9680 w
->window_end_valid
= Qnil
;
9681 w
->desired_matrix
->no_scrolling_p
= 1;
9684 debug_method_add (w
, "try_window_reusing_current_matrix 2");
9694 /************************************************************************
9695 Window redisplay reusing current matrix when buffer has changed
9696 ************************************************************************/
9698 static struct glyph_row
*get_last_unchanged_at_beg_row
P_ ((struct window
*));
9699 static struct glyph_row
*get_first_unchanged_at_end_row
P_ ((struct window
*,
9701 static struct glyph_row
*
9702 find_last_row_displaying_text
P_ ((struct glyph_matrix
*, struct it
*,
9703 struct glyph_row
*));
9706 /* Return the last row in MATRIX displaying text. If row START is
9707 non-null, start searching with that row. IT gives the dimensions
9708 of the display. Value is null if matrix is empty; otherwise it is
9709 a pointer to the row found. */
9711 static struct glyph_row
*
9712 find_last_row_displaying_text (matrix
, it
, start
)
9713 struct glyph_matrix
*matrix
;
9715 struct glyph_row
*start
;
9717 struct glyph_row
*row
, *row_found
;
9719 /* Set row_found to the last row in IT->w's current matrix
9720 displaying text. The loop looks funny but think of partially
9723 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
9724 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9726 xassert (row
->enabled_p
);
9728 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
9737 /* Return the last row in the current matrix of W that is not affected
9738 by changes at the start of current_buffer that occurred since the
9739 last time W was redisplayed. Value is null if no such row exists.
9741 The global variable beg_unchanged has to contain the number of
9742 bytes unchanged at the start of current_buffer. BEG +
9743 beg_unchanged is the buffer position of the first changed byte in
9744 current_buffer. Characters at positions < BEG + beg_unchanged are
9745 at the same buffer positions as they were when the current matrix
9748 static struct glyph_row
*
9749 get_last_unchanged_at_beg_row (w
)
9752 int first_changed_pos
= BEG
+ BEG_UNCHANGED
;
9753 struct glyph_row
*row
;
9754 struct glyph_row
*row_found
= NULL
;
9755 int yb
= window_text_bottom_y (w
);
9757 /* Find the last row displaying unchanged text. */
9758 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9759 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
9760 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
)
9762 if (/* If row ends before first_changed_pos, it is unchanged,
9763 except in some case. */
9764 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
9765 /* When row ends in ZV and we write at ZV it is not
9767 && !row
->ends_at_zv_p
9768 /* When first_changed_pos is the end of a continued line,
9769 row is not unchanged because it may be no longer
9771 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
9772 && row
->continued_p
))
9775 /* Stop if last visible row. */
9776 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
9786 /* Find the first glyph row in the current matrix of W that is not
9787 affected by changes at the end of current_buffer since the last
9788 time the window was redisplayed. Return in *DELTA the number of
9789 chars by which buffer positions in unchanged text at the end of
9790 current_buffer must be adjusted. Return in *DELTA_BYTES the
9791 corresponding number of bytes. Value is null if no such row
9792 exists, i.e. all rows are affected by changes. */
9794 static struct glyph_row
*
9795 get_first_unchanged_at_end_row (w
, delta
, delta_bytes
)
9797 int *delta
, *delta_bytes
;
9799 struct glyph_row
*row
;
9800 struct glyph_row
*row_found
= NULL
;
9802 *delta
= *delta_bytes
= 0;
9804 /* A value of window_end_pos >= end_unchanged means that the window
9805 end is in the range of changed text. If so, there is no
9806 unchanged row at the end of W's current matrix. */
9807 xassert (!NILP (w
->window_end_valid
));
9808 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
9811 /* Set row to the last row in W's current matrix displaying text. */
9812 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
9814 /* If matrix is entirely empty, no unchanged row exists. */
9815 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
9817 /* The value of row is the last glyph row in the matrix having a
9818 meaningful buffer position in it. The end position of row
9819 corresponds to window_end_pos. This allows us to translate
9820 buffer positions in the current matrix to current buffer
9821 positions for characters not in changed text. */
9822 int Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
9823 int Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
9824 int last_unchanged_pos
, last_unchanged_pos_old
;
9825 struct glyph_row
*first_text_row
9826 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
9829 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
9831 /* Set last_unchanged_pos to the buffer position of the last
9832 character in the buffer that has not been changed. Z is the
9833 index + 1 of the last byte in current_buffer, i.e. by
9834 subtracting end_unchanged we get the index of the last
9835 unchanged character, and we have to add BEG to get its buffer
9837 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
9838 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
9840 /* Search backward from ROW for a row displaying a line that
9841 starts at a minimum position >= last_unchanged_pos_old. */
9842 while (row
>= first_text_row
)
9844 xassert (row
->enabled_p
);
9845 xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row
));
9847 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
9853 xassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
9858 /* Make sure that glyph rows in the current matrix of window W
9859 reference the same glyph memory as corresponding rows in the
9860 frame's frame matrix. This function is called after scrolling W's
9861 current matrix on a terminal frame in try_window_id and
9862 try_window_reusing_current_matrix. */
9865 sync_frame_with_window_matrix_rows (w
)
9868 struct frame
*f
= XFRAME (w
->frame
);
9869 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
9871 /* Preconditions: W must be a leaf window and full-width. Its frame
9872 must have a frame matrix. */
9873 xassert (NILP (w
->hchild
) && NILP (w
->vchild
));
9874 xassert (WINDOW_FULL_WIDTH_P (w
));
9875 xassert (!FRAME_WINDOW_P (f
));
9877 /* If W is a full-width window, glyph pointers in W's current matrix
9878 have, by definition, to be the same as glyph pointers in the
9879 corresponding frame matrix. */
9880 window_row
= w
->current_matrix
->rows
;
9881 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
9882 frame_row
= f
->current_matrix
->rows
+ XFASTINT (w
->top
);
9883 while (window_row
< window_row_end
)
9887 for (area
= LEFT_MARGIN_AREA
; area
<= LAST_AREA
; ++area
)
9888 frame_row
->glyphs
[area
] = window_row
->glyphs
[area
];
9890 /* Disable frame rows whose corresponding window rows have
9891 been disabled in try_window_id. */
9892 if (!window_row
->enabled_p
)
9893 frame_row
->enabled_p
= 0;
9895 ++window_row
, ++frame_row
;
9900 /* Find the glyph row in window W containing CHARPOS. Consider all
9901 rows between START and END (not inclusive). END null means search
9902 all rows to the end of the display area of W. Value is the row
9903 containing CHARPOS or null. */
9905 static struct glyph_row
*
9906 row_containing_pos (w
, charpos
, start
, end
)
9909 struct glyph_row
*start
, *end
;
9911 struct glyph_row
*row
= start
;
9914 /* If we happen to start on a header-line, skip that. */
9915 if (row
->mode_line_p
)
9918 if ((end
&& row
>= end
) || !row
->enabled_p
)
9921 last_y
= window_text_bottom_y (w
);
9923 while ((end
== NULL
|| row
< end
)
9924 && (MATRIX_ROW_END_CHARPOS (row
) < charpos
9925 /* The end position of a row equals the start
9926 position of the next row. If CHARPOS is there, we
9927 would rather display it in the next line, except
9928 when this line ends in ZV. */
9929 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
9930 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
9931 || !row
->ends_at_zv_p
)))
9932 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
9935 /* Give up if CHARPOS not found. */
9936 if ((end
&& row
>= end
)
9937 || charpos
< MATRIX_ROW_START_CHARPOS (row
)
9938 || charpos
> MATRIX_ROW_END_CHARPOS (row
))
9945 /* Try to redisplay window W by reusing its existing display. W's
9946 current matrix must be up to date when this function is called,
9947 i.e. window_end_valid must not be nil.
9951 1 if display has been updated
9952 0 if otherwise unsuccessful
9953 -1 if redisplay with same window start is known not to succeed
9955 The following steps are performed:
9957 1. Find the last row in the current matrix of W that is not
9958 affected by changes at the start of current_buffer. If no such row
9961 2. Find the first row in W's current matrix that is not affected by
9962 changes at the end of current_buffer. Maybe there is no such row.
9964 3. Display lines beginning with the row + 1 found in step 1 to the
9965 row found in step 2 or, if step 2 didn't find a row, to the end of
9968 4. If cursor is not known to appear on the window, give up.
9970 5. If display stopped at the row found in step 2, scroll the
9971 display and current matrix as needed.
9973 6. Maybe display some lines at the end of W, if we must. This can
9974 happen under various circumstances, like a partially visible line
9975 becoming fully visible, or because newly displayed lines are displayed
9976 in smaller font sizes.
9978 7. Update W's window end information. */
9980 /* Check that window end is what we expect it to be. */
9986 struct frame
*f
= XFRAME (w
->frame
);
9987 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
9988 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
9989 struct glyph_row
*last_unchanged_at_beg_row
;
9990 struct glyph_row
*first_unchanged_at_end_row
;
9991 struct glyph_row
*row
;
9992 struct glyph_row
*bottom_row
;
9995 int delta
= 0, delta_bytes
= 0, stop_pos
, dvpos
, dy
;
9996 struct text_pos start_pos
;
9998 int first_unchanged_at_end_vpos
= 0;
9999 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
10000 struct text_pos start
;
10002 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10004 /* Check pre-conditions. Window end must be valid, otherwise
10005 the current matrix would not be up to date. */
10006 xassert (!NILP (w
->window_end_valid
));
10007 xassert (FRAME_WINDOW_P (XFRAME (w
->frame
))
10008 || (line_ins_del_ok
&& WINDOW_FULL_WIDTH_P (w
)));
10010 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
10011 only if buffer has really changed. The reason is that the gap is
10012 initially at Z for freshly visited files. The code below would
10013 set end_unchanged to 0 in that case. */
10014 if (MODIFF
> SAVE_MODIFF
10015 /* This seems to happen sometimes after saving a buffer. */
10016 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
10018 if (GPT
- BEG
< BEG_UNCHANGED
)
10019 BEG_UNCHANGED
= GPT
- BEG
;
10020 if (Z
- GPT
< END_UNCHANGED
)
10021 END_UNCHANGED
= Z
- GPT
;
10024 /* If window starts after a line end, and the last change is in
10025 front of that newline, then changes don't affect the display.
10026 This case happens with stealth-fontification. */
10027 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
10028 if (CHARPOS (start
) > BEGV
10029 && Z
- END_UNCHANGED
< CHARPOS (start
) - 1
10030 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n'
10031 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10033 /* We have to update window end positions because the buffer's
10034 size has changed. */
10036 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10037 w
->window_end_bytepos
10038 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10042 /* Return quickly if changes are all below what is displayed in the
10043 window, and if PT is in the window. */
10044 if (BEG_UNCHANGED
> MATRIX_ROW_END_CHARPOS (row
)
10045 && PT
< MATRIX_ROW_END_CHARPOS (row
))
10047 /* We have to update window end positions because the buffer's
10048 size has changed. */
10050 = make_number (Z
- MATRIX_ROW_END_CHARPOS (row
));
10051 w
->window_end_bytepos
10052 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10056 /* Check that window start agrees with the start of the first glyph
10057 row in its current matrix. Check this after we know the window
10058 start is not in changed text, otherwise positions would not be
10060 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
10061 if (!TEXT_POS_EQUAL_P (start
, row
->start
.pos
))
10064 /* Compute the position at which we have to start displaying new
10065 lines. Some of the lines at the top of the window might be
10066 reusable because they are not displaying changed text. Find the
10067 last row in W's current matrix not affected by changes at the
10068 start of current_buffer. Value is null if changes start in the
10069 first line of window. */
10070 last_unchanged_at_beg_row
= get_last_unchanged_at_beg_row (w
);
10071 if (last_unchanged_at_beg_row
)
10073 init_to_row_end (&it
, w
, last_unchanged_at_beg_row
);
10074 start_pos
= it
.current
.pos
;
10076 /* Start displaying new lines in the desired matrix at the same
10077 vpos we would use in the current matrix, i.e. below
10078 last_unchanged_at_beg_row. */
10079 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
10081 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10082 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
10084 xassert (it
.hpos
== 0 && it
.current_x
== 0);
10088 /* There are no reusable lines at the start of the window.
10089 Start displaying in the first line. */
10090 start_display (&it
, w
, start
);
10091 start_pos
= it
.current
.pos
;
10094 /* Find the first row that is not affected by changes at the end of
10095 the buffer. Value will be null if there is no unchanged row, in
10096 which case we must redisplay to the end of the window. delta
10097 will be set to the value by which buffer positions beginning with
10098 first_unchanged_at_end_row have to be adjusted due to text
10100 first_unchanged_at_end_row
10101 = get_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
10102 IF_DEBUG (debug_delta
= delta
);
10103 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
10105 /* Set stop_pos to the buffer position up to which we will have to
10106 display new lines. If first_unchanged_at_end_row != NULL, this
10107 is the buffer position of the start of the line displayed in that
10108 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
10109 that we don't stop at a buffer position. */
10111 if (first_unchanged_at_end_row
)
10113 xassert (last_unchanged_at_beg_row
== NULL
10114 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
10116 /* If this is a continuation line, move forward to the next one
10117 that isn't. Changes in lines above affect this line.
10118 Caution: this may move first_unchanged_at_end_row to a row
10119 not displaying text. */
10120 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
10121 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10122 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10123 < it
.last_visible_y
))
10124 ++first_unchanged_at_end_row
;
10126 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
10127 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
10128 >= it
.last_visible_y
))
10129 first_unchanged_at_end_row
= NULL
;
10132 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
10134 first_unchanged_at_end_vpos
10135 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
10136 xassert (stop_pos
>= Z
- END_UNCHANGED
);
10139 else if (last_unchanged_at_beg_row
== NULL
)
10145 /* Either there is no unchanged row at the end, or the one we have
10146 now displays text. This is a necessary condition for the window
10147 end pos calculation at the end of this function. */
10148 xassert (first_unchanged_at_end_row
== NULL
10149 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
10151 debug_last_unchanged_at_beg_vpos
10152 = (last_unchanged_at_beg_row
10153 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
10155 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
10157 #endif /* GLYPH_DEBUG != 0 */
10160 /* Display new lines. Set last_text_row to the last new line
10161 displayed which has text on it, i.e. might end up as being the
10162 line where the window_end_vpos is. */
10163 w
->cursor
.vpos
= -1;
10164 last_text_row
= NULL
;
10165 overlay_arrow_seen
= 0;
10166 while (it
.current_y
< it
.last_visible_y
10167 && !fonts_changed_p
10168 && (first_unchanged_at_end_row
== NULL
10169 || IT_CHARPOS (it
) < stop_pos
))
10171 if (display_line (&it
))
10172 last_text_row
= it
.glyph_row
- 1;
10175 if (fonts_changed_p
)
10179 /* Compute differences in buffer positions, y-positions etc. for
10180 lines reused at the bottom of the window. Compute what we can
10182 if (first_unchanged_at_end_row
10183 /* No lines reused because we displayed everything up to the
10184 bottom of the window. */
10185 && it
.current_y
< it
.last_visible_y
)
10188 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
10190 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
10191 run
.current_y
= first_unchanged_at_end_row
->y
;
10192 run
.desired_y
= run
.current_y
+ dy
;
10193 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
10197 delta
= dvpos
= dy
= run
.current_y
= run
.desired_y
= run
.height
= 0;
10198 first_unchanged_at_end_row
= NULL
;
10200 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
10203 /* Find the cursor if not already found. We have to decide whether
10204 PT will appear on this window (it sometimes doesn't, but this is
10205 not a very frequent case.) This decision has to be made before
10206 the current matrix is altered. A value of cursor.vpos < 0 means
10207 that PT is either in one of the lines beginning at
10208 first_unchanged_at_end_row or below the window. Don't care for
10209 lines that might be displayed later at the window end; as
10210 mentioned, this is not a frequent case. */
10211 if (w
->cursor
.vpos
< 0)
10213 /* Cursor in unchanged rows at the top? */
10214 if (PT
< CHARPOS (start_pos
)
10215 && last_unchanged_at_beg_row
)
10217 row
= row_containing_pos (w
, PT
,
10218 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
10219 last_unchanged_at_beg_row
+ 1);
10220 xassert (row
&& row
<= last_unchanged_at_beg_row
);
10221 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
10224 /* Start from first_unchanged_at_end_row looking for PT. */
10225 else if (first_unchanged_at_end_row
)
10227 row
= row_containing_pos (w
, PT
- delta
,
10228 first_unchanged_at_end_row
, NULL
);
10230 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
10231 delta_bytes
, dy
, dvpos
);
10234 /* Give up if cursor was not found. */
10235 if (w
->cursor
.vpos
< 0)
10237 clear_glyph_matrix (w
->desired_matrix
);
10242 /* Don't let the cursor end in the scroll margins. */
10244 int this_scroll_margin
, cursor_height
;
10246 this_scroll_margin
= max (0, scroll_margin
);
10247 this_scroll_margin
= min (this_scroll_margin
,
10248 XFASTINT (w
->height
) / 4);
10249 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
10250 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
10252 if ((w
->cursor
.y
< this_scroll_margin
10253 && CHARPOS (start
) > BEGV
)
10254 /* Don't take scroll margin into account at the bottom because
10255 old redisplay didn't do it either. */
10256 || w
->cursor
.y
+ cursor_height
> it
.last_visible_y
)
10258 w
->cursor
.vpos
= -1;
10259 clear_glyph_matrix (w
->desired_matrix
);
10264 /* Scroll the display. Do it before changing the current matrix so
10265 that xterm.c doesn't get confused about where the cursor glyph is
10271 if (FRAME_WINDOW_P (f
))
10273 rif
->update_window_begin_hook (w
);
10274 rif
->scroll_run_hook (w
, &run
);
10275 rif
->update_window_end_hook (w
, 0);
10279 /* Terminal frame. In this case, dvpos gives the number of
10280 lines to scroll by; dvpos < 0 means scroll up. */
10281 int first_unchanged_at_end_vpos
10282 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
10283 int from
= XFASTINT (w
->top
) + first_unchanged_at_end_vpos
;
10284 int end
= XFASTINT (w
->top
) + window_internal_height (w
);
10286 /* Perform the operation on the screen. */
10289 /* Scroll last_unchanged_at_beg_row to the end of the
10290 window down dvpos lines. */
10291 set_terminal_window (end
);
10293 /* On dumb terminals delete dvpos lines at the end
10294 before inserting dvpos empty lines. */
10295 if (!scroll_region_ok
)
10296 ins_del_lines (end
- dvpos
, -dvpos
);
10298 /* Insert dvpos empty lines in front of
10299 last_unchanged_at_beg_row. */
10300 ins_del_lines (from
, dvpos
);
10302 else if (dvpos
< 0)
10304 /* Scroll up last_unchanged_at_beg_vpos to the end of
10305 the window to last_unchanged_at_beg_vpos - |dvpos|. */
10306 set_terminal_window (end
);
10308 /* Delete dvpos lines in front of
10309 last_unchanged_at_beg_vpos. ins_del_lines will set
10310 the cursor to the given vpos and emit |dvpos| delete
10312 ins_del_lines (from
+ dvpos
, dvpos
);
10314 /* On a dumb terminal insert dvpos empty lines at the
10316 if (!scroll_region_ok
)
10317 ins_del_lines (end
+ dvpos
, -dvpos
);
10320 set_terminal_window (0);
10326 /* Shift reused rows of the current matrix to the right position.
10327 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
10329 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
10330 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
10333 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
10334 bottom_vpos
, dvpos
);
10335 enable_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
10338 else if (dvpos
> 0)
10340 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
10341 bottom_vpos
, dvpos
);
10342 enable_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
10343 first_unchanged_at_end_vpos
+ dvpos
, 0);
10346 /* For frame-based redisplay, make sure that current frame and window
10347 matrix are in sync with respect to glyph memory. */
10348 if (!FRAME_WINDOW_P (f
))
10349 sync_frame_with_window_matrix_rows (w
);
10351 /* Adjust buffer positions in reused rows. */
10353 increment_glyph_matrix_buffer_positions (current_matrix
,
10354 first_unchanged_at_end_vpos
+ dvpos
,
10355 bottom_vpos
, delta
, delta_bytes
);
10357 /* Adjust Y positions. */
10359 shift_glyph_matrix (w
, current_matrix
,
10360 first_unchanged_at_end_vpos
+ dvpos
,
10363 if (first_unchanged_at_end_row
)
10364 first_unchanged_at_end_row
+= dvpos
;
10366 /* If scrolling up, there may be some lines to display at the end of
10368 last_text_row_at_end
= NULL
;
10371 /* Set last_row to the glyph row in the current matrix where the
10372 window end line is found. It has been moved up or down in
10373 the matrix by dvpos. */
10374 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
10375 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
10377 /* If last_row is the window end line, it should display text. */
10378 xassert (last_row
->displays_text_p
);
10380 /* If window end line was partially visible before, begin
10381 displaying at that line. Otherwise begin displaying with the
10382 line following it. */
10383 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
10385 init_to_row_start (&it
, w
, last_row
);
10386 it
.vpos
= last_vpos
;
10387 it
.current_y
= last_row
->y
;
10391 init_to_row_end (&it
, w
, last_row
);
10392 it
.vpos
= 1 + last_vpos
;
10393 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
10397 /* We may start in a continuation line. If so, we have to get
10398 the right continuation_lines_width and current_x. */
10399 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
10400 it
.hpos
= it
.current_x
= 0;
10402 /* Display the rest of the lines at the window end. */
10403 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
10404 while (it
.current_y
< it
.last_visible_y
10405 && !fonts_changed_p
)
10407 /* Is it always sure that the display agrees with lines in
10408 the current matrix? I don't think so, so we mark rows
10409 displayed invalid in the current matrix by setting their
10410 enabled_p flag to zero. */
10411 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
10412 if (display_line (&it
))
10413 last_text_row_at_end
= it
.glyph_row
- 1;
10417 /* Update window_end_pos and window_end_vpos. */
10418 if (first_unchanged_at_end_row
10419 && first_unchanged_at_end_row
->y
< it
.last_visible_y
10420 && !last_text_row_at_end
)
10422 /* Window end line if one of the preserved rows from the current
10423 matrix. Set row to the last row displaying text in current
10424 matrix starting at first_unchanged_at_end_row, after
10426 xassert (first_unchanged_at_end_row
->displays_text_p
);
10427 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
10428 first_unchanged_at_end_row
);
10429 xassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
10431 XSETFASTINT (w
->window_end_pos
, Z
- MATRIX_ROW_END_CHARPOS (row
));
10432 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
10433 XSETFASTINT (w
->window_end_vpos
,
10434 MATRIX_ROW_VPOS (row
, w
->current_matrix
));
10436 else if (last_text_row_at_end
)
10438 XSETFASTINT (w
->window_end_pos
,
10439 Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
));
10440 w
->window_end_bytepos
10441 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
10442 XSETFASTINT (w
->window_end_vpos
,
10443 MATRIX_ROW_VPOS (last_text_row_at_end
, desired_matrix
));
10445 else if (last_text_row
)
10447 /* We have displayed either to the end of the window or at the
10448 end of the window, i.e. the last row with text is to be found
10449 in the desired matrix. */
10450 XSETFASTINT (w
->window_end_pos
,
10451 Z
- MATRIX_ROW_END_CHARPOS (last_text_row
));
10452 w
->window_end_bytepos
10453 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
10454 XSETFASTINT (w
->window_end_vpos
,
10455 MATRIX_ROW_VPOS (last_text_row
, desired_matrix
));
10457 else if (first_unchanged_at_end_row
== NULL
10458 && last_text_row
== NULL
10459 && last_text_row_at_end
== NULL
)
10461 /* Displayed to end of window, but no line containing text was
10462 displayed. Lines were deleted at the end of the window. */
10464 int header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
10466 for (vpos
= XFASTINT (w
->window_end_vpos
); vpos
> 0; --vpos
)
10467 if ((w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10468 && w
->desired_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
)
10469 || (!w
->desired_matrix
->rows
[vpos
+ header_line_p
].enabled_p
10470 && w
->current_matrix
->rows
[vpos
+ header_line_p
].displays_text_p
))
10473 w
->window_end_vpos
= make_number (vpos
);
10478 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
10479 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
10481 /* Record that display has not been completed. */
10482 w
->window_end_valid
= Qnil
;
10483 w
->desired_matrix
->no_scrolling_p
= 1;
10489 /***********************************************************************
10490 More debugging support
10491 ***********************************************************************/
10495 void dump_glyph_row
P_ ((struct glyph_matrix
*, int, int));
10496 static void dump_glyph_matrix
P_ ((struct glyph_matrix
*, int));
10499 /* Dump the contents of glyph matrix MATRIX on stderr. If
10500 WITH_GLYPHS_P is non-zero, dump glyph contents as well. */
10503 dump_glyph_matrix (matrix
, with_glyphs_p
)
10504 struct glyph_matrix
*matrix
;
10508 for (i
= 0; i
< matrix
->nrows
; ++i
)
10509 dump_glyph_row (matrix
, i
, with_glyphs_p
);
10513 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
10514 WITH_GLYPH_SP non-zero means dump glyph contents, too. */
10517 dump_glyph_row (matrix
, vpos
, with_glyphs_p
)
10518 struct glyph_matrix
*matrix
;
10519 int vpos
, with_glyphs_p
;
10521 struct glyph_row
*row
;
10523 if (vpos
< 0 || vpos
>= matrix
->nrows
)
10526 row
= MATRIX_ROW (matrix
, vpos
);
10528 fprintf (stderr
, "Row Start End Used oEI><O\\CTZF X Y W\n");
10529 fprintf (stderr
, "=============================================\n");
10531 fprintf (stderr
, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d\n",
10532 row
- matrix
->rows
,
10533 MATRIX_ROW_START_CHARPOS (row
),
10534 MATRIX_ROW_END_CHARPOS (row
),
10535 row
->used
[TEXT_AREA
],
10536 row
->contains_overlapping_glyphs_p
,
10539 row
->truncated_on_left_p
,
10540 row
->truncated_on_right_p
,
10541 row
->overlay_arrow_p
,
10543 MATRIX_ROW_CONTINUATION_LINE_P (row
),
10544 row
->displays_text_p
,
10550 fprintf (stderr
, "%9d %5d\n", row
->start
.overlay_string_index
,
10551 row
->end
.overlay_string_index
);
10552 fprintf (stderr
, "%9d %5d\n",
10553 CHARPOS (row
->start
.string_pos
),
10554 CHARPOS (row
->end
.string_pos
));
10555 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
10556 row
->end
.dpvec_index
);
10560 struct glyph
*glyph
, *glyph_end
;
10561 int prev_had_glyphs_p
;
10563 glyph
= row
->glyphs
[TEXT_AREA
];
10564 glyph_end
= glyph
+ row
->used
[TEXT_AREA
];
10566 /* Glyph for a line end in text. */
10567 if (glyph
== glyph_end
&& glyph
->charpos
> 0)
10570 if (glyph
< glyph_end
)
10572 fprintf (stderr
, " Glyph Type Pos W Code C Face LR\n");
10573 prev_had_glyphs_p
= 1;
10576 prev_had_glyphs_p
= 0;
10578 while (glyph
< glyph_end
)
10580 if (glyph
->type
== CHAR_GLYPH
)
10583 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10584 glyph
- row
->glyphs
[TEXT_AREA
],
10587 glyph
->pixel_width
,
10589 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
10593 glyph
->left_box_line_p
,
10594 glyph
->right_box_line_p
);
10596 else if (glyph
->type
== STRETCH_GLYPH
)
10599 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10600 glyph
- row
->glyphs
[TEXT_AREA
],
10603 glyph
->pixel_width
,
10607 glyph
->left_box_line_p
,
10608 glyph
->right_box_line_p
);
10610 else if (glyph
->type
== IMAGE_GLYPH
)
10613 " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n",
10614 glyph
- row
->glyphs
[TEXT_AREA
],
10617 glyph
->pixel_width
,
10621 glyph
->left_box_line_p
,
10622 glyph
->right_box_line_p
);
10630 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
10631 Sdump_glyph_matrix
, 0, 1, "p",
10632 "Dump the current matrix of the selected window to stderr.\n\
10633 Shows contents of glyph row structures. With non-nil optional\n\
10634 parameter WITH-GLYPHS-P, dump glyphs as well.")
10637 struct window
*w
= XWINDOW (selected_window
);
10638 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10640 fprintf (stderr
, "PT = %d, BEGV = %d. ZV = %d\n",
10641 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
10642 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
10643 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
10644 fprintf (stderr
, "=============================================\n");
10645 dump_glyph_matrix (w
->current_matrix
, !NILP (with_glyphs_p
));
10650 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 1, "",
10651 "Dump glyph row ROW to stderr.")
10655 CHECK_NUMBER (row
, 0);
10656 dump_glyph_row (XWINDOW (selected_window
)->current_matrix
, XINT (row
), 1);
10661 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
,
10665 struct frame
*sf
= SELECTED_FRAME ();
10666 struct glyph_matrix
*m
= (XWINDOW (sf
->tool_bar_window
)
10668 dump_glyph_row (m
, 0, 1);
10673 DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle
,
10674 Strace_redisplay_toggle
, 0, 0, "",
10675 "Toggle tracing of redisplay.")
10678 trace_redisplay_p
= !trace_redisplay_p
;
10683 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, 1, "",
10684 "Print STRING to stderr.")
10686 Lisp_Object string
;
10688 CHECK_STRING (string
, 0);
10689 fprintf (stderr
, "%s", XSTRING (string
)->data
);
10693 #endif /* GLYPH_DEBUG */
10697 /***********************************************************************
10698 Building Desired Matrix Rows
10699 ***********************************************************************/
10701 /* Return a temporary glyph row holding the glyphs of an overlay
10702 arrow. Only used for non-window-redisplay windows. */
10704 static struct glyph_row
*
10705 get_overlay_arrow_glyph_row (w
)
10708 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
10709 struct buffer
*buffer
= XBUFFER (w
->buffer
);
10710 struct buffer
*old
= current_buffer
;
10711 unsigned char *arrow_string
= XSTRING (Voverlay_arrow_string
)->data
;
10712 int arrow_len
= XSTRING (Voverlay_arrow_string
)->size
;
10713 unsigned char *arrow_end
= arrow_string
+ arrow_len
;
10717 int n_glyphs_before
;
10719 set_buffer_temp (buffer
);
10720 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
10721 it
.glyph_row
->used
[TEXT_AREA
] = 0;
10722 SET_TEXT_POS (it
.position
, 0, 0);
10724 multibyte_p
= !NILP (buffer
->enable_multibyte_characters
);
10726 while (p
< arrow_end
)
10728 Lisp_Object face
, ilisp
;
10730 /* Get the next character. */
10732 it
.c
= string_char_and_length (p
, arrow_len
, &it
.len
);
10734 it
.c
= *p
, it
.len
= 1;
10737 /* Get its face. */
10738 XSETFASTINT (ilisp
, p
- arrow_string
);
10739 face
= Fget_text_property (ilisp
, Qface
, Voverlay_arrow_string
);
10740 it
.face_id
= compute_char_face (f
, it
.c
, face
);
10742 /* Compute its width, get its glyphs. */
10743 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
10744 SET_TEXT_POS (it
.position
, -1, -1);
10745 PRODUCE_GLYPHS (&it
);
10747 /* If this character doesn't fit any more in the line, we have
10748 to remove some glyphs. */
10749 if (it
.current_x
> it
.last_visible_x
)
10751 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
10756 set_buffer_temp (old
);
10757 return it
.glyph_row
;
10761 /* Insert truncation glyphs at the start of IT->glyph_row. Truncation
10762 glyphs are only inserted for terminal frames since we can't really
10763 win with truncation glyphs when partially visible glyphs are
10764 involved. Which glyphs to insert is determined by
10765 produce_special_glyphs. */
10768 insert_left_trunc_glyphs (it
)
10771 struct it truncate_it
;
10772 struct glyph
*from
, *end
, *to
, *toend
;
10774 xassert (!FRAME_WINDOW_P (it
->f
));
10776 /* Get the truncation glyphs. */
10778 truncate_it
.current_x
= 0;
10779 truncate_it
.face_id
= DEFAULT_FACE_ID
;
10780 truncate_it
.glyph_row
= &scratch_glyph_row
;
10781 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
10782 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
10783 truncate_it
.object
= make_number (0);
10784 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
10786 /* Overwrite glyphs from IT with truncation glyphs. */
10787 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
10788 end
= from
+ truncate_it
.glyph_row
->used
[TEXT_AREA
];
10789 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
10790 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
10795 /* There may be padding glyphs left over. Remove them. */
10797 while (from
< toend
&& CHAR_GLYPH_PADDING_P (*from
))
10799 while (from
< toend
)
10802 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
10806 /* Compute the pixel height and width of IT->glyph_row.
10808 Most of the time, ascent and height of a display line will be equal
10809 to the max_ascent and max_height values of the display iterator
10810 structure. This is not the case if
10812 1. We hit ZV without displaying anything. In this case, max_ascent
10813 and max_height will be zero.
10815 2. We have some glyphs that don't contribute to the line height.
10816 (The glyph row flag contributes_to_line_height_p is for future
10817 pixmap extensions).
10819 The first case is easily covered by using default values because in
10820 these cases, the line height does not really matter, except that it
10821 must not be zero. */
10824 compute_line_metrics (it
)
10827 struct glyph_row
*row
= it
->glyph_row
;
10830 if (FRAME_WINDOW_P (it
->f
))
10832 int i
, header_line_height
;
10834 /* The line may consist of one space only, that was added to
10835 place the cursor on it. If so, the row's height hasn't been
10837 if (row
->height
== 0)
10839 if (it
->max_ascent
+ it
->max_descent
== 0)
10840 it
->max_descent
= it
->max_phys_descent
= CANON_Y_UNIT (it
->f
);
10841 row
->ascent
= it
->max_ascent
;
10842 row
->height
= it
->max_ascent
+ it
->max_descent
;
10843 row
->phys_ascent
= it
->max_phys_ascent
;
10844 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
10847 /* Compute the width of this line. */
10848 row
->pixel_width
= row
->x
;
10849 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
10850 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
10852 xassert (row
->pixel_width
>= 0);
10853 xassert (row
->ascent
>= 0 && row
->height
> 0);
10855 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
10856 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
10858 /* If first line's physical ascent is larger than its logical
10859 ascent, use the physical ascent, and make the row taller.
10860 This makes accented characters fully visible. */
10861 if (row
== it
->w
->desired_matrix
->rows
10862 && row
->phys_ascent
> row
->ascent
)
10864 row
->height
+= row
->phys_ascent
- row
->ascent
;
10865 row
->ascent
= row
->phys_ascent
;
10868 /* Compute how much of the line is visible. */
10869 row
->visible_height
= row
->height
;
10871 header_line_height
= WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it
->w
);
10872 if (row
->y
< header_line_height
)
10873 row
->visible_height
-= header_line_height
- row
->y
;
10876 int max_y
= WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it
->w
);
10877 if (row
->y
+ row
->height
> max_y
)
10878 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
10883 row
->pixel_width
= row
->used
[TEXT_AREA
];
10884 row
->ascent
= row
->phys_ascent
= 0;
10885 row
->height
= row
->phys_height
= row
->visible_height
= 1;
10888 /* Compute a hash code for this row. */
10890 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
10891 for (i
= 0; i
< row
->used
[area
]; ++i
)
10892 row
->hash
= ((((row
->hash
<< 4) + (row
->hash
>> 24)) & 0x0fffffff)
10893 + row
->glyphs
[area
][i
].u
.val
10894 + row
->glyphs
[area
][i
].face_id
10895 + row
->glyphs
[area
][i
].padding_p
10896 + (row
->glyphs
[area
][i
].type
<< 2));
10898 it
->max_ascent
= it
->max_descent
= 0;
10899 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
10903 /* Append one space to the glyph row of iterator IT if doing a
10904 window-based redisplay. DEFAULT_FACE_P non-zero means let the
10905 space have the default face, otherwise let it have the same face as
10906 IT->face_id. Value is non-zero if a space was added.
10908 This function is called to make sure that there is always one glyph
10909 at the end of a glyph row that the cursor can be set on under
10910 window-systems. (If there weren't such a glyph we would not know
10911 how wide and tall a box cursor should be displayed).
10913 At the same time this space let's a nicely handle clearing to the
10914 end of the line if the row ends in italic text. */
10917 append_space (it
, default_face_p
)
10919 int default_face_p
;
10921 if (FRAME_WINDOW_P (it
->f
))
10923 int n
= it
->glyph_row
->used
[TEXT_AREA
];
10925 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
10926 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
10928 /* Save some values that must not be changed. */
10929 int saved_x
= it
->current_x
;
10930 struct text_pos saved_pos
;
10931 int saved_what
= it
->what
;
10932 int saved_face_id
= it
->face_id
;
10933 Lisp_Object saved_object
;
10936 saved_object
= it
->object
;
10937 saved_pos
= it
->position
;
10939 it
->what
= IT_CHARACTER
;
10940 bzero (&it
->position
, sizeof it
->position
);
10941 it
->object
= make_number (0);
10945 if (default_face_p
)
10946 it
->face_id
= DEFAULT_FACE_ID
;
10947 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
10948 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0);
10950 PRODUCE_GLYPHS (it
);
10952 it
->current_x
= saved_x
;
10953 it
->object
= saved_object
;
10954 it
->position
= saved_pos
;
10955 it
->what
= saved_what
;
10956 it
->face_id
= saved_face_id
;
10965 /* Extend the face of the last glyph in the text area of IT->glyph_row
10966 to the end of the display line. Called from display_line.
10967 If the glyph row is empty, add a space glyph to it so that we
10968 know the face to draw. Set the glyph row flag fill_line_p. */
10971 extend_face_to_end_of_line (it
)
10975 struct frame
*f
= it
->f
;
10977 /* If line is already filled, do nothing. */
10978 if (it
->current_x
>= it
->last_visible_x
)
10981 /* Face extension extends the background and box of IT->face_id
10982 to the end of the line. If the background equals the background
10983 of the frame, we haven't to do anything. */
10984 face
= FACE_FROM_ID (f
, it
->face_id
);
10985 if (FRAME_WINDOW_P (f
)
10986 && face
->box
== FACE_NO_BOX
10987 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
10991 /* Set the glyph row flag indicating that the face of the last glyph
10992 in the text area has to be drawn to the end of the text area. */
10993 it
->glyph_row
->fill_line_p
= 1;
10995 /* If current character of IT is not ASCII, make sure we have the
10996 ASCII face. This will be automatically undone the next time
10997 get_next_display_element returns a multibyte character. Note
10998 that the character will always be single byte in unibyte text. */
10999 if (!SINGLE_BYTE_CHAR_P (it
->c
))
11001 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0);
11004 if (FRAME_WINDOW_P (f
))
11006 /* If the row is empty, add a space with the current face of IT,
11007 so that we know which face to draw. */
11008 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
11010 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
11011 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= it
->face_id
;
11012 it
->glyph_row
->used
[TEXT_AREA
] = 1;
11017 /* Save some values that must not be changed. */
11018 int saved_x
= it
->current_x
;
11019 struct text_pos saved_pos
;
11020 Lisp_Object saved_object
;
11021 int saved_what
= it
->what
;
11023 saved_object
= it
->object
;
11024 saved_pos
= it
->position
;
11026 it
->what
= IT_CHARACTER
;
11027 bzero (&it
->position
, sizeof it
->position
);
11028 it
->object
= make_number (0);
11032 PRODUCE_GLYPHS (it
);
11034 while (it
->current_x
<= it
->last_visible_x
)
11035 PRODUCE_GLYPHS (it
);
11037 /* Don't count these blanks really. It would let us insert a left
11038 truncation glyph below and make us set the cursor on them, maybe. */
11039 it
->current_x
= saved_x
;
11040 it
->object
= saved_object
;
11041 it
->position
= saved_pos
;
11042 it
->what
= saved_what
;
11047 /* Value is non-zero if text starting at CHARPOS in current_buffer is
11048 trailing whitespace. */
11051 trailing_whitespace_p (charpos
)
11054 int bytepos
= CHAR_TO_BYTE (charpos
);
11057 while (bytepos
< ZV_BYTE
11058 && (c
= FETCH_CHAR (bytepos
),
11059 c
== ' ' || c
== '\t'))
11062 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
11064 if (bytepos
!= PT_BYTE
)
11071 /* Highlight trailing whitespace, if any, in ROW. */
11074 highlight_trailing_whitespace (f
, row
)
11076 struct glyph_row
*row
;
11078 int used
= row
->used
[TEXT_AREA
];
11082 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
11083 struct glyph
*glyph
= start
+ used
- 1;
11085 /* Skip over the space glyph inserted to display the
11086 cursor at the end of a line. */
11087 if (glyph
->type
== CHAR_GLYPH
11088 && glyph
->u
.ch
== ' '
11089 && INTEGERP (glyph
->object
))
11092 /* If last glyph is a space or stretch, and it's trailing
11093 whitespace, set the face of all trailing whitespace glyphs in
11094 IT->glyph_row to `trailing-whitespace'. */
11096 && BUFFERP (glyph
->object
)
11097 && (glyph
->type
== STRETCH_GLYPH
11098 || (glyph
->type
== CHAR_GLYPH
11099 && glyph
->u
.ch
== ' '))
11100 && trailing_whitespace_p (glyph
->charpos
))
11102 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
11104 while (glyph
>= start
11105 && BUFFERP (glyph
->object
)
11106 && (glyph
->type
== STRETCH_GLYPH
11107 || (glyph
->type
== CHAR_GLYPH
11108 && glyph
->u
.ch
== ' ')))
11109 (glyph
--)->face_id
= face_id
;
11115 /* Construct the glyph row IT->glyph_row in the desired matrix of
11116 IT->w from text at the current position of IT. See dispextern.h
11117 for an overview of struct it. Value is non-zero if
11118 IT->glyph_row displays text, as opposed to a line displaying ZV
11125 struct glyph_row
*row
= it
->glyph_row
;
11127 /* We always start displaying at hpos zero even if hscrolled. */
11128 xassert (it
->hpos
== 0 && it
->current_x
== 0);
11130 /* We must not display in a row that's not a text row. */
11131 xassert (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
11132 < it
->w
->desired_matrix
->nrows
);
11134 /* Is IT->w showing the region? */
11135 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? Qt
: Qnil
;
11137 /* Clear the result glyph row and enable it. */
11138 prepare_desired_row (row
);
11140 row
->y
= it
->current_y
;
11141 row
->start
= it
->current
;
11142 row
->continuation_lines_width
= it
->continuation_lines_width
;
11143 row
->displays_text_p
= 1;
11145 /* Arrange the overlays nicely for our purposes. Usually, we call
11146 display_line on only one line at a time, in which case this
11147 can't really hurt too much, or we call it on lines which appear
11148 one after another in the buffer, in which case all calls to
11149 recenter_overlay_lists but the first will be pretty cheap. */
11150 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
11152 /* Move over display elements that are not visible because we are
11153 hscrolled. This may stop at an x-position < IT->first_visible_x
11154 if the first glyph is partially visible or if we hit a line end. */
11155 if (it
->current_x
< it
->first_visible_x
)
11156 move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
11157 MOVE_TO_POS
| MOVE_TO_X
);
11159 /* Get the initial row height. This is either the height of the
11160 text hscrolled, if there is any, or zero. */
11161 row
->ascent
= it
->max_ascent
;
11162 row
->height
= it
->max_ascent
+ it
->max_descent
;
11163 row
->phys_ascent
= it
->max_phys_ascent
;
11164 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
11166 /* Loop generating characters. The loop is left with IT on the next
11167 character to display. */
11170 int n_glyphs_before
, hpos_before
, x_before
;
11173 /* Retrieve the next thing to display. Value is zero if end of
11175 if (!get_next_display_element (it
))
11177 /* Maybe add a space at the end of this line that is used to
11178 display the cursor there under X. Set the charpos of the
11179 first glyph of blank lines not corresponding to any text
11181 if ((append_space (it
, 1) && row
->used
[TEXT_AREA
] == 1)
11182 || row
->used
[TEXT_AREA
] == 0)
11184 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
11185 row
->displays_text_p
= 0;
11187 if (!NILP (XBUFFER (it
->w
->buffer
)->indicate_empty_lines
))
11188 row
->indicate_empty_line_p
= 1;
11191 it
->continuation_lines_width
= 0;
11192 row
->ends_at_zv_p
= 1;
11196 /* Now, get the metrics of what we want to display. This also
11197 generates glyphs in `row' (which is IT->glyph_row). */
11198 n_glyphs_before
= row
->used
[TEXT_AREA
];
11200 PRODUCE_GLYPHS (it
);
11202 /* If this display element was in marginal areas, continue with
11204 if (it
->area
!= TEXT_AREA
)
11206 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11207 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11208 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11209 row
->phys_height
= max (row
->phys_height
,
11210 it
->max_phys_ascent
+ it
->max_phys_descent
);
11211 set_iterator_to_next (it
);
11215 /* Does the display element fit on the line? If we truncate
11216 lines, we should draw past the right edge of the window. If
11217 we don't truncate, we want to stop so that we can display the
11218 continuation glyph before the right margin. If lines are
11219 continued, there are two possible strategies for characters
11220 resulting in more than 1 glyph (e.g. tabs): Display as many
11221 glyphs as possible in this line and leave the rest for the
11222 continuation line, or display the whole element in the next
11223 line. Original redisplay did the former, so we do it also. */
11224 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11225 hpos_before
= it
->hpos
;
11229 && it
->current_x
< it
->last_visible_x
)
11232 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11233 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11234 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11235 row
->phys_height
= max (row
->phys_height
,
11236 it
->max_phys_ascent
+ it
->max_phys_descent
);
11237 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
11238 row
->x
= x
- it
->first_visible_x
;
11243 struct glyph
*glyph
;
11245 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
11247 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11248 new_x
= x
+ glyph
->pixel_width
;
11250 if (/* Lines are continued. */
11251 !it
->truncate_lines_p
11252 && (/* Glyph doesn't fit on the line. */
11253 new_x
> it
->last_visible_x
11254 /* Or it fits exactly on a window system frame. */
11255 || (new_x
== it
->last_visible_x
11256 && FRAME_WINDOW_P (it
->f
))))
11258 /* End of a continued line. */
11261 || (new_x
== it
->last_visible_x
11262 && FRAME_WINDOW_P (it
->f
)))
11264 /* Current glyph fits exactly on the line. We
11265 must continue the line because we can't draw
11266 the cursor after the glyph. */
11267 row
->continued_p
= 1;
11268 it
->current_x
= new_x
;
11269 it
->continuation_lines_width
+= new_x
;
11271 if (i
== nglyphs
- 1)
11272 set_iterator_to_next (it
);
11276 /* Display element draws past the right edge of
11277 the window. Restore positions to values
11278 before the element. The next line starts
11279 with current_x before the glyph that could
11280 not be displayed, so that TAB works right. */
11281 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
11283 /* Display continuation glyphs. */
11284 if (!FRAME_WINDOW_P (it
->f
))
11285 produce_special_glyphs (it
, IT_CONTINUATION
);
11286 row
->continued_p
= 1;
11289 it
->continuation_lines_width
+= x
;
11293 else if (new_x
> it
->first_visible_x
)
11295 /* Increment number of glyphs actually displayed. */
11298 if (x
< it
->first_visible_x
)
11299 /* Glyph is partially visible, i.e. row starts at
11300 negative X position. */
11301 row
->x
= x
- it
->first_visible_x
;
11305 /* Glyph is completely off the left margin of the
11306 window. This should not happen because of the
11307 move_it_in_display_line at the start of
11313 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
11314 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
11315 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
11316 row
->phys_height
= max (row
->phys_height
,
11317 it
->max_phys_ascent
+ it
->max_phys_descent
);
11319 /* End of this display line if row is continued. */
11320 if (row
->continued_p
)
11324 /* Is this a line end? If yes, we're also done, after making
11325 sure that a non-default face is extended up to the right
11326 margin of the window. */
11327 if (ITERATOR_AT_END_OF_LINE_P (it
))
11329 int used_before
= row
->used
[TEXT_AREA
];
11331 /* Add a space at the end of the line that is used to
11332 display the cursor there. */
11333 append_space (it
, 0);
11335 /* Extend the face to the end of the line. */
11336 extend_face_to_end_of_line (it
);
11338 /* Make sure we have the position. */
11339 if (used_before
== 0)
11340 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
11342 /* Consume the line end. This skips over invisible lines. */
11343 set_iterator_to_next (it
);
11344 it
->continuation_lines_width
= 0;
11348 /* Proceed with next display element. Note that this skips
11349 over lines invisible because of selective display. */
11350 set_iterator_to_next (it
);
11352 /* If we truncate lines, we are done when the last displayed
11353 glyphs reach past the right margin of the window. */
11354 if (it
->truncate_lines_p
11355 && (FRAME_WINDOW_P (it
->f
)
11356 ? (it
->current_x
>= it
->last_visible_x
)
11357 : (it
->current_x
> it
->last_visible_x
)))
11359 /* Maybe add truncation glyphs. */
11360 if (!FRAME_WINDOW_P (it
->f
))
11362 --it
->glyph_row
->used
[TEXT_AREA
];
11363 produce_special_glyphs (it
, IT_TRUNCATION
);
11366 row
->truncated_on_right_p
= 1;
11367 it
->continuation_lines_width
= 0;
11368 reseat_at_next_visible_line_start (it
, 0);
11369 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
11370 it
->hpos
= hpos_before
;
11371 it
->current_x
= x_before
;
11376 /* If line is not empty and hscrolled, maybe insert truncation glyphs
11377 at the left window margin. */
11378 if (it
->first_visible_x
11379 && IT_CHARPOS (*it
) != MATRIX_ROW_START_CHARPOS (row
))
11381 if (!FRAME_WINDOW_P (it
->f
))
11382 insert_left_trunc_glyphs (it
);
11383 row
->truncated_on_left_p
= 1;
11386 /* If the start of this line is the overlay arrow-position, then
11387 mark this glyph row as the one containing the overlay arrow.
11388 This is clearly a mess with variable size fonts. It would be
11389 better to let it be displayed like cursors under X. */
11390 if (MARKERP (Voverlay_arrow_position
)
11391 && current_buffer
== XMARKER (Voverlay_arrow_position
)->buffer
11392 && (MATRIX_ROW_START_CHARPOS (row
)
11393 == marker_position (Voverlay_arrow_position
))
11394 && STRINGP (Voverlay_arrow_string
)
11395 && ! overlay_arrow_seen
)
11397 /* Overlay arrow in window redisplay is a bitmap. */
11398 if (!FRAME_WINDOW_P (it
->f
))
11400 struct glyph_row
*arrow_row
= get_overlay_arrow_glyph_row (it
->w
);
11401 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
11402 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
11403 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
11404 struct glyph
*p2
, *end
;
11406 /* Copy the arrow glyphs. */
11407 while (glyph
< arrow_end
)
11410 /* Throw away padding glyphs. */
11412 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
11413 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
11419 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
11423 overlay_arrow_seen
= 1;
11424 row
->overlay_arrow_p
= 1;
11427 /* Compute pixel dimensions of this line. */
11428 compute_line_metrics (it
);
11430 /* Remember the position at which this line ends. */
11431 row
->end
= it
->current
;
11433 /* Maybe set the cursor. If you change this, it's probably a good
11434 idea to also change the code in redisplay_window for cursor
11435 movement in an unchanged window. */
11436 if (it
->w
->cursor
.vpos
< 0
11437 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
11438 && MATRIX_ROW_END_CHARPOS (row
) >= PT
11439 && !(MATRIX_ROW_END_CHARPOS (row
) == PT
11440 && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)
11441 || !row
->ends_at_zv_p
)))
11442 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
11444 /* Highlight trailing whitespace. */
11445 if (!NILP (Vshow_trailing_whitespace
))
11446 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
11448 /* Prepare for the next line. This line starts horizontally at (X
11449 HPOS) = (0 0). Vertical positions are incremented. As a
11450 convenience for the caller, IT->glyph_row is set to the next
11452 it
->current_x
= it
->hpos
= 0;
11453 it
->current_y
+= row
->height
;
11456 return row
->displays_text_p
;
11461 /***********************************************************************
11463 ***********************************************************************/
11465 /* Redisplay the menu bar in the frame for window W.
11467 The menu bar of X frames that don't have X toolkit support is
11468 displayed in a special window W->frame->menu_bar_window.
11470 The menu bar of terminal frames is treated specially as far as
11471 glyph matrices are concerned. Menu bar lines are not part of
11472 windows, so the update is done directly on the frame matrix rows
11473 for the menu bar. */
11476 display_menu_bar (w
)
11479 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
11484 /* Don't do all this for graphical frames. */
11486 if (!NILP (Vwindow_system
))
11489 #ifdef USE_X_TOOLKIT
11494 #ifdef USE_X_TOOLKIT
11495 xassert (!FRAME_WINDOW_P (f
));
11496 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
11497 it
.first_visible_x
= 0;
11498 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11499 #else /* not USE_X_TOOLKIT */
11500 if (FRAME_WINDOW_P (f
))
11502 /* Menu bar lines are displayed in the desired matrix of the
11503 dummy window menu_bar_window. */
11504 struct window
*menu_w
;
11505 xassert (WINDOWP (f
->menu_bar_window
));
11506 menu_w
= XWINDOW (f
->menu_bar_window
);
11507 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
11509 it
.first_visible_x
= 0;
11510 it
.last_visible_x
= FRAME_WINDOW_WIDTH (f
) * CANON_X_UNIT (f
);
11514 /* This is a TTY frame, i.e. character hpos/vpos are used as
11516 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
11518 it
.first_visible_x
= 0;
11519 it
.last_visible_x
= FRAME_WIDTH (f
);
11521 #endif /* not USE_X_TOOLKIT */
11523 /* Clear all rows of the menu bar. */
11524 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
11526 struct glyph_row
*row
= it
.glyph_row
+ i
;
11527 clear_glyph_row (row
);
11528 row
->enabled_p
= 1;
11529 row
->full_width_p
= 1;
11532 /* Make the first line of the menu bar appear in reverse video. */
11533 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11535 /* Display all items of the menu bar. */
11536 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
11537 for (i
= 0; i
< XVECTOR (items
)->size
; i
+= 4)
11539 Lisp_Object string
;
11541 /* Stop at nil string. */
11542 string
= XVECTOR (items
)->contents
[i
+ 1];
11546 /* Remember where item was displayed. */
11547 XSETFASTINT (XVECTOR (items
)->contents
[i
+ 3], it
.hpos
);
11549 /* Display the item, pad with one space. */
11550 if (it
.current_x
< it
.last_visible_x
)
11551 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
11552 XSTRING (string
)->size
+ 1, 0, 0, -1);
11555 /* Fill out the line with spaces. */
11556 if (it
.current_x
< it
.last_visible_x
)
11557 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
11559 /* Compute the total height of the lines. */
11560 compute_line_metrics (&it
);
11565 /***********************************************************************
11567 ***********************************************************************/
11569 /* Display the mode and/or top line of window W. */
11572 display_mode_lines (w
)
11575 /* These will be set while the mode line specs are processed. */
11576 line_number_displayed
= 0;
11577 w
->column_number_displayed
= Qnil
;
11579 if (WINDOW_WANTS_MODELINE_P (w
))
11580 display_mode_line (w
, MODE_LINE_FACE_ID
,
11581 current_buffer
->mode_line_format
);
11583 if (WINDOW_WANTS_HEADER_LINE_P (w
))
11584 display_mode_line (w
, HEADER_LINE_FACE_ID
,
11585 current_buffer
->header_line_format
);
11589 /* Display mode or top line of window W. FACE_ID specifies which line
11590 to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID.
11591 FORMAT is the mode line format to display. */
11594 display_mode_line (w
, face_id
, format
)
11596 enum face_id face_id
;
11597 Lisp_Object format
;
11602 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
11603 prepare_desired_row (it
.glyph_row
);
11605 /* Temporarily make frame's keyboard the current kboard so that
11606 kboard-local variables in the mode_line_format will get the right
11608 push_frame_kboard (it
.f
);
11609 display_mode_element (&it
, 0, 0, 0, format
);
11610 pop_frame_kboard ();
11612 /* Fill up with spaces. */
11613 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
11615 compute_line_metrics (&it
);
11616 it
.glyph_row
->full_width_p
= 1;
11617 it
.glyph_row
->mode_line_p
= 1;
11618 it
.glyph_row
->inverse_p
= mode_line_inverse_video
!= 0;
11619 it
.glyph_row
->continued_p
= 0;
11620 it
.glyph_row
->truncated_on_left_p
= 0;
11621 it
.glyph_row
->truncated_on_right_p
= 0;
11623 /* Make a 3D mode-line have a shadow at its right end. */
11624 face
= FACE_FROM_ID (it
.f
, face_id
);
11625 extend_face_to_end_of_line (&it
);
11626 if (face
->box
!= FACE_NO_BOX
)
11628 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
11629 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
11630 last
->right_box_line_p
= 1;
11635 /* Contribute ELT to the mode line for window IT->w. How it
11636 translates into text depends on its data type.
11638 IT describes the display environment in which we display, as usual.
11640 DEPTH is the depth in recursion. It is used to prevent
11641 infinite recursion here.
11643 FIELD_WIDTH is the number of characters the display of ELT should
11644 occupy in the mode line, and PRECISION is the maximum number of
11645 characters to display from ELT's representation. See
11646 display_string for details. *
11648 Returns the hpos of the end of the text generated by ELT. */
11651 display_mode_element (it
, depth
, field_width
, precision
, elt
)
11654 int field_width
, precision
;
11657 int n
= 0, field
, prec
;
11665 switch (SWITCH_ENUM_CAST (XTYPE (elt
)))
11669 /* A string: output it and check for %-constructs within it. */
11671 unsigned char *this = XSTRING (elt
)->data
;
11672 unsigned char *lisp_string
= this;
11674 while ((precision
<= 0 || n
< precision
)
11676 && (frame_title_ptr
11677 || it
->current_x
< it
->last_visible_x
))
11679 unsigned char *last
= this;
11681 /* Advance to end of string or next format specifier. */
11682 while ((c
= *this++) != '\0' && c
!= '%')
11685 if (this - 1 != last
)
11687 /* Output to end of string or up to '%'. Field width
11688 is length of string. Don't output more than
11689 PRECISION allows us. */
11690 prec
= --this - last
;
11691 if (precision
> 0 && prec
> precision
- n
)
11692 prec
= precision
- n
;
11694 if (frame_title_ptr
)
11695 n
+= store_frame_title (last
, prec
, prec
);
11697 n
+= display_string (NULL
, elt
, Qnil
, 0, last
- lisp_string
,
11698 it
, 0, prec
, 0, -1);
11700 else /* c == '%' */
11702 unsigned char *percent_position
= this;
11704 /* Get the specified minimum width. Zero means
11707 while ((c
= *this++) >= '0' && c
<= '9')
11708 field
= field
* 10 + c
- '0';
11710 /* Don't pad beyond the total padding allowed. */
11711 if (field_width
- n
> 0 && field
> field_width
- n
)
11712 field
= field_width
- n
;
11714 /* Note that either PRECISION <= 0 or N < PRECISION. */
11715 prec
= precision
- n
;
11718 n
+= display_mode_element (it
, depth
, field
, prec
,
11719 Vglobal_mode_string
);
11722 unsigned char *spec
11723 = decode_mode_spec (it
->w
, c
, field
, prec
);
11725 if (frame_title_ptr
)
11726 n
+= store_frame_title (spec
, field
, prec
);
11730 = it
->glyph_row
->used
[TEXT_AREA
];
11732 = percent_position
- XSTRING (elt
)->data
;
11734 = display_string (spec
, Qnil
, elt
, charpos
, 0, it
,
11735 field
, prec
, 0, -1);
11737 /* Assign to the glyphs written above the
11738 string where the `%x' came from, position
11742 struct glyph
*glyph
11743 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
11747 for (i
= 0; i
< nwritten
; ++i
)
11749 glyph
[i
].object
= elt
;
11750 glyph
[i
].charpos
= charpos
;
11763 /* A symbol: process the value of the symbol recursively
11764 as if it appeared here directly. Avoid error if symbol void.
11765 Special case: if value of symbol is a string, output the string
11768 register Lisp_Object tem
;
11769 tem
= Fboundp (elt
);
11772 tem
= Fsymbol_value (elt
);
11773 /* If value is a string, output that string literally:
11774 don't check for % within it. */
11777 prec
= XSTRING (tem
)->size
;
11778 if (precision
> 0 && prec
> precision
- n
)
11779 prec
= precision
- n
;
11780 if (frame_title_ptr
)
11781 n
+= store_frame_title (XSTRING (tem
)->data
, -1, prec
);
11783 n
+= display_string (NULL
, tem
, Qnil
, 0, 0, it
,
11786 else if (!EQ (tem
, elt
))
11788 /* Give up right away for nil or t. */
11798 register Lisp_Object car
, tem
;
11800 /* A cons cell: three distinct cases.
11801 If first element is a string or a cons, process all the elements
11802 and effectively concatenate them.
11803 If first element is a negative number, truncate displaying cdr to
11804 at most that many characters. If positive, pad (with spaces)
11805 to at least that many characters.
11806 If first element is a symbol, process the cadr or caddr recursively
11807 according to whether the symbol's value is non-nil or nil. */
11809 if (EQ (car
, QCeval
) && CONSP (XCDR (elt
)))
11811 /* An element of the form (:eval FORM) means evaluate FORM
11812 and use the result as mode line elements. */
11813 struct gcpro gcpro1
;
11816 spec
= eval_form (XCAR (XCDR (elt
)));
11818 n
+= display_mode_element (it
, depth
, field_width
- n
,
11819 precision
- n
, spec
);
11822 else if (SYMBOLP (car
))
11824 tem
= Fboundp (car
);
11828 /* elt is now the cdr, and we know it is a cons cell.
11829 Use its car if CAR has a non-nil value. */
11832 tem
= Fsymbol_value (car
);
11839 /* Symbol's value is nil (or symbol is unbound)
11840 Get the cddr of the original list
11841 and if possible find the caddr and use that. */
11845 else if (!CONSP (elt
))
11850 else if (INTEGERP (car
))
11852 register int lim
= XINT (car
);
11856 /* Negative int means reduce maximum width. */
11857 if (precision
<= 0)
11860 precision
= min (precision
, -lim
);
11864 /* Padding specified. Don't let it be more than
11865 current maximum. */
11867 lim
= min (precision
, lim
);
11869 /* If that's more padding than already wanted, queue it.
11870 But don't reduce padding already specified even if
11871 that is beyond the current truncation point. */
11872 field_width
= max (lim
, field_width
);
11876 else if (STRINGP (car
) || CONSP (car
))
11878 register int limit
= 50;
11879 /* Limit is to protect against circular lists. */
11882 && (precision
<= 0 || n
< precision
))
11884 n
+= display_mode_element (it
, depth
, field_width
- n
,
11885 precision
- n
, XCAR (elt
));
11894 if (frame_title_ptr
)
11895 n
+= store_frame_title ("*invalid*", 0, precision
- n
);
11897 n
+= display_string ("*invalid*", Qnil
, Qnil
, 0, 0, it
, 0,
11898 precision
- n
, 0, 0);
11902 /* Pad to FIELD_WIDTH. */
11903 if (field_width
> 0 && n
< field_width
)
11905 if (frame_title_ptr
)
11906 n
+= store_frame_title ("", field_width
- n
, 0);
11908 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
11916 /* Write a null-terminated, right justified decimal representation of
11917 the positive integer D to BUF using a minimal field width WIDTH. */
11920 pint2str (buf
, width
, d
)
11921 register char *buf
;
11922 register int width
;
11925 register char *p
= buf
;
11933 *p
++ = d
% 10 + '0';
11938 for (width
-= (int) (p
- buf
); width
> 0; --width
)
11949 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
11950 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
11951 type of CODING_SYSTEM. Return updated pointer into BUF. */
11953 static unsigned char invalid_eol_type
[] = "(*invalid*)";
11956 decode_mode_spec_coding (coding_system
, buf
, eol_flag
)
11957 Lisp_Object coding_system
;
11958 register char *buf
;
11962 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
11963 unsigned char *eol_str
;
11965 /* The EOL conversion we are using. */
11966 Lisp_Object eoltype
;
11968 val
= Fget (coding_system
, Qcoding_system
);
11970 if (!VECTORP (val
)) /* Not yet decided. */
11975 eoltype
= eol_mnemonic_undecided
;
11976 /* Don't mention EOL conversion if it isn't decided. */
11980 Lisp_Object eolvalue
;
11982 eolvalue
= Fget (coding_system
, Qeol_type
);
11985 *buf
++ = XFASTINT (XVECTOR (val
)->contents
[1]);
11989 /* The EOL conversion that is normal on this system. */
11991 if (NILP (eolvalue
)) /* Not yet decided. */
11992 eoltype
= eol_mnemonic_undecided
;
11993 else if (VECTORP (eolvalue
)) /* Not yet decided. */
11994 eoltype
= eol_mnemonic_undecided
;
11995 else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */
11996 eoltype
= (XFASTINT (eolvalue
) == 0
11997 ? eol_mnemonic_unix
11998 : (XFASTINT (eolvalue
) == 1
11999 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
12005 /* Mention the EOL conversion if it is not the usual one. */
12006 if (STRINGP (eoltype
))
12008 eol_str
= XSTRING (eoltype
)->data
;
12009 eol_str_len
= XSTRING (eoltype
)->size
;
12011 else if (INTEGERP (eoltype
)
12012 && CHAR_VALID_P (XINT (eoltype
), 0))
12014 eol_str
= (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH
);
12015 eol_str_len
= CHAR_STRING (XINT (eoltype
), eol_str
);
12019 eol_str
= invalid_eol_type
;
12020 eol_str_len
= sizeof (invalid_eol_type
) - 1;
12022 bcopy (eol_str
, buf
, eol_str_len
);
12023 buf
+= eol_str_len
;
12029 /* Return a string for the output of a mode line %-spec for window W,
12030 generated by character C. PRECISION >= 0 means don't return a
12031 string longer than that value. FIELD_WIDTH > 0 means pad the
12032 string returned with spaces to that value. */
12034 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
12037 decode_mode_spec (w
, c
, field_width
, precision
)
12040 int field_width
, precision
;
12043 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
12044 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
12045 struct buffer
*b
= XBUFFER (w
->buffer
);
12052 if (!NILP (b
->read_only
))
12054 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12059 /* This differs from %* only for a modified read-only buffer. */
12060 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12062 if (!NILP (b
->read_only
))
12067 /* This differs from %* in ignoring read-only-ness. */
12068 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
12080 if (command_loop_level
> 5)
12082 p
= decode_mode_spec_buf
;
12083 for (i
= 0; i
< command_loop_level
; i
++)
12086 return decode_mode_spec_buf
;
12094 if (command_loop_level
> 5)
12096 p
= decode_mode_spec_buf
;
12097 for (i
= 0; i
< command_loop_level
; i
++)
12100 return decode_mode_spec_buf
;
12107 /* Let lots_of_dashes be a string of infinite length. */
12108 if (field_width
<= 0
12109 || field_width
> sizeof (lots_of_dashes
))
12111 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
12112 decode_mode_spec_buf
[i
] = '-';
12113 decode_mode_spec_buf
[i
] = '\0';
12114 return decode_mode_spec_buf
;
12117 return lots_of_dashes
;
12126 int col
= current_column ();
12127 XSETFASTINT (w
->column_number_displayed
, col
);
12128 pint2str (decode_mode_spec_buf
, field_width
, col
);
12129 return decode_mode_spec_buf
;
12133 /* %F displays the frame name. */
12134 if (!NILP (f
->title
))
12135 return (char *) XSTRING (f
->title
)->data
;
12136 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
12137 return (char *) XSTRING (f
->name
)->data
;
12146 int startpos
= XMARKER (w
->start
)->charpos
;
12147 int startpos_byte
= marker_byte_position (w
->start
);
12148 int line
, linepos
, linepos_byte
, topline
;
12150 int height
= XFASTINT (w
->height
);
12152 /* If we decided that this buffer isn't suitable for line numbers,
12153 don't forget that too fast. */
12154 if (EQ (w
->base_line_pos
, w
->buffer
))
12156 /* But do forget it, if the window shows a different buffer now. */
12157 else if (BUFFERP (w
->base_line_pos
))
12158 w
->base_line_pos
= Qnil
;
12160 /* If the buffer is very big, don't waste time. */
12161 if (BUF_ZV (b
) - BUF_BEGV (b
) > line_number_display_limit
)
12163 w
->base_line_pos
= Qnil
;
12164 w
->base_line_number
= Qnil
;
12168 if (!NILP (w
->base_line_number
)
12169 && !NILP (w
->base_line_pos
)
12170 && XFASTINT (w
->base_line_pos
) <= startpos
)
12172 line
= XFASTINT (w
->base_line_number
);
12173 linepos
= XFASTINT (w
->base_line_pos
);
12174 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
12179 linepos
= BUF_BEGV (b
);
12180 linepos_byte
= BUF_BEGV_BYTE (b
);
12183 /* Count lines from base line to window start position. */
12184 nlines
= display_count_lines (linepos
, linepos_byte
,
12188 topline
= nlines
+ line
;
12190 /* Determine a new base line, if the old one is too close
12191 or too far away, or if we did not have one.
12192 "Too close" means it's plausible a scroll-down would
12193 go back past it. */
12194 if (startpos
== BUF_BEGV (b
))
12196 XSETFASTINT (w
->base_line_number
, topline
);
12197 XSETFASTINT (w
->base_line_pos
, BUF_BEGV (b
));
12199 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
12200 || linepos
== BUF_BEGV (b
))
12202 int limit
= BUF_BEGV (b
);
12203 int limit_byte
= BUF_BEGV_BYTE (b
);
12205 int distance
= (height
* 2 + 30) * line_number_display_limit_width
;
12207 if (startpos
- distance
> limit
)
12209 limit
= startpos
- distance
;
12210 limit_byte
= CHAR_TO_BYTE (limit
);
12213 nlines
= display_count_lines (startpos
, startpos_byte
,
12215 - (height
* 2 + 30),
12217 /* If we couldn't find the lines we wanted within
12218 line_number_display_limit_width chars per line,
12219 give up on line numbers for this window. */
12220 if (position
== limit_byte
&& limit
== startpos
- distance
)
12222 w
->base_line_pos
= w
->buffer
;
12223 w
->base_line_number
= Qnil
;
12227 XSETFASTINT (w
->base_line_number
, topline
- nlines
);
12228 XSETFASTINT (w
->base_line_pos
, BYTE_TO_CHAR (position
));
12231 /* Now count lines from the start pos to point. */
12232 nlines
= display_count_lines (startpos
, startpos_byte
,
12233 PT_BYTE
, PT
, &junk
);
12235 /* Record that we did display the line number. */
12236 line_number_displayed
= 1;
12238 /* Make the string to show. */
12239 pint2str (decode_mode_spec_buf
, field_width
, topline
+ nlines
);
12240 return decode_mode_spec_buf
;
12243 char* p
= decode_mode_spec_buf
;
12244 int pad
= field_width
- 2;
12249 return decode_mode_spec_buf
;
12255 obj
= b
->mode_name
;
12259 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
12265 int pos
= marker_position (w
->start
);
12266 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12268 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
12270 if (pos
<= BUF_BEGV (b
))
12275 else if (pos
<= BUF_BEGV (b
))
12279 if (total
> 1000000)
12280 /* Do it differently for a large value, to avoid overflow. */
12281 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12283 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12284 /* We can't normally display a 3-digit number,
12285 so get us a 2-digit number that is close. */
12288 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12289 return decode_mode_spec_buf
;
12293 /* Display percentage of size above the bottom of the screen. */
12296 int toppos
= marker_position (w
->start
);
12297 int botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
12298 int total
= BUF_ZV (b
) - BUF_BEGV (b
);
12300 if (botpos
>= BUF_ZV (b
))
12302 if (toppos
<= BUF_BEGV (b
))
12309 if (total
> 1000000)
12310 /* Do it differently for a large value, to avoid overflow. */
12311 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
12313 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
12314 /* We can't normally display a 3-digit number,
12315 so get us a 2-digit number that is close. */
12318 if (toppos
<= BUF_BEGV (b
))
12319 sprintf (decode_mode_spec_buf
, "Top%2d%%", total
);
12321 sprintf (decode_mode_spec_buf
, "%2d%%", total
);
12322 return decode_mode_spec_buf
;
12327 /* status of process */
12328 obj
= Fget_buffer_process (w
->buffer
);
12330 return "no process";
12331 #ifdef subprocesses
12332 obj
= Fsymbol_name (Fprocess_status (obj
));
12336 case 't': /* indicate TEXT or BINARY */
12337 #ifdef MODE_LINE_BINARY_TEXT
12338 return MODE_LINE_BINARY_TEXT (b
);
12344 /* coding-system (not including end-of-line format) */
12346 /* coding-system (including end-of-line type) */
12348 int eol_flag
= (c
== 'Z');
12349 char *p
= decode_mode_spec_buf
;
12351 if (! FRAME_WINDOW_P (f
))
12353 /* No need to mention EOL here--the terminal never needs
12354 to do EOL conversion. */
12355 p
= decode_mode_spec_coding (keyboard_coding
.symbol
, p
, 0);
12356 p
= decode_mode_spec_coding (terminal_coding
.symbol
, p
, 0);
12358 p
= decode_mode_spec_coding (b
->buffer_file_coding_system
,
12361 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
12362 #ifdef subprocesses
12363 obj
= Fget_buffer_process (Fcurrent_buffer ());
12364 if (PROCESSP (obj
))
12366 p
= decode_mode_spec_coding (XPROCESS (obj
)->decode_coding_system
,
12368 p
= decode_mode_spec_coding (XPROCESS (obj
)->encode_coding_system
,
12371 #endif /* subprocesses */
12374 return decode_mode_spec_buf
;
12379 return (char *) XSTRING (obj
)->data
;
12385 /* Count up to COUNT lines starting from START / START_BYTE.
12386 But don't go beyond LIMIT_BYTE.
12387 Return the number of lines thus found (always nonnegative).
12389 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
12392 display_count_lines (start
, start_byte
, limit_byte
, count
, byte_pos_ptr
)
12393 int start
, start_byte
, limit_byte
, count
;
12396 register unsigned char *cursor
;
12397 unsigned char *base
;
12399 register int ceiling
;
12400 register unsigned char *ceiling_addr
;
12401 int orig_count
= count
;
12403 /* If we are not in selective display mode,
12404 check only for newlines. */
12405 int selective_display
= (!NILP (current_buffer
->selective_display
)
12406 && !INTEGERP (current_buffer
->selective_display
));
12410 while (start_byte
< limit_byte
)
12412 ceiling
= BUFFER_CEILING_OF (start_byte
);
12413 ceiling
= min (limit_byte
- 1, ceiling
);
12414 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
12415 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
12418 if (selective_display
)
12419 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
12422 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
12425 if (cursor
!= ceiling_addr
)
12429 start_byte
+= cursor
- base
+ 1;
12430 *byte_pos_ptr
= start_byte
;
12434 if (++cursor
== ceiling_addr
)
12440 start_byte
+= cursor
- base
;
12445 while (start_byte
> limit_byte
)
12447 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
12448 ceiling
= max (limit_byte
, ceiling
);
12449 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
12450 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
12453 if (selective_display
)
12454 while (--cursor
!= ceiling_addr
12455 && *cursor
!= '\n' && *cursor
!= 015)
12458 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
12461 if (cursor
!= ceiling_addr
)
12465 start_byte
+= cursor
- base
+ 1;
12466 *byte_pos_ptr
= start_byte
;
12467 /* When scanning backwards, we should
12468 not count the newline posterior to which we stop. */
12469 return - orig_count
- 1;
12475 /* Here we add 1 to compensate for the last decrement
12476 of CURSOR, which took it past the valid range. */
12477 start_byte
+= cursor
- base
+ 1;
12481 *byte_pos_ptr
= limit_byte
;
12484 return - orig_count
+ count
;
12485 return orig_count
- count
;
12491 /***********************************************************************
12493 ***********************************************************************/
12495 /* Display a NUL-terminated string, starting with index START.
12497 If STRING is non-null, display that C string. Otherwise, the Lisp
12498 string LISP_STRING is displayed.
12500 If FACE_STRING is not nil, FACE_STRING_POS is a position in
12501 FACE_STRING. Display STRING or LISP_STRING with the face at
12502 FACE_STRING_POS in FACE_STRING:
12504 Display the string in the environment given by IT, but use the
12505 standard display table, temporarily.
12507 FIELD_WIDTH is the minimum number of output glyphs to produce.
12508 If STRING has fewer characters than FIELD_WIDTH, pad to the right
12509 with spaces. If STRING has more characters, more than FIELD_WIDTH
12510 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
12512 PRECISION is the maximum number of characters to output from
12513 STRING. PRECISION < 0 means don't truncate the string.
12515 This is roughly equivalent to printf format specifiers:
12517 FIELD_WIDTH PRECISION PRINTF
12518 ----------------------------------------
12524 MULTIBYTE zero means do not display multibyte chars, > 0 means do
12525 display them, and < 0 means obey the current buffer's value of
12526 enable_multibyte_characters.
12528 Value is the number of glyphs produced. */
12531 display_string (string
, lisp_string
, face_string
, face_string_pos
,
12532 start
, it
, field_width
, precision
, max_x
, multibyte
)
12533 unsigned char *string
;
12534 Lisp_Object lisp_string
;
12535 Lisp_Object face_string
;
12536 int face_string_pos
;
12539 int field_width
, precision
, max_x
;
12542 int hpos_at_start
= it
->hpos
;
12543 int saved_face_id
= it
->face_id
;
12544 struct glyph_row
*row
= it
->glyph_row
;
12546 /* Initialize the iterator IT for iteration over STRING beginning
12547 with index START. We assume that IT may be modified here (which
12548 means that display_line has to do something when displaying a
12549 mini-buffer prompt, which it does). */
12550 reseat_to_string (it
, string
, lisp_string
, start
,
12551 precision
, field_width
, multibyte
);
12553 /* If displaying STRING, set up the face of the iterator
12554 from LISP_STRING, if that's given. */
12555 if (STRINGP (face_string
))
12561 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
12562 0, it
->region_beg_charpos
,
12563 it
->region_end_charpos
,
12564 &endptr
, it
->base_face_id
);
12565 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
12566 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
12569 /* Set max_x to the maximum allowed X position. Don't let it go
12570 beyond the right edge of the window. */
12572 max_x
= it
->last_visible_x
;
12574 max_x
= min (max_x
, it
->last_visible_x
);
12576 /* Skip over display elements that are not visible. because IT->w is
12578 if (it
->current_x
< it
->first_visible_x
)
12579 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
12580 MOVE_TO_POS
| MOVE_TO_X
);
12582 row
->ascent
= it
->max_ascent
;
12583 row
->height
= it
->max_ascent
+ it
->max_descent
;
12584 row
->phys_ascent
= it
->max_phys_ascent
;
12585 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
12587 /* This condition is for the case that we are called with current_x
12588 past last_visible_x. */
12589 while (it
->current_x
< max_x
)
12591 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
12593 /* Get the next display element. */
12594 if (!get_next_display_element (it
))
12597 /* Produce glyphs. */
12598 x_before
= it
->current_x
;
12599 n_glyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
12600 PRODUCE_GLYPHS (it
);
12602 nglyphs
= it
->glyph_row
->used
[TEXT_AREA
] - n_glyphs_before
;
12605 while (i
< nglyphs
)
12607 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12609 if (!it
->truncate_lines_p
12610 && x
+ glyph
->pixel_width
> max_x
)
12612 /* End of continued line or max_x reached. */
12613 it
->glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
12617 else if (x
+ glyph
->pixel_width
> it
->first_visible_x
)
12619 /* Glyph is at least partially visible. */
12621 if (x
< it
->first_visible_x
)
12622 it
->glyph_row
->x
= x
- it
->first_visible_x
;
12626 /* Glyph is off the left margin of the display area.
12627 Should not happen. */
12631 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
12632 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
12633 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
12634 row
->phys_height
= max (row
->phys_height
,
12635 it
->max_phys_ascent
+ it
->max_phys_descent
);
12636 x
+= glyph
->pixel_width
;
12640 /* Stop if max_x reached. */
12644 /* Stop at line ends. */
12645 if (ITERATOR_AT_END_OF_LINE_P (it
))
12647 it
->continuation_lines_width
= 0;
12651 set_iterator_to_next (it
);
12653 /* Stop if truncating at the right edge. */
12654 if (it
->truncate_lines_p
12655 && it
->current_x
>= it
->last_visible_x
)
12657 /* Add truncation mark, but don't do it if the line is
12658 truncated at a padding space. */
12659 if (IT_CHARPOS (*it
) < it
->string_nchars
)
12661 if (!FRAME_WINDOW_P (it
->f
))
12662 produce_special_glyphs (it
, IT_TRUNCATION
);
12663 it
->glyph_row
->truncated_on_right_p
= 1;
12669 /* Maybe insert a truncation at the left. */
12670 if (it
->first_visible_x
12671 && IT_CHARPOS (*it
) > 0)
12673 if (!FRAME_WINDOW_P (it
->f
))
12674 insert_left_trunc_glyphs (it
);
12675 it
->glyph_row
->truncated_on_left_p
= 1;
12678 it
->face_id
= saved_face_id
;
12680 /* Value is number of columns displayed. */
12681 return it
->hpos
- hpos_at_start
;
12686 /* This is like a combination of memq and assq. Return 1 if PROPVAL
12687 appears as an element of LIST or as the car of an element of LIST.
12688 If PROPVAL is a list, compare each element against LIST in that
12689 way, and return 1 if any element of PROPVAL is found in LIST.
12690 Otherwise return 0. This function cannot quit. */
12693 invisible_p (propval
, list
)
12694 register Lisp_Object propval
;
12697 register Lisp_Object tail
, proptail
;
12698 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12700 register Lisp_Object tem
;
12702 if (EQ (propval
, tem
))
12704 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12707 if (CONSP (propval
))
12708 for (proptail
= propval
; CONSP (proptail
);
12709 proptail
= XCDR (proptail
))
12711 Lisp_Object propelt
;
12712 propelt
= XCAR (proptail
);
12713 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12715 register Lisp_Object tem
;
12717 if (EQ (propelt
, tem
))
12719 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12727 /* Return 1 if PROPVAL appears as the car of an element of LIST and
12728 the cdr of that element is non-nil. If PROPVAL is a list, check
12729 each element of PROPVAL in that way, and the first time some
12730 element is found, return 1 if the cdr of that element is non-nil.
12731 Otherwise return 0. This function cannot quit. */
12734 invisible_ellipsis_p (propval
, list
)
12735 register Lisp_Object propval
;
12738 register Lisp_Object tail
, proptail
;
12740 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12742 register Lisp_Object tem
;
12744 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
12745 return ! NILP (XCDR (tem
));
12748 if (CONSP (propval
))
12749 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
12751 Lisp_Object propelt
;
12752 propelt
= XCAR (proptail
);
12753 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
12755 register Lisp_Object tem
;
12757 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
12758 return ! NILP (XCDR (tem
));
12767 /***********************************************************************
12769 ***********************************************************************/
12774 Vwith_echo_area_save_vector
= Qnil
;
12775 staticpro (&Vwith_echo_area_save_vector
);
12777 Vmessage_stack
= Qnil
;
12778 staticpro (&Vmessage_stack
);
12780 Qinhibit_redisplay
= intern ("inhibit-redisplay");
12781 staticpro (&Qinhibit_redisplay
);
12784 defsubr (&Sdump_glyph_matrix
);
12785 defsubr (&Sdump_glyph_row
);
12786 defsubr (&Sdump_tool_bar_row
);
12787 defsubr (&Strace_redisplay_toggle
);
12788 defsubr (&Strace_to_stderr
);
12791 staticpro (&Qmenu_bar_update_hook
);
12792 Qmenu_bar_update_hook
= intern ("menu-bar-update-hook");
12794 staticpro (&Qoverriding_terminal_local_map
);
12795 Qoverriding_terminal_local_map
= intern ("overriding-terminal-local-map");
12797 staticpro (&Qoverriding_local_map
);
12798 Qoverriding_local_map
= intern ("overriding-local-map");
12800 staticpro (&Qwindow_scroll_functions
);
12801 Qwindow_scroll_functions
= intern ("window-scroll-functions");
12803 staticpro (&Qredisplay_end_trigger_functions
);
12804 Qredisplay_end_trigger_functions
= intern ("redisplay-end-trigger-functions");
12806 staticpro (&Qinhibit_point_motion_hooks
);
12807 Qinhibit_point_motion_hooks
= intern ("inhibit-point-motion-hooks");
12809 QCdata
= intern (":data");
12810 staticpro (&QCdata
);
12811 Qdisplay
= intern ("display");
12812 staticpro (&Qdisplay
);
12813 Qspace_width
= intern ("space-width");
12814 staticpro (&Qspace_width
);
12815 Qraise
= intern ("raise");
12816 staticpro (&Qraise
);
12817 Qspace
= intern ("space");
12818 staticpro (&Qspace
);
12819 Qmargin
= intern ("margin");
12820 staticpro (&Qmargin
);
12821 Qleft_margin
= intern ("left-margin");
12822 staticpro (&Qleft_margin
);
12823 Qright_margin
= intern ("right-margin");
12824 staticpro (&Qright_margin
);
12825 Qalign_to
= intern ("align-to");
12826 staticpro (&Qalign_to
);
12827 QCalign_to
= intern (":align-to");
12828 staticpro (&QCalign_to
);
12829 Qrelative_width
= intern ("relative-width");
12830 staticpro (&Qrelative_width
);
12831 QCrelative_width
= intern (":relative-width");
12832 staticpro (&QCrelative_width
);
12833 QCrelative_height
= intern (":relative-height");
12834 staticpro (&QCrelative_height
);
12835 QCeval
= intern (":eval");
12836 staticpro (&QCeval
);
12837 Qwhen
= intern ("when");
12838 staticpro (&Qwhen
);
12839 QCfile
= intern (":file");
12840 staticpro (&QCfile
);
12841 Qfontified
= intern ("fontified");
12842 staticpro (&Qfontified
);
12843 Qfontification_functions
= intern ("fontification-functions");
12844 staticpro (&Qfontification_functions
);
12845 Qtrailing_whitespace
= intern ("trailing-whitespace");
12846 staticpro (&Qtrailing_whitespace
);
12847 Qimage
= intern ("image");
12848 staticpro (&Qimage
);
12850 last_arrow_position
= Qnil
;
12851 last_arrow_string
= Qnil
;
12852 staticpro (&last_arrow_position
);
12853 staticpro (&last_arrow_string
);
12855 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
12856 staticpro (&echo_buffer
[0]);
12857 staticpro (&echo_buffer
[1]);
12859 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
12860 staticpro (&echo_area_buffer
[0]);
12861 staticpro (&echo_area_buffer
[1]);
12863 DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace
,
12864 "Non-nil means highlight trailing whitespace.\n\
12865 The face used for trailing whitespace is `trailing-whitespace'.");
12866 Vshow_trailing_whitespace
= Qnil
;
12868 DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay
,
12869 "Non-nil means don't actually do any redisplay.\n\
12870 This is used for internal purposes.");
12871 Vinhibit_redisplay
= Qnil
;
12873 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string
,
12874 "String (or mode line construct) included (normally) in `mode-line-format'.");
12875 Vglobal_mode_string
= Qnil
;
12877 DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position
,
12878 "Marker for where to display an arrow on top of the buffer text.\n\
12879 This must be the beginning of a line in order to work.\n\
12880 See also `overlay-arrow-string'.");
12881 Voverlay_arrow_position
= Qnil
;
12883 DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string
,
12884 "String to display as an arrow. See also `overlay-arrow-position'.");
12885 Voverlay_arrow_string
= Qnil
;
12887 DEFVAR_INT ("scroll-step", &scroll_step
,
12888 "*The number of lines to try scrolling a window by when point moves out.\n\
12889 If that fails to bring point back on frame, point is centered instead.\n\
12890 If this is zero, point is always centered after it moves off frame.");
12892 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively
,
12893 "*Scroll up to this many lines, to bring point back on screen.\n\
12894 A value of zero means to scroll the text to center point vertically\n\
12896 scroll_conservatively
= 0;
12898 DEFVAR_INT ("scroll-margin", &scroll_margin
,
12899 "*Number of lines of margin at the top and bottom of a window.\n\
12900 Recenter the window whenever point gets within this many lines\n\
12901 of the top or bottom of the window.");
12905 DEFVAR_INT ("debug-end-pos", &debug_end_pos
, "Don't ask");
12908 DEFVAR_BOOL ("truncate-partial-width-windows",
12909 &truncate_partial_width_windows
,
12910 "*Non-nil means truncate lines in all windows less than full frame wide.");
12911 truncate_partial_width_windows
= 1;
12913 DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video
,
12914 "*Non-nil means use inverse video for the mode line.");
12915 mode_line_inverse_video
= 1;
12917 DEFVAR_INT ("line-number-display-limit", &line_number_display_limit
,
12918 "*Maximum buffer size for which line number should be displayed.\n\
12919 If the buffer is bigger than this, the line number does not appear\n\
12920 in the mode line.");
12921 line_number_display_limit
= 1000000;
12923 DEFVAR_INT ("line-number-display-limit-width", &line_number_display_limit_width
,
12924 "*Maximum line width (in characters) for line number display.\n\
12925 If the average length of the lines near point is bigger than this, then the\n\
12926 line number may be omitted from the mode line.");
12927 line_number_display_limit_width
= 200;
12929 DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows
,
12930 "*Non-nil means highlight region even in nonselected windows.");
12931 highlight_nonselected_windows
= 0;
12933 DEFVAR_BOOL ("multiple-frames", &multiple_frames
,
12934 "Non-nil if more than one frame is visible on this display.\n\
12935 Minibuffer-only frames don't count, but iconified frames do.\n\
12936 This variable is not guaranteed to be accurate except while processing\n\
12937 `frame-title-format' and `icon-title-format'.");
12939 DEFVAR_LISP ("frame-title-format", &Vframe_title_format
,
12940 "Template for displaying the title bar of visible frames.\n\
12941 \(Assuming the window manager supports this feature.)\n\
12942 This variable has the same structure as `mode-line-format' (which see),\n\
12943 and is used only on frames for which no explicit name has been set\n\
12944 \(see `modify-frame-parameters').");
12945 DEFVAR_LISP ("icon-title-format", &Vicon_title_format
,
12946 "Template for displaying the title bar of an iconified frame.\n\
12947 \(Assuming the window manager supports this feature.)\n\
12948 This variable has the same structure as `mode-line-format' (which see),\n\
12949 and is used only on frames for which no explicit name has been set\n\
12950 \(see `modify-frame-parameters').");
12952 = Vframe_title_format
12953 = Fcons (intern ("multiple-frames"),
12954 Fcons (build_string ("%b"),
12955 Fcons (Fcons (build_string (""),
12956 Fcons (intern ("invocation-name"),
12957 Fcons (build_string ("@"),
12958 Fcons (intern ("system-name"),
12962 DEFVAR_LISP ("message-log-max", &Vmessage_log_max
,
12963 "Maximum number of lines to keep in the message log buffer.\n\
12964 If nil, disable message logging. If t, log messages but don't truncate\n\
12965 the buffer when it becomes large.");
12966 XSETFASTINT (Vmessage_log_max
, 50);
12968 DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions
,
12969 "Functions called before redisplay, if window sizes have changed.\n\
12970 The value should be a list of functions that take one argument.\n\
12971 Just before redisplay, for each frame, if any of its windows have changed\n\
12972 size since the last redisplay, or have been split or deleted,\n\
12973 all the functions in the list are called, with the frame as argument.");
12974 Vwindow_size_change_functions
= Qnil
;
12976 DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions
,
12977 "List of Functions to call before redisplaying a window with scrolling.\n\
12978 Each function is called with two arguments, the window\n\
12979 and its new display-start position. Note that the value of `window-end'\n\
12980 is not valid when these functions are called.");
12981 Vwindow_scroll_functions
= Qnil
;
12983 DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p
,
12984 "*Non-nil means automatically resize tool-bars.\n\
12985 This increases a tool-bar's height if not all tool-bar items are visible.\n\
12986 It decreases a tool-bar's height when it would display blank lines\n\
12988 auto_resize_tool_bars_p
= 1;
12990 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p
,
12991 "*Non-nil means raise tool-bar buttons when the mouse moves over them.");
12992 auto_raise_tool_bar_buttons_p
= 1;
12994 DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin
,
12995 "*Margin around tool-bar buttons in pixels.");
12996 tool_bar_button_margin
= 1;
12998 DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief
,
12999 "Relief thickness of tool-bar buttons.");
13000 tool_bar_button_relief
= 3;
13002 DEFVAR_LISP ("fontification-functions", &Vfontification_functions
,
13003 "List of functions to call to fontify regions of text.\n\
13004 Each function is called with one argument POS. Functions must\n\
13005 fontify a region starting at POS in the current buffer, and give\n\
13006 fontified regions the property `fontified'.\n\
13007 This variable automatically becomes buffer-local when set.");
13008 Vfontification_functions
= Qnil
;
13009 Fmake_local_variable (Qfontification_functions
);
13011 DEFVAR_BOOL ("unibyte-display-via-language-environment",
13012 &unibyte_display_via_language_environment
,
13013 "*Non-nil means display unibyte text according to language environment.\n\
13014 Specifically this means that unibyte non-ASCII characters\n\
13015 are displayed by converting them to the equivalent multibyte characters\n\
13016 according to the current language environment. As a result, they are\n\
13017 displayed according to the current fontset.");
13018 unibyte_display_via_language_environment
= 0;
13020 DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height
,
13021 "*Maximum height for resizing mini-windows.\n\
13022 If a float, it specifies a fraction of the mini-window frame's height.\n\
13023 If an integer, it specifies a number of lines.\n\
13024 If nil, don't resize.");
13025 Vmax_mini_window_height
= make_float (0.25);
13027 DEFVAR_BOOL ("cursor-in-non-selected-windows",
13028 &cursor_in_non_selected_windows
,
13029 "*Non-nil means display a hollow cursor in non-selected windows.\n\
13030 Nil means don't display a cursor there.");
13031 cursor_in_non_selected_windows
= 1;
13035 /* Initialize this module when Emacs starts. */
13040 Lisp_Object root_window
;
13041 struct window
*mini_w
;
13043 CHARPOS (this_line_start_pos
) = 0;
13045 mini_w
= XWINDOW (minibuf_window
);
13046 root_window
= FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w
)));
13048 if (!noninteractive
)
13050 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (root_window
)));
13053 XSETFASTINT (XWINDOW (root_window
)->top
, FRAME_TOP_MARGIN (f
));
13054 set_window_height (root_window
,
13055 FRAME_HEIGHT (f
) - 1 - FRAME_TOP_MARGIN (f
),
13057 XSETFASTINT (mini_w
->top
, FRAME_HEIGHT (f
) - 1);
13058 set_window_height (minibuf_window
, 1, 0);
13060 XSETFASTINT (XWINDOW (root_window
)->width
, FRAME_WIDTH (f
));
13061 XSETFASTINT (mini_w
->width
, FRAME_WIDTH (f
));
13063 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
13064 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
13065 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
13067 /* The default ellipsis glyphs `...'. */
13068 for (i
= 0; i
< 3; ++i
)
13069 XSETFASTINT (default_invis_vector
[i
], '.');
13072 #ifdef HAVE_WINDOW_SYSTEM
13074 /* Allocate the buffer for frame titles. */
13076 frame_title_buf
= (char *) xmalloc (size
);
13077 frame_title_buf_end
= frame_title_buf
+ size
;
13078 frame_title_ptr
= NULL
;
13080 #endif /* HAVE_WINDOW_SYSTEM */