~ubuntu-branches/ubuntu/wily/weechat-scripts/wily-proposed

« back to all changes in this revision

Viewing changes to ruby/url_hinter.rb

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bouthenot
  • Date: 2015-08-20 00:36:42 UTC
  • mfrom: (3.1.18)
  • Revision ID: package-import@ubuntu.com-20150820003642-lhacqk9a6xd8zau5
Tags: 20150820-1
* New upstream Git repository snapshot
* Update debian/copyright with new, updated and removed scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# coding: utf-8
1
2
#
2
3
# Copyright (c) 2014 Kengo Tateishi <embrace.ddd.flake.peace@gmail.com>
3
4
# https://github.com/tkengo/weechat-url-hinter
33
34
# Register url-hinter plugin to weechat and do initialization.
34
35
#
35
36
def weechat_init
36
 
  Weechat.register('url_hinter', 'Kengo Tateish', '0.1', 'GPL3', 'Open an url in the weechat buffer to type a hint', '', '')
 
37
  Weechat.register('url_hinter', 'Kengo Tateish', '0.2', 'GPL3', 'Open an url in the weechat buffer to type a hint', '', '')
37
38
  Weechat.hook_command(
38
39
    'url_hinter',
39
40
    'Search url strings, and highlight them, and if you type a hint key, open the url related to hint key.',
135
136
# Custome classes
136
137
#----------------------------
137
138
 
138
 
HINT_KEYS = 'jfhkgyuiopqwertnmzxcvblasd'
139
 
 
140
139
class Hint
141
140
  include Singleton
142
141
 
183
182
 
184
183
  private
185
184
 
 
185
  def get_hint_keys
 
186
        option = 'hintkeys'
 
187
    if Weechat.config_is_set_plugin(option) == 0
 
188
      Weechat.config_set_plugin(option, 'jfhkgyuiopqwertnmzxcvblasd')
 
189
    end
 
190
    Weechat.config_get_plugin(option)
 
191
  end
 
192
 
186
193
  def next_hint_key
187
 
    if @url_count > HINT_KEYS.length
188
 
      key1 = HINT_KEYS[@hint_key_index / HINT_KEYS.length]
189
 
      key2 = HINT_KEYS[@hint_key_index % HINT_KEYS.length]
 
194
    hint_keys = get_hint_keys()
 
195
    if @url_count > hint_keys.length
 
196
      key1 = hint_keys[@hint_key_index / hint_keys.length]
 
197
      key2 = hint_keys[@hint_key_index % hint_keys.length]
190
198
      hint_key = key1 + key2
191
199
    else
192
 
      hint_key = HINT_KEYS[@hint_key_index]
 
200
      hint_key = hint_keys[@hint_key_index]
193
201
    end
194
202
 
195
203
    @hint_key_index += 1