MCPcopy
hub / github.com/micro-editor/micro / OpenCmd

Method OpenCmd

internal/action/command.go:291–321  ·  view source on GitHub ↗

OpenCmd opens a new buffer with a given filename

(args []string)

Source from the content-addressed store, hash-verified

289
290// OpenCmd opens a new buffer with a given filename
291func (h *BufPane) OpenCmd(args []string) {
292 if len(args) > 0 {
293 filename := args[0]
294 // the filename might or might not be quoted, so unquote first then join the strings.
295 args, err := shellquote.Split(filename)
296 if err != nil {
297 InfoBar.Error("Error parsing args ", err)
298 return
299 }
300 if len(args) == 0 {
301 return
302 }
303 filename = strings.Join(args, " ")
304
305 open := func() {
306 b, err := buffer.NewBufferFromFile(filename, buffer.BTDefault)
307 if err != nil {
308 InfoBar.Error(err)
309 return
310 }
311 h.OpenBuffer(b)
312 }
313 if h.Buf.Modified() && !h.Buf.Shared() {
314 h.closePrompt("Save", open)
315 } else {
316 open()
317 }
318 } else {
319 InfoBar.Error("No filename")
320 }
321}
322
323// ToggleLogCmd toggles the log view
324func (h *BufPane) ToggleLogCmd(args []string) {

Callers

nothing calls this directly

Calls 7

OpenBufferMethod · 0.95
closePromptMethod · 0.95
NewBufferFromFileFunction · 0.92
JoinMethod · 0.80
ModifiedMethod · 0.80
SharedMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected