Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit c33e085612d8243eb305b3712ba71c06bededc20 0 parents
@gcmt authored
3  .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+.swp
+tags
19 LICENSE.txt
@@ -0,0 +1,19 @@
+Copyright (C) 2014 Giacomo Comitti
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
76 README.md
@@ -0,0 +1,76 @@
+## taboo.vim
+
+Taboo aims to ease the way you set the vim tabline. In addition, Taboo provides fews useful utilities for renaming tabs.
+
+### Installation
+
+Install either with [Vundle](https://github.com/gmarik/vundle), [Pathogen](https://github.com/tpope/vim-pathogen) or [Neobundle](https://github.com/Shougo/neobundle.vim).
+
+**NOTE**: tabs look different in terminal vim than in gui versions. If you wish having terminal style tabs even in gui versions you have to add the following line to your .vimrc file
+```vim
+set guioptions-=e
+```
+
+Taboo is able to remeber custom tab names when you save the current session but you are required to set the following option in your .vimrc file
+```vim
+set sessionoptions+=tabpages,globals
+```
+
+### Commands
+
+**TabooRename {name}**
+
+Renames the current tab with the name provided.
+
+**TabooOpen {name}**
+
+Opens a new tab and and gives it the name provided.
+
+**TabooReset**
+
+Removes the custom label associated with the current tab.
+
+### Basic options
+
+**g:taboo\_tab\_format**
+
+With this option you can customize the way tabs look like. Below all the available items:
+
+- `%f`: the name of the first buffer open in the tab
+- `%a`: the path relative to `$HOME` of the first buffer open in the tab
+- `%n`: the tab number, but only on the active tab
+- `%N`: the tab number on each tab
+- `%w`: the number of windows opened into the tab, but only on the active tab
+- `%W`: the number of windows opened into the tab, on each tab
+- `%m`: the modified flag
+
+Default: ` %f%m `
+
+**g:taboo\_renamed\_tab\_format**
+
+Same as `g:taboo_tab_format` but for renamed tabs. In addition, you can use the following items:
+
+- `%l`: the custom tab name set with `:TabooRename`
+
+Note that with renamed tabs the items `%f` and `%a` will be evaluated to an empty string.
+
+Default: ` [%f]%m `
+
+**g:taboo\_modified\_tab\_flag**
+
+This option controls how the modified flag looks like.
+
+Default: `*`
+
+**g:taboo\_tabline**
+
+Turn off this option and Taboo won't get in the way of your tabline.
+
+Default: `1`
+
+### Public interface
+
+Taboo provides a couple of public functions that may be used by third party plugins:
+
+- `TabooTabTitle`: this function returns the formatted tab title according to the options `g:taboo_tab_format` and `g:taboo_renamed_tab_format` (for renamed tabs).
+- `TabooTabName`: this function returns the name of a renamed tab. If a tab has no name, an empty string is returned.
177 doc/taboo.txt
@@ -0,0 +1,177 @@
+*taboo.txt* *taboo*
+
+ Taboo
+ ~
+ Reference Manual
+
+
+==============================================================================
+CONTENTS *taboo-contents*
+
+ 1. Overview .............................. |taboo-overview|
+ 2. Installation .......................... |taboo-installation|
+ 3. Commands .............................. |taboo-commands|
+ 4. Options ............................... |taboo-options|
+ 5. Public interface ...................... |taboo-public-interface|
+ 6. Credits ............................... |taboo-credits|
+ 7. License ............................... |taboo-license|
+
+
+==============================================================================
+1. Overview *taboo-overview*
+
+Taboo aims to ease the way you set the vim tabline. In addition, Taboo provides
+fews useful utilities for renaming tabs.
+
+
+==============================================================================
+2. Installation *taboo-installation*
+
+Install either with Vundle, Pathogen or NeoBundle.
+
+NOTE: tabs look different in terminal vim than in gui versions. If you wish
+having terminal style tabs even in gui versions you have to add the following
+line to your .vimrc file
+>
+ set guioptions-=e
+<
+Taboo is able to remeber custom tab names when you save the current session
+but you are required to set the following option in your .vimrc file
+>
+ set sessionoptions+=tabpages,globals
+<
+
+==============================================================================
+3. Commands *taboo-commands*
+
+------------------------------------------------------------------------------
+TabooRename <name> *TabooRename*
+
+Renames the current tab with the name provided.
+
+
+------------------------------------------------------------------------------
+TabooOpen <name> *TabooOpen*
+
+To opn a new tab next to active. An argument (the tab name) is required.
+Opens a new tab and and gives it the name provided.
+
+
+------------------------------------------------------------------------------
+TabooReset *TabooReset*
+
+Removes the custom label associated with the current tab.
+
+
+==============================================================================
+4. Options *taboo-options*
+
+------------------------------------------------------------------------------
+ *'taboo_tab_format'*
+
+With this option you can customize the way tabs look like. Below all the
+available items:
+
+ `%f` -> the name of the first buffer open in the tab
+ `%a` -> the path relative to `$HOME` of the first buffer open in the tab
+ `%n` -> the tab number, but only on the active tab
+ `%N` -> the tab number on each tab
+ `%w` -> the number of windows opened into the tab, but only on the active tab
+ `%W` -> the number of windows opened into the tab, on each tab
+ `%m` -> the modified flag
+
+Default: " %f%m "
+
+
+------------------------------------------------------------------------------
+ *'taboo_renamed_tab_format'*
+
+Same as |'taboo_tab_format'| but for renamed tabs. In addition, you can use
+the following items:
+
+ `%l` -> the custom tab name set with |TabooRename|
+
+Note that with renamed tabs the items `%f` and `%a` will be evaluated to an
+empty string.
+
+Default: " [%f]%m "
+
+------------------------------------------------------------------------------
+ *'taboo_modified_tab_flag'*
+
+This option controls how the modified flag looks like.
+
+Default: "*"
+
+------------------------------------------------------------------------------
+ *'taboo_tabline'*
+
+Turn off this option and Taboo won't get in the way of your tabline.
+
+Default: 1
+
+------------------------------------------------------------------------------
+ *'taboo_close_tabs_label'*
+
+Set this option if you want a flag on the tabline for closing the tabline
+itself when clicked. The flag will appear at the right side of the tabline.
+This position is fixed. When the value is an empty string nothing will be
+displayed.
+
+Default: ""
+
+------------------------------------------------------------------------------
+ *'taboo_unnamed_tab_label'*
+
+Set this option if you prefer a different name for tabs containing an unnamed
+buffer.
+
+Default: "[no name]"
+
+==============================================================================
+5. Public interface *taboo-public-interface*
+
+Taboo provides a couple of public functions that may be used by third party
+plugins:
+
+ `TabooTabTitle()` -> `string`
+
+ This function returns the formatted tab title according to the options
+ |'taboo_tab_format'| and |'taboo_renamed_tab_format'| (for renamed tabs).
+
+ `TabooTabName()` -> `string`
+
+ This function returns the name of a renamed tab. If a tab has no name,
+ an empty string is returned.
+
+
+==============================================================================
+6. Credits *taboo-credits*
+
+Author: Giacomo Comitti
+Contributors: https://github.com/gcmt/taboo.vim/contributors
+Git repository: https://github.com/gcmt/taboo.vim
+
+
+==============================================================================
+7. License *taboo-license*
+
+Copyright (c) 2014 Giacomo Comitti
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
268 plugin/taboo.vim
@@ -0,0 +1,268 @@
+" =============================================================================
+" File: taboo.vim
+" Description: A little plugin for managing the vim tabline
+" Mantainer: Giacomo Comitti (https://github.com/gcmt)
+" Url: https://github.com/gcmt/taboo.vim
+" License: MIT
+" =============================================================================
+
+" Init
+" =============================================================================
+
+if exists("g:loaded_taboo") || v:version < 702
+ finish
+endif
+let g:loaded_taboo = 1
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+" Settings
+" =============================================================================
+
+" This variable is needed to remember custom tab names when a session is
+" saved. String format: 'TABNUM\tTABNAME\nTABNUM\tTABNAME\n...'
+let g:Taboo_tabs =
+ \ get(g:, "Taboo_tabs", "")
+
+let g:taboo_tabline =
+ \ get(g:, "taboo_tabline", 1)
+
+let g:taboo_tab_format =
+ \ get(g:, "taboo_tab_format", " %f%m ")
+
+let g:taboo_renamed_tab_format =
+ \ get(g:, "taboo_renamed_tab_format", " [%l]%m ")
+
+let g:taboo_modified_tab_flag =
+ \ get(g:, "taboo_modified_tab_flag", "*")
+
+let g:taboo_close_tabs_label =
+ \ get(g:, "taboo_close_tabs_label", "")
+
+let g:taboo_unnamed_tab_label =
+ \ get(g:, "taboo_unnamed_tab_label", "[no name]")
+
+" Functions
+" =============================================================================
+
+" To construct the tabline string for terminal vim.
+fu TabooTabline()
+ let tabline = ''
+ for i in s:tabs()
+ let tabline .= i == tabpagenr() ? '%#TabLineSel#' : '%#TabLine#'
+ let title = s:gettabvar(i, "taboo_tab_name")
+ let fmt = empty(title) ? g:taboo_tab_format : g:taboo_renamed_tab_format
+ let tabline .= s:expand(i, fmt)
+ endfor
+ let tabline .= '%#TabLineFill#'
+ let tabline .= '%=%#TabLine#%999X' . g:taboo_close_tabs_label
+ return tabline
+endfu
+
+" To construct a single tab title for gui vim.
+fu TabooGuiTabTitle()
+ return TabooTabTitle()
+endfu
+
+" To rename the current tab.
+fu s:RenameTab(label)
+ cal s:settabvar(tabpagenr(), "taboo_tab_name", a:label)
+ cal s:refresh_tabline()
+endfu
+
+" To open a new tab with a custom name.
+fu s:OpenNewTab(label)
+ tabe!
+ cal s:RenameTab(a:label)
+endfu
+
+" If the tab has been renamed the custom name is removed.
+fu s:ResetTabName()
+ cal s:settabvar(tabpagenr(), "taboo_tab_name", "")
+ cal s:refresh_tabline()
+endfu
+
+" Global functions
+" =============================================================================
+
+" To return the formatted tab title
+fu TabooTabTitle(tabnr)
+ let title = s:gettabvar(i, "taboo_tab_name")
+ let fmt = empty(title) ? g:taboo_tab_format : g:taboo_renamed_tab_format
+ return s:expand(i, fmt)
+endfu
+
+" To return the name of the current tab, if one has been set
+fu TabooTabName(tabnr)
+ return s:tabname(tabnr)
+endfu
+
+" Functions for formatting the tab title
+" =============================================================================
+
+fu s:expand(tabnr, fmt)
+ let out = a:fmt
+ let out = substitute(out, '\C%f', s:bufname(a:tabnr), "")
+ let out = substitute(out, '\C%a', s:bufpath(a:tabnr), "")
+ let out = substitute(out, '\C%n', s:tabnum(a:tabnr, 0), "")
+ let out = substitute(out, '\C%N', s:tabnum(a:tabnr, 1), "")
+ let out = substitute(out, '\C%w', s:wincount(a:tabnr, 0), "")
+ let out = substitute(out, '\C%W', s:wincount(a:tabnr, 1), "")
+ let out = substitute(out, '\C%m', s:modflag(a:tabnr), "")
+ let out = substitute(out, '\C%l', s:tabname(a:tabnr), "")
+ return out
+endfu
+
+fu s:tabname(tabnr)
+ return s:gettabvar(a:tabnr, "taboo_tab_name")
+endfu
+
+fu s:tabnum(tabnr, ubiquitous)
+ if a:ubiquitous
+ return a:tabnr
+ endif
+ return a:tabnr == tabpagenr() ? a:tabnr : ''
+endfu
+
+fu s:wincount(tabnr, ubiquitous)
+ let windows = tabpagewinnr(a:tabnr, '$')
+ if a:ubiquitous
+ return windows
+ endif
+ return a:tabnr == tabpagenr() ? windows : ''
+endfu
+
+fu s:modflag(tabnr)
+ for buf in tabpagebuflist(a:tabnr)
+ if getbufvar(buf, "&mod")
+ return g:taboo_modified_tab_flag
+ endif
+ endfor
+ return ""
+endfu
+
+fu s:bufname(tabnr)
+ let bufnum = tabpagebuflist(a:tabnr)[0]
+ let basename = s:basename(bufname(bufnum))
+ if !empty(basename)
+ return basename
+ endif
+ return g:taboo_unnamed_tab_label
+endfu
+
+fu s:bufpath(tabnr)
+ let bufnum = tabpagebuflist(a:tabnr)[0]
+ let path = s:fullpath(bufname(bufnum), 1)
+ if !empty(path)
+ return path
+ endif
+ return g:taboo_unnamed_tab_label
+endfu
+
+" Helpers
+" =============================================================================
+
+fu s:tabs()
+ return range(1, tabpagenr('$'))
+endfu
+
+fu s:windows(tabnr)
+ return range(1, tabpagewinnr(a:tabnr, '$'))
+endfu
+
+fu s:basename(bufname)
+ return fnamemodify(a:bufname, ':p:t')
+endfu
+
+fu s:fullpath(bufname, pretty)
+ let path = fnamemodify(a:bufname, ':p')
+ return a:pretty ? substitute(path, $HOME, '~', '') : dirname
+endfu
+
+" To refresh the tabline.
+" This function also ensures that g:Taboo_tabs stays updated.
+fu s:refresh_tabline()
+ if exists("g:SessionLoad")
+ return
+ endif
+ let g:Taboo_tabs = ""
+ for i in s:tabs()
+ if !empty(s:gettabvar(i, "taboo_tab_name"))
+ let g:Taboo_tabs .= i."\t".s:gettabvar(i, "taboo_tab_name")."\n"
+ endif
+ endfor
+ exe "set stal=" . &showtabline
+endfu
+
+" To restore tab names after a session has been restored.
+fu s:restore_tabs()
+ for [tabnum, tabname] in s:load_tabs("Taboo_tabs")
+ cal s:settabvar(tabnum, "taboo_tab_name", tabname)
+ endfor
+endfu
+
+fu s:load_tabs(var)
+ return map(split(get(g:, a:var, ""), "\n"), "split(v:val, '\t')")
+endfu
+
+" Backward compatibility functions
+" =============================================================================
+
+" 7.2: Set the tab variable in each window in the tab.
+fu s:settabvar(tabnr, var, value)
+ if v:version > 702
+ cal settabvar(a:tabnr, a:var, a:value)
+ else
+ for winnr in s:windows(a:tabnr)
+ cal settabwinvar(a:tabnr, winnr, a:var, a:value)
+ endfor
+ endif
+endfu
+
+" 7.2: Each window in a tab should have the pseudo tab variable requested.
+fu s:gettabvar(tabnr, var)
+ if v:version > 702
+ return gettabvar(a:tabnr, a:var)
+ endif
+ for winnr in s:windows(a:tabnr)
+ let value = gettabwinvar(a:tabnr, winnr, a:var)
+ if !empty(value)
+ return value
+ endif
+ endfor
+ return ""
+endfu
+
+" To make sure all windows in the tab have the 'taboo_tab_name' pseudo tab variable.
+fu s:sync_tab_name()
+ let tabnr = tabpagenr()
+ call s:settabvar(tabnr, 'taboo_tab_name', s:gettabvar(tabnr, 'taboo_tab_name'))
+endfu
+
+" Commands
+" =============================================================================
+
+command! -nargs=1 TabooRename call s:RenameTab(<q-args>)
+command! -nargs=1 TabooOpen call s:OpenNewTab(<q-args>)
+command! -nargs=0 TabooReset call s:ResetTabName()
+
+" Autocommands
+" =============================================================================
+
+augroup taboo
+ au!
+ if g:taboo_tabline
+ au VimEnter * set tabline=%!TabooTabline()
+ au VimEnter * set guitablabel=%!TabooGuiTabTitle()
+ endif
+ au SessionLoadPost * cal s:restore_tabs()
+ au TabLeave,TabEnter * cal s:refresh_tabline()
+ au WinLeave,WinEnter * if v:version < 703 | cal s:sync_tab_name() | endif
+ au BufCreate,BufLeave,BufEnter * if v:version < 703 | cal s:sync_tab_name() | endif
+augroup END
+
+" =============================================================================
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
Please sign in to comment.
Something went wrong with that request. Please try again.