You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know this plugin is designed primarily for prose, but I wanted smart quotes in comments in my code.
I've managed to do this. Currently it looks like this in my .vimrc:
" Smart quotes toggle {{{4function!s:ToggleEducate()
ifg:textobj#quote#educate
silent NoEducate
silentletg:textobj#quote#educate =0" For smart quotes in commentsechom"Smart quotes off"elsesilent Educate
silentletg:textobj#quote#educate =1" For smart quotes in commentsechom"Smart quotes on"endifendfunctionnnoremap<Leader>' :call <SID>ToggleEducate()<Cr>" Smart quotes in comments {{{4function!s:SmartQuotesInComments()
" Respect the setting above, only do smart quotes in comments" If the educate variable is truthyifg:textobj#quote#educate
ifsynIDattr(synID(line('.'),col('.')-1,1),'name') =~? 'comment'exec'silent Educate'elseexec'silent NoEducate'endifendifendfunctionaugroupsmartquotesautocmd!autocmdInsertCharPre*ifindex(textlikeft, &filetype) < 0 |
\ call<SID>SmartQuotesInComments()
\ | endifautocmdInsertLeave*ifindex(textlikeft, &filetype) < 0 |
\ exec'silent NoEducate'\ | endifaugroupEND
I've achieved this by loading the plugin for both text-like and non-text-like file types. For text-like file types, Educate is enabled when loading the plugin.
For non-text-like file types (basically, for source code), the plugin is loaded, but Educate is not enabled. However, the configuration variable is still set to 1 (after plugin init). I figured that the plugin only read it on initialization anyway (i.e. changing it after init doesn't change the plugin's behaviour), so I've reused it for the following purpose:
In non-text-like file types:
if the configuration variable is 1, a function is run before a character is inserted in insert mode. This function checks to see whether we're currently in a piece of text that has a syntax group whose name contains the string comment (case-insentive). If it does, enable Educate. If it does not, disable Educate.
if the configuration variable is 0, don't even check what the current syntax group is, and therefore don't enable Educate
always disable Educate if we leave insert mode.
The result is that I have smart quotes in my code's comments automatically. I am also able to toggle that off in case I need ASCII quotes in my comments (e.g. when typing a string in VimL, before the closing double quote is entered, Vim thinks we're in a comment—if I couldn't toggle Educate for comments I'd go mad).
I developed and tested this on an Asus Transformer Book (T100TA), which has a wimpy little Atom processor. I didn't notice any performance impact.
I thought this might be of interest to others. Perhaps you'd like to add this functionality to your plugin, or mention this in the docs. ☺
The text was updated successfully, but these errors were encountered:
The blacklisting feature in my pencil plugin uses a similar technique of examining the highlight group to determine if Vim's autoformat should be disabled.
I'll mark this as an enhancement for now as I don't have time to look into it deeper.
I know this plugin is designed primarily for prose, but I wanted smart quotes in comments in my code.
I've managed to do this. Currently it looks like this in my
.vimrc
:I've achieved this by loading the plugin for both text-like and non-text-like file types. For text-like file types,
Educate
is enabled when loading the plugin.For non-text-like file types (basically, for source code), the plugin is loaded, but
Educate
is not enabled. However, the configuration variable is still set to1
(after plugin init). I figured that the plugin only read it on initialization anyway (i.e. changing it after init doesn't change the plugin's behaviour), so I've reused it for the following purpose:In non-text-like file types:
1
, a function is run before a character is inserted in insert mode. This function checks to see whether we're currently in a piece of text that has a syntax group whose name contains the stringcomment
(case-insentive). If it does, enableEducate
. If it does not, disableEducate
.0
, don't even check what the current syntax group is, and therefore don't enableEducate
Educate
if we leave insert mode.The result is that I have smart quotes in my code's comments automatically. I am also able to toggle that off in case I need ASCII quotes in my comments (e.g. when typing a string in VimL, before the closing double quote is entered, Vim thinks we're in a comment—if I couldn't toggle
Educate
for comments I'd go mad).I developed and tested this on an Asus Transformer Book (T100TA), which has a wimpy little Atom processor. I didn't notice any performance impact.
I thought this might be of interest to others. Perhaps you'd like to add this functionality to your plugin, or mention this in the docs. ☺
The text was updated successfully, but these errors were encountered: