Skip to content
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 on execute() when triggered from modeline in neovim #154

Open
asdfzdfj opened this issue Mar 16, 2023 · 1 comment · May be fixed by #158
Open

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

asdfzdfj opened this issue Mar 16, 2023 · 1 comment · May be fixed by #158

Comments

@asdfzdfj
Copy link

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.

function! indent_guides#capture_highlight(group_name) abort
let l:output = execute('hi ' . a:group_name, 'silent')
let l:output = substitute(l:output, '\n', '', '')
return l:output
endfunction

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.

Boolean263 added a commit to Boolean263/vim-indent-guides that referenced this issue Jun 14, 2023
Instead of using `execute()` to get the foreground and background
colours of a colour scheme, use [`synIDattr()`][1] and related
functions. This prevents an E12 error when using this plugin in neovim
to edit a file which has a [modeline][2].

Tested in neovim 0.9.0 and vim 8.2.

[1]: https://vimhelp.org/builtin.txt.html#synIDattr%28%29
[2]: https://vimhelp.org/options.txt.html#modeline
@Boolean263 Boolean263 linked a pull request Jun 14, 2023 that will close this issue
@huyz
Copy link

huyz commented Jun 13, 2024

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 #158 does fix my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants