Skip to content

Commit

Permalink
feat: allow configuring colors
Browse files Browse the repository at this point in the history
This commit adds the ability to turn off automatic highlight group
setup. This enables colorschemes to override the default settings.

This change is more powerful than
t9md#56, because it gives the user
the control to reenable highlight groups at a later time.
  • Loading branch information
gregorias committed Apr 7, 2023
1 parent 839da60 commit 7ef44df
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 252 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
[日本語はこちら](https://github.com/t9md/vim-choosewin/blob/master/README-JP.md)

# Animated GIF
# ChooseWin

![gif](https://raw.githubusercontent.com/t9md/t9md/1675510eaa1b789aeffbc49c1ae3b1e8e7dceabe/img/vim-choosewin.gif)

# Navigate to the window you choose
## Navigate to the window you choose

This plugin aims to mimic tmux's `display-pane` feature, which enables you to choose a window interactively.

Expand Down Expand Up @@ -60,20 +58,20 @@ nmap - <Plug>(choosewin)

### Move around tabs, and choose windows

First of all, open multiple windows and tabs.
Invoke choosewin by typing `-` in normal mode.
Then you can move around tabs by `]` and `[`, or you cand choose the target tab directly by typing the number labeled in the tabline.
After you chose a target tab, you can choose a target window by typing the letter which is labeled in the statusline and in the middle of each window (if you have enabled the overlay feature).
First of all, open multiple windows and tabs.
Invoke choosewin by typing `-` in normal mode.
Then you can move around tabs by `]` and `[`, or you cand choose the target tab directly by typing the number labeled in the tabline.
After you chose a target tab, you can choose a target window by typing the letter which is labeled in the statusline and in the middle of each window (if you have enabled the overlay feature).

### Choose the previous window

Type `-` again to invoke choosewin, then input `-` again to choose the previous window. The previous window you were on before you choose the current window.
Type `-` again to invoke choosewin, then input `-` again to choose the previous window. The previous window you were on before you choose the current window.

### Swap windows

Type `-` to invoke choosewin, then type `s` to swap windows.
Then type the label of a window to swap content(=buffer) of that window with your current window.
After you chose, the current window's buffer is swapped with the buffer shown in the window you chose.
Type `-` to invoke choosewin, then type `s` to swap windows.
Then type the label of a window to swap content(=buffer) of that window with your current window.
After you chose, the current window's buffer is swapped with the buffer shown in the window you chose.
By combining "swap" and "previous window" features, you can easily swap any window with the previous window like so: `-s-`, invoking choosewin itself(`-`) then entering swapping mode(`s`), then instructing choosewin to swap the target window with the previous(`-`) window. Congratulations!

### NERDTree open file
Expand Down
6 changes: 4 additions & 2 deletions autoload/choosewin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function! s:cw.start(wins, ...) "{{{1
call self.choose()

catch /\v^(CHOSE \d+)$/
if self.conf['noop']
if self.conf['noop']
let tab = tabpagenr()
let win = str2nr(matchstr(v:exception, '\v^CHOSE \zs\d+'))
if tab isnot self.src.tab
Expand Down Expand Up @@ -88,14 +88,16 @@ function! s:cw.start(wins, ...) "{{{1
endfunction

function! s:cw.init(wins, conf) "{{{1
call choosewin#color#init()
let self.wins = s:wins.set(a:wins)
let self.conf = extend(choosewin#config#get(), a:conf)
let self.action = choosewin#action#init(self)
let self.exception = ''
let self.tab_options = {}
let self.statusline = {}
let self.src = {'win': winnr(), 'tab': tabpagenr()}
if self.conf.colorscheme_enable
lua require("choosewin.color").set()
endif
endfunction

function! s:cw.setup() "{{{1
Expand Down
37 changes: 0 additions & 37 deletions autoload/choosewin/color.vim

This file was deleted.

1 change: 1 addition & 0 deletions autoload/choosewin/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let s:default = {
\ 'active': 0,
\ 'debug': 0,
\ 'label_fill': 0,
\ 'colorscheme_enable': 1,
\ 'color_label': { 'gui': ['DarkGreen', 'white', 'bold'], 'cterm': [ 22, 15,'bold'] },
\ 'color_label_current': { 'gui': ['LimeGreen', 'black', 'bold'], 'cterm': [ 40, 16, 'bold'] },
\ 'color_overlay': { 'gui': ['DarkGreen', 'DarkGreen' ], 'cterm': [ 22, 22 ] },
Expand Down
194 changes: 0 additions & 194 deletions autoload/choosewin/hlmanager.vim

This file was deleted.

10 changes: 9 additions & 1 deletion doc/choosewin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ All config options in this section are set in 'autoload/choosewin/config.vim'.
Type: |Number|
Control whether the window label is shown in the |&statusline|.

*g:choosewin_colorscheme_enable*
Default: 1
Type: |Number| 0 or 1
Control whether this plugin should setup its highlight groups.
If you set it to 0, you can use `choosewin.color.enable` to enable the
default highlight groups.


*g:choosewin_color_label*
Default: See 'autoload/choosewin/config.vim'
Type: |Dictionary|
Expand Down Expand Up @@ -431,7 +439,7 @@ CHANGELOG *choosewin-changelog*
- [improve] Rewrite, cleanup overall program.
- [enhance] add tab_close action with default keymap 'x'.
2015-01-25:
- [enhance] now swap don't stay same window, original swap is now
- [enhance] now swap don't stay same window, original swap is now
swap_stay.
2015-01-20: v1.5
- verup again because of document mistake.
Expand Down
46 changes: 46 additions & 0 deletions lua/choosewin/color.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
local M = {}

local function viml_spec_to_lua_spec(viml_spec)
return {
fg = viml_spec.gui[2],
bg = viml_spec.gui[1],
ctermfg = viml_spec.cterm[2],
ctermbg = viml_spec.cterm[1],
bold = viml_spec.gui[3] and viml_spec.gui[3]:find("bold") ~= nil,
underline = viml_spec.gui[3] and viml_spec.gui[3]:find("underline") ~= nil,
}
end

-- Returns the highlight groups for Choosewin.
local function get_colors()
local config = vim.fn["choosewin#config#get"]()
local colors = {
ChooseWinLabel = config["color_label"],
ChooseWinLabelCurrent = config["color_label_current"],
ChooseWinOverlay = config["color_overlay"],
ChooseWinOverlayCurrent = config["color_overlay_current"],
ChooseWinShade = config["color_shade"],
ChooseWinLand = config["color_land"],
ChooseWinOther = config[config.label_fill and "color_label" or "color_other"],
}
for color, spec in pairs(colors) do
colors[color] = viml_spec_to_lua_spec(spec)
end
return colors
end

-- Sets highlight groups.
function M.set()
for color, spec in pairs(get_colors()) do
vim.api.nvim_set_hl(0, color, spec)
end
end

-- Clears highlight groups.
function M.clear()
for color, _ in pairs(get_colors()) do
vim.api.nvim_set_hl(0, color, {})
end
end

return M
6 changes: 0 additions & 6 deletions plugin/choosewin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ let g:loaded_choosewin = 1
let s:old_cpo = &cpo
set cpo&vim

" Main:
augroup plugin-choosewin
autocmd!
autocmd ColorScheme,SessionLoadPost * call choosewin#color#refresh()
augroup END

" KeyMap:
nnoremap <silent> <Plug>(choosewin)
\ :<C-u>call choosewin#start(range(1, winnr('$')))<CR>
Expand Down

0 comments on commit 7ef44df

Please sign in to comment.