Git Product home page Git Product logo

Comments (7)

mitermayer avatar mitermayer commented on May 21, 2024

Hi @dfishburn,

Please note that we have this logic on https://github.com/prettier/vim-prettier/blob/master/plugin/prettier.vim#L14

if exists('g:loaded_prettier')
  finish
endif
let g:loaded_prettier = 1

from vim-prettier.

dfishburn avatar dfishburn commented on May 21, 2024

One thing I am not certain on, when you reference a function in the autoload file, whether Vim automatically sources that file first and then calls it or whether it checks if the function exists and does not source it.

I just use that standard pattern in all my files.

from vim-prettier.

mitermayer avatar mitermayer commented on May 21, 2024

Hi @dfishburn

Autoloaded function get evaluated only once and are also lazy loaded. This is a good reference: http://learnvimscriptthehardway.stevelosh.com/chapters/53.html

Some quotes from the above link

:call somefile#Hello()
When you run this command, Vim will behave a bit differently than a normal function call.
If this function has already been loaded, Vim will simply call it normally.
Otherwise Vim will look for a file called autoload/somefile.vim in your ~/.vim directory (and any Pathogen bundles).
If this file exists, Vim will load/source the file. It will then try to call the function normally.

from vim-prettier.

mitermayer avatar mitermayer commented on May 21, 2024

Once again thanks @dfishburn for raising this issue,

Feel free to comment/re-open this issue if you have any further questions or any info around it

from vim-prettier.

dfishburn avatar dfishburn commented on May 21, 2024

Actually from that web link you provided:

Vim already has a definition for example#Hello, so it doesn't need to reload the file, which means:

The code outside the function wasn't run again.
It didn't pick up the changes to the function.

Now run :call example#BadFunction(). 

You'll see the loading messages again, as well as an error about a nonexistent function. 

But now try running :call example#Hello() again. This time you'll see the updated message!

That is the case I am talking about.
Once you reference a different function in the same file, a function that Vim has not used yet, it sources the file again.

Had you not defined all your functions using function!, you would have seen an error (function already exists) each time you call a different function.

So, for efficiency you do want the finish guard at the top of that file.

from vim-prettier.

mitermayer avatar mitermayer commented on May 21, 2024

Will look into this later and get back to this issue, in the meantime will leave it open until I can can check on it more in depth

from vim-prettier.

mitermayer avatar mitermayer commented on May 21, 2024

Hi @dfishburn,

In order to debug the above statement I have just performed the following test, edited autoload/prettier.vim and included on the top the following line:

echom "loading vim-prettier"

Then I did the following steps:

  1. Opened a new file
  2. Executed :Prettier
  3. Executed :PrettierCliVersion
  4. run the command :messages to check for the printed messages

outcome:

  • "loading vim-prettier" got printed only once regardless of the multiple calls, so the autoload file got only loaded once

If you can provide a working example of that I will be happy to re-open this issue.

from vim-prettier.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.