Debian packaging: Override Lintian warnings vcs-field-uses-insecure-uri
[conkeror.git] / modules / external-editor.js
blobeceb7ddc367b042797588cb064c22919d3f0b33c
1 /**
2 * (C) Copyright 2008 Jeremy Maitin-Shepard
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 "+
21 "an external editor in place of `editor_shell_command'. It "+
22 "is called with the filename as the first argument, and "+
23 "optionally the boolean keyword argument $temporary specifying "+
24 "whether the file should be deleted after the editor is closed, "+
25 "and optionally the keyword argument $line specifying a line "+
26 "number to display. The `create_external_editor_launcher' "+
27 "function may be convenient for generating a function suitable "+
28 "for use as the value of this variable.");
30 define_keyword("$temporary", "$line");
31 function open_file_with_external_editor (file) {
32 keywords(arguments);
34 if (run_external_editor_function) {
35 yield run_external_editor_function(file, forward_keywords(arguments));
36 return;
39 var line = arguments.$line;
41 var cmd = editor_shell_command + " ";
42 if (line != null)
43 cmd += "+" + line + " ";
44 cmd += "\"" + shell_quote(file.path) + "\"";
46 try {
47 yield shell_command(cmd);
48 } finally {
49 if (arguments.$temporary) {
50 try {
51 file.remove(false /* not recursive */);
52 } catch (e) {}
57 function create_external_editor_launcher (program, args) {
58 return function (file) {
59 keywords(arguments);
60 var arr = [null].concat(args.slice());
61 if (arguments.$line != null)
62 arr.push("+" + arguments.$line);
63 arr.push(file.path);
64 try {
65 yield spawn_and_wait_for_process(program, arr);
66 } finally {
67 if (arguments.$temporary) {
68 try {
69 file.remove(false);
70 } catch (e) {}
76 function open_with_external_editor (lspec) {
77 keywords(arguments);
78 let [file, temp] = yield download_as_temporary(lspec);
79 yield open_file_with_external_editor(file, $line = arguments.$line, $temporary = temp);
82 provide("external-editor");