From 0cbfeaab7f25e721f6cdac923f1e08f116276c3e Mon Sep 17 00:00:00 2001 From: itchyny Date: Thu, 29 Aug 2013 15:24:20 +0900 Subject: [PATCH] call fugitive#head only once --- README.md | 12 ++++++++++-- doc/lightline.txt | 25 ++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ccd41ce..8a9e3a0 100644 --- a/README.md +++ b/README.md @@ -483,7 +483,11 @@ endfunction Oops! We forgot the cool mark for the branch component! (work with the patched font for vim-powerline) ```vim function! MyFugitive() - return exists('*fugitive#head') && strlen(fugitive#head()) ? '⭠ '.fugitive#head() : '' + if exists("*fugitive#head") + let _ = fugitive#head() + return strlen(_) ? '⭠ '._ : '' + endif + return '' endfunction ``` ![lightline.vim - tutorial](https://raw.github.com/wiki/itchyny/lightline.vim/image/tutorial/15.png) @@ -543,7 +547,11 @@ function! MyFilename() endfunction function! MyFugitive() - return &ft !~? 'vimfiler\|gundo' && exists('*fugitive#head') && strlen(fugitive#head()) ? '⭠ '.fugitive#head() : '' + if &ft !~? 'vimfiler\|gundo' && exists("*fugitive#head") + let _ = fugitive#head() + return strlen(_) ? '⭠ '._ : '' + endif + return '' endfunction function! MyFileformat() diff --git a/doc/lightline.txt b/doc/lightline.txt index d77ee5d..48556bc 100644 --- a/doc/lightline.txt +++ b/doc/lightline.txt @@ -4,7 +4,7 @@ Version: 0.0 Author: itchyny (https://github.com/itchyny) License: MIT License Repository: https://github.com/itchyny/lightline.vim -Last Change: 2013/08/28 10:58:47. +Last Change: 2013/08/29 14:44:34. CONTENTS *lightline-contents* @@ -198,7 +198,11 @@ nice. return &readonly ? '' : '' endfunction function! MyFugitive() - return exists("*fugitive#head") && strlen(fugitive#head()) ? ''.fugitive#head() : '' + if exists("*fugitive#head") + let _ = fugitive#head() + return strlen(_) ? ''._ : '' + endif + return '' endfunction < If you have installed the patched font for |vim-powerline|, following settings @@ -219,7 +223,11 @@ look nice. return &readonly ? '⭤' : '' endfunction function! MyFugitive() - return exists("*fugitive#head") && strlen(fugitive#head()) ? '⭠ '.fugitive#head() : '' + if exists("*fugitive#head") + let _ = fugitive#head() + return strlen(_) ? '⭠ '._ : '' + endif + return '' endfunction < @@ -346,7 +354,10 @@ A nice example for non-patched font users. \ ('' != MyModified() ? ' ' . MyModified() : '') endfunction function! MyFugitive() - return &ft !~? 'vimfiler' && exists("*fugitive#head") && strlen(fugitive#head()) ? fugitive#head() : '' + if &ft !~? 'vimfiler' && exists("*fugitive#head") + return fugitive#head() + endif + return '' endfunction < A nice example for |vim-powerline| font users: @@ -378,7 +389,11 @@ A nice example for |vim-powerline| font users: \ ('' != MyModified() ? ' ' . MyModified() : '') endfunction function! MyFugitive() - return &ft !~? 'vimfiler' && exists("*fugitive#head") && strlen(fugitive#head()) ? '⭠ '.fugitive#head() : '' + if &ft !~? 'vimfiler' && exists("*fugitive#head") + let _ = fugitive#head() + return strlen(_) ? '⭠ '._ : '' + endif + return '' endfunction < ------------------------------------------------------------------------------