diff options
| author | Vitalie Spinu | 2016-03-21 05:41:55 +0100 |
|---|---|---|
| committer | Vitalie Spinu | 2016-03-22 03:16:17 +0100 |
| commit | c331b6626a427fb89303fea75faebd8c39d343a8 (patch) | |
| tree | f5cf4ee74164ed2b9fe2037d764be441e4b67175 | |
| parent | 91e667692ba1362ca1334b8d58fd16c305ad5e2a (diff) | |
| download | emacs-scratch/widen-limits.tar.gz emacs-scratch/widen-limits.zip | |
Implement buffer-widen-limits functionalityscratch/widen-limits
`widen` now respects restrictions imposed by new variable
`hard-widen-limits`
| -rw-r--r-- | src/buffer.c | 19 | ||||
| -rw-r--r-- | src/buffer.h | 17 | ||||
| -rw-r--r-- | src/editfns.c | 15 |
3 files changed, 48 insertions, 3 deletions
diff --git a/src/buffer.c b/src/buffer.c index f06d7e08e49..1b62d3a4d51 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -329,6 +329,11 @@ bset_scroll_up_aggressively (struct buffer *b, Lisp_Object val) | |||
| 329 | b->scroll_up_aggressively_ = val; | 329 | b->scroll_up_aggressively_ = val; |
| 330 | } | 330 | } |
| 331 | static void | 331 | static void |
| 332 | bset_widen_limits (struct buffer *b, Lisp_Object val) | ||
| 333 | { | ||
| 334 | b->widen_limits_ = val; | ||
| 335 | } | ||
| 336 | static void | ||
| 332 | bset_selective_display (struct buffer *b, Lisp_Object val) | 337 | bset_selective_display (struct buffer *b, Lisp_Object val) |
| 333 | { | 338 | { |
| 334 | b->selective_display_ = val; | 339 | b->selective_display_ = val; |
| @@ -847,6 +852,7 @@ CLONE nil means the indirect buffer's state is reset to default values. */) | |||
| 847 | bset_display_count (b, make_number (0)); | 852 | bset_display_count (b, make_number (0)); |
| 848 | bset_backed_up (b, Qnil); | 853 | bset_backed_up (b, Qnil); |
| 849 | bset_auto_save_file_name (b, Qnil); | 854 | bset_auto_save_file_name (b, Qnil); |
| 855 | bset_widen_limits (b, b->base_buffer->widen_limits_); | ||
| 850 | set_buffer_internal_1 (b); | 856 | set_buffer_internal_1 (b); |
| 851 | Fset (intern ("buffer-save-without-query"), Qnil); | 857 | Fset (intern ("buffer-save-without-query"), Qnil); |
| 852 | Fset (intern ("buffer-file-number"), Qnil); | 858 | Fset (intern ("buffer-file-number"), Qnil); |
| @@ -961,6 +967,7 @@ reset_buffer_local_variables (struct buffer *b, bool permanent_too) | |||
| 961 | things that depend on the major mode. | 967 | things that depend on the major mode. |
| 962 | default-major-mode is handled at a higher level. | 968 | default-major-mode is handled at a higher level. |
| 963 | We ignore it here. */ | 969 | We ignore it here. */ |
| 970 | bset_widen_limits(b, Qnil); | ||
| 964 | bset_major_mode (b, Qfundamental_mode); | 971 | bset_major_mode (b, Qfundamental_mode); |
| 965 | bset_keymap (b, Qnil); | 972 | bset_keymap (b, Qnil); |
| 966 | bset_mode_name (b, QSFundamental); | 973 | bset_mode_name (b, QSFundamental); |
| @@ -2167,7 +2174,7 @@ so the buffer is truly empty after this. */) | |||
| 2167 | { | 2174 | { |
| 2168 | Fwiden (); | 2175 | Fwiden (); |
| 2169 | 2176 | ||
| 2170 | del_range (BEG, Z); | 2177 | del_range (BEGWL, ZWL); |
| 2171 | 2178 | ||
| 2172 | current_buffer->last_window_start = 1; | 2179 | current_buffer->last_window_start = 1; |
| 2173 | /* Prevent warnings, or suspension of auto saving, that would happen | 2180 | /* Prevent warnings, or suspension of auto saving, that would happen |
| @@ -5037,6 +5044,7 @@ init_buffer_once (void) | |||
| 5037 | bset_display_count (&buffer_local_flags, make_number (-1)); | 5044 | bset_display_count (&buffer_local_flags, make_number (-1)); |
| 5038 | bset_display_time (&buffer_local_flags, make_number (-1)); | 5045 | bset_display_time (&buffer_local_flags, make_number (-1)); |
| 5039 | bset_enable_multibyte_characters (&buffer_local_flags, make_number (-1)); | 5046 | bset_enable_multibyte_characters (&buffer_local_flags, make_number (-1)); |
| 5047 | bset_widen_limits (&buffer_local_flags, make_number (-1)); | ||
| 5040 | 5048 | ||
| 5041 | /* These used to be stuck at 0 by default, but now that the all-zero value | 5049 | /* These used to be stuck at 0 by default, but now that the all-zero value |
| 5042 | means Qnil, we have to initialize them explicitly. */ | 5050 | means Qnil, we have to initialize them explicitly. */ |
| @@ -5160,6 +5168,7 @@ init_buffer_once (void) | |||
| 5160 | bset_cursor_type (&buffer_defaults, Qt); | 5168 | bset_cursor_type (&buffer_defaults, Qt); |
| 5161 | bset_extra_line_spacing (&buffer_defaults, Qnil); | 5169 | bset_extra_line_spacing (&buffer_defaults, Qnil); |
| 5162 | bset_cursor_in_non_selected_windows (&buffer_defaults, Qt); | 5170 | bset_cursor_in_non_selected_windows (&buffer_defaults, Qt); |
| 5171 | bset_widen_limits (&buffer_defaults, Qnil); | ||
| 5163 | 5172 | ||
| 5164 | bset_enable_multibyte_characters (&buffer_defaults, Qt); | 5173 | bset_enable_multibyte_characters (&buffer_defaults, Qt); |
| 5165 | bset_buffer_file_coding_system (&buffer_defaults, Qnil); | 5174 | bset_buffer_file_coding_system (&buffer_defaults, Qnil); |
| @@ -5367,7 +5376,6 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring, | |||
| 5367 | emacs_abort (); | 5376 | emacs_abort (); |
| 5368 | } | 5377 | } |
| 5369 | 5378 | ||
| 5370 | |||
| 5371 | /* Initialize the buffer routines. */ | 5379 | /* Initialize the buffer routines. */ |
| 5372 | void | 5380 | void |
| 5373 | syms_of_buffer (void) | 5381 | 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 | |||
| 5796 | if its text size shrinks. If you use `buffer-swap-text' on a buffer, | 5804 | if its text size shrinks. If you use `buffer-swap-text' on a buffer, |
| 5797 | you probably should set this to -2 in that buffer. */); | 5805 | you probably should set this to -2 in that buffer. */); |
| 5798 | 5806 | ||
| 5807 | DEFVAR_PER_BUFFER ("buffer-widen-limits", &BVAR (current_buffer, widen_limits), | ||
| 5808 | Qnil, | ||
| 5809 | doc: /* When non-nil `widen` will widen to these limits. | ||
| 5810 | Must be a cons of the form (MIN . MAX) where MIN and MAX are integers | ||
| 5811 | of hard widen limits in this buffer. This is an experimental variable | ||
| 5812 | intended primarily for multi-mode engines. */); | ||
| 5813 | |||
| 5799 | DEFVAR_PER_BUFFER ("selective-display", &BVAR (current_buffer, selective_display), | 5814 | DEFVAR_PER_BUFFER ("selective-display", &BVAR (current_buffer, selective_display), |
| 5800 | Qnil, | 5815 | Qnil, |
| 5801 | doc: /* Non-nil enables selective display. | 5816 | doc: /* Non-nil enables selective display. |
diff --git a/src/buffer.h b/src/buffer.h index 87b7cee4413..4075bbf555c 100644 --- a/src/buffer.h +++ b/src/buffer.h | |||
| @@ -59,6 +59,10 @@ INLINE_HEADER_BEGIN | |||
| 59 | #define Z (current_buffer->text->z) | 59 | #define Z (current_buffer->text->z) |
| 60 | #define Z_BYTE (current_buffer->text->z_byte) | 60 | #define Z_BYTE (current_buffer->text->z_byte) |
| 61 | 61 | ||
| 62 | /* Positions that take into account widen limits. */ | ||
| 63 | #define BEGWL (BUF_BEGWL (current_buffer)) | ||
| 64 | #define ZWL (BUF_ZWL(current_buffer)) | ||
| 65 | |||
| 62 | /* Macros for the addresses of places in the buffer. */ | 66 | /* Macros for the addresses of places in the buffer. */ |
| 63 | 67 | ||
| 64 | /* Address of beginning of buffer. */ | 68 | /* Address of beginning of buffer. */ |
| @@ -128,6 +132,15 @@ INLINE_HEADER_BEGIN | |||
| 128 | : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte \ | 132 | : NILP (BVAR (buf, begv_marker)) ? buf->begv_byte \ |
| 129 | : marker_byte_position (BVAR (buf, begv_marker))) | 133 | : marker_byte_position (BVAR (buf, begv_marker))) |
| 130 | 134 | ||
| 135 | /* Hard positions in buffer. */ | ||
| 136 | #define BUF_BEGWL(buf) \ | ||
| 137 | ((NILP (BVAR (buf, widen_limits))) ? BUF_BEG (buf) \ | ||
| 138 | : XINT( XCAR (BVAR (buf, widen_limits)))) | ||
| 139 | |||
| 140 | #define BUF_ZWL(buf) \ | ||
| 141 | ((NILP (BVAR (buf, widen_limits))) ? BUF_Z (buf) \ | ||
| 142 | : XINT( XCDR (BVAR (buf, widen_limits)))) | ||
| 143 | |||
| 131 | /* Position of point in buffer. */ | 144 | /* Position of point in buffer. */ |
| 132 | #define BUF_PT(buf) \ | 145 | #define BUF_PT(buf) \ |
| 133 | (buf == current_buffer ? PT \ | 146 | (buf == current_buffer ? PT \ |
| @@ -150,6 +163,7 @@ INLINE_HEADER_BEGIN | |||
| 150 | : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte \ | 163 | : NILP (BVAR (buf, zv_marker)) ? buf->zv_byte \ |
| 151 | : marker_byte_position (BVAR (buf, zv_marker))) | 164 | : marker_byte_position (BVAR (buf, zv_marker))) |
| 152 | 165 | ||
| 166 | |||
| 153 | /* Position of gap in buffer. */ | 167 | /* Position of gap in buffer. */ |
| 154 | #define BUF_GPT(buf) ((buf)->text->gpt) | 168 | #define BUF_GPT(buf) ((buf)->text->gpt) |
| 155 | #define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte) | 169 | #define BUF_GPT_BYTE(buf) ((buf)->text->gpt_byte) |
| @@ -748,6 +762,9 @@ struct buffer | |||
| 748 | See `cursor-type' for other values. */ | 762 | See `cursor-type' for other values. */ |
| 749 | Lisp_Object cursor_in_non_selected_windows_; | 763 | Lisp_Object cursor_in_non_selected_windows_; |
| 750 | 764 | ||
| 765 | /* Cons of hard widen limits */ | ||
| 766 | Lisp_Object widen_limits_; | ||
| 767 | |||
| 751 | /* No more Lisp_Object beyond this point. Except undo_list, | 768 | /* No more Lisp_Object beyond this point. Except undo_list, |
| 752 | which is handled specially in Fgarbage_collect. */ | 769 | which is handled specially in Fgarbage_collect. */ |
| 753 | 770 | ||
diff --git a/src/editfns.c b/src/editfns.c index 2ac0537eddb..e5ab637aba1 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -3480,12 +3480,25 @@ 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 | ||
| 3484 | DEFUN ("widen", Fwiden, Swiden, 0, 0, "", | 3485 | DEFUN ("widen", Fwiden, Swiden, 0, 0, "", |
| 3485 | doc: /* Remove restrictions (narrowing) from current buffer. | 3486 | doc: /* Remove restrictions (narrowing) from current buffer. |
| 3486 | This allows the buffer's full text to be seen and edited. */) | 3487 | This allows the buffer's full text to be seen and edited. |
| 3488 | If `buffer-widen-limits` is non-nil, widen only to those limits. */) | ||
| 3487 | (void) | 3489 | (void) |
| 3488 | { | 3490 | { |
| 3491 | |||
| 3492 | if (!NILP (BVAR(current_buffer, widen_limits))) | ||
| 3493 | { | ||
| 3494 | Lisp_Object hl = BVAR(current_buffer, widen_limits); | ||
| 3495 | CHECK_CONS(hl); | ||
| 3496 | CHECK_NUMBER(XCAR(hl)); | ||
| 3497 | CHECK_NUMBER(XCDR(hl)); | ||
| 3498 | Fnarrow_to_region(XCAR(hl), XCDR(hl)); | ||
| 3499 | return Qnil; | ||
| 3500 | } | ||
| 3501 | |||
| 3489 | if (BEG != BEGV || Z != ZV) | 3502 | if (BEG != BEGV || Z != ZV) |
| 3490 | current_buffer->clip_changed = 1; | 3503 | current_buffer->clip_changed = 1; |
| 3491 | BEGV = BEG; | 3504 | BEGV = BEG; |