new_buffer(mode)
creates a new buffer with mode
m = mode.by_name 'default'
buffer = application\new_buffer m
assert.equal m, buffer.mode
uses the default mode if no mode is specifed
buffer = application\new_buffer!
assert.equal 'default', buffer.mode.name
registers the new buffer in .buffers
buffer = application\new_buffer!
assert.same { buffer }, application.buffers
closes a single untitled buffer if present
config.autoclose_single_buffer = true
application\new_buffer!
buffer = application\new_buffer!
assert.same { buffer }, application.buffers
add_buffer(buffer, show)
adds the buffer to .buffers
buf = Buffer {}
application\add_buffer buf
assert.same {buf}, application.buffers
shows the buffer in the current editor
buf = Buffer {}
application.editor = Editor Buffer {}
application\add_buffer buf
assert.equals buf, application.editor.buffer
does not shows the buffer in the current editor if <show> is false
buf = Buffer {}
application.editor = Editor Buffer {}
application\add_buffer buf, false
assert.not_equals buf, application.editor.buffer
prevents the same buffer from being added twice
buf = Buffer {}
application\add_buffer buf
application\add_buffer buf
assert.equals 1, #application.buffers
open(location, editor)
local editor
before_each ->
editor = Editor Buffer {}
.line_nr specifies a line nr to go to
buffer = Buffer {}
buffer.text = 'one\ntwo\nthree'
application\open {:buffer, line_nr: 2}, editor
assert.equal 2, editor.cursor.line
.column specifies a column to go to
buffer = Buffer {}
buffer.text = 'one'
application\open {:buffer, line_nr: 1, column: 2}, editor
assert.equal 2, editor.cursor.column
.column_index specifies an offsetted column to go to
buffer = Buffer {}
buffer.text = '1\tX'
application\open {:buffer, line_nr: 1, column_index: 3}, editor
assert.equal 3, editor.cursor.column_index
assert.not_equal 3, editor.cursor.column
.byte_column specifies a byte offset within the line to go to
buffer = Buffer {}
buffer.text = 'x\nåäö y'
application\open {:buffer, line_nr: 2, byte_column: 8}, editor
assert.equal 5, editor.cursor.column_index
.byte_column beyond the end of the line goes to the end of the line
buffer = Buffer {}
buffer.text = 'åäö\nx'
application\open {:buffer, line_nr: 1, byte_column: 20}, editor
assert.equal 4, editor.cursor.column_index
highlight any highlights
buffer = Buffer {}
buffer.text = '123456789'
application\open {
:buffer, line_nr: 1, column: 3,
highlights: {
{ start_pos: 2, end_pos: 3 },
{ start_column: 5, end_column: 7, highlight: 'foo' }
}
}, editor
assert.same { 'search' }, highlight.at_pos(buffer, 2)
assert.same {}, highlight.at_pos(buffer, 3)
assert.same { 'foo' }, highlight.at_pos(buffer, 5)
assert.same { 'foo' }, highlight.at_pos(buffer, 6)
(when location.file is given)
opens the file in the specified editor if given
File.with_tmpfile (file) ->
file.contents = 'well hello there'
application\open :file, editor
assert.equal file.contents, editor.buffer.text
returns the newly created buffer
File.with_tmpfile (file) ->
buffer = application\open :file, editor
assert.equal buffer, editor.buffer
adds the buffer to @buffers
File.with_tmpfile (file) ->
buffer = application\open :file, editor
assert.same { buffer }, application.buffers
fires the file-opened signal
with_signal_handler 'file-opened', nil, (handler) ->
File.with_tmpfile (file) ->
application\open :file, editor
assert.spy(handler).was_called!
(.. when <file> is already open)
switches to editor to the existing buffer instead of creating a new one
with_tmpdir (dir) ->
a = dir / 'a.foo'
b = dir / 'b.foo'
buffer = application\open file: a, editor
application\open file: b, editor
application\open file: a, editor
assert.equal 2, #application.buffers
assert.equal buffer, editor.buffer
(when location.buffer is given)
opens the file in the specified editor if given
buffer = Buffer {}
buffer.text = 'my-buf'
application\open :buffer, editor
assert.equal 'my-buf', editor.buffer.text
returns the buffer
buffer = Buffer {}
buf2 = application\open :buffer, editor
assert.equal buffer, buf2
adds the buffer to @buffers
buffer = Buffer {}
application\open :buffer, editor
assert.same { buffer }, application.buffers
.recently_closed
editor = Editor Buffer {}
contains recently closed files
File.with_tmpfile (file) ->
file.contents = 'test'
buffer = application\open_file(file, editor)
application\close_buffer(buffer)
assert.same {file.path}, [f.file.path for f in *application.recently_closed]
does not show open files
File.with_tmpfile (file) ->
file.contents = 'test'
buffer = application\open_file(file, editor)
application\close_buffer(buffer)
application\open_file(file, editor)
assert.same {}, [f.file.path for f in *application.recently_closed]
limits number of saved files to config.recently_closed_limit
howl.config.recently_closed_limit = 1
File.with_tmpfile (file1) -> File.with_tmpfile (file2) ->
file1.contents = 'test'
file2.contents = 'test'
buffer1 = application\open_file(file1, editor)
buffer2 = application\open_file(file2, editor)
application\close_buffer buffer1
application\close_buffer buffer2
assert.same {file2.path}, [f.file.path for f in *application.recently_closed]