google-search-results.js: also add binding for return
[conkeror.git] / modules / rc.js
bloba6de526b7953182e0e610e555411f97f5f35215d
2 function load_rc_file(file)
4     try {
5         var name;
6         if (typeof file == "string")
7             name = file;
8         else
9             name = file.path;
11         subscript_loader.loadSubScript("file://" + name, conkeror);
12     } catch (e) {
13         dump_error(e);
14     }
17 function load_rc_directory (file_o) {
18     var entries = file_o.directoryEntries;
19     var files = [];
20     while (entries.hasMoreElements ()) {
21         var entry = entries.getNext ();
22         entry.QueryInterface (Ci.nsIFile);
23         if (entry.leafName.match(/^[^.].*\.js$/i)) {
24             files.push(entry);
25         }
26     }
27     files.sort(function (a, b) {
28             if (a.leafName < b.leafName) {
29                 return -1;
30             } else if (a.leafName > b.leafName) {
31                 return 1;
32             } else {
33                 return 0;
34             }
35         });
36     for (var i = 0; i < files.length; i++) {
37         load_rc_file(files[i]);
38     }
43  * path_s: string path to load.  may be a file, a directory, or null.
44  *   if it is a file, that file will be loaded.  if it is a directory,
45  *   all `.js' files in that directory will be loaded.  if it is null,
46  *   the preference `conkeror.rcfile' will be read for the default.
47  */
48 function load_rc(path_s)
50     if (! path_s)
51     {
52         if (pref_has_user_value("conkeror.rcfile")) {
53             var rcfile = get_pref("conkeror.rcfile");
54             if (rcfile.length)
55                 path_s = rcfile;
56             else
57                 return;
58         } else {
59             return;
60         }
61     }
63     var file_o = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
64     file_o.initWithPath(path_s);
65     if (file_o.isDirectory()) {
66         load_rc_directory (file_o);
67     } else {
68         load_rc_file (path_s);
69     }
72 require_later("command-line.js");
74 call_after_load("command-line.js", function () {
75         command_line_param_handler("l", false, function (path) {
76                 try {
77                     load_rc (path);
78                 } catch (e) { dump_error(e);  }
79             });
80     });