1 /* Lisp functions pertaining to editing.
2 Copyright (C) 1985,86,87,89,93,94,95,96,97,98 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <sys/types.h>
41 #include "intervals.h"
48 #define min(a, b) ((a) < (b) ? (a) : (b))
49 #define max(a, b) ((a) > (b) ? (a) : (b))
55 extern char **environ
;
56 extern Lisp_Object
make_time ();
57 extern void insert_from_buffer ();
58 static int tm_diff ();
59 static void update_buffer_properties ();
60 size_t emacs_strftime ();
61 void set_time_zone_rule ();
63 Lisp_Object Vbuffer_access_fontify_functions
;
64 Lisp_Object Qbuffer_access_fontify_functions
;
65 Lisp_Object Vbuffer_access_fontified_property
;
67 Lisp_Object
Fuser_full_name ();
69 /* Some static data, and a function to initialize it for each run */
71 Lisp_Object Vsystem_name
;
72 Lisp_Object Vuser_real_login_name
; /* login name of current user ID */
73 Lisp_Object Vuser_full_name
; /* full name of current user */
74 Lisp_Object Vuser_login_name
; /* user name from LOGNAME or USER */
80 register unsigned char *p
, *q
, *r
;
81 struct passwd
*pw
; /* password entry for the current user */
84 /* Set up system_name even when dumping. */
88 /* Don't bother with this on initial start when just dumping out */
91 #endif /* not CANNOT_DUMP */
93 pw
= (struct passwd
*) getpwuid (getuid ());
95 /* We let the real user name default to "root" because that's quite
96 accurate on MSDOG and because it lets Emacs find the init file.
97 (The DVX libraries override the Djgpp libraries here.) */
98 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "root");
100 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "unknown");
103 /* Get the effective user name, by consulting environment variables,
104 or the effective uid if those are unset. */
105 user_name
= (char *) getenv ("LOGNAME");
108 user_name
= (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
109 #else /* WINDOWSNT */
110 user_name
= (char *) getenv ("USER");
111 #endif /* WINDOWSNT */
114 pw
= (struct passwd
*) getpwuid (geteuid ());
115 user_name
= (char *) (pw
? pw
->pw_name
: "unknown");
117 Vuser_login_name
= build_string (user_name
);
119 /* If the user name claimed in the environment vars differs from
120 the real uid, use the claimed name to find the full name. */
121 tem
= Fstring_equal (Vuser_login_name
, Vuser_real_login_name
);
122 Vuser_full_name
= Fuser_full_name (NILP (tem
)? make_number (geteuid())
125 p
= (unsigned char *) getenv ("NAME");
127 Vuser_full_name
= build_string (p
);
128 else if (NILP (Vuser_full_name
))
129 Vuser_full_name
= build_string ("unknown");
132 DEFUN ("char-to-string", Fchar_to_string
, Schar_to_string
, 1, 1, 0,
133 "Convert arg CHAR to a string containing that character.")
135 Lisp_Object character
;
138 unsigned char workbuf
[4], *str
;
140 CHECK_NUMBER (character
, 0);
142 len
= CHAR_STRING (XFASTINT (character
), workbuf
, str
);
143 return make_string_from_bytes (str
, 1, len
);
146 DEFUN ("string-to-char", Fstring_to_char
, Sstring_to_char
, 1, 1, 0,
147 "Convert arg STRING to a character, the first character of that string.\n\
148 A multibyte character is handled correctly.")
150 register Lisp_Object string
;
152 register Lisp_Object val
;
153 register struct Lisp_String
*p
;
154 CHECK_STRING (string
, 0);
155 p
= XSTRING (string
);
157 XSETFASTINT (val
, STRING_CHAR (p
->data
, STRING_BYTES (p
)));
159 XSETFASTINT (val
, 0);
164 buildmark (charpos
, bytepos
)
165 int charpos
, bytepos
;
167 register Lisp_Object mark
;
168 mark
= Fmake_marker ();
169 set_marker_both (mark
, Qnil
, charpos
, bytepos
);
173 DEFUN ("point", Fpoint
, Spoint
, 0, 0, 0,
174 "Return value of point, as an integer.\n\
175 Beginning of buffer is position (point-min)")
179 XSETFASTINT (temp
, PT
);
183 DEFUN ("point-marker", Fpoint_marker
, Spoint_marker
, 0, 0, 0,
184 "Return value of point, as a marker object.")
187 return buildmark (PT
, PT_BYTE
);
191 clip_to_bounds (lower
, num
, upper
)
192 int lower
, num
, upper
;
196 else if (num
> upper
)
202 DEFUN ("goto-char", Fgoto_char
, Sgoto_char
, 1, 1, "NGoto char: ",
203 "Set point to POSITION, a number or marker.\n\
204 Beginning of buffer is position (point-min), end is (point-max).\n\
205 If the position is in the middle of a multibyte form,\n\
206 the actual point is set at the head of the multibyte form\n\
207 except in the case that `enable-multibyte-characters' is nil.")
209 register Lisp_Object position
;
214 if (MARKERP (position
)
215 && current_buffer
== XMARKER (position
)->buffer
)
217 pos
= marker_position (position
);
219 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
221 SET_PT_BOTH (ZV
, ZV_BYTE
);
223 SET_PT_BOTH (pos
, marker_byte_position (position
));
228 CHECK_NUMBER_COERCE_MARKER (position
, 0);
230 pos
= clip_to_bounds (BEGV
, XINT (position
), ZV
);
236 region_limit (beginningp
)
239 extern Lisp_Object Vmark_even_if_inactive
; /* Defined in callint.c. */
240 register Lisp_Object m
;
241 if (!NILP (Vtransient_mark_mode
) && NILP (Vmark_even_if_inactive
)
242 && NILP (current_buffer
->mark_active
))
243 Fsignal (Qmark_inactive
, Qnil
);
244 m
= Fmarker_position (current_buffer
->mark
);
245 if (NILP (m
)) error ("There is no region now");
246 if ((PT
< XFASTINT (m
)) == beginningp
)
247 return (make_number (PT
));
252 DEFUN ("region-beginning", Fregion_beginning
, Sregion_beginning
, 0, 0, 0,
253 "Return position of beginning of region, as an integer.")
256 return (region_limit (1));
259 DEFUN ("region-end", Fregion_end
, Sregion_end
, 0, 0, 0,
260 "Return position of end of region, as an integer.")
263 return (region_limit (0));
266 DEFUN ("mark-marker", Fmark_marker
, Smark_marker
, 0, 0, 0,
267 "Return this buffer's mark, as a marker object.\n\
268 Watch out! Moving this marker changes the mark position.\n\
269 If you set the marker not to point anywhere, the buffer will have no mark.")
272 return current_buffer
->mark
;
275 DEFUN ("line-beginning-position", Fline_beginning_position
, Sline_beginning_position
,
277 "Return the character position of the first character on the current line.\n\
278 With argument N not nil or 1, move forward N - 1 lines first.\n\
279 If scan reaches end of buffer, return that position.\n\
280 This function does not move point.")
284 register int orig
, orig_byte
, end
;
293 Fforward_line (make_number (XINT (n
) - 1));
295 SET_PT_BOTH (orig
, orig_byte
);
297 return make_number (end
);
300 DEFUN ("line-end-position", Fline_end_position
, Sline_end_position
,
302 "Return the character position of the last character on the current line.\n\
303 With argument N not nil or 1, move forward N - 1 lines first.\n\
304 If scan reaches end of buffer, return that position.\n\
305 This function does not move point.")
314 return make_number (find_before_next_newline
315 (PT
, 0, XINT (n
) - (XINT (n
) <= 0)));
319 save_excursion_save ()
321 register int visible
= (XBUFFER (XWINDOW (selected_window
)->buffer
)
324 return Fcons (Fpoint_marker (),
325 Fcons (Fcopy_marker (current_buffer
->mark
, Qnil
),
326 Fcons (visible
? Qt
: Qnil
,
327 current_buffer
->mark_active
)));
331 save_excursion_restore (info
)
334 Lisp_Object tem
, tem1
, omark
, nmark
;
335 struct gcpro gcpro1
, gcpro2
, gcpro3
;
337 tem
= Fmarker_buffer (Fcar (info
));
338 /* If buffer being returned to is now deleted, avoid error */
339 /* Otherwise could get error here while unwinding to top level
341 /* In that case, Fmarker_buffer returns nil now. */
345 omark
= nmark
= Qnil
;
346 GCPRO3 (info
, omark
, nmark
);
351 unchain_marker (tem
);
352 tem
= Fcar (Fcdr (info
));
353 omark
= Fmarker_position (current_buffer
->mark
);
354 Fset_marker (current_buffer
->mark
, tem
, Fcurrent_buffer ());
355 nmark
= Fmarker_position (tem
);
356 unchain_marker (tem
);
357 tem
= Fcdr (Fcdr (info
));
358 #if 0 /* We used to make the current buffer visible in the selected window
359 if that was true previously. That avoids some anomalies.
360 But it creates others, and it wasn't documented, and it is simpler
361 and cleaner never to alter the window/buffer connections. */
364 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
365 Fswitch_to_buffer (Fcurrent_buffer (), Qnil
);
368 tem1
= current_buffer
->mark_active
;
369 current_buffer
->mark_active
= Fcdr (tem
);
370 if (!NILP (Vrun_hooks
))
372 /* If mark is active now, and either was not active
373 or was at a different place, run the activate hook. */
374 if (! NILP (current_buffer
->mark_active
))
376 if (! EQ (omark
, nmark
))
377 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
379 /* If mark has ceased to be active, run deactivate hook. */
380 else if (! NILP (tem1
))
381 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
387 DEFUN ("save-excursion", Fsave_excursion
, Ssave_excursion
, 0, UNEVALLED
, 0,
388 "Save point, mark, and current buffer; execute BODY; restore those things.\n\
389 Executes BODY just like `progn'.\n\
390 The values of point, mark and the current buffer are restored\n\
391 even in case of abnormal exit (throw or error).\n\
392 The state of activation of the mark is also restored.\n\
394 This construct does not save `deactivate-mark', and therefore\n\
395 functions that change the buffer will still cause deactivation\n\
396 of the mark at the end of the command. To prevent that, bind\n\
397 `deactivate-mark' with `let'.")
401 register Lisp_Object val
;
402 int count
= specpdl_ptr
- specpdl
;
404 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
407 return unbind_to (count
, val
);
410 DEFUN ("save-current-buffer", Fsave_current_buffer
, Ssave_current_buffer
, 0, UNEVALLED
, 0,
411 "Save the current buffer; execute BODY; restore the current buffer.\n\
412 Executes BODY just like `progn'.")
416 register Lisp_Object val
;
417 int count
= specpdl_ptr
- specpdl
;
419 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
422 return unbind_to (count
, val
);
425 DEFUN ("buffer-size", Fbufsize
, Sbufsize
, 0, 0, 0,
426 "Return the number of characters in the current buffer.")
430 XSETFASTINT (temp
, Z
- BEG
);
434 DEFUN ("point-min", Fpoint_min
, Spoint_min
, 0, 0, 0,
435 "Return the minimum permissible value of point in the current buffer.\n\
436 This is 1, unless narrowing (a buffer restriction) is in effect.")
440 XSETFASTINT (temp
, BEGV
);
444 DEFUN ("point-min-marker", Fpoint_min_marker
, Spoint_min_marker
, 0, 0, 0,
445 "Return a marker to the minimum permissible value of point in this buffer.\n\
446 This is the beginning, unless narrowing (a buffer restriction) is in effect.")
449 return buildmark (BEGV
, BEGV_BYTE
);
452 DEFUN ("point-max", Fpoint_max
, Spoint_max
, 0, 0, 0,
453 "Return the maximum permissible value of point in the current buffer.\n\
454 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
455 is in effect, in which case it is less.")
459 XSETFASTINT (temp
, ZV
);
463 DEFUN ("point-max-marker", Fpoint_max_marker
, Spoint_max_marker
, 0, 0, 0,
464 "Return a marker to the maximum permissible value of point in this buffer.\n\
465 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
466 is in effect, in which case it is less.")
469 return buildmark (ZV
, ZV_BYTE
);
472 DEFUN ("gap-position", Fgap_position
, Sgap_position
, 0, 0, 0,
473 "Return the position of the gap, in the current buffer.\n\
474 See also `gap-size'.")
478 XSETFASTINT (temp
, GPT
);
482 DEFUN ("gap-size", Fgap_size
, Sgap_size
, 0, 0, 0,
483 "Return the size of the current buffer's gap.\n\
484 See also `gap-position'.")
488 XSETFASTINT (temp
, GAP_SIZE
);
492 DEFUN ("position-bytes", Fposition_bytes
, Sposition_bytes
, 1, 1, 0,
493 "Return the byte position for character position POSITION.")
495 Lisp_Object position
;
497 CHECK_NUMBER_COERCE_MARKER (position
, 1);
498 return make_number (CHAR_TO_BYTE (XINT (position
)));
501 DEFUN ("following-char", Ffollowing_char
, Sfollowing_char
, 0, 0, 0,
502 "Return the character following point, as a number.\n\
503 At the end of the buffer or accessible region, return 0.\n\
504 If `enable-multibyte-characters' is nil or point is not\n\
505 at character boundary, multibyte form is ignored,\n\
506 and only one byte following point is returned as a character.")
511 XSETFASTINT (temp
, 0);
513 XSETFASTINT (temp
, FETCH_CHAR (PT_BYTE
));
517 DEFUN ("preceding-char", Fprevious_char
, Sprevious_char
, 0, 0, 0,
518 "Return the character preceding point, as a number.\n\
519 At the beginning of the buffer or accessible region, return 0.\n\
520 If `enable-multibyte-characters' is nil or point is not\n\
521 at character boundary, multi-byte form is ignored,\n\
522 and only one byte preceding point is returned as a character.")
527 XSETFASTINT (temp
, 0);
528 else if (!NILP (current_buffer
->enable_multibyte_characters
))
532 XSETFASTINT (temp
, FETCH_CHAR (pos
));
535 XSETFASTINT (temp
, FETCH_BYTE (PT_BYTE
- 1));
539 DEFUN ("bobp", Fbobp
, Sbobp
, 0, 0, 0,
540 "Return t if point is at the beginning of the buffer.\n\
541 If the buffer is narrowed, this means the beginning of the narrowed part.")
549 DEFUN ("eobp", Feobp
, Seobp
, 0, 0, 0,
550 "Return t if point is at the end of the buffer.\n\
551 If the buffer is narrowed, this means the end of the narrowed part.")
559 DEFUN ("bolp", Fbolp
, Sbolp
, 0, 0, 0,
560 "Return t if point is at the beginning of a line.")
563 if (PT
== BEGV
|| FETCH_BYTE (PT_BYTE
- 1) == '\n')
568 DEFUN ("eolp", Feolp
, Seolp
, 0, 0, 0,
569 "Return t if point is at the end of a line.\n\
570 `End of a line' includes point being at the end of the buffer.")
573 if (PT
== ZV
|| FETCH_BYTE (PT_BYTE
) == '\n')
578 DEFUN ("char-after", Fchar_after
, Schar_after
, 0, 1, 0,
579 "Return character in current buffer at position POS.\n\
580 POS is an integer or a buffer pointer.\n\
581 If POS is out of range, the value is nil.")
585 register int pos_byte
;
586 register Lisp_Object val
;
596 pos_byte
= marker_byte_position (pos
);
597 if (pos_byte
< BEGV_BYTE
|| pos_byte
>= ZV_BYTE
)
602 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
603 if (XINT (pos
) < BEGV
|| XINT (pos
) >= ZV
)
606 pos_byte
= CHAR_TO_BYTE (XINT (pos
));
609 return make_number (FETCH_CHAR (pos_byte
));
612 DEFUN ("char-before", Fchar_before
, Schar_before
, 0, 1, 0,
613 "Return character in current buffer preceding position POS.\n\
614 POS is an integer or a buffer pointer.\n\
615 If POS is out of range, the value is nil.")
619 register Lisp_Object val
;
620 register int pos_byte
;
630 pos_byte
= marker_byte_position (pos
);
632 if (pos_byte
<= BEGV_BYTE
|| pos_byte
> ZV_BYTE
)
637 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
639 if (XINT (pos
) <= BEGV
|| XINT (pos
) > ZV
)
642 pos_byte
= CHAR_TO_BYTE (XINT (pos
));
645 if (!NILP (current_buffer
->enable_multibyte_characters
))
648 XSETFASTINT (val
, FETCH_CHAR (pos_byte
));
653 XSETFASTINT (val
, FETCH_BYTE (pos_byte
));
658 DEFUN ("user-login-name", Fuser_login_name
, Suser_login_name
, 0, 1, 0,
659 "Return the name under which the user logged in, as a string.\n\
660 This is based on the effective uid, not the real uid.\n\
661 Also, if the environment variable LOGNAME or USER is set,\n\
662 that determines the value of this function.\n\n\
663 If optional argument UID is an integer, return the login name of the user\n\
664 with that uid, or nil if there is no such user.")
670 /* Set up the user name info if we didn't do it before.
671 (That can happen if Emacs is dumpable
672 but you decide to run `temacs -l loadup' and not dump. */
673 if (INTEGERP (Vuser_login_name
))
677 return Vuser_login_name
;
679 CHECK_NUMBER (uid
, 0);
680 pw
= (struct passwd
*) getpwuid (XINT (uid
));
681 return (pw
? build_string (pw
->pw_name
) : Qnil
);
684 DEFUN ("user-real-login-name", Fuser_real_login_name
, Suser_real_login_name
,
686 "Return the name of the user's real uid, as a string.\n\
687 This ignores the environment variables LOGNAME and USER, so it differs from\n\
688 `user-login-name' when running under `su'.")
691 /* Set up the user name info if we didn't do it before.
692 (That can happen if Emacs is dumpable
693 but you decide to run `temacs -l loadup' and not dump. */
694 if (INTEGERP (Vuser_login_name
))
696 return Vuser_real_login_name
;
699 DEFUN ("user-uid", Fuser_uid
, Suser_uid
, 0, 0, 0,
700 "Return the effective uid of Emacs, as an integer.")
703 return make_number (geteuid ());
706 DEFUN ("user-real-uid", Fuser_real_uid
, Suser_real_uid
, 0, 0, 0,
707 "Return the real uid of Emacs, as an integer.")
710 return make_number (getuid ());
713 DEFUN ("user-full-name", Fuser_full_name
, Suser_full_name
, 0, 1, 0,
714 "Return the full name of the user logged in, as a string.\n\
715 If optional argument UID is an integer, return the full name of the user\n\
716 with that uid, or \"unknown\" if there is no such user.\n\
717 If UID is a string, return the full name of the user with that login\n\
718 name, or \"unknown\" if no such user could be found.")
723 register unsigned char *p
, *q
;
724 extern char *index ();
728 return Vuser_full_name
;
729 else if (NUMBERP (uid
))
730 pw
= (struct passwd
*) getpwuid (XINT (uid
));
731 else if (STRINGP (uid
))
732 pw
= (struct passwd
*) getpwnam (XSTRING (uid
)->data
);
734 error ("Invalid UID specification");
739 p
= (unsigned char *) USER_FULL_NAME
;
740 /* Chop off everything after the first comma. */
741 q
= (unsigned char *) index (p
, ',');
742 full
= make_string (p
, q
? q
- p
: strlen (p
));
744 #ifdef AMPERSAND_FULL_NAME
745 p
= XSTRING (full
)->data
;
746 q
= (unsigned char *) index (p
, '&');
747 /* Substitute the login name for the &, upcasing the first character. */
750 register unsigned char *r
;
753 login
= Fuser_login_name (make_number (pw
->pw_uid
));
754 r
= (unsigned char *) alloca (strlen (p
) + XSTRING (login
)->size
+ 1);
757 strcat (r
, XSTRING (login
)->data
);
758 r
[q
- p
] = UPCASE (r
[q
- p
]);
760 full
= build_string (r
);
762 #endif /* AMPERSAND_FULL_NAME */
767 DEFUN ("system-name", Fsystem_name
, Ssystem_name
, 0, 0, 0,
768 "Return the name of the machine you are running on, as a string.")
774 /* For the benefit of callers who don't want to include lisp.h */
778 if (STRINGP (Vsystem_name
))
779 return (char *) XSTRING (Vsystem_name
)->data
;
784 DEFUN ("emacs-pid", Femacs_pid
, Semacs_pid
, 0, 0, 0,
785 "Return the process ID of Emacs, as an integer.")
788 return make_number (getpid ());
791 DEFUN ("current-time", Fcurrent_time
, Scurrent_time
, 0, 0, 0,
792 "Return the current time, as the number of seconds since 1970-01-01 00:00:00.\n\
793 The time is returned as a list of three integers. The first has the\n\
794 most significant 16 bits of the seconds, while the second has the\n\
795 least significant 16 bits. The third integer gives the microsecond\n\
798 The microsecond count is zero on systems that do not provide\n\
799 resolution finer than a second.")
803 Lisp_Object result
[3];
806 XSETINT (result
[0], (EMACS_SECS (t
) >> 16) & 0xffff);
807 XSETINT (result
[1], (EMACS_SECS (t
) >> 0) & 0xffff);
808 XSETINT (result
[2], EMACS_USECS (t
));
810 return Flist (3, result
);
815 lisp_time_argument (specified_time
, result
)
816 Lisp_Object specified_time
;
819 if (NILP (specified_time
))
820 return time (result
) != -1;
823 Lisp_Object high
, low
;
824 high
= Fcar (specified_time
);
825 CHECK_NUMBER (high
, 0);
826 low
= Fcdr (specified_time
);
829 CHECK_NUMBER (low
, 0);
830 *result
= (XINT (high
) << 16) + (XINT (low
) & 0xffff);
831 return *result
>> 16 == XINT (high
);
836 DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
837 "Use FORMAT-STRING to format the time TIME, or now if omitted.\n\
838 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as returned by\n\
839 `current-time' or `file-attributes'.\n\
840 The third, optional, argument UNIVERSAL, if non-nil, means describe TIME\n\
841 as Universal Time; nil means describe TIME in the local time zone.\n\
842 The value is a copy of FORMAT-STRING, but with certain constructs replaced\n\
843 by text that describes the specified date and time in TIME:\n\
845 %Y is the year, %y within the century, %C the century.\n\
846 %G is the year corresponding to the ISO week, %g within the century.\n\
847 %m is the numeric month.\n\
848 %b and %h are the locale's abbreviated month name, %B the full name.\n\
849 %d is the day of the month, zero-padded, %e is blank-padded.\n\
850 %u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6.\n\
851 %a is the locale's abbreviated name of the day of week, %A the full name.\n\
852 %U is the week number starting on Sunday, %W starting on Monday,\n\
853 %V according to ISO 8601.\n\
854 %j is the day of the year.\n\
856 %H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H\n\
857 only blank-padded, %l is like %I blank-padded.\n\
858 %p is the locale's equivalent of either AM or PM.\n\
861 %Z is the time zone name, %z is the numeric form.\n\
862 %s is the number of seconds since 1970-01-01 00:00:00 +0000.\n\
864 %c is the locale's date and time format.\n\
865 %x is the locale's \"preferred\" date format.\n\
866 %D is like \"%m/%d/%y\".\n\
868 %R is like \"%H:%M\", %T is like \"%H:%M:%S\", %r is like \"%I:%M:%S %p\".\n\
869 %X is the locale's \"preferred\" time format.\n\
871 Finally, %n is a newline, %t is a tab, %% is a literal %.\n\
873 Certain flags and modifiers are available with some format controls.\n\
874 The flags are `_' and `-'. For certain characters X, %_X is like %X,\n\
875 but padded with blanks; %-X is like %X, but without padding.\n\
876 %NX (where N stands for an integer) is like %X,\n\
877 but takes up at least N (a number) positions.\n\
878 The modifiers are `E' and `O'. For certain characters X,\n\
879 %EX is a locale's alternative version of %X;\n\
880 %OX is like %X, but uses the locale's number symbols.\n\
882 For example, to produce full ISO 8601 format, use \"%Y-%m-%dT%T%z\".")
883 (format_string, time, universal)
886 DEFUN ("format-time-string", Fformat_time_string
, Sformat_time_string
, 1, 3, 0,
887 0 /* See immediately above */)
888 (format_string
, time
, universal
)
889 Lisp_Object format_string
, time
, universal
;
894 CHECK_STRING (format_string
, 1);
896 if (! lisp_time_argument (time
, &value
))
897 error ("Invalid time specification");
899 /* This is probably enough. */
900 size
= STRING_BYTES (XSTRING (format_string
)) * 6 + 50;
904 char *buf
= (char *) alloca (size
+ 1);
908 result
= emacs_strftime (buf
, size
, XSTRING (format_string
)->data
,
909 (NILP (universal
) ? localtime (&value
)
911 if ((result
> 0 && result
< size
) || (result
== 0 && buf
[0] == '\0'))
912 return build_string (buf
);
914 /* If buffer was too small, make it bigger and try again. */
915 result
= emacs_strftime (NULL
, 0x7fffffff, XSTRING (format_string
)->data
,
916 (NILP (universal
) ? localtime (&value
)
922 DEFUN ("decode-time", Fdecode_time
, Sdecode_time
, 0, 1, 0,
923 "Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).\n\
924 The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)\n\
925 or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'\n\
926 to use the current time. The list has the following nine members:\n\
927 SEC is an integer between 0 and 60; SEC is 60 for a leap second, which\n\
928 only some operating systems support. MINUTE is an integer between 0 and 59.\n\
929 HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.\n\
930 MONTH is an integer between 1 and 12. YEAR is an integer indicating the\n\
931 four-digit year. DOW is the day of week, an integer between 0 and 6, where\n\
932 0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.\n\
933 ZONE is an integer indicating the number of seconds east of Greenwich.\n\
934 \(Note that Common Lisp has different meanings for DOW and ZONE.)")
936 Lisp_Object specified_time
;
940 struct tm
*decoded_time
;
941 Lisp_Object list_args
[9];
943 if (! lisp_time_argument (specified_time
, &time_spec
))
944 error ("Invalid time specification");
946 decoded_time
= localtime (&time_spec
);
947 XSETFASTINT (list_args
[0], decoded_time
->tm_sec
);
948 XSETFASTINT (list_args
[1], decoded_time
->tm_min
);
949 XSETFASTINT (list_args
[2], decoded_time
->tm_hour
);
950 XSETFASTINT (list_args
[3], decoded_time
->tm_mday
);
951 XSETFASTINT (list_args
[4], decoded_time
->tm_mon
+ 1);
952 XSETINT (list_args
[5], decoded_time
->tm_year
+ 1900);
953 XSETFASTINT (list_args
[6], decoded_time
->tm_wday
);
954 list_args
[7] = (decoded_time
->tm_isdst
)? Qt
: Qnil
;
956 /* Make a copy, in case gmtime modifies the struct. */
957 save_tm
= *decoded_time
;
958 decoded_time
= gmtime (&time_spec
);
959 if (decoded_time
== 0)
962 XSETINT (list_args
[8], tm_diff (&save_tm
, decoded_time
));
963 return Flist (9, list_args
);
966 DEFUN ("encode-time", Fencode_time
, Sencode_time
, 6, MANY
, 0,
967 "Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.\n\
968 This is the reverse operation of `decode-time', which see.\n\
969 ZONE defaults to the current time zone rule. This can\n\
970 be a string or t (as from `set-time-zone-rule'), or it can be a list\n\
971 \(as from `current-time-zone') or an integer (as from `decode-time')\n\
972 applied without consideration for daylight savings time.\n\
974 You can pass more than 7 arguments; then the first six arguments\n\
975 are used as SECOND through YEAR, and the *last* argument is used as ZONE.\n\
976 The intervening arguments are ignored.\n\
977 This feature lets (apply 'encode-time (decode-time ...)) work.\n\
979 Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;\n\
980 for example, a DAY of 0 means the day preceding the given month.\n\
981 Year numbers less than 100 are treated just like other year numbers.\n\
982 If you want them to stand for years in this century, you must do that yourself.")
985 register Lisp_Object
*args
;
989 Lisp_Object zone
= (nargs
> 6 ? args
[nargs
- 1] : Qnil
);
991 CHECK_NUMBER (args
[0], 0); /* second */
992 CHECK_NUMBER (args
[1], 1); /* minute */
993 CHECK_NUMBER (args
[2], 2); /* hour */
994 CHECK_NUMBER (args
[3], 3); /* day */
995 CHECK_NUMBER (args
[4], 4); /* month */
996 CHECK_NUMBER (args
[5], 5); /* year */
998 tm
.tm_sec
= XINT (args
[0]);
999 tm
.tm_min
= XINT (args
[1]);
1000 tm
.tm_hour
= XINT (args
[2]);
1001 tm
.tm_mday
= XINT (args
[3]);
1002 tm
.tm_mon
= XINT (args
[4]) - 1;
1003 tm
.tm_year
= XINT (args
[5]) - 1900;
1009 time
= mktime (&tm
);
1014 char **oldenv
= environ
, **newenv
;
1018 else if (STRINGP (zone
))
1019 tzstring
= (char *) XSTRING (zone
)->data
;
1020 else if (INTEGERP (zone
))
1022 int abszone
= abs (XINT (zone
));
1023 sprintf (tzbuf
, "XXX%s%d:%02d:%02d", "-" + (XINT (zone
) < 0),
1024 abszone
/ (60*60), (abszone
/60) % 60, abszone
% 60);
1028 error ("Invalid time zone specification");
1030 /* Set TZ before calling mktime; merely adjusting mktime's returned
1031 value doesn't suffice, since that would mishandle leap seconds. */
1032 set_time_zone_rule (tzstring
);
1034 time
= mktime (&tm
);
1036 /* Restore TZ to previous value. */
1040 #ifdef LOCALTIME_CACHE
1045 if (time
== (time_t) -1)
1046 error ("Specified time is not representable");
1048 return make_time (time
);
1051 DEFUN ("current-time-string", Fcurrent_time_string
, Scurrent_time_string
, 0, 1, 0,
1052 "Return the current time, as a human-readable string.\n\
1053 Programs can use this function to decode a time,\n\
1054 since the number of columns in each field is fixed.\n\
1055 The format is `Sun Sep 16 01:03:52 1973'.\n\
1056 However, see also the functions `decode-time' and `format-time-string'\n\
1057 which provide a much more powerful and general facility.\n\
1059 If an argument is given, it specifies a time to format\n\
1060 instead of the current time. The argument should have the form:\n\
1063 (HIGH LOW . IGNORED).\n\
1064 Thus, you can use times obtained from `current-time'\n\
1065 and from `file-attributes'.")
1067 Lisp_Object specified_time
;
1073 if (! lisp_time_argument (specified_time
, &value
))
1075 tem
= (char *) ctime (&value
);
1077 strncpy (buf
, tem
, 24);
1080 return build_string (buf
);
1083 #define TM_YEAR_BASE 1900
1085 /* Yield A - B, measured in seconds.
1086 This function is copied from the GNU C Library. */
1091 /* Compute intervening leap days correctly even if year is negative.
1092 Take care to avoid int overflow in leap day calculations,
1093 but it's OK to assume that A and B are close to each other. */
1094 int a4
= (a
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (a
->tm_year
& 3);
1095 int b4
= (b
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (b
->tm_year
& 3);
1096 int a100
= a4
/ 25 - (a4
% 25 < 0);
1097 int b100
= b4
/ 25 - (b4
% 25 < 0);
1098 int a400
= a100
>> 2;
1099 int b400
= b100
>> 2;
1100 int intervening_leap_days
= (a4
- b4
) - (a100
- b100
) + (a400
- b400
);
1101 int years
= a
->tm_year
- b
->tm_year
;
1102 int days
= (365 * years
+ intervening_leap_days
1103 + (a
->tm_yday
- b
->tm_yday
));
1104 return (60 * (60 * (24 * days
+ (a
->tm_hour
- b
->tm_hour
))
1105 + (a
->tm_min
- b
->tm_min
))
1106 + (a
->tm_sec
- b
->tm_sec
));
1109 DEFUN ("current-time-zone", Fcurrent_time_zone
, Scurrent_time_zone
, 0, 1, 0,
1110 "Return the offset and name for the local time zone.\n\
1111 This returns a list of the form (OFFSET NAME).\n\
1112 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).\n\
1113 A negative value means west of Greenwich.\n\
1114 NAME is a string giving the name of the time zone.\n\
1115 If an argument is given, it specifies when the time zone offset is determined\n\
1116 instead of using the current time. The argument should have the form:\n\
1119 (HIGH LOW . IGNORED).\n\
1120 Thus, you can use times obtained from `current-time'\n\
1121 and from `file-attributes'.\n\
1123 Some operating systems cannot provide all this information to Emacs;\n\
1124 in this case, `current-time-zone' returns a list containing nil for\n\
1125 the data it can't find.")
1127 Lisp_Object specified_time
;
1132 if (lisp_time_argument (specified_time
, &value
)
1133 && (t
= gmtime (&value
)) != 0)
1139 gmt
= *t
; /* Make a copy, in case localtime modifies *t. */
1140 t
= localtime (&value
);
1141 offset
= tm_diff (t
, &gmt
);
1145 s
= (char *)t
->tm_zone
;
1146 #else /* not HAVE_TM_ZONE */
1148 if (t
->tm_isdst
== 0 || t
->tm_isdst
== 1)
1149 s
= tzname
[t
->tm_isdst
];
1151 #endif /* not HAVE_TM_ZONE */
1154 /* No local time zone name is available; use "+-NNNN" instead. */
1155 int am
= (offset
< 0 ? -offset
: offset
) / 60;
1156 sprintf (buf
, "%c%02d%02d", (offset
< 0 ? '-' : '+'), am
/60, am
%60);
1159 return Fcons (make_number (offset
), Fcons (build_string (s
), Qnil
));
1162 return Fmake_list (make_number (2), Qnil
);
1165 /* This holds the value of `environ' produced by the previous
1166 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
1167 has never been called. */
1168 static char **environbuf
;
1170 DEFUN ("set-time-zone-rule", Fset_time_zone_rule
, Sset_time_zone_rule
, 1, 1, 0,
1171 "Set the local time zone using TZ, a string specifying a time zone rule.\n\
1172 If TZ is nil, use implementation-defined default time zone information.\n\
1173 If TZ is t, use Universal Time.")
1181 else if (EQ (tz
, Qt
))
1185 CHECK_STRING (tz
, 0);
1186 tzstring
= (char *) XSTRING (tz
)->data
;
1189 set_time_zone_rule (tzstring
);
1192 environbuf
= environ
;
1197 #ifdef LOCALTIME_CACHE
1199 /* These two values are known to load tz files in buggy implementations,
1200 i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2.
1201 Their values shouldn't matter in non-buggy implementations.
1202 We don't use string literals for these strings,
1203 since if a string in the environment is in readonly
1204 storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
1205 See Sun bugs 1113095 and 1114114, ``Timezone routines
1206 improperly modify environment''. */
1208 static char set_time_zone_rule_tz1
[] = "TZ=GMT+0";
1209 static char set_time_zone_rule_tz2
[] = "TZ=GMT+1";
1213 /* Set the local time zone rule to TZSTRING.
1214 This allocates memory into `environ', which it is the caller's
1215 responsibility to free. */
1217 set_time_zone_rule (tzstring
)
1221 char **from
, **to
, **newenv
;
1223 /* Make the ENVIRON vector longer with room for TZSTRING. */
1224 for (from
= environ
; *from
; from
++)
1226 envptrs
= from
- environ
+ 2;
1227 newenv
= to
= (char **) xmalloc (envptrs
* sizeof (char *)
1228 + (tzstring
? strlen (tzstring
) + 4 : 0));
1230 /* Add TZSTRING to the end of environ, as a value for TZ. */
1233 char *t
= (char *) (to
+ envptrs
);
1235 strcat (t
, tzstring
);
1239 /* Copy the old environ vector elements into NEWENV,
1240 but don't copy the TZ variable.
1241 So we have only one definition of TZ, which came from TZSTRING. */
1242 for (from
= environ
; *from
; from
++)
1243 if (strncmp (*from
, "TZ=", 3) != 0)
1249 /* If we do have a TZSTRING, NEWENV points to the vector slot where
1250 the TZ variable is stored. If we do not have a TZSTRING,
1251 TO points to the vector slot which has the terminating null. */
1253 #ifdef LOCALTIME_CACHE
1255 /* In SunOS 4.1.3_U1 and 4.1.4, if TZ has a value like
1256 "US/Pacific" that loads a tz file, then changes to a value like
1257 "XXX0" that does not load a tz file, and then changes back to
1258 its original value, the last change is (incorrectly) ignored.
1259 Also, if TZ changes twice in succession to values that do
1260 not load a tz file, tzset can dump core (see Sun bug#1225179).
1261 The following code works around these bugs. */
1265 /* Temporarily set TZ to a value that loads a tz file
1266 and that differs from tzstring. */
1268 *newenv
= (strcmp (tzstring
, set_time_zone_rule_tz1
+ 3) == 0
1269 ? set_time_zone_rule_tz2
: set_time_zone_rule_tz1
);
1275 /* The implied tzstring is unknown, so temporarily set TZ to
1276 two different values that each load a tz file. */
1277 *to
= set_time_zone_rule_tz1
;
1280 *to
= set_time_zone_rule_tz2
;
1285 /* Now TZ has the desired value, and tzset can be invoked safely. */
1292 /* Insert NARGS Lisp objects in the array ARGS by calling INSERT_FUNC
1293 (if a type of object is Lisp_Int) or INSERT_FROM_STRING_FUNC (if a
1294 type of object is Lisp_String). INHERIT is passed to
1295 INSERT_FROM_STRING_FUNC as the last argument. */
1298 general_insert_function (insert_func
, insert_from_string_func
,
1299 inherit
, nargs
, args
)
1300 void (*insert_func
) P_ ((unsigned char *, int));
1301 void (*insert_from_string_func
) P_ ((Lisp_Object
, int, int, int, int, int));
1303 register Lisp_Object
*args
;
1305 register int argnum
;
1306 register Lisp_Object val
;
1308 for (argnum
= 0; argnum
< nargs
; argnum
++)
1314 unsigned char workbuf
[4], *str
;
1317 if (!NILP (current_buffer
->enable_multibyte_characters
))
1318 len
= CHAR_STRING (XFASTINT (val
), workbuf
, str
);
1320 workbuf
[0] = XINT (val
), str
= workbuf
, len
= 1;
1321 (*insert_func
) (str
, len
);
1323 else if (STRINGP (val
))
1325 (*insert_from_string_func
) (val
, 0, 0,
1326 XSTRING (val
)->size
,
1327 STRING_BYTES (XSTRING (val
)),
1332 val
= wrong_type_argument (Qchar_or_string_p
, val
);
1346 /* Callers passing one argument to Finsert need not gcpro the
1347 argument "array", since the only element of the array will
1348 not be used after calling insert or insert_from_string, so
1349 we don't care if it gets trashed. */
1351 DEFUN ("insert", Finsert
, Sinsert
, 0, MANY
, 0,
1352 "Insert the arguments, either strings or characters, at point.\n\
1353 Point and before-insertion markers move forward to end up\n\
1354 after the inserted text.\n\
1355 Any other markers at the point of insertion remain before the text.\n\
1357 If the current buffer is multibyte, unibyte strings are converted\n\
1358 to multibyte for insertion (see `unibyte-char-to-multibyte').\n\
1359 If the current buffer is unibyte, multiibyte strings are converted\n\
1360 to unibyte for insertion.")
1363 register Lisp_Object
*args
;
1365 general_insert_function (insert
, insert_from_string
, 0, nargs
, args
);
1369 DEFUN ("insert-and-inherit", Finsert_and_inherit
, Sinsert_and_inherit
,
1371 "Insert the arguments at point, inheriting properties from adjoining text.\n\
1372 Point and before-insertion markers move forward to end up\n\
1373 after the inserted text.\n\
1374 Any other markers at the point of insertion remain before the text.\n\
1376 If the current buffer is multibyte, unibyte strings are converted\n\
1377 to multibyte for insertion (see `unibyte-char-to-multibyte').\n\
1378 If the current buffer is unibyte, multiibyte strings are converted\n\
1379 to unibyte for insertion.")
1382 register Lisp_Object
*args
;
1384 general_insert_function (insert_and_inherit
, insert_from_string
, 1,
1389 DEFUN ("insert-before-markers", Finsert_before_markers
, Sinsert_before_markers
, 0, MANY
, 0,
1390 "Insert strings or characters at point, relocating markers after the text.\n\
1391 Point and markers move forward to end up after the inserted text.\n\
1393 If the current buffer is multibyte, unibyte strings are converted\n\
1394 to multibyte for insertion (see `unibyte-char-to-multibyte').\n\
1395 If the current buffer is unibyte, multiibyte strings are converted\n\
1396 to unibyte for insertion.")
1399 register Lisp_Object
*args
;
1401 general_insert_function (insert_before_markers
,
1402 insert_from_string_before_markers
, 0,
1407 DEFUN ("insert-before-markers-and-inherit", Finsert_and_inherit_before_markers
,
1408 Sinsert_and_inherit_before_markers
, 0, MANY
, 0,
1409 "Insert text at point, relocating markers and inheriting properties.\n\
1410 Point and markers move forward to end up after the inserted text.\n\
1412 If the current buffer is multibyte, unibyte strings are converted\n\
1413 to multibyte for insertion (see `unibyte-char-to-multibyte').\n\
1414 If the current buffer is unibyte, multiibyte strings are converted\n\
1415 to unibyte for insertion.")
1418 register Lisp_Object
*args
;
1420 general_insert_function (insert_before_markers_and_inherit
,
1421 insert_from_string_before_markers
, 1,
1426 DEFUN ("insert-char", Finsert_char
, Sinsert_char
, 2, 3, 0,
1427 "Insert COUNT (second arg) copies of CHARACTER (first arg).\n\
1428 Both arguments are required.\n\
1429 Point, and before-insertion markers, are relocated as in the function `insert'.\n\
1430 The optional third arg INHERIT, if non-nil, says to inherit text properties\n\
1431 from adjoining text, if those properties are sticky.")
1432 (character
, count
, inherit
)
1433 Lisp_Object character
, count
, inherit
;
1435 register unsigned char *string
;
1436 register int strlen
;
1439 unsigned char workbuf
[4], *str
;
1441 CHECK_NUMBER (character
, 0);
1442 CHECK_NUMBER (count
, 1);
1444 if (!NILP (current_buffer
->enable_multibyte_characters
))
1445 len
= CHAR_STRING (XFASTINT (character
), workbuf
, str
);
1447 workbuf
[0] = XFASTINT (character
), str
= workbuf
, len
= 1;
1448 n
= XINT (count
) * len
;
1451 strlen
= min (n
, 256 * len
);
1452 string
= (unsigned char *) alloca (strlen
);
1453 for (i
= 0; i
< strlen
; i
++)
1454 string
[i
] = str
[i
% len
];
1458 if (!NILP (inherit
))
1459 insert_and_inherit (string
, strlen
);
1461 insert (string
, strlen
);
1466 if (!NILP (inherit
))
1467 insert_and_inherit (string
, n
);
1475 /* Making strings from buffer contents. */
1477 /* Return a Lisp_String containing the text of the current buffer from
1478 START to END. If text properties are in use and the current buffer
1479 has properties in the range specified, the resulting string will also
1480 have them, if PROPS is nonzero.
1482 We don't want to use plain old make_string here, because it calls
1483 make_uninit_string, which can cause the buffer arena to be
1484 compacted. make_string has no way of knowing that the data has
1485 been moved, and thus copies the wrong data into the string. This
1486 doesn't effect most of the other users of make_string, so it should
1487 be left as is. But we should use this function when conjuring
1488 buffer substrings. */
1491 make_buffer_string (start
, end
, props
)
1495 int start_byte
= CHAR_TO_BYTE (start
);
1496 int end_byte
= CHAR_TO_BYTE (end
);
1498 return make_buffer_string_both (start
, start_byte
, end
, end_byte
, props
);
1501 /* Return a Lisp_String containing the text of the current buffer from
1502 START / START_BYTE to END / END_BYTE.
1504 If text properties are in use and the current buffer
1505 has properties in the range specified, the resulting string will also
1506 have them, if PROPS is nonzero.
1508 We don't want to use plain old make_string here, because it calls
1509 make_uninit_string, which can cause the buffer arena to be
1510 compacted. make_string has no way of knowing that the data has
1511 been moved, and thus copies the wrong data into the string. This
1512 doesn't effect most of the other users of make_string, so it should
1513 be left as is. But we should use this function when conjuring
1514 buffer substrings. */
1517 make_buffer_string_both (start
, start_byte
, end
, end_byte
, props
)
1518 int start
, start_byte
, end
, end_byte
;
1521 Lisp_Object result
, tem
, tem1
;
1523 if (start
< GPT
&& GPT
< end
)
1526 if (! NILP (current_buffer
->enable_multibyte_characters
))
1527 result
= make_uninit_multibyte_string (end
- start
, end_byte
- start_byte
);
1529 result
= make_uninit_string (end
- start
);
1530 bcopy (BYTE_POS_ADDR (start_byte
), XSTRING (result
)->data
,
1531 end_byte
- start_byte
);
1533 /* If desired, update and copy the text properties. */
1534 #ifdef USE_TEXT_PROPERTIES
1537 update_buffer_properties (start
, end
);
1539 tem
= Fnext_property_change (make_number (start
), Qnil
, make_number (end
));
1540 tem1
= Ftext_properties_at (make_number (start
), Qnil
);
1542 if (XINT (tem
) != end
|| !NILP (tem1
))
1543 copy_intervals_to_string (result
, current_buffer
, start
,
1551 /* Call Vbuffer_access_fontify_functions for the range START ... END
1552 in the current buffer, if necessary. */
1555 update_buffer_properties (start
, end
)
1558 #ifdef USE_TEXT_PROPERTIES
1559 /* If this buffer has some access functions,
1560 call them, specifying the range of the buffer being accessed. */
1561 if (!NILP (Vbuffer_access_fontify_functions
))
1563 Lisp_Object args
[3];
1566 args
[0] = Qbuffer_access_fontify_functions
;
1567 XSETINT (args
[1], start
);
1568 XSETINT (args
[2], end
);
1570 /* But don't call them if we can tell that the work
1571 has already been done. */
1572 if (!NILP (Vbuffer_access_fontified_property
))
1574 tem
= Ftext_property_any (args
[1], args
[2],
1575 Vbuffer_access_fontified_property
,
1578 Frun_hook_with_args (3, args
);
1581 Frun_hook_with_args (3, args
);
1586 DEFUN ("buffer-substring", Fbuffer_substring
, Sbuffer_substring
, 2, 2, 0,
1587 "Return the contents of part of the current buffer as a string.\n\
1588 The two arguments START and END are character positions;\n\
1589 they can be in either order.\n\
1590 The string returned is multibyte if the buffer is multibyte.")
1592 Lisp_Object start
, end
;
1596 validate_region (&start
, &end
);
1600 return make_buffer_string (b
, e
, 1);
1603 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties
,
1604 Sbuffer_substring_no_properties
, 2, 2, 0,
1605 "Return the characters of part of the buffer, without the text properties.\n\
1606 The two arguments START and END are character positions;\n\
1607 they can be in either order.")
1609 Lisp_Object start
, end
;
1613 validate_region (&start
, &end
);
1617 return make_buffer_string (b
, e
, 0);
1620 DEFUN ("buffer-string", Fbuffer_string
, Sbuffer_string
, 0, 0, 0,
1621 "Return the contents of the current buffer as a string.\n\
1622 If narrowing is in effect, this function returns only the visible part\n\
1626 return make_buffer_string (BEGV
, ZV
, 1);
1629 DEFUN ("insert-buffer-substring", Finsert_buffer_substring
, Sinsert_buffer_substring
,
1631 "Insert before point a substring of the contents of buffer BUFFER.\n\
1632 BUFFER may be a buffer or a buffer name.\n\
1633 Arguments START and END are character numbers specifying the substring.\n\
1634 They default to the beginning and the end of BUFFER.")
1636 Lisp_Object buf
, start
, end
;
1638 register int b
, e
, temp
;
1639 register struct buffer
*bp
, *obuf
;
1642 buffer
= Fget_buffer (buf
);
1645 bp
= XBUFFER (buffer
);
1646 if (NILP (bp
->name
))
1647 error ("Selecting deleted buffer");
1653 CHECK_NUMBER_COERCE_MARKER (start
, 0);
1660 CHECK_NUMBER_COERCE_MARKER (end
, 1);
1665 temp
= b
, b
= e
, e
= temp
;
1667 if (!(BUF_BEGV (bp
) <= b
&& e
<= BUF_ZV (bp
)))
1668 args_out_of_range (start
, end
);
1670 obuf
= current_buffer
;
1671 set_buffer_internal_1 (bp
);
1672 update_buffer_properties (b
, e
);
1673 set_buffer_internal_1 (obuf
);
1675 insert_from_buffer (bp
, b
, e
- b
, 0);
1679 DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings
, Scompare_buffer_substrings
,
1681 "Compare two substrings of two buffers; return result as number.\n\
1682 the value is -N if first string is less after N-1 chars,\n\
1683 +N if first string is greater after N-1 chars, or 0 if strings match.\n\
1684 Each substring is represented as three arguments: BUFFER, START and END.\n\
1685 That makes six args in all, three for each substring.\n\n\
1686 The value of `case-fold-search' in the current buffer\n\
1687 determines whether case is significant or ignored.")
1688 (buffer1
, start1
, end1
, buffer2
, start2
, end2
)
1689 Lisp_Object buffer1
, start1
, end1
, buffer2
, start2
, end2
;
1691 register int begp1
, endp1
, begp2
, endp2
, temp
;
1692 register struct buffer
*bp1
, *bp2
;
1693 register Lisp_Object
*trt
1694 = (!NILP (current_buffer
->case_fold_search
)
1695 ? XCHAR_TABLE (current_buffer
->case_canon_table
)->contents
: 0);
1697 int i1
, i2
, i1_byte
, i2_byte
;
1699 /* Find the first buffer and its substring. */
1702 bp1
= current_buffer
;
1706 buf1
= Fget_buffer (buffer1
);
1709 bp1
= XBUFFER (buf1
);
1710 if (NILP (bp1
->name
))
1711 error ("Selecting deleted buffer");
1715 begp1
= BUF_BEGV (bp1
);
1718 CHECK_NUMBER_COERCE_MARKER (start1
, 1);
1719 begp1
= XINT (start1
);
1722 endp1
= BUF_ZV (bp1
);
1725 CHECK_NUMBER_COERCE_MARKER (end1
, 2);
1726 endp1
= XINT (end1
);
1730 temp
= begp1
, begp1
= endp1
, endp1
= temp
;
1732 if (!(BUF_BEGV (bp1
) <= begp1
1734 && endp1
<= BUF_ZV (bp1
)))
1735 args_out_of_range (start1
, end1
);
1737 /* Likewise for second substring. */
1740 bp2
= current_buffer
;
1744 buf2
= Fget_buffer (buffer2
);
1747 bp2
= XBUFFER (buf2
);
1748 if (NILP (bp2
->name
))
1749 error ("Selecting deleted buffer");
1753 begp2
= BUF_BEGV (bp2
);
1756 CHECK_NUMBER_COERCE_MARKER (start2
, 4);
1757 begp2
= XINT (start2
);
1760 endp2
= BUF_ZV (bp2
);
1763 CHECK_NUMBER_COERCE_MARKER (end2
, 5);
1764 endp2
= XINT (end2
);
1768 temp
= begp2
, begp2
= endp2
, endp2
= temp
;
1770 if (!(BUF_BEGV (bp2
) <= begp2
1772 && endp2
<= BUF_ZV (bp2
)))
1773 args_out_of_range (start2
, end2
);
1777 i1_byte
= buf_charpos_to_bytepos (bp1
, i1
);
1778 i2_byte
= buf_charpos_to_bytepos (bp2
, i2
);
1780 while (i1
< endp1
&& i2
< endp2
)
1782 /* When we find a mismatch, we must compare the
1783 characters, not just the bytes. */
1786 if (! NILP (bp1
->enable_multibyte_characters
))
1788 c1
= BUF_FETCH_MULTIBYTE_CHAR (bp1
, i1_byte
);
1789 BUF_INC_POS (bp1
, i1_byte
);
1794 c1
= BUF_FETCH_BYTE (bp1
, i1
);
1795 c1
= unibyte_char_to_multibyte (c1
);
1799 if (! NILP (bp2
->enable_multibyte_characters
))
1801 c2
= BUF_FETCH_MULTIBYTE_CHAR (bp2
, i2_byte
);
1802 BUF_INC_POS (bp2
, i2_byte
);
1807 c2
= BUF_FETCH_BYTE (bp2
, i2
);
1808 c2
= unibyte_char_to_multibyte (c2
);
1814 c1
= XINT (trt
[c1
]);
1815 c2
= XINT (trt
[c2
]);
1818 return make_number (- 1 - chars
);
1820 return make_number (chars
+ 1);
1825 /* The strings match as far as they go.
1826 If one is shorter, that one is less. */
1827 if (chars
< endp1
- begp1
)
1828 return make_number (chars
+ 1);
1829 else if (chars
< endp2
- begp2
)
1830 return make_number (- chars
- 1);
1832 /* Same length too => they are equal. */
1833 return make_number (0);
1837 subst_char_in_region_unwind (arg
)
1840 return current_buffer
->undo_list
= arg
;
1844 subst_char_in_region_unwind_1 (arg
)
1847 return current_buffer
->filename
= arg
;
1850 DEFUN ("subst-char-in-region", Fsubst_char_in_region
,
1851 Ssubst_char_in_region
, 4, 5, 0,
1852 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\
1853 If optional arg NOUNDO is non-nil, don't record this change for undo\n\
1854 and don't mark the buffer as really changed.\n\
1855 Both characters must have the same length of multi-byte form.")
1856 (start
, end
, fromchar
, tochar
, noundo
)
1857 Lisp_Object start
, end
, fromchar
, tochar
, noundo
;
1859 register int pos
, pos_byte
, stop
, i
, len
, end_byte
;
1861 unsigned char fromwork
[4], *fromstr
, towork
[4], *tostr
, *p
;
1862 int count
= specpdl_ptr
- specpdl
;
1864 validate_region (&start
, &end
);
1865 CHECK_NUMBER (fromchar
, 2);
1866 CHECK_NUMBER (tochar
, 3);
1868 if (! NILP (current_buffer
->enable_multibyte_characters
))
1870 len
= CHAR_STRING (XFASTINT (fromchar
), fromwork
, fromstr
);
1871 if (CHAR_STRING (XFASTINT (tochar
), towork
, tostr
) != len
)
1872 error ("Characters in subst-char-in-region have different byte-lengths");
1877 fromwork
[0] = XFASTINT (fromchar
), fromstr
= fromwork
;
1878 towork
[0] = XFASTINT (tochar
), tostr
= towork
;
1882 pos_byte
= CHAR_TO_BYTE (pos
);
1883 stop
= CHAR_TO_BYTE (XINT (end
));
1886 /* If we don't want undo, turn off putting stuff on the list.
1887 That's faster than getting rid of things,
1888 and it prevents even the entry for a first change.
1889 Also inhibit locking the file. */
1892 record_unwind_protect (subst_char_in_region_unwind
,
1893 current_buffer
->undo_list
);
1894 current_buffer
->undo_list
= Qt
;
1895 /* Don't do file-locking. */
1896 record_unwind_protect (subst_char_in_region_unwind_1
,
1897 current_buffer
->filename
);
1898 current_buffer
->filename
= Qnil
;
1901 if (pos_byte
< GPT_BYTE
)
1902 stop
= min (stop
, GPT_BYTE
);
1905 if (pos_byte
>= stop
)
1907 if (pos_byte
>= end_byte
) break;
1910 p
= BYTE_POS_ADDR (pos_byte
);
1911 if (p
[0] == fromstr
[0]
1913 || (p
[1] == fromstr
[1]
1914 && (len
== 2 || (p
[2] == fromstr
[2]
1915 && (len
== 3 || p
[3] == fromstr
[3]))))))
1919 modify_region (current_buffer
, XINT (start
), XINT (end
));
1921 if (! NILP (noundo
))
1923 if (MODIFF
- 1 == SAVE_MODIFF
)
1925 if (MODIFF
- 1 == current_buffer
->auto_save_modified
)
1926 current_buffer
->auto_save_modified
++;
1933 record_change (pos
, 1);
1934 for (i
= 0; i
< len
; i
++) *p
++ = tostr
[i
];
1936 INC_BOTH (pos
, pos_byte
);
1940 signal_after_change (XINT (start
),
1941 XINT (end
) - XINT (start
), XINT (end
) - XINT (start
));
1943 unbind_to (count
, Qnil
);
1947 DEFUN ("translate-region", Ftranslate_region
, Stranslate_region
, 3, 3, 0,
1948 "From START to END, translate characters according to TABLE.\n\
1949 TABLE is a string; the Nth character in it is the mapping\n\
1950 for the character with code N.\n\
1951 This function does not alter multibyte characters.\n\
1952 It returns the number of characters changed.")
1956 register Lisp_Object table
;
1958 register int pos_byte
, stop
; /* Limits of the region. */
1959 register unsigned char *tt
; /* Trans table. */
1960 register int nc
; /* New character. */
1961 int cnt
; /* Number of changes made. */
1962 int size
; /* Size of translate table. */
1965 validate_region (&start
, &end
);
1966 CHECK_STRING (table
, 2);
1968 size
= STRING_BYTES (XSTRING (table
));
1969 tt
= XSTRING (table
)->data
;
1971 pos_byte
= CHAR_TO_BYTE (XINT (start
));
1972 stop
= CHAR_TO_BYTE (XINT (end
));
1973 modify_region (current_buffer
, XINT (start
), XINT (end
));
1977 for (; pos_byte
< stop
; )
1979 register unsigned char *p
= BYTE_POS_ADDR (pos_byte
);
1983 oc
= STRING_CHAR_AND_LENGTH (p
, stop
- pos_byte
, len
);
1984 if (oc
< size
&& len
== 1)
1989 record_change (pos
, 1);
1991 signal_after_change (pos
, 1, 1);
1999 return make_number (cnt
);
2002 DEFUN ("delete-region", Fdelete_region
, Sdelete_region
, 2, 2, "r",
2003 "Delete the text between point and mark.\n\
2004 When called from a program, expects two arguments,\n\
2005 positions (integers or markers) specifying the stretch to be deleted.")
2007 Lisp_Object start
, end
;
2009 validate_region (&start
, &end
);
2010 del_range (XINT (start
), XINT (end
));
2014 DEFUN ("widen", Fwiden
, Swiden
, 0, 0, "",
2015 "Remove restrictions (narrowing) from current buffer.\n\
2016 This allows the buffer's full text to be seen and edited.")
2019 if (BEG
!= BEGV
|| Z
!= ZV
)
2020 current_buffer
->clip_changed
= 1;
2022 BEGV_BYTE
= BEG_BYTE
;
2023 SET_BUF_ZV_BOTH (current_buffer
, Z
, Z_BYTE
);
2024 /* Changing the buffer bounds invalidates any recorded current column. */
2025 invalidate_current_column ();
2029 DEFUN ("narrow-to-region", Fnarrow_to_region
, Snarrow_to_region
, 2, 2, "r",
2030 "Restrict editing in this buffer to the current region.\n\
2031 The rest of the text becomes temporarily invisible and untouchable\n\
2032 but is not deleted; if you save the buffer in a file, the invisible\n\
2033 text is included in the file. \\[widen] makes all visible again.\n\
2034 See also `save-restriction'.\n\
2036 When calling from a program, pass two arguments; positions (integers\n\
2037 or markers) bounding the text that should remain visible.")
2039 register Lisp_Object start
, end
;
2041 CHECK_NUMBER_COERCE_MARKER (start
, 0);
2042 CHECK_NUMBER_COERCE_MARKER (end
, 1);
2044 if (XINT (start
) > XINT (end
))
2047 tem
= start
; start
= end
; end
= tem
;
2050 if (!(BEG
<= XINT (start
) && XINT (start
) <= XINT (end
) && XINT (end
) <= Z
))
2051 args_out_of_range (start
, end
);
2053 if (BEGV
!= XFASTINT (start
) || ZV
!= XFASTINT (end
))
2054 current_buffer
->clip_changed
= 1;
2056 SET_BUF_BEGV (current_buffer
, XFASTINT (start
));
2057 SET_BUF_ZV (current_buffer
, XFASTINT (end
));
2058 if (PT
< XFASTINT (start
))
2059 SET_PT (XFASTINT (start
));
2060 if (PT
> XFASTINT (end
))
2061 SET_PT (XFASTINT (end
));
2062 /* Changing the buffer bounds invalidates any recorded current column. */
2063 invalidate_current_column ();
2068 save_restriction_save ()
2070 register Lisp_Object bottom
, top
;
2071 /* Note: I tried using markers here, but it does not win
2072 because insertion at the end of the saved region
2073 does not advance mh and is considered "outside" the saved region. */
2074 XSETFASTINT (bottom
, BEGV
- BEG
);
2075 XSETFASTINT (top
, Z
- ZV
);
2077 return Fcons (Fcurrent_buffer (), Fcons (bottom
, top
));
2081 save_restriction_restore (data
)
2084 register struct buffer
*buf
;
2085 register int newhead
, newtail
;
2086 register Lisp_Object tem
;
2089 buf
= XBUFFER (XCONS (data
)->car
);
2091 data
= XCONS (data
)->cdr
;
2093 tem
= XCONS (data
)->car
;
2094 newhead
= XINT (tem
);
2095 tem
= XCONS (data
)->cdr
;
2096 newtail
= XINT (tem
);
2097 if (newhead
+ newtail
> BUF_Z (buf
) - BUF_BEG (buf
))
2103 obegv
= BUF_BEGV (buf
);
2106 SET_BUF_BEGV (buf
, BUF_BEG (buf
) + newhead
);
2107 SET_BUF_ZV (buf
, BUF_Z (buf
) - newtail
);
2109 if (obegv
!= BUF_BEGV (buf
) || ozv
!= BUF_ZV (buf
))
2110 current_buffer
->clip_changed
= 1;
2112 /* If point is outside the new visible range, move it inside. */
2113 SET_BUF_PT_BOTH (buf
,
2114 clip_to_bounds (BUF_BEGV (buf
), BUF_PT (buf
), BUF_ZV (buf
)),
2115 clip_to_bounds (BUF_BEGV_BYTE (buf
), BUF_PT_BYTE (buf
),
2116 BUF_ZV_BYTE (buf
)));
2121 DEFUN ("save-restriction", Fsave_restriction
, Ssave_restriction
, 0, UNEVALLED
, 0,
2122 "Execute BODY, saving and restoring current buffer's restrictions.\n\
2123 The buffer's restrictions make parts of the beginning and end invisible.\n\
2124 \(They are set up with `narrow-to-region' and eliminated with `widen'.)\n\
2125 This special form, `save-restriction', saves the current buffer's restrictions\n\
2126 when it is entered, and restores them when it is exited.\n\
2127 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\
2128 The old restrictions settings are restored\n\
2129 even in case of abnormal exit (throw or error).\n\
2131 The value returned is the value of the last form in BODY.\n\
2133 `save-restriction' can get confused if, within the BODY, you widen\n\
2134 and then make changes outside the area within the saved restrictions.\n\
2136 Note: if you are using both `save-excursion' and `save-restriction',\n\
2137 use `save-excursion' outermost:\n\
2138 (save-excursion (save-restriction ...))")
2142 register Lisp_Object val
;
2143 int count
= specpdl_ptr
- specpdl
;
2145 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
2146 val
= Fprogn (body
);
2147 return unbind_to (count
, val
);
2150 /* Buffer for the most recent text displayed by Fmessage. */
2151 static char *message_text
;
2153 /* Allocated length of that buffer. */
2154 static int message_length
;
2156 DEFUN ("message", Fmessage
, Smessage
, 1, MANY
, 0,
2157 "Print a one-line message at the bottom of the screen.\n\
2158 The first argument is a format control string, and the rest are data\n\
2159 to be formatted under control of the string. See `format' for details.\n\
2161 If the first argument is nil, clear any existing message; let the\n\
2162 minibuffer contents show.")
2174 register Lisp_Object val
;
2175 val
= Fformat (nargs
, args
);
2176 /* Copy the data so that it won't move when we GC. */
2179 message_text
= (char *)xmalloc (80);
2180 message_length
= 80;
2182 if (STRING_BYTES (XSTRING (val
)) > message_length
)
2184 message_length
= STRING_BYTES (XSTRING (val
));
2185 message_text
= (char *)xrealloc (message_text
, message_length
);
2187 bcopy (XSTRING (val
)->data
, message_text
, STRING_BYTES (XSTRING (val
)));
2188 message2 (message_text
, STRING_BYTES (XSTRING (val
)),
2189 STRING_MULTIBYTE (val
));
2194 DEFUN ("message-box", Fmessage_box
, Smessage_box
, 1, MANY
, 0,
2195 "Display a message, in a dialog box if possible.\n\
2196 If a dialog box is not available, use the echo area.\n\
2197 The first argument is a format control string, and the rest are data\n\
2198 to be formatted under control of the string. See `format' for details.\n\
2200 If the first argument is nil, clear any existing message; let the\n\
2201 minibuffer contents show.")
2213 register Lisp_Object val
;
2214 val
= Fformat (nargs
, args
);
2217 Lisp_Object pane
, menu
, obj
;
2218 struct gcpro gcpro1
;
2219 pane
= Fcons (Fcons (build_string ("OK"), Qt
), Qnil
);
2221 menu
= Fcons (val
, pane
);
2222 obj
= Fx_popup_dialog (Qt
, menu
);
2226 #else /* not HAVE_MENUS */
2227 /* Copy the data so that it won't move when we GC. */
2230 message_text
= (char *)xmalloc (80);
2231 message_length
= 80;
2233 if (STRING_BYTES (XSTRING (val
)) > message_length
)
2235 message_length
= STRING_BYTES (XSTRING (val
));
2236 message_text
= (char *)xrealloc (message_text
, message_length
);
2238 bcopy (XSTRING (val
)->data
, message_text
, STRING_BYTES (XSTRING (val
)));
2239 message2 (message_text
, STRING_BYTES (XSTRING (val
)),
2240 STRING_MULTIBYTE (val
));
2242 #endif /* not HAVE_MENUS */
2246 extern Lisp_Object last_nonmenu_event
;
2249 DEFUN ("message-or-box", Fmessage_or_box
, Smessage_or_box
, 1, MANY
, 0,
2250 "Display a message in a dialog box or in the echo area.\n\
2251 If this command was invoked with the mouse, use a dialog box.\n\
2252 Otherwise, use the echo area.\n\
2253 The first argument is a format control string, and the rest are data\n\
2254 to be formatted under control of the string. See `format' for details.\n\
2256 If the first argument is nil, clear any existing message; let the\n\
2257 minibuffer contents show.")
2263 if (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
2264 return Fmessage_box (nargs
, args
);
2266 return Fmessage (nargs
, args
);
2269 DEFUN ("current-message", Fcurrent_message
, Scurrent_message
, 0, 0, 0,
2270 "Return the string currently displayed in the echo area, or nil if none.")
2273 return (echo_area_glyphs
2274 ? make_string (echo_area_glyphs
, echo_area_glyphs_length
)
2278 /* Number of bytes that STRING will occupy when put into the result.
2279 MULTIBYTE is nonzero if the result should be multibyte. */
2281 #define CONVERTED_BYTE_SIZE(MULTIBYTE, STRING) \
2282 (((MULTIBYTE) && ! STRING_MULTIBYTE (STRING)) \
2283 ? count_size_as_multibyte (XSTRING (STRING)->data, \
2284 STRING_BYTES (XSTRING (STRING))) \
2285 : STRING_BYTES (XSTRING (STRING)))
2287 DEFUN ("format", Fformat
, Sformat
, 1, MANY
, 0,
2288 "Format a string out of a control-string and arguments.\n\
2289 The first argument is a control string.\n\
2290 The other arguments are substituted into it to make the result, a string.\n\
2291 It may contain %-sequences meaning to substitute the next argument.\n\
2292 %s means print a string argument. Actually, prints any object, with `princ'.\n\
2293 %d means print as number in decimal (%o octal, %x hex).\n\
2294 %e means print a number in exponential notation.\n\
2295 %f means print a number in decimal-point notation.\n\
2296 %g means print a number in exponential notation\n\
2297 or decimal-point notation, whichever uses fewer characters.\n\
2298 %c means print a number as a single character.\n\
2299 %S means print any object as an s-expression (using prin1).\n\
2300 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.\n\
2301 Use %% to put a single % into the output.")
2304 register Lisp_Object
*args
;
2306 register int n
; /* The number of the next arg to substitute */
2307 register int total
; /* An estimate of the final length */
2309 register unsigned char *format
, *end
;
2311 /* Nonzero if the output should be a multibyte string,
2312 which is true if any of the inputs is one. */
2314 unsigned char *this_format
;
2318 extern char *index ();
2320 /* It should not be necessary to GCPRO ARGS, because
2321 the caller in the interpreter should take care of that. */
2323 /* Try to determine whether the result should be multibyte.
2324 This is not always right; sometimes the result needs to be multibyte
2325 because of an object that we will pass through prin1,
2326 and in that case, we won't know it here. */
2327 for (n
= 0; n
< nargs
; n
++)
2328 if (STRINGP (args
[n
]) && STRING_MULTIBYTE (args
[n
]))
2331 CHECK_STRING (args
[0], 0);
2333 /* If we start out planning a unibyte result,
2334 and later find it has to be multibyte, we jump back to retry. */
2337 format
= XSTRING (args
[0])->data
;
2338 end
= format
+ STRING_BYTES (XSTRING (args
[0]));
2341 /* Make room in result for all the non-%-codes in the control string. */
2342 total
= 5 + CONVERTED_BYTE_SIZE (multibyte
, args
[0]);
2344 /* Add to TOTAL enough space to hold the converted arguments. */
2347 while (format
!= end
)
2348 if (*format
++ == '%')
2350 int minlen
, thissize
= 0;
2351 unsigned char *this_format_start
= format
- 1;
2353 /* Process a numeric arg and skip it. */
2354 minlen
= atoi (format
);
2358 while ((*format
>= '0' && *format
<= '9')
2359 || *format
== '-' || *format
== ' ' || *format
== '.')
2362 if (format
- this_format_start
+ 1 > longest_format
)
2363 longest_format
= format
- this_format_start
+ 1;
2367 else if (++n
>= nargs
)
2368 error ("Not enough arguments for format string");
2369 else if (*format
== 'S')
2371 /* For `S', prin1 the argument and then treat like a string. */
2372 register Lisp_Object tem
;
2373 tem
= Fprin1_to_string (args
[n
], Qnil
);
2374 if (STRING_MULTIBYTE (tem
) && ! multibyte
)
2382 else if (SYMBOLP (args
[n
]))
2384 XSETSTRING (args
[n
], XSYMBOL (args
[n
])->name
);
2385 if (STRING_MULTIBYTE (args
[n
]) && ! multibyte
)
2392 else if (STRINGP (args
[n
]))
2395 if (*format
!= 's' && *format
!= 'S')
2396 error ("format specifier doesn't match argument type");
2397 thissize
= CONVERTED_BYTE_SIZE (multibyte
, args
[n
]);
2399 /* Would get MPV otherwise, since Lisp_Int's `point' to low memory. */
2400 else if (INTEGERP (args
[n
]) && *format
!= 's')
2402 #ifdef LISP_FLOAT_TYPE
2403 /* The following loop assumes the Lisp type indicates
2404 the proper way to pass the argument.
2405 So make sure we have a flonum if the argument should
2407 if (*format
== 'e' || *format
== 'f' || *format
== 'g')
2408 args
[n
] = Ffloat (args
[n
]);
2412 && (! SINGLE_BYTE_CHAR_P (XINT (args
[n
]))
2413 || XINT (args
[n
]) == 0))
2420 args
[n
] = Fchar_to_string (args
[n
]);
2421 thissize
= STRING_BYTES (XSTRING (args
[n
]));
2424 #ifdef LISP_FLOAT_TYPE
2425 else if (FLOATP (args
[n
]) && *format
!= 's')
2427 if (! (*format
== 'e' || *format
== 'f' || *format
== 'g'))
2428 args
[n
] = Ftruncate (args
[n
], Qnil
);
2434 /* Anything but a string, convert to a string using princ. */
2435 register Lisp_Object tem
;
2436 tem
= Fprin1_to_string (args
[n
], Qt
);
2437 if (STRING_MULTIBYTE (tem
) & ! multibyte
)
2446 if (thissize
< minlen
)
2449 total
+= thissize
+ 4;
2452 /* Now we can no longer jump to retry.
2453 TOTAL and LONGEST_FORMAT are known for certain. */
2455 this_format
= (unsigned char *) alloca (longest_format
+ 1);
2457 /* Allocate the space for the result.
2458 Note that TOTAL is an overestimate. */
2460 buf
= (char *) alloca (total
+ 1);
2462 buf
= (char *) xmalloc (total
+ 1);
2468 /* Scan the format and store result in BUF. */
2469 format
= XSTRING (args
[0])->data
;
2470 while (format
!= end
)
2476 unsigned char *this_format_start
= format
;
2480 /* Process a numeric arg and skip it. */
2481 minlen
= atoi (format
);
2483 minlen
= - minlen
, negative
= 1;
2485 while ((*format
>= '0' && *format
<= '9')
2486 || *format
== '-' || *format
== ' ' || *format
== '.')
2489 if (*format
++ == '%')
2498 if (STRINGP (args
[n
]))
2500 int padding
, nbytes
;
2501 int width
= strwidth (XSTRING (args
[n
])->data
,
2502 STRING_BYTES (XSTRING (args
[n
])));
2504 /* If spec requires it, pad on right with spaces. */
2505 padding
= minlen
- width
;
2507 while (padding
-- > 0)
2513 nbytes
= copy_text (XSTRING (args
[n
])->data
, p
,
2514 STRING_BYTES (XSTRING (args
[n
])),
2515 STRING_MULTIBYTE (args
[n
]), multibyte
);
2517 nchars
+= XSTRING (args
[n
])->size
;
2520 while (padding
-- > 0)
2526 else if (INTEGERP (args
[n
]) || FLOATP (args
[n
]))
2530 bcopy (this_format_start
, this_format
,
2531 format
- this_format_start
);
2532 this_format
[format
- this_format_start
] = 0;
2534 if (INTEGERP (args
[n
]))
2535 sprintf (p
, this_format
, XINT (args
[n
]));
2537 sprintf (p
, this_format
, XFLOAT (args
[n
])->data
);
2539 this_nchars
= strlen (p
);
2541 nchars
+= this_nchars
;
2544 else if (STRING_MULTIBYTE (args
[0]))
2546 /* Copy a whole multibyte character. */
2548 while (! CHAR_HEAD_P (*format
)) *p
++ = *format
++;
2553 /* Convert a single-byte character to multibyte. */
2554 int len
= copy_text (format
, p
, 1, 0, 1);
2561 *p
++ = *format
++, nchars
++;
2564 val
= make_specified_string (buf
, nchars
, p
- buf
, multibyte
);
2566 /* If we allocated BUF with malloc, free it too. */
2576 format1 (string1
, arg0
, arg1
, arg2
, arg3
, arg4
)
2577 EMACS_INT arg0
, arg1
, arg2
, arg3
, arg4
;
2591 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, (char **) args
);
2593 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, &string1
+ 1);
2595 return build_string (buf
);
2598 DEFUN ("char-equal", Fchar_equal
, Schar_equal
, 2, 2, 0,
2599 "Return t if two characters match, optionally ignoring case.\n\
2600 Both arguments must be characters (i.e. integers).\n\
2601 Case is ignored if `case-fold-search' is non-nil in the current buffer.")
2603 register Lisp_Object c1
, c2
;
2606 CHECK_NUMBER (c1
, 0);
2607 CHECK_NUMBER (c2
, 1);
2609 if (XINT (c1
) == XINT (c2
))
2611 if (NILP (current_buffer
->case_fold_search
))
2614 /* Do these in separate statements,
2615 then compare the variables.
2616 because of the way DOWNCASE uses temp variables. */
2617 i1
= DOWNCASE (XFASTINT (c1
));
2618 i2
= DOWNCASE (XFASTINT (c2
));
2619 return (i1
== i2
? Qt
: Qnil
);
2622 /* Transpose the markers in two regions of the current buffer, and
2623 adjust the ones between them if necessary (i.e.: if the regions
2626 START1, END1 are the character positions of the first region.
2627 START1_BYTE, END1_BYTE are the byte positions.
2628 START2, END2 are the character positions of the second region.
2629 START2_BYTE, END2_BYTE are the byte positions.
2631 Traverses the entire marker list of the buffer to do so, adding an
2632 appropriate amount to some, subtracting from some, and leaving the
2633 rest untouched. Most of this is copied from adjust_markers in insdel.c.
2635 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
2638 transpose_markers (start1
, end1
, start2
, end2
,
2639 start1_byte
, end1_byte
, start2_byte
, end2_byte
)
2640 register int start1
, end1
, start2
, end2
;
2641 register int start1_byte
, end1_byte
, start2_byte
, end2_byte
;
2643 register int amt1
, amt1_byte
, amt2
, amt2_byte
, diff
, diff_byte
, mpos
;
2644 register Lisp_Object marker
;
2646 /* Update point as if it were a marker. */
2650 TEMP_SET_PT_BOTH (PT
+ (end2
- end1
),
2651 PT_BYTE
+ (end2_byte
- end1_byte
));
2652 else if (PT
< start2
)
2653 TEMP_SET_PT_BOTH (PT
+ (end2
- start2
) - (end1
- start1
),
2654 (PT_BYTE
+ (end2_byte
- start2_byte
)
2655 - (end1_byte
- start1_byte
)));
2657 TEMP_SET_PT_BOTH (PT
- (start2
- start1
),
2658 PT_BYTE
- (start2_byte
- start1_byte
));
2660 /* We used to adjust the endpoints here to account for the gap, but that
2661 isn't good enough. Even if we assume the caller has tried to move the
2662 gap out of our way, it might still be at start1 exactly, for example;
2663 and that places it `inside' the interval, for our purposes. The amount
2664 of adjustment is nontrivial if there's a `denormalized' marker whose
2665 position is between GPT and GPT + GAP_SIZE, so it's simpler to leave
2666 the dirty work to Fmarker_position, below. */
2668 /* The difference between the region's lengths */
2669 diff
= (end2
- start2
) - (end1
- start1
);
2670 diff_byte
= (end2_byte
- start2_byte
) - (end1_byte
- start1_byte
);
2672 /* For shifting each marker in a region by the length of the other
2673 region plus the distance between the regions. */
2674 amt1
= (end2
- start2
) + (start2
- end1
);
2675 amt2
= (end1
- start1
) + (start2
- end1
);
2676 amt1_byte
= (end2_byte
- start2_byte
) + (start2_byte
- end1_byte
);
2677 amt2_byte
= (end1_byte
- start1_byte
) + (start2_byte
- end1_byte
);
2679 for (marker
= BUF_MARKERS (current_buffer
); !NILP (marker
);
2680 marker
= XMARKER (marker
)->chain
)
2682 mpos
= marker_byte_position (marker
);
2683 if (mpos
>= start1_byte
&& mpos
< end2_byte
)
2685 if (mpos
< end1_byte
)
2687 else if (mpos
< start2_byte
)
2691 XMARKER (marker
)->bytepos
= mpos
;
2693 mpos
= XMARKER (marker
)->charpos
;
2694 if (mpos
>= start1
&& mpos
< end2
)
2698 else if (mpos
< start2
)
2703 XMARKER (marker
)->charpos
= mpos
;
2707 DEFUN ("transpose-regions", Ftranspose_regions
, Stranspose_regions
, 4, 5, 0,
2708 "Transpose region START1 to END1 with START2 to END2.\n\
2709 The regions may not be overlapping, because the size of the buffer is\n\
2710 never changed in a transposition.\n\
2712 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't update\n\
2713 any markers that happen to be located in the regions.\n\
2715 Transposing beyond buffer boundaries is an error.")
2716 (startr1
, endr1
, startr2
, endr2
, leave_markers
)
2717 Lisp_Object startr1
, endr1
, startr2
, endr2
, leave_markers
;
2719 register int start1
, end1
, start2
, end2
;
2720 int start1_byte
, start2_byte
, len1_byte
, len2_byte
;
2721 int gap
, len1
, len_mid
, len2
;
2722 unsigned char *start1_addr
, *start2_addr
, *temp
;
2723 int combined_before_bytes_1
, combined_after_bytes_1
;
2724 int combined_before_bytes_2
, combined_after_bytes_2
;
2725 struct gcpro gcpro1
, gcpro2
;
2727 #ifdef USE_TEXT_PROPERTIES
2728 INTERVAL cur_intv
, tmp_interval1
, tmp_interval_mid
, tmp_interval2
;
2729 cur_intv
= BUF_INTERVALS (current_buffer
);
2730 #endif /* USE_TEXT_PROPERTIES */
2732 validate_region (&startr1
, &endr1
);
2733 validate_region (&startr2
, &endr2
);
2735 start1
= XFASTINT (startr1
);
2736 end1
= XFASTINT (endr1
);
2737 start2
= XFASTINT (startr2
);
2738 end2
= XFASTINT (endr2
);
2741 /* Swap the regions if they're reversed. */
2744 register int glumph
= start1
;
2752 len1
= end1
- start1
;
2753 len2
= end2
- start2
;
2756 error ("Transposed regions overlap");
2757 else if (start1
== end1
|| start2
== end2
)
2758 error ("Transposed region has length 0");
2760 /* The possibilities are:
2761 1. Adjacent (contiguous) regions, or separate but equal regions
2762 (no, really equal, in this case!), or
2763 2. Separate regions of unequal size.
2765 The worst case is usually No. 2. It means that (aside from
2766 potential need for getting the gap out of the way), there also
2767 needs to be a shifting of the text between the two regions. So
2768 if they are spread far apart, we are that much slower... sigh. */
2770 /* It must be pointed out that the really studly thing to do would
2771 be not to move the gap at all, but to leave it in place and work
2772 around it if necessary. This would be extremely efficient,
2773 especially considering that people are likely to do
2774 transpositions near where they are working interactively, which
2775 is exactly where the gap would be found. However, such code
2776 would be much harder to write and to read. So, if you are
2777 reading this comment and are feeling squirrely, by all means have
2778 a go! I just didn't feel like doing it, so I will simply move
2779 the gap the minimum distance to get it out of the way, and then
2780 deal with an unbroken array. */
2782 /* Make sure the gap won't interfere, by moving it out of the text
2783 we will operate on. */
2784 if (start1
< gap
&& gap
< end2
)
2786 if (gap
- start1
< end2
- gap
)
2792 start1_byte
= CHAR_TO_BYTE (start1
);
2793 start2_byte
= CHAR_TO_BYTE (start2
);
2794 len1_byte
= CHAR_TO_BYTE (end1
) - start1_byte
;
2795 len2_byte
= CHAR_TO_BYTE (end2
) - start2_byte
;
2799 combined_before_bytes_2
2800 = count_combining_before (BYTE_POS_ADDR (start2_byte
),
2801 len2_byte
, start1
, start1_byte
);
2802 combined_before_bytes_1
2803 = count_combining_before (BYTE_POS_ADDR (start1_byte
),
2804 len1_byte
, end2
, start2_byte
+ len2_byte
);
2805 combined_after_bytes_1
2806 = count_combining_after (BYTE_POS_ADDR (start1_byte
),
2807 len1_byte
, end2
, start2_byte
+ len2_byte
);
2808 combined_after_bytes_2
= 0;
2812 combined_before_bytes_2
2813 = count_combining_before (BYTE_POS_ADDR (start2_byte
),
2814 len2_byte
, start1
, start1_byte
);
2815 combined_before_bytes_1
2816 = count_combining_before (BYTE_POS_ADDR (start1_byte
),
2817 len1_byte
, start2
, start2_byte
);
2818 combined_after_bytes_2
2819 = count_combining_after (BYTE_POS_ADDR (start2_byte
),
2820 len2_byte
, end1
, start1_byte
+ len1_byte
);
2821 combined_after_bytes_1
2822 = count_combining_after (BYTE_POS_ADDR (start1_byte
),
2823 len1_byte
, end2
, start2_byte
+ len2_byte
);
2826 /* If any combining is going to happen, do this the stupid way,
2827 because replace handles combining properly. */
2828 if (combined_before_bytes_1
|| combined_before_bytes_2
2829 || combined_after_bytes_1
|| combined_after_bytes_2
)
2831 Lisp_Object text1
, text2
;
2833 text1
= text2
= Qnil
;
2834 GCPRO2 (text1
, text2
);
2836 text1
= make_buffer_string_both (start1
, start1_byte
,
2837 end1
, start1_byte
+ len1_byte
, 1);
2838 text2
= make_buffer_string_both (start2
, start2_byte
,
2839 end2
, start2_byte
+ len2_byte
, 1);
2841 transpose_markers (start1
, end1
, start2
, end2
,
2842 start1_byte
, start1_byte
+ len1_byte
,
2843 start2_byte
, start2_byte
+ len2_byte
);
2845 replace_range (start2
, end2
, text1
, 1, 0, 1);
2846 replace_range (start1
, end1
, text2
, 1, 0, 1);
2852 /* Hmmm... how about checking to see if the gap is large
2853 enough to use as the temporary storage? That would avoid an
2854 allocation... interesting. Later, don't fool with it now. */
2856 /* Working without memmove, for portability (sigh), so must be
2857 careful of overlapping subsections of the array... */
2859 if (end1
== start2
) /* adjacent regions */
2861 modify_region (current_buffer
, start1
, end2
);
2862 record_change (start1
, len1
+ len2
);
2864 #ifdef USE_TEXT_PROPERTIES
2865 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2866 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2867 Fset_text_properties (make_number (start1
), make_number (end2
),
2869 #endif /* USE_TEXT_PROPERTIES */
2871 /* First region smaller than second. */
2872 if (len1_byte
< len2_byte
)
2874 /* We use alloca only if it is small,
2875 because we want to avoid stack overflow. */
2876 if (len2_byte
> 20000)
2877 temp
= (unsigned char *) xmalloc (len2_byte
);
2879 temp
= (unsigned char *) alloca (len2_byte
);
2881 /* Don't precompute these addresses. We have to compute them
2882 at the last minute, because the relocating allocator might
2883 have moved the buffer around during the xmalloc. */
2884 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2885 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2887 bcopy (start2_addr
, temp
, len2_byte
);
2888 bcopy (start1_addr
, start1_addr
+ len2_byte
, len1_byte
);
2889 bcopy (temp
, start1_addr
, len2_byte
);
2890 if (len2_byte
> 20000)
2894 /* First region not smaller than second. */
2896 if (len1_byte
> 20000)
2897 temp
= (unsigned char *) xmalloc (len1_byte
);
2899 temp
= (unsigned char *) alloca (len1_byte
);
2900 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2901 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2902 bcopy (start1_addr
, temp
, len1_byte
);
2903 bcopy (start2_addr
, start1_addr
, len2_byte
);
2904 bcopy (temp
, start1_addr
+ len2_byte
, len1_byte
);
2905 if (len1_byte
> 20000)
2908 #ifdef USE_TEXT_PROPERTIES
2909 graft_intervals_into_buffer (tmp_interval1
, start1
+ len2
,
2910 len1
, current_buffer
, 0);
2911 graft_intervals_into_buffer (tmp_interval2
, start1
,
2912 len2
, current_buffer
, 0);
2913 #endif /* USE_TEXT_PROPERTIES */
2915 /* Non-adjacent regions, because end1 != start2, bleagh... */
2918 len_mid
= start2_byte
- (start1_byte
+ len1_byte
);
2920 if (len1_byte
== len2_byte
)
2921 /* Regions are same size, though, how nice. */
2923 modify_region (current_buffer
, start1
, end1
);
2924 modify_region (current_buffer
, start2
, end2
);
2925 record_change (start1
, len1
);
2926 record_change (start2
, len2
);
2927 #ifdef USE_TEXT_PROPERTIES
2928 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2929 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2930 Fset_text_properties (make_number (start1
), make_number (end1
),
2932 Fset_text_properties (make_number (start2
), make_number (end2
),
2934 #endif /* USE_TEXT_PROPERTIES */
2936 if (len1_byte
> 20000)
2937 temp
= (unsigned char *) xmalloc (len1_byte
);
2939 temp
= (unsigned char *) alloca (len1_byte
);
2940 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2941 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2942 bcopy (start1_addr
, temp
, len1_byte
);
2943 bcopy (start2_addr
, start1_addr
, len2_byte
);
2944 bcopy (temp
, start2_addr
, len1_byte
);
2945 if (len1_byte
> 20000)
2947 #ifdef USE_TEXT_PROPERTIES
2948 graft_intervals_into_buffer (tmp_interval1
, start2
,
2949 len1
, current_buffer
, 0);
2950 graft_intervals_into_buffer (tmp_interval2
, start1
,
2951 len2
, current_buffer
, 0);
2952 #endif /* USE_TEXT_PROPERTIES */
2955 else if (len1_byte
< len2_byte
) /* Second region larger than first */
2956 /* Non-adjacent & unequal size, area between must also be shifted. */
2958 modify_region (current_buffer
, start1
, end2
);
2959 record_change (start1
, (end2
- start1
));
2960 #ifdef USE_TEXT_PROPERTIES
2961 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2962 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
2963 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2964 Fset_text_properties (make_number (start1
), make_number (end2
),
2966 #endif /* USE_TEXT_PROPERTIES */
2968 /* holds region 2 */
2969 if (len2_byte
> 20000)
2970 temp
= (unsigned char *) xmalloc (len2_byte
);
2972 temp
= (unsigned char *) alloca (len2_byte
);
2973 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
2974 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
2975 bcopy (start2_addr
, temp
, len2_byte
);
2976 bcopy (start1_addr
, start1_addr
+ len_mid
+ len2_byte
, len1_byte
);
2977 safe_bcopy (start1_addr
+ len1_byte
, start1_addr
+ len2_byte
, len_mid
);
2978 bcopy (temp
, start1_addr
, len2_byte
);
2979 if (len2_byte
> 20000)
2981 #ifdef USE_TEXT_PROPERTIES
2982 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
2983 len1
, current_buffer
, 0);
2984 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
2985 len_mid
, current_buffer
, 0);
2986 graft_intervals_into_buffer (tmp_interval2
, start1
,
2987 len2
, current_buffer
, 0);
2988 #endif /* USE_TEXT_PROPERTIES */
2991 /* Second region smaller than first. */
2993 record_change (start1
, (end2
- start1
));
2994 modify_region (current_buffer
, start1
, end2
);
2996 #ifdef USE_TEXT_PROPERTIES
2997 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2998 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
2999 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
3000 Fset_text_properties (make_number (start1
), make_number (end2
),
3002 #endif /* USE_TEXT_PROPERTIES */
3004 /* holds region 1 */
3005 if (len1_byte
> 20000)
3006 temp
= (unsigned char *) xmalloc (len1_byte
);
3008 temp
= (unsigned char *) alloca (len1_byte
);
3009 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1_byte
);
3010 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2_byte
);
3011 bcopy (start1_addr
, temp
, len1_byte
);
3012 bcopy (start2_addr
, start1_addr
, len2_byte
);
3013 bcopy (start1_addr
+ len1_byte
, start1_addr
+ len2_byte
, len_mid
);
3014 bcopy (temp
, start1_addr
+ len2_byte
+ len_mid
, len1_byte
);
3015 if (len1_byte
> 20000)
3017 #ifdef USE_TEXT_PROPERTIES
3018 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
3019 len1
, current_buffer
, 0);
3020 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
3021 len_mid
, current_buffer
, 0);
3022 graft_intervals_into_buffer (tmp_interval2
, start1
,
3023 len2
, current_buffer
, 0);
3024 #endif /* USE_TEXT_PROPERTIES */
3028 /* When doing multiple transpositions, it might be nice
3029 to optimize this. Perhaps the markers in any one buffer
3030 should be organized in some sorted data tree. */
3031 if (NILP (leave_markers
))
3033 transpose_markers (start1
, end1
, start2
, end2
,
3034 start1_byte
, start1_byte
+ len1_byte
,
3035 start2_byte
, start2_byte
+ len2_byte
);
3036 fix_overlays_in_range (start1
, end2
);
3048 Qbuffer_access_fontify_functions
3049 = intern ("buffer-access-fontify-functions");
3050 staticpro (&Qbuffer_access_fontify_functions
);
3052 DEFVAR_LISP ("buffer-access-fontify-functions",
3053 &Vbuffer_access_fontify_functions
,
3054 "List of functions called by `buffer-substring' to fontify if necessary.\n\
3055 Each function is called with two arguments which specify the range\n\
3056 of the buffer being accessed.");
3057 Vbuffer_access_fontify_functions
= Qnil
;
3061 extern Lisp_Object Vprin1_to_string_buffer
;
3062 obuf
= Fcurrent_buffer ();
3063 /* Do this here, because init_buffer_once is too early--it won't work. */
3064 Fset_buffer (Vprin1_to_string_buffer
);
3065 /* Make sure buffer-access-fontify-functions is nil in this buffer. */
3066 Fset (Fmake_local_variable (intern ("buffer-access-fontify-functions")),
3071 DEFVAR_LISP ("buffer-access-fontified-property",
3072 &Vbuffer_access_fontified_property
,
3073 "Property which (if non-nil) indicates text has been fontified.\n\
3074 `buffer-substring' need not call the `buffer-access-fontify-functions'\n\
3075 functions if all the text being accessed has this property.");
3076 Vbuffer_access_fontified_property
= Qnil
;
3078 DEFVAR_LISP ("system-name", &Vsystem_name
,
3079 "The name of the machine Emacs is running on.");
3081 DEFVAR_LISP ("user-full-name", &Vuser_full_name
,
3082 "The full name of the user logged in.");
3084 DEFVAR_LISP ("user-login-name", &Vuser_login_name
,
3085 "The user's name, taken from environment variables if possible.");
3087 DEFVAR_LISP ("user-real-login-name", &Vuser_real_login_name
,
3088 "The user's name, based upon the real uid only.");
3090 defsubr (&Schar_equal
);
3091 defsubr (&Sgoto_char
);
3092 defsubr (&Sstring_to_char
);
3093 defsubr (&Schar_to_string
);
3094 defsubr (&Sbuffer_substring
);
3095 defsubr (&Sbuffer_substring_no_properties
);
3096 defsubr (&Sbuffer_string
);
3098 defsubr (&Spoint_marker
);
3099 defsubr (&Smark_marker
);
3101 defsubr (&Sregion_beginning
);
3102 defsubr (&Sregion_end
);
3104 defsubr (&Sline_beginning_position
);
3105 defsubr (&Sline_end_position
);
3107 /* defsubr (&Smark); */
3108 /* defsubr (&Sset_mark); */
3109 defsubr (&Ssave_excursion
);
3110 defsubr (&Ssave_current_buffer
);
3112 defsubr (&Sbufsize
);
3113 defsubr (&Spoint_max
);
3114 defsubr (&Spoint_min
);
3115 defsubr (&Spoint_min_marker
);
3116 defsubr (&Spoint_max_marker
);
3117 defsubr (&Sgap_position
);
3118 defsubr (&Sgap_size
);
3119 defsubr (&Sposition_bytes
);
3125 defsubr (&Sfollowing_char
);
3126 defsubr (&Sprevious_char
);
3127 defsubr (&Schar_after
);
3128 defsubr (&Schar_before
);
3130 defsubr (&Sinsert_before_markers
);
3131 defsubr (&Sinsert_and_inherit
);
3132 defsubr (&Sinsert_and_inherit_before_markers
);
3133 defsubr (&Sinsert_char
);
3135 defsubr (&Suser_login_name
);
3136 defsubr (&Suser_real_login_name
);
3137 defsubr (&Suser_uid
);
3138 defsubr (&Suser_real_uid
);
3139 defsubr (&Suser_full_name
);
3140 defsubr (&Semacs_pid
);
3141 defsubr (&Scurrent_time
);
3142 defsubr (&Sformat_time_string
);
3143 defsubr (&Sdecode_time
);
3144 defsubr (&Sencode_time
);
3145 defsubr (&Scurrent_time_string
);
3146 defsubr (&Scurrent_time_zone
);
3147 defsubr (&Sset_time_zone_rule
);
3148 defsubr (&Ssystem_name
);
3149 defsubr (&Smessage
);
3150 defsubr (&Smessage_box
);
3151 defsubr (&Smessage_or_box
);
3152 defsubr (&Scurrent_message
);
3155 defsubr (&Sinsert_buffer_substring
);
3156 defsubr (&Scompare_buffer_substrings
);
3157 defsubr (&Ssubst_char_in_region
);
3158 defsubr (&Stranslate_region
);
3159 defsubr (&Sdelete_region
);
3161 defsubr (&Snarrow_to_region
);
3162 defsubr (&Ssave_restriction
);
3163 defsubr (&Stranspose_regions
);