unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Vitalie Spinu <spinuvit@gmail.com>
To: Stefan Monnier <monnier@IRO.UMontreal.CA>
Cc: emacs-devel@gnu.org
Subject: Re: [Patch] hard-widen-limits [was Re: Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.]]
Date: Tue, 22 Mar 2016 04:17:59 +0100	[thread overview]
Message-ID: <87egb3ryjc.fsf@gmail.com> (raw)
In-Reply-To: <87lh5bd4ib.fsf@gmail.com> (Vitalie Spinu's message of "Mon, 21 Mar 2016 20:18:04 +0100")

[-- Attachment #1: Type: text/plain, Size: 618 bytes --]



>> On Mon, Mar 21 2016 20:18, Vitalie Spinu wrote:

>>> This is outside of use cases that I have in mind.

>> Indeed, it's a different case, but one where the narrowing should be
>> hard as well.

> Ok. This part is trickier but it might not be that hard. Will keep this in mind.

I have pushed the proposed change to `widen-limits` branch. The C level
consequences are fairly innocuous. There are only 3 instances of calls to Fwiden
in the whole emacs.

Given that there seem to be use cases of permanent limiting I kept it as buffer
local variable. I also switched to milder name buffer-widen-limits.

  Vitalie



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff, Size: 5854 bytes --]

3 files changed, 48 insertions(+), 3 deletions(-)
src/buffer.c  | 19 +++++++++++++++++--
src/buffer.h  | 17 +++++++++++++++++
src/editfns.c | 15 ++++++++++++++-

modified   src/buffer.c
@@ -329,6 +329,11 @@ bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val)
   b->scroll_up_aggressively_ = val;
 }
 static void
+bset_widen_limits (struct buffer *b, Lisp_Object val)
+{
+  b->widen_limits_ = val;
+}
+static void
 bset_selective_display (struct buffer *b, Lisp_Object val)
 {
   b->selective_display_ = val;
@@ -847,6 +852,7 @@ CLONE nil means the indirect buffer's state is reset to default values.  */)
       bset_display_count (b, make_number (0));
       bset_backed_up (b, Qnil);
       bset_auto_save_file_name (b, Qnil);
+      bset_widen_limits (b, b->base_buffer->widen_limits_);
       set_buffer_internal_1 (b);
       Fset (intern ("buffer-save-without-query"), Qnil);
       Fset (intern ("buffer-file-number"), Qnil);
@@ -961,6 +967,7 @@ reset_buffer_local_variables (struct buffer *b, bool permanent_too)
      things that depend on the major mode.
      default-major-mode is handled at a higher level.
      We ignore it here.  */
+  bset_widen_limits(b, Qnil);
   bset_major_mode (b, Qfundamental_mode);
   bset_keymap (b, Qnil);
   bset_mode_name (b, QSFundamental);
@@ -2167,7 +2174,7 @@ so the buffer is truly empty after this.  */)
 {
   Fwiden ();
 
-  del_range (BEG, Z);
+  del_range (BEGWL, ZWL);
 
   current_buffer->last_window_start = 1;
   /* Prevent warnings, or suspension of auto saving, that would happen
@@ -5037,6 +5044,7 @@ init_buffer_once (void)
   bset_display_count (&buffer_local_flags, make_number (-1));
   bset_display_time (&buffer_local_flags, make_number (-1));
   bset_enable_multibyte_characters (&buffer_local_flags, make_number (-1));
+  bset_widen_limits (&buffer_local_flags, make_number (-1));
 
   /* These used to be stuck at 0 by default, but now that the all-zero value
      means Qnil, we have to initialize them explicitly.  */
@@ -5160,6 +5168,7 @@ init_buffer_once (void)
   bset_cursor_type (&buffer_defaults, Qt);
   bset_extra_line_spacing (&buffer_defaults, Qnil);
   bset_cursor_in_non_selected_windows (&buffer_defaults, Qt);
+  bset_widen_limits (&buffer_defaults, Qnil);
 
   bset_enable_multibyte_characters (&buffer_defaults, Qt);
   bset_buffer_file_coding_system (&buffer_defaults, Qnil);
@@ -5367,7 +5376,6 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring,
     emacs_abort ();
 }
 
-
 /* Initialize the buffer routines.  */
 void
 syms_of_buffer (void)
