1 /* Lisp functions pertaining to editing.
2 Copyright (C) 1985,86,87,89,93,94,95,96,97,98, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include <sys/types.h>
39 #include "intervals.h"
50 #define MAX_10_EXP DBL_MAX_10_EXP
52 #define MAX_10_EXP 310
60 extern char **environ
;
63 extern Lisp_Object make_time
P_ ((time_t));
64 extern size_t emacs_strftimeu
P_ ((char *, size_t, const char *,
65 const struct tm
*, int));
66 static int tm_diff
P_ ((struct tm
*, struct tm
*));
67 static void find_field
P_ ((Lisp_Object
, Lisp_Object
, int *, int *));
68 static void update_buffer_properties
P_ ((int, int));
69 static Lisp_Object region_limit
P_ ((int));
70 static int lisp_time_argument
P_ ((Lisp_Object
, time_t *, int *));
71 static size_t emacs_memftimeu
P_ ((char *, size_t, const char *,
72 size_t, const struct tm
*, int));
73 static void general_insert_function
P_ ((void (*) (unsigned char *, int),
74 void (*) (Lisp_Object
, int, int, int,
76 int, int, Lisp_Object
*));
77 static Lisp_Object subst_char_in_region_unwind
P_ ((Lisp_Object
));
78 static Lisp_Object subst_char_in_region_unwind_1
P_ ((Lisp_Object
));
79 static void transpose_markers
P_ ((int, int, int, int, int, int, int, int));
82 extern char *index
P_ ((const char *, int));
85 Lisp_Object Vbuffer_access_fontify_functions
;
86 Lisp_Object Qbuffer_access_fontify_functions
;
87 Lisp_Object Vbuffer_access_fontified_property
;
89 Lisp_Object Fuser_full_name
P_ ((Lisp_Object
));
91 /* Non-nil means don't stop at field boundary in text motion commands. */
93 Lisp_Object Vinhibit_field_text_motion
;
95 /* Some static data, and a function to initialize it for each run */
97 Lisp_Object Vsystem_name
;
98 Lisp_Object Vuser_real_login_name
; /* login name of current user ID */
99 Lisp_Object Vuser_full_name
; /* full name of current user */
100 Lisp_Object Vuser_login_name
; /* user name from LOGNAME or USER */
102 /* Symbol for the text property used to mark fields. */
106 /* A special value for Qfield properties. */
108 Lisp_Object Qboundary
;
115 register unsigned char *p
;
116 struct passwd
*pw
; /* password entry for the current user */
119 /* Set up system_name even when dumping. */
123 /* Don't bother with this on initial start when just dumping out */
126 #endif /* not CANNOT_DUMP */
128 pw
= (struct passwd
*) getpwuid (getuid ());
130 /* We let the real user name default to "root" because that's quite
131 accurate on MSDOG and because it lets Emacs find the init file.
132 (The DVX libraries override the Djgpp libraries here.) */
133 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "root");
135 Vuser_real_login_name
= build_string (pw
? pw
->pw_name
: "unknown");
138 /* Get the effective user name, by consulting environment variables,
139 or the effective uid if those are unset. */
140 user_name
= (char *) getenv ("LOGNAME");
143 user_name
= (char *) getenv ("USERNAME"); /* it's USERNAME on NT */
144 #else /* WINDOWSNT */
145 user_name
= (char *) getenv ("USER");
146 #endif /* WINDOWSNT */
149 pw
= (struct passwd
*) getpwuid (geteuid ());
150 user_name
= (char *) (pw
? pw
->pw_name
: "unknown");
152 Vuser_login_name
= build_string (user_name
);
154 /* If the user name claimed in the environment vars differs from
155 the real uid, use the claimed name to find the full name. */
156 tem
= Fstring_equal (Vuser_login_name
, Vuser_real_login_name
);
157 Vuser_full_name
= Fuser_full_name (NILP (tem
)? make_number (geteuid())
160 p
= (unsigned char *) getenv ("NAME");
162 Vuser_full_name
= build_string (p
);
163 else if (NILP (Vuser_full_name
))
164 Vuser_full_name
= build_string ("unknown");
167 DEFUN ("char-to-string", Fchar_to_string
, Schar_to_string
, 1, 1, 0,
168 doc
: /* Convert arg CHAR to a string containing that character.
169 usage: (char-to-string CHAR) */)
171 Lisp_Object character
;
174 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
176 CHECK_NUMBER (character
);
178 len
= (SINGLE_BYTE_CHAR_P (XFASTINT (character
))
179 ? (*str
= (unsigned char)(XFASTINT (character
)), 1)
180 : char_to_string (XFASTINT (character
), str
));
181 return make_string_from_bytes (str
, 1, len
);
184 DEFUN ("string-to-char", Fstring_to_char
, Sstring_to_char
, 1, 1, 0,
185 doc
: /* Convert arg STRING to a character, the first character of that string.
186 A multibyte character is handled correctly. */)
188 register Lisp_Object string
;
190 register Lisp_Object val
;
191 register struct Lisp_String
*p
;
192 CHECK_STRING (string
);
193 p
= XSTRING (string
);
196 if (STRING_MULTIBYTE (string
))
197 XSETFASTINT (val
, STRING_CHAR (p
->data
, STRING_BYTES (p
)));
199 XSETFASTINT (val
, p
->data
[0]);
202 XSETFASTINT (val
, 0);
207 buildmark (charpos
, bytepos
)
208 int charpos
, bytepos
;
210 register Lisp_Object mark
;
211 mark
= Fmake_marker ();
212 set_marker_both (mark
, Qnil
, charpos
, bytepos
);
216 DEFUN ("point", Fpoint
, Spoint
, 0, 0, 0,
217 doc
: /* Return value of point, as an integer.
218 Beginning of buffer is position (point-min). */)
222 XSETFASTINT (temp
, PT
);
226 DEFUN ("point-marker", Fpoint_marker
, Spoint_marker
, 0, 0, 0,
227 doc
: /* Return value of point, as a marker object. */)
230 return buildmark (PT
, PT_BYTE
);
234 clip_to_bounds (lower
, num
, upper
)
235 int lower
, num
, upper
;
239 else if (num
> upper
)
245 DEFUN ("goto-char", Fgoto_char
, Sgoto_char
, 1, 1, "NGoto char: ",
246 doc
: /* Set point to POSITION, a number or marker.
247 Beginning of buffer is position (point-min), end is (point-max).
248 If the position is in the middle of a multibyte form,
249 the actual point is set at the head of the multibyte form
250 except in the case that `enable-multibyte-characters' is nil. */)
252 register Lisp_Object position
;
256 if (MARKERP (position
)
257 && current_buffer
== XMARKER (position
)->buffer
)
259 pos
= marker_position (position
);
261 SET_PT_BOTH (BEGV
, BEGV_BYTE
);
263 SET_PT_BOTH (ZV
, ZV_BYTE
);
265 SET_PT_BOTH (pos
, marker_byte_position (position
));
270 CHECK_NUMBER_COERCE_MARKER (position
);
272 pos
= clip_to_bounds (BEGV
, XINT (position
), ZV
);
278 /* Return the start or end position of the region.
279 BEGINNINGP non-zero means return the start.
280 If there is no region active, signal an error. */
283 region_limit (beginningp
)
286 extern Lisp_Object Vmark_even_if_inactive
; /* Defined in callint.c. */
289 if (!NILP (Vtransient_mark_mode
)
290 && NILP (Vmark_even_if_inactive
)
291 && NILP (current_buffer
->mark_active
))
292 Fsignal (Qmark_inactive
, Qnil
);
294 m
= Fmarker_position (current_buffer
->mark
);
296 error ("There is no region now");
298 if ((PT
< XFASTINT (m
)) == beginningp
)
299 m
= make_number (PT
);
303 DEFUN ("region-beginning", Fregion_beginning
, Sregion_beginning
, 0, 0, 0,
304 doc
: /* Return position of beginning of region, as an integer. */)
307 return region_limit (1);
310 DEFUN ("region-end", Fregion_end
, Sregion_end
, 0, 0, 0,
311 doc
: /* Return position of end of region, as an integer. */)
314 return region_limit (0);
317 DEFUN ("mark-marker", Fmark_marker
, Smark_marker
, 0, 0, 0,
318 doc
: /* Return this buffer's mark, as a marker object.
319 Watch out! Moving this marker changes the mark position.
320 If you set the marker not to point anywhere, the buffer will have no mark. */)
323 return current_buffer
->mark
;
327 #if 0 /* Not used. */
329 /* Return nonzero if POS1 and POS2 have the same value
330 for the text property PROP. */
333 char_property_eq (prop
, pos1
, pos2
)
335 Lisp_Object pos1
, pos2
;
337 Lisp_Object pval1
, pval2
;
339 pval1
= Fget_char_property (pos1
, prop
, Qnil
);
340 pval2
= Fget_char_property (pos2
, prop
, Qnil
);
342 return EQ (pval1
, pval2
);
347 /* Return the direction from which the text-property PROP would be
348 inherited by any new text inserted at POS: 1 if it would be
349 inherited from the char after POS, -1 if it would be inherited from
350 the char before POS, and 0 if from neither. */
353 text_property_stickiness (prop
, pos
)
357 Lisp_Object prev_pos
, front_sticky
;
358 int is_rear_sticky
= 1, is_front_sticky
= 0; /* defaults */
360 if (XINT (pos
) > BEGV
)
361 /* Consider previous character. */
363 Lisp_Object rear_non_sticky
;
365 prev_pos
= make_number (XINT (pos
) - 1);
366 rear_non_sticky
= Fget_text_property (prev_pos
, Qrear_nonsticky
, Qnil
);
368 if (!NILP (CONSP (rear_non_sticky
)
369 ? Fmemq (prop
, rear_non_sticky
)
371 /* PROP is rear-non-sticky. */
375 /* Consider following character. */
376 front_sticky
= Fget_text_property (pos
, Qfront_sticky
, Qnil
);
378 if (EQ (front_sticky
, Qt
)
379 || (CONSP (front_sticky
)
380 && !NILP (Fmemq (prop
, front_sticky
))))
381 /* PROP is inherited from after. */
384 /* Simple cases, where the properties are consistent. */
385 if (is_rear_sticky
&& !is_front_sticky
)
387 else if (!is_rear_sticky
&& is_front_sticky
)
389 else if (!is_rear_sticky
&& !is_front_sticky
)
392 /* The stickiness properties are inconsistent, so we have to
393 disambiguate. Basically, rear-sticky wins, _except_ if the
394 property that would be inherited has a value of nil, in which case
395 front-sticky wins. */
396 if (XINT (pos
) == BEGV
|| NILP (Fget_text_property (prev_pos
, prop
, Qnil
)))
403 /* Find the field surrounding POS in *BEG and *END. If POS is nil,
404 the value of point is used instead. If BEG or END null,
405 means don't store the beginning or end of the field.
407 If MERGE_AT_BOUNDARY is nonzero, then if POS is at the very first
408 position of a field, then the beginning of the previous field is
409 returned instead of the beginning of POS's field (since the end of a
410 field is actually also the beginning of the next input field, this
411 behavior is sometimes useful). Additionally in the MERGE_AT_BOUNDARY
412 true case, if two fields are separated by a field with the special
413 value `boundary', and POS lies within it, then the two separated
414 fields are considered to be adjacent, and POS between them, when
415 finding the beginning and ending of the "merged" field.
417 Either BEG or END may be 0, in which case the corresponding value
421 find_field (pos
, merge_at_boundary
, beg
, end
)
423 Lisp_Object merge_at_boundary
;
426 /* Fields right before and after the point. */
427 Lisp_Object before_field
, after_field
;
428 /* If the fields came from overlays, the associated overlays.
429 Qnil means they came from text-properties. */
430 Lisp_Object before_overlay
= Qnil
, after_overlay
= Qnil
;
431 /* 1 if POS counts as the start of a field. */
432 int at_field_start
= 0;
433 /* 1 if POS counts as the end of a field. */
434 int at_field_end
= 0;
437 XSETFASTINT (pos
, PT
);
439 CHECK_NUMBER_COERCE_MARKER (pos
);
442 = get_char_property_and_overlay (pos
, Qfield
, Qnil
, &after_overlay
);
444 = (XFASTINT (pos
) > BEGV
445 ? get_char_property_and_overlay (make_number (XINT (pos
) - 1),
450 /* See if we need to handle the case where MERGE_AT_BOUNDARY is nil
451 and POS is at beginning of a field, which can also be interpreted
452 as the end of the previous field. Note that the case where if
453 MERGE_AT_BOUNDARY is non-nil (see function comment) is actually the
454 more natural one; then we avoid treating the beginning of a field
456 if (NILP (merge_at_boundary
) && !EQ (after_field
, before_field
))
457 /* We are at a boundary, see which direction is inclusive. We
458 decide by seeing which field the `field' property sticks to. */
460 /* -1 means insertions go into before_field, 1 means they go
461 into after_field, 0 means neither. */
463 /* Whether the before/after_field come from overlays. */
464 int bop
= !NILP (before_overlay
);
465 int aop
= !NILP (after_overlay
);
467 if (bop
&& XMARKER (OVERLAY_END (before_overlay
))->insertion_type
== 1)
468 /* before_field is from an overlay, which expands upon
469 end-insertions. Note that it's possible for after_overlay to
470 also eat insertions here, but then they will overlap, and
471 there's not much we can do. */
474 && XMARKER (OVERLAY_START (after_overlay
))->insertion_type
== 0)
475 /* after_field is from an overlay, which expand to contain
479 /* Both fields come from overlays, but neither will contain any
483 /* before_field is an overlay that won't eat any insertion, but
484 after_field is from a text-property. Assume that the
485 text-property continues underneath the overlay, and so will
486 be inherited by any insertion, regardless of any stickiness
490 /* Similarly, when after_field is the overlay. */
493 /* Both fields come from text-properties. Look for explicit
494 stickiness properties. */
495 stickiness
= text_property_stickiness (Qfield
, pos
);
499 else if (stickiness
< 0)
502 /* STICKINESS == 0 means that any inserted text will get a
503 `field' char-property of nil, so check to see if that
504 matches either of the adjacent characters (this being a
505 kind of "stickiness by default"). */
507 if (NILP (before_field
))
508 at_field_end
= 1; /* Sticks to the left. */
509 else if (NILP (after_field
))
510 at_field_start
= 1; /* Sticks to the right. */
514 /* Note about special `boundary' fields:
516 Consider the case where the point (`.') is between the fields `x' and `y':
520 In this situation, if merge_at_boundary is true, we consider the
521 `x' and `y' fields as forming one big merged field, and so the end
522 of the field is the end of `y'.
524 However, if `x' and `y' are separated by a special `boundary' field
525 (a field with a `field' char-property of 'boundary), then we ignore
526 this special field when merging adjacent fields. Here's the same
527 situation, but with a `boundary' field between the `x' and `y' fields:
531 Here, if point is at the end of `x', the beginning of `y', or
532 anywhere in-between (within the `boundary' field), we merge all
533 three fields and consider the beginning as being the beginning of
534 the `x' field, and the end as being the end of the `y' field. */
539 /* POS is at the edge of a field, and we should consider it as
540 the beginning of the following field. */
541 *beg
= XFASTINT (pos
);
543 /* Find the previous field boundary. */
545 if (!NILP (merge_at_boundary
) && EQ (before_field
, Qboundary
))
546 /* Skip a `boundary' field. */
547 pos
= Fprevious_single_char_property_change (pos
, Qfield
, Qnil
,Qnil
);
549 pos
= Fprevious_single_char_property_change (pos
, Qfield
, Qnil
, Qnil
);
550 *beg
= NILP (pos
) ? BEGV
: XFASTINT (pos
);
557 /* POS is at the edge of a field, and we should consider it as
558 the end of the previous field. */
559 *end
= XFASTINT (pos
);
561 /* Find the next field boundary. */
563 if (!NILP (merge_at_boundary
) && EQ (after_field
, Qboundary
))
564 /* Skip a `boundary' field. */
565 pos
= Fnext_single_char_property_change (pos
, Qfield
, Qnil
, Qnil
);
567 pos
= Fnext_single_char_property_change (pos
, Qfield
, Qnil
, Qnil
);
568 *end
= NILP (pos
) ? ZV
: XFASTINT (pos
);
574 DEFUN ("delete-field", Fdelete_field
, Sdelete_field
, 0, 1, 0,
575 doc
: /* Delete the field surrounding POS.
576 A field is a region of text with the same `field' property.
577 If POS is nil, the value of point is used for POS. */)
582 find_field (pos
, Qnil
, &beg
, &end
);
584 del_range (beg
, end
);
588 DEFUN ("field-string", Ffield_string
, Sfield_string
, 0, 1, 0,
589 doc
: /* Return the contents of the field surrounding POS as a string.
590 A field is a region of text with the same `field' property.
591 If POS is nil, the value of point is used for POS. */)
596 find_field (pos
, Qnil
, &beg
, &end
);
597 return make_buffer_string (beg
, end
, 1);
600 DEFUN ("field-string-no-properties", Ffield_string_no_properties
, Sfield_string_no_properties
, 0, 1, 0,
601 doc
: /* Return the contents of the field around POS, without text-properties.
602 A field is a region of text with the same `field' property.
603 If POS is nil, the value of point is used for POS. */)
608 find_field (pos
, Qnil
, &beg
, &end
);
609 return make_buffer_string (beg
, end
, 0);
612 DEFUN ("field-beginning", Ffield_beginning
, Sfield_beginning
, 0, 2, 0,
613 doc
: /* Return the beginning of the field surrounding POS.
614 A field is a region of text with the same `field' property.
615 If POS is nil, the value of point is used for POS.
616 If ESCAPE-FROM-EDGE is non-nil and POS is at the beginning of its
617 field, then the beginning of the *previous* field is returned. */)
618 (pos
, escape_from_edge
)
619 Lisp_Object pos
, escape_from_edge
;
622 find_field (pos
, escape_from_edge
, &beg
, 0);
623 return make_number (beg
);
626 DEFUN ("field-end", Ffield_end
, Sfield_end
, 0, 2, 0,
627 doc
: /* Return the end of the field surrounding POS.
628 A field is a region of text with the same `field' property.
629 If POS is nil, the value of point is used for POS.
630 If ESCAPE-FROM-EDGE is non-nil and POS is at the end of its field,
631 then the end of the *following* field is returned. */)
632 (pos
, escape_from_edge
)
633 Lisp_Object pos
, escape_from_edge
;
636 find_field (pos
, escape_from_edge
, 0, &end
);
637 return make_number (end
);
640 DEFUN ("constrain-to-field", Fconstrain_to_field
, Sconstrain_to_field
, 2, 5, 0,
641 doc
: /* Return the position closest to NEW-POS that is in the same field as OLD-POS.
643 A field is a region of text with the same `field' property.
644 If NEW-POS is nil, then the current point is used instead, and set to the
645 constrained position if that is different.
647 If OLD-POS is at the boundary of two fields, then the allowable
648 positions for NEW-POS depends on the value of the optional argument
649 ESCAPE-FROM-EDGE: If ESCAPE-FROM-EDGE is nil, then NEW-POS is
650 constrained to the field that has the same `field' char-property
651 as any new characters inserted at OLD-POS, whereas if ESCAPE-FROM-EDGE
652 is non-nil, NEW-POS is constrained to the union of the two adjacent
653 fields. Additionally, if two fields are separated by another field with
654 the special value `boundary', then any point within this special field is
655 also considered to be `on the boundary'.
657 If the optional argument ONLY-IN-LINE is non-nil and constraining
658 NEW-POS would move it to a different line, NEW-POS is returned
659 unconstrained. This useful for commands that move by line, like
660 \\[next-line] or \\[beginning-of-line], which should generally respect field boundaries
661 only in the case where they can still move to the right line.
663 If the optional argument INHIBIT-CAPTURE-PROPERTY is non-nil, and OLD-POS has
664 a non-nil property of that name, then any field boundaries are ignored.
666 Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
667 (new_pos
, old_pos
, escape_from_edge
, only_in_line
, inhibit_capture_property
)
668 Lisp_Object new_pos
, old_pos
;
669 Lisp_Object escape_from_edge
, only_in_line
, inhibit_capture_property
;
671 /* If non-zero, then the original point, before re-positioning. */
675 /* Use the current point, and afterwards, set it. */
678 XSETFASTINT (new_pos
, PT
);
681 if (NILP (Vinhibit_field_text_motion
)
682 && !EQ (new_pos
, old_pos
)
683 && (!NILP (Fget_char_property (new_pos
, Qfield
, Qnil
))
684 || !NILP (Fget_char_property (old_pos
, Qfield
, Qnil
)))
685 && (NILP (inhibit_capture_property
)
686 || NILP (Fget_char_property(old_pos
, inhibit_capture_property
, Qnil
))))
687 /* NEW_POS is not within the same field as OLD_POS; try to
688 move NEW_POS so that it is. */
691 Lisp_Object field_bound
;
693 CHECK_NUMBER_COERCE_MARKER (new_pos
);
694 CHECK_NUMBER_COERCE_MARKER (old_pos
);
696 fwd
= (XFASTINT (new_pos
) > XFASTINT (old_pos
));
699 field_bound
= Ffield_end (old_pos
, escape_from_edge
);
701 field_bound
= Ffield_beginning (old_pos
, escape_from_edge
);
703 if (/* See if ESCAPE_FROM_EDGE caused FIELD_BOUND to jump to the
704 other side of NEW_POS, which would mean that NEW_POS is
705 already acceptable, and it's not necessary to constrain it
707 ((XFASTINT (field_bound
) < XFASTINT (new_pos
)) ? fwd
: !fwd
)
708 /* NEW_POS should be constrained, but only if either
709 ONLY_IN_LINE is nil (in which case any constraint is OK),
710 or NEW_POS and FIELD_BOUND are on the same line (in which
711 case the constraint is OK even if ONLY_IN_LINE is non-nil). */
712 && (NILP (only_in_line
)
713 /* This is the ONLY_IN_LINE case, check that NEW_POS and
714 FIELD_BOUND are on the same line by seeing whether
715 there's an intervening newline or not. */
716 || (scan_buffer ('\n',
717 XFASTINT (new_pos
), XFASTINT (field_bound
),
718 fwd
? -1 : 1, &shortage
, 1),
720 /* Constrain NEW_POS to FIELD_BOUND. */
721 new_pos
= field_bound
;
723 if (orig_point
&& XFASTINT (new_pos
) != orig_point
)
724 /* The NEW_POS argument was originally nil, so automatically set PT. */
725 SET_PT (XFASTINT (new_pos
));
732 DEFUN ("line-beginning-position",
733 Fline_beginning_position
, Sline_beginning_position
, 0, 1, 0,
734 doc
: /* Return the character position of the first character on the current line.
735 With argument N not nil or 1, move forward N - 1 lines first.
736 If scan reaches end of buffer, return that position.
738 The scan does not cross a field boundary unless doing so would move
739 beyond there to a different line; if N is nil or 1, and scan starts at a
740 field boundary, the scan stops as soon as it starts. To ignore field
741 boundaries bind `inhibit-field-text-motion' to t.
743 This function does not move point. */)
747 int orig
, orig_byte
, end
;
756 Fforward_line (make_number (XINT (n
) - 1));
759 SET_PT_BOTH (orig
, orig_byte
);
761 /* Return END constrained to the current input field. */
762 return Fconstrain_to_field (make_number (end
), make_number (orig
),
763 XINT (n
) != 1 ? Qt
: Qnil
,
767 DEFUN ("line-end-position", Fline_end_position
, Sline_end_position
, 0, 1, 0,
768 doc
: /* Return the character position of the last character on the current line.
769 With argument N not nil or 1, move forward N - 1 lines first.
770 If scan reaches end of buffer, return that position.
772 The scan does not cross a field boundary unless doing so would move
773 beyond there to a different line; if N is nil or 1, and scan starts at a
774 field boundary, the scan stops as soon as it starts. To ignore field
775 boundaries bind `inhibit-field-text-motion' to t.
777 This function does not move point. */)
789 end_pos
= find_before_next_newline (orig
, 0, XINT (n
) - (XINT (n
) <= 0));
791 /* Return END_POS constrained to the current input field. */
792 return Fconstrain_to_field (make_number (end_pos
), make_number (orig
),
798 save_excursion_save ()
800 int visible
= (XBUFFER (XWINDOW (selected_window
)->buffer
)
803 return Fcons (Fpoint_marker (),
804 Fcons (Fcopy_marker (current_buffer
->mark
, Qnil
),
805 Fcons (visible
? Qt
: Qnil
,
806 Fcons (current_buffer
->mark_active
,
811 save_excursion_restore (info
)
814 Lisp_Object tem
, tem1
, omark
, nmark
;
815 struct gcpro gcpro1
, gcpro2
, gcpro3
;
818 tem
= Fmarker_buffer (XCAR (info
));
819 /* If buffer being returned to is now deleted, avoid error */
820 /* Otherwise could get error here while unwinding to top level
822 /* In that case, Fmarker_buffer returns nil now. */
826 omark
= nmark
= Qnil
;
827 GCPRO3 (info
, omark
, nmark
);
834 unchain_marker (tem
);
839 omark
= Fmarker_position (current_buffer
->mark
);
840 Fset_marker (current_buffer
->mark
, tem
, Fcurrent_buffer ());
841 nmark
= Fmarker_position (tem
);
842 unchain_marker (tem
);
846 visible_p
= !NILP (XCAR (info
));
848 #if 0 /* We used to make the current buffer visible in the selected window
849 if that was true previously. That avoids some anomalies.
850 But it creates others, and it wasn't documented, and it is simpler
851 and cleaner never to alter the window/buffer connections. */
854 && current_buffer
!= XBUFFER (XWINDOW (selected_window
)->buffer
))
855 Fswitch_to_buffer (Fcurrent_buffer (), Qnil
);
861 tem1
= current_buffer
->mark_active
;
862 current_buffer
->mark_active
= tem
;
864 if (!NILP (Vrun_hooks
))
866 /* If mark is active now, and either was not active
867 or was at a different place, run the activate hook. */
868 if (! NILP (current_buffer
->mark_active
))
870 if (! EQ (omark
, nmark
))
871 call1 (Vrun_hooks
, intern ("activate-mark-hook"));
873 /* If mark has ceased to be active, run deactivate hook. */
874 else if (! NILP (tem1
))
875 call1 (Vrun_hooks
, intern ("deactivate-mark-hook"));
878 /* If buffer was visible in a window, and a different window was
879 selected, and the old selected window is still showing this
880 buffer, restore point in that window. */
883 && !EQ (tem
, selected_window
)
884 && (tem1
= XWINDOW (tem
)->buffer
,
885 (/* Window is live... */
887 /* ...and it shows the current buffer. */
888 && XBUFFER (tem1
) == current_buffer
)))
889 Fset_window_point (tem
, make_number (PT
));
895 DEFUN ("save-excursion", Fsave_excursion
, Ssave_excursion
, 0, UNEVALLED
, 0,
896 doc
: /* Save point, mark, and current buffer; execute BODY; restore those things.
897 Executes BODY just like `progn'.
898 The values of point, mark and the current buffer are restored
899 even in case of abnormal exit (throw or error).
900 The state of activation of the mark is also restored.
902 This construct does not save `deactivate-mark', and therefore
903 functions that change the buffer will still cause deactivation
904 of the mark at the end of the command. To prevent that, bind
905 `deactivate-mark' with `let'.
907 usage: (save-excursion &rest BODY) */)
911 register Lisp_Object val
;
912 int count
= specpdl_ptr
- specpdl
;
914 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
917 return unbind_to (count
, val
);
920 DEFUN ("save-current-buffer", Fsave_current_buffer
, Ssave_current_buffer
, 0, UNEVALLED
, 0,
921 doc
: /* Save the current buffer; execute BODY; restore the current buffer.
922 Executes BODY just like `progn'.
923 usage: (save-current-buffer &rest BODY) */)
928 int count
= specpdl_ptr
- specpdl
;
930 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
933 return unbind_to (count
, val
);
936 DEFUN ("buffer-size", Fbufsize
, Sbufsize
, 0, 1, 0,
937 doc
: /* Return the number of characters in the current buffer.
938 If BUFFER, return the number of characters in that buffer instead. */)
943 return make_number (Z
- BEG
);
946 CHECK_BUFFER (buffer
);
947 return make_number (BUF_Z (XBUFFER (buffer
))
948 - BUF_BEG (XBUFFER (buffer
)));
952 DEFUN ("point-min", Fpoint_min
, Spoint_min
, 0, 0, 0,
953 doc
: /* Return the minimum permissible value of point in the current buffer.
954 This is 1, unless narrowing (a buffer restriction) is in effect. */)
958 XSETFASTINT (temp
, BEGV
);
962 DEFUN ("point-min-marker", Fpoint_min_marker
, Spoint_min_marker
, 0, 0, 0,
963 doc
: /* Return a marker to the minimum permissible value of point in this buffer.
964 This is the beginning, unless narrowing (a buffer restriction) is in effect. */)
967 return buildmark (BEGV
, BEGV_BYTE
);
970 DEFUN ("point-max", Fpoint_max
, Spoint_max
, 0, 0, 0,
971 doc
: /* Return the maximum permissible value of point in the current buffer.
972 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
973 is in effect, in which case it is less. */)
977 XSETFASTINT (temp
, ZV
);
981 DEFUN ("point-max-marker", Fpoint_max_marker
, Spoint_max_marker
, 0, 0, 0,
982 doc
: /* Return a marker to the maximum permissible value of point in this buffer.
983 This is (1+ (buffer-size)), unless narrowing (a buffer restriction)
984 is in effect, in which case it is less. */)
987 return buildmark (ZV
, ZV_BYTE
);
990 DEFUN ("gap-position", Fgap_position
, Sgap_position
, 0, 0, 0,
991 doc
: /* Return the position of the gap, in the current buffer.
992 See also `gap-size'. */)
996 XSETFASTINT (temp
, GPT
);
1000 DEFUN ("gap-size", Fgap_size
, Sgap_size
, 0, 0, 0,
1001 doc
: /* Return the size of the current buffer's gap.
1002 See also `gap-position'. */)
1006 XSETFASTINT (temp
, GAP_SIZE
);
1010 DEFUN ("position-bytes", Fposition_bytes
, Sposition_bytes
, 1, 1, 0,
1011 doc
: /* Return the byte position for character position POSITION.
1012 If POSITION is out of range, the value is nil. */)
1014 Lisp_Object position
;
1016 CHECK_NUMBER_COERCE_MARKER (position
);
1017 if (XINT (position
) < BEG
|| XINT (position
) > Z
)
1019 return make_number (CHAR_TO_BYTE (XINT (position
)));
1022 DEFUN ("byte-to-position", Fbyte_to_position
, Sbyte_to_position
, 1, 1, 0,
1023 doc
: /* Return the character position for byte position BYTEPOS.
1024 If BYTEPOS is out of range, the value is nil. */)
1026 Lisp_Object bytepos
;
1028 CHECK_NUMBER (bytepos
);
1029 if (XINT (bytepos
) < BEG_BYTE
|| XINT (bytepos
) > Z_BYTE
)
1031 return make_number (BYTE_TO_CHAR (XINT (bytepos
)));
1034 DEFUN ("following-char", Ffollowing_char
, Sfollowing_char
, 0, 0, 0,
1035 doc
: /* Return the character following point, as a number.
1036 At the end of the buffer or accessible region, return 0. */)
1041 XSETFASTINT (temp
, 0);
1043 XSETFASTINT (temp
, FETCH_CHAR (PT_BYTE
));
1047 DEFUN ("preceding-char", Fprevious_char
, Sprevious_char
, 0, 0, 0,
1048 doc
: /* Return the character preceding point, as a number.
1049 At the beginning of the buffer or accessible region, return 0. */)
1054 XSETFASTINT (temp
, 0);
1055 else if (!NILP (current_buffer
->enable_multibyte_characters
))
1059 XSETFASTINT (temp
, FETCH_CHAR (pos
));
1062 XSETFASTINT (temp
, FETCH_BYTE (PT_BYTE
- 1));
1066 DEFUN ("bobp", Fbobp
, Sbobp
, 0, 0, 0,
1067 doc
: /* Return t if point is at the beginning of the buffer.
1068 If the buffer is narrowed, this means the beginning of the narrowed part. */)
1076 DEFUN ("eobp", Feobp
, Seobp
, 0, 0, 0,
1077 doc
: /* Return t if point is at the end of the buffer.
1078 If the buffer is narrowed, this means the end of the narrowed part. */)
1086 DEFUN ("bolp", Fbolp
, Sbolp
, 0, 0, 0,
1087 doc
: /* Return t if point is at the beginning of a line. */)
1090 if (PT
== BEGV
|| FETCH_BYTE (PT_BYTE
- 1) == '\n')
1095 DEFUN ("eolp", Feolp
, Seolp
, 0, 0, 0,
1096 doc
: /* Return t if point is at the end of a line.
1097 `End of a line' includes point being at the end of the buffer. */)
1100 if (PT
== ZV
|| FETCH_BYTE (PT_BYTE
) == '\n')
1105 DEFUN ("char-after", Fchar_after
, Schar_after
, 0, 1, 0,
1106 doc
: /* Return character in current buffer at position POS.
1107 POS is an integer or a marker.
1108 If POS is out of range, the value is nil. */)
1112 register int pos_byte
;
1117 XSETFASTINT (pos
, PT
);
1122 pos_byte
= marker_byte_position (pos
);
1123 if (pos_byte
< BEGV_BYTE
|| pos_byte
>= ZV_BYTE
)
1128 CHECK_NUMBER_COERCE_MARKER (pos
);
1129 if (XINT (pos
) < BEGV
|| XINT (pos
) >= ZV
)
1132 pos_byte
= CHAR_TO_BYTE (XINT (pos
));
1135 return make_number (FETCH_CHAR (pos_byte
));
1138 DEFUN ("char-before", Fchar_before
, Schar_before
, 0, 1, 0,
1139 doc
: /* Return character in current buffer preceding position POS.
1140 POS is an integer or a marker.
1141 If POS is out of range, the value is nil. */)
1145 register Lisp_Object val
;
1146 register int pos_byte
;
1151 XSETFASTINT (pos
, PT
);
1156 pos_byte
= marker_byte_position (pos
);
1158 if (pos_byte
<= BEGV_BYTE
|| pos_byte
> ZV_BYTE
)
1163 CHECK_NUMBER_COERCE_MARKER (pos
);
1165 if (XINT (pos
) <= BEGV
|| XINT (pos
) > ZV
)
1168 pos_byte
= CHAR_TO_BYTE (XINT (pos
));
1171 if (!NILP (current_buffer
->enable_multibyte_characters
))
1174 XSETFASTINT (val
, FETCH_CHAR (pos_byte
));
1179 XSETFASTINT (val
, FETCH_BYTE (pos_byte
));
1184 DEFUN ("user-login-name", Fuser_login_name
, Suser_login_name
, 0, 1, 0,
1185 doc
: /* Return the name under which the user logged in, as a string.
1186 This is based on the effective uid, not the real uid.
1187 Also, if the environment variable LOGNAME or USER is set,
1188 that determines the value of this function.
1190 If optional argument UID is an integer, return the login name of the user
1191 with that uid, or nil if there is no such user. */)
1197 /* Set up the user name info if we didn't do it before.
1198 (That can happen if Emacs is dumpable
1199 but you decide to run `temacs -l loadup' and not dump. */
1200 if (INTEGERP (Vuser_login_name
))
1204 return Vuser_login_name
;
1207 pw
= (struct passwd
*) getpwuid (XINT (uid
));
1208 return (pw
? build_string (pw
->pw_name
) : Qnil
);
1211 DEFUN ("user-real-login-name", Fuser_real_login_name
, Suser_real_login_name
,
1213 doc
: /* Return the name of the user's real uid, as a string.
1214 This ignores the environment variables LOGNAME and USER, so it differs from
1215 `user-login-name' when running under `su'. */)
1218 /* Set up the user name info if we didn't do it before.
1219 (That can happen if Emacs is dumpable
1220 but you decide to run `temacs -l loadup' and not dump. */
1221 if (INTEGERP (Vuser_login_name
))
1223 return Vuser_real_login_name
;
1226 DEFUN ("user-uid", Fuser_uid
, Suser_uid
, 0, 0, 0,
1227 doc
: /* Return the effective uid of Emacs.
1228 Value is an integer or float, depending on the value. */)
1231 return make_fixnum_or_float (geteuid ());
1234 DEFUN ("user-real-uid", Fuser_real_uid
, Suser_real_uid
, 0, 0, 0,
1235 doc
: /* Return the real uid of Emacs.
1236 Value is an integer or float, depending on the value. */)
1239 return make_fixnum_or_float (getuid ());
1242 DEFUN ("user-full-name", Fuser_full_name
, Suser_full_name
, 0, 1, 0,
1243 doc
: /* Return the full name of the user logged in, as a string.
1244 If the full name corresponding to Emacs's userid is not known,
1247 If optional argument UID is an integer or float, return the full name
1248 of the user with that uid, or nil if there is no such user.
1249 If UID is a string, return the full name of the user with that login
1250 name, or nil if there is no such user. */)
1255 register unsigned char *p
, *q
;
1259 return Vuser_full_name
;
1260 else if (NUMBERP (uid
))
1261 pw
= (struct passwd
*) getpwuid ((uid_t
) XFLOATINT (uid
));
1262 else if (STRINGP (uid
))
1263 pw
= (struct passwd
*) getpwnam (XSTRING (uid
)->data
);
1265 error ("Invalid UID specification");
1270 p
= (unsigned char *) USER_FULL_NAME
;
1271 /* Chop off everything after the first comma. */
1272 q
= (unsigned char *) index (p
, ',');
1273 full
= make_string (p
, q
? q
- p
: strlen (p
));
1275 #ifdef AMPERSAND_FULL_NAME
1276 p
= XSTRING (full
)->data
;
1277 q
= (unsigned char *) index (p
, '&');
1278 /* Substitute the login name for the &, upcasing the first character. */
1281 register unsigned char *r
;
1284 login
= Fuser_login_name (make_number (pw
->pw_uid
));
1285 r
= (unsigned char *) alloca (strlen (p
) + XSTRING (login
)->size
+ 1);
1286 bcopy (p
, r
, q
- p
);
1288 strcat (r
, XSTRING (login
)->data
);
1289 r
[q
- p
] = UPCASE (r
[q
- p
]);
1291 full
= build_string (r
);
1293 #endif /* AMPERSAND_FULL_NAME */
1298 DEFUN ("system-name", Fsystem_name
, Ssystem_name
, 0, 0, 0,
1299 doc
: /* Return the name of the machine you are running on, as a string. */)
1302 return Vsystem_name
;
1305 /* For the benefit of callers who don't want to include lisp.h */
1310 if (STRINGP (Vsystem_name
))
1311 return (char *) XSTRING (Vsystem_name
)->data
;
1316 DEFUN ("emacs-pid", Femacs_pid
, Semacs_pid
, 0, 0, 0,
1317 doc
: /* Return the process ID of Emacs, as an integer. */)
1320 return make_number (getpid ());
1323 DEFUN ("current-time", Fcurrent_time
, Scurrent_time
, 0, 0, 0,
1324 doc
: /* Return the current time, as the number of seconds since 1970-01-01 00:00:00.
1325 The time is returned as a list of three integers. The first has the
1326 most significant 16 bits of the seconds, while the second has the
1327 least significant 16 bits. The third integer gives the microsecond
1330 The microsecond count is zero on systems that do not provide
1331 resolution finer than a second. */)
1335 Lisp_Object result
[3];
1338 XSETINT (result
[0], (EMACS_SECS (t
) >> 16) & 0xffff);
1339 XSETINT (result
[1], (EMACS_SECS (t
) >> 0) & 0xffff);
1340 XSETINT (result
[2], EMACS_USECS (t
));
1342 return Flist (3, result
);
1347 lisp_time_argument (specified_time
, result
, usec
)
1348 Lisp_Object specified_time
;
1352 if (NILP (specified_time
))
1359 *usec
= EMACS_USECS (t
);
1360 *result
= EMACS_SECS (t
);
1364 return time (result
) != -1;
1368 Lisp_Object high
, low
;
1369 high
= Fcar (specified_time
);
1370 CHECK_NUMBER (high
);
1371 low
= Fcdr (specified_time
);
1376 Lisp_Object usec_l
= Fcdr (low
);
1378 usec_l
= Fcar (usec_l
);
1383 CHECK_NUMBER (usec_l
);
1384 *usec
= XINT (usec_l
);
1392 *result
= (XINT (high
) << 16) + (XINT (low
) & 0xffff);
1393 return *result
>> 16 == XINT (high
);
1397 DEFUN ("float-time", Ffloat_time
, Sfloat_time
, 0, 1, 0,
1398 doc
: /* Return the current time, as a float number of seconds since the epoch.
1399 If an argument is given, it specifies a time to convert to float
1400 instead of the current time. The argument should have the forms:
1401 (HIGH . LOW) or (HIGH LOW USEC) or (HIGH LOW . USEC).
1402 Thus, you can use times obtained from `current-time'
1403 and from `file-attributes'.
1405 WARNING: Since the result is floating point, it may not be exact.
1406 Do not use this function if precise time stamps are required. */)
1408 Lisp_Object specified_time
;
1413 if (! lisp_time_argument (specified_time
, &sec
, &usec
))
1414 error ("Invalid time specification");
1416 return make_float ((sec
* 1e6
+ usec
) / 1e6
);
1419 /* Write information into buffer S of size MAXSIZE, according to the
1420 FORMAT of length FORMAT_LEN, using time information taken from *TP.
1421 Default to Universal Time if UT is nonzero, local time otherwise.
1422 Return the number of bytes written, not including the terminating
1423 '\0'. If S is NULL, nothing will be written anywhere; so to
1424 determine how many bytes would be written, use NULL for S and
1425 ((size_t) -1) for MAXSIZE.
1427 This function behaves like emacs_strftimeu, except it allows null
1430 emacs_memftimeu (s
, maxsize
, format
, format_len
, tp
, ut
)
1435 const struct tm
*tp
;
1440 /* Loop through all the null-terminated strings in the format
1441 argument. Normally there's just one null-terminated string, but
1442 there can be arbitrarily many, concatenated together, if the
1443 format contains '\0' bytes. emacs_strftimeu stops at the first
1444 '\0' byte so we must invoke it separately for each such string. */
1453 result
= emacs_strftimeu (s
, maxsize
, format
, tp
, ut
);
1457 if (result
== 0 && s
[0] != '\0')
1462 maxsize
-= result
+ 1;
1464 len
= strlen (format
);
1465 if (len
== format_len
)
1469 format_len
-= len
+ 1;
1473 DEFUN ("format-time-string", Fformat_time_string
, Sformat_time_string
, 1, 3, 0,
1474 doc
: /* Use FORMAT-STRING to format the time TIME, or now if omitted.
1475 TIME is specified as (HIGH LOW . IGNORED) or (HIGH . LOW), as returned by
1476 `current-time' or `file-attributes'.
1477 The third, optional, argument UNIVERSAL, if non-nil, means describe TIME
1478 as Universal Time; nil means describe TIME in the local time zone.
1479 The value is a copy of FORMAT-STRING, but with certain constructs replaced
1480 by text that describes the specified date and time in TIME:
1482 %Y is the year, %y within the century, %C the century.
1483 %G is the year corresponding to the ISO week, %g within the century.
1484 %m is the numeric month.
1485 %b and %h are the locale's abbreviated month name, %B the full name.
1486 %d is the day of the month, zero-padded, %e is blank-padded.
1487 %u is the numeric day of week from 1 (Monday) to 7, %w from 0 (Sunday) to 6.
1488 %a is the locale's abbreviated name of the day of week, %A the full name.
1489 %U is the week number starting on Sunday, %W starting on Monday,
1490 %V according to ISO 8601.
1491 %j is the day of the year.
1493 %H is the hour on a 24-hour clock, %I is on a 12-hour clock, %k is like %H
1494 only blank-padded, %l is like %I blank-padded.
1495 %p is the locale's equivalent of either AM or PM.
1498 %Z is the time zone name, %z is the numeric form.
1499 %s is the number of seconds since 1970-01-01 00:00:00 +0000.
1501 %c is the locale's date and time format.
1502 %x is the locale's "preferred" date format.
1503 %D is like "%m/%d/%y".
1505 %R is like "%H:%M", %T is like "%H:%M:%S", %r is like "%I:%M:%S %p".
1506 %X is the locale's "preferred" time format.
1508 Finally, %n is a newline, %t is a tab, %% is a literal %.
1510 Certain flags and modifiers are available with some format controls.
1511 The flags are `_', `-', `^' and `#'. For certain characters X,
1512 %_X is like %X, but padded with blanks; %-X is like %X,
1513 ut without padding. %^X is like %X but with all textual
1514 characters up-cased; %#X is like %X but with letter-case of
1515 all textual characters reversed.
1516 %NX (where N stands for an integer) is like %X,
1517 but takes up at least N (a number) positions.
1518 The modifiers are `E' and `O'. For certain characters X,
1519 %EX is a locale's alternative version of %X;
1520 %OX is like %X, but uses the locale's number symbols.
1522 For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z". */)
1523 (format_string
, time
, universal
)
1524 Lisp_Object format_string
, time
, universal
;
1529 int ut
= ! NILP (universal
);
1531 CHECK_STRING (format_string
);
1533 if (! lisp_time_argument (time
, &value
, NULL
))
1534 error ("Invalid time specification");
1536 format_string
= code_convert_string_norecord (format_string
,
1537 Vlocale_coding_system
, 1);
1539 /* This is probably enough. */
1540 size
= STRING_BYTES (XSTRING (format_string
)) * 6 + 50;
1542 tm
= ut
? gmtime (&value
) : localtime (&value
);
1544 error ("Specified time is not representable");
1546 synchronize_system_time_locale ();
1550 char *buf
= (char *) alloca (size
+ 1);
1554 result
= emacs_memftimeu (buf
, size
, XSTRING (format_string
)->data
,
1555 STRING_BYTES (XSTRING (format_string
)),
1557 if ((result
> 0 && result
< size
) || (result
== 0 && buf
[0] == '\0'))
1558 return code_convert_string_norecord (make_string (buf
, result
),
1559 Vlocale_coding_system
, 0);
1561 /* If buffer was too small, make it bigger and try again. */
1562 result
= emacs_memftimeu (NULL
, (size_t) -1,
1563 XSTRING (format_string
)->data
,
1564 STRING_BYTES (XSTRING (format_string
)),
1570 DEFUN ("decode-time", Fdecode_time
, Sdecode_time
, 0, 1, 0,
1571 doc
: /* Decode a time value as (SEC MINUTE HOUR DAY MONTH YEAR DOW DST ZONE).
1572 The optional SPECIFIED-TIME should be a list of (HIGH LOW . IGNORED)
1573 or (HIGH . LOW), as from `current-time' and `file-attributes', or `nil'
1574 to use the current time. The list has the following nine members:
1575 SEC is an integer between 0 and 60; SEC is 60 for a leap second, which
1576 only some operating systems support. MINUTE is an integer between 0 and 59.
1577 HOUR is an integer between 0 and 23. DAY is an integer between 1 and 31.
1578 MONTH is an integer between 1 and 12. YEAR is an integer indicating the
1579 four-digit year. DOW is the day of week, an integer between 0 and 6, where
1580 0 is Sunday. DST is t if daylight savings time is effect, otherwise nil.
1581 ZONE is an integer indicating the number of seconds east of Greenwich.
1582 (Note that Common Lisp has different meanings for DOW and ZONE.) */)
1584 Lisp_Object specified_time
;
1588 struct tm
*decoded_time
;
1589 Lisp_Object list_args
[9];
1591 if (! lisp_time_argument (specified_time
, &time_spec
, NULL
))
1592 error ("Invalid time specification");
1594 decoded_time
= localtime (&time_spec
);
1596 error ("Specified time is not representable");
1597 XSETFASTINT (list_args
[0], decoded_time
->tm_sec
);
1598 XSETFASTINT (list_args
[1], decoded_time
->tm_min
);
1599 XSETFASTINT (list_args
[2], decoded_time
->tm_hour
);
1600 XSETFASTINT (list_args
[3], decoded_time
->tm_mday
);
1601 XSETFASTINT (list_args
[4], decoded_time
->tm_mon
+ 1);
1602 XSETINT (list_args
[5], decoded_time
->tm_year
+ 1900);
1603 XSETFASTINT (list_args
[6], decoded_time
->tm_wday
);
1604 list_args
[7] = (decoded_time
->tm_isdst
)? Qt
: Qnil
;
1606 /* Make a copy, in case gmtime modifies the struct. */
1607 save_tm
= *decoded_time
;
1608 decoded_time
= gmtime (&time_spec
);
1609 if (decoded_time
== 0)
1610 list_args
[8] = Qnil
;
1612 XSETINT (list_args
[8], tm_diff (&save_tm
, decoded_time
));
1613 return Flist (9, list_args
);
1616 DEFUN ("encode-time", Fencode_time
, Sencode_time
, 6, MANY
, 0,
1617 doc
: /* Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time.
1618 This is the reverse operation of `decode-time', which see.
1619 ZONE defaults to the current time zone rule. This can
1620 be a string or t (as from `set-time-zone-rule'), or it can be a list
1621 \(as from `current-time-zone') or an integer (as from `decode-time')
1622 applied without consideration for daylight savings time.
1624 You can pass more than 7 arguments; then the first six arguments
1625 are used as SECOND through YEAR, and the *last* argument is used as ZONE.
1626 The intervening arguments are ignored.
1627 This feature lets (apply 'encode-time (decode-time ...)) work.
1629 Out-of-range values for SEC, MINUTE, HOUR, DAY, or MONTH are allowed;
1630 for example, a DAY of 0 means the day preceding the given month.
1631 Year numbers less than 100 are treated just like other year numbers.
1632 If you want them to stand for years in this century, you must do that yourself.
1634 usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */)
1637 register Lisp_Object
*args
;
1641 Lisp_Object zone
= (nargs
> 6 ? args
[nargs
- 1] : Qnil
);
1643 CHECK_NUMBER (args
[0]); /* second */
1644 CHECK_NUMBER (args
[1]); /* minute */
1645 CHECK_NUMBER (args
[2]); /* hour */
1646 CHECK_NUMBER (args
[3]); /* day */
1647 CHECK_NUMBER (args
[4]); /* month */
1648 CHECK_NUMBER (args
[5]); /* year */
1650 tm
.tm_sec
= XINT (args
[0]);
1651 tm
.tm_min
= XINT (args
[1]);
1652 tm
.tm_hour
= XINT (args
[2]);
1653 tm
.tm_mday
= XINT (args
[3]);
1654 tm
.tm_mon
= XINT (args
[4]) - 1;
1655 tm
.tm_year
= XINT (args
[5]) - 1900;
1661 time
= mktime (&tm
);
1666 char **oldenv
= environ
, **newenv
;
1670 else if (STRINGP (zone
))
1671 tzstring
= (char *) XSTRING (zone
)->data
;
1672 else if (INTEGERP (zone
))
1674 int abszone
= abs (XINT (zone
));
1675 sprintf (tzbuf
, "XXX%s%d:%02d:%02d", "-" + (XINT (zone
) < 0),
1676 abszone
/ (60*60), (abszone
/60) % 60, abszone
% 60);
1680 error ("Invalid time zone specification");
1682 /* Set TZ before calling mktime; merely adjusting mktime's returned
1683 value doesn't suffice, since that would mishandle leap seconds. */
1684 set_time_zone_rule (tzstring
);
1686 time
= mktime (&tm
);
1688 /* Restore TZ to previous value. */
1692 #ifdef LOCALTIME_CACHE
1697 if (time
== (time_t) -1)
1698 error ("Specified time is not representable");
1700 return make_time (time
);
1703 DEFUN ("current-time-string", Fcurrent_time_string
, Scurrent_time_string
, 0, 1, 0,
1704 doc
: /* Return the current time, as a human-readable string.
1705 Programs can use this function to decode a time,
1706 since the number of columns in each field is fixed.
1707 The format is `Sun Sep 16 01:03:52 1973'.
1708 However, see also the functions `decode-time' and `format-time-string'
1709 which provide a much more powerful and general facility.
1711 If an argument is given, it specifies a time to format
1712 instead of the current time. The argument should have the form:
1715 (HIGH LOW . IGNORED).
1716 Thus, you can use times obtained from `current-time'
1717 and from `file-attributes'. */)
1719 Lisp_Object specified_time
;
1725 if (! lisp_time_argument (specified_time
, &value
, NULL
))
1727 tem
= (char *) ctime (&value
);
1729 strncpy (buf
, tem
, 24);
1732 return build_string (buf
);
1735 #define TM_YEAR_BASE 1900
1737 /* Yield A - B, measured in seconds.
1738 This function is copied from the GNU C Library. */
1743 /* Compute intervening leap days correctly even if year is negative.
1744 Take care to avoid int overflow in leap day calculations,
1745 but it's OK to assume that A and B are close to each other. */
1746 int a4
= (a
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (a
->tm_year
& 3);
1747 int b4
= (b
->tm_year
>> 2) + (TM_YEAR_BASE
>> 2) - ! (b
->tm_year
& 3);
1748 int a100
= a4
/ 25 - (a4
% 25 < 0);
1749 int b100
= b4
/ 25 - (b4
% 25 < 0);
1750 int a400
= a100
>> 2;
1751 int b400
= b100
>> 2;
1752 int intervening_leap_days
= (a4
- b4
) - (a100
- b100
) + (a400
- b400
);
1753 int years
= a
->tm_year
- b
->tm_year
;
1754 int days
= (365 * years
+ intervening_leap_days
1755 + (a
->tm_yday
- b
->tm_yday
));
1756 return (60 * (60 * (24 * days
+ (a
->tm_hour
- b
->tm_hour
))
1757 + (a
->tm_min
- b
->tm_min
))
1758 + (a
->tm_sec
- b
->tm_sec
));
1761 DEFUN ("current-time-zone", Fcurrent_time_zone
, Scurrent_time_zone
, 0, 1, 0,
1762 doc
: /* Return the offset and name for the local time zone.
1763 This returns a list of the form (OFFSET NAME).
1764 OFFSET is an integer number of seconds ahead of UTC (east of Greenwich).
1765 A negative value means west of Greenwich.
1766 NAME is a string giving the name of the time zone.
1767 If an argument is given, it specifies when the time zone offset is determined
1768 instead of using the current time. The argument should have the form:
1771 (HIGH LOW . IGNORED).
1772 Thus, you can use times obtained from `current-time'
1773 and from `file-attributes'.
1775 Some operating systems cannot provide all this information to Emacs;
1776 in this case, `current-time-zone' returns a list containing nil for
1777 the data it can't find. */)
1779 Lisp_Object specified_time
;
1785 if (lisp_time_argument (specified_time
, &value
, NULL
)
1786 && (t
= gmtime (&value
)) != 0
1787 && (gmt
= *t
, t
= localtime (&value
)) != 0)
1789 int offset
= tm_diff (t
, &gmt
);
1794 s
= (char *)t
->tm_zone
;
1795 #else /* not HAVE_TM_ZONE */
1797 if (t
->tm_isdst
== 0 || t
->tm_isdst
== 1)
1798 s
= tzname
[t
->tm_isdst
];
1800 #endif /* not HAVE_TM_ZONE */
1802 #if defined HAVE_TM_ZONE || defined HAVE_TZNAME
1805 /* On Japanese w32, we can get a Japanese string as time
1806 zone name. Don't accept that. */
1808 for (p
= s
; *p
&& (isalnum ((unsigned char)*p
) || *p
== ' '); ++p
)
1817 /* No local time zone name is available; use "+-NNNN" instead. */
1818 int am
= (offset
< 0 ? -offset
: offset
) / 60;
1819 sprintf (buf
, "%c%02d%02d", (offset
< 0 ? '-' : '+'), am
/60, am
%60);
1822 return Fcons (make_number (offset
), Fcons (build_string (s
), Qnil
));
1825 return Fmake_list (make_number (2), Qnil
);
1828 /* This holds the value of `environ' produced by the previous
1829 call to Fset_time_zone_rule, or 0 if Fset_time_zone_rule
1830 has never been called. */
1831 static char **environbuf
;
1833 DEFUN ("set-time-zone-rule", Fset_time_zone_rule
, Sset_time_zone_rule
, 1, 1, 0,
1834 doc
: /* Set the local time zone using TZ, a string specifying a time zone rule.
1835 If TZ is nil, use implementation-defined default time zone information.
1836 If TZ is t, use Universal Time. */)
1844 else if (EQ (tz
, Qt
))
1849 tzstring
= (char *) XSTRING (tz
)->data
;
1852 set_time_zone_rule (tzstring
);
1855 environbuf
= environ
;
1860 #ifdef LOCALTIME_CACHE
1862 /* These two values are known to load tz files in buggy implementations,
1863 i.e. Solaris 1 executables running under either Solaris 1 or Solaris 2.
1864 Their values shouldn't matter in non-buggy implementations.
1865 We don't use string literals for these strings,
1866 since if a string in the environment is in readonly
1867 storage, it runs afoul of bugs in SVR4 and Solaris 2.3.
1868 See Sun bugs 1113095 and 1114114, ``Timezone routines
1869 improperly modify environment''. */
1871 static char set_time_zone_rule_tz1
[] = "TZ=GMT+0";
1872 static char set_time_zone_rule_tz2
[] = "TZ=GMT+1";
1876 /* Set the local time zone rule to TZSTRING.
1877 This allocates memory into `environ', which it is the caller's
1878 responsibility to free. */
1881 set_time_zone_rule (tzstring
)
1885 char **from
, **to
, **newenv
;
1887 /* Make the ENVIRON vector longer with room for TZSTRING. */
1888 for (from
= environ
; *from
; from
++)
1890 envptrs
= from
- environ
+ 2;
1891 newenv
= to
= (char **) xmalloc (envptrs
* sizeof (char *)
1892 + (tzstring
? strlen (tzstring
) + 4 : 0));
1894 /* Add TZSTRING to the end of environ, as a value for TZ. */
1897 char *t
= (char *) (to
+ envptrs
);
1899 strcat (t
, tzstring
);
1903 /* Copy the old environ vector elements into NEWENV,
1904 but don't copy the TZ variable.
1905 So we have only one definition of TZ, which came from TZSTRING. */
1906 for (from
= environ
; *from
; from
++)
1907 if (strncmp (*from
, "TZ=", 3) != 0)
1913 /* If we do have a TZSTRING, NEWENV points to the vector slot where
1914 the TZ variable is stored. If we do not have a TZSTRING,
1915 TO points to the vector slot which has the terminating null. */
1917 #ifdef LOCALTIME_CACHE
1919 /* In SunOS 4.1.3_U1 and 4.1.4, if TZ has a value like
1920 "US/Pacific" that loads a tz file, then changes to a value like
1921 "XXX0" that does not load a tz file, and then changes back to
1922 its original value, the last change is (incorrectly) ignored.
1923 Also, if TZ changes twice in succession to values that do
1924 not load a tz file, tzset can dump core (see Sun bug#1225179).
1925 The following code works around these bugs. */
1929 /* Temporarily set TZ to a value that loads a tz file
1930 and that differs from tzstring. */
1932 *newenv
= (strcmp (tzstring
, set_time_zone_rule_tz1
+ 3) == 0
1933 ? set_time_zone_rule_tz2
: set_time_zone_rule_tz1
);
1939 /* The implied tzstring is unknown, so temporarily set TZ to
1940 two different values that each load a tz file. */
1941 *to
= set_time_zone_rule_tz1
;
1944 *to
= set_time_zone_rule_tz2
;
1949 /* Now TZ has the desired value, and tzset can be invoked safely. */
1956 /* Insert NARGS Lisp objects in the array ARGS by calling INSERT_FUNC
1957 (if a type of object is Lisp_Int) or INSERT_FROM_STRING_FUNC (if a
1958 type of object is Lisp_String). INHERIT is passed to
1959 INSERT_FROM_STRING_FUNC as the last argument. */
1962 general_insert_function (insert_func
, insert_from_string_func
,
1963 inherit
, nargs
, args
)
1964 void (*insert_func
) P_ ((unsigned char *, int));
1965 void (*insert_from_string_func
) P_ ((Lisp_Object
, int, int, int, int, int));
1967 register Lisp_Object
*args
;
1969 register int argnum
;
1970 register Lisp_Object val
;
1972 for (argnum
= 0; argnum
< nargs
; argnum
++)
1978 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
1981 if (!NILP (current_buffer
->enable_multibyte_characters
))
1982 len
= CHAR_STRING (XFASTINT (val
), str
);
1985 str
[0] = (SINGLE_BYTE_CHAR_P (XINT (val
))
1987 : multibyte_char_to_unibyte (XINT (val
), Qnil
));
1990 (*insert_func
) (str
, len
);
1992 else if (STRINGP (val
))
1994 (*insert_from_string_func
) (val
, 0, 0,
1995 XSTRING (val
)->size
,
1996 STRING_BYTES (XSTRING (val
)),
2001 val
= wrong_type_argument (Qchar_or_string_p
, val
);
2015 /* Callers passing one argument to Finsert need not gcpro the
2016 argument "array", since the only element of the array will
2017 not be used after calling insert or insert_from_string, so
2018 we don't care if it gets trashed. */
2020 DEFUN ("insert", Finsert
, Sinsert
, 0, MANY
, 0,
2021 doc
: /* Insert the arguments, either strings or characters, at point.
2022 Point and before-insertion markers move forward to end up
2023 after the inserted text.
2024 Any other markers at the point of insertion remain before the text.
2026 If the current buffer is multibyte, unibyte strings are converted
2027 to multibyte for insertion (see `unibyte-char-to-multibyte').
2028 If the current buffer is unibyte, multibyte strings are converted
2029 to unibyte for insertion.
2031 usage: (insert &rest ARGS) */)
2034 register Lisp_Object
*args
;
2036 general_insert_function (insert
, insert_from_string
, 0, nargs
, args
);
2040 DEFUN ("insert-and-inherit", Finsert_and_inherit
, Sinsert_and_inherit
,
2042 doc
: /* Insert the arguments at point, inheriting properties from adjoining text.
2043 Point and before-insertion markers move forward to end up
2044 after the inserted text.
2045 Any other markers at the point of insertion remain before the text.
2047 If the current buffer is multibyte, unibyte strings are converted
2048 to multibyte for insertion (see `unibyte-char-to-multibyte').
2049 If the current buffer is unibyte, multibyte strings are converted
2050 to unibyte for insertion.
2052 usage: (insert-and-inherit &rest ARGS) */)
2055 register Lisp_Object
*args
;
2057 general_insert_function (insert_and_inherit
, insert_from_string
, 1,
2062 DEFUN ("insert-before-markers", Finsert_before_markers
, Sinsert_before_markers
, 0, MANY
, 0,
2063 doc
: /* Insert strings or characters at point, relocating markers after the text.
2064 Point and markers move forward to end up after the inserted text.
2066 If the current buffer is multibyte, unibyte strings are converted
2067 to multibyte for insertion (see `unibyte-char-to-multibyte').
2068 If the current buffer is unibyte, multibyte strings are converted
2069 to unibyte for insertion.
2071 usage: (insert-before-markers &rest ARGS) */)
2074 register Lisp_Object
*args
;
2076 general_insert_function (insert_before_markers
,
2077 insert_from_string_before_markers
, 0,
2082 DEFUN ("insert-before-markers-and-inherit", Finsert_and_inherit_before_markers
,
2083 Sinsert_and_inherit_before_markers
, 0, MANY
, 0,
2084 doc
: /* Insert text at point, relocating markers and inheriting properties.
2085 Point and markers move forward to end up after the inserted text.
2087 If the current buffer is multibyte, unibyte strings are converted
2088 to multibyte for insertion (see `unibyte-char-to-multibyte').
2089 If the current buffer is unibyte, multibyte strings are converted
2090 to unibyte for insertion.
2092 usage: (insert-before-markers-and-inherit &rest ARGS) */)
2095 register Lisp_Object
*args
;
2097 general_insert_function (insert_before_markers_and_inherit
,
2098 insert_from_string_before_markers
, 1,
2103 DEFUN ("insert-char", Finsert_char
, Sinsert_char
, 2, 3, 0,
2104 doc
: /* Insert COUNT (second arg) copies of CHARACTER (first arg).
2105 Both arguments are required.
2106 Point, and before-insertion markers, are relocated as in the function `insert'.
2107 The optional third arg INHERIT, if non-nil, says to inherit text properties
2108 from adjoining text, if those properties are sticky. */)
2109 (character
, count
, inherit
)
2110 Lisp_Object character
, count
, inherit
;
2112 register unsigned char *string
;
2113 register int strlen
;
2116 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
2118 CHECK_NUMBER (character
);
2119 CHECK_NUMBER (count
);
2121 if (!NILP (current_buffer
->enable_multibyte_characters
))
2122 len
= CHAR_STRING (XFASTINT (character
), str
);
2124 str
[0] = XFASTINT (character
), len
= 1;
2125 n
= XINT (count
) * len
;
2128 strlen
= min (n
, 256 * len
);
2129 string
= (unsigned char *) alloca (strlen
);
2130 for (i
= 0; i
< strlen
; i
++)
2131 string
[i
] = str
[i
% len
];
2135 if (!NILP (inherit
))
2136 insert_and_inherit (string
, strlen
);
2138 insert (string
, strlen
);
2143 if (!NILP (inherit
))
2144 insert_and_inherit (string
, n
);
2152 /* Making strings from buffer contents. */
2154 /* Return a Lisp_String containing the text of the current buffer from
2155 START to END. If text properties are in use and the current buffer
2156 has properties in the range specified, the resulting string will also
2157 have them, if PROPS is nonzero.
2159 We don't want to use plain old make_string here, because it calls
2160 make_uninit_string, which can cause the buffer arena to be
2161 compacted. make_string has no way of knowing that the data has
2162 been moved, and thus copies the wrong data into the string. This
2163 doesn't effect most of the other users of make_string, so it should
2164 be left as is. But we should use this function when conjuring
2165 buffer substrings. */
2168 make_buffer_string (start
, end
, props
)
2172 int start_byte
= CHAR_TO_BYTE (start
);
2173 int end_byte
= CHAR_TO_BYTE (end
);
2175 return make_buffer_string_both (start
, start_byte
, end
, end_byte
, props
);
2178 /* Return a Lisp_String containing the text of the current buffer from
2179 START / START_BYTE to END / END_BYTE.
2181 If text properties are in use and the current buffer
2182 has properties in the range specified, the resulting string will also
2183 have them, if PROPS is nonzero.
2185 We don't want to use plain old make_string here, because it calls
2186 make_uninit_string, which can cause the buffer arena to be
2187 compacted. make_string has no way of knowing that the data has
2188 been moved, and thus copies the wrong data into the string. This
2189 doesn't effect most of the other users of make_string, so it should
2190 be left as is. But we should use this function when conjuring
2191 buffer substrings. */
2194 make_buffer_string_both (start
, start_byte
, end
, end_byte
, props
)
2195 int start
, start_byte
, end
, end_byte
;
2198 Lisp_Object result
, tem
, tem1
;
2200 if (start
< GPT
&& GPT
< end
)
2203 if (! NILP (current_buffer
->enable_multibyte_characters
))
2204 result
= make_uninit_multibyte_string (end
- start
, end_byte
- start_byte
);
2206 result
= make_uninit_string (end
- start
);
2207 bcopy (BYTE_POS_ADDR (start_byte
), XSTRING (result
)->data
,
2208 end_byte
- start_byte
);
2210 /* If desired, update and copy the text properties. */
2213 update_buffer_properties (start
, end
);
2215 tem
= Fnext_property_change (make_number (start
), Qnil
, make_number (end
));
2216 tem1
= Ftext_properties_at (make_number (start
), Qnil
);
2218 if (XINT (tem
) != end
|| !NILP (tem1
))
2219 copy_intervals_to_string (result
, current_buffer
, start
,
2226 /* Call Vbuffer_access_fontify_functions for the range START ... END
2227 in the current buffer, if necessary. */
2230 update_buffer_properties (start
, end
)
2233 /* If this buffer has some access functions,
2234 call them, specifying the range of the buffer being accessed. */
2235 if (!NILP (Vbuffer_access_fontify_functions
))
2237 Lisp_Object args
[3];
2240 args
[0] = Qbuffer_access_fontify_functions
;
2241 XSETINT (args
[1], start
);
2242 XSETINT (args
[2], end
);
2244 /* But don't call them if we can tell that the work
2245 has already been done. */
2246 if (!NILP (Vbuffer_access_fontified_property
))
2248 tem
= Ftext_property_any (args
[1], args
[2],
2249 Vbuffer_access_fontified_property
,
2252 Frun_hook_with_args (3, args
);
2255 Frun_hook_with_args (3, args
);
2259 DEFUN ("buffer-substring", Fbuffer_substring
, Sbuffer_substring
, 2, 2, 0,
2260 doc
: /* Return the contents of part of the current buffer as a string.
2261 The two arguments START and END are character positions;
2262 they can be in either order.
2263 The string returned is multibyte if the buffer is multibyte.
2265 This function copies the text properties of that part of the buffer
2266 into the result string; if you don't want the text properties,
2267 use `buffer-substring-no-properties' instead. */)
2269 Lisp_Object start
, end
;
2273 validate_region (&start
, &end
);
2277 return make_buffer_string (b
, e
, 1);
2280 DEFUN ("buffer-substring-no-properties", Fbuffer_substring_no_properties
,
2281 Sbuffer_substring_no_properties
, 2, 2, 0,
2282 doc
: /* Return the characters of part of the buffer, without the text properties.
2283 The two arguments START and END are character positions;
2284 they can be in either order. */)
2286 Lisp_Object start
, end
;
2290 validate_region (&start
, &end
);
2294 return make_buffer_string (b
, e
, 0);
2297 DEFUN ("buffer-string", Fbuffer_string
, Sbuffer_string
, 0, 0, 0,
2298 doc
: /* Return the contents of the current buffer as a string.
2299 If narrowing is in effect, this function returns only the visible part
2303 return make_buffer_string (BEGV
, ZV
, 1);
2306 DEFUN ("insert-buffer-substring", Finsert_buffer_substring
, Sinsert_buffer_substring
,
2308 doc
: /* Insert before point a substring of the contents of buffer BUFFER.
2309 BUFFER may be a buffer or a buffer name.
2310 Arguments START and END are character numbers specifying the substring.
2311 They default to the beginning and the end of BUFFER. */)
2313 Lisp_Object buf
, start
, end
;
2315 register int b
, e
, temp
;
2316 register struct buffer
*bp
, *obuf
;
2319 buffer
= Fget_buffer (buf
);
2322 bp
= XBUFFER (buffer
);
2323 if (NILP (bp
->name
))
2324 error ("Selecting deleted buffer");
2330 CHECK_NUMBER_COERCE_MARKER (start
);
2337 CHECK_NUMBER_COERCE_MARKER (end
);
2342 temp
= b
, b
= e
, e
= temp
;
2344 if (!(BUF_BEGV (bp
) <= b
&& e
<= BUF_ZV (bp
)))
2345 args_out_of_range (start
, end
);
2347 obuf
= current_buffer
;
2348 set_buffer_internal_1 (bp
);
2349 update_buffer_properties (b
, e
);
2350 set_buffer_internal_1 (obuf
);
2352 insert_from_buffer (bp
, b
, e
- b
, 0);
2356 DEFUN ("compare-buffer-substrings", Fcompare_buffer_substrings
, Scompare_buffer_substrings
,
2358 doc
: /* Compare two substrings of two buffers; return result as number.
2359 the value is -N if first string is less after N-1 chars,
2360 +N if first string is greater after N-1 chars, or 0 if strings match.
2361 Each substring is represented as three arguments: BUFFER, START and END.
2362 That makes six args in all, three for each substring.
2364 The value of `case-fold-search' in the current buffer
2365 determines whether case is significant or ignored. */)
2366 (buffer1
, start1
, end1
, buffer2
, start2
, end2
)
2367 Lisp_Object buffer1
, start1
, end1
, buffer2
, start2
, end2
;
2369 register int begp1
, endp1
, begp2
, endp2
, temp
;
2370 register struct buffer
*bp1
, *bp2
;
2371 register Lisp_Object
*trt
2372 = (!NILP (current_buffer
->case_fold_search
)
2373 ? XCHAR_TABLE (current_buffer
->case_canon_table
)->contents
: 0);
2375 int i1
, i2
, i1_byte
, i2_byte
;
2377 /* Find the first buffer and its substring. */
2380 bp1
= current_buffer
;
2384 buf1
= Fget_buffer (buffer1
);
2387 bp1
= XBUFFER (buf1
);
2388 if (NILP (bp1
->name
))
2389 error ("Selecting deleted buffer");
2393 begp1
= BUF_BEGV (bp1
);
2396 CHECK_NUMBER_COERCE_MARKER (start1
);
2397 begp1
= XINT (start1
);
2400 endp1
= BUF_ZV (bp1
);
2403 CHECK_NUMBER_COERCE_MARKER (end1
);
2404 endp1
= XINT (end1
);
2408 temp
= begp1
, begp1
= endp1
, endp1
= temp
;
2410 if (!(BUF_BEGV (bp1
) <= begp1
2412 && endp1
<= BUF_ZV (bp1
)))
2413 args_out_of_range (start1
, end1
);
2415 /* Likewise for second substring. */
2418 bp2
= current_buffer
;
2422 buf2
= Fget_buffer (buffer2
);
2425 bp2
= XBUFFER (buf2
);
2426 if (NILP (bp2
->name
))
2427 error ("Selecting deleted buffer");
2431 begp2
= BUF_BEGV (bp2
);
2434 CHECK_NUMBER_COERCE_MARKER (start2
);
2435 begp2
= XINT (start2
);
2438 endp2
= BUF_ZV (bp2
);
2441 CHECK_NUMBER_COERCE_MARKER (end2
);
2442 endp2
= XINT (end2
);
2446 temp
= begp2
, begp2
= endp2
, endp2
= temp
;
2448 if (!(BUF_BEGV (bp2
) <= begp2
2450 && endp2
<= BUF_ZV (bp2
)))
2451 args_out_of_range (start2
, end2
);
2455 i1_byte
= buf_charpos_to_bytepos (bp1
, i1
);
2456 i2_byte
= buf_charpos_to_bytepos (bp2
, i2
);
2458 while (i1
< endp1
&& i2
< endp2
)
2460 /* When we find a mismatch, we must compare the
2461 characters, not just the bytes. */
2464 if (! NILP (bp1
->enable_multibyte_characters
))
2466 c1
= BUF_FETCH_MULTIBYTE_CHAR (bp1
, i1_byte
);
2467 BUF_INC_POS (bp1
, i1_byte
);
2472 c1
= BUF_FETCH_BYTE (bp1
, i1
);
2473 c1
= unibyte_char_to_multibyte (c1
);
2477 if (! NILP (bp2
->enable_multibyte_characters
))
2479 c2
= BUF_FETCH_MULTIBYTE_CHAR (bp2
, i2_byte
);
2480 BUF_INC_POS (bp2
, i2_byte
);
2485 c2
= BUF_FETCH_BYTE (bp2
, i2
);
2486 c2
= unibyte_char_to_multibyte (c2
);
2492 c1
= XINT (trt
[c1
]);
2493 c2
= XINT (trt
[c2
]);
2496 return make_number (- 1 - chars
);
2498 return make_number (chars
+ 1);
2503 /* The strings match as far as they go.
2504 If one is shorter, that one is less. */
2505 if (chars
< endp1
- begp1
)
2506 return make_number (chars
+ 1);
2507 else if (chars
< endp2
- begp2
)
2508 return make_number (- chars
- 1);
2510 /* Same length too => they are equal. */
2511 return make_number (0);
2515 subst_char_in_region_unwind (arg
)
2518 return current_buffer
->undo_list
= arg
;
2522 subst_char_in_region_unwind_1 (arg
)
2525 return current_buffer
->filename
= arg
;
2528 DEFUN ("subst-char-in-region", Fsubst_char_in_region
,
2529 Ssubst_char_in_region
, 4, 5, 0,
2530 doc
: /* From START to END, replace FROMCHAR with TOCHAR each time it occurs.
2531 If optional arg NOUNDO is non-nil, don't record this change for undo
2532 and don't mark the buffer as really changed.
2533 Both characters must have the same length of multi-byte form. */)
2534 (start
, end
, fromchar
, tochar
, noundo
)
2535 Lisp_Object start
, end
, fromchar
, tochar
, noundo
;
2537 register int pos
, pos_byte
, stop
, i
, len
, end_byte
;
2539 unsigned char fromstr
[MAX_MULTIBYTE_LENGTH
], tostr
[MAX_MULTIBYTE_LENGTH
];
2541 int count
= specpdl_ptr
- specpdl
;
2542 #define COMBINING_NO 0
2543 #define COMBINING_BEFORE 1
2544 #define COMBINING_AFTER 2
2545 #define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
2546 int maybe_byte_combining
= COMBINING_NO
;
2547 int last_changed
= 0;
2548 int multibyte_p
= !NILP (current_buffer
->enable_multibyte_characters
);
2550 validate_region (&start
, &end
);
2551 CHECK_NUMBER (fromchar
);
2552 CHECK_NUMBER (tochar
);
2556 len
= CHAR_STRING (XFASTINT (fromchar
), fromstr
);
2557 if (CHAR_STRING (XFASTINT (tochar
), tostr
) != len
)
2558 error ("Characters in subst-char-in-region have different byte-lengths");
2559 if (!ASCII_BYTE_P (*tostr
))
2561 /* If *TOSTR is in the range 0x80..0x9F and TOCHAR is not a
2562 complete multibyte character, it may be combined with the
2563 after bytes. If it is in the range 0xA0..0xFF, it may be
2564 combined with the before and after bytes. */
2565 if (!CHAR_HEAD_P (*tostr
))
2566 maybe_byte_combining
= COMBINING_BOTH
;
2567 else if (BYTES_BY_CHAR_HEAD (*tostr
) > len
)
2568 maybe_byte_combining
= COMBINING_AFTER
;
2574 fromstr
[0] = XFASTINT (fromchar
);
2575 tostr
[0] = XFASTINT (tochar
);
2579 pos_byte
= CHAR_TO_BYTE (pos
);
2580 stop
= CHAR_TO_BYTE (XINT (end
));
2583 /* If we don't want undo, turn off putting stuff on the list.
2584 That's faster than getting rid of things,
2585 and it prevents even the entry for a first change.
2586 Also inhibit locking the file. */
2589 record_unwind_protect (subst_char_in_region_unwind
,
2590 current_buffer
->undo_list
);
2591 current_buffer
->undo_list
= Qt
;
2592 /* Don't do file-locking. */
2593 record_unwind_protect (subst_char_in_region_unwind_1
,
2594 current_buffer
->filename
);
2595 current_buffer
->filename
= Qnil
;
2598 if (pos_byte
< GPT_BYTE
)
2599 stop
= min (stop
, GPT_BYTE
);
2602 int pos_byte_next
= pos_byte
;
2604 if (pos_byte
>= stop
)
2606 if (pos_byte
>= end_byte
) break;
2609 p
= BYTE_POS_ADDR (pos_byte
);
2611 INC_POS (pos_byte_next
);
2614 if (pos_byte_next
- pos_byte
== len
2615 && p
[0] == fromstr
[0]
2617 || (p
[1] == fromstr
[1]
2618 && (len
== 2 || (p
[2] == fromstr
[2]
2619 && (len
== 3 || p
[3] == fromstr
[3]))))))
2624 modify_region (current_buffer
, changed
, XINT (end
));
2626 if (! NILP (noundo
))
2628 if (MODIFF
- 1 == SAVE_MODIFF
)
2630 if (MODIFF
- 1 == current_buffer
->auto_save_modified
)
2631 current_buffer
->auto_save_modified
++;
2635 /* Take care of the case where the new character
2636 combines with neighboring bytes. */
2637 if (maybe_byte_combining
2638 && (maybe_byte_combining
== COMBINING_AFTER
2639 ? (pos_byte_next
< Z_BYTE
2640 && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next
)))
2641 : ((pos_byte_next
< Z_BYTE
2642 && ! CHAR_HEAD_P (FETCH_BYTE (pos_byte_next
)))
2643 || (pos_byte
> BEG_BYTE
2644 && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte
- 1))))))
2646 Lisp_Object tem
, string
;
2648 struct gcpro gcpro1
;
2650 tem
= current_buffer
->undo_list
;
2653 /* Make a multibyte string containing this single character. */
2654 string
= make_multibyte_string (tostr
, 1, len
);
2655 /* replace_range is less efficient, because it moves the gap,
2656 but it handles combining correctly. */
2657 replace_range (pos
, pos
+ 1, string
,
2659 pos_byte_next
= CHAR_TO_BYTE (pos
);
2660 if (pos_byte_next
> pos_byte
)
2661 /* Before combining happened. We should not increment
2662 POS. So, to cancel the later increment of POS,
2666 INC_POS (pos_byte_next
);
2668 if (! NILP (noundo
))
2669 current_buffer
->undo_list
= tem
;
2676 record_change (pos
, 1);
2677 for (i
= 0; i
< len
; i
++) *p
++ = tostr
[i
];
2679 last_changed
= pos
+ 1;
2681 pos_byte
= pos_byte_next
;
2687 signal_after_change (changed
,
2688 last_changed
- changed
, last_changed
- changed
);
2689 update_compositions (changed
, last_changed
, CHECK_ALL
);
2692 unbind_to (count
, Qnil
);
2696 DEFUN ("translate-region", Ftranslate_region
, Stranslate_region
, 3, 3, 0,
2697 doc
: /* From START to END, translate characters according to TABLE.
2698 TABLE is a string; the Nth character in it is the mapping
2699 for the character with code N.
2700 This function does not alter multibyte characters.
2701 It returns the number of characters changed. */)
2705 register Lisp_Object table
;
2707 register int pos_byte
, stop
; /* Limits of the region. */
2708 register unsigned char *tt
; /* Trans table. */
2709 register int nc
; /* New character. */
2710 int cnt
; /* Number of changes made. */
2711 int size
; /* Size of translate table. */
2713 int multibyte
= !NILP (current_buffer
->enable_multibyte_characters
);
2715 validate_region (&start
, &end
);
2716 CHECK_STRING (table
);
2718 size
= STRING_BYTES (XSTRING (table
));
2719 tt
= XSTRING (table
)->data
;
2721 pos_byte
= CHAR_TO_BYTE (XINT (start
));
2722 stop
= CHAR_TO_BYTE (XINT (end
));
2723 modify_region (current_buffer
, XINT (start
), XINT (end
));
2727 for (; pos_byte
< stop
; )
2729 register unsigned char *p
= BYTE_POS_ADDR (pos_byte
);
2735 oc
= STRING_CHAR_AND_LENGTH (p
, stop
- pos_byte
, len
);
2738 pos_byte_next
= pos_byte
+ len
;
2739 if (oc
< size
&& len
== 1)
2744 /* Take care of the case where the new character
2745 combines with neighboring bytes. */
2746 if (!ASCII_BYTE_P (nc
)
2747 && (CHAR_HEAD_P (nc
)
2748 ? ! CHAR_HEAD_P (FETCH_BYTE (pos_byte
+ 1))
2749 : (pos_byte
> BEG_BYTE
2750 && ! ASCII_BYTE_P (FETCH_BYTE (pos_byte
- 1)))))
2754 string
= make_multibyte_string (tt
+ oc
, 1, 1);
2755 /* This is less efficient, because it moves the gap,
2756 but it handles combining correctly. */
2757 replace_range (pos
, pos
+ 1, string
,
2759 pos_byte_next
= CHAR_TO_BYTE (pos
);
2760 if (pos_byte_next
> pos_byte
)
2761 /* Before combining happened. We should not
2762 increment POS. So, to cancel the later
2763 increment of POS, we decrease it now. */
2766 INC_POS (pos_byte_next
);
2770 record_change (pos
, 1);
2772 signal_after_change (pos
, 1, 1);
2773 update_compositions (pos
, pos
+ 1, CHECK_BORDER
);
2778 pos_byte
= pos_byte_next
;
2782 return make_number (cnt
);
2785 DEFUN ("delete-region", Fdelete_region
, Sdelete_region
, 2, 2, "r",
2786 doc
: /* Delete the text between point and mark.
2787 When called from a program, expects two arguments,
2788 positions (integers or markers) specifying the stretch to be deleted. */)
2790 Lisp_Object start
, end
;
2792 validate_region (&start
, &end
);
2793 del_range (XINT (start
), XINT (end
));
2797 DEFUN ("delete-and-extract-region", Fdelete_and_extract_region
,
2798 Sdelete_and_extract_region
, 2, 2, 0,
2799 doc
: /* Delete the text between START and END and return it. */)
2801 Lisp_Object start
, end
;
2803 validate_region (&start
, &end
);
2804 return del_range_1 (XINT (start
), XINT (end
), 1, 1);
2807 DEFUN ("widen", Fwiden
, Swiden
, 0, 0, "",
2808 doc
: /* Remove restrictions (narrowing) from current buffer.
2809 This allows the buffer's full text to be seen and edited. */)
2812 if (BEG
!= BEGV
|| Z
!= ZV
)
2813 current_buffer
->clip_changed
= 1;
2815 BEGV_BYTE
= BEG_BYTE
;
2816 SET_BUF_ZV_BOTH (current_buffer
, Z
, Z_BYTE
);
2817 /* Changing the buffer bounds invalidates any recorded current column. */
2818 invalidate_current_column ();
2822 DEFUN ("narrow-to-region", Fnarrow_to_region
, Snarrow_to_region
, 2, 2, "r",
2823 doc
: /* Restrict editing in this buffer to the current region.
2824 The rest of the text becomes temporarily invisible and untouchable
2825 but is not deleted; if you save the buffer in a file, the invisible
2826 text is included in the file. \\[widen] makes all visible again.
2827 See also `save-restriction'.
2829 When calling from a program, pass two arguments; positions (integers
2830 or markers) bounding the text that should remain visible. */)
2832 register Lisp_Object start
, end
;
2834 CHECK_NUMBER_COERCE_MARKER (start
);
2835 CHECK_NUMBER_COERCE_MARKER (end
);
2837 if (XINT (start
) > XINT (end
))
2840 tem
= start
; start
= end
; end
= tem
;
2843 if (!(BEG
<= XINT (start
) && XINT (start
) <= XINT (end
) && XINT (end
) <= Z
))
2844 args_out_of_range (start
, end
);
2846 if (BEGV
!= XFASTINT (start
) || ZV
!= XFASTINT (end
))
2847 current_buffer
->clip_changed
= 1;
2849 SET_BUF_BEGV (current_buffer
, XFASTINT (start
));
2850 SET_BUF_ZV (current_buffer
, XFASTINT (end
));
2851 if (PT
< XFASTINT (start
))
2852 SET_PT (XFASTINT (start
));
2853 if (PT
> XFASTINT (end
))
2854 SET_PT (XFASTINT (end
));
2855 /* Changing the buffer bounds invalidates any recorded current column. */
2856 invalidate_current_column ();
2861 save_restriction_save ()
2863 if (BEGV
== BEG
&& ZV
== Z
)
2864 /* The common case that the buffer isn't narrowed.
2865 We return just the buffer object, which save_restriction_restore
2866 recognizes as meaning `no restriction'. */
2867 return Fcurrent_buffer ();
2869 /* We have to save a restriction, so return a pair of markers, one
2870 for the beginning and one for the end. */
2872 Lisp_Object beg
, end
;
2874 beg
= buildmark (BEGV
, BEGV_BYTE
);
2875 end
= buildmark (ZV
, ZV_BYTE
);
2877 /* END must move forward if text is inserted at its exact location. */
2878 XMARKER(end
)->insertion_type
= 1;
2880 return Fcons (beg
, end
);
2885 save_restriction_restore (data
)
2889 /* A pair of marks bounding a saved restriction. */
2891 struct Lisp_Marker
*beg
= XMARKER (XCAR (data
));
2892 struct Lisp_Marker
*end
= XMARKER (XCDR (data
));
2893 struct buffer
*buf
= beg
->buffer
; /* END should have the same buffer. */
2895 if (beg
->charpos
!= BUF_BEGV(buf
) || end
->charpos
!= BUF_ZV(buf
))
2896 /* The restriction has changed from the saved one, so restore
2897 the saved restriction. */
2899 int pt
= BUF_PT (buf
);
2901 SET_BUF_BEGV_BOTH (buf
, beg
->charpos
, beg
->bytepos
);
2902 SET_BUF_ZV_BOTH (buf
, end
->charpos
, end
->bytepos
);
2904 if (pt
< beg
->charpos
|| pt
> end
->charpos
)
2905 /* The point is outside the new visible range, move it inside. */
2906 SET_BUF_PT_BOTH (buf
,
2907 clip_to_bounds (beg
->charpos
, pt
, end
->charpos
),
2908 clip_to_bounds (beg
->bytepos
, BUF_PT_BYTE(buf
),
2911 buf
->clip_changed
= 1; /* Remember that the narrowing changed. */
2915 /* A buffer, which means that there was no old restriction. */
2917 struct buffer
*buf
= XBUFFER (data
);
2919 if (BUF_BEGV(buf
) != BUF_BEG(buf
) || BUF_ZV(buf
) != BUF_Z(buf
))
2920 /* The buffer has been narrowed, get rid of the narrowing. */
2922 SET_BUF_BEGV_BOTH (buf
, BUF_BEG(buf
), BUF_BEG_BYTE(buf
));
2923 SET_BUF_ZV_BOTH (buf
, BUF_Z(buf
), BUF_Z_BYTE(buf
));
2925 buf
->clip_changed
= 1; /* Remember that the narrowing changed. */
2932 DEFUN ("save-restriction", Fsave_restriction
, Ssave_restriction
, 0, UNEVALLED
, 0,
2933 doc
: /* Execute BODY, saving and restoring current buffer's restrictions.
2934 The buffer's restrictions make parts of the beginning and end invisible.
2935 (They are set up with `narrow-to-region' and eliminated with `widen'.)
2936 This special form, `save-restriction', saves the current buffer's restrictions
2937 when it is entered, and restores them when it is exited.
2938 So any `narrow-to-region' within BODY lasts only until the end of the form.
2939 The old restrictions settings are restored
2940 even in case of abnormal exit (throw or error).
2942 The value returned is the value of the last form in BODY.
2944 Note: if you are using both `save-excursion' and `save-restriction',
2945 use `save-excursion' outermost:
2946 (save-excursion (save-restriction ...))
2948 usage: (save-restriction &rest BODY) */)
2952 register Lisp_Object val
;
2953 int count
= specpdl_ptr
- specpdl
;
2955 record_unwind_protect (save_restriction_restore
, save_restriction_save ());
2956 val
= Fprogn (body
);
2957 return unbind_to (count
, val
);
2960 /* Buffer for the most recent text displayed by Fmessage_box. */
2961 static char *message_text
;
2963 /* Allocated length of that buffer. */
2964 static int message_length
;
2966 DEFUN ("message", Fmessage
, Smessage
, 1, MANY
, 0,
2967 doc
: /* Print a one-line message at the bottom of the screen.
2968 The first argument is a format control string, and the rest are data
2969 to be formatted under control of the string. See `format' for details.
2971 If the first argument is nil, clear any existing message; let the
2972 minibuffer contents show.
2974 usage: (message STRING &rest ARGS) */)
2986 register Lisp_Object val
;
2987 val
= Fformat (nargs
, args
);
2988 message3 (val
, STRING_BYTES (XSTRING (val
)), STRING_MULTIBYTE (val
));
2993 DEFUN ("message-box", Fmessage_box
, Smessage_box
, 1, MANY
, 0,
2994 doc
: /* Display a message, in a dialog box if possible.
2995 If a dialog box is not available, use the echo area.
2996 The first argument is a format control string, and the rest are data
2997 to be formatted under control of the string. See `format' for details.
2999 If the first argument is nil, clear any existing message; let the
3000 minibuffer contents show.
3002 usage: (message-box STRING &rest ARGS) */)
3014 register Lisp_Object val
;
3015 val
= Fformat (nargs
, args
);
3017 /* The MS-DOS frames support popup menus even though they are
3018 not FRAME_WINDOW_P. */
3019 if (FRAME_WINDOW_P (XFRAME (selected_frame
))
3020 || FRAME_MSDOS_P (XFRAME (selected_frame
)))
3022 Lisp_Object pane
, menu
, obj
;
3023 struct gcpro gcpro1
;
3024 pane
= Fcons (Fcons (build_string ("OK"), Qt
), Qnil
);
3026 menu
= Fcons (val
, pane
);
3027 obj
= Fx_popup_dialog (Qt
, menu
);
3031 #endif /* HAVE_MENUS */
3032 /* Copy the data so that it won't move when we GC. */
3035 message_text
= (char *)xmalloc (80);
3036 message_length
= 80;
3038 if (STRING_BYTES (XSTRING (val
)) > message_length
)
3040 message_length
= STRING_BYTES (XSTRING (val
));
3041 message_text
= (char *)xrealloc (message_text
, message_length
);
3043 bcopy (XSTRING (val
)->data
, message_text
, STRING_BYTES (XSTRING (val
)));
3044 message2 (message_text
, STRING_BYTES (XSTRING (val
)),
3045 STRING_MULTIBYTE (val
));
3050 extern Lisp_Object last_nonmenu_event
;
3053 DEFUN ("message-or-box", Fmessage_or_box
, Smessage_or_box
, 1, MANY
, 0,
3054 doc
: /* Display a message in a dialog box or in the echo area.
3055 If this command was invoked with the mouse, use a dialog box if
3056 `use-dialog-box' is non-nil.
3057 Otherwise, use the echo area.
3058 The first argument is a format control string, and the rest are data
3059 to be formatted under control of the string. See `format' for details.
3061 If the first argument is nil, clear any existing message; let the
3062 minibuffer contents show.
3064 usage: (message-or-box STRING &rest ARGS) */)
3070 if ((NILP (last_nonmenu_event
) || CONSP (last_nonmenu_event
))
3072 return Fmessage_box (nargs
, args
);
3074 return Fmessage (nargs
, args
);
3077 DEFUN ("current-message", Fcurrent_message
, Scurrent_message
, 0, 0, 0,
3078 doc
: /* Return the string currently displayed in the echo area, or nil if none. */)
3081 return current_message ();
3085 DEFUN ("propertize", Fpropertize
, Spropertize
, 3, MANY
, 0,
3086 doc
: /* Return a copy of STRING with text properties added.
3087 First argument is the string to copy.
3088 Remaining arguments form a sequence of PROPERTY VALUE pairs for text
3089 properties to add to the result.
3090 usage: (propertize STRING &rest PROPERTIES) */)
3095 Lisp_Object properties
, string
;
3096 struct gcpro gcpro1
, gcpro2
;
3099 /* Number of args must be odd. */
3100 if ((nargs
& 1) == 0 || nargs
< 3)
3101 error ("Wrong number of arguments");
3103 properties
= string
= Qnil
;
3104 GCPRO2 (properties
, string
);
3106 /* First argument must be a string. */
3107 CHECK_STRING (args
[0]);
3108 string
= Fcopy_sequence (args
[0]);
3110 for (i
= 1; i
< nargs
; i
+= 2)
3112 CHECK_SYMBOL (args
[i
]);
3113 properties
= Fcons (args
[i
], Fcons (args
[i
+ 1], properties
));
3116 Fadd_text_properties (make_number (0),
3117 make_number (XSTRING (string
)->size
),
3118 properties
, string
);
3119 RETURN_UNGCPRO (string
);
3123 /* Number of bytes that STRING will occupy when put into the result.
3124 MULTIBYTE is nonzero if the result should be multibyte. */
3126 #define CONVERTED_BYTE_SIZE(MULTIBYTE, STRING) \
3127 (((MULTIBYTE) && ! STRING_MULTIBYTE (STRING)) \
3128 ? count_size_as_multibyte (XSTRING (STRING)->data, \
3129 STRING_BYTES (XSTRING (STRING))) \
3130 : STRING_BYTES (XSTRING (STRING)))
3132 DEFUN ("format", Fformat
, Sformat
, 1, MANY
, 0,
3133 doc
: /* Format a string out of a control-string and arguments.
3134 The first argument is a control string.
3135 The other arguments are substituted into it to make the result, a string.
3136 It may contain %-sequences meaning to substitute the next argument.
3137 %s means print a string argument. Actually, prints any object, with `princ'.
3138 %d means print as number in decimal (%o octal, %x hex).
3139 %X is like %x, but uses upper case.
3140 %e means print a number in exponential notation.
3141 %f means print a number in decimal-point notation.
3142 %g means print a number in exponential notation
3143 or decimal-point notation, whichever uses fewer characters.
3144 %c means print a number as a single character.
3145 %S means print any object as an s-expression (using `prin1').
3146 The argument used for %d, %o, %x, %e, %f, %g or %c must be a number.
3147 Use %% to put a single % into the output.
3149 usage: (format STRING &rest OBJECTS) */)
3152 register Lisp_Object
*args
;
3154 register int n
; /* The number of the next arg to substitute */
3155 register int total
; /* An estimate of the final length */
3157 register unsigned char *format
, *end
;
3159 /* Nonzero if the output should be a multibyte string,
3160 which is true if any of the inputs is one. */
3162 /* When we make a multibyte string, we must pay attention to the
3163 byte combining problem, i.e., a byte may be combined with a
3164 multibyte charcter of the previous string. This flag tells if we
3165 must consider such a situation or not. */
3166 int maybe_combine_byte
;
3167 unsigned char *this_format
;
3175 /* It should not be necessary to GCPRO ARGS, because
3176 the caller in the interpreter should take care of that. */
3178 /* Try to determine whether the result should be multibyte.
3179 This is not always right; sometimes the result needs to be multibyte
3180 because of an object that we will pass through prin1,
3181 and in that case, we won't know it here. */
3182 for (n
= 0; n
< nargs
; n
++)
3183 if (STRINGP (args
[n
]) && STRING_MULTIBYTE (args
[n
]))
3186 CHECK_STRING (args
[0]);
3188 /* If we start out planning a unibyte result,
3189 and later find it has to be multibyte, we jump back to retry. */
3192 format
= XSTRING (args
[0])->data
;
3193 end
= format
+ STRING_BYTES (XSTRING (args
[0]));
3196 /* Make room in result for all the non-%-codes in the control string. */
3197 total
= 5 + CONVERTED_BYTE_SIZE (multibyte
, args
[0]);
3199 /* Add to TOTAL enough space to hold the converted arguments. */
3202 while (format
!= end
)
3203 if (*format
++ == '%')
3206 unsigned char *this_format_start
= format
- 1;
3207 int field_width
, precision
;
3209 /* General format specifications look like
3211 '%' [flags] [field-width] [precision] format
3216 field-width ::= [0-9]+
3217 precision ::= '.' [0-9]*
3219 If a field-width is specified, it specifies to which width
3220 the output should be padded with blanks, iff the output
3221 string is shorter than field-width.
3223 if precision is specified, it specifies the number of
3224 digits to print after the '.' for floats, or the max.
3225 number of chars to print from a string. */
3227 precision
= field_width
= 0;
3229 while (index ("-*# 0", *format
))
3232 if (*format
>= '0' && *format
<= '9')
3234 for (field_width
= 0; *format
>= '0' && *format
<= '9'; ++format
)
3235 field_width
= 10 * field_width
+ *format
- '0';
3241 for (precision
= 0; *format
>= '0' && *format
<= '9'; ++format
)
3242 precision
= 10 * precision
+ *format
- '0';
3245 if (format
- this_format_start
+ 1 > longest_format
)
3246 longest_format
= format
- this_format_start
+ 1;
3249 error ("Format string ends in middle of format specifier");
3252 else if (++n
>= nargs
)
3253 error ("Not enough arguments for format string");
3254 else if (*format
== 'S')
3256 /* For `S', prin1 the argument and then treat like a string. */
3257 register Lisp_Object tem
;
3258 tem
= Fprin1_to_string (args
[n
], Qnil
);
3259 if (STRING_MULTIBYTE (tem
) && ! multibyte
)
3267 else if (SYMBOLP (args
[n
]))
3269 /* Use a temp var to avoid problems when ENABLE_CHECKING
3271 struct Lisp_String
*t
= XSYMBOL (args
[n
])->name
;
3272 XSETSTRING (args
[n
], t
);
3273 if (STRING_MULTIBYTE (args
[n
]) && ! multibyte
)
3280 else if (STRINGP (args
[n
]))
3283 if (*format
!= 's' && *format
!= 'S')
3284 error ("Format specifier doesn't match argument type");
3285 thissize
= CONVERTED_BYTE_SIZE (multibyte
, args
[n
]);
3287 /* Would get MPV otherwise, since Lisp_Int's `point' to low memory. */
3288 else if (INTEGERP (args
[n
]) && *format
!= 's')
3290 /* The following loop assumes the Lisp type indicates
3291 the proper way to pass the argument.
3292 So make sure we have a flonum if the argument should
3294 if (*format
== 'e' || *format
== 'f' || *format
== 'g')
3295 args
[n
] = Ffloat (args
[n
]);
3297 if (*format
!= 'd' && *format
!= 'o' && *format
!= 'x'
3298 && *format
!= 'i' && *format
!= 'X' && *format
!= 'c')
3299 error ("Invalid format operation %%%c", *format
);
3303 && (! SINGLE_BYTE_CHAR_P (XINT (args
[n
]))
3304 || XINT (args
[n
]) == 0))
3311 args
[n
] = Fchar_to_string (args
[n
]);
3312 thissize
= STRING_BYTES (XSTRING (args
[n
]));
3315 else if (FLOATP (args
[n
]) && *format
!= 's')
3317 if (! (*format
== 'e' || *format
== 'f' || *format
== 'g'))
3318 args
[n
] = Ftruncate (args
[n
], Qnil
);
3320 /* Note that we're using sprintf to print floats,
3321 so we have to take into account what that function
3323 thissize
= MAX_10_EXP
+ 100 + precision
;
3327 /* Anything but a string, convert to a string using princ. */
3328 register Lisp_Object tem
;
3329 tem
= Fprin1_to_string (args
[n
], Qt
);
3330 if (STRING_MULTIBYTE (tem
) & ! multibyte
)
3339 thissize
= max (field_width
, thissize
);
3340 total
+= thissize
+ 4;
3343 /* Now we can no longer jump to retry.
3344 TOTAL and LONGEST_FORMAT are known for certain. */
3346 this_format
= (unsigned char *) alloca (longest_format
+ 1);
3348 /* Allocate the space for the result.
3349 Note that TOTAL is an overestimate. */
3351 buf
= (char *) alloca (total
+ 1);
3353 buf
= (char *) xmalloc (total
+ 1);
3359 /* Scan the format and store result in BUF. */
3360 format
= XSTRING (args
[0])->data
;
3361 maybe_combine_byte
= 0;
3362 while (format
!= end
)
3368 unsigned char *this_format_start
= format
;
3372 /* Process a numeric arg and skip it. */
3373 minlen
= atoi (format
);
3375 minlen
= - minlen
, negative
= 1;
3377 while ((*format
>= '0' && *format
<= '9')
3378 || *format
== '-' || *format
== ' ' || *format
== '.')
3381 if (*format
++ == '%')
3390 if (STRINGP (args
[n
]))
3392 int padding
, nbytes
, start
, end
;
3393 int width
= lisp_string_width (args
[n
], -1, NULL
, NULL
);
3395 /* If spec requires it, pad on right with spaces. */
3396 padding
= minlen
- width
;
3398 while (padding
-- > 0)
3408 && !ASCII_BYTE_P (*((unsigned char *) p
- 1))
3409 && STRING_MULTIBYTE (args
[n
])
3410 && !CHAR_HEAD_P (XSTRING (args
[n
])->data
[0]))
3411 maybe_combine_byte
= 1;
3412 nbytes
= copy_text (XSTRING (args
[n
])->data
, p
,
3413 STRING_BYTES (XSTRING (args
[n
])),
3414 STRING_MULTIBYTE (args
[n
]), multibyte
);
3416 nchars
+= XSTRING (args
[n
])->size
;
3420 while (padding
-- > 0)
3426 /* If this argument has text properties, record where
3427 in the result string it appears. */
3428 if (XSTRING (args
[n
])->intervals
)
3432 int nbytes
= nargs
* sizeof *info
;
3433 info
= (struct info
*) alloca (nbytes
);
3434 bzero (info
, nbytes
);
3437 info
[n
].start
= start
;
3441 else if (INTEGERP (args
[n
]) || FLOATP (args
[n
]))
3445 bcopy (this_format_start
, this_format
,
3446 format
- this_format_start
);
3447 this_format
[format
- this_format_start
] = 0;
3449 if (INTEGERP (args
[n
]))
3450 sprintf (p
, this_format
, XINT (args
[n
]));
3452 sprintf (p
, this_format
, XFLOAT_DATA (args
[n
]));
3456 && !ASCII_BYTE_P (*((unsigned char *) p
- 1))
3457 && !CHAR_HEAD_P (*((unsigned char *) p
)))
3458 maybe_combine_byte
= 1;
3459 this_nchars
= strlen (p
);
3461 p
+= str_to_multibyte (p
, buf
+ total
- p
, this_nchars
);
3464 nchars
+= this_nchars
;
3467 else if (STRING_MULTIBYTE (args
[0]))
3469 /* Copy a whole multibyte character. */
3472 && !ASCII_BYTE_P (*((unsigned char *) p
- 1))
3473 && !CHAR_HEAD_P (*format
))
3474 maybe_combine_byte
= 1;
3476 while (! CHAR_HEAD_P (*format
)) *p
++ = *format
++;
3481 /* Convert a single-byte character to multibyte. */
3482 int len
= copy_text (format
, p
, 1, 0, 1);
3489 *p
++ = *format
++, nchars
++;
3492 if (p
> buf
+ total
+ 1)
3495 if (maybe_combine_byte
)
3496 nchars
= multibyte_chars_in_text (buf
, p
- buf
);
3497 val
= make_specified_string (buf
, nchars
, p
- buf
, multibyte
);
3499 /* If we allocated BUF with malloc, free it too. */
3503 /* If the format string has text properties, or any of the string
3504 arguments has text properties, set up text properties of the
3507 if (XSTRING (args
[0])->intervals
|| info
)
3509 Lisp_Object len
, new_len
, props
;
3510 struct gcpro gcpro1
;
3512 /* Add text properties from the format string. */
3513 len
= make_number (XSTRING (args
[0])->size
);
3514 props
= text_property_list (args
[0], make_number (0), len
, Qnil
);
3519 new_len
= make_number (XSTRING (val
)->size
);
3520 extend_property_ranges (props
, len
, new_len
);
3521 add_text_properties_from_list (val
, props
, make_number (0));
3524 /* Add text properties from arguments. */
3526 for (n
= 1; n
< nargs
; ++n
)
3529 len
= make_number (XSTRING (args
[n
])->size
);
3530 new_len
= make_number (info
[n
].end
- info
[n
].start
);
3531 props
= text_property_list (args
[n
], make_number (0), len
, Qnil
);
3532 extend_property_ranges (props
, len
, new_len
);
3533 /* If successive arguments have properites, be sure that
3534 the value of `composition' property be the copy. */
3535 if (n
> 1 && info
[n
- 1].end
)
3536 make_composition_value_copy (props
);
3537 add_text_properties_from_list (val
, props
,
3538 make_number (info
[n
].start
));
3551 format1 (string1
, arg0
, arg1
, arg2
, arg3
, arg4
)
3552 EMACS_INT arg0
, arg1
, arg2
, arg3
, arg4
;
3566 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, (char **) args
);
3568 doprnt (buf
, sizeof buf
, string1
, (char *)0, 5, &string1
+ 1);
3570 return build_string (buf
);
3573 DEFUN ("char-equal", Fchar_equal
, Schar_equal
, 2, 2, 0,
3574 doc
: /* Return t if two characters match, optionally ignoring case.
3575 Both arguments must be characters (i.e. integers).
3576 Case is ignored if `case-fold-search' is non-nil in the current buffer. */)
3578 register Lisp_Object c1
, c2
;
3584 if (XINT (c1
) == XINT (c2
))
3586 if (NILP (current_buffer
->case_fold_search
))
3589 /* Do these in separate statements,
3590 then compare the variables.
3591 because of the way DOWNCASE uses temp variables. */
3592 i1
= DOWNCASE (XFASTINT (c1
));
3593 i2
= DOWNCASE (XFASTINT (c2
));
3594 return (i1
== i2
? Qt
: Qnil
);
3597 /* Transpose the markers in two regions of the current buffer, and
3598 adjust the ones between them if necessary (i.e.: if the regions
3601 START1, END1 are the character positions of the first region.
3602 START1_BYTE, END1_BYTE are the byte positions.
3603 START2, END2 are the character positions of the second region.
3604 START2_BYTE, END2_BYTE are the byte positions.
3606 Traverses the entire marker list of the buffer to do so, adding an
3607 appropriate amount to some, subtracting from some, and leaving the
3608 rest untouched. Most of this is copied from adjust_markers in insdel.c.
3610 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */
3613 transpose_markers (start1
, end1
, start2
, end2
,
3614 start1_byte
, end1_byte
, start2_byte
, end2_byte
)
3615 register int start1
, end1
, start2
, end2
;
3616 register int start1_byte
, end1_byte
, start2_byte
, end2_byte
;
3618 register int amt1
, amt1_byte
, amt2
, amt2_byte
, diff
, diff_byte
, mpos
;
3619 register Lisp_Object marker
;
3621 /* Update point as if it were a marker. */
3625 TEMP_SET_PT_BOTH (PT
+ (end2
- end1
),
3626 PT_BYTE
+ (end2_byte
- end1_byte
));
3627 else if (PT
< start2
)
3628 TEMP_SET_PT_BOTH (PT
+ (end2
- start2
) - (end1
- start1
),
3629 (PT_BYTE
+ (end2_byte
- start2_byte
)
3630 - (end1_byte
- start1_byte
)));
3632 TEMP_SET_PT_BOTH (PT
- (start2
- start1
),
3633 PT_BYTE
- (start2_byte
- start1_byte
));
3635 /* We used to adjust the endpoints here to account for the gap, but that
3636 isn't good enough. Even if we assume the caller has tried to move the
3637 gap out of our way, it might still be at start1 exactly, for example;
3638 and that places it `inside' the interval, for our purposes. The amount
3639 of adjustment is nontrivial if there's a `denormalized' marker whose
3640 position is between GPT and GPT + GAP_SIZE, so it's simpler to leave
3641 the dirty work to Fmarker_position, below. */
3643 /* The difference between the region's lengths */
3644 diff
= (end2
- start2
) - (end1
- start1
);
3645 diff_byte
= (end2_byte
- start2_byte
) - (end1_byte
- start1_byte
);
3647 /* For shifting each marker in a region by the length of the other
3648 region plus the distance between the regions. */
3649 amt1
= (end2
- start2
) + (start2
- end1
);
3650 amt2
= (end1
- start1
) + (start2
- end1
);
3651 amt1_byte
= (end2_byte
- start2_byte
) + (start2_byte
- end1_byte
);
3652 amt2_byte
= (end1_byte
- start1_byte
) + (start2_byte
- end1_byte
);
3654 for (marker
= BUF_MARKERS (current_buffer
); !NILP (marker
);
3655 marker
= XMARKER (marker
)->chain
)
3657 mpos
= marker_byte_position (marker
);
3658 if (mpos
>= start1_byte
&& mpos
< end2_byte
)
3660 if (mpos
< end1_byte
)
3662 else if (mpos
< start2_byte
)
3666 XMARKER (marker
)->bytepos
= mpos
;
3668 mpos
= XMARKER (marker
)->charpos
;
3669 if (mpos
>= start1
&& mpos
< end2
)
3673 else if (mpos
< start2
)
3678 XMARKER (marker
)->charpos
= mpos
;
3682 DEFUN ("transpose-regions", Ftranspose_regions
, Stranspose_regions
, 4, 5, 0,
3683 doc
: /* Transpose region START1 to END1 with START2 to END2.
3684 The regions may not be overlapping, because the size of the buffer is
3685 never changed in a transposition.
3687 Optional fifth arg LEAVE_MARKERS, if non-nil, means don't update
3688 any markers that happen to be located in the regions.
3690 Transposing beyond buffer boundaries is an error. */)
3691 (startr1
, endr1
, startr2
, endr2
, leave_markers
)
3692 Lisp_Object startr1
, endr1
, startr2
, endr2
, leave_markers
;
3694 register int start1
, end1
, start2
, end2
;
3695 int start1_byte
, start2_byte
, len1_byte
, len2_byte
;
3696 int gap
, len1
, len_mid
, len2
;
3697 unsigned char *start1_addr
, *start2_addr
, *temp
;
3699 INTERVAL cur_intv
, tmp_interval1
, tmp_interval_mid
, tmp_interval2
;
3700 cur_intv
= BUF_INTERVALS (current_buffer
);
3702 validate_region (&startr1
, &endr1
);
3703 validate_region (&startr2
, &endr2
);
3705 start1
= XFASTINT (startr1
);
3706 end1
= XFASTINT (endr1
);
3707 start2
= XFASTINT (startr2
);
3708 end2
= XFASTINT (endr2
);
3711 /* Swap the regions if they're reversed. */
3714 register int glumph
= start1
;
3722 len1
= end1
- start1
;
3723 len2
= end2
- start2
;
3726 error ("Transposed regions overlap");
3727 else if (start1
== end1
|| start2
== end2
)
3728 error ("Transposed region has length 0");
3730 /* The possibilities are:
3731 1. Adjacent (contiguous) regions, or separate but equal regions
3732 (no, really equal, in this case!), or
3733 2. Separate regions of unequal size.
3735 The worst case is usually No. 2. It means that (aside from
3736 potential need for getting the gap out of the way), there also
3737 needs to be a shifting of the text between the two regions. So
3738 if they are spread far apart, we are that much slower... sigh. */
3740 /* It must be pointed out that the really studly thing to do would
3741 be not to move the gap at all, but to leave it in place and work
3742 around it if necessary. This would be extremely efficient,
3743 especially considering that people are likely to do
3744 transpositions near where they are working interactively, which
3745 is exactly where the gap would be found. However, such code
3746 would be much harder to write and to read. So, if you are
3747 reading this comment and are feeling squirrely, by all means have
3748 a go! I just didn't feel like doing it, so I will simply move
3749 the gap the minimum distance to get it out of the way, and then
3750 deal with an unbroken array. */
3752 /* Make sure the gap won't interfere, by moving it out of the text
3753 we will operate on. */
3754 if (start1
< gap
&& gap
< end2
)
3756 if (gap
- start1
< end2
- gap
)
3762 start1_byte
= CHAR_TO_BYTE (start1
);
3763 start2_byte
= CHAR_TO_BYTE (start2
);
3764 len1_byte
= CHAR_TO_BYTE (end1
) - start1_byte
;
3765 len2_byte
= CHAR_TO_BYTE (end2
) - start2_byte
;
3767 #ifdef BYTE_COMBINING_DEBUG
3770 if (count_combining_before (BYTE_POS_ADDR (start2_byte
),
3771 len2_byte
, start1
, start1_byte
)
3772 || count_combining_before (BYTE_POS_ADDR (start1_byte
),
3773 len1_byte
, end2
, start2_byte
+ len2_byte
)
3774 || count_combining_after (BYTE_POS_ADDR (start1_byte
),
3775 len1_byte
, end2
, start2_byte
+ len2_byte
))
3780 if (count_combining_before (BYTE_POS_ADDR (start2_byte
),
3781 len2_byte
, start1
, start1_byte
)
3782 || count_combining_before (BYTE_POS_ADDR (start1_byte
),
3783 len1_byte
, start2
, start2_byte
)
3784 || count_combining_after (BYTE_POS_ADDR (start2_byte
),
3785 len2_byte
, end1
, start1_byte
+ len1_byte
)
3786 || count_combining_after (BYTE_POS_ADDR (start1_byte
),
3787 len1_byte
, end2
, start2_byte
+ len2_byte
))
3792 /* Hmmm... how about checking to see if the gap is large
3793 enough to use as the temporary storage? That would avoid an
3794 allocation... interesting. Later, don't fool with it now. */
3796 /* Working without memmove, for portability (sigh), so must be
3797 careful of overlapping subsections of the array... */
3799 if (end1
== start2
) /* adjacent regions */
3801 modify_region (current_buffer
, start1
, end2
);
3802 record_change (start1
, len1
+ len2
);
3804 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
3805 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
3806 Fset_text_properties (make_number (start1
), make_number (end2
),
3809 /* First region smaller than second. */
3810 if (len1_byte
< len2_byte
)
3812 /* We use alloca only if it is small,
3813 because we want to avoid stack overflow. */
3814 if (len2_byte
> 20000)
3815 temp
= (unsigned char *) xmalloc (len2_byte
);
3817 temp
= (unsigned char *) alloca (len2_byte
);
3819 /* Don't precompute these addresses. We have to compute them
3820 at the last minute, because the relocating allocator might
3821 have moved the buffer around during the xmalloc. */
3822 start1_addr
= BYTE_POS_ADDR (start1_byte
);
3823 start2_addr
= BYTE_POS_ADDR (start2_byte
);
3825 bcopy (start2_addr
, temp
, len2_byte
);
3826 bcopy (start1_addr
, start1_addr
+ len2_byte
, len1_byte
);
3827 bcopy (temp
, start1_addr
, len2_byte
);
3828 if (len2_byte
> 20000)
3832 /* First region not smaller than second. */
3834 if (len1_byte
> 20000)
3835 temp
= (unsigned char *) xmalloc (len1_byte
);
3837 temp
= (unsigned char *) alloca (len1_byte
);
3838 start1_addr
= BYTE_POS_ADDR (start1_byte
);
3839 start2_addr
= BYTE_POS_ADDR (start2_byte
);
3840 bcopy (start1_addr
, temp
, len1_byte
);
3841 bcopy (start2_addr
, start1_addr
, len2_byte
);
3842 bcopy (temp
, start1_addr
+ len2_byte
, len1_byte
);
3843 if (len1_byte
> 20000)
3846 graft_intervals_into_buffer (tmp_interval1
, start1
+ len2
,
3847 len1
, current_buffer
, 0);
3848 graft_intervals_into_buffer (tmp_interval2
, start1
,
3849 len2
, current_buffer
, 0);
3850 update_compositions (start1
, start1
+ len2
, CHECK_BORDER
);
3851 update_compositions (start1
+ len2
, end2
, CHECK_TAIL
);
3853 /* Non-adjacent regions, because end1 != start2, bleagh... */
3856 len_mid
= start2_byte
- (start1_byte
+ len1_byte
);
3858 if (len1_byte
== len2_byte
)
3859 /* Regions are same size, though, how nice. */
3861 modify_region (current_buffer
, start1
, end1
);
3862 modify_region (current_buffer
, start2
, end2
);
3863 record_change (start1
, len1
);
3864 record_change (start2
, len2
);
3865 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
3866 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
3867 Fset_text_properties (make_number (start1
), make_number (end1
),
3869 Fset_text_properties (make_number (start2
), make_number (end2
),
3872 if (len1_byte
> 20000)
3873 temp
= (unsigned char *) xmalloc (len1_byte
);
3875 temp
= (unsigned char *) alloca (len1_byte
);
3876 start1_addr
= BYTE_POS_ADDR (start1_byte
);
3877 start2_addr
= BYTE_POS_ADDR (start2_byte
);
3878 bcopy (start1_addr
, temp
, len1_byte
);
3879 bcopy (start2_addr
, start1_addr
, len2_byte
);
3880 bcopy (temp
, start2_addr
, len1_byte
);
3881 if (len1_byte
> 20000)
3883 graft_intervals_into_buffer (tmp_interval1
, start2
,
3884 len1
, current_buffer
, 0);
3885 graft_intervals_into_buffer (tmp_interval2
, start1
,
3886 len2
, current_buffer
, 0);
3889 else if (len1_byte
< len2_byte
) /* Second region larger than first */
3890 /* Non-adjacent & unequal size, area between must also be shifted. */
3892 modify_region (current_buffer
, start1
, end2
);
3893 record_change (start1
, (end2
- start1
));
3894 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
3895 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
3896 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
3897 Fset_text_properties (make_number (start1
), make_number (end2
),
3900 /* holds region 2 */
3901 if (len2_byte
> 20000)
3902 temp
= (unsigned char *) xmalloc (len2_byte
);
3904 temp
= (unsigned char *) alloca (len2_byte
);
3905 start1_addr
= BYTE_POS_ADDR (start1_byte
);
3906 start2_addr
= BYTE_POS_ADDR (start2_byte
);
3907 bcopy (start2_addr
, temp
, len2_byte
);
3908 bcopy (start1_addr
, start1_addr
+ len_mid
+ len2_byte
, len1_byte
);
3909 safe_bcopy (start1_addr
+ len1_byte
, start1_addr
+ len2_byte
, len_mid
);
3910 bcopy (temp
, start1_addr
, len2_byte
);
3911 if (len2_byte
> 20000)
3913 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
3914 len1
, current_buffer
, 0);
3915 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
3916 len_mid
, current_buffer
, 0);
3917 graft_intervals_into_buffer (tmp_interval2
, start1
,
3918 len2
, current_buffer
, 0);
3921 /* Second region smaller than first. */
3923 record_change (start1
, (end2
- start1
));
3924 modify_region (current_buffer
, start1
, end2
);
3926 tmp_interval1
= copy_intervals (cur_intv
, start1
, len1
);
3927 tmp_interval_mid
= copy_intervals (cur_intv
, end1
, len_mid
);
3928 tmp_interval2
= copy_intervals (cur_intv
, start2
, len2
);
3929 Fset_text_properties (make_number (start1
), make_number (end2
),
3932 /* holds region 1 */
3933 if (len1_byte
> 20000)
3934 temp
= (unsigned char *) xmalloc (len1_byte
);
3936 temp
= (unsigned char *) alloca (len1_byte
);
3937 start1_addr
= BYTE_POS_ADDR (start1_byte
);
3938 start2_addr
= BYTE_POS_ADDR (start2_byte
);
3939 bcopy (start1_addr
, temp
, len1_byte
);
3940 bcopy (start2_addr
, start1_addr
, len2_byte
);
3941 bcopy (start1_addr
+ len1_byte
, start1_addr
+ len2_byte
, len_mid
);
3942 bcopy (temp
, start1_addr
+ len2_byte
+ len_mid
, len1_byte
);
3943 if (len1_byte
> 20000)
3945 graft_intervals_into_buffer (tmp_interval1
, end2
- len1
,
3946 len1
, current_buffer
, 0);
3947 graft_intervals_into_buffer (tmp_interval_mid
, start1
+ len2
,
3948 len_mid
, current_buffer
, 0);
3949 graft_intervals_into_buffer (tmp_interval2
, start1
,
3950 len2
, current_buffer
, 0);
3953 update_compositions (start1
, start1
+ len2
, CHECK_BORDER
);
3954 update_compositions (end2
- len1
, end2
, CHECK_BORDER
);
3957 /* When doing multiple transpositions, it might be nice
3958 to optimize this. Perhaps the markers in any one buffer
3959 should be organized in some sorted data tree. */
3960 if (NILP (leave_markers
))
3962 transpose_markers (start1
, end1
, start2
, end2
,
3963 start1_byte
, start1_byte
+ len1_byte
,
3964 start2_byte
, start2_byte
+ len2_byte
);
3965 fix_overlays_in_range (start1
, end2
);
3977 Qbuffer_access_fontify_functions
3978 = intern ("buffer-access-fontify-functions");
3979 staticpro (&Qbuffer_access_fontify_functions
);
3981 DEFVAR_LISP ("inhibit-field-text-motion", &Vinhibit_field_text_motion
,
3982 doc
: /* Non-nil means.text motion commands don't notice fields. */);
3983 Vinhibit_field_text_motion
= Qnil
;
3985 DEFVAR_LISP ("buffer-access-fontify-functions",
3986 &Vbuffer_access_fontify_functions
,
3987 doc
: /* List of functions called by `buffer-substring' to fontify if necessary.
3988 Each function is called with two arguments which specify the range
3989 of the buffer being accessed. */);
3990 Vbuffer_access_fontify_functions
= Qnil
;
3994 extern Lisp_Object Vprin1_to_string_buffer
;
3995 obuf
= Fcurrent_buffer ();
3996 /* Do this here, because init_buffer_once is too early--it won't work. */
3997 Fset_buffer (Vprin1_to_string_buffer
);
3998 /* Make sure buffer-access-fontify-functions is nil in this buffer. */
3999 Fset (Fmake_local_variable (intern ("buffer-access-fontify-functions")),
4004 DEFVAR_LISP ("buffer-access-fontified-property",
4005 &Vbuffer_access_fontified_property
,
4006 doc
: /* Property which (if non-nil) indicates text has been fontified.
4007 `buffer-substring' need not call the `buffer-access-fontify-functions'
4008 functions if all the text being accessed has this property. */);
4009 Vbuffer_access_fontified_property
= Qnil
;
4011 DEFVAR_LISP ("system-name", &Vsystem_name
,
4012 doc
: /* The name of the machine Emacs is running on. */);
4014 DEFVAR_LISP ("user-full-name", &Vuser_full_name
,
4015 doc
: /* The full name of the user logged in. */);
4017 DEFVAR_LISP ("user-login-name", &Vuser_login_name
,
4018 doc
: /* The user's name, taken from environment variables if possible. */);
4020 DEFVAR_LISP ("user-real-login-name", &Vuser_real_login_name
,
4021 doc
: /* The user's name, based upon the real uid only. */);
4023 defsubr (&Spropertize
);
4024 defsubr (&Schar_equal
);
4025 defsubr (&Sgoto_char
);
4026 defsubr (&Sstring_to_char
);
4027 defsubr (&Schar_to_string
);
4028 defsubr (&Sbuffer_substring
);
4029 defsubr (&Sbuffer_substring_no_properties
);
4030 defsubr (&Sbuffer_string
);
4032 defsubr (&Spoint_marker
);
4033 defsubr (&Smark_marker
);
4035 defsubr (&Sregion_beginning
);
4036 defsubr (&Sregion_end
);
4038 staticpro (&Qfield
);
4039 Qfield
= intern ("field");
4040 staticpro (&Qboundary
);
4041 Qboundary
= intern ("boundary");
4042 defsubr (&Sfield_beginning
);
4043 defsubr (&Sfield_end
);
4044 defsubr (&Sfield_string
);
4045 defsubr (&Sfield_string_no_properties
);
4046 defsubr (&Sdelete_field
);
4047 defsubr (&Sconstrain_to_field
);
4049 defsubr (&Sline_beginning_position
);
4050 defsubr (&Sline_end_position
);
4052 /* defsubr (&Smark); */
4053 /* defsubr (&Sset_mark); */
4054 defsubr (&Ssave_excursion
);
4055 defsubr (&Ssave_current_buffer
);
4057 defsubr (&Sbufsize
);
4058 defsubr (&Spoint_max
);
4059 defsubr (&Spoint_min
);
4060 defsubr (&Spoint_min_marker
);
4061 defsubr (&Spoint_max_marker
);
4062 defsubr (&Sgap_position
);
4063 defsubr (&Sgap_size
);
4064 defsubr (&Sposition_bytes
);
4065 defsubr (&Sbyte_to_position
);
4071 defsubr (&Sfollowing_char
);
4072 defsubr (&Sprevious_char
);
4073 defsubr (&Schar_after
);
4074 defsubr (&Schar_before
);
4076 defsubr (&Sinsert_before_markers
);
4077 defsubr (&Sinsert_and_inherit
);
4078 defsubr (&Sinsert_and_inherit_before_markers
);
4079 defsubr (&Sinsert_char
);
4081 defsubr (&Suser_login_name
);
4082 defsubr (&Suser_real_login_name
);
4083 defsubr (&Suser_uid
);
4084 defsubr (&Suser_real_uid
);
4085 defsubr (&Suser_full_name
);
4086 defsubr (&Semacs_pid
);
4087 defsubr (&Scurrent_time
);
4088 defsubr (&Sformat_time_string
);
4089 defsubr (&Sfloat_time
);
4090 defsubr (&Sdecode_time
);
4091 defsubr (&Sencode_time
);
4092 defsubr (&Scurrent_time_string
);
4093 defsubr (&Scurrent_time_zone
);
4094 defsubr (&Sset_time_zone_rule
);
4095 defsubr (&Ssystem_name
);
4096 defsubr (&Smessage
);
4097 defsubr (&Smessage_box
);
4098 defsubr (&Smessage_or_box
);
4099 defsubr (&Scurrent_message
);
4102 defsubr (&Sinsert_buffer_substring
);
4103 defsubr (&Scompare_buffer_substrings
);
4104 defsubr (&Ssubst_char_in_region
);
4105 defsubr (&Stranslate_region
);
4106 defsubr (&Sdelete_region
);
4107 defsubr (&Sdelete_and_extract_region
);
4109 defsubr (&Snarrow_to_region
);
4110 defsubr (&Ssave_restriction
);
4111 defsubr (&Stranspose_regions
);