1 /* Lisp functions pertaining to editing.
2 Copyright (C) 1985,86,87,89,93,94,95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <sys/types.h>
33 #include "intervals.h"
39 #define min(a, b) ((a) < (b) ? (a) : (b))
40 #define max(a, b) ((a) > (b) ? (a) : (b))
42 extern char **environ
;
43 extern Lisp_Object
make_time ();
44 extern void insert_from_buffer ();
45 static long difftm ();
46 static void update_buffer_properties ();
47 void set_time_zone_rule ();
49 Lisp_Object Vbuffer_access_fontify_functions
;
50 Lisp_Object Qbuffer_access_fontify_functions
;
51 Lisp_Object Vbuffer_access_fontified_property
;
53 /* Some static data, and a function to initialize it for each run */
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 */
64 register unsigned char *p
, *q
, *r
;
65 struct passwd
*pw
; /* password entry for the current user */
66 extern char *index ();
69 /* Set up system_name even when dumping. */
73 /* Don't bother with this on initial start when just dumping out */
76 #endif /* not CANNOT_DUMP */
78 pw
= (struct passwd
*) getpwuid (getuid ());
80 /* We let the real user name default to "root" because that's quite
81 accurate on MSDOG and because it lets Emacs find the init file.
82 (The DVX libraries override the Djgpp libraries here.) */
83 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "root");
85 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "unknown");
88 /* Get the effective user name, by consulting environment variables,
89 or the effective uid if those are unset. */
90 user_name
= (char *) getenv ("LOGNAME");
93 user_name
= (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
95 user_name
= (char *) getenv ("USER");
96 #endif /* WINDOWSNT */
99 pw
= (struct passwd
*) getpwuid (geteuid ());
100 user_name
= (char *) (pw
? pw
->pw_name
: "unknown");
102 Vuser_login_name
= build_string (user_name
);
104 /* If the user name claimed in the environment vars differs from
105 the real uid, use the claimed name to find the full name. */
106 tem
= Fstring_equal (Vuser_login_name
, Vuser_real_login_name
);
108 pw
= (struct passwd
*) getpwnam (XSTRING (Vuser_login_name
)->data
);
110 p
= (unsigned char *) (pw
? USER_FULL_NAME
: "unknown");
111 q
= (unsigned char *) index (p
, ',');
112 Vuser_full_name
= make_string (p
, q
? q
- p
: strlen (p
));
114 #ifdef AMPERSAND_FULL_NAME
115 p
= XSTRING (Vuser_full_name
)->data
;
116 q
= (unsigned char *) index (p
, '&');
117 /* Substitute the login name for the &, upcasing the first character. */
120 r
= (unsigned char *) alloca (strlen (p
)
121 + XSTRING (Vuser_login_name
)->size
+ 1);
124 strcat (r
, XSTRING (Vuser_login_name
)->data
);
125 r
[q
- p
] = UPCASE (r
[q
- p
]);
127 Vuser_full_name
= build_string (r
);
129 #endif /* AMPERSAND_FULL_NAME */
131 p
= (unsigned char *) getenv ("NAME");
133 Vuser_full_name
= build_string (p
);
136 DEFUN ("char-to-string", Fchar_to_string
, Schar_to_string
, 1, 1, 0,
137 "Convert arg CHARACTER to a one-character string containing that character.")
139 Lisp_Object character
;
142 CHECK_NUMBER (character
, 0);
144 c
= XINT (character
);
145 return make_string (&c
, 1);
148 DEFUN ("string-to-char", Fstring_to_char
, Sstring_to_char
, 1, 1, 0,
149 "Convert arg STRING to a character, the first character of that string.")
151 register Lisp_Object string
;
153 register Lisp_Object val
;
154 register struct Lisp_String
*p
;
155 CHECK_STRING (string
, 0);
157 p
= XSTRING (string
);
159 XSETFASTINT (val
, ((unsigned char *) p
->data
)[0]);
161 XSETFASTINT (val
, 0);
169 register Lisp_Object mark
;
170 mark
= Fmake_marker ();
171 Fset_marker (mark
, make_number (val
), Qnil
);
175 DEFUN ("point", Fpoint
, Spoint
, 0, 0, 0,
176 "Return value of point, as an integer.\n\
177 Beginning of buffer is position (point-min)")
181 XSETFASTINT (temp
, PT
);
185 DEFUN ("point-marker", Fpoint_marker
, Spoint_marker
, 0, 0, 0,
186 "Return value of point, as a marker object.")
189 return buildmark (PT
);
193 clip_to_bounds (lower
, num
, upper
)
194 int lower
, num
, upper
;
198 else if (num
> upper
)
204 DEFUN ("goto-char", Fgoto_char
, Sgoto_char
, 1, 1, "NGoto char: ",
205 "Set point to POSITION, a number or marker.\n\
206 Beginning of buffer is position (point-min), end is (point-max).")
208 register Lisp_Object position
;
210 CHECK_NUMBER_COERCE_MARKER (position
, 0);
212 SET_PT (clip_to_bounds (BEGV
, XINT (position
), ZV
));
217 region_limit (beginningp
)
220 extern Lisp_Object Vmark_even_if_inactive
; /* Defined in callint.c. */
221 register Lisp_Object m
;
222 if (!NILP (Vtransient_mark_mode
) && NILP (Vmark_even_if_inactive
)
223 && NILP (current_buffer
->mark_active
))
224 Fsignal (Qmark_inactive
, Qnil
);
225 m
= Fmarker_position (current_buffer
->mark
);
226 if (NILP (m
)) error ("There is no region now");
227 if ((PT
< XFASTINT (m
)) == beginningp
)
228 return (make_number (PT
));
233 DEFUN ("region-beginning", Fregion_beginning
, Sregion_beginning
, 0, 0, 0,
234 "Return position of beginning of region, as an integer.")
237 return (region_limit (1));
240 DEFUN ("region-end", Fregion_end
, Sregion_end
, 0, 0, 0,
241 "Return position of end of region, as an integer.")
244 return (region_limit (0));
247 DEFUN ("mark-marker", Fmark_marker
, Smark_marker
, 0, 0, 0,
248 "Return this buffer's mark, as a marker object.\n\
249 Watch out! Moving this marker changes the mark position.\n\
250 If you set the marker not to point anywhere, the buffer will have no mark.")
253 return current_buffer
->mark
;
257 save_excursion_save ()
259 register int visible
= (XBUFFER (XWINDOW (selected_window
)->buffer
)
262 return Fcons (Fpoint_marker (),
263 Fcons (Fcopy_marker (current_buffer
->mark
, Qnil
),
264 Fcons (visible
? Qt
: Qnil
,
265 current_buffer
->mark_active
)));
269 save_excursion_restore (info
)
272 Lisp_Object tem
, tem1
, omark
, nmark
;
273 struct gcpro gcpro1
, gcpro2
, gcpro3
;
275 tem
= Fmarker_buffer (Fcar (info
));
276 /* If buffer being returned to is now deleted, avoid error */
277 /* Otherwise could get error here while unwinding to top level
279 /* In that case, Fmarker_buffer returns nil now. */
283 omark
= nmark
= Qnil
;
284 GCPRO3 (info
, omark
, nmark
);
289 unchain_marker (tem
);
290 tem
= Fcar (Fcdr (info
));
291 omark
= Fmarker_position (current_buffer
->mark
);
292 Fset_marker (current_buffer
->mark
, tem
, Fcurrent_buffer ());
293 nmark
= Fmarker_position (tem
);
294 unchain_marker (tem
);
295 tem
= Fcdr (Fcdr (info
));
296 #if 0 /* We used to make the current buffer visible in the selected window
297 if that was true previously. That avoids some anomalies.
298 But it creates others, and it wasn't documented, and it is simpler
299 and cleaner never to alter the window/buffer connections. */
302 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
303 Fswitch_to_buffer (Fcurrent_buffer (), Qnil
);
306 tem1
= current_buffer
->mark_active
;
307 current_buffer
->mark_active
= Fcdr (tem
);
308 if (!NILP (Vrun_hooks
))
310 /* If mark is active now, and either was not active
311 or was at a different place, run the activate hook. */
312 if (! NILP (current_buffer
->mark_active
))
314 if (! EQ (omark
, nmark
))
315 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
317 /* If mark has ceased to be active, run deactivate hook. */
318 else if (! NILP (tem1
))
319 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
325 DEFUN ("save-excursion", Fsave_excursion
, Ssave_excursion
, 0, UNEVALLED
, 0,
326 "Save point, mark, and current buffer; execute BODY; restore those things.\n\
327 Executes BODY just like `progn'.\n\
328 The values of point, mark and the current buffer are restored\n\
329 even in case of abnormal exit (throw or error).\n\
330 The state of activation of the mark is also restored.")
334 register Lisp_Object val
;
335 int count
= specpdl_ptr
- specpdl
;
337 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
340 return unbind_to (count
, val
);
343 DEFUN ("buffer-size", Fbufsize
, Sbufsize
, 0, 0, 0,
344 "Return the number of characters in the current buffer.")
348 XSETFASTINT (temp
, Z
- BEG
);
352 DEFUN ("point-min", Fpoint_min
, Spoint_min
, 0, 0, 0,
353 "Return the minimum permissible value of point in the current buffer.\n\
354 This is 1, unless narrowing (a buffer restriction) is in effect.")
358 XSETFASTINT (temp
, BEGV
);
362 DEFUN ("point-min-marker", Fpoint_min_marker
, Spoint_min_marker
, 0, 0, 0,
363 "Return a marker to the minimum permissible value of point in this buffer.\n\
364 This is the beginning, unless narrowing (a buffer restriction) is in effect.")
367 return buildmark (BEGV
);
370 DEFUN ("point-max", Fpoint_max
, Spoint_max
, 0, 0, 0,
371 "Return the maximum permissible value of point in the current buffer.\n\
372 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
373 is in effect, in which case it is less.")
377 XSETFASTINT (temp
, ZV
);
381 DEFUN ("point-max-marker", Fpoint_max_marker
, Spoint_max_marker
, 0, 0, 0,
382 "Return a marker to the maximum permissible value of point in this buffer.\n\
383 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)\n\
384 is in effect, in which case it is less.")
387 return buildmark (ZV
);
390 DEFUN ("following-char", Ffollowing_char
, Sfollowing_char
, 0, 0, 0,
391 "Return the character following point, as a number.\n\
392 At the end of the buffer or accessible region, return 0.")
397 XSETFASTINT (temp
, 0);
399 XSETFASTINT (temp
, FETCH_CHAR (PT
));
403 DEFUN ("preceding-char", Fprevious_char
, Sprevious_char
, 0, 0, 0,
404 "Return the character preceding point, as a number.\n\
405 At the beginning of the buffer or accessible region, return 0.")
410 XSETFASTINT (temp
, 0);
412 XSETFASTINT (temp
, FETCH_CHAR (PT
- 1));
416 DEFUN ("bobp", Fbobp
, Sbobp
, 0, 0, 0,
417 "Return T if point is at the beginning of the buffer.\n\
418 If the buffer is narrowed, this means the beginning of the narrowed part.")
426 DEFUN ("eobp", Feobp
, Seobp
, 0, 0, 0,
427 "Return T if point is at the end of the buffer.\n\
428 If the buffer is narrowed, this means the end of the narrowed part.")
436 DEFUN ("bolp", Fbolp
, Sbolp
, 0, 0, 0,
437 "Return T if point is at the beginning of a line.")
440 if (PT
== BEGV
|| FETCH_CHAR (PT
- 1) == '\n')
445 DEFUN ("eolp", Feolp
, Seolp
, 0, 0, 0,
446 "Return T if point is at the end of a line.\n\
447 `End of a line' includes point being at the end of the buffer.")
450 if (PT
== ZV
|| FETCH_CHAR (PT
) == '\n')
455 DEFUN ("char-after", Fchar_after
, Schar_after
, 1, 1, 0,
456 "Return character in current buffer at position POS.\n\
457 POS is an integer or a buffer pointer.\n\
458 If POS is out of range, the value is nil.")
462 register Lisp_Object val
;
465 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
468 if (n
< BEGV
|| n
>= ZV
) return Qnil
;
470 XSETFASTINT (val
, FETCH_CHAR (n
));
474 DEFUN ("user-login-name", Fuser_login_name
, Suser_login_name
, 0, 1, 0,
475 "Return the name under which the user logged in, as a string.\n\
476 This is based on the effective uid, not the real uid.\n\
477 Also, if the environment variable LOGNAME or USER is set,\n\
478 that determines the value of this function.\n\n\
479 If optional argument UID is an integer, return the login name of the user\n\
480 with that uid, or nil if there is no such user.")
486 /* Set up the user name info if we didn't do it before.
487 (That can happen if Emacs is dumpable
488 but you decide to run `temacs -l loadup' and not dump. */
489 if (INTEGERP (Vuser_login_name
))
493 return Vuser_login_name
;
495 CHECK_NUMBER (uid
, 0);
496 pw
= (struct passwd
*) getpwuid (XINT (uid
));
497 return (pw
? build_string (pw
->pw_name
) : Qnil
);
500 DEFUN ("user-real-login-name", Fuser_real_login_name
, Suser_real_login_name
,
502 "Return the name of the user's real uid, as a string.\n\
503 This ignores the environment variables LOGNAME and USER, so it differs from\n\
504 `user-login-name' when running under `su'.")
507 /* Set up the user name info if we didn't do it before.
508 (That can happen if Emacs is dumpable
509 but you decide to run `temacs -l loadup' and not dump. */
510 if (INTEGERP (Vuser_login_name
))
512 return Vuser_real_login_name
;
515 DEFUN ("user-uid", Fuser_uid
, Suser_uid
, 0, 0, 0,
516 "Return the effective uid of Emacs, as an integer.")
519 return make_number (geteuid ());
522 DEFUN ("user-real-uid", Fuser_real_uid
, Suser_real_uid
, 0, 0, 0,
523 "Return the real uid of Emacs, as an integer.")
526 return make_number (getuid ());
529 DEFUN ("user-full-name", Fuser_full_name
, Suser_full_name
, 0, 0, 0,
530 "Return the full name of the user logged in, as a string.")
533 return Vuser_full_name
;
536 DEFUN ("system-name", Fsystem_name
, Ssystem_name
, 0, 0, 0,
537 "Return the name of the machine you are running on, as a string.")
543 /* For the benefit of callers who don't want to include lisp.h */
547 return (char *) XSTRING (Vsystem_name
)->data
;
550 DEFUN ("emacs-pid", Femacs_pid
, Semacs_pid
, 0, 0, 0,
551 "Return the process ID of Emacs, as an integer.")
554 return make_number (getpid ());
557 DEFUN ("current-time", Fcurrent_time
, Scurrent_time
, 0, 0, 0,
558 "Return the current time, as the number of seconds since 1970-01-01 00:00:00.\n\
559 The time is returned as a list of three integers. The first has the\n\
560 most significant 16 bits of the seconds, while the second has the\n\
561 least significant 16 bits. The third integer gives the microsecond\n\
564 The microsecond count is zero on systems that do not provide\n\
565 resolution finer than a second.")
569 Lisp_Object result
[3];
572 XSETINT (result
[0], (EMACS_SECS (t
) >> 16) & 0xffff);
573 XSETINT (result
[1], (EMACS_SECS (t
) >> 0) & 0xffff);
574 XSETINT (result
[2], EMACS_USECS (t
));
576 return Flist (3, result
);
581 lisp_time_argument (specified_time
, result
)
582 Lisp_Object specified_time
;
585 if (NILP (specified_time
))
586 return time (result
) != -1;
589 Lisp_Object high
, low
;
590 high
= Fcar (specified_time
);
591 CHECK_NUMBER (high
, 0);
592 low
= Fcdr (specified_time
);
595 CHECK_NUMBER (low
, 0);
596 *result
= (XINT (high
) << 16) + (XINT (low
) & 0xffff);
597 return *result
>> 16 == XINT (high
);
601 DEFUN ("format-time-string", Fformat_time_string
, Sformat_time_string
, 1, 2, 0,
602 "Use FORMAT-STRING to format the time TIME.\n\
603 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as from\n\
604 `current-time' and `file-attributes'.\n\
605 FORMAT-STRING may contain %-sequences to substitute parts of the time.\n\
606 %a is replaced by the abbreviated name of the day of week.\n\
607 %A is replaced by the full name of the day of week.\n\
608 %b is replaced by the abbreviated name of the month.\n\
609 %B is replaced by the full name of the month.\n\
610 %c stands for the preferred date/time format of the C locale.\n\
611 %d is replaced by the day of month, zero-padded.\n\
612 %D is a synonym for \"%m/%d/%y\".\n\
613 %e is replaced by the day of month, blank-padded.\n\
614 %h is a synonym for \"%b\".\n\
615 %H is replaced by the hour (00-23).\n\
616 %I is replaced by the hour (00-12).\n\
617 %j is replaced by the day of the year (001-366).\n\
618 %k is replaced by the hour (0-23), blank padded.\n\
619 %l is replaced by the hour (1-12), blank padded.\n\
620 %m is replaced by the month (01-12).\n\
621 %M is replaced by the minute (00-59).\n\
622 %n is a synonym for \"\\n\".\n\
623 %p is replaced by AM or PM, as appropriate.\n\
624 %r is a synonym for \"%I:%M:%S %p\".\n\
625 %R is a synonym for \"%H:%M\".\n\
626 %S is replaced by the second (00-60).\n\
627 %t is a synonym for \"\\t\".\n\
628 %T is a synonym for \"%H:%M:%S\".\n\
629 %U is replaced by the week of the year (00-53), first day of week is Sunday.\n\
630 %w is replaced by the day of week (0-6), Sunday is day 0.\n\
631 %W is replaced by the week of the year (00-53), first day of week is Monday.\n\
632 %x is a locale-specific synonym, which defaults to \"%D\" in the C locale.\n\
633 %X is a locale-specific synonym, which defaults to \"%T\" in the C locale.\n\
634 %y is replaced by the year without century (00-99).\n\
635 %Y is replaced by the year with century.\n\
636 %Z is replaced by the time zone abbreviation.\n\
638 The number of options reflects the `strftime' function.")
639 (format_string
, time
)
640 Lisp_Object format_string
, time
;
645 CHECK_STRING (format_string
, 1);
647 if (! lisp_time_argument (time
, &value
))
648 error ("Invalid time specification");
650 /* This is probably enough. */
651 size
= XSTRING (format_string
)->size
* 6 + 50;
655 char *buf
= (char *) alloca (size
);
657 if (emacs_strftime (buf
, size
, XSTRING (format_string
)->data
,
660 return build_string (buf
);
661 /* If buffer was too small, make it bigger. */
666 DEFUN ("decode-time", Fdecode_time
, Sdecode_time
, 0, 1, 0,
667 "Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).\n\
668 The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)\n\
669 or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'\n\
670 to use the current time. The list has the following nine members:\n\
671 SEC is an integer between 0 and 60; SEC is 60 for a leap second, which\n\
672 only some operating systems support. MINUTE is an integer between 0 and 59.\n\
673 HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.\n\
674 MONTH is an integer between 1 and 12. YEAR is an integer indicating the\n\
675 four-digit year. DOW is the day of week, an integer between 0 and 6, where\n\
676 0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.\n\
677 ZONE is an integer indicating the number of seconds east of Greenwich.\n\
678 \(Note that Common Lisp has different meanings for DOW and ZONE.)")
680 Lisp_Object specified_time
;
684 struct tm
*decoded_time
;
685 Lisp_Object list_args
[9];
687 if (! lisp_time_argument (specified_time
, &time_spec
))
688 error ("Invalid time specification");
690 decoded_time
= localtime (&time_spec
);
691 XSETFASTINT (list_args
[0], decoded_time
->tm_sec
);
692 XSETFASTINT (list_args
[1], decoded_time
->tm_min
);
693 XSETFASTINT (list_args
[2], decoded_time
->tm_hour
);
694 XSETFASTINT (list_args
[3], decoded_time
->tm_mday
);
695 XSETFASTINT (list_args
[4], decoded_time
->tm_mon
+ 1);
696 XSETINT (list_args
[5], decoded_time
->tm_year
+ 1900);
697 XSETFASTINT (list_args
[6], decoded_time
->tm_wday
);
698 list_args
[7] = (decoded_time
->tm_isdst
)? Qt
: Qnil
;
700 /* Make a copy, in case gmtime modifies the struct. */
701 save_tm
= *decoded_time
;
702 decoded_time
= gmtime (&time_spec
);
703 if (decoded_time
== 0)
706 XSETINT (list_args
[8], difftm (&save_tm
, decoded_time
));
707 return Flist (9, list_args
);
710 DEFUN ("encode-time", Fencode_time
, Sencode_time
, 6, MANY
, 0,
711 "Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.\n\
712 This is the reverse operation of `decode-time', which see.\n\
713 ZONE defaults to the current time zone rule. This can\n\
714 be a string or t (as from `set-time-zone-rule'), or it can be a list\n\
715 (as from `current-time-zone') or an integer (as from `decode-time')\n\
716 applied without consideration for daylight savings time.\n\
718 You can pass more than 7 arguments; then the first six arguments\n\
719 are used as SECOND through YEAR, and the *last* argument is used as ZONE.\n\
720 The intervening arguments are ignored.\n\
721 This feature lets (apply 'encode-time (decode-time ...)) work.\n\
723 Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;\n\
724 for example, a DAY of 0 means the day preceding the given month.\n\
725 Year numbers less than 100 are treated just like other year numbers.\n\
726 If you want them to stand for years in this century, you must do that yourself.")
729 register Lisp_Object
*args
;
733 Lisp_Object zone
= (nargs
> 6)? args
[nargs
- 1] : Qnil
;
735 CHECK_NUMBER (args
[0], 0); /* second */
736 CHECK_NUMBER (args
[1], 1); /* minute */
737 CHECK_NUMBER (args
[2], 2); /* hour */
738 CHECK_NUMBER (args
[3], 3); /* day */
739 CHECK_NUMBER (args
[4], 4); /* month */
740 CHECK_NUMBER (args
[5], 5); /* year */
742 tm
.tm_sec
= XINT (args
[0]);
743 tm
.tm_min
= XINT (args
[1]);
744 tm
.tm_hour
= XINT (args
[2]);
745 tm
.tm_mday
= XINT (args
[3]);
746 tm
.tm_mon
= XINT (args
[4]) - 1;
747 tm
.tm_year
= XINT (args
[5]) - 1900;
758 char **oldenv
= environ
, **newenv
;
762 else if (STRINGP (zone
))
763 tzstring
= (char *) XSTRING (zone
)->data
;
764 else if (INTEGERP (zone
))
766 int abszone
= abs (XINT (zone
));
767 sprintf (tzbuf
, "XXX%s%d:%02d:%02d", "-" + (XINT (zone
) < 0),
768 abszone
/ (60*60), (abszone
/60) % 60, abszone
% 60);
772 error ("Invalid time zone specification");
774 /* Set TZ before calling mktime; merely adjusting mktime's returned
775 value doesn't suffice, since that would mishandle leap seconds. */
776 set_time_zone_rule (tzstring
);
780 /* Restore TZ to previous value. */
784 #ifdef LOCALTIME_CACHE
789 if (time
== (time_t) -1)
790 error ("Specified time is not representable");
792 return make_time (time
);
795 DEFUN ("current-time-string", Fcurrent_time_string
, Scurrent_time_string
, 0, 1, 0,
796 "Return the current time, as a human-readable string.\n\
797 Programs can use this function to decode a time,\n\
798 since the number of columns in each field is fixed.\n\
799 The format is `Sun Sep 16 01:03:52 1973'.\n\
800 If an argument is given, it specifies a time to format\n\
801 instead of the current time. The argument should have the form:\n\
804 (HIGH LOW . IGNORED).\n\
805 Thus, you can use times obtained from `current-time'\n\
806 and from `file-attributes'.")
808 Lisp_Object specified_time
;
814 if (! lisp_time_argument (specified_time
, &value
))
816 tem
= (char *) ctime (&value
);
818 strncpy (buf
, tem
, 24);
821 return build_string (buf
);
824 #define TM_YEAR_ORIGIN 1900
826 /* Yield A - B, measured in seconds. */
831 int ay
= a
->tm_year
+ (TM_YEAR_ORIGIN
- 1);
832 int by
= b
->tm_year
+ (TM_YEAR_ORIGIN
- 1);
833 /* Divide years by 100, rounding towards minus infinity. */
834 int ac
= ay
/ 100 - (ay
% 100 < 0);
835 int bc
= by
/ 100 - (by
% 100 < 0);
836 /* Some compilers can't handle this as a single return statement. */
838 /* difference in day of year */
839 a
->tm_yday
- b
->tm_yday
840 /* + intervening leap days */
841 + ((ay
>> 2) - (by
>> 2))
843 + ((ac
>> 2) - (bc
>> 2))
844 /* + difference in years * 365 */
845 + (long)(ay
-by
) * 365
847 return (60*(60*(24*days
+ (a
->tm_hour
- b
->tm_hour
))
848 + (a
->tm_min
- b
->tm_min
))
849 + (a
->tm_sec
- b
->tm_sec
));
852 DEFUN ("current-time-zone", Fcurrent_time_zone
, Scurrent_time_zone
, 0, 1, 0,
853 "Return the offset and name for the local time zone.\n\
854 This returns a list of the form (OFFSET NAME).\n\
855 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).\n\
856 A negative value means west of Greenwich.\n\
857 NAME is a string giving the name of the time zone.\n\
858 If an argument is given, it specifies when the time zone offset is determined\n\
859 instead of using the current time. The argument should have the form:\n\
862 (HIGH LOW . IGNORED).\n\
863 Thus, you can use times obtained from `current-time'\n\
864 and from `file-attributes'.\n\
866 Some operating systems cannot provide all this information to Emacs;\n\
867 in this case, `current-time-zone' returns a list containing nil for\n\
868 the data it can't find.")
870 Lisp_Object specified_time
;
875 if (lisp_time_argument (specified_time
, &value
)
876 && (t
= gmtime (&value
)) != 0)
882 gmt
= *t
; /* Make a copy, in case localtime modifies *t. */
883 t
= localtime (&value
);
884 offset
= difftm (t
, &gmt
);
888 s
= (char *)t
->tm_zone
;
889 #else /* not HAVE_TM_ZONE */
891 if (t
->tm_isdst
== 0 || t
->tm_isdst
== 1)
892 s
= tzname
[t
->tm_isdst
];
894 #endif /* not HAVE_TM_ZONE */
897 /* No local time zone name is available; use "+-NNNN" instead. */
898 int am
= (offset
< 0 ? -offset
: offset
) / 60;
899 sprintf (buf
, "%c%02d%02d", (offset
< 0 ? '-' : '+'), am
/60, am
%60);
902 return Fcons (make_number (offset
), Fcons (build_string (s
), Qnil
));
905 return Fmake_list (2, Qnil
);
908 /* This holds the value of `environ' produced by the previous
909 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
910 has never been called. */
911 static char **environbuf
;
913 DEFUN ("set-time-zone-rule", Fset_time_zone_rule
, Sset_time_zone_rule
, 1, 1, 0,
914 "Set the local time zone using TZ, a string specifying a time zone rule.\n\
915 If TZ is nil, use implementation-defined default time zone information.\n\
916 If TZ is t, use Universal Time.")
928 CHECK_STRING (tz
, 0);
929 tzstring
= (char *) XSTRING (tz
)->data
;
932 set_time_zone_rule (tzstring
);
935 environbuf
= environ
;
940 /* These two values are known to load tz files in buggy implementations.
941 Their values shouldn't matter in non-buggy implementations.
942 We don't use string literals for these strings,
943 since if a string in the environment is in readonly
944 storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
945 See Sun bugs 1113095 and 1114114, ``Timezone routines
946 improperly modify environment''. */
948 static char set_time_zone_rule_tz1
[] = "TZ=GMT0";
949 static char set_time_zone_rule_tz2
[] = "TZ=GMT1";
951 /* Set the local time zone rule to TZSTRING.
952 This allocates memory into `environ', which it is the caller's
953 responsibility to free. */
955 set_time_zone_rule (tzstring
)
959 char **from
, **to
, **newenv
;
961 /* Make the ENVIRON vector longer with room for TZSTRING. */
962 for (from
= environ
; *from
; from
++)
964 envptrs
= from
- environ
+ 2;
965 newenv
= to
= (char **) xmalloc (envptrs
* sizeof (char *)
966 + (tzstring
? strlen (tzstring
) + 4 : 0));
968 /* Add TZSTRING to the end of environ, as a value for TZ. */
971 char *t
= (char *) (to
+ envptrs
);
973 strcat (t
, tzstring
);
977 /* Copy the old environ vector elements into NEWENV,
978 but don't copy the TZ variable.
979 So we have only one definition of TZ, which came from TZSTRING. */
980 for (from
= environ
; *from
; from
++)
981 if (strncmp (*from
, "TZ=", 3) != 0)
987 /* If we do have a TZSTRING, NEWENV points to the vector slot where
988 the TZ variable is stored. If we do not have a TZSTRING,
989 TO points to the vector slot which has the terminating null. */
991 #ifdef LOCALTIME_CACHE
993 /* In SunOS 4.1.3_U1 and 4.1.4, if TZ has a value like
994 "US/Pacific" that loads a tz file, then changes to a value like
995 "XXX0" that does not load a tz file, and then changes back to
996 its original value, the last change is (incorrectly) ignored.
997 Also, if TZ changes twice in succession to values that do
998 not load a tz file, tzset can dump core (see Sun bug#1225179).
999 The following code works around these bugs. */
1003 /* Temporarily set TZ to a value that loads a tz file
1004 and that differs from tzstring. */
1006 *newenv
= (strcmp (tzstring
, set_time_zone_rule_tz1
+ 3) == 0
1007 ? set_time_zone_rule_tz2
: set_time_zone_rule_tz1
);
1013 /* The implied tzstring is unknown, so temporarily set TZ to
1014 two different values that each load a tz file. */
1015 *to
= set_time_zone_rule_tz1
;
1018 *to
= set_time_zone_rule_tz2
;
1023 /* Now TZ has the desired value, and tzset can be invoked safely. */
1038 /* Callers passing one argument to Finsert need not gcpro the
1039 argument "array", since the only element of the array will
1040 not be used after calling insert or insert_from_string, so
1041 we don't care if it gets trashed. */
1043 DEFUN ("insert", Finsert
, Sinsert
, 0, MANY
, 0,
1044 "Insert the arguments, either strings or characters, at point.\n\
1045 Point moves forward so that it ends up after the inserted text.\n\
1046 Any other markers at the point of insertion remain before the text.")
1049 register Lisp_Object
*args
;
1051 register int argnum
;
1052 register Lisp_Object tem
;
1055 for (argnum
= 0; argnum
< nargs
; argnum
++)
1061 str
[0] = XINT (tem
);
1064 else if (STRINGP (tem
))
1066 insert_from_string (tem
, 0, XSTRING (tem
)->size
, 0);
1070 tem
= wrong_type_argument (Qchar_or_string_p
, tem
);
1078 DEFUN ("insert-and-inherit", Finsert_and_inherit
, Sinsert_and_inherit
,
1080 "Insert the arguments at point, inheriting properties from adjoining text.\n\
1081 Point moves forward so that it ends up after the inserted text.\n\
1082 Any other markers at the point of insertion remain before the text.")
1085 register Lisp_Object
*args
;
1087 register int argnum
;
1088 register Lisp_Object tem
;
1091 for (argnum
= 0; argnum
< nargs
; argnum
++)
1097 str
[0] = XINT (tem
);
1098 insert_and_inherit (str
, 1);
1100 else if (STRINGP (tem
))
1102 insert_from_string (tem
, 0, XSTRING (tem
)->size
, 1);
1106 tem
= wrong_type_argument (Qchar_or_string_p
, tem
);
1114 DEFUN ("insert-before-markers", Finsert_before_markers
, Sinsert_before_markers
, 0, MANY
, 0,
1115 "Insert strings or characters at point, relocating markers after the text.\n\
1116 Point moves forward so that it ends up after the inserted text.\n\
1117 Any other markers at the point of insertion also end up after the text.")
1120 register Lisp_Object
*args
;
1122 register int argnum
;
1123 register Lisp_Object tem
;
1126 for (argnum
= 0; argnum
< nargs
; argnum
++)
1132 str
[0] = XINT (tem
);
1133 insert_before_markers (str
, 1);
1135 else if (STRINGP (tem
))
1137 insert_from_string_before_markers (tem
, 0, XSTRING (tem
)->size
, 0);
1141 tem
= wrong_type_argument (Qchar_or_string_p
, tem
);
1149 DEFUN ("insert-before-markers-and-inherit",
1150 Finsert_and_inherit_before_markers
, Sinsert_and_inherit_before_markers
,
1152 "Insert text at point, relocating markers and inheriting properties.\n\
1153 Point moves forward so that it ends up after the inserted text.\n\
1154 Any other markers at the point of insertion also end up after the text.")
1157 register Lisp_Object
*args
;
1159 register int argnum
;
1160 register Lisp_Object tem
;
1163 for (argnum
= 0; argnum
< nargs
; argnum
++)
1169 str
[0] = XINT (tem
);
1170 insert_before_markers_and_inherit (str
, 1);
1172 else if (STRINGP (tem
))
1174 insert_from_string_before_markers (tem
, 0, XSTRING (tem
)->size
, 1);
1178 tem
= wrong_type_argument (Qchar_or_string_p
, tem
);
1186 DEFUN ("insert-char", Finsert_char
, Sinsert_char
, 2, 3, 0,
1187 "Insert COUNT (second arg) copies of CHARACTER (first arg).\n\
1188 Point and all markers are affected as in the function `insert'.\n\
1189 Both arguments are required.\n\
1190 The optional third arg INHERIT, if non-nil, says to inherit text properties\n\
1191 from adjoining text, if those properties are sticky.")
1192 (character
, count
, inherit
)
1193 Lisp_Object character
, count
, inherit
;
1195 register unsigned char *string
;
1196 register int strlen
;
1199 CHECK_NUMBER (character
, 0);
1200 CHECK_NUMBER (count
, 1);
1205 strlen
= min (n
, 256);
1206 string
= (unsigned char *) alloca (strlen
);
1207 for (i
= 0; i
< strlen
; i
++)
1208 string
[i
] = XFASTINT (character
);
1211 if (!NILP (inherit
))
1212 insert_and_inherit (string
, strlen
);
1214 insert (string
, strlen
);
1219 if (!NILP (inherit
))
1220 insert_and_inherit (string
, n
);
1228 /* Making strings from buffer contents. */
1230 /* Return a Lisp_String containing the text of the current buffer from
1231 START to END. If text properties are in use and the current buffer
1232 has properties in the range specified, the resulting string will also
1233 have them, if PROPS is nonzero.
1235 We don't want to use plain old make_string here, because it calls
1236 make_uninit_string, which can cause the buffer arena to be
1237 compacted. make_string has no way of knowing that the data has
1238 been moved, and thus copies the wrong data into the string. This
1239 doesn't effect most of the other users of make_string, so it should
1240 be left as is. But we should use this function when conjuring
1241 buffer substrings. */
1244 make_buffer_string (start
, end
, props
)
1248 Lisp_Object result
, tem
, tem1
;
1250 if (start
< GPT
&& GPT
< end
)
1253 result
= make_uninit_string (end
- start
);
1254 bcopy (&FETCH_CHAR (start
), XSTRING (result
)->data
, end
- start
);
1256 /* If desired, update and copy the text properties. */
1257 #ifdef USE_TEXT_PROPERTIES
1260 update_buffer_properties (start
, end
);
1262 tem
= Fnext_property_change (make_number (start
), Qnil
, make_number (end
));
1263 tem1
= Ftext_properties_at (make_number (start
), Qnil
);
1265 if (XINT (tem
) != end
|| !NILP (tem1
))
1266 copy_intervals_to_string (result
, current_buffer
, start
, end
- start
);
1273 /* Call Vbuffer_access_fontify_functions for the range START ... END
1274 in the current buffer, if necessary. */
1277 update_buffer_properties (start
, end
)
1280 #ifdef USE_TEXT_PROPERTIES
1281 /* If this buffer has some access functions,
1282 call them, specifying the range of the buffer being accessed. */
1283 if (!NILP (Vbuffer_access_fontify_functions
))
1285 Lisp_Object args
[3];
1288 args
[0] = Qbuffer_access_fontify_functions
;
1289 XSETINT (args
[1], start
);
1290 XSETINT (args
[2], end
);
1292 /* But don't call them if we can tell that the work
1293 has already been done. */
1294 if (!NILP (Vbuffer_access_fontified_property
))
1296 tem
= Ftext_property_any (args
[1], args
[2],
1297 Vbuffer_access_fontified_property
,
1300 Frun_hook_with_args (3, args
);
1303 Frun_hook_with_args (3, args
);
1308 DEFUN ("buffer-substring", Fbuffer_substring
, Sbuffer_substring
, 2, 2, 0,
1309 "Return the contents of part of the current buffer as a string.\n\
1310 The two arguments START and END are character positions;\n\
1311 they can be in either order.")
1313 Lisp_Object start
, end
;
1317 validate_region (&start
, &end
);
1321 return make_buffer_string (b
, e
, 1);
1324 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties
,
1325 Sbuffer_substring_no_properties
, 2, 2, 0,
1326 "Return the characters of part of the buffer, without the text properties.\n\
1327 The two arguments START and END are character positions;\n\
1328 they can be in either order.")
1330 Lisp_Object start
, end
;
1334 validate_region (&start
, &end
);
1338 return make_buffer_string (b
, e
, 0);
1341 DEFUN ("buffer-string", Fbuffer_string
, Sbuffer_string
, 0, 0, 0,
1342 "Return the contents of the current buffer as a string.\n\
1343 If narrowing is in effect, this function returns only the visible part\n\
1347 return make_buffer_string (BEGV
, ZV
, 1);
1350 DEFUN ("insert-buffer-substring", Finsert_buffer_substring
, Sinsert_buffer_substring
,
1352 "Insert before point a substring of the contents of buffer BUFFER.\n\
1353 BUFFER may be a buffer or a buffer name.\n\
1354 Arguments START and END are character numbers specifying the substring.\n\
1355 They default to the beginning and the end of BUFFER.")
1357 Lisp_Object buf
, start
, end
;
1359 register int b
, e
, temp
;
1360 register struct buffer
*bp
, *obuf
;
1363 buffer
= Fget_buffer (buf
);
1366 bp
= XBUFFER (buffer
);
1367 if (NILP (bp
->name
))
1368 error ("Selecting deleted buffer");
1374 CHECK_NUMBER_COERCE_MARKER (start
, 0);
1381 CHECK_NUMBER_COERCE_MARKER (end
, 1);
1386 temp
= b
, b
= e
, e
= temp
;
1388 if (!(BUF_BEGV (bp
) <= b
&& e
<= BUF_ZV (bp
)))
1389 args_out_of_range (start
, end
);
1391 obuf
= current_buffer
;
1392 set_buffer_internal_1 (bp
);
1393 update_buffer_properties (b
, e
);
1394 set_buffer_internal_1 (obuf
);
1396 insert_from_buffer (bp
, b
, e
- b
, 0);
1400 DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings
, Scompare_buffer_substrings
,
1402 "Compare two substrings of two buffers; return result as number.\n\
1403 the value is -N if first string is less after N-1 chars,\n\
1404 +N if first string is greater after N-1 chars, or 0 if strings match.\n\
1405 Each substring is represented as three arguments: BUFFER, START and END.\n\
1406 That makes six args in all, three for each substring.\n\n\
1407 The value of `case-fold-search' in the current buffer\n\
1408 determines whether case is significant or ignored.")
1409 (buffer1
, start1
, end1
, buffer2
, start2
, end2
)
1410 Lisp_Object buffer1
, start1
, end1
, buffer2
, start2
, end2
;
1412 register int begp1
, endp1
, begp2
, endp2
, temp
, len1
, len2
, length
, i
;
1413 register struct buffer
*bp1
, *bp2
;
1414 register Lisp_Object
*trt
1415 = (!NILP (current_buffer
->case_fold_search
)
1416 ? XCHAR_TABLE (current_buffer
->case_canon_table
)->contents
: 0);
1418 /* Find the first buffer and its substring. */
1421 bp1
= current_buffer
;
1425 buf1
= Fget_buffer (buffer1
);
1428 bp1
= XBUFFER (buf1
);
1429 if (NILP (bp1
->name
))
1430 error ("Selecting deleted buffer");
1434 begp1
= BUF_BEGV (bp1
);
1437 CHECK_NUMBER_COERCE_MARKER (start1
, 1);
1438 begp1
= XINT (start1
);
1441 endp1
= BUF_ZV (bp1
);
1444 CHECK_NUMBER_COERCE_MARKER (end1
, 2);
1445 endp1
= XINT (end1
);
1449 temp
= begp1
, begp1
= endp1
, endp1
= temp
;
1451 if (!(BUF_BEGV (bp1
) <= begp1
1453 && endp1
<= BUF_ZV (bp1
)))
1454 args_out_of_range (start1
, end1
);
1456 /* Likewise for second substring. */
1459 bp2
= current_buffer
;
1463 buf2
= Fget_buffer (buffer2
);
1466 bp2
= XBUFFER (buf2
);
1467 if (NILP (bp2
->name
))
1468 error ("Selecting deleted buffer");
1472 begp2
= BUF_BEGV (bp2
);
1475 CHECK_NUMBER_COERCE_MARKER (start2
, 4);
1476 begp2
= XINT (start2
);
1479 endp2
= BUF_ZV (bp2
);
1482 CHECK_NUMBER_COERCE_MARKER (end2
, 5);
1483 endp2
= XINT (end2
);
1487 temp
= begp2
, begp2
= endp2
, endp2
= temp
;
1489 if (!(BUF_BEGV (bp2
) <= begp2
1491 && endp2
<= BUF_ZV (bp2
)))
1492 args_out_of_range (start2
, end2
);
1494 len1
= endp1
- begp1
;
1495 len2
= endp2
- begp2
;
1500 for (i
= 0; i
< length
; i
++)
1502 int c1
= *BUF_CHAR_ADDRESS (bp1
, begp1
+ i
);
1503 int c2
= *BUF_CHAR_ADDRESS (bp2
, begp2
+ i
);
1510 return make_number (- 1 - i
);
1512 return make_number (i
+ 1);
1515 /* The strings match as far as they go.
1516 If one is shorter, that one is less. */
1518 return make_number (length
+ 1);
1519 else if (length
< len2
)
1520 return make_number (- length
- 1);
1522 /* Same length too => they are equal. */
1523 return make_number (0);
1527 subst_char_in_region_unwind (arg
)
1530 return current_buffer
->undo_list
= arg
;
1534 subst_char_in_region_unwind_1 (arg
)
1537 return current_buffer
->filename
= arg
;
1540 DEFUN ("subst-char-in-region", Fsubst_char_in_region
,
1541 Ssubst_char_in_region
, 4, 5, 0,
1542 "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\
1543 If optional arg NOUNDO is non-nil, don't record this change for undo\n\
1544 and don't mark the buffer as really changed.")
1545 (start
, end
, fromchar
, tochar
, noundo
)
1546 Lisp_Object start
, end
, fromchar
, tochar
, noundo
;
1548 register int pos
, stop
, look
;
1550 int count
= specpdl_ptr
- specpdl
;
1552 validate_region (&start
, &end
);
1553 CHECK_NUMBER (fromchar
, 2);
1554 CHECK_NUMBER (tochar
, 3);
1558 look
= XINT (fromchar
);
1560 /* If we don't want undo, turn off putting stuff on the list.
1561 That's faster than getting rid of things,
1562 and it prevents even the entry for a first change.
1563 Also inhibit locking the file. */
1566 record_unwind_protect (subst_char_in_region_unwind
,
1567 current_buffer
->undo_list
);
1568 current_buffer
->undo_list
= Qt
;
1569 /* Don't do file-locking. */
1570 record_unwind_protect (subst_char_in_region_unwind_1
,
1571 current_buffer
->filename
);
1572 current_buffer
->filename
= Qnil
;
1577 if (FETCH_CHAR (pos
) == look
)
1581 modify_region (current_buffer
, XINT (start
), stop
);
1583 if (! NILP (noundo
))
1585 if (MODIFF
- 1 == SAVE_MODIFF
)
1587 if (MODIFF
- 1 == current_buffer
->auto_save_modified
)
1588 current_buffer
->auto_save_modified
++;
1595 record_change (pos
, 1);
1596 FETCH_CHAR (pos
) = XINT (tochar
);
1602 signal_after_change (XINT (start
),
1603 stop
- XINT (start
), stop
- XINT (start
));
1605 unbind_to (count
, Qnil
);
1609 DEFUN ("translate-region", Ftranslate_region
, Stranslate_region
, 3, 3, 0,
1610 "From START to END, translate characters according to TABLE.\n\
1611 TABLE is a string; the Nth character in it is the mapping\n\
1612 for the character with code N. Returns the number of characters changed.")
1616 register Lisp_Object table
;
1618 register int pos
, stop
; /* Limits of the region. */
1619 register unsigned char *tt
; /* Trans table. */
1620 register int oc
; /* Old character. */
1621 register int nc
; /* New character. */
1622 int cnt
; /* Number of changes made. */
1623 Lisp_Object z
; /* Return. */
1624 int size
; /* Size of translate table. */
1626 validate_region (&start
, &end
);
1627 CHECK_STRING (table
, 2);
1629 size
= XSTRING (table
)->size
;
1630 tt
= XSTRING (table
)->data
;
1634 modify_region (current_buffer
, pos
, stop
);
1637 for (; pos
< stop
; ++pos
)
1639 oc
= FETCH_CHAR (pos
);
1645 record_change (pos
, 1);
1646 FETCH_CHAR (pos
) = nc
;
1647 signal_after_change (pos
, 1, 1);
1653 XSETFASTINT (z
, cnt
);
1657 DEFUN ("delete-region", Fdelete_region
, Sdelete_region
, 2, 2, "r",
1658 "Delete the text between point and mark.\n\
1659 When called from a program, expects two arguments,\n\
1660 positions (integers or markers) specifying the stretch to be deleted.")
1662 Lisp_Object start
, end
;
1664 validate_region (&start
, &end
);
1665 del_range (XINT (start
), XINT (end
));
1669 DEFUN ("widen", Fwiden
, Swiden
, 0, 0, "",
1670 "Remove restrictions (narrowing) from current buffer.\n\
1671 This allows the buffer's full text to be seen and edited.")
1675 SET_BUF_ZV (current_buffer
, Z
);
1676 current_buffer
->clip_changed
= 1;
1677 /* Changing the buffer bounds invalidates any recorded current column. */
1678 invalidate_current_column ();
1682 DEFUN ("narrow-to-region", Fnarrow_to_region
, Snarrow_to_region
, 2, 2, "r",
1683 "Restrict editing in this buffer to the current region.\n\
1684 The rest of the text becomes temporarily invisible and untouchable\n\
1685 but is not deleted; if you save the buffer in a file, the invisible\n\
1686 text is included in the file. \\[widen] makes all visible again.\n\
1687 See also `save-restriction'.\n\
1689 When calling from a program, pass two arguments; positions (integers\n\
1690 or markers) bounding the text that should remain visible.")
1692 register Lisp_Object start
, end
;
1694 CHECK_NUMBER_COERCE_MARKER (start
, 0);
1695 CHECK_NUMBER_COERCE_MARKER (end
, 1);
1697 if (XINT (start
) > XINT (end
))
1700 tem
= start
; start
= end
; end
= tem
;
1703 if (!(BEG
<= XINT (start
) && XINT (start
) <= XINT (end
) && XINT (end
) <= Z
))
1704 args_out_of_range (start
, end
);
1706 BEGV
= XFASTINT (start
);
1707 SET_BUF_ZV (current_buffer
, XFASTINT (end
));
1708 if (PT
< XFASTINT (start
))
1709 SET_PT (XFASTINT (start
));
1710 if (PT
> XFASTINT (end
))
1711 SET_PT (XFASTINT (end
));
1712 current_buffer
->clip_changed
= 1;
1713 /* Changing the buffer bounds invalidates any recorded current column. */
1714 invalidate_current_column ();
1719 save_restriction_save ()
1721 register Lisp_Object bottom
, top
;
1722 /* Note: I tried using markers here, but it does not win
1723 because insertion at the end of the saved region
1724 does not advance mh and is considered "outside" the saved region. */
1725 XSETFASTINT (bottom
, BEGV
- BEG
);
1726 XSETFASTINT (top
, Z
- ZV
);
1728 return Fcons (Fcurrent_buffer (), Fcons (bottom
, top
));
1732 save_restriction_restore (data
)
1735 register struct buffer
*buf
;
1736 register int newhead
, newtail
;
1737 register Lisp_Object tem
;
1739 buf
= XBUFFER (XCONS (data
)->car
);
1741 data
= XCONS (data
)->cdr
;
1743 tem
= XCONS (data
)->car
;
1744 newhead
= XINT (tem
);
1745 tem
= XCONS (data
)->cdr
;
1746 newtail
= XINT (tem
);
1747 if (newhead
+ newtail
> BUF_Z (buf
) - BUF_BEG (buf
))
1752 BUF_BEGV (buf
) = BUF_BEG (buf
) + newhead
;
1753 SET_BUF_ZV (buf
, BUF_Z (buf
) - newtail
);
1754 current_buffer
->clip_changed
= 1;
1756 /* If point is outside the new visible range, move it inside. */
1758 clip_to_bounds (BUF_BEGV (buf
), BUF_PT (buf
), BUF_ZV (buf
)));
1763 DEFUN ("save-restriction", Fsave_restriction
, Ssave_restriction
, 0, UNEVALLED
, 0,
1764 "Execute BODY, saving and restoring current buffer's restrictions.\n\
1765 The buffer's restrictions make parts of the beginning and end invisible.\n\
1766 \(They are set up with `narrow-to-region' and eliminated with `widen'.)\n\
1767 This special form, `save-restriction', saves the current buffer's restrictions\n\
1768 when it is entered, and restores them when it is exited.\n\
1769 So any `narrow-to-region' within BODY lasts only until the end of the form.\n\
1770 The old restrictions settings are restored\n\
1771 even in case of abnormal exit (throw or error).\n\
1773 The value returned is the value of the last form in BODY.\n\
1775 `save-restriction' can get confused if, within the BODY, you widen\n\
1776 and then make changes outside the area within the saved restrictions.\n\
1778 Note: if you are using both `save-excursion' and `save-restriction',\n\
1779 use `save-excursion' outermost:\n\
1780 (save-excursion (save-restriction ...))")
1784 register Lisp_Object val
;
1785 int count
= specpdl_ptr
- specpdl
;
1787 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
1788 val
= Fprogn (body
);
1789 return unbind_to (count
, val
);
1792 /* Buffer for the most recent text displayed by Fmessage. */
1793 static char *message_text
;
1795 /* Allocated length of that buffer. */
1796 static int message_length
;
1798 DEFUN ("message", Fmessage
, Smessage
, 1, MANY
, 0,
1799 "Print a one-line message at the bottom of the screen.\n\
1800 The first argument is a format control string, and the rest are data\n\
1801 to be formatted under control of the string. See `format' for details.\n\
1803 If the first argument is nil, clear any existing message; let the\n\
1804 minibuffer contents show.")
1816 register Lisp_Object val
;
1817 val
= Fformat (nargs
, args
);
1818 /* Copy the data so that it won't move when we GC. */
1821 message_text
= (char *)xmalloc (80);
1822 message_length
= 80;
1824 if (XSTRING (val
)->size
> message_length
)
1826 message_length
= XSTRING (val
)->size
;
1827 message_text
= (char *)xrealloc (message_text
, message_length
);
1829 bcopy (XSTRING (val
)->data
, message_text
, XSTRING (val
)->size
);
1830 message2 (message_text
, XSTRING (val
)->size
);
1835 DEFUN ("message-box", Fmessage_box
, Smessage_box
, 1, MANY
, 0,
1836 "Display a message, in a dialog box if possible.\n\
1837 If a dialog box is not available, use the echo area.\n\
1838 The first argument is a format control string, and the rest are data\n\
1839 to be formatted under control of the string. See `format' for details.\n\
1841 If the first argument is nil, clear any existing message; let the\n\
1842 minibuffer contents show.")
1854 register Lisp_Object val
;
1855 val
= Fformat (nargs
, args
);
1858 Lisp_Object pane
, menu
, obj
;
1859 struct gcpro gcpro1
;
1860 pane
= Fcons (Fcons (build_string ("OK"), Qt
), Qnil
);
1862 menu
= Fcons (val
, pane
);
1863 obj
= Fx_popup_dialog (Qt
, menu
);
1867 #else /* not HAVE_MENUS */
1868 /* Copy the data so that it won't move when we GC. */
1871 message_text
= (char *)xmalloc (80);
1872 message_length
= 80;
1874 if (XSTRING (val
)->size
> message_length
)
1876 message_length
= XSTRING (val
)->size
;
1877 message_text
= (char *)xrealloc (message_text
, message_length
);
1879 bcopy (XSTRING (val
)->data
, message_text
, XSTRING (val
)->size
);
1880 message2 (message_text
, XSTRING (val
)->size
);
1882 #endif /* not HAVE_MENUS */
1886 extern Lisp_Object last_nonmenu_event
;
1889 DEFUN ("message-or-box", Fmessage_or_box
, Smessage_or_box
, 1, MANY
, 0,
1890 "Display a message in a dialog box or in the echo area.\n\
1891 If this command was invoked with the mouse, use a dialog box.\n\
1892 Otherwise, use the echo area.\n\
1893 The first argument is a format control string, and the rest are data\n\
1894 to be formatted under control of the string. See `format' for details.\n\
1896 If the first argument is nil, clear any existing message; let the\n\
1897 minibuffer contents show.")
1903 if (NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
1904 return Fmessage_box (nargs
, args
);
1906 return Fmessage (nargs
, args
);
1909 DEFUN ("format", Fformat
, Sformat
, 1, MANY
, 0,
1910 "Format a string out of a control-string and arguments.\n\
1911 The first argument is a control string.\n\
1912 The other arguments are substituted into it to make the result, a string.\n\
1913 It may contain %-sequences meaning to substitute the next argument.\n\
1914 %s means print a string argument. Actually, prints any object, with `princ'.\n\
1915 %d means print as number in decimal (%o octal, %x hex).\n\
1916 %e means print a number in exponential notation.\n\
1917 %f means print a number in decimal-point notation.\n\
1918 %g means print a number in exponential notation\n\
1919 or decimal-point notation, whichever uses fewer characters.\n\
1920 %c means print a number as a single character.\n\
1921 %S means print any object as an s-expression (using prin1).\n\
1922 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.\n\
1923 Use %% to put a single % into the output.")
1926 register Lisp_Object
*args
;
1928 register int n
; /* The number of the next arg to substitute */
1929 register int total
= 5; /* An estimate of the final length */
1931 register unsigned char *format
, *end
;
1933 extern char *index ();
1934 /* It should not be necessary to GCPRO ARGS, because
1935 the caller in the interpreter should take care of that. */
1937 CHECK_STRING (args
[0], 0);
1938 format
= XSTRING (args
[0])->data
;
1939 end
= format
+ XSTRING (args
[0])->size
;
1942 while (format
!= end
)
1943 if (*format
++ == '%')
1947 /* Process a numeric arg and skip it. */
1948 minlen
= atoi (format
);
1952 while ((*format
>= '0' && *format
<= '9')
1953 || *format
== '-' || *format
== ' ' || *format
== '.')
1958 else if (++n
>= nargs
)
1959 error ("Not enough arguments for format string");
1960 else if (*format
== 'S')
1962 /* For `S', prin1 the argument and then treat like a string. */
1963 register Lisp_Object tem
;
1964 tem
= Fprin1_to_string (args
[n
], Qnil
);
1968 else if (SYMBOLP (args
[n
]))
1970 XSETSTRING (args
[n
], XSYMBOL (args
[n
])->name
);
1973 else if (STRINGP (args
[n
]))
1976 if (*format
!= 's' && *format
!= 'S')
1977 error ("format specifier doesn't match argument type");
1978 total
+= XSTRING (args
[n
])->size
;
1979 /* We have to put an arbitrary limit on minlen
1980 since otherwise it could make alloca fail. */
1981 if (minlen
< XSTRING (args
[n
])->size
+ 1000)
1984 /* Would get MPV otherwise, since Lisp_Int's `point' to low memory. */
1985 else if (INTEGERP (args
[n
]) && *format
!= 's')
1987 #ifdef LISP_FLOAT_TYPE
1988 /* The following loop assumes the Lisp type indicates
1989 the proper way to pass the argument.
1990 So make sure we have a flonum if the argument should
1992 if (*format
== 'e' || *format
== 'f' || *format
== 'g')
1993 args
[n
] = Ffloat (args
[n
]);
1996 /* We have to put an arbitrary limit on minlen
1997 since otherwise it could make alloca fail. */
2001 #ifdef LISP_FLOAT_TYPE
2002 else if (FLOATP (args
[n
]) && *format
!= 's')
2004 if (! (*format
== 'e' || *format
== 'f' || *format
== 'g'))
2005 args
[n
] = Ftruncate (args
[n
]);
2007 /* We have to put an arbitrary limit on minlen
2008 since otherwise it could make alloca fail. */
2015 /* Anything but a string, convert to a string using princ. */
2016 register Lisp_Object tem
;
2017 tem
= Fprin1_to_string (args
[n
], Qt
);
2024 register int nstrings
= n
+ 1;
2026 /* Allocate twice as many strings as we have %-escapes; floats occupy
2027 two slots, and we're not sure how many of those we have. */
2028 register unsigned char **strings
2029 = (unsigned char **) alloca (2 * nstrings
* sizeof (unsigned char *));
2033 for (n
= 0; n
< nstrings
; n
++)
2036 strings
[i
++] = (unsigned char *) "";
2037 else if (INTEGERP (args
[n
]))
2038 /* We checked above that the corresponding format effector
2039 isn't %s, which would cause MPV. */
2040 strings
[i
++] = (unsigned char *) XINT (args
[n
]);
2041 #ifdef LISP_FLOAT_TYPE
2042 else if (FLOATP (args
[n
]))
2044 union { double d
; char *half
[2]; } u
;
2046 u
.d
= XFLOAT (args
[n
])->data
;
2047 strings
[i
++] = (unsigned char *) u
.half
[0];
2048 strings
[i
++] = (unsigned char *) u
.half
[1];
2052 /* The first string is treated differently
2053 because it is the format string. */
2054 strings
[i
++] = XSTRING (args
[n
])->data
;
2056 strings
[i
++] = (unsigned char *) XSTRING (args
[n
]);
2059 /* Make room in result for all the non-%-codes in the control string. */
2060 total
+= XSTRING (args
[0])->size
;
2062 /* Format it in bigger and bigger buf's until it all fits. */
2065 buf
= (char *) alloca (total
+ 1);
2068 length
= doprnt_lisp (buf
, total
+ 1, strings
[0],
2069 end
, i
-1, strings
+ 1);
2070 if (buf
[total
- 1] == 0)
2078 return make_string (buf
, length
);
2084 format1 (string1
, arg0
, arg1
, arg2
, arg3
, arg4
)
2085 EMACS_INT arg0
, arg1
, arg2
, arg3
, arg4
;
2099 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, args
);
2101 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, &string1
+ 1);
2103 return build_string (buf
);
2106 DEFUN ("char-equal", Fchar_equal
, Schar_equal
, 2, 2, 0,
2107 "Return t if two characters match, optionally ignoring case.\n\
2108 Both arguments must be characters (i.e. integers).\n\
2109 Case is ignored if `case-fold-search' is non-nil in the current buffer.")
2111 register Lisp_Object c1
, c2
;
2113 Lisp_Object
*downcase
= DOWNCASE_TABLE
;
2114 CHECK_NUMBER (c1
, 0);
2115 CHECK_NUMBER (c2
, 1);
2117 if (!NILP (current_buffer
->case_fold_search
)
2118 ? ((XINT (downcase
[0xff & XFASTINT (c1
)])
2119 == XINT (downcase
[0xff & XFASTINT (c2
)]))
2120 && (XFASTINT (c1
) & ~0xff) == (XFASTINT (c2
) & ~0xff))
2121 : XINT (c1
) == XINT (c2
))
2126 /* Transpose the markers in two regions of the current buffer, and
2127 adjust the ones between them if necessary (i.e.: if the regions
2130 Traverses the entire marker list of the buffer to do so, adding an
2131 appropriate amount to some, subtracting from some, and leaving the
2132 rest untouched. Most of this is copied from adjust_markers in insdel.c.
2134 It's the caller's job to see that (start1 <= end1 <= start2 <= end2). */
2137 transpose_markers (start1
, end1
, start2
, end2
)
2138 register int start1
, end1
, start2
, end2
;
2140 register int amt1
, amt2
, diff
, mpos
;
2141 register Lisp_Object marker
;
2143 /* Update point as if it were a marker. */
2147 TEMP_SET_PT (PT
+ (end2
- end1
));
2148 else if (PT
< start2
)
2149 TEMP_SET_PT (PT
+ (end2
- start2
) - (end1
- start1
));
2151 TEMP_SET_PT (PT
- (start2
- start1
));
2153 /* We used to adjust the endpoints here to account for the gap, but that
2154 isn't good enough. Even if we assume the caller has tried to move the
2155 gap out of our way, it might still be at start1 exactly, for example;
2156 and that places it `inside' the interval, for our purposes. The amount
2157 of adjustment is nontrivial if there's a `denormalized' marker whose
2158 position is between GPT and GPT + GAP_SIZE, so it's simpler to leave
2159 the dirty work to Fmarker_position, below. */
2161 /* The difference between the region's lengths */
2162 diff
= (end2
- start2
) - (end1
- start1
);
2164 /* For shifting each marker in a region by the length of the other
2165 * region plus the distance between the regions.
2167 amt1
= (end2
- start2
) + (start2
- end1
);
2168 amt2
= (end1
- start1
) + (start2
- end1
);
2170 for (marker
= BUF_MARKERS (current_buffer
); !NILP (marker
);
2171 marker
= XMARKER (marker
)->chain
)
2173 mpos
= Fmarker_position (marker
);
2174 if (mpos
>= start1
&& mpos
< end2
)
2178 else if (mpos
< start2
)
2182 if (mpos
> GPT
) mpos
+= GAP_SIZE
;
2183 XMARKER (marker
)->bufpos
= mpos
;
2188 DEFUN ("transpose-regions", Ftranspose_regions
, Stranspose_regions
, 4, 5, 0,
2189 "Transpose region START1 to END1 with START2 to END2.\n\
2190 The regions may not be overlapping, because the size of the buffer is\n\
2191 never changed in a transposition.\n\
2193 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't transpose\n\
2194 any markers that happen to be located in the regions.\n\
2196 Transposing beyond buffer boundaries is an error.")
2197 (startr1
, endr1
, startr2
, endr2
, leave_markers
)
2198 Lisp_Object startr1
, endr1
, startr2
, endr2
, leave_markers
;
2200 register int start1
, end1
, start2
, end2
,
2201 gap
, len1
, len_mid
, len2
;
2202 unsigned char *start1_addr
, *start2_addr
, *temp
;
2204 #ifdef USE_TEXT_PROPERTIES
2205 INTERVAL cur_intv
, tmp_interval1
, tmp_interval_mid
, tmp_interval2
;
2206 cur_intv
= BUF_INTERVALS (current_buffer
);
2207 #endif /* USE_TEXT_PROPERTIES */
2209 validate_region (&startr1
, &endr1
);
2210 validate_region (&startr2
, &endr2
);
2212 start1
= XFASTINT (startr1
);
2213 end1
= XFASTINT (endr1
);
2214 start2
= XFASTINT (startr2
);
2215 end2
= XFASTINT (endr2
);
2218 /* Swap the regions if they're reversed. */
2221 register int glumph
= start1
;
2229 len1
= end1
- start1
;
2230 len2
= end2
- start2
;
2233 error ("transposed regions not properly ordered");
2234 else if (start1
== end1
|| start2
== end2
)
2235 error ("transposed region may not be of length 0");
2237 /* The possibilities are:
2238 1. Adjacent (contiguous) regions, or separate but equal regions
2239 (no, really equal, in this case!), or
2240 2. Separate regions of unequal size.
2242 The worst case is usually No. 2. It means that (aside from
2243 potential need for getting the gap out of the way), there also
2244 needs to be a shifting of the text between the two regions. So
2245 if they are spread far apart, we are that much slower... sigh. */
2247 /* It must be pointed out that the really studly thing to do would
2248 be not to move the gap at all, but to leave it in place and work
2249 around it if necessary. This would be extremely efficient,
2250 especially considering that people are likely to do
2251 transpositions near where they are working interactively, which
2252 is exactly where the gap would be found. However, such code
2253 would be much harder to write and to read. So, if you are
2254 reading this comment and are feeling squirrely, by all means have
2255 a go! I just didn't feel like doing it, so I will simply move
2256 the gap the minimum distance to get it out of the way, and then
2257 deal with an unbroken array. */
2259 /* Make sure the gap won't interfere, by moving it out of the text
2260 we will operate on. */
2261 if (start1
< gap
&& gap
< end2
)
2263 if (gap
- start1
< end2
- gap
)
2269 /* Hmmm... how about checking to see if the gap is large
2270 enough to use as the temporary storage? That would avoid an
2271 allocation... interesting. Later, don't fool with it now. */
2273 /* Working without memmove, for portability (sigh), so must be
2274 careful of overlapping subsections of the array... */
2276 if (end1
== start2
) /* adjacent regions */
2278 modify_region (current_buffer
, start1
, end2
);
2279 record_change (start1
, len1
+ len2
);
2281 #ifdef USE_TEXT_PROPERTIES
2282 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2283 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2284 Fset_text_properties (start1
, end2
, Qnil
, Qnil
);
2285 #endif /* USE_TEXT_PROPERTIES */
2287 /* First region smaller than second. */
2290 /* We use alloca only if it is small,
2291 because we want to avoid stack overflow. */
2293 temp
= (unsigned char *) xmalloc (len2
);
2295 temp
= (unsigned char *) alloca (len2
);
2297 /* Don't precompute these addresses. We have to compute them
2298 at the last minute, because the relocating allocator might
2299 have moved the buffer around during the xmalloc. */
2300 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1
);
2301 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2
);
2303 bcopy (start2_addr
, temp
, len2
);
2304 bcopy (start1_addr
, start1_addr
+ len2
, len1
);
2305 bcopy (temp
, start1_addr
, len2
);
2310 /* First region not smaller than second. */
2313 temp
= (unsigned char *) xmalloc (len1
);
2315 temp
= (unsigned char *) alloca (len1
);
2316 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1
);
2317 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2
);
2318 bcopy (start1_addr
, temp
, len1
);
2319 bcopy (start2_addr
, start1_addr
, len2
);
2320 bcopy (temp
, start1_addr
+ len2
, len1
);
2324 #ifdef USE_TEXT_PROPERTIES
2325 graft_intervals_into_buffer (tmp_interval1
, start1
+ len2
,
2326 len1
, current_buffer
, 0);
2327 graft_intervals_into_buffer (tmp_interval2
, start1
,
2328 len2
, current_buffer
, 0);
2329 #endif /* USE_TEXT_PROPERTIES */
2331 /* Non-adjacent regions, because end1 != start2, bleagh... */
2335 /* Regions are same size, though, how nice. */
2337 modify_region (current_buffer
, start1
, end1
);
2338 modify_region (current_buffer
, start2
, end2
);
2339 record_change (start1
, len1
);
2340 record_change (start2
, len2
);
2341 #ifdef USE_TEXT_PROPERTIES
2342 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2343 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2344 Fset_text_properties (start1
, end1
, Qnil
, Qnil
);
2345 Fset_text_properties (start2
, end2
, Qnil
, Qnil
);
2346 #endif /* USE_TEXT_PROPERTIES */
2349 temp
= (unsigned char *) xmalloc (len1
);
2351 temp
= (unsigned char *) alloca (len1
);
2352 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1
);
2353 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2
);
2354 bcopy (start1_addr
, temp
, len1
);
2355 bcopy (start2_addr
, start1_addr
, len2
);
2356 bcopy (temp
, start2_addr
, len1
);
2359 #ifdef USE_TEXT_PROPERTIES
2360 graft_intervals_into_buffer (tmp_interval1
, start2
,
2361 len1
, current_buffer
, 0);
2362 graft_intervals_into_buffer (tmp_interval2
, start1
,
2363 len2
, current_buffer
, 0);
2364 #endif /* USE_TEXT_PROPERTIES */
2367 else if (len1
< len2
) /* Second region larger than first */
2368 /* Non-adjacent & unequal size, area between must also be shifted. */
2370 len_mid
= start2
- end1
;
2371 modify_region (current_buffer
, start1
, end2
);
2372 record_change (start1
, (end2
- start1
));
2373 #ifdef USE_TEXT_PROPERTIES
2374 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2375 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
2376 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2377 Fset_text_properties (start1
, end2
, Qnil
, Qnil
);
2378 #endif /* USE_TEXT_PROPERTIES */
2380 /* holds region 2 */
2382 temp
= (unsigned char *) xmalloc (len2
);
2384 temp
= (unsigned char *) alloca (len2
);
2385 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1
);
2386 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2
);
2387 bcopy (start2_addr
, temp
, len2
);
2388 bcopy (start1_addr
, start1_addr
+ len_mid
+ len2
, len1
);
2389 safe_bcopy (start1_addr
+ len1
, start1_addr
+ len2
, len_mid
);
2390 bcopy (temp
, start1_addr
, len2
);
2393 #ifdef USE_TEXT_PROPERTIES
2394 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
2395 len1
, current_buffer
, 0);
2396 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
2397 len_mid
, current_buffer
, 0);
2398 graft_intervals_into_buffer (tmp_interval2
, start1
,
2399 len2
, current_buffer
, 0);
2400 #endif /* USE_TEXT_PROPERTIES */
2403 /* Second region smaller than first. */
2405 len_mid
= start2
- end1
;
2406 record_change (start1
, (end2
- start1
));
2407 modify_region (current_buffer
, start1
, end2
);
2409 #ifdef USE_TEXT_PROPERTIES
2410 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
2411 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
2412 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
2413 Fset_text_properties (start1
, end2
, Qnil
, Qnil
);
2414 #endif /* USE_TEXT_PROPERTIES */
2416 /* holds region 1 */
2418 temp
= (unsigned char *) xmalloc (len1
);
2420 temp
= (unsigned char *) alloca (len1
);
2421 start1_addr
= BUF_CHAR_ADDRESS (current_buffer
, start1
);
2422 start2_addr
= BUF_CHAR_ADDRESS (current_buffer
, start2
);
2423 bcopy (start1_addr
, temp
, len1
);
2424 bcopy (start2_addr
, start1_addr
, len2
);
2425 bcopy (start1_addr
+ len1
, start1_addr
+ len2
, len_mid
);
2426 bcopy (temp
, start1_addr
+ len2
+ len_mid
, len1
);
2429 #ifdef USE_TEXT_PROPERTIES
2430 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
2431 len1
, current_buffer
, 0);
2432 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
2433 len_mid
, current_buffer
, 0);
2434 graft_intervals_into_buffer (tmp_interval2
, start1
,
2435 len2
, current_buffer
, 0);
2436 #endif /* USE_TEXT_PROPERTIES */
2440 /* todo: this will be slow, because for every transposition, we
2441 traverse the whole friggin marker list. Possible solutions:
2442 somehow get a list of *all* the markers across multiple
2443 transpositions and do it all in one swell phoop. Or maybe modify
2444 Emacs' marker code to keep an ordered list or tree. This might
2445 be nicer, and more beneficial in the long run, but would be a
2446 bunch of work. Plus the way they're arranged now is nice. */
2447 if (NILP (leave_markers
))
2449 transpose_markers (start1
, end1
, start2
, end2
);
2450 fix_overlays_in_range (start1
, end2
);
2462 Qbuffer_access_fontify_functions
2463 = intern ("buffer-access-fontify-functions");
2464 staticpro (&Qbuffer_access_fontify_functions
);
2466 DEFVAR_LISP ("buffer-access-fontify-functions",
2467 &Vbuffer_access_fontify_functions
,
2468 "List of functions called by `buffer-substring' to fontify if necessary.\n\
2469 Each function is called with two arguments which specify the range\n\
2470 of the buffer being accessed.");
2471 Vbuffer_access_fontify_functions
= Qnil
;
2475 extern Lisp_Object Vprin1_to_string_buffer
;
2476 obuf
= Fcurrent_buffer ();
2477 /* Do this here, because init_buffer_once is too early--it won't work. */
2478 Fset_buffer (Vprin1_to_string_buffer
);
2479 /* Make sure buffer-access-fontify-functions is nil in this buffer. */
2480 Fset (Fmake_local_variable (intern ("buffer-access-fontify-functions")),
2485 DEFVAR_LISP ("buffer-access-fontified-property",
2486 &Vbuffer_access_fontified_property
,
2487 "Property which (if non-nil) indicates text has been fontified.\n\
2488 `buffer-substring' need not call the `buffer-access-fontify-functions'\n\
2489 functions if all the text being accessed has this property.");
2490 Vbuffer_access_fontified_property
= Qnil
;
2492 DEFVAR_LISP ("system-name", &Vsystem_name
,
2493 "The name of the machine Emacs is running on.");
2495 DEFVAR_LISP ("user-full-name", &Vuser_full_name
,
2496 "The full name of the user logged in.");
2498 DEFVAR_LISP ("user-login-name", &Vuser_login_name
,
2499 "The user's name, taken from environment variables if possible.");
2501 DEFVAR_LISP ("user-real-login-name", &Vuser_real_login_name
,
2502 "The user's name, based upon the real uid only.");
2504 defsubr (&Schar_equal
);
2505 defsubr (&Sgoto_char
);
2506 defsubr (&Sstring_to_char
);
2507 defsubr (&Schar_to_string
);
2508 defsubr (&Sbuffer_substring
);
2509 defsubr (&Sbuffer_substring_no_properties
);
2510 defsubr (&Sbuffer_string
);
2512 defsubr (&Spoint_marker
);
2513 defsubr (&Smark_marker
);
2515 defsubr (&Sregion_beginning
);
2516 defsubr (&Sregion_end
);
2517 /* defsubr (&Smark); */
2518 /* defsubr (&Sset_mark); */
2519 defsubr (&Ssave_excursion
);
2521 defsubr (&Sbufsize
);
2522 defsubr (&Spoint_max
);
2523 defsubr (&Spoint_min
);
2524 defsubr (&Spoint_min_marker
);
2525 defsubr (&Spoint_max_marker
);
2531 defsubr (&Sfollowing_char
);
2532 defsubr (&Sprevious_char
);
2533 defsubr (&Schar_after
);
2535 defsubr (&Sinsert_before_markers
);
2536 defsubr (&Sinsert_and_inherit
);
2537 defsubr (&Sinsert_and_inherit_before_markers
);
2538 defsubr (&Sinsert_char
);
2540 defsubr (&Suser_login_name
);
2541 defsubr (&Suser_real_login_name
);
2542 defsubr (&Suser_uid
);
2543 defsubr (&Suser_real_uid
);
2544 defsubr (&Suser_full_name
);
2545 defsubr (&Semacs_pid
);
2546 defsubr (&Scurrent_time
);
2547 defsubr (&Sformat_time_string
);
2548 defsubr (&Sdecode_time
);
2549 defsubr (&Sencode_time
);
2550 defsubr (&Scurrent_time_string
);
2551 defsubr (&Scurrent_time_zone
);
2552 defsubr (&Sset_time_zone_rule
);
2553 defsubr (&Ssystem_name
);
2554 defsubr (&Smessage
);
2555 defsubr (&Smessage_box
);
2556 defsubr (&Smessage_or_box
);
2559 defsubr (&Sinsert_buffer_substring
);
2560 defsubr (&Scompare_buffer_substrings
);
2561 defsubr (&Ssubst_char_in_region
);
2562 defsubr (&Stranslate_region
);
2563 defsubr (&Sdelete_region
);
2565 defsubr (&Snarrow_to_region
);
2566 defsubr (&Ssave_restriction
);
2567 defsubr (&Stranspose_regions
);