]> code.delx.au - gnu-emacs/blobdiff - src/editfns.c
(Fbyte_code): Harmonize arguments with documentation.
[gnu-emacs] / src / editfns.c
index 5254a76856946ef7fe2f90b405f030115f6baf05..e115300e24bffbd389dd197191f3526504ca8359 100644 (file)
@@ -43,6 +43,11 @@ extern Lisp_Object make_time ();
 extern void insert_from_buffer ();
 static long difftm ();
 static void set_time_zone_rule ();
+static void update_buffer_properties ();
+
+Lisp_Object Vbuffer_access_fontify_functions;
+Lisp_Object Qbuffer_access_fontify_functions;
+Lisp_Object Vbuffer_access_fontified_property;
 
 /* Some static data, and a function to initialize it for each run */
 
@@ -543,7 +548,7 @@ DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0,
 }
 
 DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
-  "Return the current time, as the number of seconds since 12:00 AM January 1970.\n\
+  "Return the current time, as the number of seconds since 1970-01-01 00:00:00.\n\
 The time is returned as a list of three integers.  The first has the\n\
 most significant 16 bits of the seconds, while the second has the\n\
 least significant 16 bits.  The third integer gives the microsecond\n\
@@ -737,7 +742,7 @@ If you want them to stand for years in this century, you must do that yourself."
       char **oldenv = environ, **newenv;
       
       if (STRINGP (zone))
-       tzstring = XSTRING (zone)->data;
+       tzstring = (char *) XSTRING (zone)->data;
       else if (INTEGERP (zone))
        {
          int abszone = abs (XINT (zone));
@@ -879,13 +884,17 @@ the data it can't find.")
     return Fmake_list (2, Qnil);
 }
 
+/* This holds the value of `environ' produced by the previous
+   call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
+   has never been called.  */
+static char **environbuf;
+
 DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0,
   "Set the local time zone using TZ, a string specifying a time zone rule.\n\
 If TZ is nil, use implementation-defined default time zone information.")
   (tz)
      Lisp_Object tz;
 {
-  static char **environbuf;
   char *tzstring;
 
   if (NILP (tz))
@@ -893,7 +902,7 @@ If TZ is nil, use implementation-defined default time zone information.")
   else
     {
       CHECK_STRING (tz, 0);
-      tzstring = XSTRING (tz)->data;
+      tzstring = (char *) XSTRING (tz)->data;
     }
 
   set_time_zone_rule (tzstring);
@@ -1142,7 +1151,7 @@ from adjoining text, if those properties are sticky.")
 /* Return a Lisp_String containing the text of the current buffer from
    START to END.  If text properties are in use and the current buffer
    has properties in the range specified, the resulting string will also
-   have them.
+   have them, if PROPS is nonzero.
 
    We don't want to use plain old make_string here, because it calls
    make_uninit_string, which can cause the buffer arena to be
@@ -1153,8 +1162,9 @@ from adjoining text, if those properties are sticky.")
    buffer substrings.  */
 
 Lisp_Object
-make_buffer_string (start, end)
+make_buffer_string (start, end, props)
      int start, end;
+     int props;
 {
   Lisp_Object result, tem, tem1;
 
@@ -1164,17 +1174,58 @@ make_buffer_string (start, end)
   result = make_uninit_string (end - start);
   bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start);
 
-  tem = Fnext_property_change (make_number (start), Qnil, make_number (end));
-  tem1 = Ftext_properties_at (make_number (start), Qnil);
-
+  /* If desired, update and copy the text properties.  */
 #ifdef USE_TEXT_PROPERTIES
-  if (XINT (tem) != end || !NILP (tem1))
-    copy_intervals_to_string (result, current_buffer, start, end - start);
+  if (props)
+    {
+      update_buffer_properties (start, end);
+
+      tem = Fnext_property_change (make_number (start), Qnil, make_number (end));
+      tem1 = Ftext_properties_at (make_number (start), Qnil);
+
+      if (XINT (tem) != end || !NILP (tem1))
+       copy_intervals_to_string (result, current_buffer, start, end - start);
+    }
 #endif
 
   return result;
 }
 
