alexherbo2 / auto-pairs.kak

Auto-pairing of characters for Kakoune
https://kakoune.org
77 stars 18 forks source link

auto-pairs and VHDL file type insert-on-new-line commands. #45

Closed m-kru closed 3 years ago

m-kru commented 3 years ago

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?

alexherbo2 commented 3 years ago

Does it still happen with the new version?