-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error with Chinese (possibly other multibye) characters #1
Comments
Multibyte characters are tricky :). I should remember to test my plugins with them more often. I've pushed some commits that should fix this, could you check it out and confirm that it works now? |
The update works OK now. one more thing I notice is case matching. |
There's really no way to somehow automatically detect capitalization. The plugin attemts to do a substitution, and that respects your Still, the |
I disagree on this one. I have some sample code from vim-cycle: function! s:imitate_case(text, reference) "{{{
if a:reference =~# '^\u*$'
return toupper(a:text)
elseif a:reference =~# '^\U*$'
return tolower(a:text)
else
let uppers = substitute(a:reference, '\U', '0', 'g')
let new_text = tolower(a:text)
while uppers !~ '^0\+$'
let index = match(uppers, '[^0]')
if len(new_text) < index
break
endif
let new_text = substitute(new_text, '\%' . (index + 1) . 'c[a-z]', toupper(new_text[index]), '')
let uppers = substitute(uppers, '\%' . (index + 1) . 'c.', '0', '')
endwhile
return new_text
endif
endfunction "}}}
from neocomplcache " Convert words.
if neocomplcache#is_text_mode() "{{{
let convert_candidates = filter(copy(complete_words),
\ "get(v:val, 'neocomplcache__convertable', 1)")
if a:cur_keyword_str =~ '^\l\+$'
for keyword in convert_candidates
let keyword.word = tolower(keyword.word)
let keyword.abbr = tolower(keyword.abbr)
endfor
elseif a:cur_keyword_str =~ '^\u\+$'
for keyword in convert_candidates
let keyword.word = toupper(keyword.word)
let keyword.abbr = toupper(keyword.abbr)
endfor
elseif a:cur_keyword_str =~ '^\u\l\+$'
for keyword in convert_candidates
let keyword.word = toupper(keyword.word[0]).
\ tolower(keyword.word[1:])
let keyword.abbr = toupper(keyword.abbr[0]).
\ tolower(keyword.abbr[1:])
endfor
endif
endif"}}}
|
Imagine I have the following definition: let g:switch_definitions =
\ [
\ {
\ '\<\(\k\+\)\>': '@_\1',
\ '@_\(\k\+\)\>': '\1',
\ }
\ ] This changes between This is what I meant when I said that it's impossible to detect capitalization -- it's impossible to correctly detect capitalization, since in many cases, capitalization holds meaning. For an example closer to what vim-cycle would do, consider It may be possible to normalize case on a pattern-by-pattern basis, but I'd have to change the API and somehow put in a flag, and I don't think that this is a case that would be worth the complexity. Incidentally, I didn't actually see this function in the As for neocomplcache, I haven't really experimented with the code, but it seems like it's simply attempting to match two strings together, by trying out A thread on reddit that discusses this can be found here. The general thoughts there are that you can define the very patterns to hold the information. They get a bit complicated, but that's a lot better than any automatic transformation that I can think of on the plugin side. There's also a |
The answer depends on the grand goal of this plugin. For this particular case, I am thinking of context (filetype, syntax, etc. ) to trigger the switch.
Capitalization match is triggered only for text context. and I am not talking about weird heuristics to imitate case; check capitalization for the first letter usually is good enough. |
You should have mentioned that earlier :). Both examples you gave seem to do more than just that, so I assumed you wanted a more complete solution. In any case, this still can't be done for all patterns. The solution you propose -- to separate "text" and "code" doesn't look viable to me at all. There are a lot of file formats out there, many of which are not built into Vim. It's completely impossible for me to separate them, especially "comment" and "text" areas in code. Spellchecking is a good example of something that works exactly that way, but that's encoded in the syntax files, each of which is maintained by a different person. It's not feasible for me to attempt to do something like this in the plugin. I could make the separation a job for the user -- make them set variables with filetypes they use as "text" and as "code", but that goes in the realm of yak shaving, I think -- you need to set a list of filetypes in order for the plugin to figure out if it's code or text in order to take care of capitalization... And even so, there's no guarantee that you wouldn't want a particular pattern to behave differently. Making the transformation automatic for one or the other case means taking the freedom of the user to choose one or the other. As for the user's choice in this matter, it's possible to simply duplicate the patterns: let g:switch_definitions =
\ [
\ { '\Ctrue': 'false', '\Cfalse': 'true' },
\ { '\CTrue': 'False', '\CFalse': 'True' },
\ ] Admittedly, this makes them more complicated and makes it impossible to use the shorthand form of the plugin. A compromise I propose is something like this: let g:switch_definitions =
\ [
\ ['normalize_case', ['true', 'false']]
\ ] And this pattern would capitalize the first letter if it has to. I can probably implement it easily by simply duplicating the patterns -- getting the form I described above. Considering I'm probably going to make more complicated ways to define patterns anyway, this seems like a reasonable start. I could add additional transformation flags (that I may think of in the future) in the list, having the last item be the actual switch definition. That way, the shorthand version remains the same, but if you want some additional tweaks to the pattern, you can do that as well in this new form. What do you think? |
Hi, just for information: I've asked @mjbrownie and @zef for borrowing the name, and we felt okay at that time. |
The text was updated successfully, but these errors were encountered: