Skip to content

Tag renaming#193

Merged
lervag merged 3 commits intolervag:masterfrom
anjiro:tagrename
Oct 29, 2021
Merged

Tag renaming#193
lervag merged 3 commits intolervag:masterfrom
anjiro:tagrename

Conversation

@anjiro
Copy link
Copy Markdown
Contributor

@anjiro anjiro commented Oct 26, 2021

This PR adds functionality to rename tags. Some highlights:

tags.vim:

  • wiki#tags#rename(old_tag, new_tag='', rename_to_existing=0)
    The main renaming function. The rename_to_existing parameter forces a tag to be renamed even if the new name already exists (implemented primarily for non-interactive testing).
  • wiki#tags#rename_ask(old_tag='', new_tag='', ...)
    The user-facing rename function, called by the WikiTagRename command. Prompts for one or both parameters.
  • wiki#tags#get_tag_names(...)
    Returns a list of tag names from the cache. Used for completion by WikiTagRename.
  • g:wiki#tags#default_parser.make(taglist, curline='')
    Required to construct a new buffer line containing the updated tag name.

buffer.vim:

  • Command WikiTagRename
  • Default mapping: <leader>wsn<plug>(wiki-tag-rename)

Tests:

  • Added test cases for renaming tags to test-tags/test-defaults.vim and test-tags/test-custom-yaml.vim

There is some overlap in functionality between tags.vim:394-407,420-424 and page.vim:118-132,137-141, but I wasn’t sure if it was worth pulling out into a third file.

Copy link
Copy Markdown
Owner

@lervag lervag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, this is quite impressive. I do have some comments. I'll probably make minor adjustments myself, so feel free to ignore the trivial comments if you find me too pedantic. :p

In general, it seems this is pretty much ready for merging, but there a couple of important comments to discuss:

  • Version requirement due to optional function args.
  • Use customlist instead of custom for completion and adjust the get_tag_names output to list instead of string?

I think the overlap between page.vim and tags.vim is OK for now. I agree this could probably be generalised, but let's be pragmatic.

endfunction

" }}}1
function! wiki#tags#rename(old_tag, new_tag='', rename_to_existing=0) abort " {{{1
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I was not aware of the default value syntax. It seems it was introduced quite recently? I like it, but it does set a requirement to the users to use Vim 8.1 and/or neovim 0.5. Is that OK? I never did specify a version requirement...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m a Python programmer so default args like that make me happy. It would be simple to change it to use instead, but not as nice looking. I have no sense of what versions people are using currently; it seems like one would naturally use an up-to-date Vim for one’s personal wiki? But… 🤷

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also quite used to Python, and I tend to like this syntax myself. I would not mind to accept this, but we should add a comment in the README and docs about version requirement.

@anjiro
Copy link
Copy Markdown
Contributor Author

anjiro commented Oct 28, 2021

I will attack any pedantry-related changes and anything else when I have some time, possibly during the weekend; or of course feel free to do it for me 😉.

lervag added a commit that referenced this pull request Oct 29, 2021
@lervag lervag merged commit e584c6d into lervag:master Oct 29, 2021
@lervag
Copy link
Copy Markdown
Owner

lervag commented Oct 29, 2021

Thanks! I've merged this now. Very nice work, I appreciate the contribution!

lervag added a commit that referenced this pull request Nov 1, 2021
@lervag
Copy link
Copy Markdown
Owner

lervag commented Nov 1, 2021

FYI: I've reverted the modern optional arg syntax due to #194.

@anjiro
Copy link
Copy Markdown
Contributor Author

anjiro commented Nov 1, 2021

Yes, makes sense, the nicer syntax probably isn't worth the compatibility issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants