preservim / vim-indent-guides

A Vim plugin for visually displaying indent levels in code
MIT License
2.62k stars 162 forks source link

error on execute() when triggered from modeline in neovim #154

Open asdfzdfj opened 1 year ago

asdfzdfj commented 1 year ago

sample error text (slightly edited for readability):

Error detected while processing modelines[2075]
..OptionSet Autocommands for "tabstop"
..function indent_guides#process_autocmds[2]
..indent_guides#enable[8]
..indent_guides#init_script_vars[7]
..indent_guides#capture_highlight:
line    1:
E12: Command not allowed from exrc/vimrc in current dir or tag search
E12: Command not allowed from exrc/vimrc in current dir or tag search
E12: Command not allowed from exrc/vimrc in current dir or tag search

steps to reproduce (approx).:

  1. start nvim with this plugin and modeline enabled
  2. open a file containing modeline (by :e command)

looks like when this plugin is triggered from OptionSet event via modeline, it is run inside sandbox where indent_guides#capture_highlight() function errors out because execute() function is not allowed inside sandbox.

https://github.com/preservim/vim-indent-guides/blob/9a106c73f64b16f898276ca87cd55326a2e5cf4c/autoload/indent_guides.vim#L255-L259

one possible solution is to use some function like synIDattr() and related functions (synIDtrans(), hlID()) to directly query any needed highlight color values instead of execute()ing and parsing :highlight output.
those functions exists in regular vim for quite some time and appears to be sandbox safe, so it should be safe to use.

huyz commented 3 months ago

I get a similar error when I open help in neovim 0.10.0:

Error detected while processing modelines[272]..OptionSet Autocommands for "tabstop"..function indent_guides#process_autoc
mds[2]..indent_guides#enable[8]..indent_guides#init_script_vars[7]..indent_guides#capture_highlight:
line    1:
E12: Command not allowed in secure mode in current dir or tag search
E12: Command not allowed in secure mode in current dir or tag search

PR https://github.com/preservim/vim-indent-guides/pull/158 does fix my problem.