Class: Relisp::Buffer
- Inherits:
-
Proxy
show all
- Defined in:
- lib/relisp/type_conversion/editing_types.rb
Overview
A proxy to an Emacs buffer.
Instance Attribute Summary
Attributes inherited from Proxy
#elisp_variable, #slave
Instance Method Summary
collapse
-
#<<(object) ⇒ Object
-
#==(buffer2) ⇒ Object
-
#alive? ⇒ Boolean
-
#bury ⇒ Object
-
#chars_modified_tick ⇒ Object
-
#erase ⇒ Object
-
#filename ⇒ Object
Return name of file that the Buffer is visiting, or nil if none (buffer-file-name).
-
#filename=(newname, along_with_file = false) ⇒ Object
Change name of file visited in the Buffer to newname.
-
#initialize(*args) ⇒ Buffer
constructor
args can be any of these forms: * (symbol, slave = Relisp.default_slave) * (string, slave = Relisp.default_slave) * (slave = Relisp.default_slave).
-
#insert(object) ⇒ Object
(also: #print)
-
#kill ⇒ Object
-
#kill! ⇒ Object
-
#method_missing(method, *args) ⇒ Object
-
#modified=(flag) ⇒ Object
-
#modified? ⇒ Boolean
-
#modified_tick ⇒ Object
-
#name ⇒ Object
Return the name of Buffer, as a string (buffer-name).
-
#puts(object = "") ⇒ Object
-
#read_only=(flag) ⇒ Object
-
#read_only? ⇒ Boolean
-
#rename(newname, unique = false) ⇒ Object
Change current buffer’s name to newname (a string).
-
#save ⇒ Object
Save the buffer in its visited file, if it has been modified (save-buffer).
-
#set ⇒ Object
-
#set_modified(flag = true) ⇒ Object
-
#size ⇒ Object
-
#substring(start_position, end_position) ⇒ Object
-
#substring_no_properties(start_position, end_position) ⇒ Object
-
#to_s ⇒ Object
-
#window ⇒ Object
-
#window=(new_window) ⇒ Object
-
#windows ⇒ Object
-
#write(newfile) ⇒ Object
Methods inherited from Proxy
from_elisp, #to_elisp
Constructor Details
#initialize(*args) ⇒ Buffer
args can be any of these forms:
-
(symbol, slave = Relisp.default_slave)
-
(string, slave = Relisp.default_slave)
-
(slave = Relisp.default_slave)
When a symbol is given it is considered to be the name of a pre-existing bufer in the slave process. Otherwise a new buffer is created (generate-new-buffer). The name is string, if given, and a variant of “relisp-buffer” otherwise.
64
65
66
67
68
69
70
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 64
def initialize(*args)
super do |args|
name = args[0] ? args[0] : "relisp-buffer"
raise ArgumentError unless name.kind_of?(String)
@slave.elisp_exec( "(setq #{@elisp_variable} (generate-new-buffer #{name.to_elisp}))" )
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
247
248
249
250
251
252
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 247
def method_missing(method, *args)
@slave.save_excursion do
set
@slave.send(method, *args)
end
end
|
Instance Method Details
#<<(object) ⇒ Object
234
235
236
237
238
239
240
241
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 234
def <<(object)
@slave.save_excursion do
set
@slave.elisp_eval "(goto-char (point-max))"
insert object
end
return self
end
|
#==(buffer2) ⇒ Object
243
244
245
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 243
def ==(buffer2)
@slave.elisp_eval "(equal #{to_elisp} #{buffer2.to_elisp})"
end
|
#alive? ⇒ Boolean
172
173
174
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 172
def alive?
call_on_self :buffer_live_p
end
|
155
156
157
158
159
160
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 155
def bury
call_on_self :bury_buffer
if @slave.elisp_eval "(equal (current-buffer) #{self.to_elisp})"
@slave.elisp_exec "(switch-to-buffer (other-buffer))"
end
end
|
#chars_modified_tick ⇒ Object
143
144
145
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 143
def chars_modified_tick
call_on_self :buffer_chars_modified_tick
end
|
204
205
206
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 204
def erase
eval_in_buffer "(erase-buffer)"
end
|
Return name of file that the Buffer is visiting, or nil if none (buffer-file-name).
107
108
109
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 107
def filename
call_on_self :buffer_file_name
end
|
#filename=(newname, along_with_file = false) ⇒ Object
Change name of file visited in the Buffer to newname. This also renames the buffer to correspond to the new file. The next time the buffer is saved it will go in the newly specified file. newname nil or an empty string means mark buffer as not visiting any file.
The optional along_with_file, if non-nil, means that the old visited file has been renamed to newname (set-visited-file-name).
121
122
123
124
125
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 121
def filename=(newname, along_with_file=false)
eval_in_buffer "(set-visited-file-name #{newname.to_elisp} t #{along_with_file.to_elisp})"
end
|
#insert(object) ⇒ Object
Also known as:
print
220
221
222
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 220
def insert(object)
eval_in_buffer "(insert #{object.to_elisp})"
end
|
162
163
164
165
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 162
def kill
raise if modified?
call_on_self :kill_buffer
end
|
167
168
169
170
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 167
def kill!
set_modified(false)
kill
end
|
#modified=(flag) ⇒ Object
135
136
137
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 135
def modified=(flag)
set_modified(flag)
end
|
#modified? ⇒ Boolean
127
128
129
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 127
def modified?
call_on_self :buffer_modified_p
end
|
#modified_tick ⇒ Object
139
140
141
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 139
def modified_tick
call_on_self :buffer_modified_tick
end
|
Return the name of Buffer, as a string (buffer-name).
90
91
92
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 90
def name
call_on_self :buffer_name
end
|
#puts(object = "") ⇒ Object
226
227
228
229
230
231
232
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 226
def puts(object="")
line_number = @slave.line_number_at_pos
insert object
if line_number == @slave.line_number_at_pos
insert "\n"
end
end
|
#read_only=(flag) ⇒ Object
151
152
153
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 151
def read_only=(flag)
eval_in_buffer "(setq buffer-read-only #{flag.to_elisp})"
end
|
#read_only? ⇒ Boolean
147
148
149
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 147
def read_only?
eval_in_buffer "buffer-read-only"
end
|
#rename(newname, unique = false) ⇒ Object
Change current buffer’s name to newname (a string). If unique is nil, it is an error if a buffer named newname already exists. If unique is non-nil, come up with a new name using generate-new-buffer-name' (rename-buffer).
100
101
102
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 100
def rename(newname, unique = false)
eval_in_buffer "(rename-buffer #{newname.to_elisp} #{unique.to_elisp})"
end
|
Save the buffer in its visited file, if it has been modified (save-buffer).
179
180
181
182
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 179
def save
raise "Attempt to save buffer with no filename." unless filename
eval_in_buffer "(with-output-to-string (save-buffer))"
end
|
84
85
86
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 84
def set
@slave.set_buffer(@elisp_variable.value)
end
|
#set_modified(flag = true) ⇒ Object
131
132
133
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 131
def set_modified(flag=true)
eval_in_buffer "(set-buffer-modified-p #{flag.to_elisp})"
end
|
188
189
190
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 188
def size
call_on_self :buffer_size
end
|
#substring(start_position, end_position) ⇒ Object
192
193
194
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 192
def substring(start_position, end_position)
eval_in_buffer "(buffer-substring #{start_position} #{end_position})"
end
|
#substring_no_properties(start_position, end_position) ⇒ Object
196
197
198
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 196
def substring_no_properties(start_position, end_position)
eval_in_buffer "(buffer-substring-no-properties #{start_position} #{end_position})"
end
|
200
201
202
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 200
def to_s
eval_in_buffer "(buffer-string)"
end
|
208
209
210
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 208
def window
call_on_self :get_buffer_window
end
|
#window=(new_window) ⇒ Object
212
213
214
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 212
def window=(new_window)
new_window.buffer = self
end
|
216
217
218
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 216
def windows
call_on_self :get_buffer_window_list
end
|
#write(newfile) ⇒ Object
184
185
186
|
# File 'lib/relisp/type_conversion/editing_types.rb', line 184
def write(newfile)
eval_in_buffer "(with-output-to-string (write-file #{newfile.to_elisp}))"
end
|