emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mode-line-element-to-string


From: Stefan Monnier
Subject: mode-line-element-to-string
Date: Thu, 11 Apr 2002 10:11:46 -0400

Any objection to the patch below ?
I'd also welcome comments, especially suggestions for a better name.


        Stefan


--- xdisp.c.~1.746.~    Mon Apr  8 15:43:35 2002
+++ xdisp.c     Thu Apr 11 10:09:05 2002
@@ -7169,8 +7169,6 @@
  ***********************************************************************/
 
 
-#ifdef HAVE_WINDOW_SYSTEM
-
 /* A buffer for constructing frame titles in it; allocated from the
    heap in init_xdisp and resized as needed in store_frame_title_char.  */
 
@@ -7237,6 +7235,26 @@
   return n;
 }
 
+DEFUN ("mode-line-element-to-string", Fmode_line_element_to_string,
+       Smode_line_element_to_string, 1, 1, 0,
+       doc: /* Return the string corresponding to a mode-line-element.  */)
+  (fmt)
+     Lisp_Object fmt;
+{
+  struct it it;
+  int len;
+
+  frame_title_ptr = frame_title_buf;
+  init_iterator (&it, XWINDOW (selected_window), -1, -1,
+                NULL, DEFAULT_FACE_ID);
+  display_mode_element (&it , 0, -1, -1, fmt, Qnil, 0);
+  len = frame_title_ptr - frame_title_buf;
+  frame_title_ptr = NULL;
+  return make_string (frame_title_buf, len);
+}
+
+
+#ifdef HAVE_WINDOW_SYSTEM
 
 /* Set the title of FRAME, if it has changed.  The title format is
    Vicon_title_format if FRAME is iconified, otherwise it is
@@ -7301,11 +7319,6 @@
     }
 }
 
-#else /* not HAVE_WINDOW_SYSTEM */
-
-#define frame_title_ptr ((char *)0)
-#define store_frame_title(str, mincol, maxcol) 0
-
 #endif /* not HAVE_WINDOW_SYSTEM */
 
 
@@ -13628,7 +13641,10 @@
    PROPS is a property list to add to any string we encounter.
 
    If RISKY is nonzero, remove (disregard) any properties in any string 
-   we encounter, and ignore :eval and :propertize.  */
+   we encounter, and ignore :eval and :propertize.
+
+   If the global variable `frame_title_ptr' is non-NULL, then the output
+   is passed to `store_frame_title' instead of `display_string'.  */
 
 static int
 display_mode_element (it, depth, field_width, precision, elt, props, risky)
@@ -14868,6 +14884,7 @@
 #ifdef HAVE_WINDOW_SYSTEM
   defsubr (&Stool_bar_lines_needed);
 #endif
+  defsubr (&Smode_line_element_to_string);
 
   staticpro (&Qmenu_bar_update_hook);
   Qmenu_bar_update_hook = intern ("menu-bar-update-hook");
@@ -15263,15 +15280,14 @@
        default_invis_vector[i] = make_number ('.');
     }
 
-#ifdef HAVE_WINDOW_SYSTEM
   {
-    /* Allocate the buffer for frame titles.  */
+    /* Allocate the buffer for frame titles.
+       Also used for mode-line-element-to-string.  */
     int size = 100;
     frame_title_buf = (char *) xmalloc (size);
     frame_title_buf_end = frame_title_buf + size;
     frame_title_ptr = NULL;
   }
-#endif /* HAVE_WINDOW_SYSTEM */
   
   help_echo_showing_p = 0;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]