Class: Overlay

Inherits:
Object show all
Defined in:
lib/xiki/overlay.rb

Overview

Wrapper around the elisp ‘overlay’.

Represents an overlay and has finder methods for getting overlays for more, see www.gnu.org/software/emacs/elisp/html_node/Overlays.html represents an elisp overlay. the Overlay class finder methods for getting overlays – IMPORTANT NOTES:

start/end have been renamed to left/right respectively

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(elisp_overlay) ⇒ Overlay

Returns a new instance of Overlay.



10
11
12
13
# File 'lib/xiki/overlay.rb', line 10

def initialize(elisp_overlay)
  # raise TypeError.new("argument must be elisp overlay") if overlayp(elisp_overlay)
  @overlay = elisp_overlay
end

Class Method Details

.allObject

returns all overlays for current buffer



39
40
41
# File 'lib/xiki/overlay.rb', line 39

def self.all
  between(View.top, View.bottom)
end

.at(pos) ⇒ Object

returns all overlays that cover pos



49
50
51
52
# File 'lib/xiki/overlay.rb', line 49

def self.at(pos)
  overlays = $el.overlays_at(pos).to_a
  overlays.map { |o| Overlay.new(o) }
end

.between(left, right) ⇒ Object

returns all overlays that contain at least one character between left and right empty overlays are included



33
34
35
36
# File 'lib/xiki/overlay.rb', line 33

def self.between(left, right)
  overlays = $el.overlays_in(left, right).to_a
  overlays.map { |o| Overlay.new(o) }
end

.delete_allObject



93
94
95
96
# File 'lib/xiki/overlay.rb', line 93

def self.delete_all
  $el.overlays_in(View.top, View.bottom).to_a.each{|o| $el.delete_overlay o}
  nil
end

.face(face, options = {}) ⇒ Object

Code Sample: Overlay.face :trailing_whitespace, :what=>:line Apply face to region



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/xiki/overlay.rb', line 80

def self.face(face, options={})
  left ||= options[:left]
  right ||= options[:right]
  if options[:what] == :line or left.nil?
    left, right = Line.left, Line.right+1
  end

  o = Overlay.find_or_make(left, right)
  o[:face] = face
  o
  nil
end

.find_or_make(left, right) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/xiki/overlay.rb', line 58

def self.find_or_make(left, right)
  overlays = on(left, right)
  if overlays.any?
    puts "warning: more than 1 overlay" if overlays.size > 1
    overlays.first
  else
    make(left, right)
  end
end

.find_overlay_by_name(name) ⇒ Object

maybe subclass NamedOverlay what about uniqueness of name?



70
71
72
# File 'lib/xiki/overlay.rb', line 70

def self.find_overlay_by_name(name)
  # search overlays for all overlays with property name
end

.make(left, right) ⇒ Object

create elisp overlay and wrap it in a ruby object



27
28
29
# File 'lib/xiki/overlay.rb', line 27

def self.make(left, right)
  Overlay.new($el.make_overlay(left, right))
end


15
16
17
18
19
20
21
22
23
24
# File 'lib/xiki/overlay.rb', line 15

def self.menu
  "
  - api/
    | Make some text have a style
    @ Overlay.face :underline, :left=>1, :right=>300
    |
    | Remove all overlays
    @ Overlay.delete_all
  "
end

.on(left, right) ⇒ Object

returns all overlays that have left and right exactly



44
45
46
# File 'lib/xiki/overlay.rb', line 44

def self.on(left, right)
  between(left, right).select { |o| o.left == left && o.right == right }
end

.overlays_with(left, right, properties = {}) ⇒ Object



54
55
56
# File 'lib/xiki/overlay.rb', line 54

def self.overlays_with(left, right, properties = {})
  # implementation needed
end

.remove_overlaysObject



74
75
76
# File 'lib/xiki/overlay.rb', line 74

def self.remove_overlays
  # implementation needed
end

Instance Method Details

#[](key) ⇒ Object



164
165
166
# File 'lib/xiki/overlay.rb', line 164

def [] key
  $el.overlay_get(@overlay, key)
end

#[]=(key, val) ⇒ Object



160
161
162
# File 'lib/xiki/overlay.rb', line 160

def []= key, val
  $el.overlay_put(@overlay, key, val)
end

#bufferObject

returns the buffer that overlay belongs to. It returns nil if overlay has been deleted.



99
100
101
# File 'lib/xiki/overlay.rb', line 99

def buffer
  $el.overlay_buffer @overlay
end

#deleteObject

deletes overlay. The overlay continues to exist as a Lisp object, and its property list is unchanged, but it ceases to be attached to the buffer it belonged to, and ceases to have any effect on display. A deleted overlay is not permanently disconnected. You can give it a position in a buffer again by calling move-overlay.



124
125
126
# File 'lib/xiki/overlay.rb', line 124

def delete
  $el.delete_overlay @overlay
end

#invisibleObject

method missing candidate. name space with ‘set’ or ‘propset’



136
137
138
# File 'lib/xiki/overlay.rb', line 136

def invisible
  $el.overlay_get(@overlay, :invisible)
end

#invisible=(arg) ⇒ Object



140
141
142
143
144
145
146
# File 'lib/xiki/overlay.rb', line 140

def invisible=(arg)
  if arg
    $el.overlay_put(@overlay, :invisible, true)
  else
    $el.overlay_put(@overlay, :invisible, nil)
  end
end

#isearch_open_invisible_temporaryObject



148
149
150
# File 'lib/xiki/overlay.rb', line 148

def isearch_open_invisible_temporary
  $el.overlay_get(@overlay, :isearch_open_invisible_temporary)
end

#isearch_open_invisible_temporary=(arg) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/xiki/overlay.rb', line 152

def isearch_open_invisible_temporary=(arg)
  if arg
    $el.overlay_put(@overlay, :isearch_open_invisible_temporary, true)
  else
    $el.overlay_put(@overlay, :isearch_open_invisible_temporary, nil)
  end
end

#leftObject

returns the position at which overlay starts, as an integer.



109
110
111
# File 'lib/xiki/overlay.rb', line 109

def left
  $el.overlay_start @overlay
end

#propertiesObject

returns a copy of the property list.



104
105
106
# File 'lib/xiki/overlay.rb', line 104

def properties
  $el.overlay_properties @overlay
end

#rightObject

returns the position at which overlay ends, as an integer.



114
115
116
# File 'lib/xiki/overlay.rb', line 114

def right
  $el.overlay_end @overlay
end

#to_elispObject

def move end



131
132
133
# File 'lib/xiki/overlay.rb', line 131

def to_elisp
  @overlay
end