bpstahlman / txtfmt

Txtfmt (The Vim Highlighter) : "Rich text" highlighting in Vim! (colors, underline, bold, italic, etc...)
MIT License
49 stars 2 forks source link

Error E218 (autocommand nesting too deep) generated when user follows Notes plugin's suggestion for enabling Txtfmt "nesting" within note #10

Open bpstahlman opened 8 years ago

bpstahlman commented 8 years ago

Reported by @pdoak with the caveat that it may not be a Txtfmt issue. Initial analysis suggests it is not a Txtfmt issue, but rather a problem with the instructions in the Notes plugin documentation. In particular, the Notes documentation suggests that users put this... setlocal filetype=notes.txtfmt ...inside an after/ftplugin/notes.vim in the runtime path. But this appears to create a sort of infinite loop:

  1. The initial setlocal filetype=notes (from xolox#notes#edit) causes after/ftplugin/notes.vim to be sourced.
  2. The setlocal in after/ftplugin/notes.vim eventually causes notes ftplugin to be re-sourced.
  3. The re-sourcing of the notes ftplugin causes after/ftplugin/notes.vim to be re-sourced.
  4. Steps 2 and 3 repeated until E218 is triggered...

Possible Solution: Instead of using after/ftplugin/notes.vim to set filetype, use a FileType autocommand to substitute "notes.txtfmt" for "notes": E.g.,

augroup TxtfmtInNotes
au!
au FileType * if expand("<amatch>") == "notes" | setlocal ft=notes.txtfmt | endif
augroup END

Note: If the autocommand is defined in the user's vimrc, the au FileType... line is probably sufficient: i.e., the augroup is probably unnecessary, since its sole purpose is to prevent redefinition of the autocommand, but vimrc should never be sourced more than once.

TODO: Communicate all this to @xolox (author of Notes plugin), and see whether he concurs, and if so, whether he'd be willing to update the instructions in the Notes docs...

pdoak commented 8 years ago

@bpstahlman thanks for looking into this and suggesting a solution. It is exactly what I was looking for.

bpstahlman commented 8 years ago

@pdoak: No problem. Were you able to confirm that it works for you?

pdoak commented 8 years ago

@bpstahlman: yes it does. Thank you.

bpstahlman commented 8 years ago

No problem. I'll see whether Peter Odding is willing to update the suggestion in the Notes documentation to prevent others having the same issue. I'm really not sure how that approach ever would have worked, but I'm thinking it must have at some point, since the Notes plugin author probably would have tried it. Perhaps a change in Notes, Txtfmt and/or Vim itself broke it at some point...

On Sat, Apr 30, 2016 at 12:16 PM, pdoak notifications@github.com wrote:

@bpstahlman https://github.com/bpstahlman: yes it does. Thank you.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/bpstahlman/txtfmt/issues/10#issuecomment-215979813

ghost commented 7 years ago

When reopening notes, formatting is not initially displayed until the file is written, than confirm overwrite, than console return....

bpstahlman commented 7 years ago

@bluTaz I'm not sure exactly what you mean. Are you saying that whenever you open a Txtfmt-enabled Notes file, the highlighting isn't displayed until after you've subsequently written the file? "Confirm overwrite" what exactly? And I'm not sure what you mean by "console return".

Also, how are you enabling Txtfmt in Notes files?

Guitarflier commented 7 years ago

I appreciate both Notes and Txtfmt plugins and trying without success for the time to use 'em together. Established that, as stated in this page's initial post, the solution given in Notes documentation does not work, it seemed in my case that FyleType autocommand solution could be working, in that it declares a 'notes.txtfmt' ft in Vim status bar, immediatlely after opening a new :Note buffer. And I was happy with that. But, here's the bad, I soon after realized that txtfmt plugin had really not loaded, since no mapped command is working. What's funny is that doing again :setlocal ft=notes.txtfmt (which is supposed to have already been done by the suggested autocommand) everything gets properly loaded. In other words it looks like the autocommand in my case works in changing filetype but not loading the txtfmt plugin. Any further suggestion on this? Thanks

bpstahlman commented 7 years ago

It seems that something may have changed since I proposed the solution described earlier in this thread. In order to make it work now, I have to have both the setf in after/ftplugin/notes.vim and the setf in the FileType autocmd (defined in my vimrc). This seems like overkill. I'll research and post when I have a better solution. In the meantime, you might try the heavy-handed approach as a workaround. Sorry for the inconvenience...

bpstahlman commented 7 years ago

Actually, I can't reproduce the issue after all... Do you have something like the following in your vimrc?

augroup TxtfmtInNotes
au!
au FileType * if expand("<amatch>") == "notes" | setlocal ft=notes.txtfmt | endif
augroup END

If so, then perhaps you could capture some debug output like so...

:redir >/tmp/notes.dbg
set verbose=9
:Note
set verbose=0
:redir END

...and upload the file (or send to me at brettstahlman AT gmail DOT com)...

Incidentally, are you using the latest version of Txtfmt (v3.1)?

Thanks, Brett S.

Guitarflier commented 7 years ago

@bpstahlman thank you for your nice job. Eventually I got both notes and txtfmt plugins being able to work together thanks to this line: runtime! ftplugin/txtfmt.vim ftplugin/txtfmt_*.vim ftplugin/txtfmt/*.vim in /.vim/after/ftplugin/notes.vim as suggested by https://stackoverflow.com/users/813602/ingo-karkat in this https://stackoverflow.com/questions/45717502/vims-dot-separated-double-filetype-fashion thread that I started. By the way, I beg your pardon, could you tell me how to check for the currently installed version of a plugin, and also, could you be a little more desciptive in how to take the debug file you asked for above? Sincerely Daniele

bpstahlman commented 7 years ago

You can check the version with... :echo Txtfmt_Version The latest is 3.1. Incidentally, if you do have the latest, you should probably use the quick-start guide and/or tutorial on the download page to familiarize yourself with the "visual maps" feature. Visual maps represent a paradigm shift in the creation of highlighting regions, but the feature is not yet documented in the Txtfmt help file...

As for the debug commands outlined in my earlier response... Here they are again with explanations interspersed...

" Disable Vim's pager, so you won't have to hit Spacebar after every screen of output.
:set nomore
" Redirect all Vim output to file /tmp/notes.dbg
:redir >/tmp/notes.dbg
" Cause Vim to output a lot of debug information when you execute the :Note command.
:set verbose=9
" Create a note.
:Note
" Disable the extra debug information
:set verbose=0
" Stop redirecting Vim output to file.
:redir END
" Restore normal paging
:set more

Note: At this point, the file /tmp/notes.dbg (or whatever you called it) should have lots of output I can use to see what's happening when you create a note with the :Note command...

Guitarflier commented 7 years ago

Ok, grateful for your patience. Yes, I'm using Txtfmt 3.1. Here I need to premise that BEFORE taking the dbg I set up everything like it was after reading your first suggestion in this post, i.e. putting augroup TxtfmtInNotes au! au FileType * if expand("<amatch>") == "notes" | setlocal ft=notes.txtfmt | endif augroup END in my vimrc and nothing more. Then I made sure this reproduced the non-functioning of the double plugin loading. After that I had the output in the notes.dbg file that I sent to your email. By the way, you might be in the need to check an italian dictionary while reading through the file... Thank you Regards Daniele

bpstahlman commented 7 years ago

Thanks! I'll post my findings once I've had a chance to investigate fully...