diff options
author | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2014-11-16 23:36:58 +0100 |
---|---|---|
committer | Lars Magne Ingebrigtsen <larsi@gnus.org> | 2014-11-16 23:41:55 +0100 |
commit | d1b04a9e7ada7070dbd84bb450411c1f169b3739 (patch) | |
tree | 8f0e26d1e2154f91364fd1b919df8bd8855604fd /src | |
parent | c94988f4b740738cbc4660ee9c64637e55ad5d76 (diff) | |
download | emacs-d1b04a9e7ada7070dbd84bb450411c1f169b3739.tar.gz |
Implement an `inhibit-read-only' text property
* doc/lispref/text.texi (Special Properties): Mention `inhibit-read-only'.
* src/buffer.c (Fbarf_if_buffer_read_only): Don't raise an error if
the text at POSITION (new optional argument) has the
`inhibit-read-only' text property set.
* src/callint.c (Fcall_interactively): Pass in nil as argument to
Fbarf_if_buffer_read_only.
* src/fileio.c (Finsert_file_contents): Ditto.
* src/insdel.c (prepare_to_modify_buffer_1): Pass start region in.
* src/intervals.h (INTERVAL_WRITABLE_P): Check the `inhibit-read-only'
text property.
* src/textprop.c (verify_interval_modification): Check buffer
readedness after the last interval.
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 19 | ||||
-rw-r--r-- | src/buffer.c | 16 | ||||
-rw-r--r-- | src/callint.c | 6 | ||||
-rw-r--r-- | src/fileio.c | 2 | ||||
-rw-r--r-- | src/insdel.c | 4 | ||||
-rw-r--r-- | src/intervals.h | 1 | ||||
-rw-r--r-- | src/textprop.c | 5 |
7 files changed, 44 insertions, 9 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 7bb16668406..d1888987dbc 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,22 @@ +2014-11-16 Lars Magne Ingebrigtsen <larsi@gnus.org> + + * intervals.h (INTERVAL_WRITABLE_P): Check the `inhibit-read-only' + text property. + + * callint.c (Fcall_interactively): Pass in nil as argument to + Fbarf_if_buffer_read_only. + + * fileio.c (Finsert_file_contents): Ditto. + + * insdel.c (prepare_to_modify_buffer_1): Pass start region in. + + * textprop.c (verify_interval_modification): Check buffer + readedness after the last interval. + + * buffer.c (Fbarf_if_buffer_read_only): Don't raise an error if + the text at POSITION (new optional argument) has the + `inhibit-read-only' text property set. + 2014-11-16 Eli Zaretskii <eliz@gnu.org> * window.c (window_scroll_pixel_based): Avoid truncation/rounding diff --git a/src/buffer.c b/src/buffer.c index 80791a1fdb1..9bdbfb830fd 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -2184,12 +2184,20 @@ set_buffer_if_live (Lisp_Object buffer) } DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only, - Sbarf_if_buffer_read_only, 0, 0, 0, - doc: /* Signal a `buffer-read-only' error if the current buffer is read-only. */) - (void) + Sbarf_if_buffer_read_only, 0, 1, 0, + doc: /* Signal a `buffer-read-only' error if the current buffer is read-only. +If the text under POSITION (which defaults to point) has the +`inhibit-read-only' text property set, the error will not be raised. */) + (Lisp_Object pos) { + if (NILP (pos)) + XSETFASTINT (pos, PT); + else + CHECK_NUMBER (pos); + if (!NILP (BVAR (current_buffer, read_only)) - && NILP (Vinhibit_read_only)) + && NILP (Vinhibit_read_only) + && NILP (Fget_text_property (pos, Qinhibit_read_only, Qnil))) xsignal1 (Qbuffer_read_only, Fcurrent_buffer ()); return Qnil; } diff --git a/src/callint.c b/src/callint.c index 9a4573c77be..94676952b25 100644 --- a/src/callint.c +++ b/src/callint.c @@ -448,13 +448,13 @@ invoke it. If KEYS is omitted or nil, the return value of { if (! (*p == 'r' || *p == 'p' || *p == 'P' || *p == '\n')) - Fbarf_if_buffer_read_only (); + Fbarf_if_buffer_read_only (Qnil); p++; } record_then_fail = 1; } else - Fbarf_if_buffer_read_only (); + Fbarf_if_buffer_read_only (Qnil); } } /* Ignore this for semi-compatibility with Lucid. */ @@ -865,7 +865,7 @@ invoke it. If KEYS is omitted or nil, the return value of XSETINT (args[i], marker_position (args[i])); if (record_then_fail) - Fbarf_if_buffer_read_only (); + Fbarf_if_buffer_read_only (Qnil); Vthis_command = save_this_command; Vthis_original_command = save_this_original_command; diff --git a/src/fileio.c b/src/fileio.c index 7d7b0b3148f..b8dec3a2041 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3471,7 +3471,7 @@ by calling `format-decode', which see. */) error ("Cannot do file visiting in an indirect buffer"); if (!NILP (BVAR (current_buffer, read_only))) - Fbarf_if_buffer_read_only (); + Fbarf_if_buffer_read_only (Qnil); val = Qnil; p = Qnil; diff --git a/src/insdel.c b/src/insdel.c index 463392dcada..3133ca4bd2c 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -1797,9 +1797,11 @@ prepare_to_modify_buffer_1 (ptrdiff_t start, ptrdiff_t end, ptrdiff_t *preserve_ptr) { struct buffer *base_buffer; + Lisp_Object temp; + XSETFASTINT (temp, start); if (!NILP (BVAR (current_buffer, read_only))) - Fbarf_if_buffer_read_only (); + Fbarf_if_buffer_read_only (temp); bset_redisplay (current_buffer); diff --git a/src/intervals.h b/src/intervals.h index 4e7a177140e..bd1f49dc383 100644 --- a/src/intervals.h +++ b/src/intervals.h @@ -197,6 +197,7 @@ set_interval_plist (INTERVAL i, Lisp_Object plist) /* Is this interval writable? Replace later with cache access. */ #define INTERVAL_WRITABLE_P(i) \ (i && (NILP (textget ((i)->plist, Qread_only)) \ + || !NILP (textget ((i)->plist, Qinhibit_read_only)) \ || ((CONSP (Vinhibit_read_only) \ ? !NILP (Fmemq (textget ((i)->plist, Qread_only), \ Vinhibit_read_only)) \ diff --git a/src/textprop.c b/src/textprop.c index 91ade8ae298..7ecac62be98 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -2298,6 +2298,11 @@ verify_interval_modification (struct buffer *buf, } } + if (i->position + LENGTH (i) < end + && (!NILP (BVAR (current_buffer, read_only)) + && NILP (Vinhibit_read_only))) + xsignal1 (Qbuffer_read_only, Fcurrent_buffer ()); + i = next_interval (i); } /* Keep going thru the interval containing the char before END. */ |