+/* Call Vbuffer_access_fontify_functions for the range START ... END
+   in the current buffer, if necessary.  */
+
+static void
+update_buffer_properties (start, end)
+     int start, end;
+{
+#ifdef USE_TEXT_PROPERTIES
+  /* If this buffer has some access functions,
+     call them, specifying the range of the buffer being accessed.  */
+  if (!NILP (Vbuffer_access_fontify_functions))
+    {
+      Lisp_Object args[3];
+      Lisp_Object tem;
+
+      args[0] = Qbuffer_access_fontify_functions;
+      XSETINT (args[1], start);
+      XSETINT (args[2], end);
+
+      /* But don't call them if we can tell that the work
+        has already been done.  */
+      if (!NILP (Vbuffer_access_fontified_property))
+       {
+         tem = Ftext_property_any (args[1], args[2],
+                                   Vbuffer_access_fontified_property,
+                                   Qnil, Qnil);
+         if (! NILP (tem))
+           Frun_hook_with_args (3, &args);
+       }
+      else
+       Frun_hook_with_args (3, &args);
+    }
+#endif
+}
+
 DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,
   "Return the contents of part of the current buffer as a string.\n\
 The two arguments START and END are character positions;\n\
@@ -1188,7 +1239,24 @@ they can be in either order.")
   beg = XINT (b);
   end = XINT (e);
 
-  return make_buffer_string (beg, end);
+  return make_buffer_string (beg, end, 1);
+}
+
+DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties,
+       Sbuffer_substring_no_properties, 2, 2, 0,
+  "Return the characters of part of the buffer, without the text properties.\n\
+The two arguments START and END are character positions;\n\
+they can be in either order.")
+  (b, e)
+     Lisp_Object b, e;
+{
+  register int beg, end;
+
+  validate_region (&b, &e);
+  beg = XINT (b);
+  end = XINT (e);
+
+  return make_buffer_string (beg, end, 0);
 }
 
 DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
@@ -1197,7 +1265,7 @@ If narrowing is in effect, this function returns only the visible part\n\
 of the buffer.")
   ()
 {
-  return make_buffer_string (BEGV, ZV);
+  return make_buffer_string (BEGV, ZV, 1);
 }
 
 DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,
@@ -1210,7 +1278,7 @@ They default to the beginning and the end of BUFFER.")
      Lisp_Object buf, b, e;
 {
   register int beg, end, temp;
-  register struct buffer *bp;
+  register struct buffer *bp, *obuf;
   Lisp_Object buffer;
 
   buffer = Fget_buffer (buf);
@@ -1239,6 +1307,11 @@ They default to the beginning and the end of BUFFER.")
   if (!(BUF_BEGV (bp) <= beg && end <= BUF_ZV (bp)))
     args_out_of_range (b, e);
 
+  obuf = current_buffer;
+  set_buffer_internal_1 (bp);
+  update_buffer_properties (beg, end);
+  set_buffer_internal_1 (obuf);
+
   insert_from_buffer (bp, beg, end - beg, 0);
   return Qnil;
 }
@@ -1677,12 +1750,9 @@ minibuffer contents show.")
 DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0,
   "Display a message, in a dialog box if possible.\n\
 If a dialog box is not available, use the echo area.\n\
-The first argument is a control string.\n\
-It may contain %s or %d or %c to print successive following arguments.\n\
-%s means print an argument as a string, %d means print as number in decimal,\n\
-%c means print a number as a single character.\n\
-The argument used by %s must be a string or a symbol;\n\
-the argument used by %d or %c must be a number.\n\
+The first argument is a format control string, and the rest are data\n\
+to be formatted under control of the string.  See `format' for details.\n\
+\n\
 If the first argument is nil, clear any existing message; let the\n\
 minibuffer contents show.")
   (nargs, args)
