Monday, March 13, 2023

Re: E121: Undefined variable

On Mo, 13 Mär 2023, Jose Caballero wrote:

> Hello,
>
> I have this function [*].
> It is meant to create a line when opening a new file with extension
> .pan, where that line is based on the path of the file.
> That code works on my personal computer, with VIM 9.0.1023
> However, it fails on the computer at work where it has to run, with VIM 7.4.629
> I get this error [**].
>
> Is there an easy way to make it work with version 7.4?
>
> Thanks a lot in advance.
> Cheers,
> Jose
>
>
> [*]
> function! CreatePanFile()
> let path = expand('%:p:h')
> let file = expand('%:t:r')
> let features_idx = match(path, 'features')
> if features_idx != -1
> let features_path = substitute(path[features_idx:],
> '\v(features\/.*)$', '\1', '')
> let line = "template '" . features_path . "/" . file . "';"
> call setline(1, line)
> endif
> endfunction
> autocmd BufNewFile *.pan call CreatePanFile()
>
> [**]
> Error detected while processing function CreatePanFile:
> line 5: E121: Undefined variable: features_idx:
> E116: Invalid arguments for function substitute(path[features_idx:],
> '\v(features\/.*)$', '\1', '')
> E15: Invalid expression: substitute(path[features_idx:],
> '\v(features\/.*)$', '\1', '')
> line 6: E121: Undefined variable: features_path
> E15: Invalid expression: "template '" . features_path . "/" . file . "';"
> line 7: E121: Undefined variable:
> line E116: Invalid arguments for function setline

looks like Vim thinks the ':' belongs to the variable name.

I think it should work, if you add parenthesis around it like this:

#v+
substitute(path[(features_idx):],'\v(features\/.*)$', '\1', '')
#v-

Best,
Christian
--
Verdoppeln sie den Platz auf Ihrer Festplatte: Löschen sie Windows!

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ZA8t4mrhdGYRAu2w%40256bit.org.

No comments: