(Fset_time_zone_rule): Move static var environbuf
[bpt/emacs.git] / src / editfns.c
CommitLineData
35692fe0 1/* Lisp functions pertaining to editing.
f8c25f1b 2 Copyright (C) 1985,86,87,89,93,94,95 Free Software Foundation, Inc.
35692fe0
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
7c938215 8the Free Software Foundation; either version 2, or (at your option)
35692fe0
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
738429d1
JB
21#include <sys/types.h>
22
18160b98 23#include <config.h>
bfb61299
JB
24
25#ifdef VMS
956ace37 26#include "vms-pwd.h"
bfb61299 27#else
35692fe0 28#include <pwd.h>
bfb61299
JB
29#endif
30
35692fe0 31#include "lisp.h"
74d6d8c5 32#include "intervals.h"
35692fe0
JB
33#include "buffer.h"
34#include "window.h"
35
956ace37 36#include "systime.h"
35692fe0
JB
37
38#define min(a, b) ((a) < (b) ? (a) : (b))
39#define max(a, b) ((a) > (b) ? (a) : (b))
40
c59b5089
PE
41extern char **environ;
42extern Lisp_Object make_time ();
b1b0ee5a 43extern void insert_from_buffer ();
3c887943 44static long difftm ();
c59b5089 45static void set_time_zone_rule ();
260e2e2a
KH
46static void update_buffer_properties ();
47
48Lisp_Object Vbuffer_access_fontify_functions;
49Lisp_Object Qbuffer_access_fontify_functions;
50Lisp_Object Vbuffer_access_fontified_property;
b1b0ee5a 51
35692fe0
JB
52/* Some static data, and a function to initialize it for each run */
53
54Lisp_Object Vsystem_name;
35b34f72
KH
55Lisp_Object Vuser_real_login_name; /* login name of current user ID */
56Lisp_Object Vuser_full_name; /* full name of current user */
57Lisp_Object Vuser_login_name; /* user name from LOGNAME or USER */
35692fe0
JB
58
59void
60init_editfns ()
61{
52b14ac0 62 char *user_name;
35692fe0
JB
63 register unsigned char *p, *q, *r;
64 struct passwd *pw; /* password entry for the current user */
65 extern char *index ();
66 Lisp_Object tem;
67
68 /* Set up system_name even when dumping. */
ac988277 69 init_system_name ();
35692fe0
JB
70
71#ifndef CANNOT_DUMP
72 /* Don't bother with this on initial start when just dumping out */
73 if (!initialized)
74 return;
75#endif /* not CANNOT_DUMP */
76
77 pw = (struct passwd *) getpwuid (getuid ());
87485d6f
MW
78#ifdef MSDOS
79 /* We let the real user name default to "root" because that's quite
80 accurate on MSDOG and because it lets Emacs find the init file.
81 (The DVX libraries override the Djgpp libraries here.) */
35b34f72 82 Vuser_real_login_name = build_string (pw ? pw->pw_name : "root");
87485d6f 83#else
35b34f72 84 Vuser_real_login_name = build_string (pw ? pw->pw_name : "unknown");
87485d6f 85#endif
35692fe0 86
52b14ac0
JB
87 /* Get the effective user name, by consulting environment variables,
88 or the effective uid if those are unset. */
2c9ae24e 89 user_name = (char *) getenv ("LOGNAME");
35692fe0 90 if (!user_name)
4691c06d
RS
91#ifdef WINDOWSNT
92 user_name = (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
93#else /* WINDOWSNT */
2c9ae24e 94 user_name = (char *) getenv ("USER");
4691c06d 95#endif /* WINDOWSNT */
52b14ac0
JB
96 if (!user_name)
97 {
98 pw = (struct passwd *) getpwuid (geteuid ());
99 user_name = (char *) (pw ? pw->pw_name : "unknown");
100 }
35b34f72 101 Vuser_login_name = build_string (user_name);
35692fe0 102
52b14ac0
JB
103 /* If the user name claimed in the environment vars differs from
104 the real uid, use the claimed name to find the full name. */
35b34f72 105 tem = Fstring_equal (Vuser_login_name, Vuser_real_login_name);
56a98455 106 if (NILP (tem))
35b34f72 107 pw = (struct passwd *) getpwnam (XSTRING (Vuser_login_name)->data);
35692fe0
JB
108
109 p = (unsigned char *) (pw ? USER_FULL_NAME : "unknown");
110 q = (unsigned char *) index (p, ',');
111 Vuser_full_name = make_string (p, q ? q - p : strlen (p));
112
113#ifdef AMPERSAND_FULL_NAME
114 p = XSTRING (Vuser_full_name)->data;
8f1e2d16 115 q = (unsigned char *) index (p, '&');
35692fe0
JB
116 /* Substitute the login name for the &, upcasing the first character. */
117 if (q)
118 {
35b34f72
KH
119 r = (unsigned char *) alloca (strlen (p)
120 + XSTRING (Vuser_login_name)->size + 1);
35692fe0
JB
121 bcopy (p, r, q - p);
122 r[q - p] = 0;
35b34f72 123 strcat (r, XSTRING (Vuser_login_name)->data);
35692fe0
JB
124 r[q - p] = UPCASE (r[q - p]);
125 strcat (r, q + 1);
126 Vuser_full_name = build_string (r);
127 }
128#endif /* AMPERSAND_FULL_NAME */
9d36d071 129
8f1e2d16 130 p = (unsigned char *) getenv ("NAME");
9d36d071
RS
131 if (p)
132 Vuser_full_name = build_string (p);
35692fe0
JB
133}
134\f
135DEFUN ("char-to-string", Fchar_to_string, Schar_to_string, 1, 1, 0,
136 "Convert arg CHAR to a one-character string containing that character.")
137 (n)
138 Lisp_Object n;
139{
140 char c;
141 CHECK_NUMBER (n, 0);
142
143 c = XINT (n);
144 return make_string (&c, 1);
145}
146
147DEFUN ("string-to-char", Fstring_to_char, Sstring_to_char, 1, 1, 0,
148 "Convert arg STRING to a character, the first character of that string.")
149 (str)
150 register Lisp_Object str;
151{
152 register Lisp_Object val;
153 register struct Lisp_String *p;
154 CHECK_STRING (str, 0);
155
156 p = XSTRING (str);
157 if (p->size)
55561c63 158 XSETFASTINT (val, ((unsigned char *) p->data)[0]);
35692fe0 159 else
55561c63 160 XSETFASTINT (val, 0);
35692fe0
JB
161 return val;
162}
163\f
164static Lisp_Object
165buildmark (val)
166 int val;
167{
168 register Lisp_Object mark;
169 mark = Fmake_marker ();
170 Fset_marker (mark, make_number (val), Qnil);
171 return mark;
172}
173
174DEFUN ("point", Fpoint, Spoint, 0, 0, 0,
175 "Return value of point, as an integer.\n\
176Beginning of buffer is position (point-min)")
177 ()
178{
179 Lisp_Object temp;
55561c63 180 XSETFASTINT (temp, point);
35692fe0
JB
181 return temp;
182}
183
184DEFUN ("point-marker", Fpoint_marker, Spoint_marker, 0, 0, 0,
185 "Return value of point, as a marker object.")
186 ()
187{
188 return buildmark (point);
189}
190
191int
192clip_to_bounds (lower, num, upper)
193 int lower, num, upper;
194{
195 if (num < lower)
196 return lower;
197 else if (num > upper)
198 return upper;
199 else
200 return num;
201}
202
203DEFUN ("goto-char", Fgoto_char, Sgoto_char, 1, 1, "NGoto char: ",
204 "Set point to POSITION, a number or marker.\n\
205Beginning of buffer is position (point-min), end is (point-max).")
206 (n)
207 register Lisp_Object n;
208{
209 CHECK_NUMBER_COERCE_MARKER (n, 0);
210
211 SET_PT (clip_to_bounds (BEGV, XINT (n), ZV));
212 return n;
213}
214
215static Lisp_Object
216region_limit (beginningp)
217 int beginningp;
218{
646d9d18 219 extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c. */
35692fe0 220 register Lisp_Object m;
c9dd14e1
RM
221 if (!NILP (Vtransient_mark_mode) && NILP (Vmark_even_if_inactive)
222 && NILP (current_buffer->mark_active))
223 Fsignal (Qmark_inactive, Qnil);
35692fe0 224 m = Fmarker_position (current_buffer->mark);
56a98455 225 if (NILP (m)) error ("There is no region now");
35692fe0
JB
226 if ((point < XFASTINT (m)) == beginningp)
227 return (make_number (point));
228 else
229 return (m);
230}
231
232DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0,
233 "Return position of beginning of region, as an integer.")
234 ()
235{
236 return (region_limit (1));
237}
238
239DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0,
240 "Return position of end of region, as an integer.")
241 ()
242{
243 return (region_limit (0));
244}
245
35692fe0
JB
246DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0,
247 "Return this buffer's mark, as a marker object.\n\
248Watch out! Moving this marker changes the mark position.\n\
249If you set the marker not to point anywhere, the buffer will have no mark.")
250 ()
251{
252 return current_buffer->mark;
253}
254
35692fe0
JB
255Lisp_Object
256save_excursion_save ()
257{
0e2c9c70
JB
258 register int visible = (XBUFFER (XWINDOW (selected_window)->buffer)
259 == current_buffer);
35692fe0
JB
260
261 return Fcons (Fpoint_marker (),
aea4a109 262 Fcons (Fcopy_marker (current_buffer->mark, Qnil),
9772455e
RS
263 Fcons (visible ? Qt : Qnil,
264 current_buffer->mark_active)));
35692fe0
JB
265}
266
267Lisp_Object
268save_excursion_restore (info)
269 register Lisp_Object info;
270{
03d18690 271 register Lisp_Object tem, tem1, omark, nmark;
35692fe0
JB
272
273 tem = Fmarker_buffer (Fcar (info));
274 /* If buffer being returned to is now deleted, avoid error */
275 /* Otherwise could get error here while unwinding to top level
276 and crash */
277 /* In that case, Fmarker_buffer returns nil now. */
56a98455 278 if (NILP (tem))
35692fe0
JB
279 return Qnil;
280 Fset_buffer (tem);
281 tem = Fcar (info);
282 Fgoto_char (tem);
283 unchain_marker (tem);
284 tem = Fcar (Fcdr (info));
03d18690 285 omark = Fmarker_position (current_buffer->mark);
35692fe0 286 Fset_marker (current_buffer->mark, tem, Fcurrent_buffer ());
03d18690 287 nmark = Fmarker_position (tem);
35692fe0
JB
288 unchain_marker (tem);
289 tem = Fcdr (Fcdr (info));
ef580991
RS
290#if 0 /* We used to make the current buffer visible in the selected window
291 if that was true previously. That avoids some anomalies.
292 But it creates others, and it wasn't documented, and it is simpler
293 and cleaner never to alter the window/buffer connections. */
9772455e
RS
294 tem1 = Fcar (tem);
295 if (!NILP (tem1)
0e2c9c70 296 && current_buffer != XBUFFER (XWINDOW (selected_window)->buffer))
35692fe0 297 Fswitch_to_buffer (Fcurrent_buffer (), Qnil);
ef580991 298#endif /* 0 */
9772455e
RS
299
300 tem1 = current_buffer->mark_active;
301 current_buffer->mark_active = Fcdr (tem);
9fed2b18
RS
302 if (!NILP (Vrun_hooks))
303 {
03d18690
RS
304 /* If mark is active now, and either was not active
305 or was at a different place, run the activate hook. */
9fed2b18 306 if (! NILP (current_buffer->mark_active))
03d18690
RS
307 {
308 if (! EQ (omark, nmark))
309 call1 (Vrun_hooks, intern ("activate-mark-hook"));
310 }
311 /* If mark has ceased to be active, run deactivate hook. */
9fed2b18
RS
312 else if (! NILP (tem1))
313 call1 (Vrun_hooks, intern ("deactivate-mark-hook"));
314 }
35692fe0
JB
315 return Qnil;
316}
317
318DEFUN ("save-excursion", Fsave_excursion, Ssave_excursion, 0, UNEVALLED, 0,
319 "Save point, mark, and current buffer; execute BODY; restore those things.\n\
320Executes BODY just like `progn'.\n\
321The values of point, mark and the current buffer are restored\n\
9772455e
RS
322even in case of abnormal exit (throw or error).\n\
323The state of activation of the mark is also restored.")
35692fe0
JB
324 (args)
325 Lisp_Object args;
326{
327 register Lisp_Object val;
328 int count = specpdl_ptr - specpdl;
329
330 record_unwind_protect (save_excursion_restore, save_excursion_save ());
331
332 val = Fprogn (args);
333 return unbind_to (count, val);
334}
335\f
336DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 0, 0,
337 "Return the number of characters in the current buffer.")
338 ()
339{
340 Lisp_Object temp;
55561c63 341 XSETFASTINT (temp, Z - BEG);
35692fe0
JB
342 return temp;
343}
344
345DEFUN ("point-min", Fpoint_min, Spoint_min, 0, 0, 0,
346 "Return the minimum permissible value of point in the current buffer.\n\
4c390850 347This is 1, unless narrowing (a buffer restriction) is in effect.")
35692fe0
JB
348 ()
349{
350 Lisp_Object temp;
55561c63 351 XSETFASTINT (temp, BEGV);
35692fe0
JB
352 return temp;
353}
354
355DEFUN ("point-min-marker", Fpoint_min_marker, Spoint_min_marker, 0, 0, 0,
356 "Return a marker to the minimum permissible value of point in this buffer.\n\
4c390850 357This is the beginning, unless narrowing (a buffer restriction) is in effect.")
35692fe0
JB
358 ()
359{
360 return buildmark (BEGV);
361}
362
363DEFUN ("point-max", Fpoint_max, Spoint_max, 0, 0, 0,
364 "Return the maximum permissible value of point in the current buffer.\n\
4c390850
RS
365This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
366is in effect, in which case it is less.")
35692fe0
JB
367 ()
368{
369 Lisp_Object temp;
55561c63 370 XSETFASTINT (temp, ZV);
35692fe0
JB
371 return temp;
372}
373
374DEFUN ("point-max-marker", Fpoint_max_marker, Spoint_max_marker, 0, 0, 0,
375 "Return a marker to the maximum permissible value of point in this buffer.\n\
4c390850
RS
376This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
377is in effect, in which case it is less.")
35692fe0
JB
378 ()
379{
380 return buildmark (ZV);
381}
382
850a8179
JB
383DEFUN ("following-char", Ffollowing_char, Sfollowing_char, 0, 0, 0,
384 "Return the character following point, as a number.\n\
385At the end of the buffer or accessible region, return 0.")
35692fe0
JB
386 ()
387{
388 Lisp_Object temp;
850a8179 389 if (point >= ZV)
55561c63 390 XSETFASTINT (temp, 0);
850a8179 391 else
55561c63 392 XSETFASTINT (temp, FETCH_CHAR (point));
35692fe0
JB
393 return temp;
394}
395
850a8179
JB
396DEFUN ("preceding-char", Fprevious_char, Sprevious_char, 0, 0, 0,
397 "Return the character preceding point, as a number.\n\
398At the beginning of the buffer or accessible region, return 0.")
35692fe0
JB
399 ()
400{
401 Lisp_Object temp;
402 if (point <= BEGV)
55561c63 403 XSETFASTINT (temp, 0);
35692fe0 404 else
55561c63 405 XSETFASTINT (temp, FETCH_CHAR (point - 1));
35692fe0
JB
406 return temp;
407}
408
409DEFUN ("bobp", Fbobp, Sbobp, 0, 0, 0,
410 "Return T if point is at the beginning of the buffer.\n\
411If the buffer is narrowed, this means the beginning of the narrowed part.")
412 ()
413{
414 if (point == BEGV)
415 return Qt;
416 return Qnil;
417}
418
419DEFUN ("eobp", Feobp, Seobp, 0, 0, 0,
420 "Return T if point is at the end of the buffer.\n\
421If the buffer is narrowed, this means the end of the narrowed part.")
422 ()
423{
424 if (point == ZV)
425 return Qt;
426 return Qnil;
427}
428
429DEFUN ("bolp", Fbolp, Sbolp, 0, 0, 0,
430 "Return T if point is at the beginning of a line.")
431 ()
432{
433 if (point == BEGV || FETCH_CHAR (point - 1) == '\n')
434 return Qt;
435 return Qnil;
436}
437
438DEFUN ("eolp", Feolp, Seolp, 0, 0, 0,
439 "Return T if point is at the end of a line.\n\
440`End of a line' includes point being at the end of the buffer.")
441 ()
442{
443 if (point == ZV || FETCH_CHAR (point) == '\n')
444 return Qt;
445 return Qnil;
446}
447
448DEFUN ("char-after", Fchar_after, Schar_after, 1, 1, 0,
449 "Return character in current buffer at position POS.\n\
450POS is an integer or a buffer pointer.\n\
451If POS is out of range, the value is nil.")
452 (pos)
453 Lisp_Object pos;
454{
455 register Lisp_Object val;
456 register int n;
457
458 CHECK_NUMBER_COERCE_MARKER (pos, 0);
459
460 n = XINT (pos);
461 if (n < BEGV || n >= ZV) return Qnil;
462
55561c63 463 XSETFASTINT (val, FETCH_CHAR (n));
35692fe0
JB
464 return val;
465}
466\f
87485d6f 467DEFUN ("user-login-name", Fuser_login_name, Suser_login_name, 0, 1, 0,
35692fe0
JB
468 "Return the name under which the user logged in, as a string.\n\
469This is based on the effective uid, not the real uid.\n\
2c9ae24e 470Also, if the environment variable LOGNAME or USER is set,\n\
87485d6f
MW
471that determines the value of this function.\n\n\
472If optional argument UID is an integer, return the login name of the user\n\
473with that uid, or nil if there is no such user.")
474 (uid)
475 Lisp_Object uid;
35692fe0 476{
87485d6f
MW
477 struct passwd *pw;
478
f8a0e364
RS
479 /* Set up the user name info if we didn't do it before.
480 (That can happen if Emacs is dumpable
481 but you decide to run `temacs -l loadup' and not dump. */
35b34f72 482 if (INTEGERP (Vuser_login_name))
f8a0e364 483 init_editfns ();
87485d6f
MW
484
485 if (NILP (uid))
35b34f72 486 return Vuser_login_name;
87485d6f
MW
487
488 CHECK_NUMBER (uid, 0);
489 pw = (struct passwd *) getpwuid (XINT (uid));
490 return (pw ? build_string (pw->pw_name) : Qnil);
35692fe0
JB
491}
492
493DEFUN ("user-real-login-name", Fuser_real_login_name, Suser_real_login_name,
494 0, 0, 0,
495 "Return the name of the user's real uid, as a string.\n\
9658bdd0 496This ignores the environment variables LOGNAME and USER, so it differs from\n\
b1da234a 497`user-login-name' when running under `su'.")
35692fe0
JB
498 ()
499{
f8a0e364
RS
500 /* Set up the user name info if we didn't do it before.
501 (That can happen if Emacs is dumpable
502 but you decide to run `temacs -l loadup' and not dump. */
35b34f72 503 if (INTEGERP (Vuser_login_name))
f8a0e364 504 init_editfns ();
35b34f72 505 return Vuser_real_login_name;
35692fe0
JB
506}
507
508DEFUN ("user-uid", Fuser_uid, Suser_uid, 0, 0, 0,
509 "Return the effective uid of Emacs, as an integer.")
510 ()
511{
512 return make_number (geteuid ());
513}
514
515DEFUN ("user-real-uid", Fuser_real_uid, Suser_real_uid, 0, 0, 0,
516 "Return the real uid of Emacs, as an integer.")
517 ()
518{
519 return make_number (getuid ());
520}
521
522DEFUN ("user-full-name", Fuser_full_name, Suser_full_name, 0, 0, 0,
523 "Return the full name of the user logged in, as a string.")
524 ()
525{
526 return Vuser_full_name;
527}
528
529DEFUN ("system-name", Fsystem_name, Ssystem_name, 0, 0, 0,
530 "Return the name of the machine you are running on, as a string.")
531 ()
532{
533 return Vsystem_name;
534}
535
ac988277
KH
536/* For the benefit of callers who don't want to include lisp.h */
537char *
538get_system_name ()
539{
316506b2 540 return (char *) XSTRING (Vsystem_name)->data;
ac988277
KH
541}
542
7fd233b3
RS
543DEFUN ("emacs-pid", Femacs_pid, Semacs_pid, 0, 0, 0,
544 "Return the process ID of Emacs, as an integer.")
545 ()
546{
547 return make_number (getpid ());
548}
549
d940e0e4 550DEFUN ("current-time", Fcurrent_time, Scurrent_time, 0, 0, 0,
e983fdb2 551 "Return the current time, as the number of seconds since 1970-01-01 00:00:00.\n\
956ace37
JB
552The time is returned as a list of three integers. The first has the\n\
553most significant 16 bits of the seconds, while the second has the\n\
554least significant 16 bits. The third integer gives the microsecond\n\
555count.\n\
556\n\
557The microsecond count is zero on systems that do not provide\n\
558resolution finer than a second.")
d940e0e4
JB
559 ()
560{
956ace37
JB
561 EMACS_TIME t;
562 Lisp_Object result[3];
563
564 EMACS_GET_TIME (t);
d2fd0445
KH
565 XSETINT (result[0], (EMACS_SECS (t) >> 16) & 0xffff);
566 XSETINT (result[1], (EMACS_SECS (t) >> 0) & 0xffff);
567 XSETINT (result[2], EMACS_USECS (t));
956ace37
JB
568
569 return Flist (3, result);
d940e0e4
JB
570}
571\f
572
e3120ab5
JB
573static int
574lisp_time_argument (specified_time, result)
575 Lisp_Object specified_time;
576 time_t *result;
577{
578 if (NILP (specified_time))
579 return time (result) != -1;
580 else
581 {
582 Lisp_Object high, low;
583 high = Fcar (specified_time);
584 CHECK_NUMBER (high, 0);
585 low = Fcdr (specified_time);
ae683129 586 if (CONSP (low))
e3120ab5
JB
587 low = Fcar (low);
588 CHECK_NUMBER (low, 0);
589 *result = (XINT (high) << 16) + (XINT (low) & 0xffff);
590 return *result >> 16 == XINT (high);
591 }
592}
593
a82d387c
RS
594DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 2, 2, 0,
595 "Use FORMAT-STRING to format the time TIME.\n\
596TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from\n\
597`current-time' and `file-attributes'.\n\
598FORMAT-STRING may contain %-sequences to substitute parts of the time.\n\
599%a is replaced by the abbreviated name of the day of week.\n\
600%A is replaced by the full name of the day of week.\n\
601%b is replaced by the abbreviated name of the month.\n\
602%B is replaced by the full name of the month.\n\
603%c is a synonym for \"%x %X\".\n\
604%C is a locale-specific synonym, which defaults to \"%A, %B %e, %Y\" in the C locale.\n\
605%d is replaced by the day of month, zero-padded.\n\
606%D is a synonym for \"%m/%d/%y\".\n\
607%e is replaced by the day of month, blank-padded.\n\
608%h is a synonym for \"%b\".\n\
609%H is replaced by the hour (00-23).\n\
610%I is replaced by the hour (00-12).\n\
611%j is replaced by the day of the year (001-366).\n\
612%k is replaced by the hour (0-23), blank padded.\n\
613%l is replaced by the hour (1-12), blank padded.\n\
614%m is replaced by the month (01-12).\n\
615%M is replaced by the minut (00-59).\n\
616%n is a synonym for \"\\n\".\n\
617%p is replaced by AM or PM, as appropriate.\n\
618%r is a synonym for \"%I:%M:%S %p\".\n\
619%R is a synonym for \"%H:%M\".\n\
620%S is replaced by the seconds (00-60).\n\
621%t is a synonym for \"\\t\".\n\
622%T is a synonym for \"%H:%M:%S\".\n\
623%U is replaced by the week of the year (01-52), first day of week is Sunday.\n\
624%w is replaced by the day of week (0-6), Sunday is day 0.\n\
625%W is replaced by the week of the year (01-52), first day of week is Monday.\n\
626%x is a locale-specific synonym, which defaults to \"%D\" in the C locale.\n\
627%X is a locale-specific synonym, which defaults to \"%T\" in the C locale.\n\
628%y is replaced by the year without century (00-99).\n\
629%Y is replaced by the year with century.\n\
630%Z is replaced by the time zone abbreviation.\n\
631\n\
57937a87 632The number of options reflects the `strftime' function.")
a82d387c
RS
633 (format_string, time)
634 Lisp_Object format_string, time;
635{
636 time_t value;
637 int size;
638
639 CHECK_STRING (format_string, 1);
640
641 if (! lisp_time_argument (time, &value))
642 error ("Invalid time specification");
643
644 /* This is probably enough. */
645 size = XSTRING (format_string)->size * 6 + 50;
646
647 while (1)
648 {
649 char *buf = (char *) alloca (size);
57937a87
RS
650 if (emacs_strftime (buf, size, XSTRING (format_string)->data,
651 localtime (&value)))
a82d387c
RS
652 return build_string (buf);
653 /* If buffer was too small, make it bigger. */
654 size *= 2;
655 }
656}
657
4691c06d
RS
658DEFUN ("decode-time", Fdecode_time, Sdecode_time, 0, 1, 0,
659 "Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).\n\
660The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)\n\
661or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'\n\
662to use the current time. The list has the following nine members:\n\
145b0681
RS
663SEC is an integer between 0 and 60; SEC is 60 for a leap second, which\n\
664only some operating systems support. MINUTE is an integer between 0 and 59.\n\
4691c06d
RS
665HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.\n\
666MONTH is an integer between 1 and 12. YEAR is an integer indicating the\n\
667four-digit year. DOW is the day of week, an integer between 0 and 6, where\n\
6680 is Sunday. DST is t if daylight savings time is effect, otherwise nil.\n\
669ZONE is an integer indicating the number of seconds east of Greenwich.\n\
2c6c7c72 670\(Note that Common Lisp has different meanings for DOW and ZONE.)")
4691c06d
RS
671 (specified_time)
672 Lisp_Object specified_time;
673{
674 time_t time_spec;
3c887943 675 struct tm save_tm;
4691c06d
RS
676 struct tm *decoded_time;
677 Lisp_Object list_args[9];
678
679 if (! lisp_time_argument (specified_time, &time_spec))
680 error ("Invalid time specification");
681
682 decoded_time = localtime (&time_spec);
3c887943
KH
683 XSETFASTINT (list_args[0], decoded_time->tm_sec);
684 XSETFASTINT (list_args[1], decoded_time->tm_min);
685 XSETFASTINT (list_args[2], decoded_time->tm_hour);
686 XSETFASTINT (list_args[3], decoded_time->tm_mday);
687 XSETFASTINT (list_args[4], decoded_time->tm_mon + 1);
688 XSETFASTINT (list_args[5], decoded_time->tm_year + 1900);
689 XSETFASTINT (list_args[6], decoded_time->tm_wday);
4691c06d 690 list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil;
3c887943
KH
691
692 /* Make a copy, in case gmtime modifies the struct. */
693 save_tm = *decoded_time;
694 decoded_time = gmtime (&time_spec);
695 if (decoded_time == 0)
696 list_args[8] = Qnil;
697 else
698 XSETINT (list_args[8], difftm (&save_tm, decoded_time));
4691c06d
RS
699 return Flist (9, list_args);
700}
701
cce7b8a0 702DEFUN ("encode-time", Fencode_time, Sencode_time, 6, 7, 0,
d65666d5 703 "Convert SEC, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.\n\
167d976b 704This is the reverse operation of `decode-time', which see. ZONE defaults\n\
c59b5089
PE
705to the current time zone rule if not specified; if specified, it can\n\
706be a string (as from `set-time-zone-rule'), or it can be a list\n\
707(as from `current-time-zone') or an integer (as from `decode-time')\n\
708applied without consideration for daylight savings time.\n\
709Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;\n\
710for example, a DAY of 0 means the day preceding the given month.\n\
01ba8cce 711Year numbers less than 100 are treated just like other year numbers.\n\
c59b5089 712If you want them to stand for years in this century, you must do that yourself.")
d65666d5
RS
713 (sec, minute, hour, day, month, year, zone)
714 Lisp_Object sec, minute, hour, day, month, year, zone;
cce7b8a0 715{
1b8fa736 716 time_t time;
c59b5089
PE
717 struct tm tm;
718
719 CHECK_NUMBER (sec, 0);
720 CHECK_NUMBER (minute, 1);
721 CHECK_NUMBER (hour, 2);
722 CHECK_NUMBER (day, 3);
723 CHECK_NUMBER (month, 4);
724 CHECK_NUMBER (year, 5);
725
726 tm.tm_sec = XINT (sec);
727 tm.tm_min = XINT (minute);
728 tm.tm_hour = XINT (hour);
729 tm.tm_mday = XINT (day);
730 tm.tm_mon = XINT (month) - 1;
731 tm.tm_year = XINT (year) - 1900;
732 tm.tm_isdst = -1;
733
734 if (CONSP (zone))
735 zone = Fcar (zone);
1b8fa736 736 if (NILP (zone))
c59b5089
PE
737 time = mktime (&tm);
738 else
1b8fa736 739 {
c59b5089
PE
740 char tzbuf[100];
741 char *tzstring;
742 char **oldenv = environ, **newenv;
743
744 if (STRINGP (zone))
4d4c1514 745 tzstring = (char *) XSTRING (zone)->data;
c59b5089 746 else if (INTEGERP (zone))
1b8fa736 747 {
c59b5089
PE
748 int abszone = abs (XINT (zone));
749 sprintf (tzbuf, "XXX%s%d:%02d:%02d", "-" + (XINT (zone) < 0),
750 abszone / (60*60), (abszone/60) % 60, abszone % 60);
751 tzstring = tzbuf;
1b8fa736 752 }
c59b5089
PE
753 else
754 error ("Invalid time zone specification");
755
756 /* Set TZ before calling mktime; merely adjusting mktime's returned
757 value doesn't suffice, since that would mishandle leap seconds. */
758 set_time_zone_rule (tzstring);
759
760 time = mktime (&tm);
761
762 /* Restore TZ to previous value. */
763 newenv = environ;
764 environ = oldenv;
765 free (newenv);
766#ifdef LOCALTIME_CACHE
767 tzset ();
768#endif
1b8fa736 769 }
1b8fa736 770
c59b5089
PE
771 if (time == (time_t) -1)
772 error ("Specified time is not representable");
773
774 return make_time (time);
cce7b8a0
RS
775}
776
2148f2b4 777DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0,
35692fe0 778 "Return the current time, as a human-readable string.\n\
2148f2b4
RS
779Programs can use this function to decode a time,\n\
780since the number of columns in each field is fixed.\n\
781The format is `Sun Sep 16 01:03:52 1973'.\n\
782If an argument is given, it specifies a time to format\n\
783instead of the current time. The argument should have the form:\n\
784 (HIGH . LOW)\n\
785or the form:\n\
786 (HIGH LOW . IGNORED).\n\
787Thus, you can use times obtained from `current-time'\n\
788and from `file-attributes'.")
789 (specified_time)
790 Lisp_Object specified_time;
791{
e3120ab5 792 time_t value;
35692fe0 793 char buf[30];
2148f2b4
RS
794 register char *tem;
795
e3120ab5
JB
796 if (! lisp_time_argument (specified_time, &value))
797 value = -1;
2148f2b4 798 tem = (char *) ctime (&value);
35692fe0
JB
799
800 strncpy (buf, tem, 24);
801 buf[24] = 0;
802
803 return build_string (buf);
804}
c2662aea 805
e3120ab5
JB
806#define TM_YEAR_ORIGIN 1900
807
808/* Yield A - B, measured in seconds. */
809static long
8e718b4e 810difftm (a, b)
e3120ab5
JB
811 struct tm *a, *b;
812{
813 int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
814 int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
8e718b4e 815 /* Some compilers can't handle this as a single return statement. */
68a49b18 816 long days = (
8e718b4e
KH
817 /* difference in day of year */
818 a->tm_yday - b->tm_yday
819 /* + intervening leap days */
820 + ((ay >> 2) - (by >> 2))
821 - (ay/100 - by/100)
822 + ((ay/100 >> 2) - (by/100 >> 2))
823 /* + difference in years * 365 */
824 + (long)(ay-by) * 365
825 );
826 return (60*(60*(24*days + (a->tm_hour - b->tm_hour))
827 + (a->tm_min - b->tm_min))
828 + (a->tm_sec - b->tm_sec));
e3120ab5
JB
829}
830
831DEFUN ("current-time-zone", Fcurrent_time_zone, Scurrent_time_zone, 0, 1, 0,
832 "Return the offset and name for the local time zone.\n\
833This returns a list of the form (OFFSET NAME).\n\
834OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).\n\
835 A negative value means west of Greenwich.\n\
836NAME is a string giving the name of the time zone.\n\
837If an argument is given, it specifies when the time zone offset is determined\n\
838instead of using the current time. The argument should have the form:\n\
839 (HIGH . LOW)\n\
840or the form:\n\
841 (HIGH LOW . IGNORED).\n\
842Thus, you can use times obtained from `current-time'\n\
843and from `file-attributes'.\n\
773c1fd3
JB
844\n\
845Some operating systems cannot provide all this information to Emacs;\n\
2d88f747 846in this case, `current-time-zone' returns a list containing nil for\n\
773c1fd3 847the data it can't find.")
e3120ab5
JB
848 (specified_time)
849 Lisp_Object specified_time;
c2662aea 850{
e3120ab5
JB
851 time_t value;
852 struct tm *t;
c2662aea 853
e3120ab5 854 if (lisp_time_argument (specified_time, &value)
2d88f747 855 && (t = gmtime (&value)) != 0)
e3120ab5 856 {
2d88f747 857 struct tm gmt;
e3120ab5
JB
858 long offset;
859 char *s, buf[6];
2d88f747
RS
860
861 gmt = *t; /* Make a copy, in case localtime modifies *t. */
862 t = localtime (&value);
863 offset = difftm (t, &gmt);
e3120ab5
JB
864 s = 0;
865#ifdef HAVE_TM_ZONE
866 if (t->tm_zone)
5fd4de15 867 s = (char *)t->tm_zone;
a7971c39
RS
868#else /* not HAVE_TM_ZONE */
869#ifdef HAVE_TZNAME
870 if (t->tm_isdst == 0 || t->tm_isdst == 1)
871 s = tzname[t->tm_isdst];
c2662aea 872#endif
a7971c39 873#endif /* not HAVE_TM_ZONE */
e3120ab5
JB
874 if (!s)
875 {
876 /* No local time zone name is available; use "+-NNNN" instead. */
00fc94d0 877 int am = (offset < 0 ? -offset : offset) / 60;
e3120ab5
JB
878 sprintf (buf, "%c%02d%02d", (offset < 0 ? '-' : '+'), am/60, am%60);
879 s = buf;
880 }
881 return Fcons (make_number (offset), Fcons (build_string (s), Qnil));
882 }
883 else
884 return Fmake_list (2, Qnil);
c2662aea
JB
885}
886
260e2e2a
KH
887/* This holds the value of `environ' produced by the previous
888 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
889 has never been called. */
890static char **environbuf;
891
143cb9a9
RS
892DEFUN ("set-time-zone-rule", Fset_time_zone_rule, Sset_time_zone_rule, 1, 1, 0,
893 "Set the local time zone using TZ, a string specifying a time zone rule.\n\
894If TZ is nil, use implementation-defined default time zone information.")
895 (tz)
896 Lisp_Object tz;
897{
143cb9a9
RS
898 char *tzstring;
899
900 if (NILP (tz))
901 tzstring = 0;
902 else
903 {
904 CHECK_STRING (tz, 0);
4d4c1514 905 tzstring = (char *) XSTRING (tz)->data;
143cb9a9
RS
906 }
907
c59b5089
PE
908 set_time_zone_rule (tzstring);
909 if (environbuf)
910 free (environbuf);
911 environbuf = environ;
912
913 return Qnil;
914}
915
916/* Set the local time zone rule to TZSTRING.
917 This allocates memory into `environ', which it is the caller's
918 responsibility to free. */
919static void
920set_time_zone_rule (tzstring)
921 char *tzstring;
922{
923 int envptrs;
924 char **from, **to, **newenv;
925
143cb9a9
RS
926 for (from = environ; *from; from++)
927 continue;
928 envptrs = from - environ + 2;
929 newenv = to = (char **) xmalloc (envptrs * sizeof (char *)
930 + (tzstring ? strlen (tzstring) + 4 : 0));
931 if (tzstring)
932 {
933 char *t = (char *) (to + envptrs);
934 strcpy (t, "TZ=");
935 strcat (t, tzstring);
936 *to++ = t;
937 }
938
939 for (from = environ; *from; from++)
940 if (strncmp (*from, "TZ=", 3) != 0)
941 *to++ = *from;
942 *to = 0;
943
944 environ = newenv;
143cb9a9
RS
945
946#ifdef LOCALTIME_CACHE
947 tzset ();
948#endif
143cb9a9 949}
35692fe0
JB
950\f
951void
952insert1 (arg)
953 Lisp_Object arg;
954{
955 Finsert (1, &arg);
956}
957
52b14ac0
JB
958
959/* Callers passing one argument to Finsert need not gcpro the
960 argument "array", since the only element of the array will
961 not be used after calling insert or insert_from_string, so
962 we don't care if it gets trashed. */
963
35692fe0
JB
964DEFUN ("insert", Finsert, Sinsert, 0, MANY, 0,
965 "Insert the arguments, either strings or characters, at point.\n\
966Point moves forward so that it ends up after the inserted text.\n\
967Any other markers at the point of insertion remain before the text.")
968 (nargs, args)
969 int nargs;
970 register Lisp_Object *args;
971{
972 register int argnum;
973 register Lisp_Object tem;
974 char str[1];
35692fe0
JB
975
976 for (argnum = 0; argnum < nargs; argnum++)
977 {
978 tem = args[argnum];
979 retry:
ae683129 980 if (INTEGERP (tem))
35692fe0
JB
981 {
982 str[0] = XINT (tem);
983 insert (str, 1);
984 }
ae683129 985 else if (STRINGP (tem))
35692fe0 986 {
be91036a
RS
987 insert_from_string (tem, 0, XSTRING (tem)->size, 0);
988 }
989 else
990 {
991 tem = wrong_type_argument (Qchar_or_string_p, tem);
992 goto retry;
993 }
994 }
995
996 return Qnil;
997}
998
999DEFUN ("insert-and-inherit", Finsert_and_inherit, Sinsert_and_inherit,
1000 0, MANY, 0,
1001 "Insert the arguments at point, inheriting properties from adjoining text.\n\
1002Point moves forward so that it ends up after the inserted text.\n\
1003Any other markers at the point of insertion remain before the text.")
1004 (nargs, args)
1005 int nargs;
1006 register Lisp_Object *args;
1007{
1008 register int argnum;
1009 register Lisp_Object tem;
1010 char str[1];
1011
1012 for (argnum = 0; argnum < nargs; argnum++)
1013 {
1014 tem = args[argnum];
1015 retry:
ae683129 1016 if (INTEGERP (tem))
be91036a
RS
1017 {
1018 str[0] = XINT (tem);
107740f5 1019 insert_and_inherit (str, 1);
be91036a 1020 }
ae683129 1021 else if (STRINGP (tem))
be91036a
RS
1022 {
1023 insert_from_string (tem, 0, XSTRING (tem)->size, 1);
35692fe0
JB
1024 }
1025 else
1026 {
1027 tem = wrong_type_argument (Qchar_or_string_p, tem);
1028 goto retry;
1029 }
1030 }
1031
35692fe0
JB
1032 return Qnil;
1033}
1034
1035DEFUN ("insert-before-markers", Finsert_before_markers, Sinsert_before_markers, 0, MANY, 0,
1036 "Insert strings or characters at point, relocating markers after the text.\n\
1037Point moves forward so that it ends up after the inserted text.\n\
1038Any other markers at the point of insertion also end up after the text.")
1039 (nargs, args)
1040 int nargs;
1041 register Lisp_Object *args;
1042{
1043 register int argnum;
1044 register Lisp_Object tem;
1045 char str[1];
35692fe0
JB
1046
1047 for (argnum = 0; argnum < nargs; argnum++)
1048 {
1049 tem = args[argnum];
1050 retry:
ae683129 1051 if (INTEGERP (tem))
35692fe0
JB
1052 {
1053 str[0] = XINT (tem);
1054 insert_before_markers (str, 1);
1055 }
ae683129 1056 else if (STRINGP (tem))
35692fe0 1057 {
be91036a
RS
1058 insert_from_string_before_markers (tem, 0, XSTRING (tem)->size, 0);
1059 }
1060 else
1061 {
1062 tem = wrong_type_argument (Qchar_or_string_p, tem);
1063 goto retry;
1064 }
1065 }
1066
1067 return Qnil;
1068}
1069
1070DEFUN ("insert-before-markers-and-inherit",
1071 Finsert_and_inherit_before_markers, Sinsert_and_inherit_before_markers,
1072 0, MANY, 0,
1073 "Insert text at point, relocating markers and inheriting properties.\n\
1074Point moves forward so that it ends up after the inserted text.\n\
1075Any other markers at the point of insertion also end up after the text.")
1076 (nargs, args)
1077 int nargs;
1078 register Lisp_Object *args;
1079{
1080 register int argnum;
1081 register Lisp_Object tem;
1082 char str[1];
1083
1084 for (argnum = 0; argnum < nargs; argnum++)
1085 {
1086 tem = args[argnum];
1087 retry:
ae683129 1088 if (INTEGERP (tem))
be91036a
RS
1089 {
1090 str[0] = XINT (tem);
107740f5 1091 insert_before_markers_and_inherit (str, 1);
be91036a 1092 }
ae683129 1093 else if (STRINGP (tem))
be91036a
RS
1094 {
1095 insert_from_string_before_markers (tem, 0, XSTRING (tem)->size, 1);
35692fe0
JB
1096 }
1097 else
1098 {
1099 tem = wrong_type_argument (Qchar_or_string_p, tem);
1100 goto retry;
1101 }
1102 }
1103
35692fe0
JB
1104 return Qnil;
1105}
1106\f
e2eeabbb 1107DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 3, 0,
35692fe0
JB
1108 "Insert COUNT (second arg) copies of CHAR (first arg).\n\
1109Point and all markers are affected as in the function `insert'.\n\
e2eeabbb
RS
1110Both arguments are required.\n\
1111The optional third arg INHERIT, if non-nil, says to inherit text properties\n\
1112from adjoining text, if those properties are sticky.")
1113 (chr, count, inherit)
1114 Lisp_Object chr, count, inherit;
35692fe0
JB
1115{
1116 register unsigned char *string;
1117 register int strlen;
1118 register int i, n;
1119
1120 CHECK_NUMBER (chr, 0);
1121 CHECK_NUMBER (count, 1);
1122
1123 n = XINT (count);
1124 if (n <= 0)
1125 return Qnil;
1126 strlen = min (n, 256);
1127 string = (unsigned char *) alloca (strlen);
1128 for (i = 0; i < strlen; i++)
1129 string[i] = XFASTINT (chr);
1130 while (n >= strlen)
1131 {
e2eeabbb
RS
1132 if (!NILP (inherit))
1133 insert_and_inherit (string, strlen);
1134 else
1135 insert (string, strlen);
35692fe0
JB
1136 n -= strlen;
1137 }
1138 if (n > 0)
83951f1e
KH
1139 {
1140 if (!NILP (inherit))
1141 insert_and_inherit (string, n);
1142 else
1143 insert (string, n);
1144 }
35692fe0
JB
1145 return Qnil;
1146}
1147
1148\f
ffd56f97
JB
1149/* Making strings from buffer contents. */
1150
1151/* Return a Lisp_String containing the text of the current buffer from
74d6d8c5 1152 START to END. If text properties are in use and the current buffer
eb8c3be9 1153 has properties in the range specified, the resulting string will also
260e2e2a 1154 have them, if PROPS is nonzero.
ffd56f97
JB
1155
1156 We don't want to use plain old make_string here, because it calls
1157 make_uninit_string, which can cause the buffer arena to be
1158 compacted. make_string has no way of knowing that the data has
1159 been moved, and thus copies the wrong data into the string. This
1160 doesn't effect most of the other users of make_string, so it should
1161 be left as is. But we should use this function when conjuring
1162 buffer substrings. */
74d6d8c5 1163
ffd56f97 1164Lisp_Object
260e2e2a 1165make_buffer_string (start, end, props)
ffd56f97 1166 int start, end;
260e2e2a 1167 int props;
ffd56f97 1168{
36b0d50e 1169 Lisp_Object result, tem, tem1;
ffd56f97
JB
1170
1171 if (start < GPT && GPT < end)
1172 move_gap (start);
1173
1174 result = make_uninit_string (end - start);
1175 bcopy (&FETCH_CHAR (start), XSTRING (result)->data, end - start);
1176
260e2e2a 1177 /* If desired, update and copy the text properties. */
60b96ee7 1178#ifdef USE_TEXT_PROPERTIES
260e2e2a
KH
1179 if (props)
1180 {
1181 update_buffer_properties (start, end);
1182
1183 tem = Fnext_property_change (make_number (start), Qnil, make_number (end));
1184 tem1 = Ftext_properties_at (make_number (start), Qnil);
1185
1186 if (XINT (tem) != end || !NILP (tem1))
1187 copy_intervals_to_string (result, current_buffer, start, end - start);
1188 }
60b96ee7 1189#endif
74d6d8c5 1190
ffd56f97
JB
1191 return result;
1192}
35692fe0 1193
260e2e2a
KH
1194/* Call Vbuffer_access_fontify_functions for the range START ... END
1195 in the current buffer, if necessary. */
1196
1197static void
1198update_buffer_properties (start, end)
1199 int start, end;
1200{
1201#ifdef USE_TEXT_PROPERTIES
1202 /* If this buffer has some access functions,
1203 call them, specifying the range of the buffer being accessed. */
1204 if (!NILP (Vbuffer_access_fontify_functions))
1205 {
1206 Lisp_Object args[3];
1207 Lisp_Object tem;
1208
1209 args[0] = Qbuffer_access_fontify_functions;
1210 XSETINT (args[1], start);
1211 XSETINT (args[2], end);
1212
1213 /* But don't call them if we can tell that the work
1214 has already been done. */
1215 if (!NILP (Vbuffer_access_fontified_property))
1216 {
1217 tem = Ftext_property_any (args[1], args[2],
1218 Vbuffer_access_fontified_property,
1219 Qnil, Qnil);
1220 if (! NILP (tem))
1221 Frun_hook_with_args (3, &args);
1222 }
1223 else
1224 Frun_hook_with_args (3, &args);
1225 }
1226#endif
1227}
1228
35692fe0
JB
1229DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,
1230 "Return the contents of part of the current buffer as a string.\n\
1231The two arguments START and END are character positions;\n\
1232they can be in either order.")
1233 (b, e)
1234 Lisp_Object b, e;
1235{
1236 register int beg, end;
35692fe0
JB
1237
1238 validate_region (&b, &e);
1239 beg = XINT (b);
1240 end = XINT (e);
1241
260e2e2a
KH
1242 return make_buffer_string (beg, end, 1);
1243}
1244
1245DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties,
1246 Sbuffer_substring_no_properties, 2, 2, 0,
1247 "Return the characters of part of the buffer, without the text properties.\n\
1248The two arguments START and END are character positions;\n\
1249they can be in either order.")
1250 (b, e)
1251 Lisp_Object b, e;
1252{
1253 register int beg, end;
1254
1255 validate_region (&b, &e);
1256 beg = XINT (b);
1257 end = XINT (e);
1258
1259 return make_buffer_string (beg, end, 0);
35692fe0
JB
1260}
1261
1262DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,
af7bd86c
KH
1263 "Return the contents of the current buffer as a string.\n\
1264If narrowing is in effect, this function returns only the visible part\n\
1265of the buffer.")
35692fe0
JB
1266 ()
1267{
260e2e2a 1268 return make_buffer_string (BEGV, ZV, 1);
35692fe0
JB
1269}
1270
1271DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,
1272 1, 3, 0,
83ea6fc2 1273 "Insert before point a substring of the contents of buffer BUFFER.\n\
35692fe0
JB
1274BUFFER may be a buffer or a buffer name.\n\
1275Arguments START and END are character numbers specifying the substring.\n\
1276They default to the beginning and the end of BUFFER.")
1277 (buf, b, e)
1278 Lisp_Object buf, b, e;
1279{
b1b0ee5a 1280 register int beg, end, temp;
260e2e2a 1281 register struct buffer *bp, *obuf;
3fff2dfa 1282 Lisp_Object buffer;
35692fe0 1283
3fff2dfa
RS
1284 buffer = Fget_buffer (buf);
1285 if (NILP (buffer))
1286 nsberror (buf);
1287 bp = XBUFFER (buffer);
35692fe0 1288
56a98455 1289 if (NILP (b))
35692fe0
JB
1290 beg = BUF_BEGV (bp);
1291 else
1292 {
1293 CHECK_NUMBER_COERCE_MARKER (b, 0);
1294 beg = XINT (b);
1295 }
56a98455 1296 if (NILP (e))
35692fe0
JB
1297 end = BUF_ZV (bp);
1298 else
1299 {
1300 CHECK_NUMBER_COERCE_MARKER (e, 1);
1301 end = XINT (e);
1302 }
1303
1304 if (beg > end)
74d6d8c5 1305 temp = beg, beg = end, end = temp;
35692fe0 1306
b1b0ee5a 1307 if (!(BUF_BEGV (bp) <= beg && end <= BUF_ZV (bp)))
35692fe0
JB
1308 args_out_of_range (b, e);
1309
260e2e2a
KH
1310 obuf = current_buffer;
1311 set_buffer_internal_1 (bp);
1312 update_buffer_properties (beg, end);
1313 set_buffer_internal_1 (obuf);
1314
b1b0ee5a 1315 insert_from_buffer (bp, beg, end - beg, 0);
35692fe0
JB
1316 return Qnil;
1317}
e9cf2084
RS
1318
1319DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings, Scompare_buffer_substrings,
1320 6, 6, 0,
1321 "Compare two substrings of two buffers; return result as number.\n\
1322the value is -N if first string is less after N-1 chars,\n\
1323+N if first string is greater after N-1 chars, or 0 if strings match.\n\
1324Each substring is represented as three arguments: BUFFER, START and END.\n\
1325That makes six args in all, three for each substring.\n\n\
1326The value of `case-fold-search' in the current buffer\n\
1327determines whether case is significant or ignored.")
1328 (buffer1, start1, end1, buffer2, start2, end2)
1329 Lisp_Object buffer1, start1, end1, buffer2, start2, end2;
1330{
1331 register int begp1, endp1, begp2, endp2, temp, len1, len2, length, i;
1332 register struct buffer *bp1, *bp2;
1333 register unsigned char *trt
1334 = (!NILP (current_buffer->case_fold_search)
1335 ? XSTRING (current_buffer->case_canon_table)->data : 0);
1336
1337 /* Find the first buffer and its substring. */
1338
1339 if (NILP (buffer1))
1340 bp1 = current_buffer;
1341 else
1342 {
3fff2dfa
RS
1343 Lisp_Object buf1;
1344 buf1 = Fget_buffer (buffer1);
1345 if (NILP (buf1))
1346 nsberror (buffer1);
1347 bp1 = XBUFFER (buf1);
e9cf2084
RS
1348 }
1349
1350 if (NILP (start1))
1351 begp1 = BUF_BEGV (bp1);
1352 else
1353 {
1354 CHECK_NUMBER_COERCE_MARKER (start1, 1);
1355 begp1 = XINT (start1);
1356 }
1357 if (NILP (end1))
1358 endp1 = BUF_ZV (bp1);
1359 else
1360 {
1361 CHECK_NUMBER_COERCE_MARKER (end1, 2);
1362 endp1 = XINT (end1);
1363 }
1364
1365 if (begp1 > endp1)
1366 temp = begp1, begp1 = endp1, endp1 = temp;
1367
1368 if (!(BUF_BEGV (bp1) <= begp1
1369 && begp1 <= endp1
1370 && endp1 <= BUF_ZV (bp1)))
1371 args_out_of_range (start1, end1);
1372
1373 /* Likewise for second substring. */
1374
1375 if (NILP (buffer2))
1376 bp2 = current_buffer;
1377 else
1378 {
3fff2dfa
RS
1379 Lisp_Object buf2;
1380 buf2 = Fget_buffer (buffer2);
1381 if (NILP (buf2))
1382 nsberror (buffer2);
e9cf2084
RS
1383 bp2 = XBUFFER (buffer2);
1384 }
1385
1386 if (NILP (start2))
1387 begp2 = BUF_BEGV (bp2);
1388 else
1389 {
1390 CHECK_NUMBER_COERCE_MARKER (start2, 4);
1391 begp2 = XINT (start2);
1392 }
1393 if (NILP (end2))
1394 endp2 = BUF_ZV (bp2);
1395 else
1396 {
1397 CHECK_NUMBER_COERCE_MARKER (end2, 5);
1398 endp2 = XINT (end2);
1399 }
1400
1401 if (begp2 > endp2)
1402 temp = begp2, begp2 = endp2, endp2 = temp;
1403
1404 if (!(BUF_BEGV (bp2) <= begp2
1405 && begp2 <= endp2
1406 && endp2 <= BUF_ZV (bp2)))
1407 args_out_of_range (start2, end2);
1408
1409 len1 = endp1 - begp1;
1410 len2 = endp2 - begp2;
1411 length = len1;
1412 if (len2 < length)
1413 length = len2;
1414
1415 for (i = 0; i < length; i++)
1416 {
1417 int c1 = *BUF_CHAR_ADDRESS (bp1, begp1 + i);
1418 int c2 = *BUF_CHAR_ADDRESS (bp2, begp2 + i);
1419 if (trt)
1420 {
1421 c1 = trt[c1];
1422 c2 = trt[c2];
1423 }
1424 if (c1 < c2)
1425 return make_number (- 1 - i);
1426 if (c1 > c2)
1427 return make_number (i + 1);
1428 }
1429
1430 /* The strings match as far as they go.
1431 If one is shorter, that one is less. */
1432 if (length < len1)
1433 return make_number (length + 1);
1434 else if (length < len2)
1435 return make_number (- length - 1);
1436
1437 /* Same length too => they are equal. */
1438 return make_number (0);
1439}
35692fe0 1440\f
d5a539cd
RS
1441static Lisp_Object
1442subst_char_in_region_unwind (arg)
1443 Lisp_Object arg;
1444{
1445 return current_buffer->undo_list = arg;
1446}
1447
c8e76b47
RS
1448static Lisp_Object
1449subst_char_in_region_unwind_1 (arg)
1450 Lisp_Object arg;
1451{
1452 return current_buffer->filename = arg;
1453}
1454
35692fe0
JB
1455DEFUN ("subst-char-in-region", Fsubst_char_in_region,
1456 Ssubst_char_in_region, 4, 5, 0,
1457 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\
1458If optional arg NOUNDO is non-nil, don't record this change for undo\n\
1459and don't mark the buffer as really changed.")
1460 (start, end, fromchar, tochar, noundo)
1461 Lisp_Object start, end, fromchar, tochar, noundo;
1462{
1463 register int pos, stop, look;
60b96ee7 1464 int changed = 0;
d5a539cd 1465 int count = specpdl_ptr - specpdl;
35692fe0
JB
1466
1467 validate_region (&start, &end);
1468 CHECK_NUMBER (fromchar, 2);
1469 CHECK_NUMBER (tochar, 3);
1470
1471 pos = XINT (start);
1472 stop = XINT (end);
1473 look = XINT (fromchar);
1474
d5a539cd
RS
1475 /* If we don't want undo, turn off putting stuff on the list.
1476 That's faster than getting rid of things,
c8e76b47
RS
1477 and it prevents even the entry for a first change.
1478 Also inhibit locking the file. */
d5a539cd
RS
1479 if (!NILP (noundo))
1480 {
1481 record_unwind_protect (subst_char_in_region_unwind,
1482 current_buffer->undo_list);
1483 current_buffer->undo_list = Qt;
c8e76b47
RS
1484 /* Don't do file-locking. */
1485 record_unwind_protect (subst_char_in_region_unwind_1,
1486 current_buffer->filename);
1487 current_buffer->filename = Qnil;
d5a539cd
RS
1488 }
1489
35692fe0
JB
1490 while (pos < stop)
1491 {
1492 if (FETCH_CHAR (pos) == look)
1493 {
60b96ee7
RS
1494 if (! changed)
1495 {
1496 modify_region (current_buffer, XINT (start), stop);
7653d030
RS
1497
1498 if (! NILP (noundo))
1499 {
1e158d25
RS
1500 if (MODIFF - 1 == SAVE_MODIFF)
1501 SAVE_MODIFF++;
7653d030
RS
1502 if (MODIFF - 1 == current_buffer->auto_save_modified)
1503 current_buffer->auto_save_modified++;
1504 }
1505
1506 changed = 1;
60b96ee7
RS
1507 }
1508
56a98455 1509 if (NILP (noundo))
35692fe0
JB
1510 record_change (pos, 1);
1511 FETCH_CHAR (pos) = XINT (tochar);
35692fe0
JB
1512 }
1513 pos++;
1514 }
1515
60b96ee7
RS
1516 if (changed)
1517 signal_after_change (XINT (start),
1518 stop - XINT (start), stop - XINT (start));
1519
d5a539cd 1520 unbind_to (count, Qnil);
35692fe0
JB
1521 return Qnil;
1522}
1523
1524DEFUN ("translate-region", Ftranslate_region, Stranslate_region, 3, 3, 0,
1525 "From START to END, translate characters according to TABLE.\n\
1526TABLE is a string; the Nth character in it is the mapping\n\
1527for the character with code N. Returns the number of characters changed.")
1528 (start, end, table)
1529 Lisp_Object start;
1530 Lisp_Object end;
1531 register Lisp_Object table;
1532{
1533 register int pos, stop; /* Limits of the region. */
1534 register unsigned char *tt; /* Trans table. */
1535 register int oc; /* Old character. */
1536 register int nc; /* New character. */
1537 int cnt; /* Number of changes made. */
1538 Lisp_Object z; /* Return. */
1539 int size; /* Size of translate table. */
1540
1541 validate_region (&start, &end);
1542 CHECK_STRING (table, 2);
1543
1544 size = XSTRING (table)->size;
1545 tt = XSTRING (table)->data;
1546
1547 pos = XINT (start);
1548 stop = XINT (end);
04a759c8 1549 modify_region (current_buffer, pos, stop);
35692fe0
JB
1550
1551 cnt = 0;
1552 for (; pos < stop; ++pos)
1553 {
1554 oc = FETCH_CHAR (pos);
1555 if (oc < size)
1556 {
1557 nc = tt[oc];
1558 if (nc != oc)
1559 {
1560 record_change (pos, 1);
1561 FETCH_CHAR (pos) = nc;
1562 signal_after_change (pos, 1, 1);
1563 ++cnt;
1564 }
1565 }
1566 }
1567
55561c63 1568 XSETFASTINT (z, cnt);
35692fe0
JB
1569 return (z);
1570}
1571
1572DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r",
1573 "Delete the text between point and mark.\n\
1574When called from a program, expects two arguments,\n\
1575positions (integers or markers) specifying the stretch to be deleted.")
1576 (b, e)
1577 Lisp_Object b, e;
1578{
1579 validate_region (&b, &e);
1580 del_range (XINT (b), XINT (e));
1581 return Qnil;
1582}
1583\f
1584DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
1585 "Remove restrictions (narrowing) from current buffer.\n\
1586This allows the buffer's full text to be seen and edited.")
1587 ()
1588{
1589 BEGV = BEG;
1590 SET_BUF_ZV (current_buffer, Z);
18744e17 1591 current_buffer->clip_changed = 1;
52b14ac0
JB
1592 /* Changing the buffer bounds invalidates any recorded current column. */
1593 invalidate_current_column ();
35692fe0
JB
1594 return Qnil;
1595}
1596
1597DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",
1598 "Restrict editing in this buffer to the current region.\n\
1599The rest of the text becomes temporarily invisible and untouchable\n\
1600but is not deleted; if you save the buffer in a file, the invisible\n\
1601text is included in the file. \\[widen] makes all visible again.\n\
1602See also `save-restriction'.\n\
1603\n\
1604When calling from a program, pass two arguments; positions (integers\n\
1605or markers) bounding the text that should remain visible.")
1606 (b, e)
1607 register Lisp_Object b, e;
1608{
35692fe0
JB
1609 CHECK_NUMBER_COERCE_MARKER (b, 0);
1610 CHECK_NUMBER_COERCE_MARKER (e, 1);
1611
1612 if (XINT (b) > XINT (e))
1613 {
b5a6948e
KH
1614 Lisp_Object tem;
1615 tem = b; b = e; e = tem;
35692fe0
JB
1616 }
1617
1618 if (!(BEG <= XINT (b) && XINT (b) <= XINT (e) && XINT (e) <= Z))
1619 args_out_of_range (b, e);
1620
1621 BEGV = XFASTINT (b);
1622 SET_BUF_ZV (current_buffer, XFASTINT (e));
1623 if (point < XFASTINT (b))
1624 SET_PT (XFASTINT (b));
1625 if (point > XFASTINT (e))
1626 SET_PT (XFASTINT (e));
18744e17 1627 current_buffer->clip_changed = 1;
52b14ac0
JB
1628 /* Changing the buffer bounds invalidates any recorded current column. */
1629 invalidate_current_column ();
35692fe0
JB
1630 return Qnil;
1631}
1632
1633Lisp_Object
1634save_restriction_save ()
1635{
1636 register Lisp_Object bottom, top;
1637 /* Note: I tried using markers here, but it does not win
1638 because insertion at the end of the saved region
1639 does not advance mh and is considered "outside" the saved region. */
55561c63
KH
1640 XSETFASTINT (bottom, BEGV - BEG);
1641 XSETFASTINT (top, Z - ZV);
35692fe0
JB
1642
1643 return Fcons (Fcurrent_buffer (), Fcons (bottom, top));
1644}
1645
1646Lisp_Object
1647save_restriction_restore (data)
1648 Lisp_Object data;
1649{
1650 register struct buffer *buf;
1651 register int newhead, newtail;
1652 register Lisp_Object tem;
1653
1654 buf = XBUFFER (XCONS (data)->car);
1655
1656 data = XCONS (data)->cdr;
1657
1658 tem = XCONS (data)->car;
1659 newhead = XINT (tem);
1660 tem = XCONS (data)->cdr;
1661 newtail = XINT (tem);
1662 if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf))
1663 {
1664 newhead = 0;
1665 newtail = 0;
1666 }
1667 BUF_BEGV (buf) = BUF_BEG (buf) + newhead;
1668 SET_BUF_ZV (buf, BUF_Z (buf) - newtail);
18744e17 1669 current_buffer->clip_changed = 1;
35692fe0
JB
1670
1671 /* If point is outside the new visible range, move it inside. */
1672 SET_BUF_PT (buf,
1673 clip_to_bounds (BUF_BEGV (buf), BUF_PT (buf), BUF_ZV (buf)));
1674
1675 return Qnil;
1676}
1677
1678DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0,
1679 "Execute BODY, saving and restoring current buffer's restrictions.\n\
1680The buffer's restrictions make parts of the beginning and end invisible.\n\
1681\(They are set up with `narrow-to-region' and eliminated with `widen'.)\n\
1682This special form, `save-restriction', saves the current buffer's restrictions\n\
1683when it is entered, and restores them when it is exited.\n\
1684So any `narrow-to-region' within BODY lasts only until the end of the form.\n\
1685The old restrictions settings are restored\n\
1686even in case of abnormal exit (throw or error).\n\
1687\n\
1688The value returned is the value of the last form in BODY.\n\
1689\n\
1690`save-restriction' can get confused if, within the BODY, you widen\n\
1691and then make changes outside the area within the saved restrictions.\n\
1692\n\
1693Note: if you are using both `save-excursion' and `save-restriction',\n\
1694use `save-excursion' outermost:\n\
1695 (save-excursion (save-restriction ...))")
1696 (body)
1697 Lisp_Object body;
1698{
1699 register Lisp_Object val;
1700 int count = specpdl_ptr - specpdl;
1701
1702 record_unwind_protect (save_restriction_restore, save_restriction_save ());
1703 val = Fprogn (body);
1704 return unbind_to (count, val);
1705}
1706\f
671fbc4d
KH
1707/* Buffer for the most recent text displayed by Fmessage. */
1708static char *message_text;
1709
1710/* Allocated length of that buffer. */
1711static int message_length;
1712
35692fe0
JB
1713DEFUN ("message", Fmessage, Smessage, 1, MANY, 0,
1714 "Print a one-line message at the bottom of the screen.\n\
98fc5c3c
RS
1715The first argument is a format control string, and the rest are data\n\
1716to be formatted under control of the string. See `format' for details.\n\
1717\n\
ccdac5be
JB
1718If the first argument is nil, clear any existing message; let the\n\
1719minibuffer contents show.")
35692fe0
JB
1720 (nargs, args)
1721 int nargs;
1722 Lisp_Object *args;
1723{
ccdac5be 1724 if (NILP (args[0]))
f0250249
JB
1725 {
1726 message (0);
1727 return Qnil;
1728 }
ccdac5be
JB
1729 else
1730 {
1731 register Lisp_Object val;
1732 val = Fformat (nargs, args);
671fbc4d
KH
1733 /* Copy the data so that it won't move when we GC. */
1734 if (! message_text)
1735 {
1736 message_text = (char *)xmalloc (80);
1737 message_length = 80;
1738 }
1739 if (XSTRING (val)->size > message_length)
1740 {
1741 message_length = XSTRING (val)->size;
1742 message_text = (char *)xrealloc (message_text, message_length);
1743 }
1744 bcopy (XSTRING (val)->data, message_text, XSTRING (val)->size);
1745 message2 (message_text, XSTRING (val)->size);
ccdac5be
JB
1746 return val;
1747 }
35692fe0
JB
1748}
1749
cacc3e2c
RS
1750DEFUN ("message-box", Fmessage_box, Smessage_box, 1, MANY, 0,
1751 "Display a message, in a dialog box if possible.\n\
1752If a dialog box is not available, use the echo area.\n\
1753The first argument is a control string.\n\
1754It may contain %s or %d or %c to print successive following arguments.\n\
1755%s means print an argument as a string, %d means print as number in decimal,\n\
1756%c means print a number as a single character.\n\
1757The argument used by %s must be a string or a symbol;\n\
1758the argument used by %d or %c must be a number.\n\
1759If the first argument is nil, clear any existing message; let the\n\
1760minibuffer contents show.")
1761 (nargs, args)
1762 int nargs;
1763 Lisp_Object *args;
1764{
1765 if (NILP (args[0]))
1766 {
1767 message (0);
1768 return Qnil;
1769 }
1770 else
1771 {
1772 register Lisp_Object val;
1773 val = Fformat (nargs, args);
1774#ifdef HAVE_X_MENU
1775 {
1776 Lisp_Object pane, menu, obj;
1777 struct gcpro gcpro1;
1778 pane = Fcons (Fcons (build_string ("OK"), Qt), Qnil);
1779 GCPRO1 (pane);
1780 menu = Fcons (val, pane);
1781 obj = Fx_popup_dialog (Qt, menu);
1782 UNGCPRO;
1783 return val;
1784 }
1785#else
1786 /* Copy the data so that it won't move when we GC. */
1787 if (! message_text)
1788 {
1789 message_text = (char *)xmalloc (80);
1790 message_length = 80;
1791 }
1792 if (XSTRING (val)->size > message_length)
1793 {
1794 message_length = XSTRING (val)->size;
1795 message_text = (char *)xrealloc (message_text, message_length);
1796 }
1797 bcopy (XSTRING (val)->data, message_text, XSTRING (val)->size);
1798 message2 (message_text, XSTRING (val)->size);
1799 return val;
1800#endif
1801 }
1802}
1803#ifdef HAVE_X_MENU
1804extern Lisp_Object last_nonmenu_event;
1805#endif
1806DEFUN ("message-or-box", Fmessage_or_box, Smessage_or_box, 1, MANY, 0,
1807 "Display a message in a dialog box or in the echo area.\n\
1808If this command was invoked with the mouse, use a dialog box.\n\
1809Otherwise, use the echo area.\n\
1810\n\
1811The first argument is a control string.\n\
1812It may contain %s or %d or %c to print successive following arguments.\n\
1813%s means print an argument as a string, %d means print as number in decimal,\n\
1814%c means print a number as a single character.\n\
1815The argument used by %s must be a string or a symbol;\n\
1816the argument used by %d or %c must be a number.\n\
1817If the first argument is nil, clear any existing message; let the\n\
1818minibuffer contents show.")
1819 (nargs, args)
1820 int nargs;
1821 Lisp_Object *args;
1822{
1823#ifdef HAVE_X_MENU
1824 if (NILP (last_nonmenu_event) || CONSP (last_nonmenu_event))
0a56ee6b 1825 return Fmessage_box (nargs, args);
cacc3e2c
RS
1826#endif
1827 return Fmessage (nargs, args);
1828}
1829
35692fe0
JB
1830DEFUN ("format", Fformat, Sformat, 1, MANY, 0,
1831 "Format a string out of a control-string and arguments.\n\
1832The first argument is a control string.\n\
1833The other arguments are substituted into it to make the result, a string.\n\
1834It may contain %-sequences meaning to substitute the next argument.\n\
1835%s means print a string argument. Actually, prints any object, with `princ'.\n\
1836%d means print as number in decimal (%o octal, %x hex).\n\
9db1775a
RS
1837%e means print a number in exponential notation.\n\
1838%f means print a number in decimal-point notation.\n\
1839%g means print a number in exponential notation\n\
1840 or decimal-point notation, whichever uses fewer characters.\n\
35692fe0
JB
1841%c means print a number as a single character.\n\
1842%S means print any object as an s-expression (using prin1).\n\
9db1775a 1843 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.\n\
52b14ac0 1844Use %% to put a single % into the output.")
35692fe0
JB
1845 (nargs, args)
1846 int nargs;
1847 register Lisp_Object *args;
1848{
1849 register int n; /* The number of the next arg to substitute */
1850 register int total = 5; /* An estimate of the final length */
1851 char *buf;
1852 register unsigned char *format, *end;
1853 int length;
1854 extern char *index ();
1855 /* It should not be necessary to GCPRO ARGS, because
1856 the caller in the interpreter should take care of that. */
1857
1858 CHECK_STRING (args[0], 0);
1859 format = XSTRING (args[0])->data;
1860 end = format + XSTRING (args[0])->size;
1861
1862 n = 0;
1863 while (format != end)
1864 if (*format++ == '%')
1865 {
1866 int minlen;
1867
1868 /* Process a numeric arg and skip it. */
1869 minlen = atoi (format);
537dfb13
RS
1870 if (minlen < 0)
1871 minlen = - minlen;
1872
35692fe0
JB
1873 while ((*format >= '0' && *format <= '9')
1874 || *format == '-' || *format == ' ' || *format == '.')
1875 format++;
1876
1877 if (*format == '%')
1878 format++;
1879 else if (++n >= nargs)
537dfb13 1880 error ("Not enough arguments for format string");
35692fe0
JB
1881 else if (*format == 'S')
1882 {
1883 /* For `S', prin1 the argument and then treat like a string. */
1884 register Lisp_Object tem;
1885 tem = Fprin1_to_string (args[n], Qnil);
1886 args[n] = tem;
1887 goto string;
1888 }
ae683129 1889 else if (SYMBOLP (args[n]))
35692fe0 1890 {
d2fd0445 1891 XSETSTRING (args[n], XSYMBOL (args[n])->name);
35692fe0
JB
1892 goto string;
1893 }
ae683129 1894 else if (STRINGP (args[n]))
35692fe0
JB
1895 {
1896 string:
b22e7ecc
KH
1897 if (*format != 's' && *format != 'S')
1898 error ("format specifier doesn't match argument type");
35692fe0 1899 total += XSTRING (args[n])->size;
537dfb13
RS
1900 /* We have to put an arbitrary limit on minlen
1901 since otherwise it could make alloca fail. */
1902 if (minlen < XSTRING (args[n])->size + 1000)
1903 total += minlen;
35692fe0
JB
1904 }
1905 /* Would get MPV otherwise, since Lisp_Int's `point' to low memory. */
ae683129 1906 else if (INTEGERP (args[n]) && *format != 's')
35692fe0 1907 {
4746118a 1908#ifdef LISP_FLOAT_TYPE
eb8c3be9 1909 /* The following loop assumes the Lisp type indicates
35692fe0
JB
1910 the proper way to pass the argument.
1911 So make sure we have a flonum if the argument should
1912 be a double. */
1913 if (*format == 'e' || *format == 'f' || *format == 'g')
1914 args[n] = Ffloat (args[n]);
4746118a 1915#endif
d65666d5 1916 total += 30;
537dfb13
RS
1917 /* We have to put an arbitrary limit on minlen
1918 since otherwise it could make alloca fail. */
1919 if (minlen < 1000)
1920 total += minlen;
35692fe0 1921 }
4746118a 1922#ifdef LISP_FLOAT_TYPE
ae683129 1923 else if (FLOATP (args[n]) && *format != 's')
35692fe0
JB
1924 {
1925 if (! (*format == 'e' || *format == 'f' || *format == 'g'))
1926 args[n] = Ftruncate (args[n]);
d65666d5 1927 total += 30;
537dfb13
RS
1928 /* We have to put an arbitrary limit on minlen
1929 since otherwise it could make alloca fail. */
1930 if (minlen < 1000)
1931 total += minlen;
35692fe0 1932 }
4746118a 1933#endif
35692fe0
JB
1934 else
1935 {
1936 /* Anything but a string, convert to a string using princ. */
1937 register Lisp_Object tem;
1938 tem = Fprin1_to_string (args[n], Qt);
1939 args[n] = tem;
1940 goto string;
1941 }
1942 }
1943
1944 {
1945 register int nstrings = n + 1;
50aa2f90
JB
1946
1947 /* Allocate twice as many strings as we have %-escapes; floats occupy
1948 two slots, and we're not sure how many of those we have. */
35692fe0 1949 register unsigned char **strings
50aa2f90
JB
1950 = (unsigned char **) alloca (2 * nstrings * sizeof (unsigned char *));
1951 int i;
35692fe0 1952
50aa2f90 1953 i = 0;
35692fe0
JB
1954 for (n = 0; n < nstrings; n++)
1955 {
1956 if (n >= nargs)
50aa2f90 1957 strings[i++] = (unsigned char *) "";
ae683129 1958 else if (INTEGERP (args[n]))
35692fe0
JB
1959 /* We checked above that the corresponding format effector
1960 isn't %s, which would cause MPV. */
50aa2f90 1961 strings[i++] = (unsigned char *) XINT (args[n]);
4746118a 1962#ifdef LISP_FLOAT_TYPE
ae683129 1963 else if (FLOATP (args[n]))
35692fe0 1964 {
86246708 1965 union { double d; char *half[2]; } u;
35692fe0
JB
1966
1967 u.d = XFLOAT (args[n])->data;
86246708
KH
1968 strings[i++] = (unsigned char *) u.half[0];
1969 strings[i++] = (unsigned char *) u.half[1];
35692fe0 1970 }
4746118a 1971#endif
102cfe92
RS
1972 else if (i == 0)
1973 /* The first string is treated differently
1974 because it is the format string. */
50aa2f90 1975 strings[i++] = XSTRING (args[n])->data;
102cfe92
RS
1976 else
1977 strings[i++] = (unsigned char *) XFASTINT (args[n]);
35692fe0
JB
1978 }
1979
fb893977
RS
1980 /* Make room in result for all the non-%-codes in the control string. */
1981 total += XSTRING (args[0])->size;
1982
35692fe0
JB
1983 /* Format it in bigger and bigger buf's until it all fits. */
1984 while (1)
1985 {
1986 buf = (char *) alloca (total + 1);
1987 buf[total - 1] = 0;
1988
102cfe92
RS
1989 length = doprnt_lisp (buf, total + 1, strings[0],
1990 end, i-1, strings + 1);
35692fe0
JB
1991 if (buf[total - 1] == 0)
1992 break;
1993
1994 total *= 2;
1995 }
1996 }
1997
1998 /* UNGCPRO; */
1999 return make_string (buf, length);
2000}
2001
2002/* VARARGS 1 */
2003Lisp_Object
2004#ifdef NO_ARG_ARRAY
2005format1 (string1, arg0, arg1, arg2, arg3, arg4)
679e18b1 2006 EMACS_INT arg0, arg1, arg2, arg3, arg4;
35692fe0
JB
2007#else
2008format1 (string1)
2009#endif
2010 char *string1;
2011{
2012 char buf[100];
2013#ifdef NO_ARG_ARRAY
679e18b1 2014 EMACS_INT args[5];
35692fe0
JB
2015 args[0] = arg0;
2016 args[1] = arg1;
2017 args[2] = arg2;
2018 args[3] = arg3;
2019 args[4] = arg4;
ea4d2909 2020 doprnt (buf, sizeof buf, string1, (char *)0, 5, args);
35692fe0 2021#else
ea4d2909 2022 doprnt (buf, sizeof buf, string1, (char *)0, 5, &string1 + 1);
35692fe0
JB
2023#endif
2024 return build_string (buf);
2025}
2026\f
2027DEFUN ("char-equal", Fchar_equal, Schar_equal, 2, 2, 0,
2028 "Return t if two characters match, optionally ignoring case.\n\
2029Both arguments must be characters (i.e. integers).\n\
2030Case is ignored if `case-fold-search' is non-nil in the current buffer.")
2031 (c1, c2)
2032 register Lisp_Object c1, c2;
2033{
be46733f 2034 Lisp_Object *downcase = DOWNCASE_TABLE;
35692fe0
JB
2035 CHECK_NUMBER (c1, 0);
2036 CHECK_NUMBER (c2, 1);
2037
56a98455 2038 if (!NILP (current_buffer->case_fold_search)
be46733f
RS
2039 ? ((XINT (downcase[0xff & XFASTINT (c1)])
2040 == XINT (downcase[0xff & XFASTINT (c2)]))
c34beca9 2041 && (XFASTINT (c1) & ~0xff) == (XFASTINT (c2) & ~0xff))
35692fe0
JB
2042 : XINT (c1) == XINT (c2))
2043 return Qt;
2044 return Qnil;
2045}
b229b8d1
RS
2046\f
2047/* Transpose the markers in two regions of the current buffer, and
2048 adjust the ones between them if necessary (i.e.: if the regions
2049 differ in size).
2050
2051 Traverses the entire marker list of the buffer to do so, adding an
2052 appropriate amount to some, subtracting from some, and leaving the
2053 rest untouched. Most of this is copied from adjust_markers in insdel.c.
2054
03240d11 2055 It's the caller's job to see that (start1 <= end1 <= start2 <= end2). */
b229b8d1
RS
2056
2057void
2058transpose_markers (start1, end1, start2, end2)
2059 register int start1, end1, start2, end2;
2060{
2061 register int amt1, amt2, diff, mpos;
2062 register Lisp_Object marker;
b229b8d1 2063
03240d11 2064 /* Update point as if it were a marker. */
8de1d5f0
KH
2065 if (PT < start1)
2066 ;
2067 else if (PT < end1)
2068 TEMP_SET_PT (PT + (end2 - end1));
2069 else if (PT < start2)
2070 TEMP_SET_PT (PT + (end2 - start2) - (end1 - start1));
2071 else if (PT < end2)
2072 TEMP_SET_PT (PT - (start2 - start1));
2073
03240d11
KH
2074 /* We used to adjust the endpoints here to account for the gap, but that
2075 isn't good enough. Even if we assume the caller has tried to move the
2076 gap out of our way, it might still be at start1 exactly, for example;
2077 and that places it `inside' the interval, for our purposes. The amount
2078 of adjustment is nontrivial if there's a `denormalized' marker whose
2079 position is between GPT and GPT + GAP_SIZE, so it's simpler to leave
2080 the dirty work to Fmarker_position, below. */
b229b8d1
RS
2081
2082 /* The difference between the region's lengths */
2083 diff = (end2 - start2) - (end1 - start1);
2084
2085 /* For shifting each marker in a region by the length of the other
2086 * region plus the distance between the regions.
2087 */
2088 amt1 = (end2 - start2) + (start2 - end1);
2089 amt2 = (end1 - start1) + (start2 - end1);
2090
1e158d25 2091 for (marker = BUF_MARKERS (current_buffer); !NILP (marker);
03240d11 2092 marker = XMARKER (marker)->chain)
b229b8d1 2093 {
03240d11
KH
2094 mpos = Fmarker_position (marker);
2095 if (mpos >= start1 && mpos < end2)
2096 {
2097 if (mpos < end1)
2098 mpos += amt1;
2099 else if (mpos < start2)
2100 mpos += diff;
2101 else
2102 mpos -= amt2;
2103 if (mpos > GPT) mpos += GAP_SIZE;
2104 XMARKER (marker)->bufpos = mpos;
2105 }
b229b8d1
RS
2106 }
2107}
2108
2109DEFUN ("transpose-regions", Ftranspose_regions, Stranspose_regions, 4, 5, 0,
2110 "Transpose region START1 to END1 with START2 to END2.\n\
2111The regions may not be overlapping, because the size of the buffer is\n\
2112never changed in a transposition.\n\
2113\n\
2114Optional fifth arg LEAVE_MARKERS, if non-nil, means don't transpose\n\
2115any markers that happen to be located in the regions.\n\
2116\n\
2117Transposing beyond buffer boundaries is an error.")
2118 (startr1, endr1, startr2, endr2, leave_markers)
2119 Lisp_Object startr1, endr1, startr2, endr2, leave_markers;
2120{
2121 register int start1, end1, start2, end2,
2122 gap, len1, len_mid, len2;
3c6bc7d0 2123 unsigned char *start1_addr, *start2_addr, *temp;
b229b8d1
RS
2124
2125#ifdef USE_TEXT_PROPERTIES
2126 INTERVAL cur_intv, tmp_interval1, tmp_interval_mid, tmp_interval2;
1e158d25 2127 cur_intv = BUF_INTERVALS (current_buffer);
b229b8d1
RS
2128#endif /* USE_TEXT_PROPERTIES */
2129
2130 validate_region (&startr1, &endr1);
2131 validate_region (&startr2, &endr2);
2132
2133 start1 = XFASTINT (startr1);
2134 end1 = XFASTINT (endr1);
2135 start2 = XFASTINT (startr2);
2136 end2 = XFASTINT (endr2);
2137 gap = GPT;
2138
2139 /* Swap the regions if they're reversed. */
2140 if (start2 < end1)
2141 {
2142 register int glumph = start1;
2143 start1 = start2;
2144 start2 = glumph;
2145 glumph = end1;
2146 end1 = end2;
2147 end2 = glumph;
2148 }
2149
b229b8d1
RS
2150 len1 = end1 - start1;
2151 len2 = end2 - start2;
2152
2153 if (start2 < end1)
2154 error ("transposed regions not properly ordered");
2155 else if (start1 == end1 || start2 == end2)
2156 error ("transposed region may not be of length 0");
2157
2158 /* The possibilities are:
2159 1. Adjacent (contiguous) regions, or separate but equal regions
2160 (no, really equal, in this case!), or
2161 2. Separate regions of unequal size.
2162
2163 The worst case is usually No. 2. It means that (aside from
2164 potential need for getting the gap out of the way), there also
2165 needs to be a shifting of the text between the two regions. So
2166 if they are spread far apart, we are that much slower... sigh. */
2167
2168 /* It must be pointed out that the really studly thing to do would
2169 be not to move the gap at all, but to leave it in place and work
2170 around it if necessary. This would be extremely efficient,
2171 especially considering that people are likely to do
2172 transpositions near where they are working interactively, which
2173 is exactly where the gap would be found. However, such code
2174 would be much harder to write and to read. So, if you are
2175 reading this comment and are feeling squirrely, by all means have
2176 a go! I just didn't feel like doing it, so I will simply move
2177 the gap the minimum distance to get it out of the way, and then
2178 deal with an unbroken array. */
3c6bc7d0
RS
2179
2180 /* Make sure the gap won't interfere, by moving it out of the text
2181 we will operate on. */
2182 if (start1 < gap && gap < end2)
2183 {
2184 if (gap - start1 < end2 - gap)
2185 move_gap (start1);
2186 else
2187 move_gap (end2);
2188 }
b229b8d1
RS
2189
2190 /* Hmmm... how about checking to see if the gap is large
2191 enough to use as the temporary storage? That would avoid an
2192 allocation... interesting. Later, don't fool with it now. */
2193
2194 /* Working without memmove, for portability (sigh), so must be
2195 careful of overlapping subsections of the array... */
2196
2197 if (end1 == start2) /* adjacent regions */
2198 {
b229b8d1
RS
2199 modify_region (current_buffer, start1, end2);
2200 record_change (start1, len1 + len2);
2201
2202#ifdef USE_TEXT_PROPERTIES
2203 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
2204 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
2205 Fset_text_properties (start1, end2, Qnil, Qnil);
2206#endif /* USE_TEXT_PROPERTIES */
2207
2208 /* First region smaller than second. */
2209 if (len1 < len2)
2210 {
3c6bc7d0
RS
2211 /* We use alloca only if it is small,
2212 because we want to avoid stack overflow. */
2213 if (len2 > 20000)
2214 temp = (unsigned char *) xmalloc (len2);
2215 else
2216 temp = (unsigned char *) alloca (len2);
03240d11
KH
2217
2218 /* Don't precompute these addresses. We have to compute them
2219 at the last minute, because the relocating allocator might
2220 have moved the buffer around during the xmalloc. */
2221 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1);
2222 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2);
2223
b229b8d1
RS
2224 bcopy (start2_addr, temp, len2);
2225 bcopy (start1_addr, start1_addr + len2, len1);
2226 bcopy (temp, start1_addr, len2);
3c6bc7d0
RS
2227 if (len2 > 20000)
2228 free (temp);
b229b8d1
RS
2229 }
2230 else
2231 /* First region not smaller than second. */
2232 {
3c6bc7d0
RS
2233 if (len1 > 20000)
2234 temp = (unsigned char *) xmalloc (len1);
2235 else
2236 temp = (unsigned char *) alloca (len1);
03240d11
KH
2237 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1);
2238 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2);
b229b8d1
RS
2239 bcopy (start1_addr, temp, len1);
2240 bcopy (start2_addr, start1_addr, len2);
2241 bcopy (temp, start1_addr + len2, len1);
3c6bc7d0
RS
2242 if (len1 > 20000)
2243 free (temp);
b229b8d1
RS
2244 }
2245#ifdef USE_TEXT_PROPERTIES
2246 graft_intervals_into_buffer (tmp_interval1, start1 + len2,
2247 len1, current_buffer, 0);
2248 graft_intervals_into_buffer (tmp_interval2, start1,
2249 len2, current_buffer, 0);
2250#endif /* USE_TEXT_PROPERTIES */
2251 }
2252 /* Non-adjacent regions, because end1 != start2, bleagh... */
2253 else
2254 {
b229b8d1
RS
2255 if (len1 == len2)
2256 /* Regions are same size, though, how nice. */
2257 {
2258 modify_region (current_buffer, start1, end1);
2259 modify_region (current_buffer, start2, end2);
2260 record_change (start1, len1);
2261 record_change (start2, len2);
2262#ifdef USE_TEXT_PROPERTIES
2263 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
2264 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
2265 Fset_text_properties (start1, end1, Qnil, Qnil);
2266 Fset_text_properties (start2, end2, Qnil, Qnil);
2267#endif /* USE_TEXT_PROPERTIES */
2268
3c6bc7d0
RS
2269 if (len1 > 20000)
2270 temp = (unsigned char *) xmalloc (len1);
2271 else
2272 temp = (unsigned char *) alloca (len1);
03240d11
KH
2273 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1);
2274 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2);
b229b8d1
RS
2275 bcopy (start1_addr, temp, len1);
2276 bcopy (start2_addr, start1_addr, len2);
2277 bcopy (temp, start2_addr, len1);
3c6bc7d0
RS
2278 if (len1 > 20000)
2279 free (temp);
b229b8d1
RS
2280#ifdef USE_TEXT_PROPERTIES
2281 graft_intervals_into_buffer (tmp_interval1, start2,
2282 len1, current_buffer, 0);
2283 graft_intervals_into_buffer (tmp_interval2, start1,
2284 len2, current_buffer, 0);
2285#endif /* USE_TEXT_PROPERTIES */
2286 }
2287
2288 else if (len1 < len2) /* Second region larger than first */
2289 /* Non-adjacent & unequal size, area between must also be shifted. */
2290 {
2291 len_mid = start2 - end1;
2292 modify_region (current_buffer, start1, end2);
2293 record_change (start1, (end2 - start1));
2294#ifdef USE_TEXT_PROPERTIES
2295 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
2296 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
2297 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
2298 Fset_text_properties (start1, end2, Qnil, Qnil);
2299#endif /* USE_TEXT_PROPERTIES */
2300
3c6bc7d0
RS
2301 /* holds region 2 */
2302 if (len2 > 20000)
2303 temp = (unsigned char *) xmalloc (len2);
2304 else
2305 temp = (unsigned char *) alloca (len2);
03240d11
KH
2306 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1);
2307 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2);
3c6bc7d0 2308 bcopy (start2_addr, temp, len2);
b229b8d1 2309 bcopy (start1_addr, start1_addr + len_mid + len2, len1);
3c6bc7d0
RS
2310 safe_bcopy (start1_addr + len1, start1_addr + len2, len_mid);
2311 bcopy (temp, start1_addr, len2);
2312 if (len2 > 20000)
2313 free (temp);
b229b8d1
RS
2314#ifdef USE_TEXT_PROPERTIES
2315 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
2316 len1, current_buffer, 0);
2317 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
2318 len_mid, current_buffer, 0);
2319 graft_intervals_into_buffer (tmp_interval2, start1,
2320 len2, current_buffer, 0);
2321#endif /* USE_TEXT_PROPERTIES */
2322 }
2323 else
2324 /* Second region smaller than first. */
2325 {
2326 len_mid = start2 - end1;
2327 record_change (start1, (end2 - start1));
2328 modify_region (current_buffer, start1, end2);
2329
2330#ifdef USE_TEXT_PROPERTIES
2331 tmp_interval1 = copy_intervals (cur_intv, start1, len1);
2332 tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid);
2333 tmp_interval2 = copy_intervals (cur_intv, start2, len2);
2334 Fset_text_properties (start1, end2, Qnil, Qnil);
2335#endif /* USE_TEXT_PROPERTIES */
2336
3c6bc7d0
RS
2337 /* holds region 1 */
2338 if (len1 > 20000)
2339 temp = (unsigned char *) xmalloc (len1);
2340 else
2341 temp = (unsigned char *) alloca (len1);
03240d11
KH
2342 start1_addr = BUF_CHAR_ADDRESS (current_buffer, start1);
2343 start2_addr = BUF_CHAR_ADDRESS (current_buffer, start2);
3c6bc7d0 2344 bcopy (start1_addr, temp, len1);
b229b8d1 2345 bcopy (start2_addr, start1_addr, len2);
3c6bc7d0
RS
2346 bcopy (start1_addr + len1, start1_addr + len2, len_mid);
2347 bcopy (temp, start1_addr + len2 + len_mid, len1);
2348 if (len1 > 20000)
2349 free (temp);
b229b8d1
RS
2350#ifdef USE_TEXT_PROPERTIES
2351 graft_intervals_into_buffer (tmp_interval1, end2 - len1,
2352 len1, current_buffer, 0);
2353 graft_intervals_into_buffer (tmp_interval_mid, start1 + len2,
2354 len_mid, current_buffer, 0);
2355 graft_intervals_into_buffer (tmp_interval2, start1,
2356 len2, current_buffer, 0);
2357#endif /* USE_TEXT_PROPERTIES */
2358 }
2359 }
2360
2361 /* todo: this will be slow, because for every transposition, we
2362 traverse the whole friggin marker list. Possible solutions:
2363 somehow get a list of *all* the markers across multiple
2364 transpositions and do it all in one swell phoop. Or maybe modify
2365 Emacs' marker code to keep an ordered list or tree. This might
2366 be nicer, and more beneficial in the long run, but would be a
2367 bunch of work. Plus the way they're arranged now is nice. */
2368 if (NILP (leave_markers))
8de1d5f0
KH
2369 {
2370 transpose_markers (start1, end1, start2, end2);
2371 fix_overlays_in_range (start1, end2);
2372 }
b229b8d1
RS
2373
2374 return Qnil;
2375}
35692fe0 2376
35692fe0
JB
2377\f
2378void
2379syms_of_editfns ()
2380{
260e2e2a
KH
2381 environbuf = 0;
2382
2383 Qbuffer_access_fontify_functions
2384 = intern ("buffer-access-fontify-functions");
2385 staticpro (&Qbuffer_access_fontify_functions);
2386
2387 DEFVAR_LISP ("buffer-access-fontify-functions",
2388 &Vbuffer_access_fontify_functions,
2389 "List of functions called by `buffer-substring' to fontify if necessary.\n\
2390Each function is called with two arguments which specify the range\n\
2391of the buffer being accessed.");
2392 Vbuffer_access_fontify_functions = Qnil;
2393
2394 DEFVAR_LISP ("buffer_access_fontified_property",
2395 &Vbuffer_access_fontified_property,
2396 "Property which (if non-nil) indicates text has been fontified.\n\
2397`buffer-substring' need not call the `buffer-access-fontify-functions'\n\
2398functions if all the text being accessed has this property.");
2399 Vbuffer_access_fontified_property = Qnil;
2400
f43754f6
KH
2401 DEFVAR_LISP ("system-name", &Vsystem_name,
2402 "The name of the machine Emacs is running on.");
2403
2404 DEFVAR_LISP ("user-full-name", &Vuser_full_name,
2405 "The full name of the user logged in.");
2406
35b34f72 2407 DEFVAR_LISP ("user-login-name", &Vuser_login_name,
f43754f6
KH
2408 "The user's name, taken from environment variables if possible.");
2409
35b34f72 2410 DEFVAR_LISP ("user-real-login-name", &Vuser_real_login_name,
f43754f6 2411 "The user's name, based upon the real uid only.");
35692fe0
JB
2412
2413 defsubr (&Schar_equal);
2414 defsubr (&Sgoto_char);
2415 defsubr (&Sstring_to_char);
2416 defsubr (&Schar_to_string);
2417 defsubr (&Sbuffer_substring);
260e2e2a 2418 defsubr (&Sbuffer_substring_no_properties);
35692fe0
JB
2419 defsubr (&Sbuffer_string);
2420
2421 defsubr (&Spoint_marker);
2422 defsubr (&Smark_marker);
2423 defsubr (&Spoint);
2424 defsubr (&Sregion_beginning);
2425 defsubr (&Sregion_end);
2426/* defsubr (&Smark); */
2427/* defsubr (&Sset_mark); */
2428 defsubr (&Ssave_excursion);
2429
2430 defsubr (&Sbufsize);
2431 defsubr (&Spoint_max);
2432 defsubr (&Spoint_min);
2433 defsubr (&Spoint_min_marker);
2434 defsubr (&Spoint_max_marker);
2435
2436 defsubr (&Sbobp);
2437 defsubr (&Seobp);
2438 defsubr (&Sbolp);
2439 defsubr (&Seolp);
850a8179
JB
2440 defsubr (&Sfollowing_char);
2441 defsubr (&Sprevious_char);
35692fe0
JB
2442 defsubr (&Schar_after);
2443 defsubr (&Sinsert);
2444 defsubr (&Sinsert_before_markers);
be91036a
RS
2445 defsubr (&Sinsert_and_inherit);
2446 defsubr (&Sinsert_and_inherit_before_markers);
35692fe0
JB
2447 defsubr (&Sinsert_char);
2448
2449 defsubr (&Suser_login_name);
2450 defsubr (&Suser_real_login_name);
2451 defsubr (&Suser_uid);
2452 defsubr (&Suser_real_uid);
2453 defsubr (&Suser_full_name);
7fd233b3 2454 defsubr (&Semacs_pid);
d940e0e4 2455 defsubr (&Scurrent_time);
a82d387c 2456 defsubr (&Sformat_time_string);
4691c06d 2457 defsubr (&Sdecode_time);
cce7b8a0 2458 defsubr (&Sencode_time);
35692fe0 2459 defsubr (&Scurrent_time_string);
c2662aea 2460 defsubr (&Scurrent_time_zone);
143cb9a9 2461 defsubr (&Sset_time_zone_rule);
35692fe0 2462 defsubr (&Ssystem_name);
35692fe0 2463 defsubr (&Smessage);
cacc3e2c
RS
2464 defsubr (&Smessage_box);
2465 defsubr (&Smessage_or_box);
35692fe0 2466 defsubr (&Sformat);
35692fe0
JB
2467
2468 defsubr (&Sinsert_buffer_substring);
e9cf2084 2469 defsubr (&Scompare_buffer_substrings);
35692fe0
JB
2470 defsubr (&Ssubst_char_in_region);
2471 defsubr (&Stranslate_region);
2472 defsubr (&Sdelete_region);
2473 defsubr (&Swiden);
2474 defsubr (&Snarrow_to_region);
2475 defsubr (&Ssave_restriction);
b229b8d1 2476 defsubr (&Stranspose_regions);
35692fe0 2477}