branch: elpa/evil
commit afb3788d69db9f4c13d0ee8e1d0c85807a0676d8
Author: Tom Dalziel <tom...@hotmail.com>
Commit: Tom Dalziel <33435574+tomd...@users.noreply.github.com>

    Add :view and :sview ex commands
---
 evil-commands.el | 23 ++++++++++++++++++++---
 evil-maps.el     |  2 ++
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 6e2849f38b..3fd984f12d 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -3334,7 +3334,18 @@ If no FILE is specified, reload the current buffer from 
disk."
   (interactive "<f><!>")
   (if file
       (find-file file)
-    (revert-buffer bang (or bang (not (buffer-modified-p))) t)))
+    (revert-buffer bang (or bang (not (buffer-modified-p))) t)
+    (read-only-mode -1)))
+
+(evil-define-command evil-view (file &optional bang)
+  "Open FILE but don't allow changes.
+If no FILE is specified, reload the current buffer from disk as read-only."
+  :repeat nil
+  (interactive "<f><!>")
+  (if file
+      (find-file-read-only file)
+    (revert-buffer bang (or bang (not (buffer-modified-p))) t)
+    (read-only-mode +1)))
 
 (evil-define-command evil-read (count file)
   "Insert the contents of FILE below the current line or line COUNT."
@@ -4517,7 +4528,7 @@ the deleted window's parent window are rebalanced."
         ;; any further children (then rebalancing is not necessary anyway)
         (ignore-errors (balance-windows p))))))
 
-(evil-define-command evil-window-split (&optional count file)
+(evil-define-command evil-window-split (&optional count file read-only)
   "Split the current window horizontally, COUNT lines height,
 editing a certain FILE. The new window will be created below
 when `evil-split-window-below' is non-nil. If COUNT and
@@ -4531,7 +4542,13 @@ of the parent of the splitted window are rebalanced."
   (when (and (not count) evil-auto-balance-windows)
     (balance-windows (window-parent)))
   (when file
-    (evil-edit file)))
+    (funcall (if read-only #'evil-view #'evil-edit) file)))
+
+(evil-define-command evil-window-split-view (&optional count file)
+  "As with `evil-window-split' but the file is opened read-only."
+  :repeat nil
+  (interactive "<c><f>")
+  (evil-window-split count file t))
 
 (evil-define-command evil-window-vsplit (&optional count file)
   "Split the current window vertically, COUNT columns width,
diff --git a/evil-maps.el b/evil-maps.el
index 4b81472158..0dfa85dd47 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -508,6 +508,7 @@ included in `evil-insert-state-bindings' by default."
 (define-key evil-motion-state-map "!" 'evil-shell-command)
 
 (evil-ex-define-cmd "e[dit]" 'evil-edit)
+(evil-ex-define-cmd "vie[w]" 'evil-view)
 (evil-ex-define-cmd "w[rite]" 'evil-write)
 (evil-ex-define-cmd "up[date]" 'evil-update)
 (evil-ex-define-cmd "wa[ll]" 'evil-write-all)
@@ -538,6 +539,7 @@ included in `evil-insert-state-bindings' by default."
 (evil-ex-define-cmd "ri[ght]" 'evil-align-right)
 (evil-ex-define-cmd "ce[nter]" 'evil-align-center)
 (evil-ex-define-cmd "sp[lit]" 'evil-window-split)
+(evil-ex-define-cmd "sv[iew]" 'evil-window-split-view)
 (evil-ex-define-cmd "vs[plit]" 'evil-window-vsplit)
 (evil-ex-define-cmd "new" 'evil-window-new)
 (evil-ex-define-cmd "ene[w]" 'evil-buffer-new)

Reply via email to