howl.app.editor.buffer\append('\nhello')
.
insert
method that inserts text at the cursor.
To get the editor you just need howl.app.editor
, so this code works for me:
howl.app.editor\insert('hello')
This inserts text at the cursor position
OK, so to finally make it a command:
howl.command.register
name: 'type-hello'
description: 'types "hello" at cursor position'
handler: -> howl.app.editor\insert('hello')
Note that you can just select this snippet in your editor and eval it, the command is immediately registered.
Type alt_x
and press tab, start typing type-h
and you should see the command. You can run it too.
Finally, let's give it a shortcut:
howl.bindings.push
f3: 'type-hello'
Now f3 should invoke your new command. Hope this works.
insert(text, pos)
. Since it takes the position, you need to get the cursor position howl.app.editor.cursor.pos
and pass it in.
local instance_for_mode
in howl.mode
(by means of debug.setupvalue
) to make word_pattern
a config variable
Is there an easy way to get Buffer
- or Editor
-local key bindings, like in other text editors?
I'm writing a language bundle, and its key bindings can only work for a few select languages.
Right now the keymap is global, and I get error messages when I use those keys in other files.
(The bundle "hijacks" keys like delete
, backspace
, enter
...)
Even if I only push the keymap when a specific mode is activated, the issue will still be there if I have more than one file opened.
The only ways (that I can think of) to achieve similar effect is to either
Editor.buffer.file.extension
from within the key handlers and, if not the right one, let the key event propagate further , or*-buffer-switch
and editor-*focused
events, and proactively push/remove the keymap from the bindings stack.One of these will probably get me what I want, but it looks like too much work, compared to what I've used in other editors.
I read the modes docs, and it seems like they can't help either.
So, again, is there an easier way?
~/.howl/bundles/custom_themes
. Make sure your bundle contains an init.moon file where you register your themes.
bindings.push {
editor:
ctrl_slash: 'editor-toggle-comment'
}