aboutsummaryrefslogtreecommitdiffstats
path: root/twittperator/dump-msg.tw
blob: 7de3c348743eeb4de8722599e843cfbffa89f583 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Please write the below line into .vimperatorrc.
 * let g:twittperator_plugin_dump_msg = 1
 */


(function () {
  function objectToString (obj, head) {
    if (!head)
      head = '';

    let result = '';
    for (let [n, v] in Iterator(obj)) {
      if (v && typeof v === 'object') {
        result += head + n + ':\n' + objectToString(v, head + '  ');
      } else {
        result += head + n + ': ' + v + '\n';
      }
    }

    return result;
  }

  plugins.twittperator.ChirpUserStream.addListener(
    function onMsg (msg, raw) {
      liberator.log('\n' + objectToString(msg));
    }
  );
})();

// vim: sw=2 ts=2 et fdm=marker ft=javascript:
1 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
//
// _smooziee.js
//
// LICENSE: {{{
//   Copyright (c) 2009 snaka<snaka.gml@gmail.com>
//
//     distributable under the terms of an MIT-style license.
//     http://www.opensource.jp/licenses/mit-license.html
// }}}
//
// PLUGIN INFO: {{{
var PLUGIN_INFO =
<VimperatorPlugin>
  <name>smooziee</name>
  <description>At j,k key scrolling to be smooth.</description>
  <description lang="ja">j,kキーでのスクロールをスムースに</description>
  <minVersion>2.3pre</minVersion>
  <maxVersion>2.3</maxVersion>
  <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/_smooziee.js</updateURL>
  <author mail="snaka.gml@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/snaka72/">snaka</author>
  <license>MIT style license</license>
  <version>0.10.2</version>
  <detail><![CDATA[
    == Subject ==
    j,k key scrolling to be smoothly.

    == Global variables ==
    You can configure following variable as you like.
    :smooziee_scroll_amount: Scrolling amount(unit:px). Default value is 400px.
    :smooziee_interval: Scrolling interval(unit:ms). Default value is 20ms.

    === Excample ===
    Set scroll amount is 300px and interval is 10ms.
    >||
    let g:smooziee_scroll_amount="300"
    let g:smooziee_scroll_interval="10"
    ||<

    == API ==
    >||
    smooziee.smoothScrollBy(amount);
    ||<
    Example.
    >||
    :js liberator.plugins.smooziee.smoothScrollBy(600)
    :js liberator.plugins.smooziee.smoothScrollBy(-600)
    ||<

    == ToDo ==

  ]]></detail>

  <detail lang="ja"><![CDATA[
    == 概要 ==
    普段のj,kキーのスクロールをLDRizeライクにスムースにします

    == グローバル変数 ==
    以下の変数を.vimperatorrcなどで設定することで動作を調整することができます
    :smooziee_scroll_amount:
      1回にスクロールする幅です単位ピクセル)。デフォルトは"400"です
    :smooziee_interval:
      スクロール時のアニメーションのインターバルです単位ミリ秒)。
      "1"以上の値を設定しますデフォルトは"20"です
    === 設定例 ===
    スクロール量を300pxにインターバルを10msに設定します
    >||
    let g:smooziee_scroll_amount="300"
    let g:smooziee_scroll_interval="10"
    ||<

    == API ==
    他のキーにマップする場合やスクリプトから呼び出せるようAPIを用意してます
    >||
    smooziee.smoothScrollBy(amount);
    ||<
    amountにはスクロール量(ピクセル)を指定してください正の値で下方向へ負の値で上方向へスクロールします

    Example.
    >||
    :js liberator.plugins.smooziee.smoothScrollBy(600)
    :js liberator.plugins.smooziee.smoothScrollBy(-600)
    ||<

    == ToDo ==
    - 読み込みの順番によっては他のプラグインと競合する可能性があるのをなんとかしたい

  ]]></detail>
</VimperatorPlugin>;
// }}}

let self = liberator.plugins.smooziee = (function(){

  // Mappings  {{{
  mappings.addUserMap(
    [modes.NORMAL],
    ["j"],
    "Smooth scroll down",
    function(count){
      self.smoothScrollBy(getScrollAmount() * (count || 1));
    },
    {
      count: true
    }
  );
  mappings.addUserMap(
    [modes.NORMAL],
    ["k"],
    "Smooth scroll up",
    function(count){
      self.smoothScrollBy(getScrollAmount() * -(count || 1));
    },
    {
      count: true
    }
  );
  // }}}
  // PUBLIC {{{
  var PUBLICS = {
    smoothScrollBy: function(moment) {
      win = Buffer.findScrollableWindow();
      interval = window.eval(liberator.globalVariables.smooziee_scroll_interval || '20');
      destY = win.scrollY + moment;
      clearTimeout(next);
      smoothScroll(moment);
    }
  }

  // }}}
  // PRIVATE {{{
  var next;
  var destY;
  var win;
  var interval;

  function getScrollAmount() window.eval(liberator.globalVariables.smooziee_scroll_amount || '400');

  function smoothScroll(moment) {
    if (moment > 0)
      moment = Math.floor(moment / 2);
    else
      moment = Math.ceil(moment / 2);

    win.scrollBy(0, moment);

    if (Math.abs(moment) < 1) {
      setTimeout(makeScrollTo(win.scrollX, destY), interval);
      destY = null;
      return;
    }
    next = setTimeout(function() smoothScroll(moment), interval);
  }

  function makeScrollTo(x, y) function() win.scrollTo(x, y);
  // }}}
  return PUBLICS;
})();
// vim: sw=2 ts=2 et si fdm=marker: