Module: VER::Methods::Search

Included in:
VER::Methods
Defined in:
lib/ver/methods/search.rb

Constant Summary collapse

SEARCH_HIGHLIGHT =
{
  foreground: '#000',
  background: '#ff0',
}

Instance Method Summary collapse

Instance Method Details

#search_char_leftObject



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ver/methods/search.rb', line 70

def search_char_left
  status_ask 'Search char left: ', take: 1 do |char|
    from, to = 'insert', 'insert linestart'
    regexp = Regexp.new(Regexp.escape(char))

    rsearch_all regexp, from, to do |match, pos, mark|
      mark_set :insert, pos
      break
    end
  end
end

#search_char_rightObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ver/methods/search.rb', line 58

def search_char_right
  status_ask 'Search char right: ', take: 1 do |char|
    from, to = 'insert', 'insert lineend'
    regexp = Regexp.new(Regexp.escape(char))

    search_all regexp, from, to do |match, pos, mark|
      mark_set :insert, pos
      break
    end
  end
end

#search_nextObject



34
35
36
37
# File 'lib/ver/methods/search.rb', line 34

def search_next
  from, to = tag_nextrange('search', 'insert + 1 chars', 'end')
  mark_set(:insert, from) if from
end

#search_next_word_under_cursorObject



44
45
46
47
48
49
# File 'lib/ver/methods/search.rb', line 44

def search_next_word_under_cursor
  word = get('insert wordstart', 'insert wordend')
  return if word.squeeze == ' ' # we don't want to match space
  tag_all_matching(:search, word, SEARCH_HIGHLIGHT)
  search_next
end

#search_prevObject



39
40
41
42
# File 'lib/ver/methods/search.rb', line 39

def search_prev
  from, to = tag_prevrange('search', 'insert - 1 chars', '1.0')
  mark_set(:insert, from) if from
end

#search_prev_word_under_cursorObject



51
52
53
54
55
56
# File 'lib/ver/methods/search.rb', line 51

def search_prev_word_under_cursor
  word = get('insert wordstart', 'insert wordend')
  return if word.squeeze == ' ' # we don't want to match space
  tag_all_matching(:search, word, SEARCH_HIGHLIGHT)
  search_prev
end

#status_search_common(question) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ver/methods/search.rb', line 21

def status_search_common(question)
  status_ask question do |term|
    begin
      needle = Regexp.new(term)
    rescue RegexpError
      needle = Regexp.escape(term)
    end

    tag_all_matching(:search, needle, SEARCH_HIGHLIGHT)
    yield
  end
end

#status_search_nextObject



9
10
11
12
13
# File 'lib/ver/methods/search.rb', line 9

def status_search_next
  status_search_common('/') do
    search_next
  end
end

#status_search_prevObject



15
16
17
18
19
# File 'lib/ver/methods/search.rb', line 15

def status_search_prev
  status_search_common('?') do
    search_prev
  end
end