1 /* Lisp functions pertaining to editing.
2 Copyright (C) 1985,86,87,89,93,94,95,96,97,98 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <sys/types.h>
33 #include "intervals.h"
40 #define min(a, b) ((a) < (b) ? (a) : (b))
41 #define max(a, b) ((a) > (b) ? (a) : (b))
47 extern char **environ
;
48 extern Lisp_Object
make_time ();
49 extern void insert_from_buffer ();
50 static int tm_diff ();
51 static void update_buffer_properties ();
52 size_t emacs_strftime ();
53 void set_time_zone_rule ();
55 Lisp_Object Vbuffer_access_fontify_functions
;
56 Lisp_Object Qbuffer_access_fontify_functions
;
57 Lisp_Object Vbuffer_access_fontified_property
;
59 Lisp_Object
Fuser_full_name ();
61 /* Some static data, and a function to initialize it for each run */
63 Lisp_Object Vsystem_name
;
64 Lisp_Object Vuser_real_login_name
; /* login name of current user ID */
65 Lisp_Object Vuser_full_name
; /* full name of current user */
66 Lisp_Object Vuser_login_name
; /* user name from LOGNAME or USER */
72 register unsigned char *p
, *q
, *r
;
73 struct passwd
*pw
; /* password entry for the current user */
76 /* Set up system_name even when dumping. */
80 /* Don't bother with this on initial start when just dumping out */
83 #endif /* not CANNOT_DUMP */
85 pw
= (struct passwd
*) getpwuid (getuid ());
87 /* We let the real user name default to "root" because that's quite
88 accurate on MSDOG and because it lets Emacs find the init file.
89 (The DVX libraries override the Djgpp libraries here.) */
90 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "root");
92 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "unknown");
95 /* Get the effective user name, by consulting environment variables,
96 or the effective uid if those are unset. */
97 user_name
= (char *) getenv ("LOGNAME");
100 user_name
= (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
101 #else /* WINDOWSNT */
102 user_name
= (char *) getenv ("USER");
103 #endif /* WINDOWSNT */
106 pw
= (struct passwd
*) getpwuid (geteuid ());
107 user_name
= (char *) (pw
? pw
->pw_name
: "unknown");
109 Vuser_login_name
= build_string (user_name
);
111 /* If the user name claimed in the environment vars differs from
112 the real uid, use the claimed name to find the full name. */
113 tem
= Fstring_equal (Vuser_login_name
, Vuser_real_login_name
);
114 Vuser_full_name
= Fuser_full_name (NILP (tem
)? make_number (geteuid())
117 p
= (unsigned char *) getenv ("NAME");
119 Vuser_full_name
= build_string (p
);
120 else if (NILP (Vuser_full_name
))
121 Vuser_full_name
= build_string ("unknown");
124 DEFUN ("char-to-string", Fchar_to_string
, Schar_to_string
, 1, 1, 0,
125 "Convert arg CHAR to a string containing multi-byte form of that character.")
127 Lisp_Object character
;
130 unsigned char workbuf
[4], *str
;
132 CHECK_NUMBER (character
, 0);
134 len
= CHAR_STRING (XFASTINT (character
), workbuf
, str
);
135 return make_multibyte_string (str
, 1, len
);
138 DEFUN ("string-to-char", Fstring_to_char
, Sstring_to_char
, 1, 1, 0,
139 "Convert arg STRING to a character, the first character of that string.\n\
140 A multibyte character is handled correctly.")
142 register Lisp_Object string
;
144 register Lisp_Object val
;
145 register struct Lisp_String
*p
;
146 CHECK_STRING (string
, 0);
147 p
= XSTRING (string
);
149 XSETFASTINT (val
, STRING_CHAR (p
->data
, STRING_BYTES (p
)));
151 XSETFASTINT (val
, 0);
156 buildmark (charpos
, bytepos
)
157 int charpos
, bytepos
;
159 register Lisp_Object mark
;
160 mark
= Fmake_marker ();
161 set_marker_both (mark
, Qnil
, charpos
, bytepos
);
165 DEFUN ("point", Fpoint
, Spoint
, 0, 0, 0,
166 "Return value of point, as an integer.\n\
167 Beginning of buffer is position (point-min)")
171 XSETFASTINT (temp
, PT
);
175 DEFUN ("point-marker", Fpoint_marker
, Spoint_marker
, 0, 0, 0,
176 "Return value of point, as a marker object.")
179 return buildmark (PT
, PT_BYTE
);
183 clip_to_bounds (lower
, num
, upper
)
184 int lower
, num
, upper
;
188 else if (num
> upper
)
194 DEFUN ("goto-char", Fgoto_char
, Sgoto_char
, 1, 1, "NGoto char: ",
195 "Set point to POSITION, a number or marker.\n\
196 Beginning of buffer is position (point-min), end is (point-max).\n\
197 If the position is in the middle of a multibyte form,\n\
198 the actual point is set at the head of the multibyte form\n\
199 except in the case that `enable-multibyte-characters' is nil.")
201 register Lisp_Object position
;
206 if (MARKERP (position
)
207 && current_buffer
== XMARKER (position
)->buffer
)
209 pos
= marker_position (position
);
211 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
213 SET_PT_BOTH (ZV
, ZV_BYTE
);
215 SET_PT_BOTH (pos
, marker_byte_position (position
));
220 CHECK_NUMBER_COERCE_MARKER (position
, 0);
222 pos
= clip_to_bounds (BEGV
, XINT (position
), ZV
);
228 region_limit (beginningp
)
231 extern Lisp_Object Vmark_even_if_inactive
; /* Defined in callint.c. */
232 register Lisp_Object m
;
233 if (!NILP (Vtransient_mark_mode
) && NILP (Vmark_even_if_inactive
)
234 && NILP (current_buffer
->mark_active
))
235 Fsignal (Qmark_inactive
, Qnil
);
236 m
= Fmarker_position (current_buffer
->mark
);
237 if (NILP (m
)) error ("There is no region now");
238 if ((PT
< XFASTINT (m
)) == beginningp
)
239 return (make_number (PT
));
244 DEFUN ("region-beginning", Fregion_beginning
, Sregion_beginning
, 0, 0, 0,
245 "Return position of beginning of region, as an integer.")
248 return (region_limit (1));
251 DEFUN ("region-end", Fregion_end
, Sregion_end
, 0, 0, 0,
252 "Return position of end of region, as an integer.")
255 return (region_limit (0));
258 DEFUN ("mark-marker", Fmark_marker
, Smark_marker
, 0, 0, 0,
259 "Return this buffer's mark, as a marker object.\n\
260 Watch out! Moving this marker changes the mark position.\n\
261 If you set the marker not to point anywhere, the buffer will have no mark.")
264 return current_buffer
->mark
;
267 DEFUN ("line-beginning-position", Fline_beginning_position
, Sline_beginning_position
,
269 "Return the character position of the first character on the current line.\n\
270 With argument N not nil or 1, move forward N - 1 lines first.\n\
271 If scan reaches end of buffer, return that position.\n\
272 This function does not move point.")
276 register int orig
, orig_byte
, end
;
285 Fforward_line (make_number (XINT (n
) - 1));
287 SET_PT_BOTH (orig
, orig_byte
);
289 return make_number (end
);
292 DEFUN ("line-end-position", Fline_end_position
, Sline_end_position
,
294 "Return the character position of the last character on the current line.\n\
295 With argument N not nil or 1, move forward N - 1 lines first.\n\
296 If scan reaches end of buffer, return that position.\n\
297 This function does not move point.")
306 return make_number (find_before_next_newline
307 (PT
, 0, XINT (n
) - (XINT (n
) <= 0)));
311 save_excursion_save ()
313 register int visible
= (XBUFFER (XWINDOW (selected_window
)->buffer
)
316 return Fcons (Fpoint_marker (),
317 Fcons (Fcopy_marker (current_buffer
->mark
, Qnil
),
318 Fcons (visible
? Qt
: Qnil
,
319 current_buffer
->mark_active
)));
323 save_excursion_restore (info
)
326 Lisp_Object tem
, tem1
, omark
, nmark
;
327 struct gcpro gcpro1
, gcpro2
, gcpro3
;
329 tem
= Fmarker_buffer (Fcar (info
));
330 /* If buffer being returned to is now deleted, avoid error */
331 /* Otherwise could get error here while unwinding to top level
333 /* In that case, Fmarker_buffer returns nil now. */
337 omark
= nmark
= Qnil
;
338 GCPRO3 (info
, omark
, nmark
);
343 unchain_marker (tem
);
344 tem
= Fcar (Fcdr (info
));
345 omark
= Fmarker_position (current_buffer
->mark
);
346 Fset_marker (current_buffer
->mark
, tem
, Fcurrent_buffer ());
347 nmark
= Fmarker_position (tem
);
348 unchain_marker (tem
);
349 tem
= Fcdr (Fcdr (info
));
350 #if 0 /* We used to make the current buffer visible in the selected window
351 if that was true previously. That avoids some anomalies.
352 But it creates others, and it wasn't documented, and it is simpler
353 and cleaner never to alter the window/buffer connections. */
356 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
357 Fswitch_to_buffer (Fcurrent_buffer (), Qnil
);
360 tem1
= current_buffer
->mark_active
;
361 current_buffer
->mark_active
= Fcdr (tem
);
362 if (!NILP (Vrun_hooks
))
364 /* If mark is active now, and either was not active
365 or was at a different place, run the activate hook. */
366 if (! NILP (current_buffer
->mark_active
))
368 if (! EQ (omark
, nmark
))
369 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
371 /* If mark has ceased to be active, run deactivate hook. */
372 else if (! NILP (tem1
))
373 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
379 DEFUN ("save-excursion", Fsave_excursion
, Ssave_excursion
, 0, UNEVALLED
, 0,
380 "Save point, mark, and current buffer; execute BODY; restore those things.\n\
381 Executes BODY just like `progn'.\n\
382 The values of point, mark and the current buffer are restored\n\
383 even in case of abnormal exit (throw or error).\n\
384 The state of activation of the mark is also restored.\n\
386 This construct does not save `deactivate-mark', and therefore\n\
387 functions that change the buffer will still cause deactivation\n\
388 of the mark at the end of the command. To prevent that, bind\n\
389 `deactivate-mark' with `let'.")
393 register Lisp_Object val
;
394 int count
= specpdl_ptr
- specpdl
;
396 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
399 return unbind_to (count
, val
);
402 DEFUN ("save-current-buffer", Fsave_current_buffer
, Ssave_current_buffer
, 0, UNEVALLED
, 0,
403 "Save the current buffer; execute BODY; restore the current buffer.\n\
404 Executes BODY just like `progn'.")
408 register Lisp_Object val
;
409 int count
= specpdl_ptr
- specpdl
;
411 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
414 return unbind_to (count
, val
);
417 DEFUN ("buffer-size", Fbufsize
, Sbufsize
, 0, 0, 0,
418 "Return the number of characters in the current buffer.")
422 XSETFASTINT (temp
, Z
- BEG
);
426 DEFUN ("point-min", Fpoint_min
, Spoint_min
, 0, 0, 0,
427 "Return the minimum permissible value of point in the current buffer.\n\
428 This is 1, unless narrowing (a buffer restriction) is in effect.")
432 XSETFASTINT (temp
, BEGV
);
436 DEFUN ("point-min-marker", Fpoint_min_marker
, Spoint_min_marker
, 0, 0, 0,
437 "Return a marker to the minimum permissible value of point in this buffer.\n\
438 This is the beginning, unless narrowing (a buffer restriction) is in effect.")
441 return buildmark (BEGV
, BEGV_BYTE
);
444 DEFUN ("point-max", Fpoint_max
, Spoint_max
, 0, 0, 0,
445 "Return the maximum permissible value of point in the current buffer.\n\
446 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
447 is in effect, in which case it is less.")
451 XSETFASTINT (temp
, ZV
);
455 DEFUN ("point-max-marker", Fpoint_max_marker
, Spoint_max_marker
, 0, 0, 0,
456 "Return a marker to the maximum permissible value of point in this buffer.\n\
457 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
458 is in effect, in which case it is less.")
461 return buildmark (ZV
, ZV_BYTE
);
464 DEFUN ("position-bytes", Fposition_bytes
, Sposition_bytes
, 1, 1, 0,
465 "Return the byte position for character position POSITION.")
467 Lisp_Object position
;
469 CHECK_NUMBER_COERCE_MARKER (position
, 1);
470 return make_number (CHAR_TO_BYTE (XINT (position
)));
473 DEFUN ("following-char", Ffollowing_char
, Sfollowing_char
, 0, 0, 0,
474 "Return the character following point, as a number.\n\
475 At the end of the buffer or accessible region, return 0.\n\
476 If `enable-multibyte-characters' is nil or point is not\n\
477 at character boundary, multibyte form is ignored,\n\
478 and only one byte following point is returned as a character.")
483 XSETFASTINT (temp
, 0);
485 XSETFASTINT (temp
, FETCH_CHAR (PT_BYTE
));
489 DEFUN ("preceding-char", Fprevious_char
, Sprevious_char
, 0, 0, 0,
490 "Return the character preceding point, as a number.\n\
491 At the beginning of the buffer or accessible region, return 0.\n\
492 If `enable-multibyte-characters' is nil or point is not\n\
493 at character boundary, multi-byte form is ignored,\n\
494 and only one byte preceding point is returned as a character.")
499 XSETFASTINT (temp
, 0);
500 else if (!NILP (current_buffer
->enable_multibyte_characters
))
504 XSETFASTINT (temp
, FETCH_CHAR (pos
));
507 XSETFASTINT (temp
, FETCH_BYTE (PT_BYTE
- 1));
511 DEFUN ("bobp", Fbobp
, Sbobp
, 0, 0, 0,
512 "Return t if point is at the beginning of the buffer.\n\
513 If the buffer is narrowed, this means the beginning of the narrowed part.")
521 DEFUN ("eobp", Feobp
, Seobp
, 0, 0, 0,
522 "Return t if point is at the end of the buffer.\n\
523 If the buffer is narrowed, this means the end of the narrowed part.")
531 DEFUN ("bolp", Fbolp
, Sbolp
, 0, 0, 0,
532 "Return t if point is at the beginning of a line.")
535 if (PT
== BEGV
|| FETCH_BYTE (PT_BYTE
- 1) == '\n')
540 DEFUN ("eolp", Feolp
, Seolp
, 0, 0, 0,
541 "Return t if point is at the end of a line.\n\
542 `End of a line' includes point being at the end of the buffer.")
545 if (PT
== ZV
|| FETCH_BYTE (PT_BYTE
) == '\n')
550 DEFUN ("char-after", Fchar_after
, Schar_after
, 0, 1, 0,
551 "Return character in current buffer at position POS.\n\
552 POS is an integer or a buffer pointer.\n\
553 If POS is out of range, the value is nil.\n\
554 If `enable-multibyte-characters' is nil or POS is not at character boundary,\n\
555 multi-byte form is ignored, and only one byte at POS\n\
556 is returned as a character.")
560 register int pos_byte
;
561 register Lisp_Object val
;
565 else if (MARKERP (pos
))
567 pos_byte
= marker_byte_position (pos
);
568 if (pos_byte
< BEGV_BYTE
|| pos_byte
>= ZV_BYTE
)
573 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
574 if (pos
< BEGV
|| pos
>= ZV
)
577 pos_byte
= CHAR_TO_BYTE (XINT (pos
));
580 return make_number (FETCH_CHAR (pos_byte
));
583 DEFUN ("char-before", Fchar_before
, Schar_before
, 0, 1, 0,
584 "Return character in current buffer preceding position POS.\n\
585 POS is an integer or a buffer pointer.\n\
586 If POS is out of range, the value is nil.\n\
587 If `enable-multibyte-characters' is nil or POS is not at character boundary,\n\
588 multi-byte form is ignored, and only one byte preceding POS\n\
589 is returned as a character.")
593 register Lisp_Object val
;
594 register int pos_byte
;
598 else if (MARKERP (pos
))
600 pos_byte
= marker_byte_position (pos
);
602 if (pos_byte
<= BEGV_BYTE
|| pos_byte
> ZV_BYTE
)
607 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
609 if (pos
<= BEGV
|| pos
> ZV
)
612 pos_byte
= CHAR_TO_BYTE (XINT (pos
));
615 if (!NILP (current_buffer
->enable_multibyte_characters
))
618 XSETFASTINT (val
, FETCH_CHAR (pos_byte
));
623 XSETFASTINT (val
, FETCH_BYTE (pos_byte
));
628 DEFUN ("user-login-name", Fuser_login_name
, Suser_login_name
, 0, 1, 0,
629 "Return the name under which the user logged in, as a string.\n\
630 This is based on the effective uid, not the real uid.\n\
631 Also, if the environment variable LOGNAME or USER is set,\n\
632 that determines the value of this function.\n\n\
633 If optional argument UID is an integer, return the login name of the user\n\
634 with that uid, or nil if there is no such user.")
640 /* Set up the user name info if we didn't do it before.
641 (That can happen if Emacs is dumpable
642 but you decide to run `temacs -l loadup' and not dump. */
643 if (INTEGERP (Vuser_login_name
))
647 return Vuser_login_name
;
649 CHECK_NUMBER (uid
, 0);
650 pw
= (struct passwd
*) getpwuid (XINT (uid
));
651 return (pw
? build_string (pw
->pw_name
) : Qnil
);
654 DEFUN ("user-real-login-name", Fuser_real_login_name
, Suser_real_login_name
,
656 "Return the name of the user's real uid, as a string.\n\
657 This ignores the environment variables LOGNAME and USER, so it differs from\n\
658 `user-login-name' when running under `su'.")
661 /* Set up the user name info if we didn't do it before.
662 (That can happen if Emacs is dumpable
663 but you decide to run `temacs -l loadup' and not dump. */
664 if (INTEGERP (Vuser_login_name
))
666 return Vuser_real_login_name
;
669 DEFUN ("user-uid", Fuser_uid
, Suser_uid
, 0, 0, 0,
670 "Return the effective uid of Emacs, as an integer.")
673 return make_number (geteuid ());
676 DEFUN ("user-real-uid", Fuser_real_uid
, Suser_real_uid
, 0, 0, 0,
677 "Return the real uid of Emacs, as an integer.")
680 return make_number (getuid ());
683 DEFUN ("user-full-name", Fuser_full_name
, Suser_full_name
, 0, 1, 0,
684 "Return the full name of the user logged in, as a string.\n\
685 If optional argument UID is an integer, return the full name of the user\n\
686 with that uid, or \"unknown\" if there is no such user.\n\
687 If UID is a string, return the full name of the user with that login\n\
688 name, or \"unknown\" if no such user could be found.")
693 register unsigned char *p
, *q
;
694 extern char *index ();
698 return Vuser_full_name
;
699 else if (NUMBERP (uid
))
700 pw
= (struct passwd
*) getpwuid (XINT (uid
));
701 else if (STRINGP (uid
))
702 pw
= (struct passwd
*) getpwnam (XSTRING (uid
)->data
);
704 error ("Invalid UID specification");
709 p
= (unsigned char *) USER_FULL_NAME
;
710 /* Chop off everything after the first comma. */
711 q
= (unsigned char *) index (p
, ',');
712 full
= make_string (p
, q
? q
- p
: strlen (p
));
714 #ifdef AMPERSAND_FULL_NAME
715 p
= XSTRING (full
)->data
;
716 q
= (unsigned char *) index (p
, '&');
717 /* Substitute the login name for the &, upcasing the first character. */
720 register unsigned char *r
;
723 login
= Fuser_login_name (make_number (pw
->pw_uid
));
724 r
= (unsigned char *) alloca (strlen (p
) + XSTRING (login
)->size
+ 1);
727 strcat (r
, XSTRING (login
)->data
);
728 r
[q
- p
] = UPCASE (r
[q
- p
]);
730 full
= build_string (r
);
732 #endif /* AMPERSAND_FULL_NAME */
737 DEFUN ("system-name", Fsystem_name
, Ssystem_name
, 0, 0, 0,
738 "Return the name of the machine you are running on, as a string.")
744 /* For the benefit of callers who don't want to include lisp.h */
748 if (STRINGP (Vsystem_name
))
749 return (char *) XSTRING (Vsystem_name
)->data
;
754 DEFUN ("emacs-pid", Femacs_pid
, Semacs_pid
, 0, 0, 0,
755 "Return the process ID of Emacs, as an integer.")
758 return make_number (getpid ());
761 DEFUN ("current-time", Fcurrent_time
, Scurrent_time
, 0, 0, 0,
762 "Return the current time, as the number of seconds since 1970-01-01 00:00:00.\n\
763 The time is returned as a list of three integers. The first has the\n\
764 most significant 16 bits of the seconds, while the second has the\n\
765 least significant 16 bits. The third integer gives the microsecond\n\
768 The microsecond count is zero on systems that do not provide\n\
769 resolution finer than a second.")
773 Lisp_Object result
[3];
776 XSETINT (result
[0], (EMACS_SECS (t
) >> 16) & 0xffff);
777 XSETINT (result
[1], (EMACS_SECS (t
) >> 0) & 0xffff);
778 XSETINT (result
[2], EMACS_USECS (t
));
780 return Flist (3, result
);
785 lisp_time_argument (specified_time
, result
)
786 Lisp_Object specified_time
;
789 if (NILP (specified_time
))
790 return time (result
) != -1;
793 Lisp_Object high
, low
;
794 high
= Fcar (specified_time
);
795 CHECK_NUMBER (high
, 0);
796 low
= Fcdr (specified_time
);
799 CHECK_NUMBER (low
, 0);
800 *result
= (XINT (high
) << 16) + (XINT (low
) & 0xffff);
801 return *result
>> 16 == XINT (high
);
806 DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
807 "Use FORMAT-STRING to format the time TIME, or now if omitted.\n\
808 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as returned by\n\
809 `current-time' or `file-attributes'.\n\
810 The third, optional, argument UNIVERSAL, if non-nil, means describe TIME\n\
811 as Universal Time; nil means describe TIME in the local time zone.\n\
812 The value is a copy of FORMAT-STRING, but with certain constructs replaced\n\
813 by text that describes the specified date and time in TIME:\n\
815 %Y is the year, %y within the century, %C the century.\n\
816 %G is the year corresponding to the ISO week, %g within the century.\n\
817 %m is the numeric month.\n\
818 %b and %h are the locale's abbreviated month name, %B the full name.\n\
819 %d is the day of the month, zero-padded, %e is blank-padded.\n\
820 %u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6.\n\
821 %a is the locale's abbreviated name of the day of week, %A the full name.\n\
822 %U is the week number starting on Sunday, %W starting on Monday,\n\
823 %V according to ISO 8601.\n\
824 %j is the day of the year.\n\
826 %H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H\n\
827 only blank-padded, %l is like %I blank-padded.\n\
828 %p is the locale's equivalent of either AM or PM.\n\
831 %Z is the time zone name, %z is the numeric form.\n\
832 %s is the number of seconds since 1970-01-01 00:00:00 +0000.\n\
834 %c is the locale's date and time format.\n\
835 %x is the locale's \"preferred\" date format.\n\
836 %D is like \"%m/%d/%y\".\n\
838 %R is like \"%H:%M\", %T is like \"%H:%M:%S\", %r is like \"%I:%M:%S %p\".\n\
839 %X is the locale's \"preferred\" time format.\n\
841 Finally, %n is a newline, %t is a tab, %% is a literal %.\n\
843 Certain flags and modifiers are available with some format controls.\n\
844 The flags are `_' and `-'. For certain characters X, %_X is like %X,\n\
845 but padded with blanks; %-X is like %X, but without padding.\n\
846 %NX (where N stands for an integer) is like %X,\n\
847 but takes up at least N (a number) positions.\n\
848 The modifiers are `E' and `O'. For certain characters X,\n\
849 %EX is a locale's alternative version of %X;\n\
850 %OX is like %X, but uses the locale's number symbols.\n\
852 For example, to produce full ISO 8601 format, use \"%Y-%m-%dT%T%z\".")
853 (format_string, time, universal)
856 DEFUN ("format-time-string", Fformat_time_string
, Sformat_time_string
, 1, 3, 0,
857 0 /* See immediately above */)
858 (format_string
, time
, universal
)
859 Lisp_Object format_string
, time
, universal
;
864 CHECK_STRING (format_string
, 1);
866 if (! lisp_time_argument (time
, &value
))
867 error ("Invalid time specification");
869 /* This is probably enough. */
870 size
= STRING_BYTES (XSTRING (format_string
)) * 6 + 50;
874 char *buf
= (char *) alloca (size
+ 1);
878 result
= emacs_strftime (buf
, size
, XSTRING (format_string
)->data
,
879 (NILP (universal
) ? localtime (&value
)
881 if ((result
> 0 && result
< size
) || (result
== 0 && buf
[0] == '\0'))
882 return build_string (buf
);
884 /* If buffer was too small, make it bigger and try again. */
885 result
= emacs_strftime (NULL
, 0x7fffffff, XSTRING (format_string
)->data
,
886 (NILP (universal
) ? localtime (&value
)
892 DEFUN ("decode-time", Fdecode_time
, Sdecode_time
, 0, 1, 0,
893 "Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).\n\
894 The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)\n\
895 or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'\n\
896 to use the current time. The list has the following nine members:\n\
897 SEC is an integer between 0 and 60; SEC is 60 for a leap second, which\n\
898 only some operating systems support. MINUTE is an integer between 0 and 59.\n\
899 HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.\n\
900 MONTH is an integer between 1 and 12. YEAR is an integer indicating the\n\
901 four-digit year. DOW is the day of week, an integer between 0 and 6, where\n\
902 0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.\n\
903 ZONE is an integer indicating the number of seconds east of Greenwich.\n\
904 \(Note that Common Lisp has different meanings for DOW and ZONE.)")
906 Lisp_Object specified_time
;
910 struct tm
*decoded_time
;
911 Lisp_Object list_args
[9];
913 if (! lisp_time_argument (specified_time
, &time_spec
))
914 error ("Invalid time specification");
916 decoded_time
= localtime (&time_spec
);
917 XSETFASTINT (list_args
[0], decoded_time
->tm_sec
);
918 XSETFASTINT (list_args
[1], decoded_time
->tm_min
);
919 XSETFASTINT (list_args
[2], decoded_time
->tm_hour
);
920 XSETFASTINT (list_args
[3], decoded_time
->tm_mday
);
921 XSETFASTINT (list_args
[4], decoded_time
->tm_mon
+ 1);
922 XSETINT (list_args
[5], decoded_time
->tm_year
+ 1900);
923 XSETFASTINT (list_args
[6], decoded_time
->tm_wday
);
924 list_args
[7] = (decoded_time
->tm_isdst
)? Qt
: Qnil
;
926 /* Make a copy, in case gmtime modifies the struct. */
927 save_tm
= *decoded_time
;
928 decoded_time
= gmtime (&time_spec
);
929 if (decoded_time
== 0)
932 XSETINT (list_args
[8], tm_diff (&save_tm
, decoded_time
));
933 return Flist (9, list_args
);
936 DEFUN ("encode-time", Fencode_time
, Sencode_time
, 6, MANY
, 0,
937 "Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.\n\
938 This is the reverse operation of `decode-time', which see.\n\
939 ZONE defaults to the current time zone rule. This can\n\
940 be a string or t (as from `set-time-zone-rule'), or it can be a list\n\
941 \(as from `current-time-zone') or an integer (as from `decode-time')\n\
942 applied without consideration for daylight savings time.\n\
944 You can pass more than 7 arguments; then the first six arguments\n\
945 are used as SECOND through YEAR, and the *last* argument is used as ZONE.\n\
946 The intervening arguments are ignored.\n\
947 This feature lets (apply 'encode-time (decode-time ...)) work.\n\
949 Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;\n\
950 for example, a DAY of 0 means the day preceding the given month.\n\
951 Year numbers less than 100 are treated just like other year numbers.\n\
952 If you want them to stand for years in this century, you must do that yourself.")
955 register Lisp_Object
*args
;
959 Lisp_Object zone
= (nargs
> 6 ? args
[nargs
- 1] : Qnil
);
961 CHECK_NUMBER (args
[0], 0); /* second */
962 CHECK_NUMBER (args
[1], 1); /* minute */
963 CHECK_NUMBER (args
[2], 2); /* hour */
964 CHECK_NUMBER (args
[3], 3); /* day */
965 CHECK_NUMBER (args
[4], 4); /* month */
966 CHECK_NUMBER (args
[5], 5); /* year */
968 tm
.tm_sec
= XINT (args
[0]);
969 tm
.tm_min
= XINT (args
[1]);
970 tm
.tm_hour
= XINT (args
[2]);
971 tm
.tm_mday
= XINT (args
[3]);
972 tm
.tm_mon
= XINT (args
[4]) - 1;
973 tm
.tm_year
= XINT (args
[5]) - 1900;
984 char **oldenv
= environ
, **newenv
;
988 else if (STRINGP (zone
))
989 tzstring
= (char *) XSTRING (zone
)->data
;
990 else if (INTEGERP (zone
))
992 int abszone
= abs (XINT (zone
));
993 sprintf (tzbuf
, "XXX%s%d:%02d:%02d", "-" + (XINT (zone
) < 0),
994 abszone
/ (60*60), (abszone
/60) % 60, abszone
% 60);
998 error ("Invalid time zone specification");
1000 /* Set TZ before calling mktime; merely adjusting mktime's returned
1001 value doesn't suffice, since that would mishandle leap seconds. */
1002 set_time_zone_rule (tzstring
);
1004 time
= mktime (&tm
);
1006 /* Restore TZ to previous value. */
1010 #ifdef LOCALTIME_CACHE
1015 if (time
== (time_t) -1)
1016 error ("Specified time is not representable");
1018 return make_time (time
);
1021 DEFUN ("current-time-string", Fcurrent_time_string
, Scurrent_time_string
, 0, 1, 0,
1022 "Return the current time, as a human-readable string.\n\
1023 Programs can use this function to decode a time,\n\
1024 since the number of columns in each field is fixed.\n\
1025 The format is `Sun Sep 16 01:03:52 1973'.\n\
1026 However, see also the functions `decode-time' and `format-time-string'\n\
1027 which provide a much more powerful and general facility.\n\
1029 If an argument is given, it specifies a time to format\n\
1030 instead of the current time. The argument should have the form:\n\
1033 (HIGH LOW . IGNORED).\n\
1034 Thus, you can use times obtained from `current-time'\n\
1035 and from `file-attributes'.")
1037 Lisp_Object specified_time
;
1043 if (! lisp_time_argument (specified_time
, &value
))
1045 tem
= (char *) ctime (&value
);
1047 strncpy (buf
, tem
, 24);
1050 return build_string (buf
);
1053 #define TM_YEAR_BASE 1900
1055 /* Yield A - B, measured in seconds.
1056 This function is copied from the GNU C Library. */
1061 /* Compute intervening leap days correctly even if year is negative.
1062 Take care to avoid int overflow in leap day calculations,
1063 but it's OK to assume that A and B are close to each other. */
1064 int a4
= (a
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (a
->tm_year
& 3);
1065 int b4
= (b
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (b
->tm_year
& 3);
1066 int a100
= a4
/ 25 - (a4
% 25 < 0);
1067 int b100
= b4
/ 25 - (b4
% 25 < 0);
1068 int a400
= a100
>> 2;
1069 int b400
= b100
>> 2;
1070 int intervening_leap_days
= (a4
- b4
) - (a100
- b100
) + (a400
- b400
);
1071 int years
= a
->tm_year
- b
->tm_year
;
1072 int days
= (365 * years
+ intervening_leap_days
1073 + (a
->tm_yday
- b
->tm_yday
));
1074 return (60 * (60 * (24 * days
+ (a
->tm_hour
- b
->tm_hour
))
1075 + (a
->tm_min
- b
->tm_min
))
1076 + (a
->tm_sec
- b
->tm_sec
));
1079 DEFUN ("current-time-zone", Fcurrent_time_zone
, Scurrent_time_zone
, 0, 1, 0,
1080 "Return the offset and name for the local time zone.\n\
1081 This returns a list of the form (OFFSET NAME).\n\
1082 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).\n\
1083 A negative value means west of Greenwich.\n\
1084 NAME is a string giving the name of the time zone.\n\
1085 If an argument is given, it specifies when the time zone offset is determined\n\
1086 instead of using the current time. The argument should have the form:\n\
1089 (HIGH LOW . IGNORED).\n\
1090 Thus, you can use times obtained from `current-time'\n\
1091 and from `file-attributes'.\n\
1093 Some operating systems cannot provide all this information to Emacs;\n\
1094 in this case, `current-time-zone' returns a list containing nil for\n\
1095 the data it can't find.")
1097 Lisp_Object specified_time
;
1102 if (lisp_time_argument (specified_time
, &value
)
1103 && (t
= gmtime (&value
)) != 0)
1109 gmt
= *t
; /* Make a copy, in case localtime modifies *t. */
1110 t
= localtime (&value
);
1111 offset
= tm_diff (t
, &gmt
);
1115 s
= (char *)t
->tm_zone
;
1116 #else /* not HAVE_TM_ZONE */
1118 if (t
->tm_isdst
== 0 || t
->tm_isdst
== 1)
1119 s
= tzname
[t
->tm_isdst
];
1121 #endif /* not HAVE_TM_ZONE */
1124 /* No local time zone name is available; use "+-NNNN" instead. */
1125 int am
= (offset
< 0 ? -offset
: offset
) / 60;
1126 sprintf (buf
, "%c%02d%02d", (offset
< 0 ? '-' : '+'), am
/60, am
%60);
1129 return Fcons (make_number (offset
), Fcons (build_string (s
), Qnil
));
1132 return Fmake_list (make_number (2), Qnil
);
1135 /* This holds the value of `environ' produced by the previous
1136 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
1137 has never been called. */
1138 static char **environbuf
;
1140 DEFUN ("set-time-zone-rule", Fset_time_zone_rule
, Sset_time_zone_rule
, 1, 1, 0,
1141 "Set the local time zone using TZ, a string specifying a time zone rule.\n\
1142 If TZ is nil, use implementation-defined default time zone information.\n\
1143 If TZ is t, use Universal Time.")
1151 else if (EQ (tz
, Qt
))
1155 CHECK_STRING (tz
, 0);
1156 tzstring
= (char *) XSTRING (tz
)->data
;
1159 set_time_zone_rule (tzstring
);
1162 environbuf
= environ
;
1167 #ifdef LOCALTIME_CACHE
1169 /* These two values are known to load tz files in buggy implementations,
1170 i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2.
1171 Their values shouldn't matter in non-buggy implementations.
1172 We don't use string literals for these strings,
1173 since if a string in the environment is in readonly
1174 storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
1175 See Sun bugs 1113095 and 1114114, ``Timezone routines
1176 improperly modify environment''. */
1178 static char set_time_zone_rule_tz1
[] = "TZ=GMT+0";
1179 static char set_time_zone_rule_tz2
[] = "TZ=GMT+1";
1183 /* Set the local time zone rule to TZSTRING.
1184 This allocates memory into `environ', which it is the caller's
1185 responsibility to free. */
1187 set_time_zone_rule (tzstring
)
1191 char **from
, **to
, **newenv
;
1193 /* Make the ENVIRON vector longer with room for TZSTRING. */
1194 for (from
= environ
; *from
; from
++)
1196 envptrs
= from
- environ
+ 2;
1197 newenv
= to
= (char **) xmalloc (envptrs
* sizeof (char *)
1198 + (tzstring
? strlen (tzstring
) + 4 : 0));
1200 /* Add TZSTRING to the end of environ, as a value for TZ. */
1203 char *t
= (char *) (to
+ envptrs
);
1205 strcat (t
, tzstring
);
1209 /* Copy the old environ vector elements into NEWENV,
1210 but don't copy the TZ variable.
1211 So we have only one definition of TZ, which came from TZSTRING. */
1212 for (from
= environ
; *from
; from
++)
1213 if (strncmp (*from
, "TZ=", 3) != 0)
1219 /* If we do have a TZSTRING, NEWENV points to the vector slot where
1220 the TZ variable is stored. If we do not have a TZSTRING,
1221 TO points to the vector slot which has the terminating null. */
1223 #ifdef LOCALTIME_CACHE
1225 /* In SunOS 4.1.3_U1 and 4.1.4, if TZ has a value like
1226 "US/Pacific" that loads a tz file, then changes to a value like
1227 "XXX0" that does not load a tz file, and then changes back to
1228 its original value, the last change is (incorrectly) ignored.
1229 Also, if TZ changes twice in succession to values that do
1230 not load a tz file, tzset can dump core (see Sun bug#1225179).
1231 The following code works around these bugs. */
1235 /* Temporarily set TZ to a value that loads a tz file
1236 and that differs from tzstring. */
1238 *newenv
= (strcmp (tzstring
, set_time_zone_rule_tz1
+ 3) == 0
1239 ? set_time_zone_rule_tz2
: set_time_zone_rule_tz1
);
1245 /* The implied tzstring is unknown, so temporarily set TZ to
1246 two different values that each load a tz file. */
1247 *to
= set_time_zone_rule_tz1
;
1250 *to
= set_time_zone_rule_tz2
;
1255 /* Now TZ has the desired value, and tzset can be invoked safely. */
1262 /* Insert NARGS Lisp objects in the array ARGS by calling INSERT_FUNC
1263 (if a type of object is Lisp_Int) or INSERT_FROM_STRING_FUNC (if a
1264 type of object is Lisp_String). INHERIT is passed to
1265 INSERT_FROM_STRING_FUNC as the last argument. */
1268 general_insert_function (insert_func
, insert_from_string_func
,
1269 inherit
, nargs
, args
)
1270 void (*insert_func
) P_ ((unsigned char *, int));
1271 void (*insert_from_string_func
) P_ ((Lisp_Object
, int, int, int, int, int));
1273 register Lisp_Object
*args
;
1275 register int argnum
;
1276 register Lisp_Object val
;
1278 for (argnum
= 0; argnum
< nargs
; argnum
++)
1284 unsigned char workbuf
[4], *str
;
1287 if (!NILP (current_buffer
->enable_multibyte_characters
))
1288 len
= CHAR_STRING (XFASTINT (val
), workbuf
, str
);
1290 workbuf
[0] = XINT (val
), str
= workbuf
, len
= 1;
1291 (*insert_func
) (str
, len
);
1293 else if (STRINGP (val
))
1295 (*insert_from_string_func
) (val
, 0, 0,
1296 XSTRING (val
)->size
,
1297 STRING_BYTES (XSTRING (val
)),
1302 val
= wrong_type_argument (Qchar_or_string_p
, val
);
1316 /* Callers passing one argument to Finsert need not gcpro the
1317 argument "array", since the only element of the array will
1318 not be used after calling insert or insert_from_string, so
1319 we don't care if it gets trashed. */
1321 DEFUN ("insert", Finsert
, Sinsert
, 0, MANY
, 0,
1322 "Insert the arguments, either strings or characters, at point.\n\
1323 Point and before-insertion-markers move forward so that it ends up\n\
1324 after the inserted text.\n\
1325 Any other markers at the point of insertion remain before the text.")
1328 register Lisp_Object
*args
;
1330 general_insert_function (insert
, insert_from_string
, 0, nargs
, args
);
1334 DEFUN ("insert-and-inherit", Finsert_and_inherit
, Sinsert_and_inherit
,
1336 "Insert the arguments at point, inheriting properties from adjoining text.\n\
1337 Point and before-insertion-markers move forward so that it ends up\n\
1338 after the inserted text.\n\
1339 Any other markers at the point of insertion remain before the text.")
1342 register Lisp_Object
*args
;
1344 general_insert_function (insert_and_inherit
, insert_from_string
, 1,
1349 DEFUN ("insert-before-markers", Finsert_before_markers
, Sinsert_before_markers
, 0, MANY
, 0,
1350 "Insert strings or characters at point, relocating markers after the text.\n\
1351 Point and before-insertion-markers move forward so that it ends up\n\
1352 after the inserted text.\n\
1353 Any other markers at the point of insertion also end up after the text.")
1356 register Lisp_Object
*args
;
1358 general_insert_function (insert_before_markers
,
1359 insert_from_string_before_markers
, 0,
1364 DEFUN ("insert-before-markers-and-inherit", Finsert_and_inherit_before_markers
,
1365 Sinsert_and_inherit_before_markers
, 0, MANY
, 0,
1366 "Insert text at point, relocating markers and inheriting properties.\n\
1367 Point moves forward so that it ends up after the inserted text.\n\
1368 Any other markers at the point of insertion also end up after the text.")
1371 register Lisp_Object
*args
;
1373 general_insert_function (insert_before_markers_and_inherit
,
1374 insert_from_string_before_markers
, 1,
1379 DEFUN ("insert-char", Finsert_char
, Sinsert_char
, 2, 3, 0,
1380 "Insert COUNT (second arg) copies of CHARACTER (first arg).\n\
1381 Point and before-insertion-markers are affected as in the function `insert'.\n\
1382 Both arguments are required.\n\
1383 The optional third arg INHERIT, if non-nil, says to inherit text properties\n\
1384 from adjoining text, if those properties are sticky.")
1385 (character
, count
, inherit
)
1386 Lisp_Object character
, count
, inherit
;
1388 register unsigned char *string
;
1389 register int strlen
;
1392 unsigned char workbuf
[4], *str
;
1394 CHECK_NUMBER (character
, 0);
1395 CHECK_NUMBER (count
, 1);
1397 if (!NILP (current_buffer
->enable_multibyte_characters
))
1398 len
= CHAR_STRING (XFASTINT (character
), workbuf
, str
);
1400 workbuf
[0] = XFASTINT (character
), str
= workbuf
, len
= 1;
1401 n
= XINT (count
) * len
;
1404 strlen
= min (n
, 256 * len
);
1405 string
= (unsigned char *) alloca (strlen
);
1406 for (i
= 0; i
< strlen
; i
++)
1407 string
[i
] = str
[i
% len
];
1411 if (!NILP (inherit
))
1412 insert_and_inherit (string
, strlen
);
1414 insert (string
, strlen
);
1419 if (!NILP (inherit
))
1420 insert_and_inherit (string
, n
);
1428 /* Making strings from buffer contents. */
1430 /* Return a Lisp_String containing the text of the current buffer from
1431 START to END. If text properties are in use and the current buffer
1432 has properties in the range specified, the resulting string will also
1433 have them, if PROPS is nonzero.
1435 We don't want to use plain old make_string here, because it calls
1436 make_uninit_string, which can cause the buffer arena to be
1437 compacted. make_string has no way of knowing that the data has
1438 been moved, and thus copies the wrong data into the string. This
1439 doesn't effect most of the other users of make_string, so it should
1440 be left as is. But we should use this function when conjuring
1441 buffer substrings. */
1444 make_buffer_string (start
, end
, props
)
1448 int start_byte
= CHAR_TO_BYTE (start
);
1449 int end_byte
= CHAR_TO_BYTE (end
);
1451 return make_buffer_string_both (start
, start_byte
, end
, end_byte
, props
);
1454 /* Return a Lisp_String containing the text of the current buffer from
1455 START / START_BYTE to END / END_BYTE.
1457 If text properties are in use and the current buffer
1458 has properties in the range specified, the resulting string will also
1459 have them, if PROPS is nonzero.
1461 We don't want to use plain old make_string here, because it calls
1462 make_uninit_string, which can cause the buffer arena to be
1463 compacted. make_string has no way of knowing that the data has
1464 been moved, and thus copies the wrong data into the string. This
1465 doesn't effect most of the other users of make_string, so it should
1466 be left as is. But we should use this function when conjuring
1467 buffer substrings. */
1470 make_buffer_string_both (start
, start_byte
, end
, end_byte
, props
)
1471 int start
, start_byte
, end
, end_byte
;
1474 Lisp_Object result
, tem
, tem1
;
1476 if (start
< GPT
&& GPT
< end
)
1479 result
= make_uninit_multibyte_string (end
- start
, end_byte
- start_byte
);
1480 bcopy (BYTE_POS_ADDR (start_byte
), XSTRING (result
)->data
,
1481 end_byte
- start_byte
);
1483 /* If desired, update and copy the text properties. */
1484 #ifdef USE_TEXT_PROPERTIES
1487 update_buffer_properties (start
, end
);
1489 tem
= Fnext_property_change (make_number (start
), Qnil
, make_number (end
));
1490 tem1
= Ftext_properties_at (make_number (start
), Qnil
);
1492 if (XINT (tem
) != end
|| !NILP (tem1
))
1493 copy_intervals_to_string (result
, current_buffer
, start
,
1501 /* Call Vbuffer_access_fontify_functions for the range START ... END
1502 in the current buffer, if necessary. */
1505 update_buffer_properties (start
, end
)
1508 #ifdef USE_TEXT_PROPERTIES
1509 /* If this buffer has some access functions,
1510 call them, specifying the range of the buffer being accessed. */
1511 if (!NILP (Vbuffer_access_fontify_functions
))
1513 Lisp_Object args
[3];
1516 args
[0] = Qbuffer_access_fontify_functions
;
1517 XSETINT (args
[1], start
);
1518 XSETINT (args
[2], end
);
1520 /* But don't call them if we can tell that the work
1521 has already been done. */
1522 if (!NILP (Vbuffer_access_fontified_property
))
1524 tem
= Ftext_property_any (args
[1], args
[2],
1525 Vbuffer_access_fontified_property
,
1528 Frun_hook_with_args (3, args
);
1531 Frun_hook_with_args (3, args
);
1536 DEFUN ("buffer-substring", Fbuffer_substring
, Sbuffer_substring
, 2, 2, 0,
1537 "Return the contents of part of the current buffer as a string.\n\
1538 The two arguments START and END are character positions;\n\
1539 they can be in either order.")
1541 Lisp_Object start
, end
;
1545 validate_region (&start
, &end
);
1549 return make_buffer_string (b
, e
, 1);
1552 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties
,
1553 Sbuffer_substring_no_properties
, 2, 2, 0,
1554 "Return the characters of part of the buffer, without the text properties.\n\
1555 The two arguments START and END are character positions;\n\
1556 they can be in either order.")
1558 Lisp_Object start
, end
;
1562 validate_region (&start
, &end
);
1566 return make_buffer_string (b
, e
, 0);
1569 DEFUN ("buffer-string", Fbuffer_string
, Sbuffer_string
, 0, 0, 0,
1570 "Return the contents of the current buffer as a string.\n\
1571 If narrowing is in effect, this function returns only the visible part\n\
1575 return make_buffer_string (BEGV
, ZV
, 1);
1578 DEFUN ("insert-buffer-substring", Finsert_buffer_substring
, Sinsert_buffer_substring
,
1580 "Insert before point a substring of the contents of buffer BUFFER.\n\
1581 BUFFER may be a buffer or a buffer name.\n\
1582 Arguments START and END are character numbers specifying the substring.\n\
1583 They default to the beginning and the end of BUFFER.")
1585 Lisp_Object buf
, start
, end
;
1587 register int b
, e
, temp
;
1588 register struct buffer
*bp
, *obuf
;
1591 buffer
= Fget_buffer (buf
);
1594 bp
= XBUFFER (buffer
);
1595 if (NILP (bp
->name
))
1596 error ("Selecting deleted buffer");
1602 CHECK_NUMBER_COERCE_MARKER (start
, 0);
1609 CHECK_NUMBER_COERCE_MARKER (end
, 1);
1614 temp
= b
, b
= e
, e
= temp
;
1616 if (!(BUF_BEGV (bp
) <= b
&& e
<= BUF_ZV (bp
)))
1617 args_out_of_range (start
, end
);
1619 obuf
= current_buffer
;
1620 set_buffer_internal_1 (bp
);
1621 update_buffer_properties (b
, e
);
1622 set_buffer_internal_1 (obuf
);
1624 insert_from_buffer (bp
, b
, e
- b
, 0);
1628 DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings
, Scompare_buffer_substrings
,
1630 "Compare two substrings of two buffers; return result as number.\n\
1631 the value is -N if first string is less after N-1 chars,\n\
1632 +N if first string is greater after N-1 chars, or 0 if strings match.\n\
1633 Each substring is represented as three arguments: BUFFER, START and END.\n\
1634 That makes six args in all, three for each substring.\n\n\
1635 The value of `case-fold-search' in the current buffer\n\
1636 determines whether case is significant or ignored.")
1637 (buffer1
, start1
, end1
, buffer2
, start2
, end2
)
1638 Lisp_Object buffer1
, start1
, end1
, buffer2
, start2
, end2
;
1640 register int begp1
, endp1
, begp2
, endp2
, temp
, len1
, len2
, length
, i
;
1641 register struct buffer
*bp1
, *bp2
;
1642 register Lisp_Object
*trt
1643 = (!NILP (current_buffer
->case_fold_search
)
1644 ? XCHAR_TABLE (current_buffer
->case_canon_table
)->contents
: 0);
1646 int beg1_byte
, beg2_byte
;
1648 /* Find the first buffer and its substring. */
1651 bp1
= current_buffer
;
1655 buf1
= Fget_buffer (buffer1
);
1658 bp1
= XBUFFER (buf1
);
1659 if (NILP (bp1
->name
))
1660 error ("Selecting deleted buffer");
1664 begp1
= BUF_BEGV (bp1
);
1667 CHECK_NUMBER_COERCE_MARKER (start1
, 1);
1668 begp1
= XINT (start1
);
1671 endp1
= BUF_ZV (bp1
);
1674 CHECK_NUMBER_COERCE_MARKER (end1
, 2);
1675 endp1
= XINT (end1
);
1679 temp
= begp1
, begp1
= endp1
, endp1
= temp
;
1681 if (!(BUF_BEGV (bp1
) <= begp1
1683 && endp1
<= BUF_ZV (bp1
)))
1684 args_out_of_range (start1
, end1
);
1686 /* Likewise for second substring. */
1689 bp2
= current_buffer
;
1693 buf2
= Fget_buffer (buffer2
);
1696 bp2
= XBUFFER (buf2
);
1697 if (NILP (bp2
->name
))
1698 error ("Selecting deleted buffer");
1702 begp2
= BUF_BEGV (bp2
);
1705 CHECK_NUMBER_COERCE_MARKER (start2
, 4);
1706 begp2
= XINT (start2
);
1709 endp2
= BUF_ZV (bp2
);
1712 CHECK_NUMBER_COERCE_MARKER (end2
, 5);
1713 endp2
= XINT (end2
);
1717 temp
= begp2
, begp2
= endp2
, endp2
= temp
;
1719 if (!(BUF_BEGV (bp2
) <= begp2
1721 && endp2
<= BUF_ZV (bp2
)))
1722 args_out_of_range (start2
, end2
);
1724 beg1_byte
= buf_charpos_to_bytepos (bp1
, begp1
);
1725 beg2_byte
= buf_charpos_to_bytepos (bp2
, begp2
);
1726 len1
= buf_charpos_to_bytepos (bp1
, endp1
) - begp1
;
1727 len2
= buf_charpos_to_bytepos (bp2
, endp2
) - begp2
;
1732 for (i
= 0; i
< length
; i
++)
1734 unsigned char *p1
= BUF_BYTE_ADDRESS (bp1
, beg1_byte
+ i
);
1736 int c2
= *BUF_BYTE_ADDRESS (bp2
, beg2_byte
+ i
);
1738 /* If a character begins here,
1739 count the previous character now. */
1741 && (NILP (current_buffer
->enable_multibyte_characters
)
1742 || CHAR_HEAD_P (*p1
)))
1747 c1
= XINT (trt
[c1
]);
1748 c2
= XINT (trt
[c2
]);
1751 return make_number (- 1 - chars
);
1753 return make_number (chars
+ 1);
1756 /* The strings match as far as they go.
1757 If one is shorter, that one is less. */
1759 return make_number (chars
+ 1);
1760 else if (length
< len2
)
1761 return make_number (- chars
- 1);
1763 /* Same length too => they are equal. */
1764 return make_number (0);
1768 subst_char_in_region_unwind (arg
)
1771 return current_buffer
->undo_list
= arg
;
1775 subst_char_in_region_unwind_1 (arg
)
1778 return current_buffer
->filename
= arg
;
1781 DEFUN ("subst-char-in-region", Fsubst_char_in_region
,
1782 Ssubst_char_in_region
, 4, 5, 0,
1783 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\
1784 If optional arg NOUNDO is non-nil, don't record this change for undo\n\
1785 and don't mark the buffer as really changed.\n\
1786 Both characters must have the same length of multi-byte form.")
1787 (start
, end
, fromchar
, tochar
, noundo
)
1788 Lisp_Object start
, end
, fromchar
, tochar
, noundo
;
1790 register int pos
, pos_byte
, stop
, i
, len
, end_byte
;
1792 unsigned char fromwork
[4], *fromstr
, towork
[4], *tostr
, *p
;
1793 int count
= specpdl_ptr
- specpdl
;
1795 validate_region (&start
, &end
);
1796 CHECK_NUMBER (fromchar
, 2);
1797 CHECK_NUMBER (tochar
, 3);
1799 if (! NILP (current_buffer
->enable_multibyte_characters
))
1801 len
= CHAR_STRING (XFASTINT (fromchar
), fromwork
, fromstr
);
1802 if (CHAR_STRING (XFASTINT (tochar
), towork
, tostr
) != len
)
1803 error ("Characters in subst-char-in-region have different byte-lengths");
1808 fromwork
[0] = XFASTINT (fromchar
), fromstr
= fromwork
;
1809 towork
[0] = XFASTINT (tochar
), tostr
= towork
;
1813 pos_byte
= CHAR_TO_BYTE (pos
);
1814 stop
= CHAR_TO_BYTE (XINT (end
));
1817 /* If we don't want undo, turn off putting stuff on the list.
1818 That's faster than getting rid of things,
1819 and it prevents even the entry for a first change.
1820 Also inhibit locking the file. */
1823 record_unwind_protect (subst_char_in_region_unwind
,
1824 current_buffer
->undo_list
);
1825 current_buffer
->undo_list
= Qt
;
1826 /* Don't do file-locking. */
1827 record_unwind_protect (subst_char_in_region_unwind_1
,
1828 current_buffer
->filename
);
1829 current_buffer
->filename
= Qnil
;
1832 if (pos_byte
< GPT_BYTE
)
1833 stop
= min (stop
, GPT_BYTE
);
1836 if (pos_byte
>= stop
)
1838 if (pos_byte
>= end_byte
) break;
1841 p
= BYTE_POS_ADDR (pos_byte
);
1842 if (p
[0] == fromstr
[0]
1844 || (p
[1] == fromstr
[1]
1845 && (len
== 2 || (p
[2] == fromstr
[2]
1846 && (len
== 3 || p
[3] == fromstr
[3]))))))
1850 modify_region (current_buffer
, XINT (start
), XINT (end
));
1852 if (! NILP (noundo
))
1854 if (MODIFF
- 1 == SAVE_MODIFF
)
1856 if (MODIFF
- 1 == current_buffer
->auto_save_modified
)
1857 current_buffer
->auto_save_modified
++;
1864 record_change (pos
, 1);
1865 for (i
= 0; i
< len
; i
++) *p
++ = tostr
[i
];
1867 INC_BOTH (pos
, pos_byte
);
1871 signal_after_change (XINT (start
),
1872 XINT (end
) - XINT (start
), XINT (end
) - XINT (start
));
1874 unbind_to (count
, Qnil
);
1878 DEFUN ("translate-region", Ftranslate_region
, Stranslate_region
, 3, 3, 0,
1879 "From START to END, translate characters according to TABLE.\n\
1880 TABLE is a string; the Nth character in it is the mapping\n\
1881 for the character with code N.\n\
1882 This function does not alter multibyte characters.\n\
1883 It returns the number of characters changed.")
1887 register Lisp_Object table
;
1889 register int pos_byte
, stop
; /* Limits of the region. */
1890 register unsigned char *tt
; /* Trans table. */
1891 register int nc
; /* New character. */
1892 int cnt
; /* Number of changes made. */
1893 int size
; /* Size of translate table. */
1896 validate_region (&start
, &end
);
1897 CHECK_STRING (table
, 2);
1899 size
= STRING_BYTES (XSTRING (table
));
1900 tt
= XSTRING (table
)->data
;
1902 pos_byte
= CHAR_TO_BYTE (XINT (start
));
1903 stop
= CHAR_TO_BYTE (XINT (end
));
1904 modify_region (current_buffer
, XINT (start
), XINT (end
));
1908 for (; pos_byte
< stop
; )
1910 register unsigned char *p
= BYTE_POS_ADDR (pos_byte
);
1914 oc
= STRING_CHAR_AND_LENGTH (p
, stop
- pos_byte
, len
);
1915 if (oc
< size
&& len
== 1)
1920 record_change (pos
, 1);
1922 signal_after_change (pos
, 1, 1);
1930 return make_number (cnt
);
1933 DEFUN ("delete-region", Fdelete_region
, Sdelete_region
, 2, 2, "r",
1934 "Delete the text between point and mark.\n\
1935 When called from a program, expects two arguments,\n\
1936 positions (integers or markers) specifying the stretch to be deleted.")
1938 Lisp_Object start
, end
;
1940 validate_region (&start
, &end
);
1941 del_range (XINT (start
), XINT (end
));
1945 DEFUN ("widen", Fwiden
, Swiden
, 0, 0, "",
1946 "Remove restrictions (narrowing) from current buffer.\n\
1947 This allows the buffer's full text to be seen and edited.")
1950 if (BEG
!= BEGV
|| Z
!= ZV
)
1951 current_buffer
->clip_changed
= 1;
1953 BEGV_BYTE
= BEG_BYTE
;
1954 SET_BUF_ZV_BOTH (current_buffer
, Z
, Z_BYTE
);
1955 /* Changing the buffer bounds invalidates any recorded current column. */
1956 invalidate_current_column ();
1960 DEFUN ("narrow-to-region", Fnarrow_to_region
, Snarrow_to_region
, 2, 2, "r",
1961 "Restrict editing in this buffer to the current region.\n\
1962 The rest of the text becomes temporarily invisible and untouchable\n\
1963 but is not deleted; if you save the buffer in a file, the invisible\n\
1964 text is included in the file. \\[widen] makes all visible again.\n\
1965 See also `save-restriction'.\n\
1967 When calling from a program, pass two arguments; positions (integers\n\
1968 or markers) bounding the text that should remain visible.")
1970 register Lisp_Object start
, end
;
1972 CHECK_NUMBER_COERCE_MARKER (start
, 0);
1973 CHECK_NUMBER_COERCE_MARKER (end
, 1);
1975 if (XINT (start
) > XINT (end
))
1978 tem
= start
; start
= end
; end
= tem
;
1981 if (!(BEG
<= XINT (start
) && XINT (start
) <= XINT (end
) && XINT (end
) <= Z
))
1982 args_out_of_range (start
, end
);
1984 if (BEGV
!= XFASTINT (start
) || ZV
!= XFASTINT (end
))
1985 current_buffer
->clip_changed
= 1;
1987 SET_BUF_BEGV (current_buffer
, XFASTINT (start
));
1988 SET_BUF_ZV (current_buffer
, XFASTINT (end
));
1989 if (PT
< XFASTINT (start
))
1990 SET_PT (XFASTINT (start
));
1991 if (PT
> XFASTINT (end
))
1992 SET_PT (XFASTINT (end
));
1993 /* Changing the buffer bounds invalidates any recorded current column. */
1994 invalidate_current_column ();
1999 save_restriction_save ()
2001 register Lisp_Object bottom
, top
;
2002 /* Note: I tried using markers here, but it does not win
2003 because insertion at the end of the saved region
2004 does not advance mh and is considered "outside" the saved region. */
2005 XSETFASTINT (bottom
, BEGV
- BEG
);
2006 XSETFASTINT (top
, Z
- ZV
);
2008 return Fcons (Fcurrent_buffer (), Fcons (bottom
, top
));
2012 save_restriction_restore (data
)
2015 register struct buffer
*buf
;
2016 register int newhead
, newtail
;
2017 register Lisp_Object tem
;
2020 buf
= XBUFFER (XCONS (data
)->car
);
2022 data
= XCONS (data
)->cdr
;
2024 tem
= XCONS (data
)->car
;
2025 newhead
= XINT (tem
);
2026 tem
= XCONS (data
)->cdr
;
2027 newtail
= XINT (tem
);
2028 if (newhead
+ newtail
> BUF_Z (buf
) - BUF_BEG (buf
))
2034 obegv
= BUF_BEGV (buf
);
2037 SET_BUF_BEGV (buf
, BUF_BEG (buf
) + newhead
);
2038 SET_BUF_ZV (buf
, BUF_Z (buf
) - newtail
);
2040 if (obegv
!= BUF_BEGV (buf
) || ozv
!= BUF_ZV (buf
))
2041 current_buffer
->clip_changed
= 1;
2043 /* If point is outside the new visible range, move it inside. */
2044 SET_BUF_PT_BOTH (buf
,
2045 clip_to_bounds (BUF_BEGV (buf
), BUF_PT (buf
), BUF_ZV (buf
)),
2046 clip_to_bounds (BUF_BEGV_BYTE (buf
), BUF_PT_BYTE (buf
),
2047 BUF_ZV_BYTE (buf
)));
2052 DEFUN ("save-restriction", Fsave_restriction
, Ssave_restriction
, 0, UNEVALLED
, 0,
2053 "Execute BODY, saving and restoring current buffer's restrictions.\n\
2054 The buffer's restrictions make parts of the beginning and end invisible.\n\
2055 \(They are set up with `narrow-to-region' and eliminated with `widen'.)\n\
2056 This special form, `save-restriction', saves the current buffer's restrictions\n\
2057 when it is entered, and restores them when it is exited.\n\
2058 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\
2059 The old restrictions settings are restored\n\
2060 even in case of abnormal exit (throw or error).\n\
2062 The value returned is the value of the last form in BODY.\n\
2064 `save-restriction' can get confused if, within the BODY, you widen\n\
2065 and then make changes outside the area within the saved restrictions.\n\
2067 Note: if you are using both `save-excursion' and `save-restriction',\n\
2068 use `save-excursion' outermost:\n\
2069 (save-excursion (save-restriction ...))")
2073 register Lisp_Object val
;
2074 int count
= specpdl_ptr
- specpdl
;
2076 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
2077 val
= Fprogn (body
);
2078 return unbind_to (count
, val
);
2081 /* Buffer for the most recent text displayed by Fmessage. */
2082 static char *message_text
;
2084 /* Allocated length of that buffer. */
2085 static int message_length
;
2087 DEFUN ("message", Fmessage
, Smessage
, 1, MANY
, 0,
2088 "Print a one-line message at the bottom of the screen.\n\
2089 The first argument is a format control string, and the rest are data\n\
2090 to be formatted under control of the string. See `format' for details.\n\
2092 If the first argument is nil, clear any existing message; let the\n\
2093 minibuffer contents show.")
2105 register Lisp_Object val
;
2106 val
= Fformat (nargs
, args
);
2107 /* Copy the data so that it won't move when we GC. */
2110 message_text
= (char *)xmalloc (80);
2111 message_length
= 80;
2113 if (STRING_BYTES (XSTRING (val
)) > message_length
)
2115 message_length
= STRING_BYTES (XSTRING (val
));
2116 message_text
= (char *)xrealloc (message_text
, message_length
);
2118 bcopy (XSTRING (val
)->data
, message_text
, STRING_BYTES (XSTRING (val
)));
2119 message2 (message_text
, STRING_BYTES (XSTRING (val
)),
2120 STRING_MULTIBYTE (val
));
2125 DEFUN ("message-box", Fmessage_box
, Smessage_box
, 1, MANY
, 0,
2126 "Display a message, in a dialog box if possible.\n\
2127 If a dialog box is not available, use the echo area.\n\
2128 The first argument is a format control string, and the rest are data\n\
2129 to be formatted under control of the string. See `format' for details.\n\
2131 If the first argument is nil, clear any existing message; let the\n\
2132 minibuffer contents show.")
2144 register Lisp_Object val
;
2145 val
= Fformat (nargs
, args
);
2148 Lisp_Object pane
, menu
, obj
;
2149 struct gcpro gcpro1
;
2150 pane
= Fcons (Fcons (build_string ("OK"), Qt
), Qnil
);
2152 menu
= Fcons (val
, pane
);
2153 obj
= Fx_popup_dialog (Qt
, menu
);
2157 #else /* not HAVE_MENUS */
2158 /* Copy the data so that it won't move when we GC. */
2161 message_text
= (char *)xmalloc (80);
2162 message_length
= 80;
2164 if (STRING_BYTES (XSTRING (val
)) > message_length
)
2166 message_length
= STRING_BYTES (XSTRING (val
));
2167 message_text
= (char *)xrealloc (message_text
, message_length
);
2169 bcopy (XSTRING (val
)->data
, message_text
, STRING_BYTES (XSTRING (val
)));
2170 message2 (message_text
, STRING_BYTES (XSTRING (val
)));
2172 #endif /* not HAVE_MENUS */
2176 extern Lisp_Object last_nonmenu_event
;
2179 DEFUN ("message-or-box", Fmessage_or_box
, Smessage_or_box
, 1, MANY
, 0,
2180 "Display a message in a dialog box or in the echo area.\n\
2181 If this command was invoked with the mouse, use a dialog box.\n\
2182 Otherwise, use the echo area.\n\
2183 The first argument is a format control string, and the rest are data\n\
2184 to be formatted under control of the string. See `format' for details.\n\
2186 If the first argument is nil, clear any existing message; let the\n\
2187 minibuffer contents show.")
2193 if (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
2194 return Fmessage_box (nargs
, args
);
2196 return Fmessage (nargs
, args
);
2199 DEFUN ("current-message", Fcurrent_message
, Scurrent_message
, 0, 0, 0,
2200 "Return the string currently displayed in the echo area, or nil if none.")
2203 return (echo_area_glyphs
2204 ? make_string (echo_area_glyphs
, echo_area_glyphs_length
)
2208 /* Number of bytes that STRING will occupy when put into the result.
2209 MULTIBYTE is nonzero if the result should be multibyte. */
2211 #define CONVERTED_BYTE_SIZE(MULTIBYTE, STRING) \
2212 (((MULTIBYTE) && ! STRING_MULTIBYTE (STRING)) \
2213 ? count_size_as_multibyte (XSTRING (STRING)->data, \
2214 STRING_BYTES (XSTRING (STRING))) \
2215 : STRING_BYTES (XSTRING (STRING)))
2217 DEFUN ("format", Fformat
, Sformat
, 1, MANY
, 0,
2218 "Format a string out of a control-string and arguments.\n\
2219 The first argument is a control string.\n\
2220 The other arguments are substituted into it to make the result, a string.\n\
2221 It may contain %-sequences meaning to substitute the next argument.\n\
2222 %s means print a string argument. Actually, prints any object, with `princ'.\n\
2223 %d means print as number in decimal (%o octal, %x hex).\n\
2224 %e means print a number in exponential notation.\n\
2225 %f means print a number in decimal-point notation.\n\
2226 %g means print a number in exponential notation\n\
2227 or decimal-point notation, whichever uses fewer characters.\n\
2228 %c means print a number as a single character.\n\
2229 %S means print any object as an s-expression (using prin1).\n\
2230 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.\n\
2231 Use %% to put a single % into the output.")
2234 register Lisp_Object
*args
;
2236 register int n
; /* The number of the next arg to substitute */
2237 register int total
; /* An estimate of the final length */
2239 register unsigned char *format
, *end
;
2241 /* Nonzero if the output should be a multibyte string,
2242 which is true if any of the inputs is one. */
2244 unsigned char *this_format
;
2248 extern char *index ();
2250 /* It should not be necessary to GCPRO ARGS, because
2251 the caller in the interpreter should take care of that. */
2253 /* Try to determine whether the result should be multibyte.
2254 This is not always right; sometimes the result needs to be multibyte
2255 because of an object that we will pass through prin1,
2256 and in that case, we won't know it here. */
2257 for (n
= 0; n
< nargs
; n
++)
2258 if (STRINGP (args
[n
]) && STRING_MULTIBYTE (args
[n
]))
2261 CHECK_STRING (args
[0], 0);
2263 /* If we start out planning a unibyte result,
2264 and later find it has to be multibyte, we jump back to retry. */
2267 format
= XSTRING (args
[0])->data
;
2268 end
= format
+ STRING_BYTES (XSTRING (args
[0]));
2271 /* Make room in result for all the non-%-codes in the control string. */
2272 total
= 5 + CONVERTED_BYTE_SIZE (multibyte
, args
[0]);
2274 /* Add to TOTAL enough space to hold the converted arguments. */
2277 while (format
!= end
)
2278 if (*format
++ == '%')
2280 int minlen
, thissize
= 0;
2281 unsigned char *this_format_start
= format
- 1;
2283 /* Process a numeric arg and skip it. */
2284 minlen
= atoi (format
);
2288 while ((*format
>= '0' && *format
<= '9')
2289 || *format
== '-' || *format
== ' ' || *format
== '.')
2292 if (format
- this_format_start
+ 1 > longest_format
)
2293 longest_format
= format
- this_format_start
+ 1;
2297 else if (++n
>= nargs
)
2298 error ("Not enough arguments for format string");
2299 else if (*format
== 'S')
2301 /* For `S', prin1 the argument and then treat like a string. */
2302 register Lisp_Object tem
;
2303 tem
= Fprin1_to_string (args
[n
], Qnil
);
2304 if (STRING_MULTIBYTE (tem
) && ! multibyte
)
2312 else if (SYMBOLP (args
[n
]))
2314 XSETSTRING (args
[n
], XSYMBOL (args
[n
])->name
);
2315 if (STRING_MULTIBYTE (args
[n
]) && ! multibyte
)
2322 else if (STRINGP (args
[n
]))
2325 if (*format
!= 's' && *format
!= 'S')
2326 error ("format specifier doesn't match argument type");
2327 thissize
= CONVERTED_BYTE_SIZE (multibyte
, args
[n
]);
2329 /* Would get MPV otherwise, since Lisp_Int's `point' to low memory. */
2330 else if (INTEGERP (args
[n
]) && *format
!= 's')
2332 #ifdef LISP_FLOAT_TYPE
2333 /* The following loop assumes the Lisp type indicates
2334 the proper way to pass the argument.
2335 So make sure we have a flonum if the argument should
2337 if (*format
== 'e' || *format
== 'f' || *format
== 'g')
2338 args
[n
] = Ffloat (args
[n
]);
2342 && (! SINGLE_BYTE_CHAR_P (XINT (args
[n
]))
2343 || XINT (args
[n
]) == 0))
2350 args
[n
] = Fchar_to_string (args
[n
]);
2351 thissize
= STRING_BYTES (XSTRING (args
[n
]));
2354 #ifdef LISP_FLOAT_TYPE
2355 else if (FLOATP (args
[n
]) && *format
!= 's')
2357 if (! (*format
== 'e' || *format
== 'f' || *format
== 'g'))
2358 args
[n
] = Ftruncate (args
[n
], Qnil
);
2364 /* Anything but a string, convert to a string using princ. */
2365 register Lisp_Object tem
;
2366 tem
= Fprin1_to_string (args
[n
], Qt
);
2367 if (STRING_MULTIBYTE (tem
) & ! multibyte
)
2376 if (thissize
< minlen
)
2379 total
+= thissize
+ 4;
2382 /* Now we can no longer jump to retry.
2383 TOTAL and LONGEST_FORMAT are known for certain. */
2385 this_format
= (unsigned char *) alloca (longest_format
+ 1);
2387 /* Allocate the space for the result.
2388 Note that TOTAL is an overestimate. */
2390 buf
= (unsigned char *) alloca (total
+ 1);
2392 buf
= (unsigned char *) xmalloc (total
+ 1);
2398 /* Scan the format and store result in BUF. */
2399 format
= XSTRING (args
[0])->data
;
2400 while (format
!= end
)
2406 unsigned char *this_format_start
= format
;
2410 /* Process a numeric arg and skip it. */
2411 minlen
= atoi (format
);
2413 minlen
= - minlen
, negative
= 1;
2415 while ((*format
>= '0' && *format
<= '9')
2416 || *format
== '-' || *format
== ' ' || *format
== '.')
2419 if (*format
++ == '%')
2428 if (STRINGP (args
[n
]))
2430 int padding
, nbytes
;
2431 int width
= strwidth (XSTRING (args
[n
])->data
,
2432 STRING_BYTES (XSTRING (args
[n
])));
2434 /* If spec requires it, pad on right with spaces. */
2435 padding
= minlen
- width
;
2437 while (padding
-- > 0)
2443 nbytes
= copy_text (XSTRING (args
[n
])->data
, p
,
2444 STRING_BYTES (XSTRING (args
[n
])),
2445 STRING_MULTIBYTE (args
[n
]), multibyte
);
2447 nchars
+= XSTRING (args
[n
])->size
;
2450 while (padding
-- > 0)
2456 else if (INTEGERP (args
[n
]) || FLOATP (args
[n
]))
2460 bcopy (this_format_start
, this_format
,
2461 format
- this_format_start
);
2462 this_format
[format
- this_format_start
] = 0;
2464 if (INTEGERP (args
[n
]))
2465 sprintf (p
, this_format
, XINT (args
[n
]));
2467 sprintf (p
, this_format
, XFLOAT (args
[n
])->data
);
2469 this_nchars
= strlen (p
);
2471 nchars
+= this_nchars
;
2474 else if (STRING_MULTIBYTE (args
[0]))
2476 /* Copy a whole multibyte character. */
2478 while (! CHAR_HEAD_P (*format
)) *p
++ = *format
++;
2483 /* Convert a single-byte character to multibyte. */
2484 int len
= copy_text (format
, p
, 1, 0, 1);
2491 *p
++ = *format
++, nchars
++;
2494 val
= make_multibyte_string (buf
, nchars
, p
- buf
);
2496 /* If we allocated BUF with malloc, free it too. */
2506 format1 (string1
, arg0
, arg1
, arg2
, arg3
, arg4
)
2507 EMACS_INT arg0
, arg1
, arg2
, arg3
, arg4
;
2521 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, (char **) args
);
2523 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, &string1
+ 1);
2525 return build_string (buf
);
2528 DEFUN ("char-equal", Fchar_equal
, Schar_equal
, 2, 2, 0,
2529 "Return t if two characters match, optionally ignoring case.\n\
2530 Both arguments must be characters (i.e. integers).\n\
2531 Case is ignored if `case-fold-search' is non-nil in the current buffer.")
2533 register Lisp_Object c1
, c2
;
2536 CHECK_NUMBER (c1
, 0);
2537 CHECK_NUMBER (c2
, 1);
2539 if (XINT (c1
) == XINT (c2
))
2541 if (NILP (current_buffer
->case_fold_search
))
2544 /* Do these in separate statements,
2545 then compare the variables.
2546 because of the way DOWNCASE uses temp variables. */
2547 i1
= DOWNCASE (XFASTINT (c1
));
2548 i2
= DOWNCASE (XFASTINT (c2
));
2549 return (i1
== i2
? Qt
: Qnil
);
2552 /* Transpose the markers in two regions of the current buffer, and
2553 adjust the ones between them if necessary (i.e.: if the regions
2556 START1, END1 are the character positions of the first region.
2557 START1_BYTE, END1_BYTE are the byte positions.
2558 START2, END2 are the character positions of the second region.
2559 START2_BYTE, END2_BYTE are the byte positions.
2561 Traverses the entire marker list of the buffer to do so, adding an
2562 appropriate amount to some, subtracting from some, and leaving the
2563 rest untouched. Most of this is copied from adjust_markers in insdel.c.
2565 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
2568 transpose_markers (start1
, end1
, start2
, end2
,
2569 start1_byte
, end1_byte
, start2_byte
, end2_byte
)
2570 register int start1
, end1
, start2
, end2
;
2571 register int start1_byte
, end1_byte
, start2_byte
, end2_byte
;
2573 register int amt1
, amt1_byte
, amt2
, amt2_byte
, diff
, diff_byte
, mpos
;
2574 register Lisp_Object marker
;
2576 /* Update point as if it were a marker. */
2580 TEMP_SET_PT_BOTH (PT
+ (end2
- end1
),
2581 PT_BYTE
+ (end2_byte
- end1_byte
));
2582 else if (PT
< start2
)
2583 TEMP_SET_PT_BOTH (PT
+ (end2
- start2
) - (end1
- start1
),
2584 (PT_BYTE
+ (end2_byte
- start2_byte
)
2585 - (end1_byte
- start1_byte
)));
2587 TEMP_SET_PT_BOTH (PT
- (start2
- start1
),
2588 PT_BYTE
- (start2_byte
- start1_byte
));
2590 /* We used to adjust the endpoints here to account for the gap, but that
2591 isn't good enough. Even if we assume the caller has tried to move the
2592 gap out of our way, it might still be at start1 exactly, for example;
2593 and that places it `inside' the interval, for our purposes. The amount
2594 of adjustment is nontrivial if there's a `denormalized' marker whose
2595 position is between GPT and GPT + GAP_SIZE, so it's simpler to leave
2596 the dirty work to Fmarker_position, below. */
2598 /* The difference between the region's lengths */
2599 diff
= (end2
- start2
) - (end1
- start1
);
2600 diff_byte
= (end2_byte
- start2_byte
) - (end1_byte
- start1_byte
);
2602 /* For shifting each marker in a region by the length of the other
2603 region plus the distance between the regions. */
2604 amt1
= (end2
- start2
) + (start2
- end1
);
2605 amt2
= (end1
- start1
) + (start2
- end1
);
2606 amt1_byte
= (end2_byte
- start2_byte
) + (start2_byte
- end1_byte
);
2607 amt2_byte
= (end1_byte
- start1_byte
) + (start2_byte
- end1_byte
);
2609 for (marker
= BUF_MARKERS (current_buffer
); !NILP (marker
);
2610 marker
= XMARKER (marker
)->chain
)
2612 mpos
= marker_byte_position (marker
);
2613 if (mpos
>= start1_byte
&& mpos
< end2_byte
)
2615 if (mpos
< end1_byte
)
2617 else if (mpos
< start2_byte
)
2621 XMARKER (marker
)->bytepos
= mpos
;
2623 mpos
= XMARKER (marker
)->charpos
;
2624 if (mpos
>= start1
&& mpos
< end2
)
2628 else if (mpos
< start2
)
2633 XMARKER (marker
)->charpos
= mpos
;
2637 DEFUN ("transpose-regions", Ftranspose_regions
, Stranspose_regions
, 4, 5, 0,
2638 "Transpose region START1 to END1 with START2 to END2.\n\
2639 The regions may not be overlapping, because the size of the buffer is\n\
2640 never changed in a transposition.\n\
2642 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't update\n\
2643 any markers that happen to be located in the regions.\n\
2645 Transposing beyond buffer boundaries is an error.")
2646 (startr1
, endr1
, startr2
, endr2
, leave_markers
)
2647 Lisp_Object startr1
, endr1
, startr2
, endr2
, leave_markers
;
2649 register int start1
, end1
, start2
, end2
;
2650 int start1_byte
, start2_byte
, len1_byte
, len2_byte
;
2651 int gap
, len1
, len_mid
, len2
;
2652 unsigned char *start1_addr
, *start2_addr
, *temp
;
2653 int combined_before_bytes_1
, combined_after_bytes_1
;
2654 int combined_before_bytes_2
, combined_after_bytes_2
;
2655 struct gcpro gcpro1
, gcpro2
;
2657 #ifdef USE_TEXT_PROPERTIES
2658 INTERVAL cur_intv
, tmp_interval1
, tmp_interval_mid
, tmp_interval2
;
2659 cur_intv
= BUF_INTERVALS (current_buffer
);
2660 #endif /* USE_TEXT_PROPERTIES */
2662 validate_region (&startr1
, &endr1
);
2663 validate_region (&startr2
, &endr2
);
2665 start1
= XFASTINT (startr1
);
2666 end1
= XFASTINT (endr1
);
2667 start2
= XFASTINT (startr2
);
2668 end2
= XFASTINT (endr2
);
2671 /* Swap the regions if they're reversed. */
2674 register int glumph
= start1
;
2682 len1
= end1
- start1
;
2683 len2
= end2
- start2
;
2686 error ("Transposed regions overlap");
2687 else if (start1
== end1
|| start2
== end2
)
2688 error ("Transposed region has length 0");
2690 /* The possibilities are:
2691 1. Adjacent (contiguous) regions, or separate but equal regions
2692 (no, really equal, in this case!), or
2693 2. Separate regions of unequal size.
2695 The worst case is usually No. 2. It means that (aside from
2696 potential need for getting the gap out of the way), there also
2697 needs to be a shifting of the text between the two regions. So
2698 if they are spread far apart, we are that much slower... sigh. */
2700 /* It must be pointed out that the really studly thing to do would
2701 be not to move the gap at all, but to leave it in place and work
2702 around it if necessary. This would be extremely efficient,
2703 especially considering that people are likely to do
2704 transpositions near where they are working interactively, which
2705 is exactly where the gap would be found. However, such code
2706 would be much harder to write and to read. So, if you are
2707 reading this comment and are feeling squirrely, by all means have
2708 a go! I just didn't feel like doing it, so I will simply move
2709 the gap the minimum distance to get it out of the way, and then
2710 deal with an unbroken array. */
2712 /* Make sure the gap won't interfere, by moving it out of the text
2713 we will operate on. */
2714 if (start1
< gap
&& gap
< end2
)
2716 if (gap
- start1
< end2
- gap
)
2722 start1_byte
= CHAR_TO_BYTE (start1
);
2723 start2_byte
= CHAR_TO_BYTE (start2
);
2724 len1_byte
= CHAR_TO_BYTE (end1
) - start1_byte
;
2725 len2_byte
= CHAR_TO_BYTE (end2
) - start2_byte
;
2729 combined_before_bytes_2
2730 = count_combining_before (BYTE_POS_ADDR (start2_byte
),
2731 len2_byte
, start1
, start1_byte
);
2732 combined_before_bytes_1
2733 = count_combining_before (BYTE_POS_ADDR (start1_byte
),
2734 len1_byte
, end2
, start2_byte
+ len2_byte
);
2735 combined_after_bytes_1
2736 = count_combining_after (BYTE_POS_ADDR (start1_byte
),
2737 len1_byte
, end2
, start2_byte
+ len2_byte
);
2738 combined_after_bytes_2
= 0;
2742 combined_before_bytes_2
2743 = count_combining_before (BYTE_POS_ADDR (start2_byte
),
2744 len2_byte
, start1
, start1_byte
);
2745 combined_before_bytes_1
2746 = count_combining_before (BYTE_POS_ADDR (start1_byte
),
2747 len1_byte
, start2
, start2_byte
);
2748 combined_after_bytes_2
2749 = count_combining_after (BYTE_POS_ADDR (start2_byte
),
2750 len2_byte
, end1
, start1_byte
+ len1_byte
);
2751 combined_after_bytes_1
2752 = count_combining_after (BYTE_POS_ADDR (start1_byte
),
2753 len1_byte
, end2
, start2_byte
+ len2_byte
);
2756 /* If any combining is going to happen, do this the stupid way,
2757 because replace handles combining properly. */
2758 if (combined_before_bytes_1
|| combined_before_bytes_2
2759 || combined_after_bytes_1
|| combined_after_bytes_2
)
2761 Lisp_Object text1
, text2
;
2763 text1
= text2
= Qnil
;
2764 GCPRO2 (text1
, text2
);
2766 text1
= make_buffer_string_both (start1
, start1_byte
,
2767 end1
, start1_byte
+ len1_byte
, 1);
2768 text2
= make_buffer_string_both (start2
, start2_byte
,
2769 end2
, start2_byte
+ len2_byte
, 1);
2771 transpose_markers (start1
, end1
, start2
, end2
,
2772 start1_byte
, start1_byte
+ len1_byte
,
2773 start2_byte
, start2_byte
+ len2_byte
);
2775 replace_range (text1
, start2
, end2
, 1, 0, 1);
2776 replace_range (text2
, start1
, end1
, 1, 0, 1);
2782 /* Hmmm... how about checking to see if the gap is large
2783 enough to use as the temporary storage? That would avoid an
2784 allocation... interesting. Later, don't fool with it now. */
2786 /* Working without memmove, for portability (sigh), so must be
2787 careful of overlapping subsections of the array... */
2789 if (end1
== start2
) /* adjacent regions */
2791 modify_region (current_buffer
, start1
, end2
);
2792 record_change (start1
, len1
+ len2
);
2794 #ifdef USE_TEXT_PROPERTIES
2795 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2796 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2797 Fset_text_properties (make_number (start1
), make_number (end2
),
2799 #endif /* USE_TEXT_PROPERTIES */
2801 /* First region smaller than second. */
2802 if (len1_byte
< len2_byte
)
2804 /* We use alloca only if it is small,
2805 because we want to avoid stack overflow. */
2806 if (len2_byte
> 20000)
2807 temp
= (unsigned char *) xmalloc (len2_byte
);
2809 temp
= (unsigned char *) alloca (len2_byte
);
2811 /* Don't precompute these addresses. We have to compute them
2812 at the last minute, because the relocating allocator might
2813 have moved the buffer around during the xmalloc. */
2814 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2815 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2817 bcopy (start2_addr
, temp
, len2_byte
);
2818 bcopy (start1_addr
, start1_addr
+ len2_byte
, len1_byte
);
2819 bcopy (temp
, start1_addr
, len2_byte
);
2820 if (len2_byte
> 20000)
2824 /* First region not smaller than second. */
2826 if (len1_byte
> 20000)
2827 temp
= (unsigned char *) xmalloc (len1_byte
);
2829 temp
= (unsigned char *) alloca (len1_byte
);
2830 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2831 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2832 bcopy (start1_addr
, temp
, len1_byte
);
2833 bcopy (start2_addr
, start1_addr
, len2_byte
);
2834 bcopy (temp
, start1_addr
+ len2_byte
, len1_byte
);
2835 if (len1_byte
> 20000)
2838 #ifdef USE_TEXT_PROPERTIES
2839 graft_intervals_into_buffer (tmp_interval1
, start1
+ len2
,
2840 len1
, current_buffer
, 0);
2841 graft_intervals_into_buffer (tmp_interval2
, start1
,
2842 len2
, current_buffer
, 0);
2843 #endif /* USE_TEXT_PROPERTIES */
2845 /* Non-adjacent regions, because end1 != start2, bleagh... */
2848 len_mid
= start2_byte
- (start1_byte
+ len1_byte
);
2850 if (len1_byte
== len2_byte
)
2851 /* Regions are same size, though, how nice. */
2853 modify_region (current_buffer
, start1
, end1
);
2854 modify_region (current_buffer
, start2
, end2
);
2855 record_change (start1
, len1
);
2856 record_change (start2
, len2
);
2857 #ifdef USE_TEXT_PROPERTIES
2858 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2859 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2860 Fset_text_properties (make_number (start1
), make_number (end1
),
2862 Fset_text_properties (make_number (start2
), make_number (end2
),
2864 #endif /* USE_TEXT_PROPERTIES */
2866 if (len1_byte
> 20000)
2867 temp
= (unsigned char *) xmalloc (len1_byte
);
2869 temp
= (unsigned char *) alloca (len1_byte
);
2870 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2871 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2872 bcopy (start1_addr
, temp
, len1_byte
);
2873 bcopy (start2_addr
, start1_addr
, len2_byte
);
2874 bcopy (temp
, start2_addr
, len1_byte
);
2875 if (len1_byte
> 20000)
2877 #ifdef USE_TEXT_PROPERTIES
2878 graft_intervals_into_buffer (tmp_interval1
, start2
,
2879 len1
, current_buffer
, 0);
2880 graft_intervals_into_buffer (tmp_interval2
, start1
,
2881 len2
, current_buffer
, 0);
2882 #endif /* USE_TEXT_PROPERTIES */
2885 else if (len1_byte
< len2_byte
) /* Second region larger than first */
2886 /* Non-adjacent & unequal size, area between must also be shifted. */
2888 modify_region (current_buffer
, start1
, end2
);
2889 record_change (start1
, (end2
- start1
));
2890 #ifdef USE_TEXT_PROPERTIES
2891 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2892 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
2893 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2894 Fset_text_properties (make_number (start1
), make_number (end2
),
2896 #endif /* USE_TEXT_PROPERTIES */
2898 /* holds region 2 */
2899 if (len2_byte
> 20000)
2900 temp
= (unsigned char *) xmalloc (len2_byte
);
2902 temp
= (unsigned char *) alloca (len2_byte
);
2903 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2904 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2905 bcopy (start2_addr
, temp
, len2_byte
);
2906 bcopy (start1_addr
, start1_addr
+ len_mid
+ len2_byte
, len1_byte
);
2907 safe_bcopy (start1_addr
+ len1_byte
, start1_addr
+ len2_byte
, len_mid
);
2908 bcopy (temp
, start1_addr
, len2_byte
);
2909 if (len2_byte
> 20000)
2911 #ifdef USE_TEXT_PROPERTIES
2912 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
2913 len1
, current_buffer
, 0);
2914 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
2915 len_mid
, current_buffer
, 0);
2916 graft_intervals_into_buffer (tmp_interval2
, start1
,
2917 len2
, current_buffer
, 0);
2918 #endif /* USE_TEXT_PROPERTIES */
2921 /* Second region smaller than first. */
2923 record_change (start1
, (end2
- start1
));
2924 modify_region (current_buffer
, start1
, end2
);
2926 #ifdef USE_TEXT_PROPERTIES
2927 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2928 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
2929 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2930 Fset_text_properties (make_number (start1
), make_number (end2
),
2932 #endif /* USE_TEXT_PROPERTIES */
2934 /* holds region 1 */
2935 if (len1_byte
> 20000)
2936 temp
= (unsigned char *) xmalloc (len1_byte
);
2938 temp
= (unsigned char *) alloca (len1_byte
);
2939 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2940 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2941 bcopy (start1_addr
, temp
, len1_byte
);
2942 bcopy (start2_addr
, start1_addr
, len2_byte
);
2943 bcopy (start1_addr
+ len1_byte
, start1_addr
+ len2_byte
, len_mid
);
2944 bcopy (temp
, start1_addr
+ len2_byte
+ len_mid
, len1_byte
);
2945 if (len1_byte
> 20000)
2947 #ifdef USE_TEXT_PROPERTIES
2948 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
2949 len1
, current_buffer
, 0);
2950 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
2951 len_mid
, current_buffer
, 0);
2952 graft_intervals_into_buffer (tmp_interval2
, start1
,
2953 len2
, current_buffer
, 0);
2954 #endif /* USE_TEXT_PROPERTIES */
2958 /* When doing multiple transpositions, it might be nice
2959 to optimize this. Perhaps the markers in any one buffer
2960 should be organized in some sorted data tree. */
2961 if (NILP (leave_markers
))
2963 transpose_markers (start1
, end1
, start2
, end2
,
2964 start1_byte
, start1_byte
+ len1_byte
,
2965 start2_byte
, start2_byte
+ len2_byte
);
2966 fix_overlays_in_range (start1
, end2
);
2978 Qbuffer_access_fontify_functions
2979 = intern ("buffer-access-fontify-functions");
2980 staticpro (&Qbuffer_access_fontify_functions
);
2982 DEFVAR_LISP ("buffer-access-fontify-functions",
2983 &Vbuffer_access_fontify_functions
,
2984 "List of functions called by `buffer-substring' to fontify if necessary.\n\
2985 Each function is called with two arguments which specify the range\n\
2986 of the buffer being accessed.");
2987 Vbuffer_access_fontify_functions
= Qnil
;
2991 extern Lisp_Object Vprin1_to_string_buffer
;
2992 obuf
= Fcurrent_buffer ();
2993 /* Do this here, because init_buffer_once is too early--it won't work. */
2994 Fset_buffer (Vprin1_to_string_buffer
);
2995 /* Make sure buffer-access-fontify-functions is nil in this buffer. */
2996 Fset (Fmake_local_variable (intern ("buffer-access-fontify-functions")),
3001 DEFVAR_LISP ("buffer-access-fontified-property",
3002 &Vbuffer_access_fontified_property
,
3003 "Property which (if non-nil) indicates text has been fontified.\n\
3004 `buffer-substring' need not call the `buffer-access-fontify-functions'\n\
3005 functions if all the text being accessed has this property.");
3006 Vbuffer_access_fontified_property
= Qnil
;
3008 DEFVAR_LISP ("system-name", &Vsystem_name
,
3009 "The name of the machine Emacs is running on.");
3011 DEFVAR_LISP ("user-full-name", &Vuser_full_name
,
3012 "The full name of the user logged in.");
3014 DEFVAR_LISP ("user-login-name", &Vuser_login_name
,
3015 "The user's name, taken from environment variables if possible.");
3017 DEFVAR_LISP ("user-real-login-name", &Vuser_real_login_name
,
3018 "The user's name, based upon the real uid only.");
3020 defsubr (&Schar_equal
);
3021 defsubr (&Sgoto_char
);
3022 defsubr (&Sstring_to_char
);
3023 defsubr (&Schar_to_string
);
3024 defsubr (&Sbuffer_substring
);
3025 defsubr (&Sbuffer_substring_no_properties
);
3026 defsubr (&Sbuffer_string
);
3028 defsubr (&Spoint_marker
);
3029 defsubr (&Smark_marker
);
3031 defsubr (&Sregion_beginning
);
3032 defsubr (&Sregion_end
);
3034 defsubr (&Sline_beginning_position
);
3035 defsubr (&Sline_end_position
);
3037 /* defsubr (&Smark); */
3038 /* defsubr (&Sset_mark); */
3039 defsubr (&Ssave_excursion
);
3040 defsubr (&Ssave_current_buffer
);
3042 defsubr (&Sbufsize
);
3043 defsubr (&Spoint_max
);
3044 defsubr (&Spoint_min
);
3045 defsubr (&Spoint_min_marker
);
3046 defsubr (&Spoint_max_marker
);
3047 defsubr (&Sposition_bytes
);
3053 defsubr (&Sfollowing_char
);
3054 defsubr (&Sprevious_char
);
3055 defsubr (&Schar_after
);
3056 defsubr (&Schar_before
);
3058 defsubr (&Sinsert_before_markers
);
3059 defsubr (&Sinsert_and_inherit
);
3060 defsubr (&Sinsert_and_inherit_before_markers
);
3061 defsubr (&Sinsert_char
);
3063 defsubr (&Suser_login_name
);
3064 defsubr (&Suser_real_login_name
);
3065 defsubr (&Suser_uid
);
3066 defsubr (&Suser_real_uid
);
3067 defsubr (&Suser_full_name
);
3068 defsubr (&Semacs_pid
);
3069 defsubr (&Scurrent_time
);
3070 defsubr (&Sformat_time_string
);
3071 defsubr (&Sdecode_time
);
3072 defsubr (&Sencode_time
);
3073 defsubr (&Scurrent_time_string
);
3074 defsubr (&Scurrent_time_zone
);
3075 defsubr (&Sset_time_zone_rule
);
3076 defsubr (&Ssystem_name
);
3077 defsubr (&Smessage
);
3078 defsubr (&Smessage_box
);
3079 defsubr (&Smessage_or_box
);
3080 defsubr (&Scurrent_message
);
3083 defsubr (&Sinsert_buffer_substring
);
3084 defsubr (&Scompare_buffer_substrings
);
3085 defsubr (&Ssubst_char_in_region
);
3086 defsubr (&Stranslate_region
);
3087 defsubr (&Sdelete_region
);
3089 defsubr (&Snarrow_to_region
);
3090 defsubr (&Ssave_restriction
);
3091 defsubr (&Stranspose_regions
);