@@ -1698,7 +1768,7 @@ minibuffer contents show.")
     {
       register Lisp_Object val;
       val = Fformat (nargs, args);
-#ifdef HAVE_X_MENU
+#ifdef HAVE_MENUS
       {
        Lisp_Object pane, menu, obj;
        struct gcpro gcpro1;
@@ -1709,7 +1779,7 @@ minibuffer contents show.")
        UNGCPRO;
        return val;
       }
-#else
+#else /* not HAVE_MENUS */
       /* Copy the data so that it won't move when we GC.  */
       if (! message_text)
        {
@@ -1724,30 +1794,27 @@ minibuffer contents show.")
       bcopy (XSTRING (val)->data, message_text, XSTRING (val)->size);
       message2 (message_text, XSTRING (val)->size);
       return val;
-#endif
+#endif /* not HAVE_MENUS */
     }
 }
-#ifdef HAVE_X_MENU
+#ifdef HAVE_MENUS
 extern Lisp_Object last_nonmenu_event;
 #endif
+
 DEFUN ("message-or-box", Fmessage_or_box, Smessage_or_box, 1, MANY, 0,
   "Display a message in a dialog box or in the echo area.\n\
 If this command was invoked with the mouse, use a dialog box.\n\
 Otherwise, use the echo area.\n\
+The first argument is a format control string, and the rest are data\n\
+to be formatted under control of the string.  See `format' for details.\n\
 \n\
-The first argument is a control string.\n\
-It may contain %s or %d or %c to print successive following arguments.\n\
-%s means print an argument as a string, %d means print as number in decimal,\n\
-%c means print a number as a single character.\n\
-The argument used by %s must be a string or a symbol;\n\
-the argument used by %d or %c must be a number.\n\
 If the first argument is nil, clear any existing message; let the\n\
 minibuffer contents show.")
   (nargs, args)
      int nargs;
      Lisp_Object *args;
 {
-#ifdef HAVE_X_MENU
+#ifdef HAVE_MENUS
   if (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
     return Fmessage_box (nargs, args);
 #endif
@@ -1896,8 +1963,12 @@ Use %% to put a single % into the output.")
            strings[i++] = (unsigned char *) u.half[1];
          }
 #endif
-       else
+       else if (i == 0)
+         /* The first string is treated differently
+            because it is the format string.  */
          strings[i++] = XSTRING (args[n])->data;
+       else
+         strings[i++] = (unsigned char *) XFASTINT (args[n]);
       }
 
     /* Make room in result for all the non-%-codes in the control string.  */
@@ -1909,7 +1980,8 @@ Use %% to put a single % into the output.")
        buf = (char *) alloca (total + 1);
        buf[total - 1] = 0;
 
-       length = doprnt (buf, total + 1, strings[0], end, i-1, strings + 1);
+       length = doprnt_lisp (buf, total + 1, strings[0],
+                             end, i-1, strings + 1);
        if (buf[total - 1] == 0)
          break;
 
@@ -2300,6 +2372,26 @@ Transposing beyond buffer boundaries is an error.")
 void
 syms_of_editfns ()
 {
+  environbuf = 0;
+
+  Qbuffer_access_fontify_functions
+    = intern ("buffer-access-fontify-functions");
+  staticpro (&Qbuffer_access_fontify_functions);
+
+  DEFVAR_LISP ("buffer-access-fontify-functions",
+              &Vbuffer_access_fontify_functions,
+              "List of functions called by `buffer-substring' to fontify if necessary.\n\
+Each function is called with two arguments which specify the range\n\
+of the buffer being accessed.");
+  Vbuffer_access_fontify_functions = Qnil;
+
+  DEFVAR_LISP ("buffer_access_fontified_property",
+              &Vbuffer_access_fontified_property,
+       "Property which (if non-nil) indicates text has been fontified.\n\
+`buffer-substring' need not call the `buffer-access-fontify-functions'\n\
+functions if all the text being accessed has this property.");
+  Vbuffer_access_fontified_property = Qnil;
+
   DEFVAR_LISP ("system-name", &Vsystem_name,
               "The name of the machine Emacs is running on.");
   
@@ -2317,6 +2409,7 @@ syms_of_editfns ()
   defsubr (&Sstring_to_char);
   defsubr (&Schar_to_string);
   defsubr (&Sbuffer_substring);
+  defsubr (&Sbuffer_substring_no_properties);
   defsubr (&Sbuffer_string);
 
   defsubr (&Spoint_marker);