aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorJoakim Verona2012-09-03 17:30:17 +0200
committerJoakim Verona2012-09-03 17:30:17 +0200
commit4a37733c693d59a9b83a3fb2d0c7f9461d149f60 (patch)
treea33402e09342f748baebf0e4f5a1e40538e620f4 /src/editfns.c
parent5436d1df5e2ba0b4d4f72b03a1cd09b20403654b (diff)
parentdcde497f27945c3ca4ce8c21f655ef6f627acdd2 (diff)
downloademacs-4a37733c693d59a9b83a3fb2d0c7f9461d149f60.tar.gz
emacs-4a37733c693d59a9b83a3fb2d0c7f9461d149f60.zip
upstream
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c112
1 files changed, 53 insertions, 59 deletions
diff --git a/src/editfns.c b/src/editfns.c
index c4725aa0ff3..a14e043c1bf 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -58,10 +58,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
58#include "window.h" 58#include "window.h"
59#include "blockinput.h" 59#include "blockinput.h"
60 60
61#ifndef USE_CRT_DLL
62extern char **environ;
63#endif
64
65#define TM_YEAR_BASE 1900 61#define TM_YEAR_BASE 1900
66 62
67#ifdef WINDOWSNT 63#ifdef WINDOWSNT
@@ -69,7 +65,7 @@ extern Lisp_Object w32_get_internal_run_time (void);
69#endif 65#endif
70 66
71static Lisp_Object format_time_string (char const *, ptrdiff_t, EMACS_TIME, 67static Lisp_Object format_time_string (char const *, ptrdiff_t, EMACS_TIME,
72 int, struct tm *); 68 bool, struct tm *);
73static int tm_diff (struct tm *, struct tm *); 69static int tm_diff (struct tm *, struct tm *);
74static void update_buffer_properties (ptrdiff_t, ptrdiff_t); 70static void update_buffer_properties (ptrdiff_t, ptrdiff_t);
75 71
@@ -250,11 +246,11 @@ The return value is POSITION. */)
250 246
251 247
252/* Return the start or end position of the region. 248/* Return the start or end position of the region.
253 BEGINNINGP non-zero means return the start. 249 BEGINNINGP means return the start.
254 If there is no region active, signal an error. */ 250 If there is no region active, signal an error. */
255 251
256static Lisp_Object 252static Lisp_Object
257region_limit (int beginningp) 253region_limit (bool beginningp)
258{ 254{
259 Lisp_Object m; 255 Lisp_Object m;
260 256
@@ -268,7 +264,7 @@ region_limit (int beginningp)
268 error ("The mark is not set now, so there is no region"); 264 error ("The mark is not set now, so there is no region");
269 265
270 /* Clip to the current narrowing (bug#11770). */ 266 /* Clip to the current narrowing (bug#11770). */
271 return make_number ((PT < XFASTINT (m)) == (beginningp != 0) 267 return make_number ((PT < XFASTINT (m)) == beginningp
272 ? PT 268 ? PT
273 : clip_to_bounds (BEGV, XFASTINT (m), ZV)); 269 : clip_to_bounds (BEGV, XFASTINT (m), ZV));
274} 270}
@@ -439,12 +435,12 @@ get_pos_property (Lisp_Object position, register Lisp_Object prop, Lisp_Object o
439 BEG_LIMIT and END_LIMIT serve to limit the ranged of the returned 435 BEG_LIMIT and END_LIMIT serve to limit the ranged of the returned
440 results; they do not effect boundary behavior. 436 results; they do not effect boundary behavior.
441 437
442 If MERGE_AT_BOUNDARY is nonzero, then if POS is at the very first 438 If MERGE_AT_BOUNDARY is non-nil, then if POS is at the very first
443 position of a field, then the beginning of the previous field is 439 position of a field, then the beginning of the previous field is
444 returned instead of the beginning of POS's field (since the end of a 440 returned instead of the beginning of POS's field (since the end of a
445 field is actually also the beginning of the next input field, this 441 field is actually also the beginning of the next input field, this
446 behavior is sometimes useful). Additionally in the MERGE_AT_BOUNDARY 442 behavior is sometimes useful). Additionally in the MERGE_AT_BOUNDARY
447 true case, if two fields are separated by a field with the special 443 non-nil case, if two fields are separated by a field with the special
448 value `boundary', and POS lies within it, then the two separated 444 value `boundary', and POS lies within it, then the two separated
449 fields are considered to be adjacent, and POS between them, when 445 fields are considered to be adjacent, and POS between them, when
450 finding the beginning and ending of the "merged" field. 446 finding the beginning and ending of the "merged" field.
@@ -459,10 +455,10 @@ find_field (Lisp_Object pos, Lisp_Object merge_at_boundary,
459{ 455{
460 /* Fields right before and after the point. */ 456 /* Fields right before and after the point. */
461 Lisp_Object before_field, after_field; 457 Lisp_Object before_field, after_field;
462 /* 1 if POS counts as the start of a field. */ 458 /* True if POS counts as the start of a field. */
463 int at_field_start = 0; 459 bool at_field_start = 0;
464 /* 1 if POS counts as the end of a field. */ 460 /* True if POS counts as the end of a field. */
465 int at_field_end = 0; 461 bool at_field_end = 0;
466 462
467 if (NILP (pos)) 463 if (NILP (pos))
468 XSETFASTINT (pos, PT); 464 XSETFASTINT (pos, PT);
@@ -506,19 +502,19 @@ find_field (Lisp_Object pos, Lisp_Object merge_at_boundary,
506 502
507 xxxx.yyyy 503 xxxx.yyyy
508 504
509 In this situation, if merge_at_boundary is true, we consider the 505 In this situation, if merge_at_boundary is non-nil, consider the
510 `x' and `y' fields as forming one big merged field, and so the end 506 `x' and `y' fields as forming one big merged field, and so the end
511 of the field is the end of `y'. 507 of the field is the end of `y'.
512 508
513 However, if `x' and `y' are separated by a special `boundary' field 509 However, if `x' and `y' are separated by a special `boundary' field
514 (a field with a `field' char-property of 'boundary), then we ignore 510 (a field with a `field' char-property of 'boundary), then ignore
515 this special field when merging adjacent fields. Here's the same 511 this special field when merging adjacent fields. Here's the same
516 situation, but with a `boundary' field between the `x' and `y' fields: 512 situation, but with a `boundary' field between the `x' and `y' fields:
517 513
518 xxx.BBBByyyy 514 xxx.BBBByyyy
519 515
520 Here, if point is at the end of `x', the beginning of `y', or 516 Here, if point is at the end of `x', the beginning of `y', or
521 anywhere in-between (within the `boundary' field), we merge all 517 anywhere in-between (within the `boundary' field), merge all
522 three fields and consider the beginning as being the beginning of 518 three fields and consider the beginning as being the beginning of
523 the `x' field, and the end as being the end of the `y' field. */ 519 the `x' field, and the end as being the end of the `y' field. */
524 520
@@ -662,7 +658,7 @@ Field boundaries are not noticed if `inhibit-field-text-motion' is non-nil. */)
662{ 658{
663 /* If non-zero, then the original point, before re-positioning. */ 659 /* If non-zero, then the original point, before re-positioning. */
664 ptrdiff_t orig_point = 0; 660 ptrdiff_t orig_point = 0;
665 int fwd; 661 bool fwd;
666 Lisp_Object prev_old, prev_new; 662 Lisp_Object prev_old, prev_new;
667 663
668 if (NILP (new_pos)) 664 if (NILP (new_pos))
@@ -820,8 +816,8 @@ This function does not move point. */)
820Lisp_Object 816Lisp_Object
821save_excursion_save (void) 817save_excursion_save (void)
822{ 818{
823 int visible = (XBUFFER (XWINDOW (selected_window)->buffer) 819 bool visible = (XBUFFER (XWINDOW (selected_window)->buffer)
824 == current_buffer); 820 == current_buffer);
825 821
826 return Fcons (Fpoint_marker (), 822 return Fcons (Fpoint_marker (),
827 Fcons (Fcopy_marker (BVAR (current_buffer, mark), Qnil), 823 Fcons (Fcopy_marker (BVAR (current_buffer, mark), Qnil),
@@ -835,7 +831,7 @@ save_excursion_restore (Lisp_Object info)
835{ 831{
836 Lisp_Object tem, tem1, omark, nmark; 832 Lisp_Object tem, tem1, omark, nmark;
837 struct gcpro gcpro1, gcpro2, gcpro3; 833 struct gcpro gcpro1, gcpro2, gcpro3;
838 int visible_p; 834 bool visible_p;
839 835
840 tem = Fmarker_buffer (XCAR (info)); 836 tem = Fmarker_buffer (XCAR (info));
841 /* If buffer being returned to is now deleted, avoid error */ 837 /* If buffer being returned to is now deleted, avoid error */
@@ -950,13 +946,10 @@ BODY is executed just like `progn'.
950usage: (save-current-buffer &rest BODY) */) 946usage: (save-current-buffer &rest BODY) */)
951 (Lisp_Object args) 947 (Lisp_Object args)
952{ 948{
953 Lisp_Object val;
954 ptrdiff_t count = SPECPDL_INDEX (); 949 ptrdiff_t count = SPECPDL_INDEX ();
955 950
956 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ()); 951 record_unwind_current_buffer ();
957 952 return unbind_to (count, Fprogn (args));
958 val = Fprogn (args);
959 return unbind_to (count, val);
960} 953}
961 954
962DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0, 955DEFUN ("buffer-size", Fbufsize, Sbufsize, 0, 1, 0,
@@ -1474,8 +1467,8 @@ make_lisp_time (EMACS_TIME t)
1474 1467
1475/* Decode a Lisp list SPECIFIED_TIME that represents a time. 1468/* Decode a Lisp list SPECIFIED_TIME that represents a time.
1476 Set *PHIGH, *PLOW, *PUSEC, *PPSEC to its parts; do not check their values. 1469 Set *PHIGH, *PLOW, *PUSEC, *PPSEC to its parts; do not check their values.
1477 Return nonzero if successful. */ 1470 Return true if successful. */
1478static int 1471static bool
1479disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh, 1472disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
1480 Lisp_Object *plow, Lisp_Object *pusec, 1473 Lisp_Object *plow, Lisp_Object *pusec,
1481 Lisp_Object *ppsec) 1474 Lisp_Object *ppsec)
@@ -1518,8 +1511,8 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
1518 If *DRESULT is not null, store into *DRESULT the number of 1511 If *DRESULT is not null, store into *DRESULT the number of
1519 seconds since the start of the POSIX Epoch. 1512 seconds since the start of the POSIX Epoch.
1520 1513
1521 Return nonzero if successful. */ 1514 Return true if successful. */
1522int 1515bool
1523decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, 1516decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1524 Lisp_Object psec, 1517 Lisp_Object psec,
1525 EMACS_TIME *result, double *dresult) 1518 EMACS_TIME *result, double *dresult)
@@ -1639,7 +1632,7 @@ or (if you need time as a string) `format-time-string'. */)
1639 1632
1640/* Write information into buffer S of size MAXSIZE, according to the 1633/* Write information into buffer S of size MAXSIZE, according to the
1641 FORMAT of length FORMAT_LEN, using time information taken from *TP. 1634 FORMAT of length FORMAT_LEN, using time information taken from *TP.
1642 Default to Universal Time if UT is nonzero, local time otherwise. 1635 Default to Universal Time if UT, local time otherwise.
1643 Use NS as the number of nanoseconds in the %N directive. 1636 Use NS as the number of nanoseconds in the %N directive.
1644 Return the number of bytes written, not including the terminating 1637 Return the number of bytes written, not including the terminating
1645 '\0'. If S is NULL, nothing will be written anywhere; so to 1638 '\0'. If S is NULL, nothing will be written anywhere; so to
@@ -1650,7 +1643,7 @@ or (if you need time as a string) `format-time-string'. */)
1650 bytes in FORMAT and it does not support nanoseconds. */ 1643 bytes in FORMAT and it does not support nanoseconds. */
1651static size_t 1644static size_t
1652emacs_nmemftime (char *s, size_t maxsize, const char *format, 1645emacs_nmemftime (char *s, size_t maxsize, const char *format,
1653 size_t format_len, const struct tm *tp, int ut, int ns) 1646 size_t format_len, const struct tm *tp, bool ut, int ns)
1654{ 1647{
1655 size_t total = 0; 1648 size_t total = 0;
1656 1649
@@ -1755,7 +1748,7 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */)
1755 1748
1756static Lisp_Object 1749static Lisp_Object
1757format_time_string (char const *format, ptrdiff_t formatlen, 1750format_time_string (char const *format, ptrdiff_t formatlen,
1758 EMACS_TIME t, int ut, struct tm *tmp) 1751 EMACS_TIME t, bool ut, struct tm *tmp)
1759{ 1752{
1760 char buffer[4000]; 1753 char buffer[4000];
1761 char *buf = buffer; 1754 char *buf = buffer;
@@ -2235,11 +2228,11 @@ general_insert_function (void (*insert_func)
2235 (const char *, ptrdiff_t), 2228 (const char *, ptrdiff_t),
2236 void (*insert_from_string_func) 2229 void (*insert_from_string_func)
2237 (Lisp_Object, ptrdiff_t, ptrdiff_t, 2230 (Lisp_Object, ptrdiff_t, ptrdiff_t,
2238 ptrdiff_t, ptrdiff_t, int), 2231 ptrdiff_t, ptrdiff_t, bool),
2239 int inherit, ptrdiff_t nargs, Lisp_Object *args) 2232 bool inherit, ptrdiff_t nargs, Lisp_Object *args)
2240{ 2233{
2241 ptrdiff_t argnum; 2234 ptrdiff_t argnum;
2242 register Lisp_Object val; 2235 Lisp_Object val;
2243 2236
2244 for (argnum = 0; argnum < nargs; argnum++) 2237 for (argnum = 0; argnum < nargs; argnum++)
2245 { 2238 {
@@ -2462,7 +2455,7 @@ from adjoining text, if those properties are sticky. */)
2462/* Return a Lisp_String containing the text of the current buffer from 2455/* Return a Lisp_String containing the text of the current buffer from
2463 START to END. If text properties are in use and the current buffer 2456 START to END. If text properties are in use and the current buffer
2464 has properties in the range specified, the resulting string will also 2457 has properties in the range specified, the resulting string will also
2465 have them, if PROPS is nonzero. 2458 have them, if PROPS is true.
2466 2459
2467 We don't want to use plain old make_string here, because it calls 2460 We don't want to use plain old make_string here, because it calls
2468 make_uninit_string, which can cause the buffer arena to be 2461 make_uninit_string, which can cause the buffer arena to be
@@ -2473,7 +2466,7 @@ from adjoining text, if those properties are sticky. */)
2473 buffer substrings. */ 2466 buffer substrings. */
2474 2467
2475Lisp_Object 2468Lisp_Object
2476make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props) 2469make_buffer_string (ptrdiff_t start, ptrdiff_t end, bool props)
2477{ 2470{
2478 ptrdiff_t start_byte = CHAR_TO_BYTE (start); 2471 ptrdiff_t start_byte = CHAR_TO_BYTE (start);
2479 ptrdiff_t end_byte = CHAR_TO_BYTE (end); 2472 ptrdiff_t end_byte = CHAR_TO_BYTE (end);
@@ -2486,7 +2479,7 @@ make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
2486 2479
2487 If text properties are in use and the current buffer 2480 If text properties are in use and the current buffer
2488 has properties in the range specified, the resulting string will also 2481 has properties in the range specified, the resulting string will also
2489 have them, if PROPS is nonzero. 2482 have them, if PROPS is true.
2490 2483
2491 We don't want to use plain old make_string here, because it calls 2484 We don't want to use plain old make_string here, because it calls
2492 make_uninit_string, which can cause the buffer arena to be 2485 make_uninit_string, which can cause the buffer arena to be
@@ -2498,7 +2491,7 @@ make_buffer_string (ptrdiff_t start, ptrdiff_t end, int props)
2498 2491
2499Lisp_Object 2492Lisp_Object
2500make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte, 2493make_buffer_string_both (ptrdiff_t start, ptrdiff_t start_byte,
2501 ptrdiff_t end, ptrdiff_t end_byte, int props) 2494 ptrdiff_t end, ptrdiff_t end_byte, bool props)
2502{ 2495{
2503 Lisp_Object result, tem, tem1; 2496 Lisp_Object result, tem, tem1;
2504 2497
@@ -2849,7 +2842,8 @@ Both characters must have the same length of multi-byte form. */)
2849#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER) 2842#define COMBINING_BOTH (COMBINING_BEFORE | COMBINING_AFTER)
2850 int maybe_byte_combining = COMBINING_NO; 2843 int maybe_byte_combining = COMBINING_NO;
2851 ptrdiff_t last_changed = 0; 2844 ptrdiff_t last_changed = 0;
2852 int multibyte_p = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 2845 bool multibyte_p
2846 = !NILP (BVAR (current_buffer, enable_multibyte_characters));
2853 int fromc, toc; 2847 int fromc, toc;
2854 2848
2855 restart: 2849 restart:
@@ -3085,8 +3079,8 @@ It returns the number of characters changed. */)
3085 int cnt; /* Number of changes made. */ 3079 int cnt; /* Number of changes made. */
3086 ptrdiff_t size; /* Size of translate table. */ 3080 ptrdiff_t size; /* Size of translate table. */
3087 ptrdiff_t pos, pos_byte, end_pos; 3081 ptrdiff_t pos, pos_byte, end_pos;
3088 int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); 3082 bool multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
3089 int string_multibyte IF_LINT (= 0); 3083 bool string_multibyte IF_LINT (= 0);
3090 3084
3091 validate_region (&start, &end); 3085 validate_region (&start, &end);
3092 if (CHAR_TABLE_P (table)) 3086 if (CHAR_TABLE_P (table))
@@ -3646,20 +3640,20 @@ usage: (format STRING &rest OBJECTS) */)
3646 ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1; 3640 ptrdiff_t max_bufsize = STRING_BYTES_BOUND + 1;
3647 char *p; 3641 char *p;
3648 Lisp_Object buf_save_value IF_LINT (= {0}); 3642 Lisp_Object buf_save_value IF_LINT (= {0});
3649 register char *format, *end, *format_start; 3643 char *format, *end, *format_start;
3650 ptrdiff_t formatlen, nchars; 3644 ptrdiff_t formatlen, nchars;
3651 /* Nonzero if the format is multibyte. */ 3645 /* True if the format is multibyte. */
3652 int multibyte_format = 0; 3646 bool multibyte_format = 0;
3653 /* Nonzero if the output should be a multibyte string, 3647 /* True if the output should be a multibyte string,
3654 which is true if any of the inputs is one. */ 3648 which is true if any of the inputs is one. */
3655 int multibyte = 0; 3649 bool multibyte = 0;
3656 /* When we make a multibyte string, we must pay attention to the 3650 /* When we make a multibyte string, we must pay attention to the
3657 byte combining problem, i.e., a byte may be combined with a 3651 byte combining problem, i.e., a byte may be combined with a
3658 multibyte character of the previous string. This flag tells if we 3652 multibyte character of the previous string. This flag tells if we
3659 must consider such a situation or not. */ 3653 must consider such a situation or not. */
3660 int maybe_combine_byte; 3654 bool maybe_combine_byte;
3661 Lisp_Object val; 3655 Lisp_Object val;
3662 int arg_intervals = 0; 3656 bool arg_intervals = 0;
3663 USE_SAFE_ALLOCA; 3657 USE_SAFE_ALLOCA;
3664 3658
3665 /* discarded[I] is 1 if byte I of the format 3659 /* discarded[I] is 1 if byte I of the format
@@ -3675,8 +3669,8 @@ usage: (format STRING &rest OBJECTS) */)
3675 struct info 3669 struct info
3676 { 3670 {
3677 ptrdiff_t start, end; 3671 ptrdiff_t start, end;
3678 int converted_to_string; 3672 unsigned converted_to_string : 1;
3679 int intervals; 3673 unsigned intervals : 1;
3680 } *info = 0; 3674 } *info = 0;
3681 3675
3682 /* It should not be necessary to GCPRO ARGS, because 3676 /* It should not be necessary to GCPRO ARGS, because
@@ -3753,13 +3747,13 @@ usage: (format STRING &rest OBJECTS) */)
3753 digits to print after the '.' for floats, or the max. 3747 digits to print after the '.' for floats, or the max.
3754 number of chars to print from a string. */ 3748 number of chars to print from a string. */
3755 3749
3756 int minus_flag = 0; 3750 bool minus_flag = 0;
3757 int plus_flag = 0; 3751 bool plus_flag = 0;
3758 int space_flag = 0; 3752 bool space_flag = 0;
3759 int sharp_flag = 0; 3753 bool sharp_flag = 0;
3760 int zero_flag = 0; 3754 bool zero_flag = 0;
3761 ptrdiff_t field_width; 3755 ptrdiff_t field_width;
3762 int precision_given; 3756 bool precision_given;
3763 uintmax_t precision = UINTMAX_MAX; 3757 uintmax_t precision = UINTMAX_MAX;
3764 char *num_end; 3758 char *num_end;
3765 char conversion; 3759 char conversion;
@@ -4139,7 +4133,7 @@ usage: (format STRING &rest OBJECTS) */)
4139 char *src = sprintf_buf; 4133 char *src = sprintf_buf;
4140 char src0 = src[0]; 4134 char src0 = src[0];
4141 int exponent_bytes = 0; 4135 int exponent_bytes = 0;
4142 int signedp = src0 == '-' || src0 == '+' || src0 == ' '; 4136 bool signedp = src0 == '-' || src0 == '+' || src0 == ' ';
4143 int significand_bytes; 4137 int significand_bytes;
4144 if (zero_flag 4138 if (zero_flag
4145 && ((src[signedp] >= '0' && src[signedp] <= '9') 4139 && ((src[signedp] >= '0' && src[signedp] <= '9')