From 8a4596bea9d85c86d03efa129c41530faa2a34a7 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 20 Jul 2016 20:45:50 +0300 Subject: 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 --- src/buffer.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/buffer.cc') 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()) + m_flags |= Flags::ReadOnly; + else + m_flags &= ~Flags::ReadOnly; + } run_hook_in_own_context("BufSetOption", format("{}={}", option.name(), option.get_as_string())); } -- cgit v1.2.3