1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:20:06 +08:00

Improve tools#mpv layer (#3534)

This commit is contained in:
Wang Shidong 2020-05-16 14:02:51 +08:00 committed by GitHub
parent d00d81ad74
commit 829094c1ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 178 additions and 14 deletions

View File

@ -6,16 +6,53 @@
" License: GPLv3
"=============================================================================
if exists('s:musics_directory')
finish
else
let s:musics_directory = '~/Musics'
let s:mpv_interpreter = 'mpv'
let s:loop_mode = 'random'
let s:stop_mpv = 0
endif
let s:JOB = SpaceVim#api#import('job')
let s:NUM = SpaceVim#api#import('data#number')
function! SpaceVim#layers#tools#mpv#config() abort
call s:load_musics()
let g:_spacevim_mappings_space.m.m = {'name' : '+mpv'}
call SpaceVim#mapping#space#def('nnoremap', ['m', 'm', 'l'], 'Leaderf menu --name MpvPlayer', 'fuzzy-find-musics', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'm', 'l'], 'Leaderf menu --name MpvPlayer', 'fuzzy-find-musics', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'm', 'n'], 'call call('
\ . string(s:_function('s:next')) . ', [])',
\ 'next-music', 1)
call SpaceVim#mapping#space#def('nnoremap', ['m', 'm', 's'], 'call call('
\ . string(s:_function('s:stop')) . ', [])',
\ 'stop-mpv', 1)
endfunction
function! SpaceVim#layers#tools#mpv#loadMusics() abort
let musics = SpaceVim#util#globpath('~/Musics', '*.mp3')
function! SpaceVim#layers#tools#mpv#set_variable(var) abort
let s:musics_directory = get(a:var, 'musics_directory', 1)
let s:mpv_interpreter = get(a:var, 'mpv_interpreter', 1)
endfunction
function! SpaceVim#layers#tools#mpv#play(fpath)
let s:stop_mpv = 0
if s:playId != 0
call s:JOB.stop(s:playId)
let s:playId = 0
endif
let s:playId = s:JOB.start([s:mpv_interpreter,'--vid=no',a:fpath],{
\ 'on_stdout': function('s:handler'),
\ 'on_stderr': function('s:handler'),
\ 'on_exit': function('s:handler'),
\ })
command! MStop call s:stop()
endfunction
function! s:load_musics() abort
let musics = SpaceVim#util#globpath(s:musics_directory, '*.mp3')
let g:unite_source_menu_menus.MpvPlayer.command_candidates = []
for m in musics
call add(g:unite_source_menu_menus.MpvPlayer.command_candidates,
@ -28,26 +65,43 @@ endfunction
let s:playId = 0
fu! s:handler(id, data, event) abort
if a:event ==# 'exit'
echom 'job ' . a:id . ' exit with code:' . string(a:data)
let s:playId = 0
if s:loop_mode ==# 'random' && !s:stop_mpv
let next = s:NUM.random(0, len(g:unite_source_menu_menus.MpvPlayer.command_candidates))
echohl TODO
echo 'playing:' . g:unite_source_menu_menus.MpvPlayer.command_candidates[next][0]
echohl NONE
exe g:unite_source_menu_menus.MpvPlayer.command_candidates[next][1]
endif
endif
endf
function! s:stop() abort
if s:playId != 0
call jobstop(s:playId)
call s:JOB.stop(s:playId)
let s:playId = 0
endif
delcommand MStop
let s:stop_mpv = 1
endfunction
function! s:play(file,...) abort
function! s:next() abort
if s:playId != 0
call s:JOB.stop(s:playId)
let s:playId = 0
endif
let s:playId = s:JOB.start(['mpv','--vid=no',a:file],{
\ 'on_stdout': function('s:handler'),
\ 'on_stderr': function('s:handler'),
\ 'on_exit': function('s:handler'),
\ })
command! MStop call zvim#mpv#stop()
endfunction
" function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:_function(fstr) abort
return function(a:fstr)
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
let s:_s = '<SNR>' . s:_SID() . '_'
function! s:_function(fstr) abort
return function(substitute(a:fstr, 's:', s:_s, 'g'))
endfunction
endif

View File

@ -76,6 +76,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [denite](denite/) | 这一模块为 SpaceVim 提供了以 denite 为核心的异步模糊查找机制,支持模糊搜索文件、历史记录、函数列表等。 |
| [edit](edit/) | 这一模块为 SpaceVim 提供了更好的文本编辑体验,提供更多种文本对象。 |
| [floobits](floobits/) | 这一模块为 SpaceVim 提供了 floobits 协作工具的支持,实现多人协作编辑等功能。 |
| [foldsearch](foldsearch/) | 这一模块为 SpaceVim 提供了 foldsearch 支持,实现的异步搜索折叠的功能。 |
| [format](format/) | 这一模块为 SpaceVim 提供了代码异步格式化功能,支持高度自定义配置和多种语言。 |
| [fzf](fzf/) | 这一模块为 SpaceVim 提供了以 fzf 为核心的异步模糊查找机制,支持模糊搜索文件、历史记录、函数列表等。 |
| [git](git/) | 这一模块为 SpaceVim 提供了 Git 支持,根据当前 Vim 版本特性,选择 gina 或者 gita 作为默认的后台 Git 插件。 |
@ -83,6 +84,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [gtags](gtags/) | 这一模块为 SpaceVim 提供了全局的 gtags 索引管理,提供快速检索定义和引用的功能。 |
| [japanese](japanese/) | 这一模块为 SpaceVim 的日文用户提供了日文的 Vim 帮助文档,同时提供部分插件的日文帮助文档。 |
| [lang#WebAssembly](lang/WebAssembly/) | 这一模块为 SpaceVim 提供了 WebAssembly 的开发支持。 |
| [lang#actionscript](lang/actionscript/) | 这一模块为 actionscript 提供语法高亮 |
| [lang#agda](lang/agda/) | 这一模块为 SpaceVim 提供了 Agda 的开发支持,主要包括语法高亮及一键运行。 |
| [lang#asciidoc](lang/asciidoc/) | 这一模块为 SpaceVim 提供了 AsciiDoc 的编辑支持,包括格式化、自动生成文章目录、代码块等特性。 |
| [lang#aspectj](lang/aspectj/) | 这一模块为 SpaceVim 提供了 AsepctJ 的编辑支持,包括代码高亮。 |
@ -92,6 +94,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [lang#c](lang/c/) | 这一模块为 SpaceVim 提供了 C/C++/Object-C 的开发支持,包括代码补全、语法检查等特性。 |
| [lang#chapel](lang/chapel/) | 这一模块为 chapel 开发提供支持,包括交互式编程、一键运行等特性。 |
| [lang#clojure](lang/clojure/) | 这一模块为 SpaceVim 提供了 Clojure 的开发支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#coffeescript](lang/coffeescript/) | 这一模块为 CoffeeScript 开发提供支持,包括交互式编程、一键运行等特性。 |
| [lang#crystal](lang/crystal/) | 这一模块为 crystal 开发提供支持,包括交互式编程、一键运行等特性。 |
| [lang#csharp](lang/csharp/) | 这一模块为 SpaceVim 提供了 CSharp 的开发支持,包括代码高亮、对齐、补全等特性。 |
| [lang#d](lang/d/) | 这一模块为 d 开发提供支持,包括语法高亮、自动补全、一键运行等特性。 |
@ -166,6 +169,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [test](test/) | 这一模块为 SpaceVim 提供了一个测试框架,支持快速运行多种语言的单元测试。 |
| [tmux](tmux/) | 这一模块为 SpaceVim 提供了一些在 Vim 内操作 tmux 的功能,使得在 tmux 窗口之间跳转更加便捷。 |
| [tools#dash](tools/dash/) | 这一模块为 SpaceVim 提供了 Dash 支持,可快速查找光标位置的单词。 |
| [tools#mpv](tools/mpv/) | 这一模块为 SpaceVim 提供了 mpv 支持,可快速查找光标位置的单词。 |
| [tools](tools/) | 这一模块为 SpaceVim 提供了多种常用工具,包括日历、计算器等多种工具类插件,并针对 Vim8 以及 Neovim 提供了更好的插件选择。 |
| [ui](ui/) | 这一模块为 SpaceVim 提供了 IDE-like 的界面,包括状态栏、文件树、语法树等等特性。 |
| [unite](unite/) | 这一模块为 SpaceVim 提供以 Unite 为核心的模糊查找机制,支持模糊搜索文件、历史纪录、函数列表等。 |

View File

@ -0,0 +1,53 @@
---
title: "SpaceVim tools#mpv 模块"
description: "这一模块为 SpaceVim 提供了mpv支持可快速查找光标位置的单词。"
lang: zh
---
# [可用模块](../) >> tools#mpv
<!-- vim-markdown-toc GFM -->
- [模块描述](#模块描述)
- [启用模块](#启用模块)
- [模块选项](#模块选项)
- [快捷键](#快捷键)
<!-- vim-markdown-toc -->
## 模块描述
该模块为 SpaceVim 提供了 mpv 集成。
## 启用模块
tools#mpv 模块默认并未启用,如果需要启用该模块,需要在配置文件里面加入:
```toml
[[layers]]
name = "tools#mpv"
```
## 模块选项
- `musics_directory`: 设置音乐存放文件夹
- `mpv_interpreter`: mpv 可执行命令路径
- `loop_mode`: 循环模式,默认是 `random`
example:
```toml
[[layers]]
name = 'tools#mpv'
mpv_interpreter = 'D:\Program Files\mpv\mpv.exe'
musics_directory = 'F:\other\musics'
```
## 快捷键
| 快捷键 | 功能描述 |
| ----------- | ---------------- |
| `SPC m m l` | 模糊搜索音乐列表 |
| `SPC m m n` | 下一首 |
| `SPC m m s` | 停止播放 |

View File

@ -83,7 +83,7 @@ Some layers are enabled by default. The following example shows how to disable `
| [denite](denite/) | This layers provide a heavily customized Denite centric work-flow |
| [edit](edit/) | Improve code edit expr in SpaceVim, provide more text opjects. |
| [floobits](floobits/) | This layer adds support for the peer programming tool floobits to SpaceVim. |
| [foldsearch](foldsearch/) | This layer provides functions that fold away lines that don't match a specific search pattern.|
| [foldsearch](foldsearch/) | This layer provides functions that fold away lines that don't match a specific search pattern. |
| [format](format/) | Code formatting support for SpaceVim |
| [fzf](fzf/) | This layers provide a heavily customized fzf centric work-flow |
| [git](git/) | This layers adds extensive support for git |
@ -91,6 +91,7 @@ Some layers are enabled by default. The following example shows how to disable `
| [gtags](gtags/) | This layer provide gtags manager for project |
| [japanese](japanese/) | Layer for japanese users, include japanese docs and runtime messages |
| [lang#WebAssembly](lang/WebAssembly/) | This layer adds WebAssembly support to SpaceVim |
| [lang#actionscript](lang/actionscript/) | This layer is for actionscript syntax highlighting |
| [lang#agda](lang/agda/) | This layer adds Agda language support to SpaceVim. |
| [lang#asciidoc](lang/asciidoc/) | Edit AsciiDoc within vim, autopreview AsciiDoc in the default browser, with this layer you can also format AsciiDoc file. |
| [lang#aspectj](lang/aspectj/) | AsepctJ language support, include syntax highlighting. |
@ -178,6 +179,7 @@ Some layers are enabled by default. The following example shows how to disable `
| [test](test/) | This layer allows to run tests directly on SpaceVim |
| [tmux](tmux/) | This layers adds extensive support for tmux |
| [tools#dash](tools/dash/) | This layer provides Dash integration for SpaceVim |
| [tools#mpv](tools/mpv/) | This layer provides mpv integration for SpaceVim |
| [tools#zeal](tools/zeal/) | This layer provides Zeal integration for SpaceVim |
| [tools](tools/) | This layer provides some tools for vim |
| [ui](ui/) | Awesome UI layer for SpaceVim, provide IDE-like UI for neovim and vim in both TUI and GUI |

51
docs/layers/tools/mpv.md Normal file
View File

@ -0,0 +1,51 @@
---
title: "SpaceVim tools#mpv layer"
description: "This layer provides mpv integration for SpaceVim"
---
# [SpaceVim Layers:](https://spacevim.org/layers) tools#mpv
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Install](#install)
- [Options](#options)
- [Key bindings](#key-bindings)
<!-- vim-markdown-toc -->
## Description
This layer provides mpv integration for SpaceVim.
## Install
To use this configuration layer, add it to your `~/.SpaceVim.d/init.toml`.
```toml
[[layers]]
name = "tools#mpv"
```
## Options
- `musics_directory`: the directory of musics
- `mpv_interpreter`: mpv executable path
- `loop_mode`: loop mode, default is `random`
example:
```toml
[[layers]]
name = 'tools#mpv'
mpv_interpreter = 'D:\Program Files\mpv\mpv.exe'
musics_directory = 'F:\other\musics'
```
## Key bindings
| Key Binding | Description |
| ----------- | ----------------- |
| `SPC m m l` | fuzzy find musics |
| `SPC m m n` | next musics |
| `SPC m m s` | stop mpv |