From eafcff9e72499e3bb6dc462d406dd33a885e3d49 Mon Sep 17 00:00:00 2001 From: Vitalie Spinu Date: Mon, 21 Mar 2016 05:41:55 +0100 Subject: [PATCH] Implement hard-narrowing `widen` now respects restrictions imposed by new variable `hard-widen-limits` --- src/buffer.c | 5 +++++ src/editfns.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/buffer.c b/src/buffer.c index f06d7e0..5232c49 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -6219,6 +6219,11 @@ and disregard a `read-only' text property if the property value is a member of the list. */); Vinhibit_read_only = Qnil; + DEFVAR_LISP ("hard-widen-limits", Vhard_widen_limits, + doc: /* When non-nil `widen` will widen to these limits. +Must be a cons of the form (MIN . MAX) where MIN and MAX are integers or markers. */); + Vhard_widen_limits = Qnil; + DEFVAR_PER_BUFFER ("cursor-type", &BVAR (current_buffer, cursor_type), Qnil, doc: /* Cursor to use when this buffer is in the selected window. Values are interpreted as follows: diff --git a/src/editfns.c b/src/editfns.c index 2ac0537..fb1f652 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -3480,12 +3480,24 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region, return empty_unibyte_string; return del_range_1 (XINT (start), XINT (end), 1, 1); } + DEFUN ("widen", Fwiden, Swiden, 0, 0, "", doc: /* Remove restrictions (narrowing) from current buffer. -This allows the buffer's full text to be seen and edited. */) +This allows the buffer's full text to be seen and edited. +If `hard-widen-limits` is non-nil, widen only to those limits. */) (void) { + + if (! NILP (Vhard_widen_limits)) + { + CHECK_CONS(Vhard_widen_limits); + Lisp_Object hbeg = XCAR(Vhard_widen_limits); + Lisp_Object hend = XCDR(Vhard_widen_limits); + Fnarrow_to_region(hbeg, hend); + return Qnil; + } + if (BEG != BEGV || Z != ZV) current_buffer->clip_changed = 1; BEGV = BEG; -- 2.5.0