Skip to content

Commit

Permalink
Some code cleanup and deduplication, version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
dosimple committed Sep 8, 2022
1 parent dbb0575 commit 05f1b47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
22 changes: 9 additions & 13 deletions plugin/workspace.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
" Workspace (as in i3wm) for Vim
" Workspace for Vim
" --------------------------
" File: workspace.vim
" Author: Olzvoi Bayasgalan <[email protected]>
" 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')
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 17 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down

0 comments on commit 05f1b47

Please sign in to comment.