aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGregory Heytings2022-07-28 20:37:49 +0000
committerGregory Heytings2022-07-28 22:40:42 +0200
commitd3c4833d1350e26a2ae35e00eaf2d6bef1724679 (patch)
tree3d062ac14705af5ae72a0647f334674b69fadb97 /src
parent2bab0f2db6fff3a99d3bc498d6139ee42aab96ea (diff)
downloademacs-d3c4833d1350e26a2ae35e00eaf2d6bef1724679.tar.gz
emacs-d3c4833d1350e26a2ae35e00eaf2d6bef1724679.zip
Add an optional 'lock' parameter to 'narrow-to-region'
* src/editfns.c (Fnarrow_to_region): Add the parameter to the function, and handle it. Update docstring. (unwind_locked_begv, unwind_locked_zv): New functions. (Fwiden): Do nothing when restrictions are locked. Update docstring. (syms_of_editfns): Replace the 'inhibit-widen' symbol and variable with a 'restrictions-locked' symbol and variable. Update docstring. * src/xdisp.c (handle_fontified_prop): Use Fnarrow_to_region with the new parameter. (unwind_narrowed_zv): Remove function. * src/process.c (Finternal_default_process_filter): Add a third argument to Fnarrow_to_region. * src/lread.c (readevalloop): Add a third argument to Fnarrow_to_region. * src/bytecode.c (exec_byte_code): Add a third argument to Fnarrow_to_region. * etc/NEWS (like): Mention the new parameter of 'narrow-to-region'. * doc/lispref/positions.texi (Narrowing): Document it.
Diffstat (limited to 'src')
-rw-r--r--src/bytecode.c2
-rw-r--r--src/editfns.c81
-rw-r--r--src/lread.c2
-rw-r--r--src/process.c2
-rw-r--r--src/xdisp.c15
5 files changed, 67 insertions, 35 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index d75767bb0c5..241cbaf04f6 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1481,7 +1481,7 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
1481 CASE (Bnarrow_to_region): 1481 CASE (Bnarrow_to_region):
1482 { 1482 {
1483 Lisp_Object v1 = POP; 1483 Lisp_Object v1 = POP;
1484 TOP = Fnarrow_to_region (TOP, v1); 1484 TOP = Fnarrow_to_region (TOP, v1, Qnil);
1485 NEXT; 1485 NEXT;
1486 } 1486 }
1487 1487
diff --git a/src/editfns.c b/src/editfns.c
index 6dec2d468c0..40e65dda0c9 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -2658,10 +2658,14 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
2658 2658
2659DEFUN ("widen", Fwiden, Swiden, 0, 0, "", 2659DEFUN ("widen", Fwiden, Swiden, 0, 0, "",
2660 doc: /* Remove restrictions (narrowing) from current buffer. 2660 doc: /* Remove restrictions (narrowing) from current buffer.
2661This allows the buffer's full text to be seen and edited. */) 2661This allows the buffer's full text to be seen and edited.
2662
2663When called from Lisp inside a body form in which `narrow-to-region'
2664was called with an optional argument LOCK non-nil, this does not
2665produce any effect. */)
2662 (void) 2666 (void)
2663{ 2667{
2664 if (!NILP (Vinhibit_widen)) 2668 if (! NILP (Vrestrictions_locked))
2665 return Qnil; 2669 return Qnil;
2666 if (BEG != BEGV || Z != ZV) 2670 if (BEG != BEGV || Z != ZV)
2667 current_buffer->clip_changed = 1; 2671 current_buffer->clip_changed = 1;
@@ -2673,7 +2677,19 @@ This allows the buffer's full text to be seen and edited. */)
2673 return Qnil; 2677 return Qnil;
2674} 2678}
2675 2679
2676DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r", 2680static void
2681unwind_locked_begv (Lisp_Object point_min)
2682{
2683 SET_BUF_BEGV (current_buffer, XFIXNUM (point_min));
2684}
2685
2686static void
2687unwind_locked_zv (Lisp_Object point_max)
2688{
2689 SET_BUF_ZV (current_buffer, XFIXNUM (point_max));
2690}
2691
2692DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 3, "r",
2677 doc: /* Restrict editing in this buffer to the current region. 2693 doc: /* Restrict editing in this buffer to the current region.
2678The rest of the text becomes temporarily invisible and untouchable 2694The rest of the text becomes temporarily invisible and untouchable
2679but is not deleted; if you save the buffer in a file, the invisible 2695but is not deleted; if you save the buffer in a file, the invisible
@@ -2682,8 +2698,13 @@ See also `save-restriction'.
2682 2698
2683When calling from Lisp, pass two arguments START and END: 2699When calling from Lisp, pass two arguments START and END:
2684positions (integers or markers) bounding the text that should 2700positions (integers or markers) bounding the text that should
2685remain visible. */) 2701remain visible.
2686 (Lisp_Object start, Lisp_Object end) 2702
2703When called from Lisp with the optional argument LOCK non-nil,
2704calls to `widen', or to `narrow-to-region' with an optional
2705argument LOCK nil, do not produce any effect until the end of
2706the current body form. */)
2707 (Lisp_Object start, Lisp_Object end, Lisp_Object lock)
2687{ 2708{
2688 EMACS_INT s = fix_position (start), e = fix_position (end); 2709 EMACS_INT s = fix_position (start), e = fix_position (end);
2689 2710
@@ -2692,14 +2713,37 @@ remain visible. */)
2692 EMACS_INT tem = s; s = e; e = tem; 2713 EMACS_INT tem = s; s = e; e = tem;
2693 } 2714 }
2694 2715
2695 if (!(BEG <= s && s <= e && e <= Z)) 2716 if (! NILP (lock))
2696 args_out_of_range (start, end); 2717 {
2718 if (!(BEGV <= s && s <= e && e <= ZV))
2719 args_out_of_range (start, end);
2697 2720
2698 if (BEGV != s || ZV != e) 2721 if (BEGV != s || ZV != e)
2699 current_buffer->clip_changed = 1; 2722 current_buffer->clip_changed = 1;
2723
2724 record_unwind_protect (unwind_locked_begv, Fpoint_min ());
2725 record_unwind_protect (unwind_locked_zv, Fpoint_max ());
2726
2727 SET_BUF_BEGV (current_buffer, s);
2728 SET_BUF_ZV (current_buffer, e);
2729
2730 specbind (Qrestrictions_locked, Qt);
2731 }
2732 else
2733 {
2734 if (! NILP (Vrestrictions_locked))
2735 return Qnil;
2736
2737 if (!(BEG <= s && s <= e && e <= Z))
2738 args_out_of_range (start, end);
2739
2740 if (BEGV != s || ZV != e)
2741 current_buffer->clip_changed = 1;
2742
2743 SET_BUF_BEGV (current_buffer, s);
2744 SET_BUF_ZV (current_buffer, e);
2745 }
2700 2746
2701 SET_BUF_BEGV (current_buffer, s);
2702 SET_BUF_ZV (current_buffer, e);
2703 if (PT < s) 2747 if (PT < s)
2704 SET_PT (s); 2748 SET_PT (s);
2705 if (e < PT) 2749 if (e < PT)
@@ -4459,7 +4503,6 @@ syms_of_editfns (void)
4459 DEFSYM (Qbuffer_access_fontify_functions, "buffer-access-fontify-functions"); 4503 DEFSYM (Qbuffer_access_fontify_functions, "buffer-access-fontify-functions");
4460 DEFSYM (Qwall, "wall"); 4504 DEFSYM (Qwall, "wall");
4461 DEFSYM (Qpropertize, "propertize"); 4505 DEFSYM (Qpropertize, "propertize");
4462 DEFSYM (Qinhibit_widen, "inhibit-widen");
4463 4506
4464 DEFVAR_LISP ("inhibit-field-text-motion", Vinhibit_field_text_motion, 4507 DEFVAR_LISP ("inhibit-field-text-motion", Vinhibit_field_text_motion,
4465 doc: /* Non-nil means text motion commands don't notice fields. */); 4508 doc: /* Non-nil means text motion commands don't notice fields. */);
@@ -4520,14 +4563,14 @@ This variable is experimental; email 32252@debbugs.gnu.org if you need
4520it to be non-nil. */); 4563it to be non-nil. */);
4521 binary_as_unsigned = false; 4564 binary_as_unsigned = false;
4522 4565
4523 DEFVAR_LISP ("inhibit-widen", Vinhibit_widen, 4566 DEFSYM (Qrestrictions_locked, "restrictions-locked");
4524 doc: /* Non-nil inhibits the `widen' function. 4567 DEFVAR_LISP ("restrictions-locked", Vrestrictions_locked,
4568 doc: /* If non-nil, restrictions are currently locked.
4525 4569
4526Do NOT set this globally to a non-nil value, as doing that will 4570This happens when `narrow-to-region', which see, is called from Lisp
4527disable the `widen' function everywhere, including the \\[widen\] 4571with an optional argument LOCK non-nil. */);
4528command. This variable is intended to be let-bound around code 4572 Vrestrictions_locked = Qnil;
4529that needs to disable `widen' temporarily. */); 4573 Funintern (Qrestrictions_locked, Qnil);
4530 Vinhibit_widen = Qnil;
4531 4574
4532 defsubr (&Spropertize); 4575 defsubr (&Spropertize);
4533 defsubr (&Schar_equal); 4576 defsubr (&Schar_equal);
diff --git a/src/lread.c b/src/lread.c
index 0b46a2e4ee5..0720774db2b 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -2261,7 +2261,7 @@ readevalloop (Lisp_Object readcharfun,
2261 /* Set point and ZV around stuff to be read. */ 2261 /* Set point and ZV around stuff to be read. */
2262 Fgoto_char (start); 2262 Fgoto_char (start);
2263 if (!NILP (end)) 2263 if (!NILP (end))
2264 Fnarrow_to_region (make_fixnum (BEGV), end); 2264 Fnarrow_to_region (make_fixnum (BEGV), end, Qnil);
2265 2265
2266 /* Just for cleanliness, convert END to a marker 2266 /* Just for cleanliness, convert END to a marker
2267 if it is an integer. */ 2267 if it is an integer. */
diff --git a/src/process.c b/src/process.c
index d6d51b26e11..444265a1bcb 100644
--- a/src/process.c
+++ b/src/process.c
@@ -6329,7 +6329,7 @@ Otherwise it discards the output. */)
6329 6329
6330 /* If the restriction isn't what it should be, set it. */ 6330 /* If the restriction isn't what it should be, set it. */
6331 if (old_begv != BEGV || old_zv != ZV) 6331 if (old_begv != BEGV || old_zv != ZV)
6332 Fnarrow_to_region (make_fixnum (old_begv), make_fixnum (old_zv)); 6332 Fnarrow_to_region (make_fixnum (old_begv), make_fixnum (old_zv), Qnil);
6333 6333
6334 bset_read_only (current_buffer, old_read_only); 6334 bset_read_only (current_buffer, old_read_only);
6335 SET_PT_BOTH (opoint, opoint_byte); 6335 SET_PT_BOTH (opoint, opoint_byte);
diff --git a/src/xdisp.c b/src/xdisp.c
index 6237d5a0222..d91a7ac65bb 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3547,12 +3547,6 @@ unwind_narrowed_begv (Lisp_Object point_min)
3547 SET_BUF_BEGV (current_buffer, XFIXNUM (point_min)); 3547 SET_BUF_BEGV (current_buffer, XFIXNUM (point_min));
3548} 3548}
3549 3549
3550static void
3551unwind_narrowed_zv (Lisp_Object point_max)
3552{
3553 SET_BUF_ZV (current_buffer, XFIXNUM (point_max));
3554}
3555
3556/* Set DST to EXPR. When IT indicates that BEGV should temporarily be 3550/* Set DST to EXPR. When IT indicates that BEGV should temporarily be
3557 updated to optimize display, evaluate EXPR with BEGV set to BV. */ 3551 updated to optimize display, evaluate EXPR with BEGV set to BV. */
3558 3552
@@ -4414,13 +4408,8 @@ handle_fontified_prop (struct it *it)
4414 eassert (it->end_charpos == ZV); 4408 eassert (it->end_charpos == ZV);
4415 4409
4416 if (it->narrowed_begv) 4410 if (it->narrowed_begv)
4417 { 4411 Fnarrow_to_region (make_fixnum (it->narrowed_begv),
4418 record_unwind_protect (unwind_narrowed_begv, Fpoint_min ()); 4412 make_fixnum (it->narrowed_zv), Qt);
4419 record_unwind_protect (unwind_narrowed_zv, Fpoint_max ());
4420 SET_BUF_BEGV (current_buffer, it->narrowed_begv);
4421 SET_BUF_ZV (current_buffer, it->narrowed_zv);
4422 specbind (Qinhibit_widen, Qt);
4423 }
4424 4413
4425 /* Don't allow Lisp that runs from 'fontification-functions' 4414 /* Don't allow Lisp that runs from 'fontification-functions'
4426 clear our face and image caches behind our back. */ 4415 clear our face and image caches behind our back. */