Skip to content

Commit

Permalink
Add :view and :sview ex commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdl89 committed Jun 17, 2024
1 parent 18962ce commit fb95066
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 20 additions & 3 deletions evil-commands.el
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fb95066

Please sign in to comment.