Skip to content

Commit

Permalink
Merge pull request #19 from bobbleclank/search-count-spell-status
Browse files Browse the repository at this point in the history
Search count spell status
  • Loading branch information
bluz71 committed Aug 7, 2023
2 parents 4198387 + a90cbea commit 6c641a1
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 2 deletions.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ and right-side groups as follows:

```
+-------------------------------------------------+
| A | B | C | D X | Y | Z |
| A | B | C | D W | X | Y | Z |
+-------------------------------------------------+
```

Expand All @@ -141,6 +141,7 @@ and right-side groups as follows:
| B | Filename (refer below for details)
| C`*` | Git branch name (if applicable)
| D`*` | Plugins notification (git, diagnostic and session status)
| W | Optional search count and spell status
| X | Current position
| Y`*` | Total lines and current location as percentage
| Z | Optional indent status (spaces and tabs shift width)
Expand Down Expand Up @@ -236,6 +237,8 @@ highlight! link MistflyReplace ErrorMsg
| [mistflyWithGitStatus](https://github.com/bluz71/vim-mistfly-statusline#mistflywithgitstatus) | Enabled
| [mistflyWithDiagnosticStatus](https://github.com/bluz71/vim-mistfly-statusline#mistflywithdiagnosticstatus) | Enabled
| [mistflyWithSessionStatus](https://github.com/bluz71/vim-mistfly-statusline#mistflywithsessionstatus) | Enabled
| [mistflyWithSearchCount](https://github.com/bluz71/vim-mistfly-statusline#mistflyWithSearchCount) | Disabled
| [mistflyWithSpellStatus](https://github.com/bluz71/vim-mistfly-statusline#mistflyWithSpellStatus) | Disabled
| [mistflyWithIndentStatus](https://github.com/bluz71/vim-mistfly-statusline#mistflywithindentstatus) | Disabled

---
Expand Down Expand Up @@ -593,6 +596,49 @@ vim.g.mistflyWithSessionStatus = false

---

### mistflyWithSearchCount

The `mistflyWithSearchCount` option specifies whether to display the search
count in the `statusline`. By default the search count will not be displayed.

Note, the search count is only displayed when the `hlsearch` option is set and
the search count result is not zero.

To enable the display of the search count in the `statusline` please add the
following to your initialization file:

```viml
" Vimscript initialization file
let g:mistflyWithSearchCount = v:true
```

```lua
-- Lua initialization file
vim.g.mistflyWithSearchCount = true
```

---

### mistflyWithSpellStatus

The `mistflyWithSpellStatus` option specifies whether to display the spell
status in the `statusline`. By default spell status will not be displayed.

To enable spell status in the `statusline` please add the following to your
initialization file:

```viml
" Vimscript initialization file
let g:mistflyWithSpellStatus = v:true
```

```lua
-- Lua initialization file
vim.g.mistflyWithSpellStatus = true
```

---

### mistflyWithIndentStatus

The `mistflyWithIndentStatus` option specifies whether to display the
Expand Down
37 changes: 36 additions & 1 deletion autoload/mistfly.vim
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,29 @@ function! mistfly#PluginsStatus() abort
return l:segments
endfunction

function! mistfly#SearchCount() abort
if !exists('*searchcount')
return ''
endif
let l:result = searchcount(#{recompute: 1, maxcount: 0})
if empty(l:result)
return ''
endif
if l:result.incomplete ==# 1 " timed out
return printf('[?/??]')
elseif l:result.incomplete ==# 2 " max count exceeded
if l:result.total > l:result.maxcount && l:result.current > l:result.maxcount
return printf('[>%d/>%d]', l:result.current, l:result.total)
elseif l:result.total > l:result.maxcount
return printf('[%d/>%d]', l:result.current, l:result.total)
endif
endif
if l:result.total ==# 0
return ''
endif
return printf('[%d/%d]', l:result.current, l:result.total)
endfunction

function! mistfly#IndentStatus() abort
if !&expandtab
return 'Tab:' . &tabstop
Expand Down Expand Up @@ -263,7 +286,19 @@ function! mistfly#ActiveStatusLine() abort
let l:statusline .= l:branch_name . '%* '
endif
let l:statusline .= mistfly#PluginsStatus()
let l:statusline .= '%*%=%l:%c %*' . l:separator
let l:statusline .= '%*%='
if g:mistflyWithSearchCount && v:hlsearch
let l:search_count = mistfly#SearchCount()
if len(l:search_count) > 0
let l:statusline .= l:search_count . '%* '
let l:statusline .= '%*' . l:separator . '%* '
endif
endif
if g:mistflyWithSpellStatus && &spell
let l:statusline .= 'Spell '
let l:statusline .= '%*' . l:separator . '%* '
endif
let l:statusline .= '%l:%c %*' . l:separator
let l:statusline .= '%* ' . l:mode_emphasis . '%L%* ' . l:progress . '%P '
if g:mistflyWithIndentStatus
let l:statusline .= '%*' . l:separator
Expand Down
37 changes: 37 additions & 0 deletions doc/mistfly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Default option values:
let g:mistflyWithGitStatus = v:true
let g:mistflyWithDiagnosticStatus = v:true
let g:mistflyWithSessionStatus = v:true
let g:mistflyWithSearchCount = v:false
let g:mistflyWithSpellStatus = v:false
let g:mistflyWithIndentStatus = v:false
<
------------------------------------------------------------------------------
Expand Down Expand Up @@ -299,6 +301,41 @@ following to your initialization file:
vim.g.mistflyWithSessionStatus = false
<
------------------------------------------------------------------------------
mistflyWithSearchCount~ *g:mistflyWithSearchCount*

The `mistflyWithSearchCount` option specifies whether to display the search
count in the `statusline`. By default the search count will not be displayed.

Note, the search count is only displayed when the `hlsearch` option is set and
the search count result is not zero.

To enable the display of the search count in the `statusline` please add the
following to your initialization file:

>
" Vimscript initialization file
let g:mistflyWithSearchCount = v:true
-- Lua initialization file
vim.g.mistflyWithSearchCount = true
<
------------------------------------------------------------------------------
mistflyWithSpellStatus~ *g:mistflyWithSpellStatus*

The `mistflyWithSpellStatus` option specifies whether to display the spell
status in the `statusline`. By default spell status will not be displayed.

To enable spell status in the `statusline` please add the following to your
initialization file:

>
" Vimscript initialization file
let g:mistflyWithSpellStatus = v:true
-- Lua initialization file
vim.g.mistflyWithSpellStatus = true
<
------------------------------------------------------------------------------
mistflyWithIndentStatus~ *g:mistflyWithIndentStatus*

The `mistflyWithIndentStatus` option specifies whether to display the
Expand Down
2 changes: 2 additions & 0 deletions plugin/mistfly-statusline.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ let g:mistflyWithGitBranch = get(g:, 'mistflyWithGitBranch', v:true)
let g:mistflyWithGitStatus = get(g:, 'mistflyWithGitStatus', v:true)
let g:mistflyWithDiagnosticStatus = get(g:, 'mistflyWithDiagnosticStatus', v:true)
let g:mistflyWithSessionStatus = get(g:, 'mistflyWithSessionStatus', v:true)
let g:mistflyWithSearchCount = get(g:, 'mistflyWithSearchCount', v:false)
let g:mistflyWithSpellStatus = get(g:, 'mistflyWithSpellStatus', v:false)
let g:mistflyWithIndentStatus = get(g:, 'mistflyWithIndentStatus', v:false)

augroup mistflyStatuslineEvents
Expand Down

0 comments on commit 6c641a1

Please sign in to comment.