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