fiatjaf / neuron.vim

📝 Manage your Zettelkasten in {n}vim.
MIT License
83 stars 21 forks source link

support as_folgezettel parameter for insert_new_from_cword and insert_new_from_visual #59

Closed lehmacdj closed 2 years ago

lehmacdj commented 3 years ago

Allow these two methods to optionally only create a normal link.

I also fix a bug: If one considers the following text (^ and $ inserted to emphasize the beginning / end of the line, not actually present in text)

^test1 test2 test3$

and calls neuron#insert_new_from_cword (or neuron#insert_new_from_visual) at each of these positions there is sometimes bad behavior.

for test1 and test2 the resulting document is currently correct, respectively:

^[[new_id]] test2 test3$

and

^test1 [[new_id]] test3$

but for test3 it is:

^test1 test2[[test3]] $

instead of

^test1 test2 [[test3]]$

as expected.

I also fix this behavior.

Furthermore I add an .editorconfig file to ensure that tabs/spaces stay intact for this repository and mixed spaces/tabs aren't introduced (of course this does require people to have https://github.com/editorconfig/editorconfig-vim installed.

fiatjaf commented 3 years ago

These are configurable extra commands, right? No default key mappings for them?

Looks good.

lehmacdj commented 3 years ago

Yes, no keymappings, I just generalized the existing function neuron#insert_zettel_new_from_cword/visual to take a paramter as_folgezettel the same way that neuron#insert_zettel_select already does.

The existing mappings pass 1 which maintains the current behavior.

lehmacdj commented 3 years ago

Found another bug with neuron#insert_zettel_new_from_cword/visual.

In cases where there was a single character following the word/selection the previous implementation was inserting the link after the period, because my previous implementation deleted the text before checking if the selection was at the end of the line. After deleting the text when there is exactly one character following the word/selection the cursor is on the last character in the line, thus my check to see if we were at the end of the line fired. Now I'm performing the check before deleting the word/selection thus we can distinguish these two cases.

Tested with cursor positioned on each test* and a, b, c, d in the following example and only exactly the word is replaced with the link with no extraneous changes.

test1 test2 test3
test4.
a b c
d.

I also unified the two functions so that neuron#insert_zettel_new_from_cword now calls neuron#insert_zettel_new_from_visual to reduce duplication.

lehmacdj commented 3 years ago

@fiatjaf or @fenetikm can you take a look at this? I've been using this (and my other PRs) for the past month or so on my patched branch and would prefer to upstream them instead of having to fix them again later (after V2 changes are made for example).

fiatjaf commented 2 years ago

I am very sorry about this @lehmacdj, I don't remember getting the pings for this or for the other PRs you've opened -- and I generally notice since I don't get many notifications on GitHub.

Either there was a failure on GitHub or on my brain, which is not unlikely as I had multiple periods of complete stress and complete lack of time in the past 2 years.

There was also the fact that I was angry with neuron being faded out and replaced by some other system which I didn't have time to learn.

lehmacdj commented 2 years ago

I don't remember getting the pings for this or for the other PRs you've opened -- and I generally notice since I don't get many notifications on GitHub.

No worries, it's super cheap to work off of a fork, just closed these today because I assumed they would never get merged since it's been a year. The past two years have been stressful for most people. 😅

There was also the fact that I was angry with neuron being faded out and replaced by some other system which I didn't have time to learn.

I empathize with this a lot, I still haven't migrated to emanote (and might never).