plugins: Change easychair2 url
[vimconf.git] / macros.vim
index 73ce12864cca1fefa1aaf7c031349ed54bca252c..1da3dae9c56080df7f1cdc01545f006bef4759ac 100644 (file)
@@ -10,6 +10,11 @@ function TexTransUmlaute()
   execute ':%s/²/\^2/&'
 endfunction
 
+function! s:texTableBfEntries()
+    execute 's/\( *\)\([^ &][^&]*[^ &]\)\( \+\)/\1\\textbf{\2}\3/g'
+endfunction
+
+command! -range TexTableBfEntries call s:texTableBfEntries()
 
 "Open current file with a specific program
 function OpenIn(prog)
@@ -73,9 +78,12 @@ endfunction
 
 
 function InsertIncludeGuardsWithoutEndif()
-  let gatename = substitute(expand("%:t"), "\\.", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
-  execute "normal! i#ifndef " . gatename
-  execute "normal!   o#define " . gatename
+  " Build name of guard: Take filename, replace some chars by _ and
+  " prepend a random sequence to make guard robust against file name
+  " collisions.
+  let guardname = substitute(expand("%:t"), "[\\.-]", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
+  execute "normal! i#ifndef " . guardname
+  execute "normal! o#define " . guardname
 endfunction
 
 
@@ -93,13 +101,29 @@ function RunPandoc()
     let cssopts = "-c pandoc.css"
   endif
 
-  execute ":!pandoc " . cssopts . " --self-contained --toc " . @% . " -o " . @% . ".html"
+  execute ":!pandoc " . cssopts . " --self-contained --toc '" . @% . "' -o '" . @% . "'.html"
 endfunction
 
+
 function RunMarkdownpy(prog)
   execute ":!" . a:prog . " " . @% . " > " . @% . ".html"
 endfunction
 
+
+function RunAsciidoctor()
+  execute ":!asciidoctor " . @%
+  if executable("asciidoctor-pdf")
+    execute ":!asciidoctor-pdf " . @%
+  elseif executable("asciidoctor")
+    execute ":!asciidoctor " . @%
+  endif
+endfunction
+
+function RunAsciidoctorPdf()
+  execute ":!asciidoctor-pdf " . @%
+endfunction
+
+
 function RunMarkdown()
   if executable("pandoc")
     call RunPandoc()
@@ -113,6 +137,29 @@ function RunMarkdown()
 endfunction
 
 
+function RunAsciidoc()
+  if executable("asciidoctor-pdf")
+    call RunAsciidoctorPdf()
+  elseif executable("asciidoctor")
+    call RunAsciidoctor()
+  else
+    echo "No asciidoc implementation found."
+  endif
+endfunction
+
+
+function OnBattery()
+  if has('macunix')
+    return match(system('pmset -g batt'), "Now drawing from 'Battery Power'") != -1
+  elseif has('unix')
+    if filereadable('/sys/class/power_supply/AC/online')
+      return readfile('/sys/class/power_supply/AC/online') == ['0']
+    endif
+  endif
+  return 0
+endfunction
+
+
 if filereadable($HOME . '/.vim/macros-local.vim')
   source ~/.vim/macros-local.vim
 endif