diff vim/autoload/ludo.vim @ 495:232351531855

Vim config improvements - Support for gui vs non gui plugin exclusions rules - Move HasPlugin to an autoload function that can be used in vimrc-local - Don't load the local bundle if it doesn't exist - Handle VS vs UE for building projects
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 12 Nov 2021 10:51:57 -0800
parents 1a54ffbc3b15
children
line wrap: on
line diff
--- a/vim/autoload/ludo.vim	Fri Nov 12 10:50:18 2021 -0800
+++ b/vim/autoload/ludo.vim	Fri Nov 12 10:51:57 2021 -0800
@@ -45,6 +45,14 @@
     echohl None
 endfunction
 
+" Returns whether a plugin file exists in the runtime path.
+function! ludo#has_plugin(plugname, ...) abort
+    let l:dirname = 'plugin/'
+    if a:0 && a:1
+        let l:dirname = 'autoload/'
+    endif
+    return globpath(&runtimepath, l:dirname.a:plugname.'.vim') !=# ''
+endfunction
 
 " Loads `pathogenrc` files in each bundle directory and, if found,
 " builds an exclude list based on the glob patterns found in them.
@@ -65,26 +73,40 @@
             if line[0] == '#'
                 continue
             endif
-            
+
+            if strcharpart(line, 0, 4) == "gui:"
+                if !has('gui')
+                    call ludo#trace("Ignoring gui-only line: ".line) 
+                    continue
+                else
+                    let line = line[4:]
+                endif
+            endif
+            if strcharpart(line, 0, 6) == "nogui:"
+                if has('gui')
+                    call ludo#trace("Ignoring terminal-only line: ".line) 
+                    continue
+                else
+                    let line = line[6:]
+                endif
+            endif
+
+            let l:add_to = l:included
+            let l:remove_from = l:excluded
             if line[0] == '-'
-                let l:excls = glob(bundle_dir.'/'.line[1:], 1, 1)
-                for excl in l:excls
-                    let l:idx = index(l:included, excl)
-                    if l:idx >= 0
-                        call remove(l:included, l:idx)
-                    endif
-                    call add(l:excluded, excl)
-                endfor
-            else
-                let l:incls = glob(bundle_dir.'/'.line, 1, 1)
-                for incl in l:incls
-                    let l:idx = index(l:excluded, incl)
-                    if l:idx >= 0
-                        call remove(l:excluded, l:idx)
-                    endif
-                    call add(l:included, incl)
-                endfor
+                let l:add_to = l:excluded
+                let l:remove_from = l:included
+                let line = line[1:]
             endif
+
+            let l:incls = glob(bundle_dir.'/'.line, 1, 1)
+            for incl in l:incls
+                let l:idx = index(l:remove_from, incl)
+                if l:idx >= 0
+                    call remove(l:remove_from, l:idx)
+                endif
+                call add(l:add_to, incl)
+            endfor
         endfor
 
         for excl in l:excluded
@@ -170,3 +192,13 @@
     endfor
     execute ':'.string(l:tagidx).'tag '.l:tag
 endfunction
+
+function! ludo#build_vs_or_ue() abort
+    if !empty(get(g:, 'unreal_branch_dir', ''))
+        UnrealBuild
+    elseif !empty(get(g: 'vimcrosoft_current_sln', ''))
+        VimcrosoftBuildActiveProject
+    else
+        call ludo#warn("No VS or UE project active")
+    endif
+endfunction