Re: Access class member from command line
Yeah, all variables within vim9script seem script-local. If you want to access them in the command line, you'd have to prefix them with the scopes in :h eval.txt — global, window, and buffer all work. Best, Igbanam On Sun, May 5, 2024 at 2:39 PM Lifepillar wrote: > Let's say I have this class in some `foo.vim` file: > > export class Config > public static var option = false > endclass > > Now, I'd like to set `Config.option` to `true` from a script and from > the command line. From a script, I can do this: > > import `foo.vim` > > type FooConfig = foo.Config > FooConfig.option = true > echo FooConfig.option # OK > echo foo.Config.option # Also works > > Unfortunately, this gives an error (Undefined variable Config): > > foo.Config.option = true > > But how do I access the class member from the command line? Is that even > possible? > > Context: I'm exploring alternatives to `g:myplugin_option` to configure > a script without using global variables. > > Thanks, > Life. > > -- > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/vim_use/v1826l%24m0o%241%40ciao.gmane.io > . > -- -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAOmRJrcLVHMM9bVJKvbAHjHvKOH1wi9fULf74jzexQS7u4V9tg%40mail.gmail.com.
Re: Access class member from command line
Looks like a bug. Should be able to do `foo.Config.option = true` ``` Items in a class ~ *E1318* *E1325* *E1388* Inside a class, in between `:class` and `:endclass`, these items can appear: - An object variable declaration: > var _protectedVariableName: memberType var readonlyVariableName: memberType public var readwriteVariableName: memberType - A class variable declaration: > static var _protectedClassVariableName: memberType static var readonlyClassVariableName: memberType public static var readwriteClassVariableName: memberType ``` On Sunday 5 May 2024 at 15:39:53 UTC+2 Lifepillar wrote: > Let's say I have this class in some `foo.vim` file: > > export class Config > public static var option = false > endclass > > Now, I'd like to set `Config.option` to `true` from a script and from > the command line. From a script, I can do this: > > import `foo.vim` > > type FooConfig = foo.Config > FooConfig.option = true > echo FooConfig.option # OK > echo foo.Config.option # Also works > > Unfortunately, this gives an error (Undefined variable Config): > > foo.Config.option = true > > But how do I access the class member from the command line? Is that even > possible? > > Context: I'm exploring alternatives to `g:myplugin_option` to configure > a script without using global variables. > > Thanks, > Life. > > -- -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/0ad05182-8aa2-467a-8bbf-2b1b32f19811n%40googlegroups.com.
Re: Access class member from command line
On 2024-05-07, Girish wrote: > On Sunday 5 May 2024 at 15:39:53 UTC+2 Lifepillar wrote: >> Let's say I have this class in some `foo.vim` file: >> >> export class Config >> public static var option = false >> endclass >> >> Now, I'd like to set `Config.option` to `true` from a script and from >> the command line. From a script, I can do this: >> >> import "foo.vim" >> >> type FooConfig = foo.Config >> FooConfig.option = true >> echo FooConfig.option # OK >> echo foo.Config.option # Also works >> >> Unfortunately, this gives an error (Undefined variable Config): >> >> foo.Config.option = true >> > Looks like a bug. Should be able to do `foo.Config.option = true` Indeed. And fixed. That works with the latest Vim (9.1.399). >> But how do I access the class member from the command line? Is that even >> possible? I still haven't found a way to do that, and I'm starting to think that it is not currently possible. If I put this in ~/.vim/autoload/foo.vim: vim9script export var x = 42 export def F() enddef export class C public var setting = "ok" public static var option = false endclass export var config = C.new() Then these work from the command line: echo foo#x call foo#F() echo foo#config echo foo#config.setting But I can't find a way to access the static variable 'option'. Life. -- -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/v1gppm%24jvc%241%40ciao.gmane.io.
Re: Access class member from command line
Hi, On Wed, May 8, 2024 at 2:11 PM Lifepillar wrote: > > On 2024-05-07, Girish wrote: > > On Sunday 5 May 2024 at 15:39:53 UTC+2 Lifepillar wrote: > > >> Let's say I have this class in some `foo.vim` file: > >> > >> export class Config > >> public static var option = false > >> endclass > >> > >> Now, I'd like to set `Config.option` to `true` from a script and from > >> the command line. From a script, I can do this: > >> > >> import "foo.vim" > >> > >> type FooConfig = foo.Config > >> FooConfig.option = true > >> echo FooConfig.option # OK > >> echo foo.Config.option # Also works > >> > >> Unfortunately, this gives an error (Undefined variable Config): > >> > >> foo.Config.option = true > >> > > Looks like a bug. Should be able to do `foo.Config.option = true` > > Indeed. And fixed. That works with the latest Vim (9.1.399). > Yes. This should be addressed by patch 9.1.0398. If you see any additional problems in using different types of imported variables in a Vim9 script (after this patch), please open an issue. In particular, look for any issues in using nested types. > > >> But how do I access the class member from the command line? Is that even > >> possible? > > I still haven't found a way to do that, and I'm starting to think that > it is not currently possible. If I put this in ~/.vim/autoload/foo.vim: > A class in a Vim9 script is a script-local variable. So it cannot be directly accessed from outside the script (without using the script name). Regards, Yegappan > vim9script > > export var x = 42 > > export def F() > enddef > > export class C > public var setting = "ok" > public static var option = false > endclass > > export var config = C.new() > > Then these work from the command line: > > echo foo#x > call foo#F() > echo foo#config > echo foo#config.setting > > But I can't find a way to access the static variable 'option'. > > Life. -- -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAAW7x7ksKt7Dq3mceEz2JjYab3vWeGbBgOWNoP9BeLXqqsPtRw%40mail.gmail.com.
Re: Access class member from command line
On 2024-05-09, Yegappan Lakshmanan wrote: > Hi, > > On Wed, May 8, 2024 at 2:11 PM Lifepillar wrote: >> > Looks like a bug. Should be able to do `foo.Config.option = true` >> >> Indeed. And fixed. That works with the latest Vim (9.1.399). >> > > Yes. This should be addressed by patch 9.1.0398. If you see any > additional problems > in using different types of imported variables in a Vim9 script (after > this patch), please > open an issue. In particular, look for any issues in using nested types. Right now, the only issue I have is with autoload scripts in my vimrc, but I see that it's being tracked as #13313 in GitHub. Other than that, I must say that Vim 9 script has been rock solid for me (no more crashes), and very pleasant to use! >> >> But how do I access the class member from the command line? Is that even >> >> possible? >> >> I still haven't found a way to do that, and I'm starting to think that >> it is not currently possible. If I put this in ~/.vim/autoload/foo.vim: >> > > A class in a Vim9 script is a script-local variable. So it cannot be > directly accessed > from outside the script (without using the script name). I'm not sure I understand. Classes can be exported, and I'm prepending the script name, so why doesn't this work in the command line? :echo foo#C.member where the script is ~/.vim/autoload/foo.vim, `C` is an exported class defined in foo.vim, and `member` is a static variable of C. Maybe because `C` is a type? For comparison, this works in a script: import autoload 'foo.vim' echo foo.C.member Thanks, Life. -- -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/v1i0o0%24n8%241%40ciao.gmane.io.
Re: Access class member from command line
Hi, On Thu, May 9, 2024 at 1:16 AM Lifepillar wrote: > > On 2024-05-09, Yegappan Lakshmanan wrote: > > Hi, > > > > On Wed, May 8, 2024 at 2:11 PM Lifepillar wrote: > >> > Looks like a bug. Should be able to do `foo.Config.option = true` > >> > >> Indeed. And fixed. That works with the latest Vim (9.1.399). > >> > > > > Yes. This should be addressed by patch 9.1.0398. If you see any > > additional problems > > in using different types of imported variables in a Vim9 script (after > > this patch), please > > open an issue. In particular, look for any issues in using nested types. > > Right now, the only issue I have is with autoload scripts in my vimrc, > but I see that it's being tracked as #13313 in GitHub. Other than that, > I must say that Vim 9 script has been rock solid for me (no more > crashes), and very pleasant to use! > I have opened the PR https://github.com/vim/vim/pull/14740 to address this issue. Regards, Yegappan > > >> >> But how do I access the class member from the command line? Is that even > >> >> possible? > >> > >> I still haven't found a way to do that, and I'm starting to think that > >> it is not currently possible. If I put this in ~/.vim/autoload/foo.vim: > >> > > -- -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAAW7x7nJHG36B%3Dspo2Xr0Y27FB7wDETn%2BV0p_PancBwtQN0Fmg%40mail.gmail.com.
Re: Access class member from command line
On 2024-05-10, Yegappan Lakshmanan wrote: >> Right now, the only issue I have is with autoload scripts in my vimrc, >> but I see that it's being tracked as #13313 in GitHub. Other than that, >> I must say that Vim 9 script has been rock solid for me (no more >> crashes), and very pleasant to use! >> > > I have opened the PR https://github.com/vim/vim/pull/14740 to address > this issue. I've just tried that, and it works like a charm! For older versions of Vim, I've found that I can create a symlink in ~/.vim/autoload, e.g.: cd ~/.vim/autoload ln -s ../pack/plugins/foo/autoload/foo.vim Then foo.vim is found by `import autoload` in my vimrc. Thanks, Life. -- -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/v1lu3p%24ead%243%40ciao.gmane.io.