ver 2009.10.14 → 2009.11.28
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1094 -0
- data/MANIFEST +227 -25
- data/README.textile +185 -0
- data/bin/ver +96 -12
- data/config/detect.rb +73 -21
- data/config/keymap/emacs.rb +66 -0
- data/config/keymap/vim.rb +250 -140
- data/config/preferences/ANTLR.json +10 -0
- data/config/preferences/ASP vb.NET.json +3 -0
- data/config/preferences/ASP.json +15 -0
- data/config/preferences/ActionScript.json +755 -0
- data/config/preferences/Active4D.json +89 -0
- data/config/preferences/Ada.json +23 -0
- data/config/preferences/Ant.json +356 -0
- data/config/preferences/Apache.json +644 -0
- data/config/preferences/AppleScript.json +92 -0
- data/config/preferences/Bison.json +3 -0
- data/config/preferences/Blogging.json +3 -0
- data/config/preferences/C.json +127 -0
- data/config/preferences/CMake.json +41 -0
- data/config/preferences/CSS.json +461 -0
- data/config/preferences/CTags.json +3 -0
- data/config/preferences/CVS.json +3 -0
- data/config/preferences/ColdFusion.json +32 -0
- data/config/preferences/D.json +58 -0
- data/config/preferences/Darcs.json +3 -0
- data/config/preferences/Diff.json +67 -0
- data/config/preferences/DokuWiki.json +19 -0
- data/config/preferences/Doxygen.json +3 -0
- data/config/preferences/Dylan.json +3 -0
- data/config/preferences/Eiffel.json +59 -0
- data/config/preferences/Erlang.json +72 -0
- data/config/preferences/Experimental.json +1356 -0
- data/config/preferences/F-Script.json +87 -0
- data/config/preferences/FXScript.json +78 -0
- data/config/preferences/FileMerge.json +3 -0
- data/config/preferences/Fortran.json +158 -0
- data/config/preferences/GTD2.json +11 -0
- data/config/preferences/GTDAlt.json +20 -0
- data/config/preferences/GetBundle.json +3 -0
- data/config/preferences/Gettext.json +24 -0
- data/config/preferences/Graphviz.json +42 -0
- data/config/preferences/Greasemonkey.json +3 -0
- data/config/preferences/Gri.json +34 -0
- data/config/preferences/HTML.json +492 -0
- data/config/preferences/Haskell.json +72 -0
- data/config/preferences/Hotkey.json +3 -0
- data/config/preferences/ImageBrowser.json +3 -0
- data/config/preferences/Inform.json +3 -0
- data/config/preferences/Ini.json +60 -0
- data/config/preferences/Installer.json +3 -0
- data/config/preferences/Io.json +64 -0
- data/config/preferences/JSON.json +3 -0
- data/config/preferences/Java.json +86 -0
- data/config/preferences/JavaDoc.json +3 -0
- data/config/preferences/JavaScript.json +76 -0
- data/config/preferences/LaTeX.json +267 -0
- data/config/preferences/Lex/Flex.json +3 -0
- data/config/preferences/Lighttpd.json +3 -0
- data/config/preferences/LilyPond.json +77 -0
- data/config/preferences/Lisp.json +63 -0
- data/config/preferences/Logo.json +58 -0
- data/config/preferences/Logtalk.json +236 -0
- data/config/preferences/Lua.json +24 -0
- data/config/preferences/MEL.json +19 -0
- data/config/preferences/MIPS Assembler.json +26 -0
- data/config/preferences/MacPorts.json +3 -0
- data/config/preferences/Mail.json +3 -0
- data/config/preferences/Make.json +16 -0
- data/config/preferences/Markdown.json +102 -0
- data/config/preferences/Math.json +3 -0
- data/config/preferences/Matlab.json +128 -0
- data/config/preferences/Maven.json +308 -0
- data/config/preferences/Mediawiki.json +73 -0
- data/config/preferences/Mercurial.json +3 -0
- data/config/preferences/Modula.json +37 -0
- data/config/preferences/MoinMoin.json +52 -0
- data/config/preferences/Navigation.json +3 -0
- data/config/preferences/Nemerle.json +3 -0
- data/config/preferences/OCaml Code Completion.json +3 -0
- data/config/preferences/OCaml.json +163 -0
- data/config/preferences/ODCompletion.json +3 -0
- data/config/preferences/Objective-C.json +84 -0
- data/config/preferences/OpenGL.json +3331 -0
- data/config/preferences/Outlines.json +3 -0
- data/config/preferences/Pascal.json +60 -0
- data/config/preferences/Perforce.json +3 -0
- data/config/preferences/Perl.json +15 -0
- data/config/preferences/PmWiki.json +27 -0
- data/config/preferences/Postscript.json +15 -0
- data/config/preferences/Processing.json +32 -0
- data/config/preferences/Prolog.json +3 -0
- data/config/preferences/Propel.json +3 -0
- data/config/preferences/Python.json +38 -0
- data/config/preferences/Quake.json +15 -0
- data/config/preferences/R.json +33 -0
- data/config/preferences/Ragel.json +15 -0
- data/config/preferences/Regular Expressions.json +3 -0
- data/config/preferences/Remind.json +15 -0
- data/config/preferences/Rez.json +46 -0
- data/config/preferences/Ruby.json +98 -0
- data/config/preferences/S5 Slide Show.json +20 -0
- data/config/preferences/SCons.json +3 -0
- data/config/preferences/SQL.json +32 -0
- data/config/preferences/SSH Config.json +15 -0
- data/config/preferences/SVK.json +3 -0
- data/config/preferences/SWIG.json +3 -0
- data/config/preferences/SWeave.json +32 -0
- data/config/preferences/Scheme.json +35 -0
- data/config/preferences/Scilab.json +15 -0
- data/config/preferences/Setext.json +3 -0
- data/config/preferences/Shell Script.json +25 -0
- data/config/preferences/Slate.json +113 -0
- data/config/preferences/Source.json +132 -0
- data/config/preferences/Subversion.json +10 -0
- data/config/preferences/TODO.json +3 -0
- data/config/preferences/Tabular.json +3 -0
- data/config/preferences/Tcl.json +82 -0
- data/config/preferences/TerminalMate.json +112 -0
- data/config/preferences/Text.json +89 -0
- data/config/preferences/TextMate.json +38 -0
- data/config/preferences/Textile.json +76 -0
- data/config/preferences/Thrift.json +56 -0
- data/config/preferences/Transmit.json +3 -0
- data/config/preferences/Twiki.json +51 -0
- data/config/preferences/Txt2tags.json +81 -0
- data/config/preferences/Vectorscript.json +1280 -0
- data/config/preferences/XML.json +60 -0
- data/config/preferences/Xcode.json +3 -0
- data/config/preferences/YAML.json +24 -0
- data/config/preferences/iCalendar.json +10 -0
- data/config/preferences/iTerm.json +36 -0
- data/config/preferences/reStructuredText.json +48 -0
- data/config/rc.rb +49 -0
- data/config/syntax/ANTLR.json +5 -5
- data/config/syntax/{ASP VB.net.json → ASP vb.NET.json } +3 -3
- data/config/syntax/ASP.json +1 -1
- data/config/syntax/ActionScript.json +6 -6
- data/config/syntax/Active4D Config.json +86 -0
- data/config/syntax/Active4D Library.json +20 -0
- data/config/syntax/Active4D.json +418 -0
- data/config/syntax/Ada.json +3 -3
- data/config/syntax/Ant.json +196 -0
- data/config/syntax/Apache.json +7 -7
- data/config/syntax/AppleScript.json +3 -3
- data/config/syntax/{Bibtex.json → BibTeX.json} +1 -1
- data/config/syntax/Bison.json +59 -0
- data/config/syntax/{Blog (HTML).json → Blog - HTML.json } +2 -2
- data/config/syntax/{Blog (Markdown).json → Blog - Markdown.json } +2 -2
- data/config/syntax/Blog (Text).json b/data/config/syntax/Blog - → Text.json +0 -0
- data/config/syntax/Blog (Textile).json b/data/config/syntax/Blog - → Textile.json +0 -0
- data/config/syntax/C++.json +3 -3
- data/config/syntax/C.json +13 -13
- data/config/syntax/CMake Listfile.json +171 -0
- data/config/syntax/CSS.json +6 -6
- data/config/syntax/CSV.json +108 -0
- data/config/syntax/ColdFusion.json +204 -0
- data/config/syntax/D.json +560 -0
- data/config/syntax/Diff.json +1 -1
- data/config/syntax/DokuWiki.json +412 -0
- data/config/syntax/Doxygen.json +80 -0
- data/config/syntax/Dylan.json +4 -4
- data/config/syntax/Erlang.json +5 -5
- data/config/syntax/F-Script.json +1 -1
- data/config/syntax/FXScript.json +5 -5
- data/config/syntax/Fortran - Modern.json +221 -0
- data/config/syntax/Fortran - Punchcard.json +468 -0
- data/config/syntax/GTD.json +39 -0
- data/config/syntax/GTDalt.json +233 -0
- data/config/syntax/Gettext.json +118 -0
- data/config/syntax/Go.json +555 -0
- data/config/syntax/{DOT.json → Graphviz (DOT).json } +3 -3
- data/config/syntax/Greasemonkey.json +56 -0
- data/config/syntax/Gri.json +4 -4
- data/config/syntax/{HTML-ASP.json → HTML (ASP).json } +1 -1
- data/config/syntax/{HTML for ASP.net.json → HTML (ASP.net).json } +19 -19
- data/config/syntax/HTML (Active4D).json +540 -0
- data/config/syntax/HTML (Erlang).json +31 -0
- data/config/syntax/HTML (Tcl).json +1 -1
- data/config/syntax/HTML.json +20 -20
- data/config/syntax/Haskell.json +3 -3
- data/config/syntax/Installer Distribution Script.json +135 -0
- data/config/syntax/Io.json +6 -6
- data/config/syntax/JSON.json +151 -0
- data/config/syntax/{JavaProperties.json → Java Properties.json } +2 -2
- data/config/syntax/Java Server Page (JSP).json +163 -0
- data/config/syntax/Java.json +7 -7
- data/config/syntax/JavaDoc.json +435 -0
- data/config/syntax/JavaScript.json +8 -8
- data/config/syntax/LaTeX Log.json +3 -3
- data/config/syntax/LaTeX Memoir.json +101 -0
- data/config/syntax/LaTeX.json +2 -2
- data/config/syntax/Lex-Flex.json +396 -0
- data/config/syntax/LilyPond.json +608 -0
- data/config/syntax/Logo.json +48 -0
- data/config/syntax/Logtalk.json +6 -6
- data/config/syntax/Lua.json +1 -1
- data/config/syntax/{M.json → MATLAB.json} +3 -3
- data/config/syntax/MEL.json +7 -7
- data/config/syntax/MIPS.json b/data/config/syntax/MIPS → Assembler.json +0 -0
- data/config/syntax/MacPorts Portfile.json +298 -0
- data/config/syntax/Mail.json +1 -1
- data/config/syntax/Markdown.json +6 -6
- data/config/syntax/Maven POM.json +774 -0
- data/config/syntax/Mediawiki.json +736 -0
- data/config/syntax/MoinMoin.json +335 -0
- data/config/syntax/MultiMarkdown.json +41 -0
- data/config/syntax/Nemerle.json +128 -0
- data/config/syntax/OCaml.json +4 -4
- data/config/syntax/OCamllex.json +307 -0
- data/config/syntax/OCamlyacc.json +346 -0
- data/config/syntax/Objective-C++.json +2 -2
- data/config/syntax/Objective-C.json +979 -0
- data/config/syntax/Octave.json +417 -0
- data/config/syntax/PHP.json +32 -32
- data/config/syntax/Pascal.json +1 -1
- data/config/syntax/Perl.json +8 -8
- data/config/syntax/{Plain text.json → Plain Text.json } +1 -1
- data/config/syntax/PmWiki.json +241 -0
- data/config/syntax/Postscript.json +206 -0
- data/config/syntax/Processing.json +8 -8
- data/config/syntax/Prolog.json +70 -0
- data/config/syntax/Python.json +1934 -0
- data/config/syntax/{Quake3 Config.json → Quake Style .cfg.json } +1 -1
- data/config/syntax/R.json +2 -2
- data/config/syntax/Ragel.json +362 -0
- data/config/syntax/Rd (R Documentation).json +119 -0
- data/config/syntax/Regular Expressions (Oniguruma).json +186 -0
- data/config/syntax/Regular Expressions (Python).json +188 -0
- data/config/syntax/Release Notes.json +78 -0
- data/config/syntax/Remind.json +461 -0
- data/config/syntax/Rez.json +5 -5
- data/config/syntax/Ruby Sass.json +497 -0
- data/config/syntax/Ruby.json +13 -13
- data/config/syntax/S5 Slide Show.json +85 -0
- data/config/syntax/SQL.json +11 -11
- data/config/syntax/SSH Config.json +55 -0
- data/config/syntax/SWIG.json +2 -2
- data/config/syntax/SWeave.json +139 -0
- data/config/syntax/Scheme.json +8 -8
- data/config/syntax/Scilab.json +69 -0
- data/config/syntax/Setext.json +247 -0
- data/config/syntax/{Shell-Unix-Generic.json → Shell Script (Bash).json } +4 -4
- data/config/syntax/Slate.json +5 -5
- data/config/syntax/Strings File.json +53 -0
- data/config/syntax/TSV.json +83 -0
- data/config/syntax/Tcl.json +1 -1
- data/config/syntax/TeX Math.json +2 -2
- data/config/syntax/TeX.json +2 -2
- data/config/syntax/Textile.json +9 -9
- data/config/syntax/Thrift.json +641 -0
- data/config/syntax/Twiki.json +1 -1
- data/config/syntax/Txt2tags.json +154 -0
- data/config/syntax/XML strict.json +4 -4
- data/config/syntax/XML.json +6 -6
- data/config/syntax/XSL.json +2 -2
- data/config/syntax/camlp4.json +63 -0
- data/config/syntax/mod_perl.json +72 -0
- data/config/syntax/reStructuredText.json +1 -1
- data/config/syntax/{Subversion commit message.json → svn-commit.tmp.json} +0 -0
- data/config/tutorial +23 -19
- data/config/welcome +3 -3
- data/lib/ver.rb +273 -62
- data/lib/ver/entry.rb +142 -26
- data/lib/ver/font.rb +51 -0
- data/lib/ver/help.rb +16 -0
- data/lib/ver/help/describe_key.rb +82 -0
- data/lib/ver/help/help_for_help.rb +39 -0
- data/lib/ver/hover_completion.rb +129 -0
- data/lib/ver/keymap.rb +95 -24
- data/lib/ver/layout.rb +107 -43
- data/lib/ver/methods.rb +24 -8
- data/lib/ver/methods/clipboard.rb +91 -0
- data/lib/ver/methods/completion.rb +146 -71
- data/lib/ver/methods/control.rb +203 -222
- data/lib/ver/methods/ctags.rb +55 -0
- data/lib/ver/methods/delete.rb +30 -0
- data/lib/ver/methods/help.rb +7 -0
- data/lib/ver/methods/insert.rb +233 -1
- data/lib/ver/methods/move.rb +181 -32
- data/lib/ver/methods/open.rb +208 -0
- data/lib/ver/methods/preview.rb +14 -0
- data/lib/ver/methods/save.rb +111 -0
- data/lib/ver/methods/search.rb +57 -7
- data/lib/ver/methods/select.rb +97 -17
- data/lib/ver/methods/shortcuts.rb +21 -0
- data/lib/ver/methods/views.rb +56 -1
- data/lib/ver/mode.rb +60 -14
- data/lib/ver/status.rb +97 -19
- data/lib/ver/syntax.rb +14 -6
- data/lib/ver/syntax/detector.rb +16 -5
- data/lib/ver/syntax/processor.rb +9 -3
- data/lib/ver/text.rb +258 -199
- data/lib/ver/text/index.rb +103 -0
- data/lib/ver/theme.rb +27 -16
- data/lib/ver/tooltip.rb +59 -0
- data/lib/ver/vendor/binary_search.rb +61 -0
- data/lib/ver/vendor/levenshtein.rb +57 -0
- data/lib/ver/{textpow.rb → vendor/textpow.rb} +31 -29
- data/lib/ver/view.rb +65 -41
- data/lib/ver/view/console.rb +171 -0
- data/lib/ver/view/entry.rb +9 -5
- data/lib/ver/view/list.rb +44 -29
- data/lib/ver/view/list/ex.rb +71 -0
- data/lib/ver/view/list/grep.rb +42 -0
- data/lib/ver/view/list/methods.rb +159 -0
- data/lib/ver/view/term.rb +249 -0
- data/tasks/syntax_list.rake +3 -2
- data/ver.gemspec +4 -4
- metadata +230 -28
- data/config/syntax/Bulletin Board.json +0 -428
- data/config/syntax/HTML (Mason).json +0 -207
- data/config/syntax/HTML (Rails).json +0 -52
- data/config/syntax/Movable Type.json +0 -348
- data/config/syntax/Ruby on Rails.json +0 -170
- data/config/syntax/SQL (Rails).json +0 -31
- data/config/syntax/Smarty.json +0 -110
- data/config/syntax/Standard ML.json +0 -322
@@ -0,0 +1,55 @@
|
|
1
|
+
module VER
|
2
|
+
module Methods
|
3
|
+
module Ctags
|
4
|
+
def ctags_find_current
|
5
|
+
word = get('insert wordstart', 'insert wordend')
|
6
|
+
ctags_find(word)
|
7
|
+
end
|
8
|
+
|
9
|
+
def ctags_find(needle)
|
10
|
+
ctags_content do |tag_name, file_name, ex_cmd|
|
11
|
+
next unless tag_name == needle
|
12
|
+
return ctags_execute(file_name, ex_cmd)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def ctags_execute(file_name, ex_cmd)
|
17
|
+
case ex_cmd
|
18
|
+
when /^\d+$/
|
19
|
+
view.find_or_create(file_name) do |view|
|
20
|
+
view.text.go_line(ex_cmd.to_i)
|
21
|
+
end
|
22
|
+
when /^\/(.*)\/$/
|
23
|
+
source = $1.gsub!(/(?!\\)([()])/, '\\\\\\1')
|
24
|
+
regexp = Regexp.new(source)
|
25
|
+
self.view.find_or_create(file_name) do |view|
|
26
|
+
view.text.tag_all_matching(:search, regexp, Search::SEARCH_HIGHLIGHT)
|
27
|
+
view.text.search_next
|
28
|
+
end
|
29
|
+
else
|
30
|
+
raise ArgumentError, "Unknown Ex command: %p" % [ex_cmd]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def ctags_content
|
35
|
+
dir = filename.dirname
|
36
|
+
file = nil
|
37
|
+
|
38
|
+
loop do
|
39
|
+
file = dir/'tags'
|
40
|
+
break if file.file? || dir.root?
|
41
|
+
dir = dir.parent
|
42
|
+
end
|
43
|
+
|
44
|
+
return unless file.file?
|
45
|
+
|
46
|
+
file.open 'rb' do |io|
|
47
|
+
io.each_line do |line|
|
48
|
+
head, tail = line.split(/;"\t/, 2)
|
49
|
+
yield(*head.split("\t"))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module VER
|
2
|
+
module Methods
|
3
|
+
module Delete
|
4
|
+
def change_motion(motion, count = 1)
|
5
|
+
delete_motion(motion, count)
|
6
|
+
start_insert_mode
|
7
|
+
end
|
8
|
+
|
9
|
+
def delete_motion(motion, count = 1)
|
10
|
+
delete(*virtual_movement(motion, count))
|
11
|
+
end
|
12
|
+
|
13
|
+
def delete_line(count = 1)
|
14
|
+
count.times do
|
15
|
+
delete 'insert linestart', 'insert lineend + 1 char'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def change_line(count = 1)
|
20
|
+
delete_line(count)
|
21
|
+
start_insert_mode
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_trailing_whitespace
|
25
|
+
tag_all_trailing_whitespace
|
26
|
+
execute :delete, *tag_ranges('invalid.trailing-whitespace').flatten
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/ver/methods/insert.rb
CHANGED
@@ -1,6 +1,238 @@
|
|
1
1
|
module VER
|
2
2
|
module Methods
|
3
3
|
module Insert
|
4
|
+
def insert_file_contents(filename)
|
5
|
+
content = read_file(filename)
|
6
|
+
insert :insert, content
|
7
|
+
rescue Errno::ENOENT => ex
|
8
|
+
VER.error(ex)
|
9
|
+
end
|
10
|
+
|
11
|
+
def insert_selection
|
12
|
+
insert :insert, Tk::Selection.get
|
13
|
+
end
|
14
|
+
|
15
|
+
def insert_tab
|
16
|
+
insert :insert, "\t"
|
17
|
+
end
|
18
|
+
|
19
|
+
def insert_indented_newline_below
|
20
|
+
if VER.options.autoindent
|
21
|
+
line = get('insert linestart', 'insert lineend')
|
22
|
+
|
23
|
+
indent = line.empty? ? "" : (line[/^\s+/] || '')
|
24
|
+
mark_set :insert, 'insert lineend'
|
25
|
+
insert :insert, "\n#{indent}"
|
26
|
+
else
|
27
|
+
mark_set :insert, 'insert lineend'
|
28
|
+
insert :insert, "\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
clean_line('insert - 1 line')
|
32
|
+
start_insert_mode
|
33
|
+
end
|
34
|
+
|
35
|
+
def insert_indented_newline_above
|
36
|
+
if index(:insert).y > 1
|
37
|
+
previous_line
|
38
|
+
insert_indented_newline_below
|
39
|
+
else
|
40
|
+
insert('insert linestart', "\n")
|
41
|
+
mark_set(:insert, 'insert - 1 line')
|
42
|
+
end
|
43
|
+
|
44
|
+
clean_line('insert + 1 line')
|
45
|
+
start_insert_mode
|
46
|
+
end
|
47
|
+
|
48
|
+
def insert_newline
|
49
|
+
insert :insert, "\n"
|
50
|
+
end
|
51
|
+
|
52
|
+
def insert_indented_newline
|
53
|
+
if VER.options.autoindent
|
54
|
+
fallback_insert_indented_newline
|
55
|
+
else
|
56
|
+
insert_newline
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def insert_auto_indented_newline
|
61
|
+
insert 'insert lineend', "\n"
|
62
|
+
indent_fix_at('insert', indent_fix('insert - 1 line', indent_after('insert - 2 line')))
|
63
|
+
rescue Errno::ENOENT, TypeError
|
64
|
+
fallback_insert_indented_newline
|
65
|
+
end
|
66
|
+
|
67
|
+
def indent_of(index)
|
68
|
+
index = index(index)
|
69
|
+
return 0 if index.y < 1
|
70
|
+
|
71
|
+
line = get(index.linestart, index.lineend)
|
72
|
+
|
73
|
+
if line =~ /^\s*$/
|
74
|
+
return indent_of(index.prev)
|
75
|
+
else
|
76
|
+
indent_size = line[/^\s*/].size
|
77
|
+
return 0 if indent_size == 0
|
78
|
+
return indent_size / 2
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def indent_after(index, indent = nil)
|
83
|
+
settings = indent_settings.values_at(:increase, :decrease, :indent_next, :unindented)
|
84
|
+
|
85
|
+
return unless settings.any?
|
86
|
+
increase, decrease, indent_next, unindented = settings
|
87
|
+
|
88
|
+
index = index(index)
|
89
|
+
indent ||= (index.y > 1 ? indent_after(index.prev) : 0)
|
90
|
+
|
91
|
+
linestart, lineend = index.linestart, index.lineend
|
92
|
+
line = get(linestart, lineend).strip
|
93
|
+
|
94
|
+
if increase && decrease && line =~ increase && line =~ decrease
|
95
|
+
indent -= 1
|
96
|
+
indent += 1
|
97
|
+
elsif decrease && line =~ decrease
|
98
|
+
indent -= 1
|
99
|
+
elsif increase && line =~ increase
|
100
|
+
indent += 1
|
101
|
+
elsif line =~ /^\s*$/
|
102
|
+
else
|
103
|
+
end
|
104
|
+
|
105
|
+
return indent
|
106
|
+
end
|
107
|
+
|
108
|
+
def indent_fix_at(index, indent)
|
109
|
+
settings = indent_settings.values_at(:increase, :decrease, :indent_next, :unindented)
|
110
|
+
|
111
|
+
return unless settings.any?
|
112
|
+
increase, decrease, indent_next, unindented = settings
|
113
|
+
|
114
|
+
index = index(index)
|
115
|
+
|
116
|
+
linestart, lineend = index.linestart, index.lineend
|
117
|
+
line = get(linestart, lineend).strip
|
118
|
+
|
119
|
+
if increase && decrease && line =~ increase && line =~ decrease
|
120
|
+
indent -= 1
|
121
|
+
replace(linestart, lineend, (' ' * indent) << line)
|
122
|
+
indent += 1
|
123
|
+
elsif decrease && line =~ decrease
|
124
|
+
replace(linestart, lineend, (' ' * indent) << line)
|
125
|
+
indent -= 1
|
126
|
+
elsif increase && line =~ increase
|
127
|
+
replace(linestart, lineend, (' ' * indent) << line)
|
128
|
+
indent += 1
|
129
|
+
elsif line =~ /^\s*$/
|
130
|
+
replace(linestart, lineend, (' ' * indent) << line)
|
131
|
+
else
|
132
|
+
replace(linestart, lineend, (' ' * indent) << line)
|
133
|
+
end
|
134
|
+
|
135
|
+
return indent
|
136
|
+
end
|
137
|
+
|
138
|
+
def fallback_insert_indented_newline
|
139
|
+
line1 = get('insert linestart', 'insert lineend')
|
140
|
+
indentation1 = line1[/^\s+/] || ''
|
141
|
+
insert :insert, "\n"
|
142
|
+
|
143
|
+
line2 = get('insert linestart', 'insert lineend')
|
144
|
+
indentation2 = line2[/^\s+/] || ''
|
145
|
+
|
146
|
+
replace(
|
147
|
+
'insert linestart',
|
148
|
+
"insert linestart + #{indentation2.size} chars",
|
149
|
+
indentation1
|
150
|
+
)
|
151
|
+
|
152
|
+
clean_line('insert - 1 line')
|
153
|
+
end
|
154
|
+
|
155
|
+
# Most of the input will be in US-ASCII, but an encoding can be set per view for the input.
|
156
|
+
# For just about all purposes, UTF-8 should be what you want to input, and it's what Tk
|
157
|
+
# can handle best.
|
158
|
+
def insert_string(string)
|
159
|
+
return if string.empty?
|
160
|
+
|
161
|
+
if !string.frozen? && string.encoding == Encoding::ASCII_8BIT
|
162
|
+
begin
|
163
|
+
string.encode!(@encoding)
|
164
|
+
rescue Encoding::UndefinedConversionError
|
165
|
+
string.force_encoding(@encoding)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# puts "Insert %p in mode %p" % [string, keymap.mode]
|
170
|
+
insert :insert, string
|
171
|
+
end
|
172
|
+
|
173
|
+
def auto_indent_line
|
174
|
+
if @syntax
|
175
|
+
syntax_indent_line
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def indent_settings
|
180
|
+
return {} unless @syntax
|
181
|
+
name = @syntax.name
|
182
|
+
file = VER.find_in_loadpath("preferences/#{name}.json")
|
183
|
+
pref = JSON.load(File.read(file))
|
184
|
+
|
185
|
+
indent_settings = {}
|
186
|
+
|
187
|
+
pref.each do |key, value|
|
188
|
+
settings = value['settings']
|
189
|
+
indent_settings[:increase] ||= settings['increaseIndentPattern']
|
190
|
+
indent_settings[:decrease] ||= settings['decreaseIndentPattern']
|
191
|
+
indent_settings[:indent_next] ||= settings['indentNextLinePattern']
|
192
|
+
indent_settings[:unindented] ||= settings['unIndentedLinePattern']
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
[:increase, :decrease, :indent_next, :unindented].each do |key|
|
197
|
+
if value = indent_settings[key]
|
198
|
+
indent_settings[key] = Regexp.new(value)
|
199
|
+
else
|
200
|
+
indent_settings.delete(key)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
return indent_settings
|
205
|
+
end
|
206
|
+
|
207
|
+
def syntax_indent_file
|
208
|
+
settings = indent_settings.values_at(:increase, :decrease, :indent_next, :unindented)
|
209
|
+
|
210
|
+
return unless settings.any?
|
211
|
+
increase, decrease, indent_next, unindented = settings
|
212
|
+
|
213
|
+
empty_line = /^\s*$/
|
214
|
+
indent = 0
|
215
|
+
|
216
|
+
index('1.0').upto(index('end')) do |pos|
|
217
|
+
pos_lineend = pos.lineend
|
218
|
+
line = get(pos, pos_lineend).strip
|
219
|
+
|
220
|
+
if increase && decrease && line =~ increase && line =~ decrease
|
221
|
+
indent -= 1
|
222
|
+
replace(pos, pos_lineend, (' ' * indent) << line)
|
223
|
+
indent += 1
|
224
|
+
elsif decrease && line =~ decrease
|
225
|
+
indent -= 1
|
226
|
+
replace(pos, pos_lineend, (' ' * indent) << line)
|
227
|
+
elsif increase && line =~ increase
|
228
|
+
replace(pos, pos_lineend, (' ' * indent) << line)
|
229
|
+
indent += 1
|
230
|
+
elsif line =~ empty_line
|
231
|
+
else
|
232
|
+
replace(pos, pos_lineend, (' ' * indent) << line)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
4
236
|
end
|
5
237
|
end
|
6
|
-
end
|
238
|
+
end
|
data/lib/ver/methods/move.rb
CHANGED
@@ -1,64 +1,213 @@
|
|
1
1
|
module VER
|
2
2
|
module Methods
|
3
3
|
module Move
|
4
|
-
|
5
|
-
|
4
|
+
GO_MATCHING_RIGHT = {
|
5
|
+
'(' => ')',
|
6
|
+
'{' => '}',
|
7
|
+
'[' => ']',
|
8
|
+
'<' => '>',
|
9
|
+
}
|
10
|
+
GO_MATCHING_LEFT = GO_MATCHING_RIGHT.invert
|
11
|
+
|
12
|
+
def matching_brace(count = nil)
|
13
|
+
opening = get(:insert)
|
14
|
+
|
15
|
+
if closing = GO_MATCHING_RIGHT[opening]
|
16
|
+
search = method(:search_all)
|
17
|
+
level = 1
|
18
|
+
start = 'insert + 1 chars'
|
19
|
+
elsif closing = GO_MATCHING_LEFT[opening]
|
20
|
+
search = method(:rsearch_all)
|
21
|
+
level = 1
|
22
|
+
start = 'insert'
|
23
|
+
else
|
24
|
+
return
|
25
|
+
end
|
26
|
+
|
27
|
+
needle = Regexp.union(opening, closing)
|
28
|
+
|
29
|
+
search.call(needle, start) do |match, pos, from|
|
30
|
+
if match == opening
|
31
|
+
level += 1
|
32
|
+
elsif match == closing
|
33
|
+
level -= 1
|
34
|
+
end
|
35
|
+
|
36
|
+
if level < 1
|
37
|
+
mark_set :insert, pos
|
38
|
+
return
|
39
|
+
end
|
40
|
+
end
|
6
41
|
end
|
7
42
|
|
8
|
-
|
9
|
-
|
43
|
+
# Move cursor +count+ characters left.
|
44
|
+
def backward_char(count = 1)
|
45
|
+
mark_set :insert, "insert - #{count} char"
|
10
46
|
end
|
11
47
|
|
12
|
-
|
13
|
-
|
48
|
+
# Move cursor +count+ characters right.
|
49
|
+
def forward_char(count = 1)
|
50
|
+
mark_set :insert, "insert + #{count} char"
|
14
51
|
end
|
15
52
|
|
16
|
-
def
|
17
|
-
mark_set :insert,
|
53
|
+
def beginning_of_line(count = nil)
|
54
|
+
mark_set :insert, 'insert display linestart'
|
18
55
|
end
|
19
56
|
|
20
|
-
def
|
21
|
-
mark_set :insert, 'insert
|
22
|
-
mark_set :insert, 'insert wordstart'
|
57
|
+
def end_of_line(count = nil)
|
58
|
+
mark_set :insert, 'insert display lineend'
|
23
59
|
end
|
24
60
|
|
25
|
-
def
|
26
|
-
|
27
|
-
|
61
|
+
def eol_then_insert_mode(count = nil)
|
62
|
+
end_of_line
|
63
|
+
start_insert_mode
|
28
64
|
end
|
29
65
|
|
30
|
-
def
|
31
|
-
|
66
|
+
def sol_then_insert_mode
|
67
|
+
beginning_of_line
|
68
|
+
start_insert_mode
|
32
69
|
end
|
33
70
|
|
34
|
-
def
|
35
|
-
|
71
|
+
def forward_char_then_insert_mode
|
72
|
+
forward_char
|
73
|
+
start_insert_mode
|
36
74
|
end
|
37
75
|
|
38
76
|
def go_line(number = 0)
|
39
77
|
mark_set :insert, "#{number}.0"
|
40
78
|
end
|
41
79
|
|
42
|
-
def
|
43
|
-
|
80
|
+
def end_of_file(count = nil)
|
81
|
+
if count
|
82
|
+
mark_set :insert, "#{count}.0"
|
83
|
+
else
|
84
|
+
mark_set :insert, :end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def virtual_movement(name, count = 1)
|
89
|
+
pos = index(:insert)
|
90
|
+
__send__(name, count)
|
91
|
+
mark = index(:insert)
|
92
|
+
mark_set :insert, pos
|
93
|
+
return [pos, mark].sort
|
94
|
+
rescue => ex
|
95
|
+
VER.error(ex)
|
96
|
+
end
|
97
|
+
|
98
|
+
# HACK: but it's just too good to do it manually
|
99
|
+
|
100
|
+
def page_up(count = 1)
|
101
|
+
mark_set :insert, tk_prev_page_pos(count)
|
102
|
+
end
|
103
|
+
|
104
|
+
def page_down(count = 1)
|
105
|
+
mark_set :insert, tk_next_page_pos(count)
|
106
|
+
end
|
107
|
+
|
108
|
+
def previous_line(count = 1)
|
109
|
+
mark_set :insert, tk_prev_line_pos(count)
|
110
|
+
end
|
111
|
+
|
112
|
+
def next_line(count = 1)
|
113
|
+
mark_set :insert, tk_next_line_pos(count)
|
114
|
+
end
|
115
|
+
|
116
|
+
def forward_word(count = 1)
|
117
|
+
count.times do
|
118
|
+
original_type = type = char_type(get(:insert))
|
119
|
+
changed = 0
|
120
|
+
|
121
|
+
begin
|
122
|
+
original_pos = index(:insert)
|
123
|
+
execute :mark, :set, :insert, 'insert + 1 chars'
|
124
|
+
break if original_pos == index(:insert)
|
125
|
+
|
126
|
+
type = char_type(get(:insert))
|
127
|
+
changed += 1 if type != original_type
|
128
|
+
original_type = type
|
129
|
+
end until changed > 0 && type != :space
|
130
|
+
end
|
131
|
+
|
132
|
+
Tk::Event.generate(self, '<<Movement>>')
|
133
|
+
rescue => ex
|
134
|
+
VER.error(ex)
|
135
|
+
end
|
136
|
+
|
137
|
+
def word_right_end(count = 1)
|
138
|
+
count.times do
|
139
|
+
mark_set :insert, tk_next_word_pos_end('insert')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def backward_word(count = 1)
|
144
|
+
count.times do
|
145
|
+
original_type = type = char_type(get(:insert))
|
146
|
+
changed = 0
|
147
|
+
|
148
|
+
begin
|
149
|
+
original_pos = index(:insert)
|
150
|
+
execute :mark, :set, :insert, 'insert - 1 chars'
|
151
|
+
break if index(:insert) == original_pos
|
152
|
+
|
153
|
+
type = char_type(get(:insert))
|
154
|
+
changed += 1 if type != original_type
|
155
|
+
original_type = type
|
156
|
+
end until changed > 0 && type != :space
|
157
|
+
|
158
|
+
type = char_type(get('insert - 1 chars'))
|
159
|
+
|
160
|
+
while type == original_type
|
161
|
+
original_pos = index(:insert)
|
162
|
+
execute :mark, :set, :insert, 'insert - 1 chars'
|
163
|
+
break if index(:insert) == original_pos
|
164
|
+
|
165
|
+
type = char_type(get('insert - 1 chars'))
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
Tk::Event.generate(self, '<<Movement>>')
|
170
|
+
rescue => ex
|
171
|
+
VER.error(ex)
|
44
172
|
end
|
45
173
|
|
46
|
-
|
47
|
-
height = Tk.root.winfo_height
|
48
|
-
linespace = cget(:font).metrics(:linespace)
|
49
|
-
diff = height / linespace
|
174
|
+
private
|
50
175
|
|
51
|
-
|
52
|
-
|
176
|
+
def char_type(char)
|
177
|
+
case char
|
178
|
+
when /\w/; :word
|
179
|
+
when /\S/; :special
|
180
|
+
when /\s/; :space
|
181
|
+
else; raise "You cannot get here"
|
182
|
+
end
|
53
183
|
end
|
54
184
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
185
|
+
def tk_prev_word_pos(start)
|
186
|
+
Tk.execute('tk::TextPrevPos', tk_pathname, start, 'tcl_startOfPreviousWord').to_s
|
187
|
+
end
|
188
|
+
|
189
|
+
def tk_next_word_pos(start)
|
190
|
+
Tk.execute('tk::TextNextPos', tk_pathname, start, 'tcl_startOfNextWord').to_s
|
191
|
+
end
|
192
|
+
|
193
|
+
def tk_next_word_pos_end(start)
|
194
|
+
Tk.execute('tk::TextNextWord', tk_pathname, start).to_s
|
195
|
+
end
|
196
|
+
|
197
|
+
def tk_prev_line_pos(count)
|
198
|
+
Tk.execute('tk::TextUpDownLine', tk_pathname, -count.abs).to_s
|
199
|
+
end
|
200
|
+
|
201
|
+
def tk_next_line_pos(count)
|
202
|
+
Tk.execute('tk::TextUpDownLine', tk_pathname, count).to_s
|
203
|
+
end
|
204
|
+
|
205
|
+
def tk_prev_page_pos(count)
|
206
|
+
Tk.execute('tk::TextScrollPages', tk_pathname, -count.abs).to_s
|
207
|
+
end
|
59
208
|
|
60
|
-
|
61
|
-
|
209
|
+
def tk_next_page_pos(count)
|
210
|
+
Tk.execute('tk::TextScrollPages', tk_pathname, count).to_s
|
62
211
|
end
|
63
212
|
end
|
64
213
|
end
|