//go:build !windows && !plan9

package editor

import (
	
	
	
	
)

// ErrStart indicates that the command to start the editor failed.
var ErrStart = errors.New("failed to start editor")

// EditBuffer starts the system editor and opens the given buffer in it.
// If the filename is specified, the file will be created in the system
// temp directory under this name.
// If the filetype is not empty and if the system editor supports it, the
// file will be opened with the specified filetype passed to the editor.
func ( *Buffers) ( []rune, ,  string,  bool) ([]rune, error) {
	,  := writeToFile([]byte(string()), )
	if  != nil {
		return , 
	}

	 := getSystemEditor()

	 := []string{}
	if  != "" {
		 = append(, fmt.Sprintf("-c 'set filetype=%s", ))
	}

	 = append(, )

	 := exec.Command(, ...)

	.Stdin = os.Stdin
	.Stdout = os.Stdout
	.Stderr = os.Stderr

	if  = .Start();  != nil {
		return , fmt.Errorf("%w: %s", ErrStart, .Error())
	}

	if  = .Wait();  != nil {
		return , fmt.Errorf("%w: %s", ErrStart, .Error())
	}

	,  := readTempFile()

	return []rune(string()), 
}