micro-editor / micro-editor/micro

help - Print/write the absolute filepath while into CommandBar

Open
#2,183 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
29.6k
Forks
1.4k
Avg merge
2d 18h
Merged PRs (30d)
10

Description

Specifications

MICRO: Version: 2.0.9
Commit hash: 6bc498e6
Compiled on May 16, 2021

Description of the problem:

Hi. I am new in Micro (so as in Lua and Go) and I am struggling trying to do a simple thing:
Print/write the absolute path of the current file (cur pane) after the cursor in the CommandBar without, somehow, the use of the clipboard.

Into lua.init, one would think of:

function curName(bp)
  local bn = bp.Buf.AbsPath
  micro.InfoBar():Message(bn)
end

But, it doesn't write the absolute path of the file AFTER I HAD TYPED STUFF in the CommandBar and waits until I type more stuff and execute. It writes it as info, though.

I would like to bind Ctrl-p for the job. So after I had entered in the CommandBar, like "> open ", "$ less -SN " or "$ okular ", I would enter this key to write the absolute path of the file then completing the command.

There was a discussion about changing cwd to the file (#785), but it's not actually what I wished to do. I just wished to pick up the filename.

Also in #1993 it was discussed about enumerating the buffers. Each one of them would be sent to the log buffer. Although, again, it's not (but close to) what I was trying to do.
So I tried something similar into lua.init:

function curName(bp)
  local bn = bp.Buf.AbsPath
  local ib = buffer.InfoBar
  fmt.Fprintf(ib, "%s", bn)   // fmt imported in the file beginning.
end

But I got this error:

Micro encountered an error: runtime.errorString runtime error: invalid memory address or nil pointer dereference

Then, I tried:

function curName(bp)
  local bn = bp.Buf.AbsPath
  fmt.Printf("%s", bn)
end

But, sort of a weird ghost string with the path appeard only temporarily. If I went down with the Cursor it would disappear. Besides, it didn't work in the CommandBar. So I changed my bindings.json to run this key under the "command" subgroup. But nothing. It didn't print things anymore.


Apart from the attempt above, I also saw something into the action pkg that could work:

func CommandEditAction(prompt string) BufKeyAction {
  return func(h *BufPane) bool {
	  InfoBar.Prompt("> ", prompt, "Command", nil, func(resp string, canceled bool) {
		  if !canceled {
			  MainTab().CurPane().HandleCommand(resp)
		  }
	  })
	  return false
  }
}

So I tried swapping that 3rd line from function curName:

function curName(bp)
  local bn = bp.Buf.AbsPath
  micro.InfoBar():Prompt("", bn, "Command", nil, func(resp, canceled))
end

And guess what:

Lua API error: init:76: attempt to call a non-function object

In another hand:

function curName(bp)
  local bn = bp.Buf.AbsPath
  local action = import("micro/action")
  action.CommandEditAction(bn)
end

Quits the whole console.

So, yeah. Idk how to use that, I guess.


So any help writing/printing that absolute filename after the cursor in the CommandBar without using the clipboard would be very appreciated.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the action package's CommandEditAction entry point and the InfoBar.Prompt usage described in the issue, then trace how command-bar key bindings reach the Lua API. Done means a documented or tested way to insert the current buffer's absolute path at the command-bar cursor without using the clipboard.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, lua
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.