diff options
| author | Xue Fuqiao | 2013-09-04 08:39:34 +0800 |
|---|---|---|
| committer | Xue Fuqiao | 2013-09-04 08:39:34 +0800 |
| commit | adf2fc4a01efe77d73cd52bc9173914ed56ff531 (patch) | |
| tree | a5a280a5554a7bffeaf94fccae29fa3ac1a5d066 /src/editfns.c | |
| parent | 63191d9f2043d2e67657e85a7b3842805dd1dad6 (diff) | |
| parent | 38726039b77db432989fed106c88e9f1aa463281 (diff) | |
| download | emacs-adf2fc4a01efe77d73cd52bc9173914ed56ff531.tar.gz emacs-adf2fc4a01efe77d73cd52bc9173914ed56ff531.zip | |
Merge from mainline.
Diffstat (limited to 'src/editfns.c')
| -rw-r--r-- | src/editfns.c | 92 |
1 files changed, 41 insertions, 51 deletions
diff --git a/src/editfns.c b/src/editfns.c index 50bde90788d..84a5c8395fc 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -64,7 +64,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 64 | extern Lisp_Object w32_get_internal_run_time (void); | 64 | extern Lisp_Object w32_get_internal_run_time (void); |
| 65 | #endif | 65 | #endif |
| 66 | 66 | ||
| 67 | static Lisp_Object format_time_string (char const *, ptrdiff_t, EMACS_TIME, | 67 | static Lisp_Object format_time_string (char const *, ptrdiff_t, struct timespec, |
| 68 | bool, struct tm *); | 68 | bool, struct tm *); |
| 69 | static int tm_diff (struct tm *, struct tm *); | 69 | static int tm_diff (struct tm *, struct tm *); |
| 70 | static void update_buffer_properties (ptrdiff_t, ptrdiff_t); | 70 | static void update_buffer_properties (ptrdiff_t, ptrdiff_t); |
| @@ -233,26 +233,12 @@ Beginning of buffer is position (point-min), end is (point-max). | |||
| 233 | The return value is POSITION. */) | 233 | The return value is POSITION. */) |
| 234 | (register Lisp_Object position) | 234 | (register Lisp_Object position) |
| 235 | { | 235 | { |
| 236 | ptrdiff_t pos; | 236 | if (MARKERP (position)) |
| 237 | 237 | set_point_from_marker (position); | |
| 238 | if (MARKERP (position) | 238 | else if (INTEGERP (position)) |
| 239 | && current_buffer == XMARKER (position)->buffer) | 239 | SET_PT (clip_to_bounds (BEGV, XINT (position), ZV)); |
| 240 | { | 240 | else |
| 241 | pos = marker_position (position); | 241 | wrong_type_argument (Qinteger_or_marker_p, position); |
| 242 | if (pos < BEGV) | ||
| 243 | SET_PT_BOTH (BEGV, BEGV_BYTE); | ||
| 244 | else if (pos > ZV) | ||
| 245 | SET_PT_BOTH (ZV, ZV_BYTE); | ||
| 246 | else | ||
| 247 | SET_PT_BOTH (pos, marker_byte_position (position)); | ||
| 248 | |||
| 249 | return position; | ||
| 250 | } | ||
| 251 | |||
| 252 | CHECK_NUMBER_COERCE_MARKER (position); | ||
| 253 | |||
| 254 | pos = clip_to_bounds (BEGV, XINT (position), ZV); | ||
| 255 | SET_PT (pos); | ||
| 256 | return position; | 242 | return position; |
| 257 | } | 243 | } |
| 258 | 244 | ||
| @@ -1420,7 +1406,7 @@ least significant 16 bits. USEC and PSEC are the microsecond and | |||
| 1420 | picosecond counts. */) | 1406 | picosecond counts. */) |
| 1421 | (void) | 1407 | (void) |
| 1422 | { | 1408 | { |
| 1423 | return make_lisp_time (current_emacs_time ()); | 1409 | return make_lisp_time (current_timespec ()); |
| 1424 | } | 1410 | } |
| 1425 | 1411 | ||
| 1426 | DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, | 1412 | DEFUN ("get-internal-run-time", Fget_internal_run_time, Sget_internal_run_time, |
| @@ -1450,7 +1436,7 @@ does the same thing as `current-time'. */) | |||
| 1450 | usecs -= 1000000; | 1436 | usecs -= 1000000; |
| 1451 | secs++; | 1437 | secs++; |
| 1452 | } | 1438 | } |
| 1453 | return make_lisp_time (make_emacs_time (secs, usecs * 1000)); | 1439 | return make_lisp_time (make_timespec (secs, usecs * 1000)); |
| 1454 | #else /* ! HAVE_GETRUSAGE */ | 1440 | #else /* ! HAVE_GETRUSAGE */ |
| 1455 | #ifdef WINDOWSNT | 1441 | #ifdef WINDOWSNT |
| 1456 | return w32_get_internal_run_time (); | 1442 | return w32_get_internal_run_time (); |
| @@ -1481,10 +1467,10 @@ make_time (time_t t) | |||
| 1481 | UNKNOWN_MODTIME_NSECS; in that case, the Lisp list contains a | 1467 | UNKNOWN_MODTIME_NSECS; in that case, the Lisp list contains a |
| 1482 | correspondingly negative picosecond count. */ | 1468 | correspondingly negative picosecond count. */ |
| 1483 | Lisp_Object | 1469 | Lisp_Object |
| 1484 | make_lisp_time (EMACS_TIME t) | 1470 | make_lisp_time (struct timespec t) |
| 1485 | { | 1471 | { |
| 1486 | int ns = EMACS_NSECS (t); | 1472 | int ns = t.tv_nsec; |
| 1487 | return make_time_tail (EMACS_SECS (t), list2i (ns / 1000, ns % 1000 * 1000)); | 1473 | return make_time_tail (t.tv_sec, list2i (ns / 1000, ns % 1000 * 1000)); |
| 1488 | } | 1474 | } |
| 1489 | 1475 | ||
| 1490 | /* Decode a Lisp list SPECIFIED_TIME that represents a time. | 1476 | /* Decode a Lisp list SPECIFIED_TIME that represents a time. |
| @@ -1529,7 +1515,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh, | |||
| 1529 | list, generate the corresponding time value. | 1515 | list, generate the corresponding time value. |
| 1530 | 1516 | ||
| 1531 | If RESULT is not null, store into *RESULT the converted time; | 1517 | If RESULT is not null, store into *RESULT the converted time; |
| 1532 | this can fail if the converted time does not fit into EMACS_TIME. | 1518 | this can fail if the converted time does not fit into struct timespec. |
| 1533 | If *DRESULT is not null, store into *DRESULT the number of | 1519 | If *DRESULT is not null, store into *DRESULT the number of |
| 1534 | seconds since the start of the POSIX Epoch. | 1520 | seconds since the start of the POSIX Epoch. |
| 1535 | 1521 | ||
| @@ -1537,7 +1523,7 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh, | |||
| 1537 | bool | 1523 | bool |
| 1538 | decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, | 1524 | decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, |
| 1539 | Lisp_Object psec, | 1525 | Lisp_Object psec, |
| 1540 | EMACS_TIME *result, double *dresult) | 1526 | struct timespec *result, double *dresult) |
| 1541 | { | 1527 | { |
| 1542 | EMACS_INT hi, lo, us, ps; | 1528 | EMACS_INT hi, lo, us, ps; |
| 1543 | if (! (INTEGERP (high) && INTEGERP (low) | 1529 | if (! (INTEGERP (high) && INTEGERP (low) |
| @@ -1565,7 +1551,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, | |||
| 1565 | /* Return the greatest representable time that is not greater | 1551 | /* Return the greatest representable time that is not greater |
| 1566 | than the requested time. */ | 1552 | than the requested time. */ |
| 1567 | time_t sec = hi; | 1553 | time_t sec = hi; |
| 1568 | *result = make_emacs_time ((sec << 16) + lo, us * 1000 + ps / 1000); | 1554 | *result = make_timespec ((sec << 16) + lo, us * 1000 + ps / 1000); |
| 1569 | } | 1555 | } |
| 1570 | else | 1556 | else |
| 1571 | { | 1557 | { |
| @@ -1583,15 +1569,15 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec, | |||
| 1583 | /* Decode a Lisp list SPECIFIED_TIME that represents a time. | 1569 | /* Decode a Lisp list SPECIFIED_TIME that represents a time. |
| 1584 | If SPECIFIED_TIME is nil, use the current time. | 1570 | If SPECIFIED_TIME is nil, use the current time. |
| 1585 | 1571 | ||
| 1586 | Round the time down to the nearest EMACS_TIME value. | 1572 | Round the time down to the nearest struct timespec value. |
| 1587 | Return seconds since the Epoch. | 1573 | Return seconds since the Epoch. |
| 1588 | Signal an error if unsuccessful. */ | 1574 | Signal an error if unsuccessful. */ |
| 1589 | EMACS_TIME | 1575 | struct timespec |
| 1590 | lisp_time_argument (Lisp_Object specified_time) | 1576 | lisp_time_argument (Lisp_Object specified_time) |
| 1591 | { | 1577 | { |
| 1592 | EMACS_TIME t; | 1578 | struct timespec t; |
| 1593 | if (NILP (specified_time)) | 1579 | if (NILP (specified_time)) |
| 1594 | t = current_emacs_time (); | 1580 | t = current_timespec (); |
| 1595 | else | 1581 | else |
| 1596 | { | 1582 | { |
| 1597 | Lisp_Object high, low, usec, psec; | 1583 | Lisp_Object high, low, usec, psec; |
| @@ -1613,12 +1599,12 @@ lisp_seconds_argument (Lisp_Object specified_time) | |||
| 1613 | else | 1599 | else |
| 1614 | { | 1600 | { |
| 1615 | Lisp_Object high, low, usec, psec; | 1601 | Lisp_Object high, low, usec, psec; |
| 1616 | EMACS_TIME t; | 1602 | struct timespec t; |
| 1617 | if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec) | 1603 | if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec) |
| 1618 | && decode_time_components (high, low, make_number (0), | 1604 | && decode_time_components (high, low, make_number (0), |
| 1619 | make_number (0), &t, 0))) | 1605 | make_number (0), &t, 0))) |
| 1620 | error ("Invalid time specification"); | 1606 | error ("Invalid time specification"); |
| 1621 | return EMACS_SECS (t); | 1607 | return t.tv_sec; |
| 1622 | } | 1608 | } |
| 1623 | } | 1609 | } |
| 1624 | 1610 | ||
| @@ -1639,8 +1625,8 @@ or (if you need time as a string) `format-time-string'. */) | |||
| 1639 | double t; | 1625 | double t; |
| 1640 | if (NILP (specified_time)) | 1626 | if (NILP (specified_time)) |
| 1641 | { | 1627 | { |
| 1642 | EMACS_TIME now = current_emacs_time (); | 1628 | struct timespec now = current_timespec (); |
| 1643 | t = EMACS_SECS (now) + EMACS_NSECS (now) / 1e9; | 1629 | t = now.tv_sec + now.tv_nsec / 1e9; |
| 1644 | } | 1630 | } |
| 1645 | else | 1631 | else |
| 1646 | { | 1632 | { |
| @@ -1758,7 +1744,7 @@ For example, to produce full ISO 8601 format, use "%Y-%m-%dT%T%z". | |||
| 1758 | usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */) | 1744 | usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */) |
| 1759 | (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal) | 1745 | (Lisp_Object format_string, Lisp_Object timeval, Lisp_Object universal) |
| 1760 | { | 1746 | { |
| 1761 | EMACS_TIME t = lisp_time_argument (timeval); | 1747 | struct timespec t = lisp_time_argument (timeval); |
| 1762 | struct tm tm; | 1748 | struct tm tm; |
| 1763 | 1749 | ||
| 1764 | CHECK_STRING (format_string); | 1750 | CHECK_STRING (format_string); |
| @@ -1770,20 +1756,20 @@ usage: (format-time-string FORMAT-STRING &optional TIME UNIVERSAL) */) | |||
| 1770 | 1756 | ||
| 1771 | static Lisp_Object | 1757 | static Lisp_Object |
| 1772 | format_time_string (char const *format, ptrdiff_t formatlen, | 1758 | format_time_string (char const *format, ptrdiff_t formatlen, |
| 1773 | EMACS_TIME t, bool ut, struct tm *tmp) | 1759 | struct timespec t, bool ut, struct tm *tmp) |
| 1774 | { | 1760 | { |
| 1775 | char buffer[4000]; | 1761 | char buffer[4000]; |
| 1776 | char *buf = buffer; | 1762 | char *buf = buffer; |
| 1777 | ptrdiff_t size = sizeof buffer; | 1763 | ptrdiff_t size = sizeof buffer; |
| 1778 | size_t len; | 1764 | size_t len; |
| 1779 | Lisp_Object bufstring; | 1765 | Lisp_Object bufstring; |
| 1780 | int ns = EMACS_NSECS (t); | 1766 | int ns = t.tv_nsec; |
| 1781 | struct tm *tm; | 1767 | struct tm *tm; |
| 1782 | USE_SAFE_ALLOCA; | 1768 | USE_SAFE_ALLOCA; |
| 1783 | 1769 | ||
| 1784 | while (1) | 1770 | while (1) |
| 1785 | { | 1771 | { |
| 1786 | time_t *taddr = emacs_secs_addr (&t); | 1772 | time_t *taddr = &t.tv_sec; |
| 1787 | block_input (); | 1773 | block_input (); |
| 1788 | 1774 | ||
| 1789 | synchronize_system_time_locale (); | 1775 | synchronize_system_time_locale (); |
| @@ -2068,17 +2054,17 @@ in this case, `current-time-zone' returns a list containing nil for | |||
| 2068 | the data it can't find. */) | 2054 | the data it can't find. */) |
| 2069 | (Lisp_Object specified_time) | 2055 | (Lisp_Object specified_time) |
| 2070 | { | 2056 | { |
| 2071 | EMACS_TIME value; | 2057 | struct timespec value; |
| 2072 | int offset; | 2058 | int offset; |
| 2073 | struct tm *t; | 2059 | struct tm *t; |
| 2074 | struct tm localtm; | 2060 | struct tm localtm; |
| 2075 | Lisp_Object zone_offset, zone_name; | 2061 | Lisp_Object zone_offset, zone_name; |
| 2076 | 2062 | ||
| 2077 | zone_offset = Qnil; | 2063 | zone_offset = Qnil; |
| 2078 | value = make_emacs_time (lisp_seconds_argument (specified_time), 0); | 2064 | value = make_timespec (lisp_seconds_argument (specified_time), 0); |
| 2079 | zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm); | 2065 | zone_name = format_time_string ("%Z", sizeof "%Z" - 1, value, 0, &localtm); |
| 2080 | block_input (); | 2066 | block_input (); |
| 2081 | t = gmtime (emacs_secs_addr (&value)); | 2067 | t = gmtime (&value.tv_sec); |
| 2082 | if (t) | 2068 | if (t) |
| 2083 | offset = tm_diff (&localtm, t); | 2069 | offset = tm_diff (&localtm, t); |
| 2084 | unblock_input (); | 2070 | unblock_input (); |
| @@ -2330,6 +2316,10 @@ to multibyte for insertion (see `unibyte-char-to-multibyte'). | |||
| 2330 | If the current buffer is unibyte, multibyte strings are converted | 2316 | If the current buffer is unibyte, multibyte strings are converted |
| 2331 | to unibyte for insertion. | 2317 | to unibyte for insertion. |
| 2332 | 2318 | ||
| 2319 | If an overlay begins at the insertion point, the inserted text falls | ||
| 2320 | outside the overlay; if a nonempty overlay ends at the insertion | ||
| 2321 | point, the inserted text falls inside that overlay. | ||
| 2322 | |||
| 2333 | usage: (insert-before-markers &rest ARGS) */) | 2323 | usage: (insert-before-markers &rest ARGS) */) |
| 2334 | (ptrdiff_t nargs, Lisp_Object *args) | 2324 | (ptrdiff_t nargs, Lisp_Object *args) |
| 2335 | { | 2325 | { |
| @@ -2928,7 +2918,7 @@ Both characters must have the same length of multi-byte form. */) | |||
| 2928 | else if (!changed) | 2918 | else if (!changed) |
| 2929 | { | 2919 | { |
| 2930 | changed = -1; | 2920 | changed = -1; |
| 2931 | modify_region_1 (pos, XINT (end), false); | 2921 | modify_text (pos, XINT (end)); |
| 2932 | 2922 | ||
| 2933 | if (! NILP (noundo)) | 2923 | if (! NILP (noundo)) |
| 2934 | { | 2924 | { |
| @@ -3104,7 +3094,7 @@ It returns the number of characters changed. */) | |||
| 3104 | pos = XINT (start); | 3094 | pos = XINT (start); |
| 3105 | pos_byte = CHAR_TO_BYTE (pos); | 3095 | pos_byte = CHAR_TO_BYTE (pos); |
| 3106 | end_pos = XINT (end); | 3096 | end_pos = XINT (end); |
| 3107 | modify_region_1 (pos, end_pos, false); | 3097 | modify_text (pos, end_pos); |
| 3108 | 3098 | ||
| 3109 | cnt = 0; | 3099 | cnt = 0; |
| 3110 | for (; pos < end_pos; ) | 3100 | for (; pos < end_pos; ) |
| @@ -4615,7 +4605,7 @@ Transposing beyond buffer boundaries is an error. */) | |||
| 4615 | 4605 | ||
| 4616 | if (end1 == start2) /* adjacent regions */ | 4606 | if (end1 == start2) /* adjacent regions */ |
| 4617 | { | 4607 | { |
| 4618 | modify_region_1 (start1, end2, false); | 4608 | modify_text (start1, end2); |
| 4619 | record_change (start1, len1 + len2); | 4609 | record_change (start1, len1 + len2); |
| 4620 | 4610 | ||
| 4621 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); | 4611 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
| @@ -4674,8 +4664,8 @@ Transposing beyond buffer boundaries is an error. */) | |||
| 4674 | { | 4664 | { |
| 4675 | USE_SAFE_ALLOCA; | 4665 | USE_SAFE_ALLOCA; |
| 4676 | 4666 | ||
| 4677 | modify_region_1 (start1, end1, false); | 4667 | modify_text (start1, end1); |
| 4678 | modify_region_1 (start2, end2, false); | 4668 | modify_text (start2, end2); |
| 4679 | record_change (start1, len1); | 4669 | record_change (start1, len1); |
| 4680 | record_change (start2, len2); | 4670 | record_change (start2, len2); |
| 4681 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); | 4671 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
| @@ -4708,7 +4698,7 @@ Transposing beyond buffer boundaries is an error. */) | |||
| 4708 | { | 4698 | { |
| 4709 | USE_SAFE_ALLOCA; | 4699 | USE_SAFE_ALLOCA; |
| 4710 | 4700 | ||
| 4711 | modify_region_1 (start1, end2, false); | 4701 | modify_text (start1, end2); |
| 4712 | record_change (start1, (end2 - start1)); | 4702 | record_change (start1, (end2 - start1)); |
| 4713 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); | 4703 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
| 4714 | tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid); | 4704 | tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid); |
| @@ -4741,7 +4731,7 @@ Transposing beyond buffer boundaries is an error. */) | |||
| 4741 | USE_SAFE_ALLOCA; | 4731 | USE_SAFE_ALLOCA; |
| 4742 | 4732 | ||
| 4743 | record_change (start1, (end2 - start1)); | 4733 | record_change (start1, (end2 - start1)); |
| 4744 | modify_region_1 (start1, end2, false); | 4734 | modify_text (start1, end2); |
| 4745 | 4735 | ||
| 4746 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); | 4736 | tmp_interval1 = copy_intervals (cur_intv, start1, len1); |
| 4747 | tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid); | 4737 | tmp_interval_mid = copy_intervals (cur_intv, end1, len_mid); |