diff options
| author | Gregory Heytings | 2022-11-27 00:24:40 +0000 |
|---|---|---|
| committer | Gregory Heytings | 2022-11-27 01:27:05 +0100 |
| commit | 1d1a83ba56e56c2eda5a22b3ba2d8d9578271eee (patch) | |
| tree | 3310fd986d4ce786215e98ead99a2310be05f5f3 /src | |
| parent | 321d4e61551a0f6dfb1abfc0b54e6177735bde58 (diff) | |
| download | emacs-1d1a83ba56e56c2eda5a22b3ba2d8d9578271eee.tar.gz emacs-1d1a83ba56e56c2eda5a22b3ba2d8d9578271eee.zip | |
Improve handling of killed buffers in locked narrowings
* src/editfns.c (narrowing_locks_add, narrowing_locks_remove):
New functions, factored out.
(narrowing_lock_push, narrowing_lock_pop)
(narrowing_locks_restore): Use the new functions.
(narrowing_lock_get_bound): Return NULL for killed buffers.
(reset_outermost_narrowings, unwind_reset_outermost_narrowing):
Remove killed buffers from the 'narrowing_locks' alist.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/src/editfns.c b/src/editfns.c index e99a007a70c..ec1eec88779 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -2662,15 +2662,33 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region, | |||
| 2662 | narrowing-lock, narrowing-unlock and save-restriction. */ | 2662 | narrowing-lock, narrowing-unlock and save-restriction. */ |
| 2663 | static Lisp_Object narrowing_locks; | 2663 | static Lisp_Object narrowing_locks; |
| 2664 | 2664 | ||
| 2665 | /* Add BUF with its LOCKS in the narrowing_locks alist. */ | ||
| 2666 | static void | ||
| 2667 | narrowing_locks_add (Lisp_Object buf, Lisp_Object locks) | ||
| 2668 | { | ||
| 2669 | narrowing_locks = nconc2 (list1 (list2 (buf, locks)), narrowing_locks); | ||
| 2670 | } | ||
| 2671 | |||
| 2672 | /* Remove BUF from the narrowing_locks alist. Do nothing if BUF is | ||
| 2673 | not present in narrowing_locks. */ | ||
| 2674 | static void | ||
| 2675 | narrowing_locks_remove (Lisp_Object buf) | ||
| 2676 | { | ||
| 2677 | narrowing_locks = Fdelq (Fassoc (buf, narrowing_locks, Qnil), | ||
| 2678 | narrowing_locks); | ||
| 2679 | } | ||
| 2680 | |||
| 2665 | /* Retrieve one of the BEGV/ZV bounds of a narrowing in BUF from the | 2681 | /* Retrieve one of the BEGV/ZV bounds of a narrowing in BUF from the |
| 2666 | narrowing_locks alist, as a pointer to a struct Lisp_Marker, or | 2682 | narrowing_locks alist, as a pointer to a struct Lisp_Marker, or |
| 2667 | NULL if BUF is not in narrowing_locks. When OUTERMOST is true, the | 2683 | NULL if BUF is not in narrowing_locks or is a killed buffer. When |
| 2668 | bounds that were set by the user and that are visible on display | 2684 | OUTERMOST is true, the bounds that were set by the user and that |
| 2669 | are returned. Otherwise the innermost locked narrowing bounds are | 2685 | are visible on display are returned. Otherwise the innermost |
| 2670 | returned. */ | 2686 | locked narrowing bounds are returned. */ |
| 2671 | static struct Lisp_Marker * | 2687 | static struct Lisp_Marker * |
| 2672 | narrowing_lock_get_bound (Lisp_Object buf, bool begv, bool outermost) | 2688 | narrowing_lock_get_bound (Lisp_Object buf, bool begv, bool outermost) |
| 2673 | { | 2689 | { |
| 2690 | if (NILP (Fbuffer_live_p (buf))) | ||
| 2691 | return NULL; | ||
| 2674 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); | 2692 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); |
| 2675 | if (NILP (buffer_locks)) | 2693 | if (NILP (buffer_locks)) |
| 2676 | return NULL; | 2694 | return NULL; |
| @@ -2699,21 +2717,20 @@ narrowing_lock_peek_tag (Lisp_Object buf) | |||
| 2699 | return tag; | 2717 | return tag; |
| 2700 | } | 2718 | } |
| 2701 | 2719 | ||
| 2702 | /* Add a LOCK in BUF in the narrowing_locks alist. */ | 2720 | /* Add a LOCK for BUF in the narrowing_locks alist. */ |
| 2703 | static void | 2721 | static void |
| 2704 | narrowing_lock_push (Lisp_Object buf, Lisp_Object lock) | 2722 | narrowing_lock_push (Lisp_Object buf, Lisp_Object lock) |
| 2705 | { | 2723 | { |
| 2706 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); | 2724 | Lisp_Object buffer_locks = assq_no_quit (buf, narrowing_locks); |
| 2707 | if (NILP (buffer_locks)) | 2725 | if (NILP (buffer_locks)) |
| 2708 | narrowing_locks = nconc2 (list1 (list2 (buf, list1 (lock))), | 2726 | narrowing_locks_add (buf, list1 (lock)); |
| 2709 | narrowing_locks); | ||
| 2710 | else | 2727 | else |
| 2711 | XSETCDR (buffer_locks, list1 (nconc2 (list1 (lock), | 2728 | XSETCDR (buffer_locks, list1 (nconc2 (list1 (lock), |
| 2712 | XCAR (XCDR (buffer_locks))))); | 2729 | XCAR (XCDR (buffer_locks))))); |
| 2713 | } | 2730 | } |
| 2714 | 2731 | ||
| 2715 | /* Remove the innermost lock in BUF from the narrowing_lock alist. | 2732 | /* Remove the innermost lock in BUF from the narrowing_locks alist. |
| 2716 | Do nothing if BUF is not in narrowing_lock. */ | 2733 | Do nothing if BUF is not present in narrowing_locks. */ |
| 2717 | static void | 2734 | static void |
| 2718 | narrowing_lock_pop (Lisp_Object buf) | 2735 | narrowing_lock_pop (Lisp_Object buf) |
| 2719 | { | 2736 | { |
| @@ -2721,8 +2738,7 @@ narrowing_lock_pop (Lisp_Object buf) | |||
| 2721 | if (NILP (buffer_locks)) | 2738 | if (NILP (buffer_locks)) |
| 2722 | return; | 2739 | return; |
| 2723 | if (EQ (narrowing_lock_peek_tag (buf), Qoutermost_narrowing)) | 2740 | if (EQ (narrowing_lock_peek_tag (buf), Qoutermost_narrowing)) |
| 2724 | narrowing_locks = Fdelq (Fassoc (buf, narrowing_locks, Qnil), | 2741 | narrowing_locks_remove (buf); |
| 2725 | narrowing_locks); | ||
| 2726 | else | 2742 | else |
| 2727 | XSETCDR (buffer_locks, list1 (XCDR (XCAR (XCDR (buffer_locks))))); | 2743 | XSETCDR (buffer_locks, list1 (XCDR (XCAR (XCDR (buffer_locks))))); |
| 2728 | } | 2744 | } |
| @@ -2737,6 +2753,8 @@ unwind_reset_outermost_narrowing (Lisp_Object buf) | |||
| 2737 | SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos); | 2753 | SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos); |
| 2738 | SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos); | 2754 | SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos); |
| 2739 | } | 2755 | } |
| 2756 | else | ||
| 2757 | narrowing_locks_remove (buf); | ||
| 2740 | } | 2758 | } |
| 2741 | 2759 | ||
| 2742 | /* Restore the narrowing bounds that were set by the user, and restore | 2760 | /* Restore the narrowing bounds that were set by the user, and restore |
| @@ -2755,10 +2773,14 @@ reset_outermost_narrowings (void) | |||
| 2755 | eassert (BUFFERP (buf)); | 2773 | eassert (BUFFERP (buf)); |
| 2756 | struct Lisp_Marker *begv = narrowing_lock_get_bound (buf, true, true); | 2774 | struct Lisp_Marker *begv = narrowing_lock_get_bound (buf, true, true); |
| 2757 | struct Lisp_Marker *zv = narrowing_lock_get_bound (buf, false, true); | 2775 | struct Lisp_Marker *zv = narrowing_lock_get_bound (buf, false, true); |
| 2758 | eassert (begv != NULL && zv != NULL); | 2776 | if (begv != NULL && zv != NULL) |
| 2759 | SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos); | 2777 | { |
| 2760 | SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos); | 2778 | SET_BUF_BEGV_BOTH (XBUFFER (buf), begv->charpos, begv->bytepos); |
| 2761 | record_unwind_protect (unwind_reset_outermost_narrowing, buf); | 2779 | SET_BUF_ZV_BOTH (XBUFFER (buf), zv->charpos, zv->bytepos); |
| 2780 | record_unwind_protect (unwind_reset_outermost_narrowing, buf); | ||
| 2781 | } | ||
| 2782 | else | ||
| 2783 | narrowing_locks_remove (buf); | ||
| 2762 | } | 2784 | } |
| 2763 | } | 2785 | } |
| 2764 | 2786 | ||
| @@ -2790,10 +2812,8 @@ narrowing_locks_restore (Lisp_Object buf_and_saved_locks) | |||
| 2790 | eassert (! NILP (saved_locks)); | 2812 | eassert (! NILP (saved_locks)); |
| 2791 | Lisp_Object current_locks = assq_no_quit (buf, narrowing_locks); | 2813 | Lisp_Object current_locks = assq_no_quit (buf, narrowing_locks); |
| 2792 | if (! NILP (current_locks)) | 2814 | if (! NILP (current_locks)) |
| 2793 | narrowing_locks = Fdelq (Fassoc (buf, narrowing_locks, Qnil), | 2815 | narrowing_locks_remove (buf); |
| 2794 | narrowing_locks); | 2816 | narrowing_locks_add (buf, saved_locks); |
| 2795 | narrowing_locks = nconc2 (list1 (list2 (buf, saved_locks)), | ||
| 2796 | narrowing_locks); | ||
| 2797 | } | 2817 | } |
| 2798 | 2818 | ||
| 2799 | static void | 2819 | static void |