2 define_user_variable("editor_shell_command", getenv("EDITOR") || "emacs",
3 "Shell command used to invoke an external editor.\n" +
4 "This defaults to the value of the EDITOR environment variable. If " +
5 "`run_external_editor_function' is non-null, it is used instead to " +
6 "invoke an external editor and the value of this variable is ignored." +
7 "It is used as part of a shell command in the following two ways:\n" +
8 "<editor_shell_command> <file>\n" +
9 "<editor_shell_command> +<line> <file>");
12 define_user_variable("run_external_editor_function", null,
13 "Coroutine function called to invoke an external editor.\n" +
14 "If this variable is set to a function, it is used to invoke an external editor in place of `editor_shell_command'. It is called with the filename as the first argument, and optionally the boolean keyword argument $temporary specifying whether the file should be deleted after the editor is closed, and optionally the keyword argument $line specifying a line number to display. The `create_external_editor_launcher' function may be convenient for generating a function suitable for use as the value of this variable.");
16 define_keyword("$temporary", "$line");
17 function open_file_with_external_editor(file) {
20 if (run_external_editor_function) {
21 yield run_external_editor_function(file, forward_keywords(arguments));
25 var line = arguments.$line;
27 var cmd = editor_shell_command + " ";
29 cmd += "+" + line + " ";
30 cmd += "\"" + shell_quote(file.path) + "\"";
33 yield shell_command(default_directory.path, cmd);
35 if (arguments.$temporary) {
37 file.remove(false /* not recursive */);
43 function create_external_editor_launcher(program, args) {
44 return function (file) {
46 var arr = args.slice();
47 if (arguments.$line != null)
48 arr.push("+" + arguments.$line);
51 yield spawn_process(program, arr);
53 if (arguments.$temporary) {
62 function open_with_external_editor(load_spec) {
64 let [file, temp] = yield download_as_temporary(load_spec);
65 yield open_file_with_external_editor(file, $line = arguments.$line, $temporary = temp);