2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/xiki/deletes.rb', line 2
def self.delete_whitespace
prefix = Keys.prefix(:clear=>true)
if prefix == :u txt = View.selection :delete=>true
linebreak_on_end = txt[/\n\z/]
txt.gsub! /^ *[+-] /, ''
txt.gsub! /[\n\t ]/, ''
View.insert("#{txt}#{linebreak_on_end}", :dont_move=>true)
return
end
was_blank = Line.blank?
was_at_end = (Line.at_right? and (! was_blank))
was_at_beginning = (Line.at_left? and (! was_blank))
if was_blank elsif was_at_end
$el.forward_char
elsif was_at_beginning and not View.char =~ /\s/
$el.backward_char
else $el.delete_horizontal_space
View.insert(" " * prefix) if prefix
return
end
$el.delete_blank_lines if Line.blank?
$el.delete_char(1) if Line.blank?
Deletes.backward if was_at_end
if was_at_beginning
Deletes.backward if Line.at_left?
$el.delete_char(1) if Line.at_right?
end
if was_blank
if prefix
View.insert("\n" * prefix)
Move.backward prefix
end
else
$el.delete_horizontal_space
View.insert(" " * prefix) if prefix
end
end
|