Hello,

> Well, if gatekeeper could also propose a way to force reloading
> (multiple times) a plugin, that would be nice.
Please see the attached version, whether it does want you intend.

Basic Idea:
let gatekeeper#YourPluginDebug = 1

do
        :source YourPlugin.vim
until you don't want anymore

unlet gatekeeper#YourPluginDebug

:source YourPlugin.vim does nothing anymore (the script is already
loaded)

> It is not that special at all. ftplugins are very close to plugins
> except that:
> - they require a local guard
> - sometimes they can need a global guard, for global definitions
> which can be moved to autoload plugins now.
Ah, ok. Got it. Something like "b:foo_loaded" instead of "g:foo_loaded".
I was confused about the "local".

> BTW, did you read David "2 cents" about storing the version of a
> plugin in its anti-reinclusion guard ?

Quote from the named thread:
> I would like us (plugin authors) to develop a standard / best practice
> that everyone adheres to. This would make it useful for others as
> well.
Nothing more to add....

> This is a good practice that, I think, should indeed be generalized
> -- and I have a lot of work to do on this one. This is something the
> Guard function from Gatekeeper should take into account (may be with
> an optional parameter receiving the current version of the script?)
> At terms, it could help to implement dependency checks when a
> particular version of another script is required.
This could be done with the central Guard function without problems. But
for the handling probably one would need some support function.
Otherwise you get problems with the loading sequence. Maybe something
like Need(["Foo", "102"], "Bar", ["Frobnicate", "200"]).

There are a few things to take care of...

1. How to come from the plugin name to the filename?
   Possibilities:
    - both are identical
    - the latter is all lowercase of the former
    - ...

2. What format do we choose for version strings?
   This is what David used: "vll".
   There could be other formats like: "vvllpp".
   In the end it doesn't really matter as long as it's consistent for a
   given plugin. But it should be comparable like x < y. The guys from
   rubygems have a quite nice versioning scheme, I think.

I'd like to use strings, BTW, because I often label my development
versions, before the first real release, with 0.<something>. Then a
number doesn't really work well...

Sincerely
Meikel

