Changeset 24656
- Timestamp:
- 11/22/08 22:23:27 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/auto_source.js
r24581 r24656 4 4 // @description-ja 指定のファイルが変更されたら自動で :so する。 5 5 // @license Creative Commons 2.1 (Attribution + Share Alike) 6 // @version 1. 06 // @version 1.1 7 7 // @author anekos (anekos@snca.net) 8 // @minVersion 1.28 // @minVersion 2.0pre 9 9 // @maxVersion 2.0pre 10 10 // ==/VimperatorPlugin== … … 32 32 (function () { 33 33 34 let files = {};34 let files = []; 35 35 let firstTime = window.eval(liberator.globalVariables.auto_source_first_time || 'false'); 36 36 let interval = window.eval(liberator.globalVariables.auto_source_interval || '500'); 37 37 38 38 function getFileModifiedTime (filepath) { 39 let file = Cc[ "@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);39 let file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile); 40 40 file.initWithPath(filepath); 41 41 return file.lastModifiedTime; 42 42 } 43 43 44 function exists (filepath) 45 files.some(function (it) (it.path.indexOf(filepath) === 0)) 46 47 function remove (filepath, func) 48 (files = files.filter(function (it) (it.path.indexOf(filepath) !== 0 && (func(it)+'-')))); 49 44 50 function startWatching (filepath) { 45 if ( files[filepath] !== undefined)46 throw "The file has already been watched: "+ filepath;51 if (exists(filepath)) 52 throw 'The file has already been watched: ' + filepath; 47 53 let last = firstTime ? null : getFileModifiedTime(filepath); 48 files[filepath]= setInterval(function () {54 let handle = setInterval(function () { 49 55 let current = getFileModifiedTime(filepath); 50 56 if (last != current) { … … 54 60 } 55 61 }, interval); 62 files.push({handle: handle, path: filepath}); 56 63 } 57 64 58 65 function killWatcher (filepath) { 59 if ( files[filepath] === undefined)60 throw "The file is not watched: "+ filepath;61 clearInterval(files[filepath]);62 delete files[filepath];66 if (!exists(filepath)) 67 throw 'The file is not watched: ' + filepath; 68 remove(filepath, function (it) clearInterval(it.handle)); 69 liberator.echo('stopped the watching for the file'); 63 70 } 64 71 … … 72 79 bang: true, 73 80 argCount: '1', 74 completer: function (arg, bang) { 75 return bang ? [0, [[filepath, ''] for (filepath in files)]] 76 : completion.file(arg); 81 completer: function (context, arg, bang) { 82 if (bang) { 83 context.title = ['Path']; 84 context.items = files.map(function (it) ([it.path])); 85 } else { 86 completion.file(context); 87 } 77 88 } 78 89 },
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)