-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
base: master
Are you sure you want to change the base?
Conversation
Hello maintainers, apart from actual code submitted, do you think the idea is worth pursuing? |
There was a problem hiding this 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.
func IsQuoteOrBraceStart(r rune) bool { | ||
return r == '"' || r == '\'' || r == '(' || r == '[' || r == '{' | ||
} |
There was a problem hiding this comment.
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
.
// Allow completion of paths inside quotes and braces | ||
path_start := strings.LastIndexFunc(input, IsQuoteOrBraceStart) + 1 |
There was a problem hiding this comment.
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.
// 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) | ||
} |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
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.