Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocompletion of file paths in editor. #3586

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bwiklak
Copy link

@bwiklak bwiklak commented Dec 24, 2024

Change:
Add file completion as a default autocomplete option in edit mode (beside buffer complete).

Rationale:
Simple text editor like micro is great for editing bash scripts and config files. In such scenarios file path completion is very handy. Micro already has code for file completion but only in command mode.

@bwiklak
Copy link
Author

bwiklak commented Jan 8, 2025

Hello maintainers, apart from actual code submitted, do you think the idea is worth pursuing?

Copy link
Contributor

@niten94 niten94 left a comment

Choose a reason for hiding this comment

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

I do not know what the maintainers would think, but I think completing paths when editing files could be useful in some cases. I have commented only on parts that I somewhat know.

Comment on lines +113 to +115
func IsQuoteOrBraceStart(r rune) bool {
return r == '"' || r == '\'' || r == '(' || r == '[' || r == '{'
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Functions like this are placed in internal/util/util.go.

Comment on lines +121 to +122
// Allow completion of paths inside quotes and braces
path_start := strings.LastIndexFunc(input, IsQuoteOrBraceStart) + 1
Copy link
Contributor

Choose a reason for hiding this comment

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

I think supporting this is good, but it is unrelated with just adding a way to complete paths in editing. It would probably be better to do this change in another commit or mention in the commit description.

Comment on lines +104 to +111
// Complete filenames or buffer words
func Complete(b *Buffer) ([]string, []string) {
completions, suggestions := FileComplete(b)
if len(completions) != 0 || len(suggestions) != 0 {
return completions, suggestions
}
return BufferComplete(b)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be better to support completing paths using a different action (like CommandComplete?), then change the default binding of Tab to AutoComplete|FileComplete (Always trying to complete paths first somehow does not seem nice). It would be possible to change the order or remove one action if someone wanted to.

package buffer

import (
"io/ioutil"
Copy link
Contributor

Choose a reason for hiding this comment

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

io/ioutil is deprecated. It is still used in other parts of code in micro but there is an open pull request switching to other functions.

files := []string{"file1.txt", "file2.txt"}

for _, subdir := range subdirs {
if err := os.Mkdir(dir+string(os.PathSeparator)+subdir, 0755); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use path/filepath.Join?
Please use gofmt with modified files too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants