1 # Copyright 2010 Wincent Colaiuta. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are met:
6 # 1. Redistributions of source code must retain the above copyright notice,
7 # this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright notice,
9 # this list of conditions and the following disclaimer in the documentation
10 # and/or other materials provided with the distribution.
12 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22 # POSSIBILITY OF SUCH DAMAGE.
25 # Abuse the status line as a prompt.
30 @abbrev = '' # abbreviation entered so far
31 @col = 0 # cursor position
35 # Erase whatever is displayed in the prompt line,
36 # effectively disposing of the prompt
39 ::VIM::command 'redraw'
42 # Clear any entered text.
49 # Insert a character at (before) the current cursor position.
51 left
, cursor
, right
= abbrev_segments
52 @abbrev = left + char + cursor + right
57 # Delete a character to the left of the current cursor position.
60 left
, cursor
, right
= abbrev_segments
61 @abbrev = left
.chop! + cursor + right
67 # Delete a character at the current cursor position.
69 if @col < @abbrev.length
70 left
, cursor
, right
= abbrev_segments
71 @abbrev = left + right
84 if @col < @abbrev.length
91 if @col < @abbrev.length
106 prompt_highlight
= 'Comment'
107 normal_highlight
= 'None'
108 cursor_highlight
= 'Underlined'
110 prompt_highlight
= 'NonText'
111 normal_highlight
= 'NonText'
112 cursor_highlight
= 'NonText'
114 left
, cursor
, right
= abbrev_segments
115 components
= [prompt_highlight
, '>>', 'None', ' ']
116 components +
= [normal_highlight
, left
] unless left
.empty
?
117 components +
= [cursor_highlight
, cursor
] unless cursor
.empty
?
118 components +
= [normal_highlight
, right
] unless right
.empty
?
119 components +
= [cursor_highlight
, ' '] if cursor
.empty
?
120 set_status
*components
139 # Returns the @abbrev string divided up into three sections, any of
140 # which may actually be zero width, depending on the location of the
142 # - left segment (to left of cursor)
143 # - cursor segment (character at cursor)
144 # - right segment (to right of cursor)
146 left
= @abbrev[0, @col]
147 cursor
= @abbrev[@col, 1]
148 right
= @abbrev[(@col +
1)..-1] || ''
149 [left
, cursor
, right
]
153 # see ':help :echo' for why forcing a redraw here helps
154 # prevent the status line from getting inadvertantly cleared
155 # after our echo commands
156 ::VIM::command 'redraw'
157 while (highlight
= args
.shift
) and (text
= args
.shift
) do
158 text
= VIM
::escape_for_single_quotes text
159 ::VIM::command "echohl #{highlight}"
160 ::VIM::command "echon '#{text}'"
162 ::VIM::command 'echohl None'
165 end # module CommandT