From 05f1b478dffed8531ffc20828730f76992e57189 Mon Sep 17 00:00:00 2001 From: Olzvoi Bayasgalan Date: Thu, 8 Sep 2022 20:13:50 +0800 Subject: [PATCH] Some code cleanup and deduplication, version bump --- plugin/workspace.vim | 22 +++++++++------------- readme.md | 31 +++++++++++++++++-------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/plugin/workspace.vim b/plugin/workspace.vim index 12fcd56..1b8e507 100644 --- a/plugin/workspace.vim +++ b/plugin/workspace.vim @@ -1,10 +1,10 @@ -" Workspace (as in i3wm) for Vim +" Workspace for Vim " -------------------------- " File: workspace.vim " Author: Olzvoi Bayasgalan " Home: https://github.com/dosimple/workspace.vim -" Version: 0.3 -" Copyright: Copyright (C) 2021 Olzvoi Bayasgalan +" Version: 0.4 +" Copyright: Copyright (C) 2022 Olzvoi Bayasgalan " License: VIM License " if exists('loaded_workspace') @@ -24,11 +24,9 @@ end " " Return: 1 for workspace created new " 0 workspace exists -" -1 invalid workspace func! WS_Open(WS) if a:WS < 1 - call s:warning("Workspace invalid.") - return -1 + throw "Workspace invalid: " .. a:WS endif let tabnum = WS_Tabnum(a:WS) if tabnum @@ -177,7 +175,7 @@ func! s:session_load() call s:renumber(t, sv.ws[t]) endif endfor - " To accomodate existing buffers proir + " To accomodate existing buffers proir to loading session call WS_Rename(sv.ws[tabpagenr()]) for fname in keys(sv.bs) if ! bufexists(fname) @@ -196,12 +194,11 @@ func! WS_Buffers(WS, ...) let all = get(a:, 1, v:false) let bs = [] for b in getbufinfo() - let ws = s:bws(b) - if empty(ws) && b.loaded + if empty(s:bws(b)) && b.loaded "echo "Found orphan buffer: " . b.name . ": " . b.bufnr - call add(ws, t:WS+0) + call s:add(t:WS, b) endif - if index(ws, a:WS+0) >= 0 && (all || s:listed(b)) + if s:in(a:WS, b) && (all || s:listed(b)) call add(bs, b) endif endfor @@ -345,9 +342,8 @@ func! s:tableave() let s:prev = t:WS endfunc - func! s:tabenter() - let WS = s:tabinit() + let WS = t:WS for b in WS_Buffers(WS) call s:setlisted(b, 1) endfor diff --git a/readme.md b/readme.md index 50248b9..bffeb70 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,17 @@ # workspace.vim -The main purpose of this plugin is to make it easier +**This plugin gives each tabpage it's own buffer list.** + +The idea is to make it easier to manage large number of buffers by keeping them grouped separately in workspaces. -* Each tabpage becomes a workspace with it's own buffer list. +* Each tabpage represents a workspace with it's own buffer list. * Workspaces are numbered starting with 1, like tabpages, - but a workspace number wouldn't change as other - workspaces/tabpages are opened and closed. -* Third party buffer switchers should work as is. + but their numbers remain static as they are opened and closed + — don't conflate these two sets of numbers. +* `:ls`, `:bn`, `:bp` will use buffers from current workspace. + Third party buffer switchers should work as is. ## Installation @@ -18,15 +21,15 @@ them grouped separately in workspaces. ## Usage -* `:WS n` Switch to workspace `n` (it is a number). -* `:WSc [n]` Close current workspace or `n`. -* `:WSmv n` Rename current workspace to `n` (again a number). -* `:WSbmv n` Move current buffer to workspace `n`. -* `:WSbrm [n]` Remove buffer from current workspace. - Or delete it, if it is open in only current workspace. - It preserves windows layout. -* `:ls`, `:bn`, `:bp` will only operate on those buffers, which belong to the current workspace. -* Use your favorite buffer switcher. +| Command | Description | +|---------------|-------------------------------------------| +| `:WS n` | Switch to workspace `n` (it is a number). Create it, when necessary. | +| `:WSc [n]` | Close current workspace or `n`. | +| `:WSmv n` | Rename current workspace to `n`. | +| `:WSbmv n` | Move current buffer to workspace `n`. | +| `:WSbrm [n]` | Remove buffer from current workspace. Or delete it, if it is open in only current workspace. | + +All commands try to preserve window layout, while handling buffers. ## Useful addition to .vimrc