source or load an autoload script

28 views
Skip to first unread message

Ni Va

unread,
Aug 17, 2017, 8:31:17 AM8/17/17
to vim_use
Hi,


I'am writing a plugin with autoload part:
myplugin\autoload\myplugin.vim


A Command mapped on a function of this autoload/myplugin.vim.

I don't know other solution that quit vim and relaunch to source my modifications.

Have you got an advice ?
Thank
Niva

Christian Brabandt

unread,
Aug 17, 2017, 4:55:13 PM8/17/17
to vim_use

On Do, 17 Aug 2017, Ni Va wrote:

> Hi,
>
>
> I'am writing a plugin with autoload part:
> myplugin\autoload\myplugin.vim
>
>
> A Command mapped on a function of this autoload/myplugin.vim.
>
>
>
> I don't know other solution that quit vim and relaunch to source my modifications.

I don't understand what problem you are trying to solve.


Best,
Christian
--
Es liegt in der menschlichen Natur, vernünftig zu denken und unlogisch
zu handeln.

Ni Va

unread,
Aug 18, 2017, 4:13:31 AM8/18/17
to vim_use
OK. My problem is that I don't see effect when I modify a vimscript.
In the joined screen, you can see two vimscript. The right one is a 'class' instanciated in the left one. Then a simple command MK call MakeMyVim.

So, if I modify my vimscritp class and launch MK command, I don't see effect of my change as if it was not sourced.

Thank you by advance.
Sans titre.png

Nikolay Aleksandrovich Pavlov

unread,
Aug 18, 2017, 4:28:30 AM8/18/17
to vim...@googlegroups.com
You need to :source autoload file yourself, :unletting guard variable
before sourcing. But note that this is generally incorrect, e.g. if
you remove some function from autoload file, but forget to remove it
from the users of the file, then function will stay in memory and
users will still work, up until you restart Vim.

Thus in any case restart Vim before publishing the modified script.

>
> --
> --
> 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+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Ni Va

unread,
Aug 18, 2017, 4:40:00 AM8/18/17
to vim_use
Ok that was that I did. Restarting Vim. bouuh :(
Thank You ! :)

Luc Hermitte

unread,
Aug 18, 2017, 4:46:49 AM8/18/17
to vim use


De: "Ni Va" <niva...@gmail.com>
> OK. My problem is that I don't see effect when I modify a vimscript.
> In the joined screen, you can see two vimscript. The right one is a
> 'class' instanciated in the left one. Then a simple command MK call
> MakeMyVim.
>
> So, if I modify my vimscritp class and launch MK command, I don't see
> effect of my change as if it was not sourced.

That seems normal. trigger#new()['setup'] cannot be updated without calling new() again.
My take on the subject: never define methods this ways. Prefer to define a s:method and bind it in the constructor/creator function with

let new_obj.method_name = function('s:method_implementation')

First it'll allow reloading. But also, it'll improve greatly debugability.

I've written more on the subject on SO: https://stackoverflow.com/questions/40254993/how-to-unload-a-vim-script-after-sourcing-it-and-making-changes-to-it/40257268#40257268

BTW, autoload plugins don't need anti-inclusion guards. It makes no sense there.

HTH,

--
Luc Hermitte
Message has been deleted
Message has been deleted
Message has been deleted

Ni Va

unread,
Aug 18, 2017, 9:13:02 AM8/18/17
to vim_use
Ok Luc, Vimscript modified as described.

Than when I launch :w! | so% | MK, nothing is took on the fly.

I modify maxTimes allowed to attempt some jobs in my script but passing it from 20 to 15 let show 20 after launch.

An idea ?
Sans titre.png

Luc Hermitte

unread,
Aug 18, 2017, 12:50:51 PM8/18/17
to vim use
Hi,
> Ok Luc, Vimscript modified as described.
>
> Than when I launch :w! | so% | MK, nothing is took on the fly.
>
> I modify maxTimes allowed to attempt some jobs in my script but
> passing it from 20 to 15 let show 20 after launch.

A few:
- you've forgotten the `dict` attribute
- if your version of vim is to old, `function('s:funcname')` won't work.
- you still have a useless and undesired anti-reinclusion guard in your autoload plugin

BTW, if you wish to add methods to an object that already exists, they'll have to be injected on a reference of the object as you won't execute whatever#new() on an object that already exists. That's the reason behind by lh#object#inject_method(): https://github.com/LucHermitte/lh-vim-lib/blob/master/autoload/lh/object.vim#L96

Here is a patched, and untested, version of your file.


--
Luc Hermitte
trigger2.vim

Luc Hermitte

unread,
Aug 18, 2017, 12:54:23 PM8/18/17
to vim use
Hi,
> Ok Luc, Vimscript modified as described.
>
> Than when I launch :w! | so% | MK, nothing is took on the fly.
>
> I modify maxTimes allowed to attempt some jobs in my script but
> passing it from 20 to 15 let show 20 after launch.

trigger2.vim

Ni Va

unread,
Aug 18, 2017, 2:15:11 PM8/18/17
to vim_use
Thank you Sir !
Lazy guy may i am.
Niva
Reply all
Reply to author
Forward
0 new messages