-- 
  |\      _,,,---,,_
  /,`.-'`'    -.  ;-;;,_
 |,4-  ) )-,_..;\ (  `'-'
'---(_/--'  `-'\_)  fL                     http://ec.kotka.de

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

" Vimball Archiver by Charles E. Campbell, Jr., Ph.D.
UseVimball
finish
autoload/gatekeeper.vim [[[1
121
"##### HEADER [ {{{ ]
" Plugin:       Gatekeeper
" Version:      0.1
" Author:       Meikel Brandmeyer <[EMAIL PROTECTED]>
" Created:      Mon Apr 21 20:13:05 2008
" Last Change:  Mon Apr 21 2008
"
" License:
" Copyright (c) 2008 Meikel Brandmeyer, Frankfurt am Main
" 
" All rights reserved.
" 
" Permission is hereby granted, free of charge, to any person obtaining a copy
" of this software and associated documentation files (the "Software"), to deal
" in the Software without restriction, including without limitation the rights
" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
" copies of the Software, and to permit persons to whom the Software is
" furnished to do so, subject to the following conditions:
" 
" The above copyright notice and this permission notice shall be included in
" all copies or substantial portions of the Software.
" 
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
" THE SOFTWARE.
"
" Description:
" Gatekeeper provides an infrastructure for scripts to handle dependencies
" and loading of scripts. The user may easily disable certain scripts or
" choose an opt-in mode, where each script must be explicitely enabled.
" Missing or disabled dependencies give either an error or are simply enabled
" if the corresponding switch is set by the user.
"##### [ }}} ]

"##### PROLOG [ {{{ ]
let s:saved_cpo = &cpo
set cpo&vim
"##### [ }}} ]

"##### VARIABLES [ {{{ ]
"### VARIABLE gatekeeper#OptOut, gatekeeper#OptIn [ {{{ ]
" Description:
" Gatekeeper works in two modes: opt-in or opt-out.
"
" opt-out is the traditional mode which is used by most plugins. In case the
" user doesn't want the script to be loaded, he has to manually fiddle around
" with one of the many ways to stop the script from being sourced.
"
" opt-in is newly introduced by Gatekeeper and works the other way around. No
" plugin is loaded unless specified by the user. In this way it is easy to
" disable scripts.
"
if !exists("gatekeeper#OptOut")
        let gatekeeper#OptOut = 1
endif
if !exists("gatekeeper#OptIn")
        let gatekeeper#OptIn = 0
endif
"### [ }}} ]
"##### [ }}} ]

"##### FUNCTIONS [ {{{ ]
"### FUNCTION gatekeeper#Guard [ {{{ ]
" Description:
" This is the heart of the system. This function is used in the header guard,
" which controls whether the script is sourced or not. Is a script disabled
" this function indicates so back to the script which should 'finish'.
"
function! gatekeeper#Guard(plugin)
        let guard = "g:gatekeeper#" . a:plugin

        " Give the developer some rope. By setting the Debug variable for
        " a plugin, it may be sourced several times. If it is set we ignore
        " any opt-in or -out modes or disable request for that plugin.
        "
        " XXX: For now this applies to all versions of the script!
        " Do a :runtime! with multiple versions installed and see the trap
        " door open!
        if exists(guard . "Debug")
                execute "let " . guard . "Loaded = 1"
                return 1
        endif

        " If the user didn't set a choice for the plugin, check for the
        " standard behaviour. If it's OptIn we stop here (script is not
        " explicitely enabled). If the choice exists, we check whether it
        " was disabled. If so we stop also.
        if !exists(guard)
                if (g:gatekeeper#OptIn == 1 || g:gatekeeper#OptOut == 0)
                        return 0
                endif
        else
                if !eval(guard)
                        return 0
                endif
        endif

        " If we reach here, either the plugin is enabled or OptOut is our
        " mode of operation.
        "
        " Now we simply check whether the plugin is already loaded. If so
        " we stop, otherwise we set the guard and give green light for
        " further processing.
        if exists(guard . "Loaded")
                return 0
        endif
        execute "let " . guard . "Loaded = 1"

        return 1
endfunction
"### [ }}} ]
"##### [ }}} ]

"##### EPILOG [ {{{ ]
let &cpo = s:saved_cpo
unlet s:saved_cpo
"##### [ }}} ]
doc/gatekeeper.txt      [[[1
123

                            Gatekeeper

                                            *gatekeeper*

Gatekeeper is a system which let's the user decide whether a plugin should be
loaded or not. By simply switching the usual opt-out to an opt-in mode, gives
full control over which plugins/scripts are loaded.

Of course the scripts have to support Gatekeeper, but this is actually very
easy. Since at the head of each plugin should be a guard, which checks whether
the plugin is already loaded, the only thing we have to do is to adjust the
guard to use the |gatekeeper#Guard| function instead of checking itself for
the guard variable. This even simplifies the guard header!

For the user is no change necessary. Without changing any setting one gets the
same behaviour one is used to. But on the other hand one gets the full control
of gatekeeper.

==============================================================================
CONTENTS

 1. OptOut                                  |gatekeeper#OptOut|
 2. OptIn                                   |gatekeeper#OptIn|
 3. Guard                                   |gatekeeper#Guard|
 4. Debug                                   |gatekeeper-Debug|
 5. Todo                                    |gatekeeper-Todo|
 6. License                                 |gatekeeper-License|
==============================================================================

 1. OptOut                                  *gatekeeper#OptOut*

let gatekeeper#OptOut = 1

In opt-out mode, Gatekeeper behaves like the traditional script. Every script
is loaded unless the user specifies otherwise. This is also the default if the
user just uses Gatekeeper without modifying any setting. So it is 100%
backward compatible.

==============================================================================

 2. OptIn                                   *gatekeeper#OptIn*

let gatekeeper#OptIn = 1
or equivalent: let gatekeeper#OptOut = 0

In opt-in mode, no script or plugin is sourced unless excplicitely wanted by
the user. This is useful if you want complete control, over which plugins are
loaded and which are skipped.

==============================================================================

 3. Guard                                   *gatekeeper#Guard*

if (!gatekeeper#Guard("MyPlugin"))
        finish
endif

This is the heart of the whole system. It checks whether the given plugin is
enabled, disabled or already loaded. According to this information it gives
feedback to calling script whether it should |:finish| loading or whether it
should go on.

To explicitely enable a plugin set the corresponding Gatekeeper variable. >

        let gatekeeper#MyPlugin = 1
<
Similarly one can disable a script by setting the value to zero. >

        let gatekeeper#MyPlugin = 0
<
==============================================================================

 4. Debug                                   *gatekeeper-Debug*

let gatekeeper#MyPluginDebug = 1
unlet gatekeeper#MyPluginDebug

Gatekeeper supports the plugin developer in .. well .. developing his plugin.
At any time one can define a "Debug" variable for the plugin. Now the plugin
may be |:soruce|d as often as the developer wishes to do so. |:unlet| the
variable to switch back to normal mode for this plugin. The rest of the system
behaves normally.

Note, that this gives plenty of rope to the developer and it's easy to open
the trap door with something like |:runtime|! if several versions of the
script are installed.

==============================================================================

 5. Todo                                    *gatekeeper-Todo*

 * different versions of a script ?
 * depedency handling ?

==============================================================================

 6. License                                 *gatekeeper-License*

Copyright (c) 2008 Meikel Brandmeyer, Frankfurt am Main

All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

==============================================================================
vim: ft=help:norl:ts=8:tw=78
t/001_gatekeeper_optout.t       [[[1
12
call vimtap#Plan(4)

let gatekeeper#PluginB = 1
let gatekeeper#PluginC = 0
let g:PluginDLoaded = 1

call vimtap#Ok(gatekeeper#Guard("PluginA"), "opt-out")
call vimtap#Ok(gatekeeper#Guard("PluginB"), "opt-out and enabled plugin")
call vimtap#Ok(!gatekeeper#Guard("PluginC"), "opt-out and disabled plugin")
call vimtap#Ok(!gatekeeper#Guard("PluginC"), "opt-out and loaded plugin")

" vim:ft=vim:
t/001_gatekeeper_debug_flag.t   [[[1
22
call vimtap#Plan(6)

if exists("g:gatekeeper#PluginALoaded")
        unlet gatekeeper#PluginALoaded
endif

call vimtap#Ok(gatekeeper#Guard("PluginA"), "initial load")
call vimtap#Ok(!gatekeeper#Guard("PluginA"), "already loaded")

" Now switch to debug mode!
let gatekeeper#PluginADebug = 1

call vimtap#Ok(gatekeeper#Guard("PluginA"), "debug load 1")
call vimtap#Ok(gatekeeper#Guard("PluginA"), "debug load 2")
call vimtap#Ok(gatekeeper#Guard("PluginA"), "debug load 3")

" Now switch to normal mode.
unlet gatekeeper#PluginADebug

call vimtap#Ok(!gatekeeper#Guard("PluginA"), "back to normal")

" vim:ft=vim:
t/001_gatekeeper_no_optout.t    [[[1
14
call vimtap#Plan(4)

let gatekeeper#OptOut = 0

let gatekeeper#PluginB = 1
let gatekeeper#PluginC = 0
let g:PluginDLoaded = 1

call vimtap#Ok(!gatekeeper#Guard("PluginA"), "no opt-out")
call vimtap#Ok(gatekeeper#Guard("PluginB"), "no opt-out and enabled plugin")
call vimtap#Ok(!gatekeeper#Guard("PluginC"), "no opt-out and disabled plugin")
call vimtap#Ok(!gatekeeper#Guard("PluginD"), "no opt-out and loaded plugin")

" vim:ft=vim:
t/001_gatekeeper_optin.t        [[[1
14
call vimtap#Plan(4)

let gatekeeper#OptIn = 1

let gatekeeper#PluginB = 1
let gatekeeper#PluginC = 0
let g:PluginDLoaded = 1

call vimtap#Ok(!gatekeeper#Guard("PluginA"), "opt-in")
call vimtap#Ok(gatekeeper#Guard("PluginB"), "opt-in and enabled plugin")
call vimtap#Ok(!gatekeeper#Guard("PluginC"), "opt-in and disabled plugin")
call vimtap#Ok(!gatekeeper#Guard("PluginD"), "opt-in and loaded plugin")

" vim:ft=vim:

Raspunde prin e-mail lui