From a6f5b4dbb1b87a7a39b922a1a725a1706bff9c95 Mon Sep 17 00:00:00 2001
From: Stefan Huber <shuber@sthu.org>
Date: Sat, 18 Apr 2020 23:38:07 +0200
Subject: [PATCH] neomake: Battery-dependent config

---
 init.vim   | 12 +++++++++---
 macros.vim | 12 ++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/init.vim b/init.vim
index 75f8c34..aa86714 100644
--- a/init.vim
+++ b/init.vim
@@ -44,6 +44,8 @@ end
 
 syntax on
 
+" Load some macros
+runtime macros.vim
 
 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 " Some global plugin settings
@@ -103,8 +105,13 @@ let NERDTreeQuitOnOpen=1
 let g:neomake_c_enabled_makers = ['clangtidy', 'clangcheck']
 let g:neomake_cpp_enabled_makers = ['clangtidy', 'clangcheck']
 
-call neomake#configure#automake('w')
-"let g:neomake_logfile = '/tmp/neomake.log'
+" Taken from neomake
+if OnBattery()
+  call neomake#configure#automake('w')
+else
+  call neomake#configure#automake('nw', 1000)
+endif
+
 
 let g:clang_compilation_database = '.'
 
@@ -193,7 +200,6 @@ let g:vimwiki_list = [{'path': '~/.vimwiki/',
 
 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 
-runtime macros.vim
 runtime keymaps.vim
 
 if filereadable($HOME . '/.vim/init-local.vim')
diff --git a/macros.vim b/macros.vim
index cba6b84..5859967 100644
--- a/macros.vim
+++ b/macros.vim
@@ -96,10 +96,12 @@ function RunPandoc()
   execute ":!pandoc " . cssopts . " --self-contained --toc '" . @% . "' -o '" . @% . "'.html"
 endfunction
 
+
 function RunMarkdownpy(prog)
   execute ":!" . a:prog . " " . @% . " > " . @% . ".html"
 endfunction
 
+
 function RunMarkdown()
   if executable("pandoc")
     call RunPandoc()
@@ -113,6 +115,16 @@ function RunMarkdown()
 endfunction
 
 
+function OnBattery()
+  if has('macunix')
+    return match(system('pmset -g batt'), "Now drawing from 'Battery Power'") != -1
+  elseif has('unix')
+    return readfile('/sys/class/power_supply/AC/online') == ['0']
+  endif
+  return 0
+endfunction
+
+
 if filereadable($HOME . '/.vim/macros-local.vim')
   source ~/.vim/macros-local.vim
 endif
-- 
2.39.5