Skip to content

Commit

Permalink
Changes to edit command as requested in Pull Request
Browse files Browse the repository at this point in the history
  • Loading branch information
hupfdule committed Apr 20, 2019
1 parent b940ff7 commit 15cce6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ create_skeleton_plugconf = true
# installed, it tries to execute "git clone" or "git pull" as a fallback
# * false: "volt get" or "volt get -u" won't try to execute fallback commands
fallback_git_cmd = true

[edit]
# If you ever wanted to use emacs to edit your vim plugin config, you can
# do so with the following. If not specified, volt will try to use
# vim/nvim, $VISUAL, sensible-editor, or $EDITOR in this order until a usable
# one is found.
editor = emacs
```

## Features
Expand Down
31 changes: 17 additions & 14 deletions subcmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (cmd *editCmd) Run(args []string) *Error {

hasChanges, err := cmd.doEdit(reposPathList)
if err != nil {
//FIXME: Which error code to use?
return &Error{Code: 15, Msg: "Failed to edit plugconf file: " + err.Error()}
}

Expand Down Expand Up @@ -91,15 +90,12 @@ func (cmd *editCmd) doEdit(reposPathList []pathutil.ReposPath) (bool, error) {
return false, errors.New("could not read config.toml: " + err.Error())
}

viitor, err := cmd.identifyEditor(cfg)
if err != nil || viitor == "" {
//FIXME: Which error code to use?
return false, &Error{Code: 30, Msg: "No usable viitor found"}
editor, err := cmd.identifyEditor(cfg)
if err != nil || editor == "" {
return false, &Error{Code: 30, Msg: "No usable editor found"}
}

changeWasMade := false
//FIXME: Run single vim instance? Leads to problems if the configured
//editor does not support to open multiple files
for _, reposPath := range reposPathList {

// Edit plugconf file
Expand All @@ -120,10 +116,10 @@ func (cmd *editCmd) doEdit(reposPathList []pathutil.ReposPath) (bool, error) {
mTimeBefore := info.ModTime()

// Call the editor with the plugconf file
vimCmd := exec.Command(viitor, plugconfPath)
vimCmd.Stdin = os.Stdin
vimCmd.Stdout = os.Stdout
if err = vimCmd.Run(); err != nil {
editorCmd := exec.Command(editor, plugconfPath)
editorCmd.Stdin = os.Stdin
editorCmd.Stdout = os.Stdout
if err = editorCmd.Run(); err != nil {
//FIXME: Don't abort immediately, but try to edit remaining files?
return false, err
}
Expand Down Expand Up @@ -179,7 +175,7 @@ func (cmd *editCmd) parseArgs(args []string) (pathutil.ReposPathList, error) {
}

func (cmd *editCmd) identifyEditor(cfg *config.Config) (string, error) {
var editors []string
editors := make([]string, 4, 6)

// if an editor is specified as commandline argument, consider it
// as alternative
Expand All @@ -193,8 +189,15 @@ func (cmd *editCmd) identifyEditor(cfg *config.Config) (string, error) {
editors = append(editors, cfg.Edit.Editor)
}

vimExecutable, err := pathutil.VimExecutable()
if err != nil {
logger.Debug("No vim executable found in $PATH")
} else {
editors = append(vimExecutable)
}

// specifiy a fixed list of other alternatives
editors = append(editors, "$VISUAL", "nvim", "vim", "sensible-editor", "$EDITOR")
editors = append(editors, "$VISUAL", "sensible-editor", "$EDITOR")

for _, editor := range editors {
// resolve content of environment variables
Expand All @@ -207,7 +210,7 @@ func (cmd *editCmd) identifyEditor(cfg *config.Config) (string, error) {

path, err := exec.LookPath(editorName)
if err != nil {
logger.Debug(editor + " not found in $PATH")
logger.Debug(editorName + " not found in $PATH")
} else if path != "" {
logger.Debug("Using " + path + " as editor")
return editorName, nil
Expand Down

0 comments on commit 15cce6d

Please sign in to comment.