diff options
| author | Gregory Heytings | 2022-11-26 16:13:04 +0000 |
|---|---|---|
| committer | Gregory Heytings | 2022-11-26 17:13:53 +0100 |
| commit | 2ea4f9784730930dbcca90ae5e97216e8a1b2333 (patch) | |
| tree | 6cc3fc19b109b0aad380830e18a7c67255b5ed9c /src | |
| parent | 558084c7f736bebcb3cffc2bf4f617158d92357f (diff) | |
| download | emacs-2ea4f9784730930dbcca90ae5e97216e8a1b2333.tar.gz emacs-2ea4f9784730930dbcca90ae5e97216e8a1b2333.zip | |
Further improvements to narrowing locks
* src/editfns.c:
(narrowing_lock_get_bound): Return a pointer to a struct
Lisp_Marker instead of a character position. Suggested by Eli
Zaretskii.
(reset_outermost_narrowings, unwind_reset_outermost_narrowing)
(Fwiden, Fnarrow_to_region): Adapt accordingly.
(narrowing_lock_peek_tag, narrowing_lock_push)
(narrowing_lock_pop, narrowing_locks_save)
(narrowing_locks_restore): Use XCAR/XCDR/XSETCAR instead of
Fcar/Fcdr/Fsetcar.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/src/editfns.c b/src/editfns.c index e6b66209b8b..5bfb0b86d14 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2663,28 +2663,26 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region, | |||
| 2663 | static Lisp_Object narrowing_locks; | 2663 | static Lisp_Object narrowing_locks; |
| 2664 | 2664 | ||
| 2665 | /* Retrieve one of the BEGV/ZV bounds of a narrowing in BUF from the | 2665 | /* Retrieve one of the BEGV/ZV bounds of a narrowing in BUF from the |
| 2666 | narrowing_locks alist. When OUTERMOST is true, the bounds that | 2666 | narrowing_locks alist, as a pointer to a struct Lisp_Marker, or |
| 2667 | were set by the user and that are visible on display are returned. | 2667 | NULL if BUF is not in narrowing_locks. When OUTERMOST is true, the |
| 2668 | Otherwise the innermost locked narrowing bounds are returned. */ | 2668 | bounds that were set by the user and that are visible on display |
| 2669 | static ptrdiff_t | 2669 | are returned. Otherwise the innermost locked narrowing bounds are |
| 2670 | returned. */ | ||
| 2671 | static struct Lisp_Marker * | ||
| 2670 | narrowing_lock_get_bound (Lisp_Object buf, bool begv, bool outermost) | 2672 | narrowing_lock_get_bound (Lisp_Object buf, bool begv, bool outermost) |
| 2671 | { | 2673 | { |
| 2672 | if (NILP (Fbuffer_live_p (buf))) | ||
| 2673 | return 0; | ||
| 2674 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); | 2674 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); |
| 2675 | if (NILP (buffer_locks)) | 2675 | if (NILP (buffer_locks)) |
| 2676 | return 0; | 2676 | return NULL; |
| 2677 | buffer_locks = Fcar (Fcdr (buffer_locks)); | 2677 | buffer_locks = XCAR (XCDR (buffer_locks)); |
| 2678 | Lisp_Object bounds | 2678 | Lisp_Object bounds |
| 2679 | = outermost | 2679 | = outermost |
| 2680 | ? Fcdr (assq_no_quit (Qoutermost_narrowing, buffer_locks)) | 2680 | ? XCDR (assq_no_quit (Qoutermost_narrowing, buffer_locks)) |
| 2681 | : Fcdr (Fcar (buffer_locks)); | 2681 | : XCDR (XCAR (buffer_locks)); |
| 2682 | eassert (! NILP (bounds)); | 2682 | eassert (! NILP (bounds)); |
| 2683 | Lisp_Object marker = begv ? Fcar (bounds) : Fcar (Fcdr (bounds)); | 2683 | Lisp_Object marker = begv ? XCAR (bounds) : XCAR (XCDR (bounds)); |
| 2684 | eassert (MARKERP (marker)); | 2684 | eassert (EQ (Fmarker_buffer (marker), buf)); |
| 2685 | Lisp_Object pos = Fmarker_position (marker); | 2685 | return XMARKER (marker); |
| 2686 | eassert (! NILP (pos)); | ||
| 2687 | return XFIXNUM (pos); | ||
| 2688 | } | 2686 | } |
| 2689 | 2687 | ||
| 2690 | /* Retrieve the tag of the innermost narrowing in BUF. */ | 2688 | /* Retrieve the tag of the innermost narrowing in BUF. */ |
| @@ -2696,7 +2694,7 @@ narrowing_lock_peek_tag (Lisp_Object buf) | |||
| 2696 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); | 2694 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); |
| 2697 | if (NILP (buffer_locks)) | 2695 | if (NILP (buffer_locks)) |
| 2698 | return Qnil; | 2696 | return Qnil; |
| 2699 | Lisp_Object tag = Fcar (Fcar (Fcar (Fcdr (buffer_locks)))); | 2697 | Lisp_Object tag = XCAR (XCAR (XCAR (XCDR (buffer_locks)))); |
| 2700 | eassert (! NILP (tag)); | 2698 | eassert (! NILP (tag)); |
| 2701 | return tag; | 2699 | return tag; |
| 2702 | } | 2700 | } |
| @@ -2710,8 +2708,8 @@ narrowing_lock_push (Lisp_Object buf, Lisp_Object lock) | |||
| 2710 | narrowing_locks = nconc2 (list1 (list2 (buf, list1 (lock))), | 2708 | narrowing_locks = nconc2 (list1 (list2 (buf, list1 (lock))), |
| 2711 | narrowing_locks); | 2709 | narrowing_locks); |
| 2712 | else | 2710 | else |
| 2713 | Fsetcdr (buffer_locks, list1 (nconc2 (list1 (lock), | 2711 | XSETCDR (buffer_locks, list1 (nconc2 (list1 (lock), |
| 2714 | Fcar (Fcdr (buffer_locks))))); | 2712 | XCAR (XCDR (buffer_locks))))); |
| 2715 | } | 2713 | } |
| 2716 | 2714 | ||
| 2717 | /* Remove the innermost lock in BUF from the narrowing_lock alist. */ | 2715 | /* Remove the innermost lock in BUF from the narrowing_lock alist. */ |
| @@ -2724,38 +2722,40 @@ narrowing_lock_pop (Lisp_Object buf) | |||
| 2724 | narrowing_locks = Fdelq (Fassoc (buf, narrowing_locks, Qnil), | 2722 | narrowing_locks = Fdelq (Fassoc (buf, narrowing_locks, Qnil), |
| 2725 | narrowing_locks); | 2723 | narrowing_locks); |
| 2726 | else | 2724 | else |
| 2727 | Fsetcdr (buffer_locks, list1 (Fcdr (Fcar (Fcdr (buffer_locks))))); | 2725 | XSETCDR (buffer_locks, list1 (XCDR (XCAR (XCDR (buffer_locks))))); |
| 2728 | } | 2726 | } |
| 2729 | 2727 | ||
| 2730 | static void | 2728 | static void |
| 2731 | unwind_reset_outermost_narrowing (Lisp_Object buf) | 2729 | unwind_reset_outermost_narrowing (Lisp_Object buf) |
| 2732 | { | 2730 | { |
| 2733 | ptrdiff_t begv, zv; | 2731 | struct Lisp_Marker *begv = narrowing_lock_get_bound (buf, true, false); |
| 2734 | begv = narrowing_lock_get_bound (buf, true, false); | 2732 | struct Lisp_Marker *zv = narrowing_lock_get_bound (buf, false, false); |
| 2735 | zv = narrowing_lock_get_bound (buf, false, false); | 2733 | if (begv != NULL && zv != NULL) |
| 2736 | if (begv && zv) | ||
| 2737 | { | 2734 | { |
| 2738 | SET_BUF_BEGV (XBUFFER (buf), begv); | 2735 | SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos); |
| 2739 | SET_BUF_ZV (XBUFFER (buf), zv); | 2736 | SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos); |
| 2740 | } | 2737 | } |
| 2741 | } | 2738 | } |
| 2742 | 2739 | ||
| 2743 | /* When redisplay is called in a function executed while a locked | 2740 | /* Restore the narrowing bounds that were set by the user, and restore |
| 2744 | narrowing is in effect, restore the narrowing bounds that were set | 2741 | the bounds of the locked narrowing upon return. |
| 2745 | by the user, and restore the bounds of the locked narrowing when | 2742 | In particular, this function is called when redisplay starts, so |
| 2746 | returning from redisplay. */ | 2743 | that if a Lisp function executed during redisplay calls (redisplay) |
| 2744 | while a locked narrowing is in effect, the locked narrowing will | ||
| 2745 | not be visible on display. */ | ||
| 2747 | void | 2746 | void |
| 2748 | reset_outermost_narrowings (void) | 2747 | reset_outermost_narrowings (void) |
| 2749 | { | 2748 | { |
| 2750 | Lisp_Object val, buf; | 2749 | Lisp_Object val, buf; |
| 2751 | for (val = narrowing_locks; CONSP (val); val = XCDR (val)) | 2750 | for (val = narrowing_locks; CONSP (val); val = XCDR (val)) |
| 2752 | { | 2751 | { |
| 2753 | buf = Fcar (Fcar (val)); | 2752 | buf = XCAR (XCAR (val)); |
| 2754 | eassert (BUFFERP (buf)); | 2753 | eassert (BUFFERP (buf)); |
| 2755 | ptrdiff_t begv = narrowing_lock_get_bound (buf, true, true); | 2754 | struct Lisp_Marker *begv = narrowing_lock_get_bound (buf, true, true); |
| 2756 | ptrdiff_t zv = narrowing_lock_get_bound (buf, false, true); | 2755 | struct Lisp_Marker *zv = narrowing_lock_get_bound (buf, false, true); |
| 2757 | SET_BUF_BEGV (XBUFFER (buf), begv); | 2756 | eassert (begv != NULL && zv != NULL); |
| 2758 | SET_BUF_ZV (XBUFFER (buf), zv); | 2757 | SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos); |
| 2758 | SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos); | ||
| 2759 | record_unwind_protect (unwind_reset_outermost_narrowing, buf); | 2759 | record_unwind_protect (unwind_reset_outermost_narrowing, buf); |
| 2760 | } | 2760 | } |
| 2761 | } | 2761 | } |
| @@ -2769,7 +2769,7 @@ narrowing_locks_save (void) | |||
| 2769 | Lisp_Object locks = assq_no_quit (buf, narrowing_locks); | 2769 | Lisp_Object locks = assq_no_quit (buf, narrowing_locks); |
| 2770 | if (NILP (locks)) | 2770 | if (NILP (locks)) |
| 2771 | return Qnil; | 2771 | return Qnil; |
| 2772 | locks = Fcar (Fcdr (locks)); | 2772 | locks = XCAR (XCDR (locks)); |
| 2773 | return Fcons (buf, Fcopy_sequence (locks)); | 2773 | return Fcons (buf, Fcopy_sequence (locks)); |
| 2774 | } | 2774 | } |
| 2775 | 2775 | ||
| @@ -2778,9 +2778,9 @@ narrowing_locks_restore (Lisp_Object buf_and_saved_locks) | |||
| 2778 | { | 2778 | { |
| 2779 | if (NILP (buf_and_saved_locks)) | 2779 | if (NILP (buf_and_saved_locks)) |
| 2780 | return; | 2780 | return; |
| 2781 | Lisp_Object buf = Fcar (buf_and_saved_locks); | 2781 | Lisp_Object buf = XCAR (buf_and_saved_locks); |
| 2782 | eassert (BUFFERP (buf)); | 2782 | eassert (BUFFERP (buf)); |
| 2783 | Lisp_Object saved_locks = Fcdr (buf_and_saved_locks); | 2783 | Lisp_Object saved_locks = XCDR (buf_and_saved_locks); |
| 2784 | eassert (! NILP (saved_locks)); | 2784 | eassert (! NILP (saved_locks)); |
| 2785 | Lisp_Object current_locks = assq_no_quit (buf, narrowing_locks); | 2785 | Lisp_Object current_locks = assq_no_quit (buf, narrowing_locks); |
| 2786 | if (! NILP (current_locks)) | 2786 | if (! NILP (current_locks)) |
| @@ -2830,12 +2830,13 @@ called is restored. */) | |||
| 2830 | } | 2830 | } |
| 2831 | else | 2831 | else |
| 2832 | { | 2832 | { |
| 2833 | ptrdiff_t begv = narrowing_lock_get_bound (buf, true, false); | 2833 | struct Lisp_Marker *begv = narrowing_lock_get_bound (buf, true, false); |
| 2834 | ptrdiff_t zv = narrowing_lock_get_bound (buf, false, false); | 2834 | struct Lisp_Marker *zv = narrowing_lock_get_bound (buf, false, false); |
| 2835 | if (begv != BEGV || zv != ZV) | 2835 | eassert (begv != NULL && zv != NULL); |
| 2836 | if (begv->charpos != BEGV || zv->charpos != ZV) | ||
| 2836 | current_buffer->clip_changed = 1; | 2837 | current_buffer->clip_changed = 1; |
| 2837 | SET_BUF_BEGV (current_buffer, begv); | 2838 | SET_BUF_BEGV_BOTH (current_buffer, begv->charpos, begv->bytepos); |
| 2838 | SET_BUF_ZV (current_buffer, zv); | 2839 | SET_BUF_ZV_BOTH (current_buffer, zv->charpos, zv->bytepos); |
| 2839 | /* If the only remaining bounds in narrowing_locks for | 2840 | /* If the only remaining bounds in narrowing_locks for |
| 2840 | current_buffer are the bounds that were set by the user, no | 2841 | current_buffer are the bounds that were set by the user, no |
| 2841 | locked narrowing is in effect in current_buffer anymore: | 2842 | locked narrowing is in effect in current_buffer anymore: |
| @@ -2879,14 +2880,15 @@ limit of the locked restriction is used instead of the argument. */) | |||
| 2879 | Lisp_Object buf = Fcurrent_buffer (); | 2880 | Lisp_Object buf = Fcurrent_buffer (); |
| 2880 | if (! NILP (narrowing_lock_peek_tag (buf))) | 2881 | if (! NILP (narrowing_lock_peek_tag (buf))) |
| 2881 | { | 2882 | { |
| 2882 | ptrdiff_t begv = narrowing_lock_get_bound (buf, true, false); | 2883 | struct Lisp_Marker *begv = narrowing_lock_get_bound (buf, true, false); |
| 2883 | ptrdiff_t zv = narrowing_lock_get_bound (buf, false, false); | 2884 | struct Lisp_Marker *zv = narrowing_lock_get_bound (buf, false, false); |
| 2885 | eassert (begv != NULL && zv != NULL); | ||
| 2884 | /* Limit the start and end positions to those of the locked | 2886 | /* Limit the start and end positions to those of the locked |
| 2885 | narrowing. */ | 2887 | narrowing. */ |
| 2886 | if (s < begv) s = begv; | 2888 | if (s < begv->charpos) s = begv->charpos; |
| 2887 | if (s > zv) s = zv; | 2889 | if (s > zv->charpos) s = zv->charpos; |
| 2888 | if (e < begv) e = begv; | 2890 | if (e < begv->charpos) e = begv->charpos; |
| 2889 | if (e > zv) e = zv; | 2891 | if (e > zv->charpos) e = zv->charpos; |
| 2890 | } | 2892 | } |
| 2891 | 2893 | ||
| 2892 | /* Record the accessible range of the buffer when narrow-to-region | 2894 | /* Record the accessible range of the buffer when narrow-to-region |