@@ -5796,6 +5804,13 @@ If you set this to -2, that means don't turn off auto-saving in this buffer
 if its text size shrinks.   If you use `buffer-swap-text' on a buffer,
 you probably should set this to -2 in that buffer.  */);
 
+  DEFVAR_PER_BUFFER ("buffer-widen-limits", &BVAR (current_buffer, widen_limits),
+                     Qnil,
+                     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
+of hard widen limits in this buffer. This is an experimental variable
+intended primarily for multi-mode engines.  */);
+
   DEFVAR_PER_BUFFER ("selective-display", &BVAR (current_buffer, selective_display),
 		     Qnil,
 		     doc: /* Non-nil enables selective display.
modified   src/buffer.h
@@ -59,6 +59,10 @@ INLINE_HEADER_BEGIN
 #define Z (current_buffer->text->z)
 #define Z_BYTE (current_buffer->text->z_byte)
 
+/* Positions that take into account widen limits.  */
+#define BEGWL (BUF_BEGWL (current_buffer))
+#define ZWL (BUF_ZWL(current_buffer))
+
 /* Macros for the addresses of places in the buffer.  */
 
 /* Address of beginning of buffer.  */
@@ -128,6 +132,15 @@ INLINE_HEADER_BEGIN
     : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte	\
     : marker_byte_position (BVAR (buf, begv_marker)))
 
+/* Hard positions in buffer. */
+#define BUF_BEGWL(buf)  	                                \
+  ((NILP (BVAR (buf, widen_limits))) ?  BUF_BEG (buf)    \
+   : XINT( XCAR (BVAR (buf, widen_limits))))
+
+#define BUF_ZWL(buf)  	                                \
+  ((NILP (BVAR (buf, widen_limits))) ?  BUF_Z (buf)      \
+   : XINT( XCDR (BVAR (buf, widen_limits))))
+
 /* Position of point in buffer.  */
 #define BUF_PT(buf)					\
    (buf == current_buffer ? PT				\
@@ -150,6 +163,7 @@ INLINE_HEADER_BEGIN
     : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte	\
     : marker_byte_position (BVAR (buf, zv_marker)))
 
+
 /* Position of gap in buffer.  */
 #define BUF_GPT(buf) ((buf)->text->gpt)
 #define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte)
@@ -748,6 +762,9 @@ struct buffer
      See `cursor-type' for other values.  */
   Lisp_Object cursor_in_non_selected_windows_;
 
+  /* Cons of hard widen limits */
+  Lisp_Object widen_limits_;
+
   /* No more Lisp_Object beyond this point.  Except undo_list,
      which is handled specially in Fgarbage_collect.  */
 
modified   src/editfns.c
@@ -3480,12 +3480,25 @@ DEFUN ("delete-and-extract-region", Fdelete_and_extract_region,
     return empty_unibyte_string;
   return del_range_1 (XINT (start), XINT (end), 1, 1);
 }
