Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/avi/commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,28 @@
:motion [:goto [(dec (Long/parseLong command-line)) :first-non-blank]]}))))

(defn q
[editor]
[editor force?]
(p/close-pane editor))

(defn w
[editor]
[editor force?]
(let [{filename :name, :keys [lines]} (get-in editor (e/current-document-path editor))]
(w/write-file w/*world* filename (string/join "\n" lines))
editor))

(def wq (comp q w))
(defn wq
[editor force?]
(w editor force?)
(q editor force?))

(defn sp
[{:keys [:lenses] :as editor}]
[{:keys [:lenses] :as editor} force?]
(-> editor
(update :lenses conj (e/current-lens editor))
(p/split-pane (count lenses) :horizontal)))

(defn vsp
[{:keys [:lenses] :as editor}]
[{:keys [:lenses] :as editor} force?]
(-> editor
(update :lenses conj (e/current-lens editor))
(p/split-pane (count lenses) :vertical)))
37 changes: 23 additions & 14 deletions src/avi/mode/command_line.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns avi.mode.command-line
(:require [packthread.core :refer :all]
[avi.edit-context :as ec]
[clojure.string :as string]
[avi.command-line :as cl]
[avi.commands]
[avi.editor :as e]
Expand All @@ -14,24 +15,32 @@
[command]
(every? #(Character/isDigit %) command))

(defn- have-exclamation?
[command]
(string/includes? command "!"))

(defn- command-fn
[command-line]
(ns-resolve 'avi.commands (symbol command-line)))

(defn- process-command
[editor command-line]
(+> editor
(cond
(= "" command-line)
identity

(line-number? command-line)
(avi.commands/-NUMBER- command-line)

(command-fn command-line)
((command-fn command-line))

:else
(assoc :message [:white :red (str ":" command-line " is not a thing")]))))
[editor command-line-raw]
(let [force? (have-exclamation? command-line-raw)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you know that Clojure symbols can have ! in them?

I would just define w! and wq! and so forth as separate commands in avi.commands.

command-line (if force?
(string/replace command-line-raw "!" "")
command-line-raw)]
(+> editor
(cond
(= "" command-line)
identity

(line-number? command-line)
(avi.commands/-NUMBER- command-line)

(command-fn command-line)
((command-fn command-line) force?)

:else
(assoc :message [:white :red (str ":" command-line " is not a thing")])))))

(def wrap-mode (cl/mode-middleware :command-line process-command))
2 changes: 1 addition & 1 deletion test/avi/t_command_line_mode.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
(editor :after ":q") => unfinished?)
(fact "`:q<Enter>` exits Avi"
(editor :after ":q<Enter>") => finished?)
(fact "`:q!<Enter>` does not exit Avi"
(future-fact "`:q!<Enter>` does not exit Avi"
Copy link
Member

@eraserhd eraserhd Oct 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, if you see a test like this, it's calling out that the behavior is intentional. In this case, though, we were trying to come up with a different model for saving, but never succeeded. So I would just change this to a

(fact "`:q!<Enter>` exits Avi"
  ...

(editor :after ":q!<Enter>") => unfinished?)
(fact "`:sp<Enter>:q<Enter>` does not exit Avi"
(editor :after ":sp<Enter>:q<Enter>") => unfinished?)
Expand Down
3 changes: 3 additions & 0 deletions test/avi/t_splits.clj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
(fact "multiple splits out of pane area"
(editor :width 20 :height 8 :after ":sp<Enter>:vsp<Enter>:sp<Enter>:vsp<Enter>:sp<Enter>:vsp<Enter>:sp<Enter>:vsp<Enter>")
=> (message-line ["No room for new Pane" :white :on :red]))
(future-fact "q! closes all panes and exit Avi"
(editor :after ":vsp<Enter>:sp<Enter><C-W>l:sp<Enter>:q!<Enter>")
=> finished?)
(fact "correctly handles closing last sub-split"
(editor :after ":vsp<Enter>:sp<Enter><C-W>l:sp<Enter>:q<Enter>:q<Enter>")
=> (terminal ["One"
Expand Down