(import ded/api) (import ded/api/internal) (use ./path) (defn buf/get `` Get the buffer with the given `:name` and/or `:path`, or nil if none exists. When both are given, only a buffer matching both is returned. (ded/buf/get :name "*scratch*") (ded/buf/get :path "~/my-notes.md") `` [&named name path] (unless (or name path) (error "expected :name or :path")) (internal/buf/get name path)) (defn buf/create `` Create a new buffer named `:name`. `:path` is the file it was loaded from, if any. Raises an error if a buffer with the same name already exists. (ded/buf/create :name "*notes*") `` [&named name path] (unless name (error "expected :name")) (internal/buf/create name path)) (defn buf/open `` Open the file at the expanded `path` and return its associated buffer. (See `ded/path/expand`) If a buffer with the same path already exists, it is returned, otherwise a new one is created with the file's contents. Raises if the file cannot be opened or read. `` [path] (def cwd (os/cwd)) # TODO: should get CWD from API (def path (path/abspath (path/expand path))) (def name (path/relpath cwd path)) (if-let [buf (internal/buf/get nil path)] buf (with [f (os/open path :r)] (def buf (internal/buf/create name path)) (forever (def chunk (ev/chunk f 65536)) (if (nil? chunk) (break)) (api/buf/write buf chunk)) buf)))