Changeset 20875

Show
Ignore:
Timestamp:
10/07/08 07:43:44 (6 weeks ago)
Author:
anekos
Message:

・どこに開くかを指定できるようにした
・lopen の仕様をちょっと変更

Files:
1 modified

Legend:

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

    r20201 r20875  
    44// @description-ja リンクをフィルタリングして開く 
    55// @license        Creative Commons 2.1 (Attribution + Share Alike) 
    6 // @version        1.0 
     6// @version        1.1 
    77// ==/VimperatorPlugin== 
    88// 
    99// Usage: 
    10 //    :fopen <REGEXP> [-i <INTERVAL_SEC>] 
     10//    :fo[pen][!] <REGEXP> [-i <INTERVAL_SEC>] 
    1111//      Open filtered links by regexp. 
     12//      When used "!", open links in foreground. 
    1213// 
    13 //    :lo[pen] URI 
     14//    :lo[pen][!] URI 
    1415//      Open URI 
    1516// 
    1617// Usage-ja: 
    17 //    :fo[pen] <ミゲ文字列> [-i <INTERVAL_SEC>] 
    18 //    :fo[pen] /<正規表現> [-i <INTERVAL_SEC>] 
     18//    :fo[pen][!] <ミゲ文字列> [-i <INTERVAL_SEC>] 
     19//    :fo[pen][!] /<正規表現> [-i <INTERVAL_SEC>] 
    1920//      ミゲ文字列か正規表現でフィルタされたリンクを開く 
    2021// 
    21 //    :lo[pen] URI 
     22//    :lo[pen][!] URI 
    2223//      URI を開く 
    2324// 
     
    2728// Variables: 
    2829//    let g:fopen_default_interval="<INTERVAL_SEC>" 
     30// 
     31// Notice: 
     32//    "--where" option's implementation has not been completed yet. 
    2933 
    3034 
     
    5862  } 
    5963 
     64  function charToWhere (str, fail) { 
     65    const table = { 
     66      f: NEW_TAB, 
     67      t: NEW_TAB, 
     68      b: NEW_BACKGROUND_TAB, 
     69      c: CURRENT_TAB, 
     70      w: NEW_WINDOW, 
     71    }; 
     72    return (str && table[str.charAt(0).toLowerCase()]) || fail; 
     73  } 
     74 
    6075  let foihandle; 
    6176 
     
    6378    ['fo[pen]', 'filteropen'], 
    6479    'Filtered open', 
    65     function (opts) { 
     80    function (opts, bang) { 
     81      let where = charToWhere(opts['-where'], bang ? NEW_TAB : NEW_BACKGROUND_TAB); 
    6682      let [i, links] = [1, filteredLinks(opts.arguments.join(''))]; 
    6783      if (!links.length) 
    6884        return; 
    69       open(links[0].href, NEW_BACKGROUND_TAB); 
     85      open(links[0].href, where); 
    7086      if (links.length <= 1) 
    7187        return; 
     
    7389      foihandle = setInterval(function () { 
    7490        try { 
    75           open(links[i].href, NEW_BACKGROUND_TAB); 
     91          open(links[i].href, where); 
    7692          if ((++i) >= links.length) 
    7793            clearInterval(foihandle); 
     
    84100      options: [ 
    85101        [['-interval', '-i'], liberator.commands.OPTIONS_INT], 
     102        [['-where', '-w'], liberator.commands.OPTIONS_STRING], 
    86103      ], 
    87104      completer: function (word) { 
     
    93110 
    94111  liberator.commands.addUserCommand( 
    95     ['stopfilteropen'], 
     112    ['stopfilteropen', 'stopfo[pen]'], 
    96113    'Stop filtered open', 
    97114    function () { 
     
    101118 
    102119  let lolinks = []; 
     120  let looptions = [ [['-where', '-w'], liberator.commands.OPTIONS_STRING], ]; 
    103121 
    104122  liberator.commands.addUserCommand( 
    105123    ['lo[pen]', 'linkopen'], 
    106124    'Filtered open', 
    107     function (uri) { 
     125    function (opts, bang) { 
     126      let where = charToWhere(opts['-where'], bang ? NEW_TAB : CURRENT_TAB); 
     127      let uri = opts.arguments[0]; 
    108128      for each (let link in lolinks) { 
    109129        if (~link.href.indexOf(uri)) 
    110           return liberator.buffer.followLink(link); 
     130          return liberator.buffer.followLink(link, where); 
    111131      } 
    112132      if (lolinks[0]) { 
    113         liberator.buffer.followLink(lolinks[0]); 
     133        liberator.buffer.followLink(lolinks[0], where); 
    114134      } else { 
    115135        liberator.echoerr('lol') 
     
    117137    }, 
    118138    { 
     139      options: looptions; 
    119140      completer: function (word) { 
    120         lolinks = filteredLinks(word); 
     141        let opts = liberator.parseArgs(word, looptions, "1", true); 
     142        log(opts); 
     143        lolinks = filteredLinks(word);//word.match(/\bhttp[^\s]+/)); 
    121144        return [0, [[it.href, it.textContent] for each (it in lolinks)]]; 
    122145      }