browser-next-form-field: skip non-visible elements
[conkeror.git] / modules / external-editor.js
blobe463fe4cce53a386719fb97566e85fb9b17367a2
1 /**
2  * (C) Copyright 2008 Jeremy Maitin-Shepard
3  *
4  * Use, modification, and distribution are subject to the terms specified in the
5  * COPYING file.
6 **/
8 define_variable("editor_shell_command", getenv("VISUAL") || getenv("EDITOR") || "emacs",
9                      "Shell command used to invoke an external editor.\n" +
10                      "This defaults to the value of the EDITOR environment variable.  If " +
11                      "`run_external_editor_function' is non-null, it is used instead to " +
12                      "invoke an external editor and the value of this variable is ignored." +
13                      "It is used as part of a shell command in the following two ways:\n" +
14                      "<editor_shell_command> <file>\n" +
15                      "<editor_shell_command> +<line> <file>");
18 define_variable("run_external_editor_function", null,
19                      "Coroutine function called to invoke an external editor.\n" +
20                      "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.");
22 define_keyword("$temporary", "$line");
23 function open_file_with_external_editor(file) {
24     keywords(arguments);
26     if (run_external_editor_function) {
27         yield run_external_editor_function(file, forward_keywords(arguments));
28         return;
29     }
31     var line = arguments.$line;
33     var cmd = editor_shell_command + " ";
34     if (line != null)
35         cmd += "+" + line + " ";
36     cmd += "\"" + shell_quote(file.path) + "\"";
38     try {
39         yield shell_command(cmd);
40     } finally {
41         if (arguments.$temporary)  {
42             try {
43                 file.remove(false /* not recursive */);
44             } catch (e) {}
45         }
46     }
49 function create_external_editor_launcher(program, args) {
50     return function (file) {
51         keywords(arguments);
52         var arr = [null].concat(args.slice());
53         if (arguments.$line != null)
54             arr.push("+" + arguments.$line);
55         arr.push(file.path);
56         try {
57             yield spawn_and_wait_for_process(program, arr);
58         } finally {
59             if (arguments.$temporary) {
60                 try {
61                     file.remove(false);
62                 } catch (e) {}
63             }
64         }
65     };
68 function open_with_external_editor(lspec) {
69     keywords(arguments);
70     let [file, temp] = yield download_as_temporary(lspec);
71     yield open_file_with_external_editor(file, $line = arguments.$line, $temporary = temp);