summaryrefslogtreecommitdiff
path: root/src/buffer.cc
diff options
context:
space:
mode:
authorFrank LENORMAND <lenormf@gmail.com>2016-07-20 20:45:50 +0300
committerFrank LENORMAND <lenormf@gmail.com>2016-07-23 10:03:21 +0300
commit8a4596bea9d85c86d03efa129c41530faa2a34a7 (patch)
tree8cd6a789c734e8507042fb5126cf692dd3ae789c /src/buffer.cc
parent88a9607552fd3c614e6d70a271b663323306a8db (diff)
Implement a `readonly` mode
This commit introduces the `readonly` variable as well as the `-ro` command line option which prevent buffers from being overwritten on disk when the `write` command is used without arguments. Some buffers can selectively be put in readonly mode by setting the `readonly` variable on the `buffer` scope, the `global` mode will affect all buffers (even those who will be open subsequently), using the `window` scope will have no effect. Closes #685
Diffstat (limited to 'src/buffer.cc')
-rw-r--r--src/buffer.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/buffer.cc b/src/buffer.cc
index 089103b1..f447f2db 100644
--- a/src/buffer.cc
+++ b/src/buffer.cc
@@ -591,6 +591,13 @@ void Buffer::set_fs_timestamp(timespec ts)
void Buffer::on_option_changed(const Option& option)
{
+ if (option.name() == "readonly")
+ {
+ if (option.get<bool>())
+ m_flags |= Flags::ReadOnly;
+ else
+ m_flags &= ~Flags::ReadOnly;
+ }
run_hook_in_own_context("BufSetOption",
format("{}={}", option.name(), option.get_as_string()));
}