Fork me on GitHub
#vim
<
2022-08-26
>
Richard Bowen06:08:59

For prettifying only when I hit a key combination, what do you recommend?

Martynas Maciulevičius06:08:39

=ap? (try vap to see what region it does it for)

James Amberger23:08:47

I use vim-sexp and fireplace and I fear I’m not really grokking the structural editing. It seems, for example, that pasting an element into a form takes tons of keystrokes. I can yank the form yafbut when I paste it, whether the elements are on a line or one per line, I end up doing manual formatting of one kind or another. In the inline case the least I would expect is thatpasting leaves spaces around the element analogously to yaw or yas followed by p in some prose. What am I missing?

nate00:08:55

Do you have some small examples to show what is happening? I do a lot of structural editing. Sometimes, the formatting can get wonky, and I hit =- to reformat the top level form. I think that mapping is provided by vim-sexp.

☝️ 1
James Amberger00:08:24

Yes, I will provide examples ASAP. Thanks!

James Amberger12:08:31

ok on further reflection at least part of the problem was using the wrong text object. vim-sexp has ae and ie for elements

James Amberger13:08:33

Still though…

(here is a [form  with a] final-element)
(another-form 1 2)
If I try yae on final-element followed by j$P I get the expected result: (another-form 1 2 final-element) but if instead I do j^p I get ( final-elementanother-form 1 2) which is not good. Also the af object doesn’t seem to have great behavior. Given the same example if I yaf on the inner vector and then put the cursor on the 1 and press p I get (another-form 1[form with a] 2)

James Amberger13:08:00

The vim-sexp doc does state that the af text object includes the delimiting brackets and not the whitespace but like… that’s not good, right?

nate17:08:59

wow, very interesting. I've actually never used the text objects that vim-sexp provides. Reading about them now and trying a few out might inspire me to use them more.

nate17:08:29

The af not including surrounding whitespace is inconsistent with ae, but I think for good reason. forms can be elements (like the inner vector), but elements can never be forms. The element yanking includes whitespace because you are expected to be putting it into another form. Form yanking could be so that the form will stand alone, so the whitespace isn't included. If, as you asked in your second example, you want to put that form into another as an element, then you'll have to supply the extra whitespace.

nate17:08:46

In the first case (`( final-elementanother-form 1 2)`), the plugin is following these rules: https://github.com/guns/vim-sexp/blob/master/doc/vim-sexp.txt#L125-L136. Perhaps the beginning whitespace is included in ae because it's assumed that if that element is last it will be last where pasted. I don't know the logic of the whitespace inclusion rules. What I would do in that case is yie most of the time and then paste and add whitespace as needed.

James Amberger20:08:02

well, as you say a form can be an element, so I can pick up some whitespace by putting the cursor on the bracket, ( perhaps, and then yae

nate21:08:54

Yes, definitely.

🙂 1