Permalink
Browse files

New "deep evaluation" option

  • Loading branch information...
1 parent fc2b9d1 commit 0194aaf8d789494159257897bb77f8ccce4cf107 @molok committed Jan 11, 2012
Showing with 46 additions and 5 deletions.
  1. +5 −3 README.md
  2. +32 −0 doc/smartusline.txt
  3. +9 −2 plugin/smartusline.vim
View
8 README.md
@@ -1,8 +1,8 @@
SmartusLine
-----------
-SmartusLine is Vim plugin that changes the color of the statusbar of the focused
-window according with the current mode (normal/insert/replace)
+SmartusLine is Vim plugin that changes the color of the statusline of the
+focused window according with the current mode (normal/insert/replace)
it looks like this:
@@ -27,7 +27,6 @@ note: you probably want to set the statusline to never hide, like this:
set laststatus=2
-
other requirements are:
set nocompatible
@@ -39,6 +38,9 @@ something like this:
set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
+
+For a more complete documentation, read the help file (:help smartusline)
+
Enjoy!
View
32 doc/smartusline.txt
@@ -35,6 +35,38 @@ These are the supported global variables that you can customize in your |.vimrc|
Defines which part of the statusline will be highlighted, by default
it highlightes the filename ('%f'), it uses the same syntax used by
'statusline'
+>
+ smartusline_deep_eval
+< Default: 0
+ If this variable is set to 0 and your statusline starts with "%!"
+ then only that expression is evaluated before searching for a match
+ of smartusline_string_to_highlight.
+ If this variable is set to 1, all the "%{}" expressions returned
+ by the %! statusline function are evaluated before looking for a
+ match.
+
+ For example, suppose you have:
+>
+ :fun! MyFilename()
+ : return 'filename: %f'
+ :endfun
+
+ :fun! MyStatusLine()
+ : return '(%n) %{MyFilename()}'
+ :endfun
+
+ :set statusline=%!MyStatusLine()
+<
+ To highlight 'filename: %f'
+
+ with smartusline_deep_eval = 0
+ you can set
+ smartusline_string_to_highlight = '%{MyFilename()}'
+
+ with smartusline_deep_eval = 1
+ you can set
+ smartusline_string_to_highlight = 'filename: %f'
+
The currently supported mode are |Normal-mode|, |Insert-mode|, |Replace-mode|
and |Virtual-Replace-mode|:
View
11 plugin/smartusline.vim
@@ -41,6 +41,10 @@ if !exists('g:smartusline_hi_normal')
let g:smartusline_hi_normal = 'guibg=#95e454 guifg=black ctermbg=lightgreen ctermfg=black'
endif
+if !exists('g:smartusline_deep_eval')
+ let g:smartusline_deep_eval = 0
+endif
+
execute 'hi StatColor ' . g:smartusline_hi_normal
"let g:smartusline_string_to_highlight = '(%n) %f '
@@ -57,7 +61,7 @@ function! SmartusLineWin(mode)
let new_stl = ""
if match(curr_stl, '^%!') >= 0
- let curr_stl = s:EvalSTL(curr_stl)
+ let curr_stl = s:EvalSTL(curr_stl, g:smartusline_deep_eval)
endif
let string_to_match = substitute(g:smartusline_string_to_highlight,'\\','\\\\','g')
@@ -114,8 +118,11 @@ augroup SmartusLine
au GUIEnter * execute 'hi StatColor ' g:smartusline_hi_normal
augroup END
-fun! s:EvalSTL(stl_to_eval)
+fun! s:EvalSTL(stl_to_eval, deep_eval)
let str = eval(a:stl_to_eval[2:-1])
+ if a:deep_eval == 0
+ return str
+ endif
let prev_out = '0'
let out = '1'

0 comments on commit 0194aaf

Please sign in to comment.