+
 \f
 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 `buffer-widen-limits` is non-nil, widen only to those limits.  */)
   (void)
 {
+
+  if (!NILP (BVAR(current_buffer, widen_limits)))
+    {
+      Lisp_Object hl = BVAR(current_buffer,  widen_limits);
+      CHECK_CONS(hl);
+      CHECK_NUMBER(XCAR(hl));
+      CHECK_NUMBER(XCDR(hl));
+      Fnarrow_to_region(XCAR(hl), XCDR(hl));
+      return Qnil;
+    }
+
   if (BEG != BEGV || Z != ZV)
     current_buffer->clip_changed = 1;
   BEGV = BEG;

[back]

  reply	other threads:[~2016-03-22  3:17 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20160311151512.GD2888@acm.fritz.box>
     [not found] ` <b158555f-e014-ed7b-23eb-d80d2d77a6f4@yandex.ru>
     [not found]   ` <20160311212410.GG2888@acm.fritz.box>
     [not found]     ` <73903215-f94b-e194-7bfe-0d6350c95769@yandex.ru>
     [not found]       ` <20160311221540.GH2888@acm.fritz.box>
     [not found]         ` <2c301ec9-041d-9172-d628-479062314b23@yandex.ru>
2016-03-14 15:16           ` Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.] Alan Mackenzie
2016-03-14 17:34             ` Andreas Röhler
2016-03-14 20:06             ` Dmitry Gutov
2016-03-19 22:51               ` Vitalie Spinu
2016-03-20  2:19                 ` Dmitry Gutov
2016-03-20 12:15                   ` Vitalie Spinu
2016-03-20 15:58                     ` Dmitry Gutov
2016-03-21  1:05                       ` Vitalie Spinu
2016-03-21  3:11                         ` Stefan Monnier
2016-03-21  5:05                           ` Vitalie Spinu
2016-03-21  7:13                             ` Andreas Röhler
2016-03-21 12:26                             ` Stefan Monnier
2016-03-21 14:13                               ` Vitalie Spinu
2016-03-21 14:43                                 ` Stefan Monnier
2016-03-21 16:42                                   ` Vitalie Spinu
2016-03-21 18:31                                     ` Stefan Monnier
2016-03-21 19:16                                       ` Vitalie Spinu
2016-03-21 20:47                                         ` Stefan Monnier
2016-03-21 20:33                                     ` Alan Mackenzie
2016-03-21 20:49                                       ` Stefan Monnier
2016-03-21 21:03                                       ` Drew Adams
2016-03-21 21:12                                       ` Dmitry Gutov
2016-03-21 16:45                                   ` Vitalie Spinu
2016-03-21 22:55                                     ` Dmitry Gutov
2016-03-22 14:51                                     ` Stefan Monnier
2016-03-22 18:17                                       ` Vitalie Spinu
2016-03-23  1:18                                         ` Dmitry Gutov
2016-03-23 13:18                                         ` Stefan Monnier
2016-03-22 18:26                                       ` Vitalie Spinu
2016-03-23  2:07                                         ` Stefan Monnier
2016-03-23 10:56                                           ` Vitalie Spinu
2016-03-23 11:41                                             ` Stefan Monnier
2016-03-23 12:39                                               ` Vitalie Spinu
2016-03-23 13:23                                                 ` Stefan Monnier
2016-03-23 15:28                                                   ` Dmitry Gutov
2016-03-23 21:51                                                     ` Vitalie Spinu
2016-03-24  7:30                                               ` Andreas Röhler
2016-03-21 11:56                           ` Dmitry Gutov
2016-03-21  5:08                         ` [Patch] hard-widen-limits [was Re: Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.]] Vitalie Spinu
2016-03-21 12:39                           ` Stefan Monnier
2016-03-21 12:54                             ` Vitalie Spinu
2016-03-21 14:07                               ` Stefan Monnier
2016-03-21 14:14                                 ` Vitalie Spinu
2016-03-21 14:04                             ` Stefan Monnier
2016-03-21 14:33                               ` Vitalie Spinu
2016-03-21 14:54                                 ` Stefan Monnier
2016-03-21 17:16                                   ` Vitalie Spinu
2016-03-21 18:36                                     ` Stefan Monnier
2016-03-21 19:18                                       ` Vitalie Spinu
2016-03-22  3:17                                         ` Vitalie Spinu [this message]
2016-03-22  9:57                                           ` Vitalie Spinu
2016-03-22 10:05                                             ` Vitalie Spinu
2016-03-22 11:57                                               ` Stefan Monnier
2016-03-22 16:28                                                 ` Vitalie Spinu
2016-03-22 16:44                                                   ` Stefan Monnier
2016-03-22 19:36                                                     ` Vitalie Spinu
2016-03-23  2:22                                                       ` Stefan Monnier
2016-03-23 11:41                                                         ` Vitalie Spinu
2016-03-23 12:34                                                           ` Stefan Monnier
2016-03-23 12:41                                                             ` Vitalie Spinu
2016-03-29 21:43                                                               ` Vitalie Spinu
2016-04-22 14:34                                                                 ` Dmitry Gutov
2016-04-24  7:22                                                                   ` Vitalie Spinu
2016-04-24  7:28                                                                     ` Achim Gratz
2016-04-24 11:33                                                                       ` Vitalie Spinu
2016-04-24 13:20                                                                         ` Andreas Schwab
2016-04-24 16:11                                                                           ` Vitalie Spinu
2016-04-24 16:19                                                                             ` Andreas Schwab
2016-04-24 16:41                                                                               ` Vitalie Spinu
2016-04-24 16:48                                                                                 ` Andreas Schwab
2016-04-24 18:01                                                                                   ` Vitalie Spinu
2016-04-24 19:05                                                                                     ` Andreas Schwab
2016-04-28 13:29                                                 ` Vitalie Spinu
2016-04-30 14:06                                                   ` Stefan Monnier
2016-03-22 20:08                                               ` Richard Stallman
2016-03-22 22:45                                                 ` Vitalie Spinu
2016-03-21 11:47                         ` Syntax tables for multiple modes [was: bug#22983: syntax-ppss returns wrong result.] Dmitry Gutov
2016-03-21 12:40                           ` Vitalie Spinu
2016-03-21 13:07                             ` Dmitry Gutov
2016-03-21 14:20                               ` Vitalie Spinu
2016-03-21 14:29                                 ` Dmitry Gutov
2016-03-21 14:42                                   ` Vitalie Spinu
2016-03-21 14:56                                     ` Dmitry Gutov
2016-03-21 16:52                                       ` Vitalie Spinu
2016-03-21 21:30                                         ` Dmitry Gutov
2016-04-03 23:34                                           ` John Wiegley
2016-03-21 14:02                             ` Stefan Monnier
2016-03-21 14:31                               ` Vitalie Spinu
2016-03-21 15:06                                 ` Stefan Monnier
2016-03-21 17:15                                   ` Andreas Röhler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87egb3ryjc.fsf@gmail.com \
    --to=spinuvit@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).