aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/buffer.c16
-rw-r--r--src/buffer.h36
-rw-r--r--src/bytecode.c7
-rw-r--r--src/editfns.c69
-rw-r--r--src/fileio.c2
-rw-r--r--src/lread.c2
-rw-r--r--src/process.c4
7 files changed, 106 insertions, 30 deletions
diff --git a/src/buffer.c b/src/buffer.c
index f06d7e08e49..2d75dba6e95 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -571,6 +571,9 @@ even if it is dead. The return value is never nil. */)
571 bset_begv_marker (b, Qnil); 571 bset_begv_marker (b, Qnil);
572 bset_zv_marker (b, Qnil); 572 bset_zv_marker (b, Qnil);
573 573
574 bset_begh_marker (b, Qnil);
575 bset_zh_marker (b, Qnil);
576
574 name = Fcopy_sequence (buffer_or_name); 577 name = Fcopy_sequence (buffer_or_name);
575 set_string_intervals (name, NULL); 578 set_string_intervals (name, NULL);
576 bset_name (b, name); 579 bset_name (b, name);
@@ -835,6 +838,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */)
835 bset_pt_marker (b, build_marker (b, b->pt, b->pt_byte)); 838 bset_pt_marker (b, build_marker (b, b->pt, b->pt_byte));
836 bset_begv_marker (b, build_marker (b, b->begv, b->begv_byte)); 839 bset_begv_marker (b, build_marker (b, b->begv, b->begv_byte));
837 bset_zv_marker (b, build_marker (b, b->zv, b->zv_byte)); 840 bset_zv_marker (b, build_marker (b, b->zv, b->zv_byte));
841
838 XMARKER (BVAR (b, zv_marker))->insertion_type = 1; 842 XMARKER (BVAR (b, zv_marker))->insertion_type = 1;
839 } 843 }
840 else 844 else
@@ -2165,9 +2169,9 @@ Any narrowing restriction in effect (see `narrow-to-region') is removed,
2165so the buffer is truly empty after this. */) 2169so the buffer is truly empty after this. */)
2166 (void) 2170 (void)
2167{ 2171{
2168 Fwiden (); 2172 Fwiden (Qnil);
2169 2173
2170 del_range (BEG, Z); 2174 del_range (BEGV, ZV);
2171 2175
2172 current_buffer->last_window_start = 1; 2176 current_buffer->last_window_start = 1;
2173 /* Prevent warnings, or suspension of auto saving, that would happen 2177 /* Prevent warnings, or suspension of auto saving, that would happen
@@ -2310,6 +2314,8 @@ DEFUN ("buffer-swap-text", Fbuffer_swap_text, Sbuffer_swap_text,
2310 swapfield_ (pt_marker, Lisp_Object); 2314 swapfield_ (pt_marker, Lisp_Object);
2311 swapfield_ (begv_marker, Lisp_Object); 2315 swapfield_ (begv_marker, Lisp_Object);
2312 swapfield_ (zv_marker, Lisp_Object); 2316 swapfield_ (zv_marker, Lisp_Object);
2317 swapfield_ (begh_marker, Lisp_Object);
2318 swapfield_ (zh_marker, Lisp_Object);
2313 bset_point_before_scroll (current_buffer, Qnil); 2319 bset_point_before_scroll (current_buffer, Qnil);
2314 bset_point_before_scroll (other_buffer, Qnil); 2320 bset_point_before_scroll (other_buffer, Qnil);
2315 2321
@@ -2490,7 +2496,7 @@ current buffer is cleared. */)
2490 } 2496 }
2491 } 2497 }
2492 if (narrowed) 2498 if (narrowed)
2493 Fnarrow_to_region (make_number (begv), make_number (zv)); 2499 Fnarrow_to_region (make_number (begv), make_number (zv), Qnil);
2494 } 2500 }
2495 else 2501 else
2496 { 2502 {
@@ -2571,7 +2577,7 @@ current buffer is cleared. */)
2571 TEMP_SET_PT (pt); 2577 TEMP_SET_PT (pt);
2572 2578
2573 if (narrowed) 2579 if (narrowed)
2574 Fnarrow_to_region (make_number (begv), make_number (zv)); 2580 Fnarrow_to_region (make_number (begv), make_number (zv), Qnil);
2575 2581
2576 /* Do this first, so that chars_in_text asks the right question. 2582 /* Do this first, so that chars_in_text asks the right question.
2577 set_intervals_multibyte needs it too. */ 2583 set_intervals_multibyte needs it too. */
@@ -5053,6 +5059,8 @@ init_buffer_once (void)
5053 bset_pt_marker (&buffer_local_flags, make_number (0)); 5059 bset_pt_marker (&buffer_local_flags, make_number (0));
5054 bset_begv_marker (&buffer_local_flags, make_number (0)); 5060 bset_begv_marker (&buffer_local_flags, make_number (0));
5055 bset_zv_marker (&buffer_local_flags, make_number (0)); 5061 bset_zv_marker (&buffer_local_flags, make_number (0));
5062 bset_begh_marker (&buffer_local_flags, make_number (0));
5063 bset_zh_marker (&buffer_local_flags, make_number (0));
5056 bset_last_selected_window (&buffer_local_flags, make_number (0)); 5064 bset_last_selected_window (&buffer_local_flags, make_number (0));
5057 5065
5058 idx = 1; 5066 idx = 1;
diff --git a/src/buffer.h b/src/buffer.h
index 87b7cee4413..5eeb3ce26e7 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -416,6 +416,26 @@ extern void enlarge_buffer_text (struct buffer *, ptrdiff_t);
416 416
417#define BUF_FETCH_BYTE(buf, n) \ 417#define BUF_FETCH_BYTE(buf, n) \
418 *(BUF_BYTE_ADDRESS ((buf), (n))) 418 *(BUF_BYTE_ADDRESS ((buf), (n)))
419
420
421/* Macros for setting and accessing hard-narrow markers */
422
423/* Position of beginning of hard-narrowed range of buffer. */
424#define BEGH (BUF_BEGH (current_buffer))
425#define BUF_BEGH(buf) \
426 ((NILP (BVAR (buf, begh_marker))) ? BUF_BEG (buf) \
427 : marker_position (BVAR (buf, begh_marker)))
428#define SET_BUF_BEGH(buf, charpos) \
429 (bset_begh_marker (buf, build_marker(buf, charpos, buf_charpos_to_bytepos(buf, charpos))))
430
431/* Position of end of hard-narrowed range of buffer. */
432#define ZH (BUF_ZH(current_buffer))
433#define BUF_ZH(buf) \
434 ((NILP (BVAR (buf, zh_marker))) ? BUF_Z (buf) \
435 : marker_position (BVAR (buf, zh_marker)))
436#define SET_BUF_ZH(buf, charpos) \
437 (bset_zh_marker (buf, build_marker(buf, charpos, buf_charpos_to_bytepos(buf, charpos))))
438
419 439
420/* Define the actual buffer data structures. */ 440/* Define the actual buffer data structures. */
421 441
@@ -666,6 +686,12 @@ struct buffer
666 ZV for this buffer when the buffer is not current. */ 686 ZV for this buffer when the buffer is not current. */
667 Lisp_Object zv_marker_; 687 Lisp_Object zv_marker_;
668 688
689 /* Lower hard limit of the buffer.*/
690 Lisp_Object begh_marker_;
691
692 /* Upper hard limit of the buffer.*/
693 Lisp_Object zh_marker_;
694
669 /* This holds the point value before the last scroll operation. 695 /* This holds the point value before the last scroll operation.
670 Explicitly setting point sets this to nil. */ 696 Explicitly setting point sets this to nil. */
671 Lisp_Object point_before_scroll_; 697 Lisp_Object point_before_scroll_;
@@ -984,6 +1010,16 @@ bset_width_table (struct buffer *b, Lisp_Object val)
984{ 1010{
985 b->width_table_ = val; 1011 b->width_table_ = val;
986} 1012}
1013INLINE void
1014bset_begh_marker (struct buffer *b, Lisp_Object val)
1015{
1016 b->begh_marker_ = val;
1017}
1018INLINE void
1019bset_zh_marker (struct buffer *b, Lisp_Object val)
1020{
1021 b->zh_marker_ = val;
1022}
987 1023
988/* Number of Lisp_Objects at the beginning of struct buffer. 1024/* Number of Lisp_Objects at the beginning of struct buffer.
989 If you add, remove, or reorder Lisp_Objects within buffer 1025 If you add, remove, or reorder Lisp_Objects within buffer
diff --git a/src/bytecode.c b/src/bytecode.c
index 9ae2e820d51..8cefa10475c 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -1682,17 +1682,18 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
1682 1682
1683 CASE (Bnarrow_to_region): 1683 CASE (Bnarrow_to_region):
1684 { 1684 {
1685 Lisp_Object v1; 1685 Lisp_Object v1, v2;
1686 BEFORE_POTENTIAL_GC (); 1686 BEFORE_POTENTIAL_GC ();
1687 v1 = POP; 1687 v1 = POP;
1688 TOP = Fnarrow_to_region (TOP, v1); 1688 v2 = POP;
1689 TOP = Fnarrow_to_region (TOP, v2, v1);
1689 AFTER_POTENTIAL_GC (); 1690 AFTER_POTENTIAL_GC ();
1690 NEXT; 1691 NEXT;
1691 } 1692 }
1692 1693
1693 CASE (Bwiden): 1694 CASE (Bwiden):
1694 BEFORE_POTENTIAL_GC (); 1695 BEFORE_POTENTIAL_GC ();
1695 PUSH (Fwiden ()); 1696 TOP = Fwiden (TOP);
1696 AFTER_POTENTIAL_GC (); 1697 AFTER_POTENTIAL_GC ();
1697 NEXT; 1698 NEXT;
1698 1699
diff --git a/src/editfns.c b/src/editfns.c
index 2ac0537eddb..80f111774ef 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3480,33 +3480,54 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
3480 return empty_unibyte_string; 3480 return empty_unibyte_string;
3481 return del_range_1 (XINT (start), XINT (end), 1, 1); 3481 return del_range_1 (XINT (start), XINT (end), 1, 1);
3482} 3482}
3483
3483 3484
3484DEFUN ("widen", Fwiden, Swiden, 0, 0, "", 3485DEFUN ("widen", Fwiden, Swiden, 0, 1, "",
3485 doc: /* Remove restrictions (narrowing) from current buffer. 3486 doc: /* Remove restrictions (narrowing) from current buffer.
3486This allows the buffer's full text to be seen and edited. */) 3487If HARD is non-nil, remove the hard restriction imposed by a previous
3487 (void) 3488call to \\[narrow-to-region]. If HARD is nil, remove visual
3489restriction up to the previously imposed hard limit (if any). */)
3490 (Lisp_Object hard)
3488{ 3491{
3489 if (BEG != BEGV || Z != ZV) 3492
3490 current_buffer->clip_changed = 1; 3493 if(!NILP (hard))
3491 BEGV = BEG; 3494 {
3492 BEGV_BYTE = BEG_BYTE; 3495 bset_begh_marker(current_buffer, Qnil);
3493 SET_BUF_ZV_BOTH (current_buffer, Z, Z_BYTE); 3496 bset_zh_marker(current_buffer, Qnil);
3494 /* Changing the buffer bounds invalidates any recorded current column. */ 3497 }
3495 invalidate_current_column (); 3498 else
3499 {
3500 if (BEG != BEGV || Z != ZV)
3501 current_buffer->clip_changed = 1;
3502 BEGV = BEG;
3503 BEGV_BYTE = BEG_BYTE;
3504 SET_BUF_ZV_BOTH (current_buffer, Z, Z_BYTE);
3505 /* Changing the buffer bounds invalidates any recorded current column. */
3506 invalidate_current_column ();
3507 }
3508
3496 return Qnil; 3509 return Qnil;
3497} 3510}
3498 3511
3499DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r", 3512DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 3, "r",
3500 doc: /* Restrict editing in this buffer to the current region. 3513 doc: /* Restrict editing in this buffer to the current
3501The rest of the text becomes temporarily invisible and untouchable 3514region. START and END are positions (integers or markers) bounding the
3502but is not deleted; if you save the buffer in a file, the invisible 3515text that should restricted. There can be two types of restrictions,
3503text is included in the file. \\[widen] makes all visible again. 3516visual and hard. If HARD is nil, impose visual restriction, otherwise
3504See also `save-restriction'. 3517a hard one.
3505 3518
3506When calling from a program, pass two arguments; positions (integers 3519When visual restriction is in place, the rest of the text is invisible
3507or markers) bounding the text that should remain visible. */) 3520and untouchable but is not deleted; if you save the buffer in a file,
3508 (register Lisp_Object start, Lisp_Object end) 3521the invisible text is included in the file. \\[widen] with nil
3522optional argument makes it all visible again.
3523
3524When hard restriction is in place, invocations of (visual) \\[widen]
3525with nil argument removes visual narrowing up to the hard
3526restriction. In order to lift hard restriction, call \\[widen] with
3527non-nil HARD argument. */)
3528 (register Lisp_Object start, Lisp_Object end, Lisp_Object hard)
3509{ 3529{
3530
3510 CHECK_NUMBER_COERCE_MARKER (start); 3531 CHECK_NUMBER_COERCE_MARKER (start);
3511 CHECK_NUMBER_COERCE_MARKER (end); 3532 CHECK_NUMBER_COERCE_MARKER (end);
3512 3533
@@ -3519,6 +3540,15 @@ or markers) bounding the text that should remain visible. */)
3519 if (!(BEG <= XINT (start) && XINT (start) <= XINT (end) && XINT (end) <= Z)) 3540 if (!(BEG <= XINT (start) && XINT (start) <= XINT (end) && XINT (end) <= Z))
3520 args_out_of_range (start, end); 3541 args_out_of_range (start, end);
3521 3542
3543 if (!NILP (hard))
3544 {
3545 SET_BUF_BEGH (current_buffer, XFASTINT (start));
3546 SET_BUF_ZH (current_buffer, XFASTINT (end));
3547 if (BEGV >= XFASTINT (start) && ZV <= XFASTINT (end))
3548 /* Visual narrowing within hard limits. */
3549 return Qnil;
3550 }
3551
3522 if (BEGV != XFASTINT (start) || ZV != XFASTINT (end)) 3552 if (BEGV != XFASTINT (start) || ZV != XFASTINT (end))
3523 current_buffer->clip_changed = 1; 3553 current_buffer->clip_changed = 1;
3524 3554
@@ -3533,6 +3563,7 @@ or markers) bounding the text that should remain visible. */)
3533 return Qnil; 3563 return Qnil;
3534} 3564}
3535 3565
3566
3536Lisp_Object 3567Lisp_Object
3537save_restriction_save (void) 3568save_restriction_save (void)
3538{ 3569{
diff --git a/src/fileio.c b/src/fileio.c
index dfab3de9e94..5b63e394216 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -4764,7 +4764,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
4764 This is useful in tar-mode. --Stef 4764 This is useful in tar-mode. --Stef
4765 XSETFASTINT (start, BEG); 4765 XSETFASTINT (start, BEG);
4766 XSETFASTINT (end, Z); */ 4766 XSETFASTINT (end, Z); */
4767 Fwiden (); 4767 Fwiden (Qnil);
4768 } 4768 }
4769 4769
4770 record_unwind_protect (build_annotations_unwind, 4770 record_unwind_protect (build_annotations_unwind,
diff --git a/src/lread.c b/src/lread.c
index 91469230b7e..515eca1ceca 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1850,7 +1850,7 @@ readevalloop (Lisp_Object readcharfun,
1850 /* Set point and ZV around stuff to be read. */ 1850 /* Set point and ZV around stuff to be read. */
1851 Fgoto_char (start); 1851 Fgoto_char (start);
1852 if (!NILP (end)) 1852 if (!NILP (end))
1853 Fnarrow_to_region (make_number (BEGV), end); 1853 Fnarrow_to_region (make_number (BEGV), end, Qnil);
1854 1854
1855 /* Just for cleanliness, convert END to a marker 1855 /* Just for cleanliness, convert END to a marker
1856 if it is an integer. */ 1856 if it is an integer. */
diff --git a/src/process.c b/src/process.c
index dd508836f79..75e3934237d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -5514,7 +5514,7 @@ Otherwise it discards the output. */)
5514 /* If the output marker is outside of the visible region, save 5514 /* If the output marker is outside of the visible region, save
5515 the restriction and widen. */ 5515 the restriction and widen. */
5516 if (! (BEGV <= PT && PT <= ZV)) 5516 if (! (BEGV <= PT && PT <= ZV))
5517 Fwiden (); 5517 Fwiden (Qnil);
5518 5518
5519 /* Adjust the multibyteness of TEXT to that of the buffer. */ 5519 /* Adjust the multibyteness of TEXT to that of the buffer. */
5520 if (NILP (BVAR (current_buffer, enable_multibyte_characters)) 5520 if (NILP (BVAR (current_buffer, enable_multibyte_characters))
@@ -5558,7 +5558,7 @@ Otherwise it discards the output. */)
5558 5558
5559 /* If the restriction isn't what it should be, set it. */ 5559 /* If the restriction isn't what it should be, set it. */
5560 if (old_begv != BEGV || old_zv != ZV) 5560 if (old_begv != BEGV || old_zv != ZV)
5561 Fnarrow_to_region (make_number (old_begv), make_number (old_zv)); 5561 Fnarrow_to_region (make_number (old_begv), make_number (old_zv), Qnil);
5562 5562
5563 bset_read_only (current_buffer, old_read_only); 5563 bset_read_only (current_buffer, old_read_only);
5564 SET_PT_BOTH (opoint, opoint_byte); 5564 SET_PT_BOTH (opoint, opoint_byte);