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
data/lib/ver/methods/control.rb
CHANGED
@@ -1,6 +1,103 @@
|
|
1
1
|
module VER
|
2
2
|
module Methods
|
3
3
|
module Control
|
4
|
+
def tags_at(index = :insert)
|
5
|
+
index = index(index)
|
6
|
+
tags = tag_names(index)
|
7
|
+
message tags.inspect
|
8
|
+
|
9
|
+
require 'ver/tooltip'
|
10
|
+
|
11
|
+
tooltip = Tk::Tooltip.new(tags.inspect)
|
12
|
+
tooltip.show_on(self)
|
13
|
+
|
14
|
+
Tk::After.ms(5000){ tooltip.destroy }
|
15
|
+
end
|
16
|
+
|
17
|
+
# Substitute over all lines of the buffer
|
18
|
+
def gsub(regexp, with)
|
19
|
+
total = 0
|
20
|
+
index('1.0').upto(index('end')) do |index|
|
21
|
+
lineend = index.lineend
|
22
|
+
line = get(index, lineend)
|
23
|
+
|
24
|
+
if line.gsub!(regexp, with)
|
25
|
+
replace(index, lineend, line)
|
26
|
+
total += 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
message "Performed gsub on #{total} lines"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Substitute on current line
|
34
|
+
def sub(regexp, with)
|
35
|
+
linestart = index('insert linestart')
|
36
|
+
lineend = linestart.lineend
|
37
|
+
line = get(linestart, lineend)
|
38
|
+
|
39
|
+
if line.sub!(regexp, with)
|
40
|
+
replace(linestart, lineend, line)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def open_grep_list
|
45
|
+
View::List::Grep.new self do |file, line|
|
46
|
+
view.find_or_create(file, line)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def open_method_list
|
51
|
+
View::List::Methods.new self do |file, line|
|
52
|
+
view.find_or_create(file, line)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# TODO: make this better?
|
57
|
+
def status_ex
|
58
|
+
completion = method(:status_ex_filter)
|
59
|
+
|
60
|
+
View::List::Ex.new self, completion do |command, propose|
|
61
|
+
begin
|
62
|
+
result = propose ? send(command, propose) : eval(command)
|
63
|
+
status.message "%s # => %p" % [command, result]
|
64
|
+
rescue Exception => ex
|
65
|
+
status.error "%s # => %p" % [command, ex]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def status_ex_filter(input)
|
71
|
+
input = input.to_s.split.last
|
72
|
+
return [] if !input || input.empty?
|
73
|
+
|
74
|
+
begin
|
75
|
+
regexp = Regexp.new(input)
|
76
|
+
rescue ArgumentError, RegexpError, SyntaxError
|
77
|
+
regexp = Regexp.new(Regexp.escape(input))
|
78
|
+
end
|
79
|
+
|
80
|
+
self.methods.grep(regexp).sort_by{|sym| sym =~ regexp }
|
81
|
+
end
|
82
|
+
|
83
|
+
def open_console
|
84
|
+
View::Console.new(self)
|
85
|
+
end
|
86
|
+
|
87
|
+
def open_terminal
|
88
|
+
require 'ver/view/term'
|
89
|
+
View::Terminal.new(self)
|
90
|
+
end
|
91
|
+
|
92
|
+
def wrap_line
|
93
|
+
text = get('insert linestart', 'insert lineend')
|
94
|
+
textwidth = options[:textwidth]
|
95
|
+
lines = wrap_lines_of(text, textwidth).join("\n")
|
96
|
+
lines.rstrip!
|
97
|
+
|
98
|
+
replace('insert linestart', 'insert lineend', lines)
|
99
|
+
end
|
100
|
+
|
4
101
|
def status_theme_select
|
5
102
|
return unless @syntax
|
6
103
|
|
@@ -23,197 +120,107 @@ module VER
|
|
23
120
|
|
24
121
|
def status_evaluate
|
25
122
|
status_ask 'Eval expression: ' do |term|
|
26
|
-
eval(term)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def status_ask(prompt, &callback)
|
31
|
-
@status.ask(prompt){|*args|
|
32
123
|
begin
|
33
|
-
|
34
|
-
rescue => ex
|
35
|
-
|
36
|
-
status.message ex.message
|
37
|
-
ensure
|
38
|
-
focus
|
124
|
+
eval(term)
|
125
|
+
rescue Exception => ex
|
126
|
+
ex
|
39
127
|
end
|
40
|
-
|
128
|
+
end
|
41
129
|
end
|
42
130
|
|
43
131
|
def smart_evaluate
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
selection_evaluate
|
48
|
-
else
|
49
|
-
line_evaluate
|
132
|
+
if sel = tag_ranges(:sel)
|
133
|
+
from, to = sel.first
|
134
|
+
return selection_evaluate if from && to
|
50
135
|
end
|
136
|
+
|
137
|
+
line_evaluate
|
51
138
|
end
|
52
139
|
|
53
140
|
def line_evaluate
|
54
141
|
text = get('insert linestart', 'insert lineend')
|
55
|
-
|
56
|
-
|
142
|
+
stdout_capture_evaluate(text) do |res,out|
|
143
|
+
insert("insert lineend", "\n%s%p" % [out, res] )
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def stdout_capture_evaluate(code)
|
148
|
+
begin
|
149
|
+
old_stdout = $stdout.dup
|
150
|
+
rd, wr = IO.pipe
|
151
|
+
$stdout.reopen(wr)
|
152
|
+
result = eval(code)
|
153
|
+
$stdout.reopen old_stdout; wr.close
|
154
|
+
stdout = rd.read
|
155
|
+
|
156
|
+
yield(result, stdout)
|
157
|
+
rescue Exception => exception
|
158
|
+
yield(exception, '')
|
159
|
+
ensure
|
160
|
+
wr.closed? || $stdout.reopen(old_stdout) && wr.close
|
161
|
+
rd.closed? || rd.close
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def eval_buffer
|
166
|
+
result = eval(value, TOPLEVEL_BINDING)
|
167
|
+
rescue Exception => exception
|
168
|
+
VER.error(exception)
|
57
169
|
end
|
58
170
|
|
59
171
|
def buffer_switch
|
60
172
|
View::List::Buffer.new self do |file|
|
61
|
-
|
62
|
-
# VER.resume_buffer file_path
|
63
|
-
open_path file if File.exists? file
|
173
|
+
view.find_or_create(file) if File.exists?(file)
|
64
174
|
end
|
65
175
|
end
|
66
176
|
|
67
177
|
def window_switch(count = nil)
|
68
178
|
if count
|
69
|
-
p count: count
|
179
|
+
# p count: count
|
70
180
|
else
|
71
181
|
View::List::Window.new self do |view|
|
182
|
+
view.push_top
|
72
183
|
view.focus
|
73
|
-
# open_path(path)
|
74
184
|
end
|
75
185
|
end
|
76
186
|
end
|
77
187
|
|
78
|
-
def file_save
|
79
|
-
save_to(filename)
|
80
|
-
end
|
81
|
-
|
82
|
-
def file_save_popup
|
83
|
-
filetypes = [
|
84
|
-
['ALL Files', '*' ],
|
85
|
-
['Text Files', '*.txt'],
|
86
|
-
]
|
87
|
-
|
88
|
-
filename = ::File.basename @filename
|
89
|
-
extension = ::File.extname @filename
|
90
|
-
directory = ::File.dirname @filename
|
91
|
-
|
92
|
-
fpath = Tk.getSaveFile(
|
93
|
-
initialfile: filename,
|
94
|
-
initialdir: directory,
|
95
|
-
defaultextension: extension,
|
96
|
-
filetypes: filetypes
|
97
|
-
)
|
98
|
-
|
99
|
-
return if fpath.empty?
|
100
|
-
|
101
|
-
save_to(fpath)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Some strategies are discussed at:
|
105
|
-
#
|
106
|
-
# http://bitworking.org/news/390/text-editor-saving-routines
|
107
|
-
#
|
108
|
-
# I try another, "wasteful" approach, copying the original file to a
|
109
|
-
# temporary location, overwriting the contents in the copy, then moving the
|
110
|
-
# file to the location of the original file.
|
111
|
-
#
|
112
|
-
# This way all permissions should be kept identical without any effort, but
|
113
|
-
# it will take up additional disk space.
|
114
|
-
#
|
115
|
-
# If there is some failure during the normal saving procedure, we will
|
116
|
-
# simply overwrite the original file in place, make sure you have good insurance ;)
|
117
|
-
def save_to(to)
|
118
|
-
save_smart(filename, to)
|
119
|
-
rescue => ex
|
120
|
-
puts "#{ex.class}: #{ex}", *ex.backtrace
|
121
|
-
save_dumb(filename, to)
|
122
|
-
end
|
123
|
-
|
124
|
-
def save_smart(from, to)
|
125
|
-
sha1 = Digest::SHA1.hexdigest([from, to].join)
|
126
|
-
temp_path = File.join(Dir.tmpdir, 'ver', sha1)
|
127
|
-
temp_dir = File.dirname(temp_path)
|
128
|
-
|
129
|
-
FileUtils.mkdir_p(temp_dir)
|
130
|
-
FileUtils.copy_file(from, temp_path, preserve = true)
|
131
|
-
File.open(temp_path, 'w+') do |io|
|
132
|
-
io.write(self.value)
|
133
|
-
end
|
134
|
-
FileUtils.mv(temp_path, to)
|
135
|
-
|
136
|
-
status.message "Saved to #{to}"
|
137
|
-
rescue Errno::ENOENT
|
138
|
-
save_dumb(to)
|
139
|
-
end
|
140
|
-
|
141
|
-
def save_dumb(to)
|
142
|
-
File.open(to, 'w+') do |io|
|
143
|
-
io.write(self.value)
|
144
|
-
end
|
145
|
-
|
146
|
-
status.message "Saved to #{to}"
|
147
|
-
end
|
148
|
-
|
149
188
|
def file_open_popup
|
150
189
|
filetypes = [
|
151
190
|
['ALL Files', '*' ],
|
152
191
|
['Text Files', '*.txt'],
|
153
192
|
]
|
154
193
|
|
155
|
-
fpath = Tk.
|
194
|
+
fpath = Tk.get_open_file(filetypes: filetypes)
|
156
195
|
|
157
|
-
return
|
196
|
+
return unless fpath
|
158
197
|
|
159
|
-
|
198
|
+
view.find_or_create(fpath)
|
160
199
|
end
|
161
200
|
|
162
201
|
def file_open_fuzzy
|
163
202
|
View::List::FuzzyFileFinder.new self do |path|
|
164
|
-
|
203
|
+
view.find_or_create(path)
|
165
204
|
end
|
166
205
|
end
|
167
206
|
|
168
|
-
def delete_char_left
|
169
|
-
delete 'insert - 1 char'
|
170
|
-
end
|
171
|
-
|
172
|
-
def delete_char_right
|
173
|
-
delete 'insert'
|
174
|
-
end
|
175
|
-
|
176
|
-
def delete_word_right
|
177
|
-
delete 'insert', 'insert wordend'
|
178
|
-
end
|
179
|
-
|
180
|
-
def delete_word_left
|
181
|
-
delete 'insert wordstart', 'insert'
|
182
|
-
end
|
183
|
-
|
184
|
-
def delete_line
|
185
|
-
delete 'insert linestart', 'insert lineend + 1 char'
|
186
|
-
end
|
187
|
-
|
188
|
-
def delete_to_eol
|
189
|
-
delete 'insert', 'insert lineend'
|
190
|
-
end
|
191
|
-
|
192
|
-
def delete_to_eol_then_insert
|
193
|
-
delete_to_eol
|
194
|
-
start_insert_mode
|
195
|
-
end
|
196
|
-
|
197
207
|
def join_lines
|
198
|
-
start_of_next_line = search(/\S/, 'insert lineend')
|
208
|
+
start_of_next_line = search(/\S/, 'insert lineend').first
|
199
209
|
replace('insert lineend', start_of_next_line, ' ')
|
200
210
|
rescue RuntimeError => exception
|
201
211
|
return if exception.message =~ /Index "\d+\.\d+" before "insert lineend" in the text/
|
202
|
-
raise exception
|
203
|
-
end
|
204
|
-
|
205
|
-
def insert_string(string)
|
206
|
-
# puts "Insert %p in mode %p" % [string, keymap.mode]
|
207
|
-
insert :insert, string unless string.empty?
|
208
|
-
end
|
209
|
-
|
210
|
-
def ignore_string(string)
|
211
|
-
status.message "Ignore %p in mode %p" % [string, keymap.mode]
|
212
|
+
Kernel.raise exception
|
212
213
|
end
|
213
214
|
|
214
215
|
def replace_char
|
215
|
-
status_ask 'Replace with: ' do |
|
216
|
-
|
216
|
+
status_ask 'Replace with: ', take: 1 do |char|
|
217
|
+
if char.size == 1
|
218
|
+
replace('insert', 'insert + 1 chars', char)
|
219
|
+
backward_char
|
220
|
+
"replaced #{char.size} chars"
|
221
|
+
else
|
222
|
+
status.message 'replace aborted'
|
223
|
+
end
|
217
224
|
end
|
218
225
|
end
|
219
226
|
|
@@ -233,59 +240,12 @@ module VER
|
|
233
240
|
)
|
234
241
|
end
|
235
242
|
|
236
|
-
def
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
start_insert_mode
|
244
|
-
end
|
245
|
-
|
246
|
-
def insert_indented_newline_above
|
247
|
-
y, x = index(:insert).split('.').map(&:to_i)
|
248
|
-
|
249
|
-
if y > 1
|
250
|
-
go_line_up
|
251
|
-
insert_indented_newline_below
|
252
|
-
else
|
253
|
-
insert('insert linestart', "\n")
|
254
|
-
mark_set(:insert, 'insert - 1 line')
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
def insert_newline
|
259
|
-
insert :insert, "\n"
|
260
|
-
end
|
261
|
-
|
262
|
-
def insert_indented_newline
|
263
|
-
line1 = get('insert linestart', 'insert lineend')
|
264
|
-
indentation1 = line1[/^\s+/] || ''
|
265
|
-
insert :insert, "\n"
|
266
|
-
|
267
|
-
line2 = get('insert linestart', 'insert lineend')
|
268
|
-
indentation2 = line2[/^\s+/] || ''
|
269
|
-
|
270
|
-
replace(
|
271
|
-
'insert linestart',
|
272
|
-
"insert linestart + #{indentation2.size} chars",
|
273
|
-
indentation1
|
274
|
-
)
|
275
|
-
end
|
276
|
-
|
277
|
-
def insert_tab
|
278
|
-
insert :insert, "\t"
|
279
|
-
end
|
280
|
-
|
281
|
-
def eol_then_insert_mode
|
282
|
-
go_end_of_line
|
283
|
-
start_insert_mode
|
284
|
-
end
|
285
|
-
|
286
|
-
def sol_then_insert_mode
|
287
|
-
go_beginning_of_line
|
288
|
-
start_insert_mode
|
243
|
+
def clean_line(index)
|
244
|
+
index = index(index)
|
245
|
+
from, to = index.linestart, index.lineend
|
246
|
+
line = get(from, to)
|
247
|
+
bare = line.rstrip
|
248
|
+
replace(from, to, bare) if bare.empty?
|
289
249
|
end
|
290
250
|
|
291
251
|
def start_insert_mode
|
@@ -293,35 +253,10 @@ module VER
|
|
293
253
|
end
|
294
254
|
|
295
255
|
def start_control_mode
|
256
|
+
clean_line(:insert)
|
296
257
|
self.mode = :control
|
297
258
|
end
|
298
259
|
|
299
|
-
def copy_line
|
300
|
-
copy get('insert linestart', 'insert lineend + 1 chars')
|
301
|
-
end
|
302
|
-
|
303
|
-
def copy_right_word
|
304
|
-
copy get('insert', 'insert wordend')
|
305
|
-
end
|
306
|
-
|
307
|
-
def copy_left_word
|
308
|
-
copy get('insert', 'insert wordstart')
|
309
|
-
end
|
310
|
-
|
311
|
-
# FIXME: nasty hack or neccesary?
|
312
|
-
def paste
|
313
|
-
text = TkClipboard.get
|
314
|
-
paste_continous text
|
315
|
-
|
316
|
-
rescue RuntimeError => ex
|
317
|
-
if ex.message =~ /form "STRING" not defined/
|
318
|
-
array = TkClipboard.get type: Array
|
319
|
-
paste_tk_array array
|
320
|
-
else
|
321
|
-
Kernel.raise ex
|
322
|
-
end
|
323
|
-
end
|
324
|
-
|
325
260
|
def undo
|
326
261
|
edit_undo
|
327
262
|
touch!
|
@@ -335,6 +270,52 @@ module VER
|
|
335
270
|
rescue RuntimeError => ex
|
336
271
|
status.value = ex.message
|
337
272
|
end
|
273
|
+
|
274
|
+
private
|
275
|
+
|
276
|
+
def wrap_lines_of(text, wrap = 80)
|
277
|
+
Kernel.raise ArgumentError, "+wrap+ must be > 1" unless wrap > 1
|
278
|
+
wrap -= 1
|
279
|
+
|
280
|
+
indent = text[/^\s+/] || ''
|
281
|
+
indent_size = indent.size
|
282
|
+
lines = [indent.dup]
|
283
|
+
|
284
|
+
text.scan(/\S+/) do |chunk|
|
285
|
+
last = lines.last
|
286
|
+
last_size = last.size
|
287
|
+
chunk_size = chunk.size
|
288
|
+
|
289
|
+
if last_size + chunk_size > wrap
|
290
|
+
lines << indent + chunk
|
291
|
+
elsif last_size == indent_size
|
292
|
+
last << chunk
|
293
|
+
elsif chunk =~ /\.$/
|
294
|
+
last << ' ' << chunk
|
295
|
+
lines << indent.dup
|
296
|
+
else
|
297
|
+
last << ' ' << chunk
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
lines
|
302
|
+
end
|
303
|
+
|
304
|
+
def status_ask(prompt, options = {}, &callback)
|
305
|
+
@status.ask(prompt, options){|*args|
|
306
|
+
begin
|
307
|
+
callback.call(*args)
|
308
|
+
rescue => ex
|
309
|
+
VER.error(ex)
|
310
|
+
ensure
|
311
|
+
begin
|
312
|
+
focus
|
313
|
+
rescue RuntimeError
|
314
|
+
# might have been destroyed, stay silent
|
315
|
+
end
|
316
|
+
end
|
317
|
+
}
|
318
|
+
end
|
338
319
|
end
|
339
320
|
end
|
340
321
|
end
|