Comments (9)
There already is a config option that does that:
Lines 813 to 819 in c534f11
You can try it out, my personal thinking is it would end up causing weird issues, but it was added by request, and I haven't heard about problems, so who knows :)
from switch.vim.
This can't work, because both a variable starting with const
and a variable not starting with const
match \([A-Za-z][A-Za-z0-9_:<>]*\)
. If you'd like to make these two work together, you need to add a "not starting with const" clause:
au FileType cpp let g:switch_custom_definitions = [
\ switch#Words(['public', 'private']),
\ switch#Words(['first', 'second']),
\ {
\ 'const \([A-Za-z][A-Za-z0-9_:<>]*\)&': '\1',
\ '\%(const \)\@!\([A-Za-z][A-Za-z0-9_:<>]*\)' : 'const \1&'
\ }
\ ] + g:switch_custom_definitions " this has the other switches that I want to be lower precedence
I've got an explanation for a similar case in the documentation:
Lines 256 to 271 in d9a8cf6
from switch.vim.
That would definitely appear to work for me, thank you for the details! Gosh if only all software maintainers would approach things like you do... programming would be a much more pleasurable trade.
The switch#NormalizedCaseWords(['yes', 'no']),
that I have put into my g:switch_custom_definitions
has been working fine for now.
What I was originally looking for was essentially something I can inject into a specific spot in my ordered list in g:switch_custom_definitions
. But what you've provided is superior to that because now I have the tools to programmatically take g:switch_builtins
and turn it from a dict and splice it as a list into my definition at the location I need, and should I find a desire to further breakdown or adjust their priority order I could customize it straightforwardly as you described.
I guess I should not set g:switch_no_builtins
as the environment is shared by vim buffers (that is my understanding of the g:
VimL variable scoping), until when I inject the builtin definitions into my ordered list for all filetypes. Very useful, you have indeed thought of everything for the config.
Thanks for the assistance :)
from switch.vim.
I tested reversing the order in the list and unfortunately it still grabbed the shorter inner match. I was hoping that it might just take the first match in the list and run with it, which would allow for superior control.
from switch.vim.
Some quick hunting in code reveals switch#match#IsBetter
that indicates to me that it's doing the exact thing that's getting in my way, maybe we can just add a config option to make it dumber and just scan the matches in order of declaration and short circuit?
from switch.vim.
That's spectacular, and I'll report back in particular if it results in other problems.
from switch.vim.
I was able to get my desired behavior working with the following config:
au FileType cpp let g:switch_custom_definitions = [
\ switch#Words(['public', 'private']),
\ switch#Words(['first', 'second']),
\ {
\ 'const \([A-Za-z][A-Za-z0-9_:<>]*\)&': '\1'
\ },
\ {
\ '\([A-Za-z][A-Za-z0-9_:<>]*\)' : 'const \1&'
\ }
\ ] + g:switch_custom_definitions " this has the other switches that I want to be lower precedence
let g:switch_find_smallest_match = 0
However when I set them inside as a pair, like this:
\ {
\ 'const \([A-Za-z][A-Za-z0-9_:<>]*\)&': '\1',
\ '\([A-Za-z][A-Za-z0-9_:<>]*\)' : 'const \1&'
\ },
it does not work properly, it will just keep matching the second one so instead of toggling the const-refness of a type it will just continually add const
to the front and &
to the end. I did also try reversing the order of these but that didn't work.
Could you help me figure out why it behaves that way? I also noticed that even without overriding g:switch_find_smallest_match
this same behavior happens. Indeed without overriding g:switch_find_smallest_match
, separating it out into two entries does not work either, because of course it will always choose the smallest match.
So now I wonder if there is a different mechanism i would need to use to get this working in any capacity without overriding g:switch_find_smallest_match
.
from switch.vim.
Thank you!
One last question: Given the above revelations I can carefully order my switches in terms of priority, which is working well. However, all custom definitions seem to take priority over builtin ones, so now I'm struggling with how to convince it to prioritize the builtin true
/false
switch over my const ref one in cpp files. I would have ran into this even earlier since I also use the camelCase/PascalCase/snake_case/CAPS_CASE/kebab-case switcher, despite it's questionable utility, luckily those regexes do not trigger on single words like true and false, and it has been an eye opening example of what's possible with this plugin.
What do you think? How could we adjust the priority of built in ones to custom ones? Maybe I just add the true/false as another switch#Words entry in the custom list? I don't see any drawbacks with that yet.
from switch.vim.
If you've already put in the work to order things by priority, you could skip the built-in list altogether and try to pick only the parts that interest you. All the definitions are located in a big dictionary:
Lines 21 to 221 in d9a8cf6
So you could, for example, add g:switch_builtins.true_false
to your list. But I guess you also want to stop the built-ins from being loaded, which you can achieve by setting g:switch_no_builtins
to 1:
Lines 358 to 374 in d9a8cf6
Would that work for your use cases?
from switch.vim.
Related Issues (20)
- Switch.vim pollutes search history HOT 2
- help with a bash switch? HOT 6
- Add case insesitivity HOT 2
- Does not working eruby_tag_type in eruby filetype. HOT 4
- [wiki] Anyone know how to write a substitution for React props? HOT 3
- Invert logical expression, using De Morgan Law HOT 1
- "." repeats always forward, even if the last used command was "SwitchReverse" HOT 2
- Undefined variable: g:switch_builtins and invalid expression error on startup when opening a Ruby file and loading the plugin through NeoBundle HOT 2
- Enable js toggles for typescript, typescript.tsx filetypes HOT 2
- switch#NormalizedCase and word boundaries HOT 3
- increase/decrease number HOT 2
- Switching all the flags at once HOT 2
- Possible to call normal commands in switch definition? HOT 10
- Enable switching booleans anywhere on the line and returning to original cursor position HOT 6
- Idea: Multiple switch alternatives HOT 3
- Comparison to swapit HOT 2
- can you please add a configuration example for lua HOT 2
- NormalizedCaseWords does not work for capitalized words HOT 2
- Patch to allow reverse action (and count) in lambda substitutions HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from switch.vim.