Mercurial > emacs
comparison src/editfns.c @ 31016:b26ac1565dd4
(find_field): Formatting changes.
(toplevel): Some old-style function forward declarations
changed to prototypes, some new protypes added, some functions
made static.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 21 Aug 2000 19:47:54 +0000 |
parents | 35428eaf59e3 |
children | e19d38e14720 |
comparison
equal
deleted
inserted
replaced
31015:0a24ffcc4061 | 31016:b26ac1565dd4 |
---|---|
1 /* Lisp functions pertaining to editing. | 1 /* Lisp functions pertaining to editing. |
2 Copyright (C) 1985,86,87,89,93,94,95,96,97,98, 1999 Free Software Foundation, Inc. | 2 Copyright (C) 1985,86,87,89,93,94,95,96,97,98, 1999, 2000 |
3 Free Software Foundation, Inc. | |
3 | 4 |
4 This file is part of GNU Emacs. | 5 This file is part of GNU Emacs. |
5 | 6 |
6 GNU Emacs is free software; you can redistribute it and/or modify | 7 GNU Emacs is free software; you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 8 it under the terms of the GNU General Public License as published by |
47 #ifndef NULL | 48 #ifndef NULL |
48 #define NULL 0 | 49 #define NULL 0 |
49 #endif | 50 #endif |
50 | 51 |
51 extern char **environ; | 52 extern char **environ; |
52 extern int use_dialog_box; | 53 extern Lisp_Object make_time P_ ((time_t)); |
53 extern Lisp_Object make_time (); | 54 extern size_t emacs_strftimeu P_ ((char *, size_t, const char *, |
54 extern void insert_from_buffer (); | 55 const struct tm *, int)); |
55 static int tm_diff (); | 56 static int tm_diff P_ ((struct tm *, struct tm *)); |
56 static void update_buffer_properties (); | 57 static void find_field P_ ((Lisp_Object, Lisp_Object, int *, int *)); |
57 size_t emacs_strftimeu (); | 58 static void update_buffer_properties P_ ((int, int)); |
58 void set_time_zone_rule (); | 59 static Lisp_Object region_limit P_ ((int)); |
60 static int lisp_time_argument P_ ((Lisp_Object, time_t *, int *)); | |
61 static size_t emacs_memftimeu P_ ((char *, size_t, const char *, | |
62 size_t, const struct tm *, int)); | |
63 static void general_insert_function P_ ((void (*) (unsigned char *, int), | |
64 void (*) (Lisp_Object, int, int, int, | |
65 int, int), | |
66 int, int, Lisp_Object *)); | |
67 static Lisp_Object subst_char_in_region_unwind P_ ((Lisp_Object)); | |
68 static Lisp_Object subst_char_in_region_unwind_1 P_ ((Lisp_Object)); | |
69 static void transpose_markers P_ ((int, int, int, int, int, int, int, int)); | |
59 | 70 |
60 Lisp_Object Vbuffer_access_fontify_functions; | 71 Lisp_Object Vbuffer_access_fontify_functions; |
61 Lisp_Object Qbuffer_access_fontify_functions; | 72 Lisp_Object Qbuffer_access_fontify_functions; |
62 Lisp_Object Vbuffer_access_fontified_property; | 73 Lisp_Object Vbuffer_access_fontified_property; |
63 | 74 |
64 Lisp_Object Fuser_full_name (); | 75 Lisp_Object Fuser_full_name P_ ((Lisp_Object)); |
65 | 76 |
66 /* Non-nil means don't stop at field boundary in text motion commands. */ | 77 /* Non-nil means don't stop at field boundary in text motion commands. */ |
67 | 78 |
68 Lisp_Object Vinhibit_field_text_motion; | 79 Lisp_Object Vinhibit_field_text_motion; |
69 | 80 |
71 | 82 |
72 Lisp_Object Vsystem_name; | 83 Lisp_Object Vsystem_name; |
73 Lisp_Object Vuser_real_login_name; /* login name of current user ID */ | 84 Lisp_Object Vuser_real_login_name; /* login name of current user ID */ |
74 Lisp_Object Vuser_full_name; /* full name of current user */ | 85 Lisp_Object Vuser_full_name; /* full name of current user */ |
75 Lisp_Object Vuser_login_name; /* user name from LOGNAME or USER */ | 86 Lisp_Object Vuser_login_name; /* user name from LOGNAME or USER */ |
87 | |
88 /* Symbol for the text property used to mark fields. */ | |
89 | |
90 Lisp_Object Qfield; | |
91 | |
92 /* A special value for Qfield properties. */ | |
93 | |
94 Lisp_Object Qboundary; | |
95 | |
76 | 96 |
77 void | 97 void |
78 init_editfns () | 98 init_editfns () |
79 { | 99 { |
80 char *user_name; | 100 char *user_name; |
235 pos = clip_to_bounds (BEGV, XINT (position), ZV); | 255 pos = clip_to_bounds (BEGV, XINT (position), ZV); |
236 SET_PT (pos); | 256 SET_PT (pos); |
237 return position; | 257 return position; |
238 } | 258 } |
239 | 259 |
260 | |
261 /* Return the start or end position of the region. | |
262 BEGINNINGP non-zero means return the start. | |
263 If there is no region active, signal an error. */ | |
264 | |
240 static Lisp_Object | 265 static Lisp_Object |
241 region_limit (beginningp) | 266 region_limit (beginningp) |
242 int beginningp; | 267 int beginningp; |
243 { | 268 { |
244 extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c. */ | 269 extern Lisp_Object Vmark_even_if_inactive; /* Defined in callint.c. */ |
245 register Lisp_Object m; | 270 Lisp_Object m; |
246 if (!NILP (Vtransient_mark_mode) && NILP (Vmark_even_if_inactive) | 271 |
272 if (!NILP (Vtransient_mark_mode) | |
273 && NILP (Vmark_even_if_inactive) | |
247 && NILP (current_buffer->mark_active)) | 274 && NILP (current_buffer->mark_active)) |
248 Fsignal (Qmark_inactive, Qnil); | 275 Fsignal (Qmark_inactive, Qnil); |
276 | |
249 m = Fmarker_position (current_buffer->mark); | 277 m = Fmarker_position (current_buffer->mark); |
250 if (NILP (m)) error ("There is no region now"); | 278 if (NILP (m)) |
279 error ("There is no region now"); | |
280 | |
251 if ((PT < XFASTINT (m)) == beginningp) | 281 if ((PT < XFASTINT (m)) == beginningp) |
252 return (make_number (PT)); | 282 m = make_number (PT); |
253 else | 283 return m; |
254 return (m); | |
255 } | 284 } |
256 | 285 |
257 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0, | 286 DEFUN ("region-beginning", Fregion_beginning, Sregion_beginning, 0, 0, 0, |
258 "Return position of beginning of region, as an integer.") | 287 "Return position of beginning of region, as an integer.") |
259 () | 288 () |
260 { | 289 { |
261 return (region_limit (1)); | 290 return region_limit (1); |
262 } | 291 } |
263 | 292 |
264 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0, | 293 DEFUN ("region-end", Fregion_end, Sregion_end, 0, 0, 0, |
265 "Return position of end of region, as an integer.") | 294 "Return position of end of region, as an integer.") |
266 () | 295 () |
267 { | 296 { |
268 return (region_limit (0)); | 297 return region_limit (0); |
269 } | 298 } |
270 | 299 |
271 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0, | 300 DEFUN ("mark-marker", Fmark_marker, Smark_marker, 0, 0, 0, |
272 "Return this buffer's mark, as a marker object.\n\ | 301 "Return this buffer's mark, as a marker object.\n\ |
273 Watch out! Moving this marker changes the mark position.\n\ | 302 Watch out! Moving this marker changes the mark position.\n\ |
274 If you set the marker not to point anywhere, the buffer will have no mark.") | 303 If you set the marker not to point anywhere, the buffer will have no mark.") |
275 () | 304 () |
276 { | 305 { |
277 return current_buffer->mark; | 306 return current_buffer->mark; |
278 } | 307 } |
308 | |
279 | 309 |
280 /* Return nonzero if POS1 and POS2 have the same value | 310 /* Return nonzero if POS1 and POS2 have the same value |
281 for the text property PROP. */ | 311 for the text property PROP. */ |
282 | 312 |
283 static int | 313 static int |
331 return 1; | 361 return 1; |
332 | 362 |
333 /* PROP is not inherited from either side. */ | 363 /* PROP is not inherited from either side. */ |
334 return 0; | 364 return 0; |
335 } | 365 } |
366 | |
336 | 367 |
337 /* Symbol for the text property used to mark fields. */ | |
338 Lisp_Object Qfield; | |
339 | |
340 /* A special value for Qfield properties. */ | |
341 Lisp_Object Qboundary; | |
342 | |
343 /* Find the field surrounding POS in *BEG and *END. If POS is nil, | 368 /* Find the field surrounding POS in *BEG and *END. If POS is nil, |
344 the value of point is used instead. | 369 the value of point is used instead. If BEG or END null, |
370 means don't store the beginning or end of the field. | |
345 | 371 |
346 If MERGE_AT_BOUNDARY is nonzero, then if POS is at the very first | 372 If MERGE_AT_BOUNDARY is nonzero, then if POS is at the very first |
347 position of a field, then the beginning of the previous field is | 373 position of a field, then the beginning of the previous field is |
348 returned instead of the beginning of POS's field (since the end of a | 374 returned instead of the beginning of POS's field (since the end of a |
349 field is actually also the beginning of the next input field, this | 375 field is actually also the beginning of the next input field, this |
354 finding the beginning and ending of the "merged" field. | 380 finding the beginning and ending of the "merged" field. |
355 | 381 |
356 Either BEG or END may be 0, in which case the corresponding value | 382 Either BEG or END may be 0, in which case the corresponding value |
357 is not stored. */ | 383 is not stored. */ |
358 | 384 |
359 void | 385 static void |
360 find_field (pos, merge_at_boundary, beg, end) | 386 find_field (pos, merge_at_boundary, beg, end) |
361 Lisp_Object pos; | 387 Lisp_Object pos; |
362 Lisp_Object merge_at_boundary; | 388 Lisp_Object merge_at_boundary; |
363 int *beg, *end; | 389 int *beg, *end; |
364 { | 390 { |
372 if (NILP (pos)) | 398 if (NILP (pos)) |
373 XSETFASTINT (pos, PT); | 399 XSETFASTINT (pos, PT); |
374 else | 400 else |
375 CHECK_NUMBER_COERCE_MARKER (pos, 0); | 401 CHECK_NUMBER_COERCE_MARKER (pos, 0); |
376 | 402 |
377 after_field = | 403 after_field |
378 Fget_char_property (pos, Qfield, Qnil); | 404 = Fget_char_property (pos, Qfield, Qnil); |
379 before_field = | 405 before_field |
380 (XFASTINT (pos) > BEGV | 406 = (XFASTINT (pos) > BEGV |
381 ? Fget_char_property (make_number (XINT (pos) - 1), Qfield, Qnil) | 407 ? Fget_char_property (make_number (XINT (pos) - 1), Qfield, Qnil) |
382 : Qnil); | 408 : Qnil); |
383 | 409 |
384 /* See if we need to handle the case where MERGE_AT_BOUNDARY is nil | 410 /* See if we need to handle the case where MERGE_AT_BOUNDARY is nil |
385 and POS is at beginning of a field, which can also be interpreted | 411 and POS is at beginning of a field, which can also be interpreted |
386 as the end of the previous field. Note that the case where if | 412 as the end of the previous field. Note that the case where if |
387 MERGE_AT_BOUNDARY is non-nil (see function comment) is actually the | 413 MERGE_AT_BOUNDARY is non-nil (see function comment) is actually the |
431 anywhere in-between (within the `boundary' field), we merge all | 457 anywhere in-between (within the `boundary' field), we merge all |
432 three fields and consider the beginning as being the beginning of | 458 three fields and consider the beginning as being the beginning of |
433 the `x' field, and the end as being the end of the `y' field. */ | 459 the `x' field, and the end as being the end of the `y' field. */ |
434 | 460 |
435 if (beg) | 461 if (beg) |
436 if (at_field_start) | 462 { |
437 /* POS is at the edge of a field, and we should consider it as | 463 if (at_field_start) |
438 the beginning of the following field. */ | 464 /* POS is at the edge of a field, and we should consider it as |
439 *beg = XFASTINT (pos); | 465 the beginning of the following field. */ |
440 else | 466 *beg = XFASTINT (pos); |
441 /* Find the previous field boundary. */ | 467 else |
442 { | 468 /* Find the previous field boundary. */ |
443 if (!NILP (merge_at_boundary) && EQ (before_field, Qboundary)) | 469 { |
444 /* Skip a `boundary' field. */ | 470 if (!NILP (merge_at_boundary) && EQ (before_field, Qboundary)) |
445 pos = Fprevious_single_char_property_change (pos, Qfield, Qnil,Qnil); | 471 /* Skip a `boundary' field. */ |
446 | 472 pos = Fprevious_single_char_property_change (pos, Qfield, Qnil,Qnil); |
447 pos = Fprevious_single_char_property_change (pos, Qfield, Qnil, Qnil); | 473 |
448 *beg = NILP (pos) ? BEGV : XFASTINT (pos); | 474 pos = Fprevious_single_char_property_change (pos, Qfield, Qnil, Qnil); |
449 } | 475 *beg = NILP (pos) ? BEGV : XFASTINT (pos); |
476 } | |
477 } | |
450 | 478 |
451 if (end) | 479 if (end) |
452 if (at_field_end) | 480 { |
453 /* POS is at the edge of a field, and we should consider it as | 481 if (at_field_end) |
454 the end of the previous field. */ | 482 /* POS is at the edge of a field, and we should consider it as |
455 *end = XFASTINT (pos); | 483 the end of the previous field. */ |
456 else | 484 *end = XFASTINT (pos); |
457 /* Find the next field boundary. */ | 485 else |
458 { | 486 /* Find the next field boundary. */ |
459 if (!NILP (merge_at_boundary) && EQ (after_field, Qboundary)) | 487 { |
460 /* Skip a `boundary' field. */ | 488 if (!NILP (merge_at_boundary) && EQ (after_field, Qboundary)) |
489 /* Skip a `boundary' field. */ | |
490 pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil); | |
491 | |
461 pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil); | 492 pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil); |
462 | 493 *end = NILP (pos) ? ZV : XFASTINT (pos); |
463 pos = Fnext_single_char_property_change (pos, Qfield, Qnil, Qnil); | 494 } |
464 *end = NILP (pos) ? ZV : XFASTINT (pos); | 495 } |
465 } | 496 } |
466 } | 497 |
467 | 498 |
468 DEFUN ("delete-field", Fdelete_field, Sdelete_field, 0, 1, 0, | 499 DEFUN ("delete-field", Fdelete_field, Sdelete_field, 0, 1, 0, |
469 "Delete the field surrounding POS.\n\ | 500 "Delete the field surrounding POS.\n\ |
470 A field is a region of text with the same `field' property.\n\ | 501 A field is a region of text with the same `field' property.\n\ |
471 If POS is nil, the value of point is used for POS.") | 502 If POS is nil, the value of point is used for POS.") |
618 SET_PT (XFASTINT (new_pos)); | 649 SET_PT (XFASTINT (new_pos)); |
619 } | 650 } |
620 | 651 |
621 return new_pos; | 652 return new_pos; |
622 } | 653 } |
654 | |
623 | 655 |
624 DEFUN ("line-beginning-position", Fline_beginning_position, Sline_beginning_position, | 656 DEFUN ("line-beginning-position", Fline_beginning_position, Sline_beginning_position, |
625 0, 1, 0, | 657 0, 1, 0, |
626 "Return the character position of the first character on the current line.\n\ | 658 "Return the character position of the first character on the current line.\n\ |
627 With argument N not nil or 1, move forward N - 1 lines first.\n\ | 659 With argument N not nil or 1, move forward N - 1 lines first.\n\ |
633 \n\ | 665 \n\ |
634 This function does not move point.") | 666 This function does not move point.") |
635 (n) | 667 (n) |
636 Lisp_Object n; | 668 Lisp_Object n; |
637 { | 669 { |
638 register int orig, orig_byte, end; | 670 int orig, orig_byte, end; |
639 | 671 |
640 if (NILP (n)) | 672 if (NILP (n)) |
641 XSETFASTINT (n, 1); | 673 XSETFASTINT (n, 1); |
642 else | 674 else |
643 CHECK_NUMBER (n, 0); | 675 CHECK_NUMBER (n, 0); |
663 This function does not move point.") | 695 This function does not move point.") |
664 (n) | 696 (n) |
665 Lisp_Object n; | 697 Lisp_Object n; |
666 { | 698 { |
667 int end_pos; | 699 int end_pos; |
668 register int orig = PT; | 700 int orig = PT; |
669 | 701 |
670 if (NILP (n)) | 702 if (NILP (n)) |
671 XSETFASTINT (n, 1); | 703 XSETFASTINT (n, 1); |
672 else | 704 else |
673 CHECK_NUMBER (n, 0); | 705 CHECK_NUMBER (n, 0); |
680 } | 712 } |
681 | 713 |
682 Lisp_Object | 714 Lisp_Object |
683 save_excursion_save () | 715 save_excursion_save () |
684 { | 716 { |
685 register int visible = (XBUFFER (XWINDOW (selected_window)->buffer) | 717 int visible = (XBUFFER (XWINDOW (selected_window)->buffer) |
686 == current_buffer); | 718 == current_buffer); |
687 | 719 |
688 return Fcons (Fpoint_marker (), | 720 return Fcons (Fpoint_marker (), |
689 Fcons (Fcopy_marker (current_buffer->mark, Qnil), | 721 Fcons (Fcopy_marker (current_buffer->mark, Qnil), |
690 Fcons (visible ? Qt : Qnil, | 722 Fcons (visible ? Qt : Qnil, |
691 current_buffer->mark_active))); | 723 current_buffer->mark_active))); |
775 "Save the current buffer; execute BODY; restore the current buffer.\n\ | 807 "Save the current buffer; execute BODY; restore the current buffer.\n\ |
776 Executes BODY just like `progn'.") | 808 Executes BODY just like `progn'.") |
777 (args) | 809 (args) |
778 Lisp_Object args; | 810 Lisp_Object args; |
779 { | 811 { |
780 register Lisp_Object val; | 812 Lisp_Object val; |
781 int count = specpdl_ptr - specpdl; | 813 int count = specpdl_ptr - specpdl; |
782 | 814 |
783 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); | 815 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); |
784 | 816 |
785 val = Fprogn (args); | 817 val = Fprogn (args); |
1152 { | 1184 { |
1153 return Vsystem_name; | 1185 return Vsystem_name; |
1154 } | 1186 } |
1155 | 1187 |
1156 /* For the benefit of callers who don't want to include lisp.h */ | 1188 /* For the benefit of callers who don't want to include lisp.h */ |
1189 | |
1157 char * | 1190 char * |
1158 get_system_name () | 1191 get_system_name () |
1159 { | 1192 { |
1160 if (STRINGP (Vsystem_name)) | 1193 if (STRINGP (Vsystem_name)) |
1161 return (char *) XSTRING (Vsystem_name)->data; | 1194 return (char *) XSTRING (Vsystem_name)->data; |
1708 #endif | 1741 #endif |
1709 | 1742 |
1710 /* Set the local time zone rule to TZSTRING. | 1743 /* Set the local time zone rule to TZSTRING. |
1711 This allocates memory into `environ', which it is the caller's | 1744 This allocates memory into `environ', which it is the caller's |
1712 responsibility to free. */ | 1745 responsibility to free. */ |
1746 | |
1713 void | 1747 void |
1714 set_time_zone_rule (tzstring) | 1748 set_time_zone_rule (tzstring) |
1715 char *tzstring; | 1749 char *tzstring; |
1716 { | 1750 { |
1717 int envptrs; | 1751 int envptrs; |
1789 /* Insert NARGS Lisp objects in the array ARGS by calling INSERT_FUNC | 1823 /* Insert NARGS Lisp objects in the array ARGS by calling INSERT_FUNC |
1790 (if a type of object is Lisp_Int) or INSERT_FROM_STRING_FUNC (if a | 1824 (if a type of object is Lisp_Int) or INSERT_FROM_STRING_FUNC (if a |
1791 type of object is Lisp_String). INHERIT is passed to | 1825 type of object is Lisp_String). INHERIT is passed to |
1792 INSERT_FROM_STRING_FUNC as the last argument. */ | 1826 INSERT_FROM_STRING_FUNC as the last argument. */ |
1793 | 1827 |
1794 void | 1828 static void |
1795 general_insert_function (insert_func, insert_from_string_func, | 1829 general_insert_function (insert_func, insert_from_string_func, |
1796 inherit, nargs, args) | 1830 inherit, nargs, args) |
1797 void (*insert_func) P_ ((unsigned char *, int)); | 1831 void (*insert_func) P_ ((unsigned char *, int)); |
1798 void (*insert_from_string_func) P_ ((Lisp_Object, int, int, int, int, int)); | 1832 void (*insert_from_string_func) P_ ((Lisp_Object, int, int, int, int, int)); |
1799 int inherit, nargs; | 1833 int inherit, nargs; |
3384 appropriate amount to some, subtracting from some, and leaving the | 3418 appropriate amount to some, subtracting from some, and leaving the |
3385 rest untouched. Most of this is copied from adjust_markers in insdel.c. | 3419 rest untouched. Most of this is copied from adjust_markers in insdel.c. |
3386 | 3420 |
3387 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */ | 3421 It's the caller's job to ensure that START1 <= END1 <= START2 <= END2. */ |
3388 | 3422 |
3389 void | 3423 static void |
3390 transpose_markers (start1, end1, start2, end2, | 3424 transpose_markers (start1, end1, start2, end2, |
3391 start1_byte, end1_byte, start2_byte, end2_byte) | 3425 start1_byte, end1_byte, start2_byte, end2_byte) |
3392 register int start1, end1, start2, end2; | 3426 register int start1, end1, start2, end2; |
3393 register int start1_byte, end1_byte, start2_byte, end2_byte; | 3427 register int start1_byte, end1_byte, start2_byte, end2_byte; |
3394 { | 3428 { |