alexherbo2 / auto-pairs.kak Goto Github PK
View Code? Open in Web Editor NEWAuto-pairing of characters for Kakoune
Home Page: https://kakoune.org
Auto-pairing of characters for Kakoune
Home Page: https://kakoune.org
v2020.09.01-400-gc507863a
)kakoune.cr
is the latest nightly binarykakrc
: https://github.com/kkga/dotfiles/blob/master/.config/kak/kakrcI'm getting the following issue, as described in the title. Demonstrated in the video below.
I've tried playing with different options and disabling other plugins, but I still get this behavior. The only thing that helps is auto-pairs-disable
.
Appreciate any tips on what could be wrong in my case.
P.S. I'm a new kak convert and just wanted to say thanks for all your plugins! My vimrc was 80% filled with plugins by tpope, and my kakrc is 80% filled with plugins by you :D
When using oksh
as /bin/sh
(which is just a portable version of OpenBSD's ksh
- in fact, this happens with loksh
, another port, and mksh
, so it's affecting all ksh
derivatives), auto-pairs.kak
acts very strangely.
When hitting enter to create a new line, it will create a new line, then indent it, create a new line after the indented line, and then leave your cursor at the indentation point. It also seems to be duplicating spaces once you have leading spaces and hit space multiple times.
Here's a recording demonstrating the problem:
I have a hunch it's the printf
statements printing spaces somewhere in there, resulting in auto-pairs thinking that it needs to "complete" a bracket represented by a
. Looking it though, I'm not quite sure what exactly the problem would be. It could also be related to bash's printf
built-in not being used (and ksh
and friends having no printf
built-in), but I've tested this possibility by replacing printf
usage with /bin/printf
without any differences from this cropping up. I also thought it could be related to busybox's printf
implementation (which is being used, as the system I'm running kak
under uses busybox for coreutils, including printf
), but again, changing out printf
to explicitly use busybox printf
changed nothing, and it worked fine under bash
.
With all plugins except auto-pairs.kak
disabled, this still occurs, so I feel pretty confident the problems lies here.
When I type [
, I expect to see
[ | ]
but lately I've been getting
[ | ]
(where |
is the cursor. Apologies for the block formatting, backtick formatting erases the precise amount of spaces!)
This seems like something that could be auto-pairs, but I'm not 100% sure. Does this seem likely to you? What other info could I provide you to check? I'm running auto-pairs.kak at 3e529e8
:auto-pairs-enable
In normal mode press this: oa=( b c
Result:
a=( b c )
Suppose you have text:
a=b c
Select b c
.
Enable :auto-pairs-surround
.
Press (<space>
Expected:
a=( b c )
Actual:
a=( b c)
When I run :auto-pairs-enable
, it throws this error:
error running hook ModuleLoaded(auto-pairs)/: 2:2: 'auto-pairs-enable' 2:5: 'auto-pairs-save-settings' no such command: '$'
Config-change detected:
Error: 1:1: 'auto-pairs-enable' 2:5: 'auto-pairs-save-settings' no such command: '$'
Hey,
is it possible to use full strings as autopairs? For example if
and fi
in shellscripts.
Thanks for providing this useful plug in!
If I insert something from the system clipboard which has parantheses (or other pairs), I will get redundant closing characters at the end of my paste.
no-hooks
: \i
CTRL-V
or CMD-V
or whatever your system / terminal supportsThank for this nice plugin.
Recently, I have observed an annoying behavior when inserting a new line between some separators on my cpp file.
The cursor is | in the following.
{|}
press Enter:
{
|
}
I would expect the lower bracket to be aligned with the upper one.
This bug seems to depends on the current filetype. It does not occurs on the kakrc
but does occur on cpp
files.
Setup:
Let's have a tracking ticket, I want to be notified when I can use this awesome plugin again ๐
I have problem with defining proper behavior of some file type command when auto-pairs is enabled.
I have following command defined
define-command -hidden vhdl-insert-on-new-line %[
evaluate-commands -save-regs x %[
# Save previous line indent in register x.
try %[ execute-keys -draft k<a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
# Wisely add ");" for "generic (".
evaluate-commands %[
try %[
execute-keys -draft k<a-x> <a-k>^\h*(?i)generic\h*\($<ret> }i<a-x> <a-K>^<c-r>x(\)\;)<ret>
execute-keys -draft o<c-r>x)<semicolon><esc>
]
]
]
When auto-pairs is not enabled, after inserting following sequence
generic (
and hitting enter I end up with:
generic (
<- cursor here
);
When auto-pairs is enabled I always end up with:
generic (
<- cursor here
)
The ;
is missing in the last line. The cursor in both cases is indented one more level, but this is expected and is the result of another command.
I have tried multiple methods to get this command work properly both with and without auto-pairs, but I failed.
Can you help?
Paste this:
'aaa'
'bbb'
Put cursor on the line 'aaa'
.
Press o
.
The line 'aaa'
is selected, but shouldn't.
On the latest kakoune master this key sequence from the new line (<enter>s
throws these errors
error running hook WinSetOption(inserted_pairs=0)/auto-pairs: 3:7: 'unmap': cannot unmap key that is currently executing
error running hook InsertChar(s)/auto-pairs: 2:7: 'unmap': cannot unmap key that is currently executing
I checked it with clear kak -n
only sourcing this plugin.
Any workaround that comes to mind?
I generally enoy using auto-pairs
, but sometimes it is getting in the way. Most of the time it's when I'm editing text, and it starts detecting completely unrelated characters.
I was wondering if it would be possible to somehow configure the following rules:
Right now it seems to me that heuristic would differentiate substantial majority of cases, where I actually don't want auto-pairs to change what I'm inserting.
Hello.
On Kakoune current master (cfbff4e1), it seems auto-pairs have stopped working.
When inserting a "([{'
the counterpart character is not inserted automatically.
Hi,
This is in the README:
map global user S -docstring 'Surround++' ': auto-pairs-surround _ _ * *<ret>'
What is the meaning of auto-pairs-surround parameters? There is no documentation for it.
An explanation for this should at least be added in the README.
Sometimes, when using .
to repeat an edit that includes an auto-pair, the following error appears:
register '^' does not contain a selections desc
Is it possible to introduce some exception rule per file type?
For example in rust it's pretty common to type <'a>
, so when I type <'
I get <''
instead.
So I'd like to have exception like do not auto-pair a single quote if previous char is <
.
Would be cool to select a phrase and make it italic or bold using surround feature.
Are you planning to add support for installing this plugin with Plug?
The current way of putting things into autoload
and installing dependencies by hand is cumbersome, and impossible to put in dotfiles. It would have been so great if users could just say plug alexherbo2/auto-pairs.kak
and try out this project immediately.
This seems like a very useful project. I didn't try it yet (it's too late today already), but will soon!
I noticed that when pasting text in insert mode, the plugin adds an extra "pair" at the end.
For example, if in insert mode I paste the following:
{
}
I get:
{
}
}
Is there anyway to disable this while pasting text?
Thank you for your help!
I'm using your new implementation of autopairs but so far I can't seem to make it work, whenever i type any "pairable" character, it doesn't pair it but when i hit space it kinda matches the indentation downwards, I'm not sure if the last thing is intended, is there a way to disable it?, and why could it be that the plugin is not pairing my input?
Thanks.
Open a new python file:
kak /tmp/foo.py
paste the following:
def f():
bar
foo
But the cursor on the line of hello
and A<ret>
to insert on a new line between bar
and foo
. Type hello world
. You should be in insert mode like so :
def f():
bar
hello world_
foo
Now start deleting with backspace. Continue pressing backspace until the begining of the line.
The line is deleted, the foo
and bar
line are unchanged
Backspace act like backspace+delete, swallowing character on the right side of the cursor. It start by deleting the \n
char. of the hello world
line and then the content of the foo
line.
Hey, thanks for the great plugin!
I'm new to using auto-pairs, so I find myself often typing []
because I forget that auto-pairs will add the closing pair for me. However, when I do this, I end up with []]
, one closing pair for the one inserted by auto-pairs and another for the one that I type. It would be great if it was possible to type "through" the closing pair if it's already there.
I think in addition to me forgetting to use auto-pairs and typing the extra ]
, there are other cases this behavior is helpful. For example, take the following Elm code:
html [] [ span [] [ text "hello" ] ]
Each time I type []
and want to continue typing past the closing pair with auto-pairs enabled, I need to do the following keystrokes:
[ -- Create the bracket (and auto-pairs inserts the closing one)
<esc> -- exit insert mode
l -- move to the right
i -- go back to insert mode
... -- continue typing
However, if I could type "through" the closing bracket I could do:
[ -- Create the bracket (and auto-pairs inserts the closing one)
] -- Don't actually insert the "]", but just move past that character
... -- continue typing, but now I don't need to leave insert mode at all!
I think that this is something VSCode does too.
I have no idea the technical hurdles to achieve this, but it would be cool if it was possible!
Not sure what caused it, but this morning kakoune started inserting spaces,backspaces,returns,and deletes twice. Once before the highlighted character, and once after.
Regression of mawww/kakoune#2861
as of
Kakoune git: 1ebea85e6f07aeb6a8287b8043480f56f0e58edb
auto-pairs.kak git: 1f11e6f
It would be nice not to have this dependency, so that all that's needed for it to work is a plug
command in your kakrc.
In the installation section you mention about 2 options:
auto-pairs.kak
to your autoloador
Which one is done by require-module auto-pairs
?
What does the opposite option look like?
When autopairs is enabled, 'o' no longer moves the insert cursor to the beginning of the next line, instead it selects the current line and adds a new line below the insert point.
For example:
If I type:
ifoobar<Esc>obazfoo
foobabazfoor
appears instead of
foobar
bazfoo
Also, if inserting text when inside a pair, typing whitespace adds additional whitespace after the insert point.
So if I type:
I(foo bar baz bat<Esc>
(foo bar baz bat )
(only one space is showing up in the preformatted text, but there should be three spaces after bat)
appears instead of
(foo bar baz bat)
I kinda get what's happening with that, (the whitespace is one of the pair characters), but I think that should only happen if there aren't any non-whitespace characters between the already paired characters. That is, if I type a left paren, then a whitespace, the balance should be a whitespace, then a right paren. But if I type a left paren and then any non-whitespace character, the balance should only ever be a right paren.
What is the right way to override global auto_pairs
option for specific file type?
For example, I've tried following in order to remove <>
pair:
hook global WinSetOption "filetype=go" %{
set window auto_pairs '(' ')' '{' '}' '[' ']' '"' '"' '''' '''' '`' '`'
}
Echoing, shows that there is no <>
pair, but <
keeps auto paired with >
.
To repro, use the following configuration
plug "alexherbo2/auto-pairs.kak" %{
enable-auto-pairs
}
plug "chambln/kakoune-readline" config %{
hook global WinCreate .* readline-enable
}
Readline keybindings (eg. <a-f>
and <a-b>
) do not work when auto-pairs is enabled.
Since it is impossible to add single quote to the auto_pairs
list, how about coming up with a workaround?
We can agree to represent a single quote as "<q>"
and treat this specially, convert "<q>"
to a single quote directly in shell scripts where auto_pairs
variable is being consumed.
What do you think?
Pressing o does create a new line below the current line, however the cursor does not go to that line. Instead, the current line is selected and the cursor is left at the end.
Unfortunately, the test added in this commit doesn't detect this behavior because it's only checking the contents of the buffer, not the state of the cursor or selection.
[ cmd ] && echo yes
Select cmd
, type :auto-pairs-surround
, press Backspace twice.
Expected:
cmd && echo yes
Actual:
error running hook InsertDelete([)/auto-pairs-surround-delete: 1:1: 'auto-pairs-surround-delete-opener' 2:4: 'execute-keys' no selections remaining
i tried to match '<' '>' but it gave me 'auto-close-pair': wrong argument count
After entering :auto-pairs-enable
command, I expect auto pair completion, but nothing happens.
For example I enter {
and result is the same.
I'm using mac os kakoune version.
It would be nice if inserting the closing character of a pair would skip over whitespace (including new lines) if the character is already in place. Example:
Buffer:
void main() {
return 0;|
}
Input: }
Result:
void main() {
return 0;
}|
I tried to implement this like so:
define-command -hidden -params 2 auto-pairs-insert-closer %{ try %{
execute-keys -draft "hf%arg(2)<a-k>\Q%arg(2)\E\s*\Q%arg(2)<ret>"
execute-keys -with-hooks "<backspace><esc>hf%arg(2)a"
}}
but it results in a bunch of extra selection and doesn't work twice in a row (without leaving insert mode) because hooks aren't executed recursively.
Is there a better way to accomplish this with Kakoune's awkward scripting?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.