From 81954352c3505360cb0e710858767f40a65a9531 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 25 May 2002 09:04:01 +0000 Subject: [PATCH] (display_mode_element): New argument RISKY; all callers changed. If non-zero, don't use values of variables which are not marked as risky-local-variables, and remove text properties from string values of such variables. --- src/ChangeLog | 7 +++++ src/xdisp.c | 74 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 026a9f2b393..331256866f1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-05-25 Eli Zaretskii + + * xdisp.c (display_mode_element): New argument RISKY; all callers + changed. If non-zero, don't use values of variables which are not + marked as risky-local-variables, and remove text properties from + string values of such variables. + 2002-05-13 Richard M. Stallman * search.c (search_buffer): Give up boyer moore search if inverse diff --git a/src/xdisp.c b/src/xdisp.c index 818331f5a62..ce12527fccd 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -33,7 +33,7 @@ Boston, MA 02111-1307, USA. */ you as part of the interpreter's command loop or as the result of calling Lisp functions like `sit-for'. The C function `redisplay' in xdisp.c is the only entry into the inner redisplay code. (Or, - let's say almost---see the the description of direct update + let's say almost---see the description of direct update operations, below.). The following diagram shows how redisplay code is invoked. As you @@ -229,6 +229,8 @@ Lisp_Object Qgrow_only; Lisp_Object Qinhibit_eval_during_redisplay; Lisp_Object Qbuffer_position, Qposition, Qobject; +Lisp_Object Qrisky_local_variable; + /* Functions called to fontify regions of text. */ Lisp_Object Vfontification_functions; @@ -733,7 +735,8 @@ static int try_window_id P_ ((struct window *)); static int display_line P_ ((struct it *)); static int display_mode_lines P_ ((struct window *)); static int display_mode_line P_ ((struct window *, enum face_id, Lisp_Object)); -static int display_mode_element P_ ((struct it *, int, int, int, Lisp_Object)); +static int display_mode_element P_ ((struct it *, int, int, int, Lisp_Object, + int)); static char *decode_mode_spec P_ ((struct window *, int, int, int, int *)); static void display_menu_bar P_ ((struct window *)); static int display_count_lines P_ ((int, int, int, int, int *)); @@ -7242,7 +7245,7 @@ x_consider_frame_title (frame) frame_title_ptr = frame_title_buf; init_iterator (&it, XWINDOW (f->selected_window), -1, -1, NULL, DEFAULT_FACE_ID); - display_mode_element (&it, 0, -1, -1, fmt); + display_mode_element (&it, 0, -1, -1, fmt, 0); len = frame_title_ptr - frame_title_buf; frame_title_ptr = NULL; set_buffer_internal (obuf); @@ -13465,7 +13468,7 @@ display_mode_line (w, face_id, format) kboard-local variables in the mode_line_format will get the right values. */ push_frame_kboard (it.f); - display_mode_element (&it, 0, 0, 0, format); + display_mode_element (&it, 0, 0, 0, format, 0); pop_frame_kboard (); /* Fill up with spaces. */ @@ -13504,16 +13507,19 @@ display_mode_line (w, face_id, format) FIELD_WIDTH is the number of characters the display of ELT should occupy in the mode line, and PRECISION is the maximum number of characters to display from ELT's representation. See - display_string for details. * + display_string for details. + + RISKY non-zero means ELT's contents are risky to use. Returns the hpos of the end of the text generated by ELT. */ static int -display_mode_element (it, depth, field_width, precision, elt) +display_mode_element (it, depth, field_width, precision, elt, risky) struct it *it; int depth; int field_width, precision; Lisp_Object elt; + int risky; { int n = 0, field, prec; @@ -13532,6 +13538,25 @@ display_mode_element (it, depth, field_width, precision, elt) unsigned char *this = XSTRING (elt)->data; unsigned char *lisp_string = this; + /* Remove text properties from mode-line elements whose values + come from variables not marked as risky. */ + if (risky) + { + Lisp_Object props; + + props = Ftext_properties_at (make_number (0), elt); + if (!NILP (props)) + { + elt = Fcopy_sequence (elt); + Fset_text_properties (make_number (0), Flength (elt), + Qnil, elt); + } + /* We've copied ELT, so we need to update this and + lisp_string. */ + this = XSTRING (elt)->data; + lisp_string = this; + } + while ((precision <= 0 || n < precision) && *this && (frame_title_ptr @@ -13584,7 +13609,7 @@ display_mode_element (it, depth, field_width, precision, elt) if (c == 'M') n += display_mode_element (it, depth, field, prec, - Vglobal_mode_string); + Vglobal_mode_string, risky); else if (c != 0) { int multibyte; @@ -13641,6 +13666,12 @@ display_mode_element (it, depth, field_width, precision, elt) literally. */ { register Lisp_Object tem; + + /* If the variable is not marked as risky to set + then its contents are risky to use. */ + if (NILP (Fget (elt, Qrisky_local_variable))) + risky = 1; + tem = Fboundp (elt); if (!NILP (tem)) { @@ -13679,18 +13710,25 @@ display_mode_element (it, depth, field_width, precision, elt) If first element is a symbol, process the cadr or caddr recursively according to whether the symbol's value is non-nil or nil. */ car = XCAR (elt); - if (EQ (car, QCeval) && CONSP (XCDR (elt))) + if (EQ (car, QCeval)) { /* An element of the form (:eval FORM) means evaluate FORM and use the result as mode line elements. */ - struct gcpro gcpro1; - Lisp_Object spec; - - spec = safe_eval (XCAR (XCDR (elt))); - GCPRO1 (spec); - n += display_mode_element (it, depth, field_width - n, - precision - n, spec); - UNGCPRO; + + if (risky) + break; + + if (CONSP (XCDR (elt))) + { + struct gcpro gcpro1; + Lisp_Object spec; + + spec = safe_eval (XCAR (XCDR (elt))); + GCPRO1 (spec); + n += display_mode_element (it, depth, field_width - n, + precision - n, spec, risky); + UNGCPRO; + } } else if (SYMBOLP (car)) { @@ -13755,7 +13793,7 @@ display_mode_element (it, depth, field_width, precision, elt) && (precision <= 0 || n < precision)) { n += display_mode_element (it, depth, field_width - n, - precision - n, XCAR (elt)); + precision - n, XCAR (elt), risky); elt = XCDR (elt); } } @@ -14772,6 +14810,8 @@ syms_of_xdisp () staticpro (&Qbuffer_position); Qobject = intern ("object"); staticpro (&Qobject); + Qrisky_local_variable = intern ("risky-local-variable"); + staticpro (&Qrisky_local_variable); last_arrow_position = Qnil; last_arrow_string = Qnil; -- 2.39.2