Changeset 24656

Show
Ignore:
Timestamp:
11/22/08 22:23:27 (7 weeks ago)
Author:
anekos
Message:

新しい completer に対応してみた。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/auto_source.js

    r24581 r24656  
    44// @description-ja 指定のファイルが変更されたら自動で :so する。 
    55// @license        Creative Commons 2.1 (Attribution + Share Alike) 
    6 // @version        1.0 
     6// @version        1.1 
    77// @author         anekos (anekos@snca.net) 
    8 // @minVersion     1.2 
     8// @minVersion     2.0pre 
    99// @maxVersion     2.0pre 
    1010// ==/VimperatorPlugin== 
     
    3232(function () { 
    3333 
    34   let files = {}; 
     34  let files = []; 
    3535  let firstTime = window.eval(liberator.globalVariables.auto_source_first_time || 'false'); 
    3636  let interval = window.eval(liberator.globalVariables.auto_source_interval || '500'); 
    3737 
    3838  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); 
    4040    file.initWithPath(filepath); 
    4141    return file.lastModifiedTime; 
    4242  } 
    4343 
     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 
    4450  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; 
    4753    let last = firstTime ? null : getFileModifiedTime(filepath); 
    48     files[filepath] = setInterval(function () { 
     54    let handle = setInterval(function () { 
    4955      let current = getFileModifiedTime(filepath); 
    5056      if (last != current) { 
     
    5460      } 
    5561    }, interval); 
     62    files.push({handle: handle, path: filepath}); 
    5663  } 
    5764 
    5865  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'); 
    6370  } 
    6471 
     
    7279      bang: true, 
    7380      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        } 
    7788      } 
    7889    },