From b34e3bec94acf78eea4af9d389796017f4758a72 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 27 Jun 2017 22:15:56 +0800 Subject: [PATCH 01/63] Add Achievements --- docs/documentation.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/documentation.md b/docs/documentation.md index 029940ed8..d1cc07ca1 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1146,6 +1146,10 @@ Symbol | Description | Custom option `✖` | Error | `g:spacevim_error_symbol` `➤` | warning | `g:spacevim_warning_symbol` + + + + ## Features ### Awesome ui From 9e69df0c8513e116ba57f86bab50175d329555e5 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 27 Jun 2017 23:08:00 +0800 Subject: [PATCH 02/63] Add achievements func --- .../autoload/SpaceVim/dev/Achievements.vim | 37 +++++++++++++++++++ docs/documentation.md | 4 +- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 .SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim diff --git a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim new file mode 100644 index 000000000..6f620196c --- /dev/null +++ b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim @@ -0,0 +1,37 @@ +function! s:generate_content() abort + let content = [] + let content += s:issues_ac() + return content +endfunction + +function! s:find_position() abort + let start = search('','bwnc') + let end = search('','bnwc') + return [start, end] +endfunction + +function! s:issues_ac() abort + let line = ['### issues'] + call add(line, '') + call add(line, 'Achievements | Account') + call add(line, '----- | -----') + let acc = [100, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000] + for id in acc + let issue = github#api#issues#Get_issue('SpaceVim', 'SpaceVim', id) + if has_key(issue, 'id') + let is_pr = has_key(issue, 'pull_request') + call add(line, id . 'th issue(' . (is_pr ? 'PR' : 'issue') . ') | ' . issue.user.login) + else + break + endif + endfor + return line +endfunction + +function! SpaceVim#dev#Achievements#update() + let [start, end] = s:find_position() + if start != 0 && end != 0 + exe (start + 1) . ',' . (end - 1) . 'delete' + call append(start, s:generate_content()) + endif +endfunction diff --git a/docs/documentation.md b/docs/documentation.md index d1cc07ca1..bc3ba57ff 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1146,9 +1146,9 @@ Symbol | Description | Custom option `✖` | Error | `g:spacevim_error_symbol` `➤` | warning | `g:spacevim_warning_symbol` - + - + ## Features From c0bb57f766866363b5c5d53010584fa17c66ad65 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 27 Jun 2017 23:22:06 +0800 Subject: [PATCH 03/63] Update achievements func --- .../autoload/SpaceVim/dev/Achievements.vim | 17 ++++++++++++----- docs/documentation.md | 9 +++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim index 6f620196c..ef1b32a59 100644 --- a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim +++ b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim @@ -1,13 +1,13 @@ function! s:generate_content() abort - let content = [] + let content = ['## Achievements', ''] let content += s:issues_ac() return content endfunction function! s:find_position() abort - let start = search('','bwnc') - let end = search('','bnwc') - return [start, end] + let start = search('^$','bwnc') + let end = search('^$','bnwc') + return sort([start, end]) endfunction function! s:issues_ac() abort @@ -20,11 +20,18 @@ function! s:issues_ac() abort let issue = github#api#issues#Get_issue('SpaceVim', 'SpaceVim', id) if has_key(issue, 'id') let is_pr = has_key(issue, 'pull_request') - call add(line, id . 'th issue(' . (is_pr ? 'PR' : 'issue') . ') | ' . issue.user.login) + call add(line, '[' . id . 'th issue(' . + \ (is_pr ? 'PR' : 'issue') . + \ ')](https://github.com/SpaceVim/SpaceVim/issues/' . id . ') | [' . issue.user.login + \ . '](https://github.com/' . issue.user.login . ')' + \ ) else break endif endfor + if line[-1] != '' + let line += [''] + endif return line endfunction diff --git a/docs/documentation.md b/docs/documentation.md index bc3ba57ff..9bb25b51b 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -79,6 +79,8 @@ title: "Documentation" * [Editing](#editing) * [Multi-Encodings](#multi-encodings) * [Errors handling](#errors-handling) +* [Achievements](#achievements) + * [issues](#issues) * [Features](#features) * [Awesome ui](#awesome-ui-1) * [Mnemonic key bindings](#mnemonic-key-bindings) @@ -1147,6 +1149,13 @@ Symbol | Description | Custom option `➤` | warning | `g:spacevim_warning_symbol` +## Achievements + +### issues + +Achievements | Account +----- | ----- +[100th issue(issue)](https://github.com/SpaceVim/SpaceVim/issues/100) | [BenBergman](https://github.com/BenBergman) From efd833054fc09c55fb034c8a6c60062b93d7bc86 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 28 Jun 2017 00:33:52 +0800 Subject: [PATCH 04/63] Add func for list stargazers --- .../autoload/SpaceVim/dev/Achievements.vim | 30 ++++++++++++++++--- docs/documentation.md | 7 +++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim index ef1b32a59..62372da96 100644 --- a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim +++ b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim @@ -1,7 +1,8 @@ function! s:generate_content() abort - let content = ['## Achievements', ''] - let content += s:issues_ac() - return content + let content = ['## Achievements', ''] + let content += s:issues_ac() + let content += s:stargazers_ac() + return content endfunction function! s:find_position() abort @@ -35,10 +36,31 @@ function! s:issues_ac() abort return line endfunction +function! s:stargazers_ac() abort + let line = ['### Stars, forks and watchers'] + call add(line, '') + call add(line, 'Achievements | Account') + call add(line, '----- | -----') + let stc = [1, 100, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000] + for id in stc + if id == 1 + let user = github#api#activity#List_stargazers('SpaceVim','SpaceVim')[0] + call add(line, 'First stargazers | [' . user.login . '](https://github.com/)' . user.login) + else + endif + endfor + if line[-1] != '' + let line += [''] + endif + return line +endfunction + function! SpaceVim#dev#Achievements#update() let [start, end] = s:find_position() if start != 0 && end != 0 - exe (start + 1) . ',' . (end - 1) . 'delete' + if end - start > 1 + exe (start + 1) . ',' . (end - 1) . 'delete' + endif call append(start, s:generate_content()) endif endfunction diff --git a/docs/documentation.md b/docs/documentation.md index 9bb25b51b..5e25b88b6 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -81,6 +81,7 @@ title: "Documentation" * [Errors handling](#errors-handling) * [Achievements](#achievements) * [issues](#issues) + * [Stars, forks and watchers](#stars-forks-and-watchers) * [Features](#features) * [Awesome ui](#awesome-ui-1) * [Mnemonic key bindings](#mnemonic-key-bindings) @@ -1157,6 +1158,12 @@ Achievements | Account ----- | ----- [100th issue(issue)](https://github.com/SpaceVim/SpaceVim/issues/100) | [BenBergman](https://github.com/BenBergman) +### Stars, forks and watchers + +Achievements | Account +----- | ----- +First stargazers | [monkeydterry](https://github.com/)monkeydterry + ## Features From 985fa6e7f84a662ad1e3482289683d4c4cbde2de Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 28 Jun 2017 00:35:58 +0800 Subject: [PATCH 05/63] Fix url type --- .SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim index 62372da96..6a2664c65 100644 --- a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim +++ b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim @@ -45,7 +45,7 @@ function! s:stargazers_ac() abort for id in stc if id == 1 let user = github#api#activity#List_stargazers('SpaceVim','SpaceVim')[0] - call add(line, 'First stargazers | [' . user.login . '](https://github.com/)' . user.login) + call add(line, 'First stargazers | [' . user.login . '](https://github.com/' . user.login . ')') else endif endfor From 3093eb866d4e1bb1111b3b193564a6a85de36690 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 28 Jun 2017 21:08:53 +0800 Subject: [PATCH 06/63] Finish star_rc --- .SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim | 12 ++++++++++++ docs/documentation.md | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim index 6a2664c65..700d6e8fc 100644 --- a/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim +++ b/.SpaceVim.d/autoload/SpaceVim/dev/Achievements.vim @@ -47,6 +47,18 @@ function! s:stargazers_ac() abort let user = github#api#activity#List_stargazers('SpaceVim','SpaceVim')[0] call add(line, 'First stargazers | [' . user.login . '](https://github.com/' . user.login . ')') else + let index = id % 30 + if index == 0 + let page = id/30 + let index = 30 + else + let page = id/30 + 1 + endif + let users = github#api#activity#List_stargazers('SpaceVim','SpaceVim', page) + if type(users) == type([]) && len(users) >= index + let user = users[index - 1] + call add(line, id . 'th stargazers | [' . user.login . '](https://github.com/' . user.login . ')') + endif endif endfor if line[-1] != '' diff --git a/docs/documentation.md b/docs/documentation.md index 5e25b88b6..986ba4d6b 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1162,7 +1162,11 @@ Achievements | Account Achievements | Account ----- | ----- -First stargazers | [monkeydterry](https://github.com/)monkeydterry +First stargazers | [monkeydterry](https://github.com/monkeydterry) +100th stargazers | [naraj](https://github.com/naraj) +1000th stargazers | [icecity96](https://github.com/icecity96) +2000th stargazers | [frowhy](https://github.com/frowhy) +3000th stargazers | [purkylin](https://github.com/purkylin) From 12db8408ef2afeaca10e61503c2de15b2fdfc6f0 Mon Sep 17 00:00:00 2001 From: Ubayd Date: Wed, 28 Jun 2017 23:49:44 +0300 Subject: [PATCH 07/63] Plugin vimfiler config direction --- config/plugins/vimfiler.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/plugins/vimfiler.vim b/config/plugins/vimfiler.vim index 9a8f1a680..9bfdd8a21 100644 --- a/config/plugins/vimfiler.vim +++ b/config/plugins/vimfiler.vim @@ -8,6 +8,7 @@ let g:vimfiler_tree_closed_icon = get(g:, 'vimfiler_tree_closed_icon', '▷') let g:vimfiler_file_icon = get(g:, 'vimfiler_file_icon', '') let g:vimfiler_readonly_file_icon = get(g:, 'vimfiler_readonly_file_icon', '*') let g:vimfiler_marked_file_icon = get(g:, 'vimfiler_marked_file_icon', '√') +let g:vimfiler_direction = get(g:, 'vimfiler_direction', 'rightbelow') "let g:vimfiler_preview_action = 'auto_preview' let g:vimfiler_ignore_pattern = get(g:, 'vimfiler_ignore_pattern', [ \ '^\.git$', @@ -41,7 +42,7 @@ call vimfiler#custom#profile('default', 'context', { \ 'winminwidth' : 30, \ 'toggle' : 1, \ 'auto_expand': 1, - \ 'direction' : 'rightbelow', + \ 'direction' : g:vimfiler_direction, \ 'explorer_columns' : s:setcolum(), \ 'parent': 0, \ 'status' : 1, From 2efc4ac5096eb9dd1626a38559cf6ce8929810ce Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Thu, 29 Jun 2017 13:45:29 +0800 Subject: [PATCH 08/63] Update index.md --- docs/layers/index.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/layers/index.md b/docs/layers/index.md index 56d3bc9c5..e90b2b059 100644 --- a/docs/layers/index.md +++ b/docs/layers/index.md @@ -3,6 +3,12 @@ Name | Description | Documentation ----- |:----:| ------------------ default | better default for vim and neovim | [documentation](https://spacevim.org/layers/default) +checkers | checking in vim | [documentation](https://spacevim.org/layers/checkers) +autocomplete | autocomplete in vim | [documentation](https://spacevim.org/layers/autocomplete) +chinese | layer for chinese vimer | [documentation](https://spacevim.org/layers/chinese) +colorscheme | all colorscheme in spacevim | [documentation](https://spacevim.org/layers/colorscheme) chat | chatting in vim | [documentation](https://spacevim.org/layers/chat) lang#java | java development in vim | [documentation](https://spacevim.org/layers/lang/java) lang#lisp | lisp development in vim | [documentation](https://spacevim.org/layers/lang/lisp) +lang#markdown | layer for editing markdown in vim | [documentation](https://spacevim.org/layers/lang/markdown) +lang#php | php development in vim | [documentation](https://spacevim.org/layers/lang/php) From 56d2b17dfc5cfd8438be3096a1080c7575ddb0f6 Mon Sep 17 00:00:00 2001 From: techgaun Date: Fri, 30 Jun 2017 12:18:03 -0500 Subject: [PATCH 09/63] update gina docs --- docs/documentation.md | 200 +++++++++++++++++++++--------------------- 1 file changed, 101 insertions(+), 99 deletions(-) diff --git a/docs/documentation.md b/docs/documentation.md index 986ba4d6b..47123750d 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -6,121 +6,121 @@ title: "Documentation" * [Core Pillars](#core-pillars) - * [Mnemonic](#mnemonic) - * [Discoverable](#discoverable) - * [Consistent](#consistent) - * [Crowd-Configured](#crowd-configured) + * [Mnemonic](#mnemonic) + * [Discoverable](#discoverable) + * [Consistent](#consistent) + * [Crowd-Configured](#crowd-configured) * [Highlighted features](#highlighted-features) * [Screenshots](#screenshots) - * [welcome page](#welcome-page) - * [working flow](#working-flow) + * [welcome page](#welcome-page) + * [working flow](#working-flow) * [Who can benefit from this?](#who-can-benefit-from-this) * [Update and Rollback](#update-and-rollback) - * [Update SpaceVim itself](#update-spacevim-itself) - * [Automatic Updates](#automatic-updates) - * [Updating from the SpaceVim Buffer](#updating-from-the-spacevim-buffer) - * [Updating Manually with git](#updating-manually-with-git) - * [Update plugins](#update-plugins) + * [Update SpaceVim itself](#update-spacevim-itself) + * [Automatic Updates](#automatic-updates) + * [Updating from the SpaceVim Buffer](#updating-from-the-spacevim-buffer) + * [Updating Manually with git](#updating-manually-with-git) + * [Update plugins](#update-plugins) * [Configuration layers](#configuration-layers) * [Custom Configuration](#custom-configuration) - * [Automatic Generation](#automatic-generation) - * [Alternative directory](#alternative-directory) + * [Automatic Generation](#automatic-generation) + * [Alternative directory](#alternative-directory) * [Awesome ui](#awesome-ui) - * [Colorschemes](#colorschemes) - * [Font](#font) - * [UI Toggles](#ui-toggles) - * [Statusline && tabline](#statusline--tabline) - * [statusline](#statusline) - * [tabline](#tabline) + * [Colorschemes](#colorschemes) + * [Font](#font) + * [UI Toggles](#ui-toggles) + * [Statusline && tabline](#statusline--tabline) + * [statusline](#statusline) + * [tabline](#tabline) * [Manual](#manual) - * [Completion](#completion) - * [Unite/Denite](#unitedenite) - * [Mappings within unite/denite buffer](#mappings-within-unitedenite-buffer) - * [Discovering](#discovering) - * [Mappings](#mappings) - * [Mappings guide](#mappings-guide) - * [Unide/Denite describe key bindings](#unidedenite-describe-key-bindings) - * [Getting help](#getting-help) - * [Available layers](#available-layers) - * [Available plugins in SpaceVim](#available-plugins-in-spacevim) - * [New packages from ELPA repositories](#new-packages-from-elpa-repositories) - * [Toggles](#toggles) - * [Navigating](#navigating) - * [Point/Cursor](#pointcursor) - * [Vim motions with vim-easymotion](#vim-motions-with-vim-easymotion) - * [quick-jump-link mode (TODO)](#quick-jump-link-mode-todo) - * [Unimpaired bindings](#unimpaired-bindings) - * [Jumping, Joining and Splitting](#jumping-joining-and-splitting) - * [Jumping](#jumping) - * [Joining and splitting](#joining-and-splitting) - * [Window manipulation](#window-manipulation) - * [Window manipulation key bindings](#window-manipulation-key-bindings) - * [Buffers and Files](#buffers-and-files) - * [Buffers manipulation key bindings](#buffers-manipulation-key-bindings) - * [Create a new empty buffer](#create-a-new-empty-buffer) - * [Special Buffers](#special-buffers) - * [Files manipulations key bindings](#files-manipulations-key-bindings) - * [Vim and SpaceVim files](#vim-and-spacevim-files) - * [File tree](#file-tree) - * [File tree navigation](#file-tree-navigation) - * [Open file with file tree.](#open-file-with-file-tree) - * [Commands starting with `g`](#commands-starting-with-g) - * [Commands starting with `z`](#commands-starting-with-z) - * [Auto-saving](#auto-saving) - * [Searching](#searching) - * [With an external tool](#with-an-external-tool) - * [Useful key bindings](#useful-key-bindings) - * [Searching in current file](#searching-in-current-file) - * [Searching in all loaded buffers](#searching-in-all-loaded-buffers) - * [Searching in an arbitrary directory](#searching-in-an-arbitrary-directory) - * [Searching in a project](#searching-in-a-project) - * [Searching the web](#searching-the-web) - * [Persistent highlighting](#persistent-highlighting) - * [Editing](#editing) - * [Multi-Encodings](#multi-encodings) - * [Errors handling](#errors-handling) + * [Completion](#completion) + * [Unite/Denite](#unitedenite) + * [Mappings within unite/denite buffer](#mappings-within-unitedenite-buffer) + * [Discovering](#discovering) + * [Mappings](#mappings) + * [Mappings guide](#mappings-guide) + * [Unide/Denite describe key bindings](#unidedenite-describe-key-bindings) + * [Getting help](#getting-help) + * [Available layers](#available-layers) + * [Available plugins in SpaceVim](#available-plugins-in-spacevim) + * [New packages from ELPA repositories](#new-packages-from-elpa-repositories) + * [Toggles](#toggles) + * [Navigating](#navigating) + * [Point/Cursor](#pointcursor) + * [Vim motions with vim-easymotion](#vim-motions-with-vim-easymotion) + * [quick-jump-link mode (TODO)](#quick-jump-link-mode-todo) + * [Unimpaired bindings](#unimpaired-bindings) + * [Jumping, Joining and Splitting](#jumping-joining-and-splitting) + * [Jumping](#jumping) + * [Joining and splitting](#joining-and-splitting) + * [Window manipulation](#window-manipulation) + * [Window manipulation key bindings](#window-manipulation-key-bindings) + * [Buffers and Files](#buffers-and-files) + * [Buffers manipulation key bindings](#buffers-manipulation-key-bindings) + * [Create a new empty buffer](#create-a-new-empty-buffer) + * [Special Buffers](#special-buffers) + * [Files manipulations key bindings](#files-manipulations-key-bindings) + * [Vim and SpaceVim files](#vim-and-spacevim-files) + * [File tree](#file-tree) + * [File tree navigation](#file-tree-navigation) + * [Open file with file tree.](#open-file-with-file-tree) + * [Commands starting with `g`](#commands-starting-with-g) + * [Commands starting with `z`](#commands-starting-with-z) + * [Auto-saving](#auto-saving) + * [Searching](#searching) + * [With an external tool](#with-an-external-tool) + * [Useful key bindings](#useful-key-bindings) + * [Searching in current file](#searching-in-current-file) + * [Searching in all loaded buffers](#searching-in-all-loaded-buffers) + * [Searching in an arbitrary directory](#searching-in-an-arbitrary-directory) + * [Searching in a project](#searching-in-a-project) + * [Searching the web](#searching-the-web) + * [Persistent highlighting](#persistent-highlighting) + * [Editing](#editing) + * [Multi-Encodings](#multi-encodings) + * [Errors handling](#errors-handling) * [Achievements](#achievements) - * [issues](#issues) - * [Stars, forks and watchers](#stars-forks-and-watchers) + * [issues](#issues) + * [Stars, forks and watchers](#stars-forks-and-watchers) * [Features](#features) - * [Awesome ui](#awesome-ui-1) - * [Mnemonic key bindings](#mnemonic-key-bindings) + * [Awesome ui](#awesome-ui-1) + * [Mnemonic key bindings](#mnemonic-key-bindings) * [Language specific mode](#language-specific-mode) * [Key Mapping](#key-mapping) - * [c/c++ support](#cc-support) - * [go support](#go-support) - * [python support](#python-support) + * [c/c++ support](#cc-support) + * [go support](#go-support) + * [python support](#python-support) * [Neovim centric - Dark powered mode of SpaceVim.](#neovim-centric---dark-powered-mode-of-spacevim) * [Modular configuration](#modular-configuration) * [Multiple leader mode](#multiple-leader-mode) - * [Global origin vim leader](#global-origin-vim-leader) - * [Local origin vim leader](#local-origin-vim-leader) - * [Windows function leader](#windows-function-leader) - * [Unite work flow leader](#unite-work-flow-leader) + * [Global origin vim leader](#global-origin-vim-leader) + * [Local origin vim leader](#local-origin-vim-leader) + * [Windows function leader](#windows-function-leader) + * [Unite work flow leader](#unite-work-flow-leader) * [Unite centric work-flow](#unite-centric-work-flow) - * [Plugin Highlights](#plugin-highlights) - * [Non Lazy-Loaded Plugins](#non-lazy-loaded-plugins) - * [Lazy-Loaded Plugins](#lazy-loaded-plugins) - * [Language](#language) - * [Commands](#commands) - * [Commands](#commands-1) - * [Completion](#completion-1) - * [Unite](#unite) - * [Operators & Text Objects](#operators--text-objects) - * [Custom Key bindings](#custom-key-bindings) - * [File Operations](#file-operations) - * [Editor UI](#editor-ui) - * [Window Management](#window-management) - * [Native functions](#native-functions) - * [Plugin: Unite](#plugin-unite) - * [Plugin: neocomplete](#plugin-neocomplete) - * [Plugin: NERD Commenter](#plugin-nerd-commenter) - * [Plugin: Goyo and Limelight](#plugin-goyo-and-limelight) - * [Plugin: ChooseWin](#plugin-choosewin) - * [Plugin: Bookmarks](#plugin-bookmarks) - * [Plugin: Gita](#plugin-gita) - * [Plugin: vim-signify](#plugin-vim-signify) - * [Misc Plugins](#misc-plugins) + * [Plugin Highlights](#plugin-highlights) + * [Non Lazy-Loaded Plugins](#non-lazy-loaded-plugins) + * [Lazy-Loaded Plugins](#lazy-loaded-plugins) + * [Language](#language) + * [Commands](#commands) + * [Commands](#commands-1) + * [Completion](#completion-1) + * [Unite](#unite) + * [Operators & Text Objects](#operators--text-objects) + * [Custom Key bindings](#custom-key-bindings) + * [File Operations](#file-operations) + * [Editor UI](#editor-ui) + * [Window Management](#window-management) + * [Native functions](#native-functions) + * [Plugin: Unite](#plugin-unite) + * [Plugin: neocomplete](#plugin-neocomplete) + * [Plugin: NERD Commenter](#plugin-nerd-commenter) + * [Plugin: Goyo and Limelight](#plugin-goyo-and-limelight) + * [Plugin: ChooseWin](#plugin-choosewin) + * [Plugin: Bookmarks](#plugin-bookmarks) + * [Plugin: Gita](#plugin-gita) + * [Plugin: vim-signify](#plugin-vim-signify) + * [Misc Plugins](#misc-plugins) @@ -1592,6 +1592,8 @@ Key | Mode | Action ``+`gc` | Normal | Git commit ``+`gb` | Normal | Git blame ``+`gp` | Normal | Git push +``+`ga` | Normal | Git add current buffer +``+`gA` | Normal | Git add all files ##### Plugin: vim-signify From f268a70896dcff27f32afe5c8b651d2c8fad63ca Mon Sep 17 00:00:00 2001 From: techgaun Date: Fri, 30 Jun 2017 12:19:46 -0500 Subject: [PATCH 10/63] update title --- docs/documentation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/documentation.md b/docs/documentation.md index 47123750d..ea345cb53 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -118,7 +118,7 @@ title: "Documentation" * [Plugin: Goyo and Limelight](#plugin-goyo-and-limelight) * [Plugin: ChooseWin](#plugin-choosewin) * [Plugin: Bookmarks](#plugin-bookmarks) - * [Plugin: Gita](#plugin-gita) + * [Plugin: Gina/Gita](#plugin-ginagita) * [Plugin: vim-signify](#plugin-vim-signify) * [Misc Plugins](#misc-plugins) @@ -1583,7 +1583,7 @@ Key | Mode | Action As SpaceVim use above bookmarks mappings, so you can not use `a`, `m`, `n`, `p` or `i` registers to mark current position, but other registers should works will. if you really need to use these registers, you can add `nnoremap m m` to your custom configuration, then you use use `a` registers via `\ma` -##### Plugin: Gita +##### Plugin: Gina/Gita Key | Mode | Action ----- |:----:| ------------------ From d05566c9012a7eff613b88e717a83a3404fbaf91 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sat, 1 Jul 2017 01:32:14 -0500 Subject: [PATCH 11/63] Add text insertion commands (#685) * Add text insertion commands * Add password api * Implement SPC i p * * Add mapping for uuidgen * Add SPC i l l for insert lorem-ipsum list * Add SPC i l p for insert lorem-ipsum paragraph * Add SPC i l s for insert lorem-ipsum sentence * Fix lint --- autoload/SpaceVim/api/data/list.vim | 28 ++++ autoload/SpaceVim/api/data/string.vim | 9 ++ autoload/SpaceVim/api/password.vim | 81 ++++++++++++ autoload/SpaceVim/layers/edit.vim | 179 ++++++++++++++++++++++++++ autoload/SpaceVim/layers/unite.vim | 1 + doc/SpaceVim.txt | 23 +++- docs/documentation.md | 19 +++ 7 files changed, 338 insertions(+), 2 deletions(-) create mode 100644 autoload/SpaceVim/api/password.vim diff --git a/autoload/SpaceVim/api/data/list.vim b/autoload/SpaceVim/api/data/list.vim index 801bc784f..512e53877 100644 --- a/autoload/SpaceVim/api/data/list.vim +++ b/autoload/SpaceVim/api/data/list.vim @@ -8,15 +8,43 @@ function! SpaceVim#api#data#list#get() abort \ 'char_range' : '', \ 'has' : '', \ 'has_index' : '', + \ 'listpart' : '', \ }, \ "function('s:' . v:key)" \ ) endfunction +"" +" @section data#list, api-data-list +" @parentsection api +" pop({list}) +" +" Removes the last element from {list} and returns the element, +" as if the {list} is a stack. +" +" push({list}) +" +" Appends {val} to the end of {list} and returns the list itself, +" as if the {list} is a stack. +" +" listpart({list}, {start}[, {len}]) +" +" The result is a List, which is part of {list}, starting from +" index {start}, with the length {len} + function! s:pop(list) abort return remove(a:list, -1) endfunction +function! s:listpart(list, start, ...) + let idx = range(a:start, a:start + get(a:000, 0, 0)) + let rst = [] + for i in idx + call add(rst, get(a:list, i)) + endfor + return rst +endfunction + function! s:push(list, val) abort call add(a:list, a:val) return a:list diff --git a/autoload/SpaceVim/api/data/string.vim b/autoload/SpaceVim/api/data/string.vim index 97180e581..5ca65101b 100644 --- a/autoload/SpaceVim/api/data/string.vim +++ b/autoload/SpaceVim/api/data/string.vim @@ -63,6 +63,15 @@ endfunction let s:file['trim_end'] = function('s:trim_end') +function! s:string2chars(str) abort + let chars = [] + for i in range(len(a:str)) + call add(chars, a:str[i : i]) + endfor + return chars +endfunction +let s:file['string2chars'] = function('s:string2chars') + function! SpaceVim#api#data#string#get() abort return deepcopy(s:file) endfunction diff --git a/autoload/SpaceVim/api/password.vim b/autoload/SpaceVim/api/password.vim new file mode 100644 index 000000000..7756b8052 --- /dev/null +++ b/autoload/SpaceVim/api/password.vim @@ -0,0 +1,81 @@ +let s:self = {} + +let s:NUMBER = SpaceVim#api#import('data#number') +let s:STRING = SpaceVim#api#import('data#string') + +function! s:self.generate_simple(len) abort + let temp = s:STRING.string2chars('abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ') + let ps = [] + " random(0,len_temp) + let i = 0 + while i < str2nr(a:len) + call add(ps, temp[s:NUMBER.random(0, len(temp))]) + let i += 1 + endwhile + return join(ps, '') +endfunction + +function! s:self.generate_strong(len) abort + let temp = s:STRING.string2chars('abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ_@!.^%,&-') + let ps = [] + " random(0,len_temp) + let i = 0 + while i < str2nr(a:len) + call add(ps, temp[s:NUMBER.random(0, len(temp))]) + let i += 1 + endwhile + return join(ps, '') +endfunction + +function! s:self.generate_paranoid(len) abort + let temp = s:STRING.string2chars('abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_-+=/?,.><[]{}~') + let ps = [] + " random(0,len_temp) + let i = 0 + while i < str2nr(a:len) + call add(ps, temp[s:NUMBER.random(0, len(temp))]) + let i += 1 + endwhile + return join(ps, '') +endfunction + +function! s:self.generate_numeric(len) abort + let temp = s:STRING.string2chars('0123456789') + let ps = [] + " random(0,len_temp) + let i = 0 + while i < str2nr(a:len) + call add(ps, temp[s:NUMBER.random(0, len(temp))]) + let i += 1 + endwhile + return join(ps, '') +endfunction + +function! s:self.generate_phonetic(len) abort + let temp_A = s:STRING.string2chars('eyuioa') + let temp_B = s:STRING.string2chars('wrtpsdfghjkzxcvbnm') + let temp_N = s:STRING.string2chars('123456789') + let type = 1 + + let ps = [] + " random(0,len_temp) + let i = 0 + while i < str2nr(a:len) + if type == 1 + call add(ps, temp_A[s:NUMBER.random(0, len(temp_A))]) + let type = 2 + elseif type == 2 + call add(ps, temp_B[s:NUMBER.random(0, len(temp_B))]) + let type = 3 + elseif type == 3 + call add(ps, temp_N[s:NUMBER.random(0, len(temp_N))]) + let type = 1 + endif + let i += 1 + endwhile + return join(ps, '') +endfunction + +function! SpaceVim#api#password#get() abort + return deepcopy(s:self) +endfunction diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index b07429a21..6027aaa85 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -1,3 +1,8 @@ +let s:PASSWORD = SpaceVim#api#import('password') +let s:NUMBER = SpaceVim#api#import('data#number') +let s:LIST = SpaceVim#api#import('data#list') + + function! SpaceVim#layers#edit#plugins() abort let plugins = [ \ ['tpope/vim-surround'], @@ -38,4 +43,178 @@ function! SpaceVim#layers#edit#config() abort "noremap (wildfire-fuel) vnoremap (wildfire-water) let g:wildfire_objects = ["i'", 'i"', 'i)', 'i]', 'i}', 'ip', 'it'] + let g:_spacevim_mappings_space.i = {'name' : '+Insertion'} + let g:_spacevim_mappings_space.i.l = {'name' : '+Lorem-ipsum'} + let g:_spacevim_mappings_space.i.p = {'name' : '+Passwords'} + let g:_spacevim_mappings_space.i.U = {'name' : '+UUID'} + call SpaceVim#mapping#space#def('nnoremap', ['i', 'p', 1], 'call call(' + \ . string(s:_function('s:insert_simple_password')) . ', [])', + \ 'insert simple password', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'p', 2], 'call call(' + \ . string(s:_function('s:insert_stronger_password')) . ', [])', + \ 'insert stronger password', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'p', 3], 'call call(' + \ . string(s:_function('s:insert_paranoid_password')) . ', [])', + \ 'insert password for paranoids', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'p', 'p'], 'call call(' + \ . string(s:_function('s:insert_phonetically_password')) . ', [])', + \ 'insert a phonetically easy password', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'p', 'n'], 'call call(' + \ . string(s:_function('s:insert_numerical_password')) . ', [])', + \ 'insert a numerical password', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'u'], 'Unite unicode', 'search and insert unicode', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'U', 'U'], 'call call(' + \ . string(s:_function('s:uuidgen_U')) . ', [])', + \ 'uuidgen-4', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'l', 'l'], 'call call(' + \ . string(s:_function('s:insert_lorem_ipsum_list')) . ', [])', + \ 'insert lorem-ipsum list', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'l', 'p'], 'call call(' + \ . string(s:_function('s:insert_lorem_ipsum_paragraph')) . ', [])', + \ 'insert lorem-ipsum paragraph', 1) + call SpaceVim#mapping#space#def('nnoremap', ['i', 'l', 's'], 'call call(' + \ . string(s:_function('s:insert_lorem_ipsum_sentence')) . ', [])', + \ 'insert lorem-ipsum sentence', 1) endfunction +let s:local_lorem_ipsum = [ + \ 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.', + \ 'Donec hendrerit tempor tellus.', + \ 'Donec pretium posuere tellus.', + \ 'Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus.', + \ 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.', + \ 'Nulla posuere.', + \ 'Donec vitae dolor.', + \ 'Nullam tristique diam non turpis.', + \ 'Cras placerat accumsan nulla.', + \ 'Nullam rutrum.', + \ 'Nam vestibulum accumsan nisl.', + \ 'Pellentesque dapibus suscipit ligula.', + \ 'Donec posuere augue in quam.', + \ 'Etiam vel tortor sodales tellus ultricies commodo.', + \ 'Suspendisse potenti.', + \ 'Aenean in sem ac leo mollis blandit.', + \ 'Donec neque quam, dignissim in, mollis nec, sagittis eu, wisi.', + \ 'Phasellus lacus.', + \ 'Etiam laoreet quam sed arcu.', + \ 'Phasellus at dui in ligula mollis ultricies.', + \ 'Integer placerat tristique nisl.', + \ 'Praesent augue.', + \ 'Fusce commodo.', + \ 'Vestibulum convallis, lorem a tempus semper, dui dui euismod elit, vitae placerat urna tortor vitae lacus.', + \ 'Nullam libero mauris, consequat quis, varius et, dictum id, arcu.', + \ 'Mauris mollis tincidunt felis.', + \ 'Aliquam feugiat tellus ut neque.', + \ 'Nulla facilisis, risus a rhoncus fermentum, tellus tellus lacinia purus, et dictum nunc justo sit amet elit.', + \ 'Aliquam erat volutpat.', + \ 'Nunc eleifend leo vitae magna.', + \ 'In id erat non orci commodo lobortis.', + \ 'Proin neque massa, cursus ut, gravida ut, lobortis eget, lacus.', + \ 'Sed diam.', + \ 'Praesent fermentum tempor tellus.', + \ 'Nullam tempus.', + \ 'Mauris ac felis vel velit tristique imperdiet.', + \ 'Donec at pede.', + \ 'Etiam vel neque nec dui dignissim bibendum.', + \ 'Vivamus id enim.', + \ 'Phasellus neque orci, porta a, aliquet quis, semper a, massa.', + \ 'Phasellus purus.', + \ 'Pellentesque tristique imperdiet tortor.', + \ 'Nam euismod tellus id erat.', + \ 'Nullam eu ante vel est convallis dignissim.', + \ 'Fusce suscipit, wisi nec facilisis facilisis, est dui fermentum leo, quis tempor ligula erat quis odio.', + \ 'Nunc porta vulputate tellus.', + \ 'Nunc rutrum turpis sed pede.', + \ 'Sed bibendum.', + \ 'Aliquam posuere.', + \ 'Nunc aliquet, augue nec adipiscing interdum, lacus tellus malesuada massa, quis varius mi purus non odio.', + \ 'Pellentesque condimentum, magna ut suscipit hendrerit, ipsum augue ornare nulla, non luctus diam neque sit amet urna.', + \ 'Curabitur vulputate vestibulum lorem.', + \ 'Fusce sagittis, libero non molestie mollis, magna orci ultrices dolor, at vulputate neque nulla lacinia eros.', + \ 'Sed id ligula quis est convallis tempor.', + \ 'Curabitur lacinia pulvinar nibh.', + \ 'Nam a sapien.', + \ ] + +let s:lorem_ipsum_paragraph_separator = "\n\n" +let s:lorem_ipsum_sentence_separator = ' ' +let s:lorem_ipsum_list_beginning = '' +let s:lorem_ipsum_list_bullet = '* ' +let s:lorem_ipsum_list_item_end = "\n" +let s:lorem_ipsum_list_end = '' + +function! s:insert_lorem_ipsum_list() abort + let save_register = @k + let @k = '* ' . s:local_lorem_ipsum[s:NUMBER.random(0, len(s:local_lorem_ipsum))] . "\n" + normal! "kgP + let @k = save_register +endfunction + +function! s:insert_lorem_ipsum_paragraph() abort + let save_register = @k + let pids = len(s:local_lorem_ipsum) / 11 + let pid = s:NUMBER.random(0, pids) * 11 + let @k = join(s:LIST.listpart(s:local_lorem_ipsum, pid, 11), s:lorem_ipsum_sentence_separator) . s:lorem_ipsum_paragraph_separator + normal! "kgP + let @k = save_register +endfunction + +function! s:insert_lorem_ipsum_sentence() abort + let save_register = @k + let @k = s:local_lorem_ipsum[s:NUMBER.random(0, len(s:local_lorem_ipsum))] . s:lorem_ipsum_sentence_separator + normal! "kgP + let @k = save_register +endfunction + +function! s:insert_simple_password() abort + let save_register = @k + let @k = s:PASSWORD.generate_simple(8) + normal! "kPl + let @k = save_register +endfunction +function! s:insert_stronger_password() abort + let save_register = @k + let @k = s:PASSWORD.generate_strong(12) + normal! "kPl + let @k = save_register +endfunction +function! s:insert_paranoid_password() abort + let save_register = @k + let @k = s:PASSWORD.generate_paranoid(20) + normal! "kPl + let @k = save_register +endfunction +function! s:insert_numerical_password() abort + let save_register = @k + let @k = s:PASSWORD.generate_numeric(4) + normal! "kPl + let @k = save_register +endfunction +function! s:insert_phonetically_password() abort + let save_register = @k + let @k = s:PASSWORD.generate_phonetic(8) + normal! "kPl + let @k = save_register +endfunction + +function! s:uuidgen_U() abort + let uuid = system('uuidgen') + let save_register = @k + let @k = uuid + normal! "kPl + let @k = save_register +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(''), '\zs\d\+\ze__SID$') + endfunction + let s:_s = '' . s:_SID() . '_' + function! s:_function(fstr) abort + return function(substitute(a:fstr, 's:', s:_s, 'g')) + endfunction +endif diff --git a/autoload/SpaceVim/layers/unite.vim b/autoload/SpaceVim/layers/unite.vim index 78905a71c..31496d084 100644 --- a/autoload/SpaceVim/layers/unite.vim +++ b/autoload/SpaceVim/layers/unite.vim @@ -3,6 +3,7 @@ function! SpaceVim#layers#unite#plugins() abort \ ['Shougo/unite.vim',{ 'merged' : 0 , 'loadconf' : 1}], \ ['Shougo/neoyank.vim'], \ ['soh335/unite-qflist'], + \ ['SpaceVim/unite-unicode'], \ ['ujihisa/unite-equery'], \ ['m2mdas/unite-file-vcs'], \ ['Shougo/neomru.vim'], diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 80ad29bc5..f35e77a00 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -49,8 +49,9 @@ CONTENTS *SpaceVim-contents* 26. tmux...........................................|SpaceVim-layer-tmux| 6. API........................................................|SpaceVim-api| 1. cmdlinemenu................................|SpaceVim-api-cmdlinemenu| - 2. sid............................................|SpaceVim-api-vim-sid| - 3. vim#message................................|SpaceVim-api-vim-message| + 2. data#list....................................|SpaceVim-api-data-list| + 3. sid............................................|SpaceVim-api-vim-sid| + 4. vim#message................................|SpaceVim-api-vim-message| 7. FAQ........................................................|SpaceVim-faq| ============================================================================== @@ -963,6 +964,24 @@ Create a cmdline selection menu from a list of {items}, each item should be a list of two value in it, first one is the description, and the next one should be a funcrc. +============================================================================== +DATA#LIST *SpaceVim-api-data-list* + +pop({list}) + +Removes the last element from {list} and returns the element, as if the {list} +is a stack. + +push({list}) + +Appends {val} to the end of {list} and returns the list itself, as if the +{list} is a stack. + +listpart({list}, {start}[, {len}]) + +The result is a List, which is part of {list}, starting from index {start}, +with the length {len} + ============================================================================== SID *SpaceVim-api-vim-sid* diff --git a/docs/documentation.md b/docs/documentation.md index 986ba4d6b..e6079bf4e 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -77,6 +77,7 @@ title: "Documentation" * [Searching the web](#searching-the-web) * [Persistent highlighting](#persistent-highlighting) * [Editing](#editing) + * [Text insertion commands](#text-insertion-commands) * [Multi-Encodings](#multi-encodings) * [Errors handling](#errors-handling) * [Achievements](#achievements) @@ -1107,6 +1108,24 @@ SpaceVim uses `g:spacevim_search_highlight_persist` to keep the searched express ### Editing +#### Text insertion commands + +Text insertion commands (start with `i`): + +Key binding | Description +`SPC i l l` | insert lorem-ipsum list +`SPC i l p` | insert lorem-ipsum paragraph +`SPC i l s` | insert lorem-ipsum sentence +`SPC i p 1` | insert simple password +`SPC i p 2` | insert stronger password +`SPC i p 3` | insert password for paranoids +`SPC i p p` | insert a phonetically easy password +`SPC i p n` | insert a numerical password +`SPC i u` | Search for Unicode characters and insert them into the active buffer. +`SPC i U 1` | insert UUIDv1 (use universal argument to insert with CID format) +`SPC i U 4` | insert UUIDv4 (use universal argument to insert with CID format) +`SPC i U U` | insert UUIDv4 (use universal argument to insert with CID format) + #### Multi-Encodings SpaceVim use utf-8 as default encoding. there are four options for these case: From 8a4d2774feecf09d55bcdee4806f7131ed123a22 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 1 Jul 2017 19:54:30 +0800 Subject: [PATCH 12/63] Add comment doc --- docs/documentation.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/documentation.md b/docs/documentation.md index e6079bf4e..f7d2d0f6c 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -78,6 +78,7 @@ title: "Documentation" * [Persistent highlighting](#persistent-highlighting) * [Editing](#editing) * [Text insertion commands](#text-insertion-commands) + * [Commenting](#commenting) * [Multi-Encodings](#multi-encodings) * [Errors handling](#errors-handling) * [Achievements](#achievements) @@ -1113,6 +1114,7 @@ SpaceVim uses `g:spacevim_search_highlight_persist` to keep the searched express Text insertion commands (start with `i`): Key binding | Description +----------- | ----------- `SPC i l l` | insert lorem-ipsum list `SPC i l p` | insert lorem-ipsum paragraph `SPC i l s` | insert lorem-ipsum sentence @@ -1126,6 +1128,25 @@ Key binding | Description `SPC i U 4` | insert UUIDv4 (use universal argument to insert with CID format) `SPC i U U` | insert UUIDv4 (use universal argument to insert with CID format) +#### Commenting + +Comments are handled by [nerdcommenter](https://github.com/scrooloose/nerdcommenter), it’s bound to the following keys. + +Key Binding | Description +----------- | ----------- +`SPC ;` | comment operator +`SPC c h` | hide/show comments +`SPC c l` | comment lines +`SPC c L` | invert comment lines +`SPC c p` | comment paragraphs +`SPC c P` | invert comment paragraphs +`SPC c t` | comment to line +`SPC c T` | invert comment to line +`SPC c y` | comment and yank +`SPC c Y` | invert comment and yank + +**Tips:** To comment efficiently a block of line use the combo `SPC ; SPC j l` + #### Multi-Encodings SpaceVim use utf-8 as default encoding. there are four options for these case: From 398c8b24659ed6a49bfaa8044def5952bb4fb127 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 1 Jul 2017 20:37:48 +0800 Subject: [PATCH 13/63] Add SPC t m p for toggle cursor position close #692 --- autoload/SpaceVim/layers/core/statusline.vim | 13 +++++++++++-- docs/documentation.md | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim index 0b5e1d7bb..1f055dc07 100644 --- a/autoload/SpaceVim/layers/core/statusline.vim +++ b/autoload/SpaceVim/layers/core/statusline.vim @@ -53,7 +53,7 @@ let s:modes = { \ }, \ } -let s:loaded_sections = ['syntax checking', 'major mode', 'minor mode lighters', 'version control info'] +let s:loaded_sections = ['syntax checking', 'major mode', 'minor mode lighters', 'version control info', 'cursorpos'] function! s:battery_status() abort if executable('acpi') @@ -156,6 +156,10 @@ function! s:whitespace() abort endif endfunction +function! s:cursorpos() abort + return ' %l:%c ' +endfunction + function! s:modes() abort let m = ' ❖ ' @@ -240,7 +244,10 @@ function! s:active() abort if index(s:loaded_sections, 'battery status') != -1 call add(rsec, s:battery_status()) endif - call add(rsec, '%{" " . &ff . "|" . (&fenc!=""?&fenc:&enc) . " "}') + call add(rsec, '%{" " . &ff . " | " . (&fenc!=""?&fenc:&enc) . " "}') + if index(s:loaded_sections, 'cursorpos') != -1 + call add(rsec, s:cursorpos()) + endif call add(rsec, ' %P ') if index(s:loaded_sections, 'time') != -1 call add(rsec, s:time()) @@ -343,6 +350,8 @@ function! SpaceVim#layers#core#statusline#config() abort \ 'toggle the battery status', 1) call SpaceVim#mapping#space#def('nnoremap', ['t', 'm', 't'], 'call SpaceVim#layers#core#statusline#toggle_section("time")', \ 'toggle the time', 1) + call SpaceVim#mapping#space#def('nnoremap', ['t', 'm', 'p'], 'call SpaceVim#layers#core#statusline#toggle_section("cursorpos")', + \ 'toggle the cursor position', 1) call SpaceVim#mapping#space#def('nnoremap', ['t', 'm', 'T'], 'if &laststatus == 2 | let &laststatus = 0 | else | let &laststatus = 2 | endif', \ 'toggle the statuline itself', 1) function! TagbarStatusline(...) abort diff --git a/docs/documentation.md b/docs/documentation.md index e6079bf4e..a52b2ee71 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -397,7 +397,7 @@ Key Binding | Description `SPC t m m` | toggle the minor mode lighters `SPC t m M` | toggle the major mode `SPC t m n` | toggle the cat! (if colors layer is declared in your dotfile) -`SPC t m p` | toggle the point character position +`SPC t m p` | toggle the cursor position `SPC t m t` | toggle the time `SPC t m T` | toggle the mode line itself `SPC t m v` | toggle the version control info From 913e9ad1527e17eec87f32d1d256fd0bedafa273 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 1 Jul 2017 20:45:24 +0800 Subject: [PATCH 14/63] Disable vim-luacomplete when if_lua is false close #682 --- autoload/SpaceVim/layers/lang/lua.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/lang/lua.vim b/autoload/SpaceVim/layers/lang/lua.vim index 244baba36..0f38efdb5 100644 --- a/autoload/SpaceVim/layers/lang/lua.vim +++ b/autoload/SpaceVim/layers/lang/lua.vim @@ -6,7 +6,7 @@ function! SpaceVim#layers#lang#lua#plugins() abort " Improved Lua 5.3 syntax and indentation support for Vim call add(plugins, ['tbastos/vim-lua', {'on_ft' : 'lua'}]) call add(plugins, ['WolfgangMehner/lua-support', {'on_ft' : 'lua'}]) - call add(plugins, ['SpaceVim/vim-luacomplete', {'on_ft' : 'lua'}]) + call add(plugins, ['SpaceVim/vim-luacomplete', {'on_ft' : 'lua', 'if' : has('lua')}]) return plugins endfunction From 498cbe0fa0c56282a377cf34f01072c8b5cc9c7b Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 2 Jul 2017 16:00:06 +0800 Subject: [PATCH 15/63] Add background searching feature --- autoload/SpaceVim/layers/core/statusline.vim | 1 + autoload/SpaceVim/mapping/space.vim | 5 +++ autoload/SpaceVim/plugins/searcher.vim | 47 ++++++++++++++++++++ init.vim | 1 + 4 files changed, 54 insertions(+) create mode 100644 autoload/SpaceVim/plugins/searcher.vim diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim index 1f055dc07..323fa7307 100644 --- a/autoload/SpaceVim/layers/core/statusline.vim +++ b/autoload/SpaceVim/layers/core/statusline.vim @@ -241,6 +241,7 @@ function! s:active() abort if index(s:loaded_sections, 'version control info') != -1 call add(lsec, s:git_branch()) endif + call add(lsec, SpaceVim#plugins#searcher#count()) if index(s:loaded_sections, 'battery status') != -1 call add(rsec, s:battery_status()) endif diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index c4ab43beb..c4ba65b28 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -105,6 +105,11 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nnoremap', ['s', 'p'], 'Unite grep:.', 'grep in project', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 'P'], "execute 'Unite grep:.::' . expand(\"\") . ' -start-insert'", \ 'grep in project', 1) + " Searching background + call SpaceVim#mapping#space#def('nnoremap', ['s', 'j'], 'call SpaceVim#plugins#searcher#find()', 'Background search keywords in project', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""))', + \ 'Background search cursor words in project', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'l'], 'call SpaceVim#plugins#searcher#list()', 'List all searching results', 1) " Searching tools " ag diff --git a/autoload/SpaceVim/plugins/searcher.vim b/autoload/SpaceVim/plugins/searcher.vim new file mode 100644 index 000000000..7c239986a --- /dev/null +++ b/autoload/SpaceVim/plugins/searcher.vim @@ -0,0 +1,47 @@ +let s:rst = [] +function! SpaceVim#plugins#searcher#find(...) + if a:0 == 0 + let expr = input('search expr: ') + else + let expr = a:1 + endif + call jobstart(['ag', expr], { + \ 'on_stdout' : function('s:search_stdout'), + \ 'on_exit' : function('s:search_exit'), + \ }) +endfunction +function! s:search_stdout(id, data, event) abort + for data in a:data + let info = split(data, '\:\d\+\:') + if len(info) == 2 + let [fname, text] = info + let lnum = matchstr(data, '\:\d\+\:')[1:-2] + call add(s:rst, { + \ 'filename' : fnamemodify(fname, ':p'), + \ 'lnum' : lnum, + \ 'text' : text, + \ }) + endif + endfor +endfunction + +function! s:search_exit(id, data, event) abort + let &l:statusline = SpaceVim#layers#core#statusline#get(1) +endfunction + + +function! SpaceVim#plugins#searcher#list() + call setqflist(s:rst) + let s:rst = [] + copen +endfunction + +function! SpaceVim#plugins#searcher#count() + if empty(s:rst) + return '' + else + return ' ' . len(s:rst) . ' items ' + endif +endfunction + + diff --git a/init.vim b/init.vim index de677ab68..4e371e1fb 100644 --- a/init.vim +++ b/init.vim @@ -1 +1,2 @@ execute 'source' fnamemodify(expand(''), ':h').'/config/main.vim' +" abfgkprt From ba6f36edfcc3370624a36045ebbf1747eac75939 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 2 Jul 2017 21:35:47 +0800 Subject: [PATCH 16/63] Mappings done --- autoload/SpaceVim/mapping/search.vim | 13 +++++++++++++ autoload/SpaceVim/mapping/space.vim | 26 ++++++++++++++++++++++++-- autoload/SpaceVim/plugins/searcher.vim | 16 ++++++++++++---- docs/documentation.md | 21 +++++++++++++++++++++ init.vim | 1 - 5 files changed, 70 insertions(+), 7 deletions(-) diff --git a/autoload/SpaceVim/mapping/search.vim b/autoload/SpaceVim/mapping/search.vim index 3e791adc1..0ac998c3a 100644 --- a/autoload/SpaceVim/mapping/search.vim +++ b/autoload/SpaceVim/mapping/search.vim @@ -50,3 +50,16 @@ function! SpaceVim#mapping#search#grep(key, scope) let g:unite_source_grep_default_opts = save_opt let g:unite_source_grep_recursive_opt = save_ropt endfunction + +function! SpaceVim#mapping#search#default_tool() + if has_key(s:search_tools, 'default_exe') + return s:search_tools.default_exe + else + for t in g:spacevim_search_tools + if executable(t) + let s:search_tools.default_exe = t + return t + endif + endfor + endif +endfunction diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index c4ba65b28..823c1e1c0 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -106,8 +106,10 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nnoremap', ['s', 'P'], "execute 'Unite grep:.::' . expand(\"\") . ' -start-insert'", \ 'grep in project', 1) " Searching background - call SpaceVim#mapping#space#def('nnoremap', ['s', 'j'], 'call SpaceVim#plugins#searcher#find()', 'Background search keywords in project', 1) - call SpaceVim#mapping#space#def('nnoremap', ['s', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""))', + call SpaceVim#mapping#space#def('nnoremap', ['s', 'j'], + \ 'call SpaceVim#plugins#searcher#find("", SpaceVim#mapping#search#default_tool())', 'Background search keywords in project', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'J'], + \ 'call SpaceVim#plugins#searcher#find(expand(""),SpaceVim#mapping#search#default_tool())', \ 'Background search cursor words in project', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 'l'], 'call SpaceVim#plugins#searcher#list()', 'List all searching results', 1) @@ -124,6 +126,10 @@ function! SpaceVim#mapping#space#init() abort \ 'search in arbitrary directory with ag', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 'a', 'F'], 'call SpaceVim#mapping#search#grep("a", "F")', \ 'search cursor word in arbitrary directory with ag', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'a', 'j'], 'call SpaceVim#plugins#searcher#find("", "ag")', + \ 'Background search cursor words in project with ag', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'a', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""), "ag")', + \ 'Background search cursor words in project with ag', 1) " grep let g:_spacevim_mappings_space.s.g = {'name' : '+grep'} call SpaceVim#mapping#space#def('nnoremap', ['s', 'g', 'b'], 'call SpaceVim#mapping#search#grep("g", "b")', @@ -137,6 +143,10 @@ function! SpaceVim#mapping#space#init() abort \ 'search in arbitrary directory with grep', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 'g', 'F'], 'call SpaceVim#mapping#search#grep("g", "F")', \ 'search cursor word in arbitrary directory with grep', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'g', 'j'], 'call SpaceVim#plugins#searcher#find("", "grep")', + \ 'Background search cursor words in project with grep', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'g', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""), "grep")', + \ 'Background search cursor words in project with grep', 1) " ack let g:_spacevim_mappings_space.s.k = {'name' : '+ack'} call SpaceVim#mapping#space#def('nnoremap', ['s', 'k', 'b'], 'call SpaceVim#mapping#search#grep("k", "b")', 'search in all buffers with ack', 1) @@ -149,6 +159,10 @@ function! SpaceVim#mapping#space#init() abort \ 'search in arbitrary directory with ack', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 'k', 'F'], 'call SpaceVim#mapping#search#grep("k", "F")', \ 'search cursor word in arbitrary directory with ack', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'k', 'j'], 'call SpaceVim#plugins#searcher#find("", "ack")', + \ 'Background search cursor words in project with ack', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'k', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""), "ack")', + \ 'Background search cursor words in project with ack', 1) " rg let g:_spacevim_mappings_space.s.r = {'name' : '+rg'} call SpaceVim#mapping#space#def('nnoremap', ['s', 'r', 'b'], 'call SpaceVim#mapping#search#grep("r", "b")', 'search in all buffers with rt', 1) @@ -161,6 +175,10 @@ function! SpaceVim#mapping#space#init() abort \ 'search in arbitrary directory with rt', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 'r', 'F'], 'call SpaceVim#mapping#search#grep("r", "F")', \ 'search cursor word in arbitrary directory with rt', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'r', 'j'], 'call SpaceVim#plugins#searcher#find("", "rg")', + \ 'Background search cursor words in project with rg', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'r', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""), "rg")', + \ 'Background search cursor words in project with rg', 1) " pt let g:_spacevim_mappings_space.s.t = {'name' : '+pt'} call SpaceVim#mapping#space#def('nnoremap', ['s', 't', 'b'], 'call SpaceVim#mapping#search#grep("t", "b")', 'search in all buffers with pt', 1) @@ -173,6 +191,10 @@ function! SpaceVim#mapping#space#init() abort \ 'search in arbitrary directory with pt', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 't', 'F'], 'call SpaceVim#mapping#search#grep("t", "F")', \ 'search cursor word in arbitrary directory with pt', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 't', 'j'], 'call SpaceVim#plugins#searcher#find("", "pt")', + \ 'Background search cursor words in project with pt', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 't', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""), "pt")', + \ 'Background search cursor words in project with pt', 1) call SpaceVim#mapping#space#def('nnoremap', ['s', 'c'], 'noh', \ 'clear search highlight', 1) diff --git a/autoload/SpaceVim/plugins/searcher.vim b/autoload/SpaceVim/plugins/searcher.vim index 7c239986a..f6e4d44b3 100644 --- a/autoload/SpaceVim/plugins/searcher.vim +++ b/autoload/SpaceVim/plugins/searcher.vim @@ -1,11 +1,11 @@ let s:rst = [] -function! SpaceVim#plugins#searcher#find(...) - if a:0 == 0 +function! SpaceVim#plugins#searcher#find(expr, exe) + if empty(a:expr) let expr = input('search expr: ') else - let expr = a:1 + let expr = a:expr endif - call jobstart(['ag', expr], { + call jobstart(s:get_search_cmd(a:exe, expr), { \ 'on_stdout' : function('s:search_stdout'), \ 'on_exit' : function('s:search_exit'), \ }) @@ -25,6 +25,14 @@ function! s:search_stdout(id, data, event) abort endfor endfunction +function! s:get_search_cmd(exe, expr) abort + if a:exe == 'grep' + return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.'] + else + return [a:exe, a:expr] + endif +endfunction + function! s:search_exit(id, data, event) abort let &l:statusline = SpaceVim#layers#core#statusline#get(1) endfunction diff --git a/docs/documentation.md b/docs/documentation.md index a52b2ee71..a3d0ffc19 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -74,6 +74,7 @@ title: "Documentation" * [Searching in all loaded buffers](#searching-in-all-loaded-buffers) * [Searching in an arbitrary directory](#searching-in-an-arbitrary-directory) * [Searching in a project](#searching-in-a-project) + * [Background searching in a project](#background-searching-in-a-project) * [Searching the web](#searching-the-web) * [Persistent highlighting](#persistent-highlighting) * [Editing](#editing) @@ -1093,6 +1094,26 @@ Key Binding | Description **Hint**: It is also possible to search in a project without needing to open a file beforehand. To do so use `SPC p p` and then `C-s` on a given project to directly search into it like with `SPC s p`. (TODO) +##### Background searching in a project + +Background search keyword in a project, when searching done, the count will be shown on the statusline. + +Key Binding | Description +----------- | ----------- +`SPC s j` | searching input expr background with the first found tool +`SPC s J` | searching cursor word background with the first found tool +`SPC s l` | List all searching result in quickfix buffer +`SPC s a j` | ag +`SPC s a J` | ag with default text +`SPC s g j` | grep +`SPC s g J` | grep with default text +`SPC s k j` | ack +`SPC s k J` | ack with default text +`SPC s t j` | pt +`SPC s t J` | pt with default text +`SPC s r j` | rg +`SPC s r J` | rg with default text + ##### Searching the web Key Binding Description diff --git a/init.vim b/init.vim index 4e371e1fb..de677ab68 100644 --- a/init.vim +++ b/init.vim @@ -1,2 +1 @@ execute 'source' fnamemodify(expand(''), ':h').'/config/main.vim' -" abfgkprt From b30a3bb7d6af71b66e89a8a2ca9e085411444b77 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 2 Jul 2017 21:45:17 +0800 Subject: [PATCH 17/63] Fix rg support --- autoload/SpaceVim/plugins/searcher.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autoload/SpaceVim/plugins/searcher.vim b/autoload/SpaceVim/plugins/searcher.vim index f6e4d44b3..90f6ed65b 100644 --- a/autoload/SpaceVim/plugins/searcher.vim +++ b/autoload/SpaceVim/plugins/searcher.vim @@ -28,6 +28,8 @@ endfunction function! s:get_search_cmd(exe, expr) abort if a:exe == 'grep' return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.'] + elseif a:exe == 'rg' + return ['rg', '-n', a:expr] else return [a:exe, a:expr] endif From 077800352549fd5cb9275742391a2a9c63c332fa Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 2 Jul 2017 22:17:25 +0800 Subject: [PATCH 18/63] Fix document for grep searching --- docs/documentation.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/documentation.md b/docs/documentation.md index a3d0ffc19..528fb93fc 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1084,6 +1084,7 @@ Key Binding | Description `SPC *` or `SPC s P` | search with the first found tool with default input `SPC s a p` | ag `SPC s a P` | ag with default text +`SPC s g p` | grep `SPC s g p` | grep with default text `SPC s k p` | ack `SPC s k P` | ack with default text From c94e6613b3df5f31dfac0cfce13842f478347d8c Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sun, 2 Jul 2017 11:17:05 -0500 Subject: [PATCH 19/63] Vim8 (#701) * Fix vim8 support * Fix vim8 job support --- autoload/SpaceVim/api/job.vim | 2 ++ autoload/SpaceVim/plugins/searcher.vim | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/api/job.vim b/autoload/SpaceVim/api/job.vim index 5db27f407..1f0a859b8 100644 --- a/autoload/SpaceVim/api/job.vim +++ b/autoload/SpaceVim/api/job.vim @@ -21,6 +21,7 @@ function! s:self.warp(argv, opts) abort let obj = {} let obj._argv = a:argv let obj._opts = a:opts + let obj.in_io = get(a:opts, 'in_io', 'pipe') " @vimlint(EVL103, 1, a:job_id) function! obj._out_cb(job_id, data) abort if has_key(self._opts, 'on_stdout') @@ -45,6 +46,7 @@ function! s:self.warp(argv, opts) abort \ 'argv': a:argv, \ 'opts': { \ 'mode': 'nl', + \ 'in_io' : obj.in_io, \ 'out_cb': obj._out_cb, \ 'err_cb': obj._err_cb, \ 'exit_cb': obj._exit_cb, diff --git a/autoload/SpaceVim/plugins/searcher.vim b/autoload/SpaceVim/plugins/searcher.vim index 90f6ed65b..e4f327753 100644 --- a/autoload/SpaceVim/plugins/searcher.vim +++ b/autoload/SpaceVim/plugins/searcher.vim @@ -1,12 +1,16 @@ +let s:JOB = SpaceVim#api#import('job') + let s:rst = [] + function! SpaceVim#plugins#searcher#find(expr, exe) if empty(a:expr) let expr = input('search expr: ') else let expr = a:expr endif - call jobstart(s:get_search_cmd(a:exe, expr), { + call s:JOB.start(s:get_search_cmd(a:exe, expr), { \ 'on_stdout' : function('s:search_stdout'), + \ 'in_io' : 'null', \ 'on_exit' : function('s:search_exit'), \ }) endfunction From 93d2b8131fa41e0eab1598216ad77e56e1296f7e Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 3 Jul 2017 19:56:35 +0800 Subject: [PATCH 20/63] Show update percentage when updating plugins close #698 --- autoload/SpaceVim/plugins/manager.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/plugins/manager.vim b/autoload/SpaceVim/plugins/manager.vim index 825641689..fb0fec9bb 100644 --- a/autoload/SpaceVim/plugins/manager.vim +++ b/autoload/SpaceVim/plugins/manager.vim @@ -356,9 +356,10 @@ endfunction function! s:pull(repo) abort let s:pct += 1 let s:ui_buf[a:repo.name] = s:pct - let argv = ['git', '-C', a:repo.path, 'pull'] + let argv = ['git', '-C', a:repo.path, 'pull', '--progress'] if s:JOB.vim_job || s:JOB.nvim_job let jobid = s:JOB.start(argv,{ + \ 'on_stderr' : function('s:on_install_stdout'), \ 'on_exit' : function('s:on_pull_exit') \ }) if jobid != 0 From 93039d0edf84cf1f12597d528de06b70e4ee64bb Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 3 Jul 2017 21:15:45 +0800 Subject: [PATCH 21/63] Update install script for spacevim --- docs/install.sh | 50 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/docs/install.sh b/docs/install.sh index 234977620..12f9ca563 100755 --- a/docs/install.sh +++ b/docs/install.sh @@ -1,30 +1,58 @@ #!/usr/bin/env bash -# -# A guarding function to avoid executing an incompletely downloaded script -guard () { +#============================================================================= +# install.sh --- bootstrap script for SpaceVim +# Copyright (c) 2016-2017 Shidong Wang & Contributors +# Author: Shidong Wang < wsdjeg at 163.com > +# URL: https://spacevim.org +# License: MIT license +#============================================================================= + # Reset Color_off='\033[0m' # Text Reset # Regular Colors -Red='\033[0;31m' # Red -Blue='\033[0;34m' # Blue +Red='\033[0;31m' +Blue='\033[0;34m' +Green='\033[0;32m' need_cmd () { if ! hash "$1" &>/dev/null; then - echo -e "${Red}need '$1' (command not found)${Color_off}" + error "Need '$1' (command not fount)" exit 1 fi } +msg() { + printf '%b\n' "$1" >&2 +} + +success() { + if [ "$ret" -eq '0' ]; + then + msg "${Green}[✔]${Color_off} ${1}${2}" + fi +} + +info() { + msg "${Blue}==>${Color_off} ${1}${2}" +} + +error() { + msg "${Red}[✘]${Color_off} ${1}${2}" + exit 1 +} + fetch_repo () { if [[ -d "$HOME/.SpaceVim" ]]; then + info "Trying to update SpaceVim" git --git-dir "$HOME/.SpaceVim/.git" pull - echo -e "${Blue}Successfully update SpaceVim${Color_off}" + success "Successfully update SpaceVim" else + info "Trying to clone SpaceVim" git clone https://github.com/SpaceVim/SpaceVim.git "$HOME/.SpaceVim" - echo -e "${Blue}Successfully clone SpaceVim${Color_off}" + success "Successfully clone SpaceVim" fi } @@ -145,9 +173,3 @@ need_cmd 'git' fetch_repo install_vim install_neovim - -# end of guard -} - -# download finished fine -guard $@ From a02bc3e628452d5c4d53c0e818d20deab1efe02f Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 3 Jul 2017 21:16:57 +0800 Subject: [PATCH 22/63] Fix type --- docs/install.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/install.sh b/docs/install.sh index 12f9ca563..d87488a1b 100755 --- a/docs/install.sh +++ b/docs/install.sh @@ -29,10 +29,7 @@ msg() { } success() { - if [ "$ret" -eq '0' ]; - then - msg "${Green}[✔]${Color_off} ${1}${2}" - fi + msg "${Green}[✔]${Color_off} ${1}${2}" } info() { From 47ef38ea7f14dc235380deaeeb2b41593aa5f61a Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 3 Jul 2017 22:08:04 +0800 Subject: [PATCH 23/63] Add version information --- docs/install.sh | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/docs/install.sh b/docs/install.sh index d87488a1b..522518a54 100755 --- a/docs/install.sh +++ b/docs/install.sh @@ -11,6 +11,7 @@ # Reset Color_off='\033[0m' # Text Reset +Version='0.4.0-dev' # Regular Colors Red='\033[0;31m' @@ -121,27 +122,44 @@ uninstall_neovim () { } usage () { - echo "SpaceVim install script : V 0.1.0-dev" + echo "SpaceVim install script : V ${Version}" + echo "" + echo "Usage : curl -sLf https://spacevim.org/install.sh [option] [target]" + echo "" + echo " This is bootstrap script for SpaceVim." + echo "" + echo "OPTIONS" + echo "" + echo " -i, --install install spacevim for vim or neovim" + echo " -v, --version Show version information and exit" + echo " -u, --uninstall Uninstall SpaceVim" + echo "" + echo "EXAMPLE" + echo "" echo " Install SpaceVim for vim and neovim" + echo "" echo " curl -sLf https://spacevim.org/install.sh | bash" + echo "" echo " Install SpaceVim for vim only or neovim only" - echo " curl -sLf https://spacevim.org/install.sh | bash -s -- install vim" - echo " or" - echo " curl -sLf https://spacevim.org/install.sh | bash -s -- install neovim" + echo "" + echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --install vim" + echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --install neovim" + echo "" echo " Uninstall SpaceVim" - echo " curl -sLf https://spacevim.org/install.sh | bash -s -- uninstall" + echo "" + echo " curl -sLf https://spacevim.org/install.sh | bash -s -- --uninstall" } if [ $# -gt 0 ] then case $1 in - uninstall) + --uninstall) uninstall_vim uninstall_neovim exit 0 ;; - install) + --install) need_cmd 'git' fetch_repo if [ $# -eq 2 ] @@ -163,6 +181,18 @@ then -h) usage exit 0 + ;; + --help) + usage + exit 0 + ;; + -v) + msg "${Version}" + exit 0 + ;; + --version) + msg "${Version}" + exit 0 esac fi # if no argv, installer will install SpaceVim From 58b6d6f51e613a503ff5777a7756c21ea1b33584 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 3 Jul 2017 22:12:06 +0800 Subject: [PATCH 24/63] Fix usage in script help --- docs/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/install.sh b/docs/install.sh index 522518a54..26648bc58 100755 --- a/docs/install.sh +++ b/docs/install.sh @@ -124,7 +124,7 @@ uninstall_neovim () { usage () { echo "SpaceVim install script : V ${Version}" echo "" - echo "Usage : curl -sLf https://spacevim.org/install.sh [option] [target]" + echo "Usage : curl -sLf https://spacevim.org/install.sh | bash -s -- [option] [target]" echo "" echo " This is bootstrap script for SpaceVim." echo "" From 317bf128a388e09886db4a606189c428105214c9 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 3 Jul 2017 23:53:55 +0800 Subject: [PATCH 25/63] Add uninstall info --- docs/install.sh | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/install.sh b/docs/install.sh index 26648bc58..6daaf503d 100755 --- a/docs/install.sh +++ b/docs/install.sh @@ -57,37 +57,37 @@ fetch_repo () { install_vim () { if [[ -f "$HOME/.vimrc" ]]; then mv "$HOME/.vimrc" "$HOME/.vimrc_back" - echo -e "${Blue}BackUp $HOME/.vimrc${Color_off}" + success "Backup $HOME/.vimrc to $HOME/.vimrc_back" fi if [[ -d "$HOME/.vim" ]]; then if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then - echo -e "${Blue}Installed SpaceVim for vim${Color_off}" + success "Installed SpaceVim for vim" else mv "$HOME/.vim" "$HOME/.vim_back" - echo -e "${Blue}BackUp $HOME/.vim${Color_off}" + success "BackUp $HOME/.vim to $HOME/.vim_back" ln -s "$HOME/.SpaceVim" "$HOME/.vim" - echo -e "${Blue}Installed SpaceVim for vim${Color_off}" + success "Installed SpaceVim for vim" fi else ln -s "$HOME/.SpaceVim" "$HOME/.vim" - echo -e "${Blue}Installed SpaceVim for vim${Color_off}" + success "Installed SpaceVim for vim" fi } install_neovim () { if [[ -d "$HOME/.config/nvim" ]]; then if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then - echo -e "${Blue}Installed SpaceVim for neovim${Color_off}" + success "Installed SpaceVim for neovim" else mv "$HOME/.config/nvim" "$HOME/.config/nvim_back" - echo -e "${Blue}BackUp $HOME/.config/nvim${Color_off}" + success "BackUp $HOME/.config/nvim to $HOME/.config/nvim_back" ln -s "$HOME/.SpaceVim" "$HOME/.config/nvim" - echo -e "${Blue}Installed SpaceVim for neovim${Color_off}" + success "Installed SpaceVim for neovim" fi else ln -s "$HOME/.SpaceVim" "$HOME/.config/nvim" - echo -e "${Blue}Installed SpaceVim for neovim${Color_off}" + success "Installed SpaceVim for neovim" fi } @@ -95,16 +95,16 @@ uninstall_vim () { if [[ -d "$HOME/.vim" ]]; then if [[ "$(readlink $HOME/.vim)" =~ \.SpaceVim$ ]]; then rm "$HOME/.vim" - echo -e "${Blue}Uninstall SpaceVim for vim${Color_off}" + success "Uninstall SpaceVim for vim" if [[ -d "$HOME/.vim_back" ]]; then mv "$HOME/.vim_back" "$HOME/.vim" - echo -e "${Blue}Recover $HOME/.vim${Color_off}" + success "Recover from $HOME/.vim_back" fi fi fi if [[ -f "$HOME/.vimrc_back" ]]; then mv "$HOME/.vimrc_back" "$HOME/.vimrc" - echo -e "${Blue}Recover $HOME/.vimrc${Color_off}" + success "Recover from $HOME/.vimrc_back" fi } @@ -112,10 +112,10 @@ uninstall_neovim () { if [[ -d "$HOME/.config/nvim" ]]; then if [[ "$(readlink $HOME/.config/nvim)" =~ \.SpaceVim$ ]]; then rm "$HOME/.config/nvim" - echo -e "${Blue}Uninstall SpaceVim for neovim${Color_off}" + success "Uninstall SpaceVim for neovim" if [[ -d "$HOME/.config/nvim_back" ]]; then mv "$HOME/.config/nvim_back" "$HOME/.config/nvim" - echo -e "${Blue}Recover $HOME/.config/nvim${Color_off}" + success "Recover from $HOME/.config/nvim_back" fi fi fi @@ -155,6 +155,7 @@ if [ $# -gt 0 ] then case $1 in --uninstall) + info "Trying to uninstall SpaceVim" uninstall_vim uninstall_neovim exit 0 From 6845ac5f748d9a6563cc4188689c2502d5e269b8 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 4 Jul 2017 00:04:59 +0800 Subject: [PATCH 26/63] Fix install script bug with -u option --- docs/install.sh | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/docs/install.sh b/docs/install.sh index 6daaf503d..6deb24874 100755 --- a/docs/install.sh +++ b/docs/install.sh @@ -154,13 +154,13 @@ usage () { if [ $# -gt 0 ] then case $1 in - --uninstall) + --uninstall|-u) info "Trying to uninstall SpaceVim" uninstall_vim uninstall_neovim exit 0 ;; - --install) + --install|-i) need_cmd 'git' fetch_repo if [ $# -eq 2 ] @@ -179,19 +179,11 @@ then install_neovim exit 0 ;; - -h) + --help|-h) usage exit 0 ;; - --help) - usage - exit 0 - ;; - -v) - msg "${Version}" - exit 0 - ;; - --version) + --version|-v) msg "${Version}" exit 0 esac From d6f184f2dad65e11b7a29b7c634f6068685a2ea9 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Thu, 6 Jul 2017 21:59:09 +0800 Subject: [PATCH 27/63] Grep on the fly (#705) * Grep on the fly * Fix screen update * Fix commands for prompt * Supprt in prompt * Redrew on stdout * Fix prompt api * Improve flygrep screen update * Add function keys for flygrep buffer * Add statusline support && ignore case * Add highlight feature * Fix highlight error * Ignore FocusLost and FocusGained * Add prompt mappings * Add documentation for fly searching * Update documentation * Fix lint for flygrep --- autoload/SpaceVim/api/prompt.vim | 132 ++++++++++++++++++ autoload/SpaceVim/layers/core/statusline.vim | 4 + autoload/SpaceVim/mapping/space.vim | 3 + autoload/SpaceVim/plugins/flygrep.vim | 133 +++++++++++++++++++ autoload/SpaceVim/plugins/searcher.vim | 16 ++- docs/documentation.md | 25 +++- syntax/SpaceVimFlyGrep.vim | 8 ++ 7 files changed, 315 insertions(+), 6 deletions(-) create mode 100644 autoload/SpaceVim/api/prompt.vim create mode 100644 autoload/SpaceVim/plugins/flygrep.vim create mode 100644 syntax/SpaceVimFlyGrep.vim diff --git a/autoload/SpaceVim/api/prompt.vim b/autoload/SpaceVim/api/prompt.vim new file mode 100644 index 000000000..f7583b23c --- /dev/null +++ b/autoload/SpaceVim/api/prompt.vim @@ -0,0 +1,132 @@ +let s:self = {} + + +let s:self._keys = { + \ 'close' : "\", + \ 'cursor_back' : '', + \ 'cursor_forword' : '', + \ } +let s:self._prompt = { + \ 'mpt' : '==>', + \ 'begin' : '', + \ 'cursor' : '', + \ 'end' : '', + \ } +let s:self._function_key = {} + +let s:self._quit = 1 + +let s:self._handle_fly = '' +let s:self._onclose = '' +let s:self._oninputpro = '' + + + +func! s:self.open() abort + let self._quit = 0 + let save_redraw = &lazyredraw + set nolazyredraw + call self._build_prompt() + call self._handle_input() + let &lazyredraw = save_redraw +endf + +function! s:self._getchar(...) abort + let ret = call('getchar', a:000) + return (type(ret) == type(0) ? nr2char(ret) : ret) +endfunction + +func! s:self._handle_input() abort + while self._quit == 0 + let char = self._getchar() + if has_key(self._function_key, char) + call call(self._function_key[char], []) + continue + endif + if char ==# "\" || char ==# "\" + continue + endif + if char ==# "\" || char == 6 + let self._prompt.begin = self._prompt.begin . self._prompt.cursor + let self._prompt.cursor = matchstr(self._prompt.end, '^.') + let self._prompt.end = substitute(self._prompt.end, '^.', '', 'g') + call self._build_prompt() + continue + elseif char ==# "\" || char == 2 + if self._prompt.begin !=# '' + let self._prompt.end = self._prompt.cursor . self._prompt.end + let self._prompt.cursor = matchstr(self._prompt.begin, '.$') + let self._prompt.begin = substitute(self._prompt.begin, '.$', '', 'g') + call self._build_prompt() + endif + continue + elseif char ==# "\" + let self._prompt.begin = substitute(self._prompt.begin,'[^\ .*]\+\s*$','','g') + call self._build_prompt() + elseif char ==# "\" || char ==# "\" + let self._prompt.end = substitute(self._prompt.begin . self._prompt.cursor . self._prompt.end, '^.', '', 'g') + let self._prompt.cursor = matchstr(self._prompt.begin, '^.') + let self._prompt.begin = '' + call self._build_prompt() + continue + elseif char ==# "\" || char ==# "\" + let self._prompt.begin = self._prompt.begin . self._prompt.cursor . self._prompt.end + let self._prompt.cursor = '' + let self._prompt.end = '' + call self._build_prompt() + continue + elseif char ==# "\" + let self._prompt.begin = '' + call self._build_prompt() + elseif char ==# "\" + let self._prompt.cursor = '' + let self._prompt.end = '' + call self._build_prompt() + elseif char ==# "\" + let self._prompt.begin = substitute(self._prompt.begin,'.$','','g') + call self._build_prompt() + elseif char == self._keys.close + call self.close() + break + else + let self._prompt.begin .= char + call self._build_prompt() + endif + if self._oninputpro !=# '' + call call(self._oninputpro, []) + endif + if self._handle_fly !=# '' + call call(self._handle_fly, [self._prompt.begin . self._prompt.cursor . self._prompt.end]) + endif + endwhile +endf + +func! s:self._build_prompt() abort + redraw + echohl Comment | echon self._prompt.mpt + echohl None | echon self._prompt.begin + echohl Wildmenu | echon self._prompt.cursor + echohl None | echon self._prompt.end +endf + +function! s:self._clear_prompt() abort + let self._prompt = { + \ 'mpt' : self._prompt.mpt, + \ 'begin' : '', + \ 'cursor' : '', + \ 'end' : '', + \ } +endfunction + +function! s:self.close() abort + if self._onclose !=# '' + call call(self._onclose, []) + endif + call self._clear_prompt() + normal! : + let self._quit = 1 +endfunction + +function! SpaceVim#api#prompt#get() abort + return deepcopy(s:self) +endfunction diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim index 323fa7307..63b6a3d99 100644 --- a/autoload/SpaceVim/layers/core/statusline.vim +++ b/autoload/SpaceVim/layers/core/statusline.vim @@ -214,6 +214,10 @@ function! SpaceVim#layers#core#statusline#get(...) abort \ . '%#SpaceVim_statusline_a_bold_SpaceVim_statusline_b# %{get(unite#get_context(), "buffer_name", "")} ' \ . '%#SpaceVim_statusline_b_SpaceVim_statusline_c# ' \ . '%#SpaceVim_statusline_c# %{unite#get_status_string()} ' + elseif &filetype ==# 'SpaceVimFlyGrep' + return '%#SpaceVim_statusline_a# FlyGrep %#SpaceVim_statusline_a_SpaceVim_statusline_b#' + \ . '%#SpaceVim_statusline_b# %{getcwd()}%#SpaceVim_statusline_b_SpaceVim_statusline_c#' + \ . '%#SpaceVim_statusline_c# %{SpaceVim#plugins#flygrep#lineNr()}' endif if a:0 > 0 return s:active() diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 823c1e1c0..62c5d0a27 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -196,6 +196,9 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nnoremap', ['s', 't', 'J'], 'call SpaceVim#plugins#searcher#find(expand(""), "pt")', \ 'Background search cursor words in project with pt', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'g', 'G'], 'call SpaceVim#plugins#flygrep#open()', + \ 'grep on the fly', 1) + call SpaceVim#mapping#space#def('nnoremap', ['s', 'c'], 'noh', \ 'clear search highlight', 1) endfunction diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim new file mode 100644 index 000000000..1ecd7fc18 --- /dev/null +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -0,0 +1,133 @@ +let s:MPT = SpaceVim#api#import('prompt') +let s:JOB = SpaceVim#api#import('job') +let s:grepid = 0 + + +function! SpaceVim#plugins#flygrep#open() abort + rightbelow split __flygrep__ + setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber + " setlocal nomodifiable + setf SpaceVimFlyGrep + redraw! + call s:MPT.open() +endfunction + +function! s:flygrep(expr) abort + call s:MPT._build_prompt() + if a:expr ==# '' + redrawstatus + return + endif + try + syn clear FileNames + catch + endtr + exe 'syn match FileNames /' . substitute(a:expr, '\([/\\]\)', '\\\1', 'g') . '/' + hi def link FileNames MoreMsg + let exe = SpaceVim#mapping#search#default_tool() + let s:grepid = s:JOB.start(s:get_search_cmd(exe, a:expr), { + \ 'on_stdout' : function('s:grep_stdout'), + \ 'in_io' : 'null', + \ 'on_exit' : function('s:grep_exit'), + \ }) +endfunction + +let s:MPT._handle_fly = function('s:flygrep') + +function! s:close_buffer() abort + q +endfunction + +let s:MPT._onclose = function('s:close_buffer') + + +function! s:close_grep_job() abort + if s:grepid != 0 + call s:JOB.stop(s:grepid) + endif + normal! "_ggdG +endfunction + +let s:MPT._oninputpro = function('s:close_grep_job') + +" @vimlint(EVL103, 1, a:data) +" @vimlint(EVL103, 1, a:id) +" @vimlint(EVL103, 1, a:event) +function! s:grep_stdout(id, data, event) abort + let datas =filter(a:data, '!empty(v:val)') + if getline(1) ==# '' + call setline(1, datas) + else + call append('$', datas) + endif + call s:MPT._build_prompt() +endfunction + +function! s:grep_exit(id, data, event) abort + redrawstatus + let s:grepid = 0 +endfunction + +" @vimlint(EVL103, 0, a:data) +" @vimlint(EVL103, 0, a:id) +" @vimlint(EVL103, 0, a:event) + +function! s:get_search_cmd(exe, expr) abort + if a:exe ==# 'grep' + return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.'] + elseif a:exe ==# 'rg' + return ['rg', '-n', '-i', a:expr] + else + return [a:exe, a:expr] + endif +endfunction + +function! s:next_item() abort + if line('.') == line('$') + normal! gg + else + normal! j + endif + redrawstatus + call s:MPT._build_prompt() +endfunction + +function! s:previous_item() abort + if line('.') == 1 + normal! G + else + normal! k + endif + redrawstatus + call s:MPT._build_prompt() +endfunction + +function! s:open_item() abort + if line('.') !=# '' + if s:grepid != 0 + call s:JOB.stop(s:grepid) + endif + call s:MPT._clear_prompt() + let s:MPT._quit = 1 + normal! gF + let nr = bufnr('%') + q + exe 'silent b' . nr + normal! : + endif +endfunction + +let s:MPT._function_key = { + \ "\" : function('s:next_item'), + \ "\" : function('s:previous_item'), + \ "\" : function('s:open_item'), + \ } + +" statusline api +function! SpaceVim#plugins#flygrep#lineNr() abort + if getline(1) ==# '' + return '' + else + return line('.') . '/' . line('$') + endif +endfunction diff --git a/autoload/SpaceVim/plugins/searcher.vim b/autoload/SpaceVim/plugins/searcher.vim index e4f327753..90189b6ac 100644 --- a/autoload/SpaceVim/plugins/searcher.vim +++ b/autoload/SpaceVim/plugins/searcher.vim @@ -2,7 +2,7 @@ let s:JOB = SpaceVim#api#import('job') let s:rst = [] -function! SpaceVim#plugins#searcher#find(expr, exe) +function! SpaceVim#plugins#searcher#find(expr, exe) abort if empty(a:expr) let expr = input('search expr: ') else @@ -14,6 +14,8 @@ function! SpaceVim#plugins#searcher#find(expr, exe) \ 'on_exit' : function('s:search_exit'), \ }) endfunction +" @vimlint(EVL103, 1, a:id) +" @vimlint(EVL103, 1, a:event) function! s:search_stdout(id, data, event) abort for data in a:data let info = split(data, '\:\d\+\:') @@ -30,27 +32,31 @@ function! s:search_stdout(id, data, event) abort endfunction function! s:get_search_cmd(exe, expr) abort - if a:exe == 'grep' + if a:exe ==# 'grep' return ['grep', '-inHR', '--exclude-dir', '.git', a:expr, '.'] - elseif a:exe == 'rg' + elseif a:exe ==# 'rg' return ['rg', '-n', a:expr] else return [a:exe, a:expr] endif endfunction +" @vimlint(EVL103, 1, a:data) function! s:search_exit(id, data, event) abort let &l:statusline = SpaceVim#layers#core#statusline#get(1) endfunction +" @vimlint(EVL103, 0, a:data) +" @vimlint(EVL103, 0, a:id) +" @vimlint(EVL103, 0, a:event) -function! SpaceVim#plugins#searcher#list() +function! SpaceVim#plugins#searcher#list() abort call setqflist(s:rst) let s:rst = [] copen endfunction -function! SpaceVim#plugins#searcher#count() +function! SpaceVim#plugins#searcher#count() abort if empty(s:rst) return '' else diff --git a/docs/documentation.md b/docs/documentation.md index 7bcf8266e..700709256 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -76,6 +76,7 @@ title: "Documentation" * [Searching in a project](#searching-in-a-project) * [Background searching in a project](#background-searching-in-a-project) * [Searching the web](#searching-the-web) + * [Searching on the fly](#searching-on-the-fly) * [Persistent highlighting](#persistent-highlighting) * [Editing](#editing) * [Text insertion commands](#text-insertion-commands) @@ -1117,13 +1118,35 @@ Key Binding | Description ##### Searching the web -Key Binding Description +Key Binding | Description -----------| ----------- `SPC s w g` | Get Google suggestions in vim. Opens Google results in Browser. `SPC s w w` | Get Wikipedia suggestions in vim. Opens Wikipedia page in Browser.(TODO) **Note**: to enable google suggestions in vim, you need to add `let g:spacevim_enable_googlesuggest = 1` to your custom Configuration file. +#### Searching on the fly + +Key Binding | Description +-----------| ----------- +`SPC s g G` | Searching in project on the fly with default tools + +key binding in FlyGrep buffer: + +Key Binding Description +-----------| ----------- +`` | close FlyGrep buffer +`` | open file at the cursor line +`` | move cursor line down +`` | move cursor line up +`` | remove last character +`` | remove the Word before the cursor +`` | remove the Line before the cursor +`` | remove the Line after the cursor +``/`` | Go to the beginning of the line +``/`` | Go to the end of the line + + #### Persistent highlighting SpaceVim uses `g:spacevim_search_highlight_persist` to keep the searched expression highlighted until the next search. It is also possible to clear the highlighting by pressing `SPC s c` or executing the ex command `:noh`. diff --git a/syntax/SpaceVimFlyGrep.vim b/syntax/SpaceVimFlyGrep.vim new file mode 100644 index 000000000..bb5782fe3 --- /dev/null +++ b/syntax/SpaceVimFlyGrep.vim @@ -0,0 +1,8 @@ +if exists("b:current_syntax") + finish +endif +let b:current_syntax = "SpaceVimFlyGrep" +syntax case ignore +syn match FileName /[^:]*:\d\+:/ + +hi def link FileName Comment From e983864ad1091d5a5b213da1401257d431b18daf Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 6 Jul 2017 22:23:02 +0800 Subject: [PATCH 28/63] Hide cursor in terminal vim --- autoload/SpaceVim/plugins/flygrep.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index 1ecd7fc18..ba496d4dc 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -6,10 +6,13 @@ let s:grepid = 0 function! SpaceVim#plugins#flygrep#open() abort rightbelow split __flygrep__ setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber + let save_tve = &t_ve + setlocal t_ve= " setlocal nomodifiable setf SpaceVimFlyGrep redraw! call s:MPT.open() + let &t_ve = save_tve endfunction function! s:flygrep(expr) abort From 056d8bce84927d8e1aa1f27768432c5ccee59162 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 6 Jul 2017 23:17:49 +0800 Subject: [PATCH 29/63] Visual mode SPC --- autoload/SpaceVim.vim | 1 + autoload/SpaceVim/mapping/space.vim | 2 ++ 2 files changed, 3 insertions(+) diff --git a/autoload/SpaceVim.vim b/autoload/SpaceVim.vim index 16c26f323..98f2add04 100644 --- a/autoload/SpaceVim.vim +++ b/autoload/SpaceVim.vim @@ -416,6 +416,7 @@ let g:spacevim_leader_guide_submode_mappings = {'': "win_close"} command -nargs=1 LeaderGuide call SpaceVim#mapping#guide#start_by_prefix('0', ) +command -range -nargs=1 LeaderGuideVisual call SpaceVim#mapping#guide#start_by_prefix('1', ) function! SpaceVim#loadCustomConfig() abort let custom_confs_old = SpaceVim#util#globpath(getcwd(), '.local.vim') diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 62c5d0a27..29971d82c 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -3,7 +3,9 @@ function! SpaceVim#mapping#space#init() abort return endif nnoremap [SPC] :LeaderGuide " " + vnoremap [SPC] :LeaderGuideVisual " " nmap [SPC] + vmap [SPC] let g:_spacevim_mappings_space = {} let g:_spacevim_mappings_prefixs['[SPC]'] = {'name' : '+SPC prefix'} let g:_spacevim_mappings_space['?'] = ['Unite menu:CustomKeyMaps -input=[SPC]', 'show mappings'] From 081beb81702186a04d11dcdac2944b7a23159764 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Fri, 7 Jul 2017 00:03:55 +0800 Subject: [PATCH 30/63] Disable welcome page when use stdin (#707) --- autoload/SpaceVim/autocmds.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autoload/SpaceVim/autocmds.vim b/autoload/SpaceVim/autocmds.vim index 674981eda..93fa2c8c4 100644 --- a/autoload/SpaceVim/autocmds.vim +++ b/autoload/SpaceVim/autocmds.vim @@ -65,6 +65,7 @@ function! SpaceVim#autocmds#init() abort " Instead of reverting the cursor to the last position in the buffer, we " set it to the first line when editing a git commit message au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0]) + au StdinReadPost * call s:disable_welcome() autocmd InsertEnter * call s:fixindentline() if executable('synclient') && g:spacevim_auto_disable_touchpad let s:touchpadoff = 0 @@ -138,5 +139,11 @@ function! SpaceVim#autocmds#VimEnter() abort endif endfunction +function! s:disable_welcome() abort + augroup SPwelcome + au! + augroup END +endfunction + " vim:set et sw=2: From 52a4ec3e1a46c83cb3941fc0f97f4b718f41cb8b Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 7 Jul 2017 20:47:26 +0800 Subject: [PATCH 31/63] Searching when input delay 1000ms --- autoload/SpaceVim/plugins/flygrep.vim | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index ba496d4dc..9e9659fac 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -15,6 +15,18 @@ function! SpaceVim#plugins#flygrep#open() abort let &t_ve = save_tve endfunction +let s:grep_expr = '' +let s:grep_exe = SpaceVim#mapping#search#default_tool() +let s:grep_timer_id = 0 + +function! s:grep_timer(timer) abort + let s:grepid = s:JOB.start(s:get_search_cmd(s:grep_exe, s:grep_expr), { + \ 'on_stdout' : function('s:grep_stdout'), + \ 'in_io' : 'null', + \ 'on_exit' : function('s:grep_exit'), + \ }) +endfunction + function! s:flygrep(expr) abort call s:MPT._build_prompt() if a:expr ==# '' @@ -27,12 +39,7 @@ function! s:flygrep(expr) abort endtr exe 'syn match FileNames /' . substitute(a:expr, '\([/\\]\)', '\\\1', 'g') . '/' hi def link FileNames MoreMsg - let exe = SpaceVim#mapping#search#default_tool() - let s:grepid = s:JOB.start(s:get_search_cmd(exe, a:expr), { - \ 'on_stdout' : function('s:grep_stdout'), - \ 'in_io' : 'null', - \ 'on_exit' : function('s:grep_exit'), - \ }) + let s:grep_timer_id = timer_start(1000, funcref('s:grep_timer'), {'repeat' : 1}) endfunction let s:MPT._handle_fly = function('s:flygrep') @@ -48,6 +55,9 @@ function! s:close_grep_job() abort if s:grepid != 0 call s:JOB.stop(s:grepid) endif + if s:grep_timer_id != 0 + call timer_stop(s:grep_timer_id) + endif normal! "_ggdG endfunction From 92b8f6de53362a8c438b9485b4d9dbfdb2979922 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 7 Jul 2017 20:48:44 +0800 Subject: [PATCH 32/63] Change delay to 500ms --- autoload/SpaceVim/plugins/flygrep.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index 9e9659fac..e8225e7d2 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -39,7 +39,7 @@ function! s:flygrep(expr) abort endtr exe 'syn match FileNames /' . substitute(a:expr, '\([/\\]\)', '\\\1', 'g') . '/' hi def link FileNames MoreMsg - let s:grep_timer_id = timer_start(1000, funcref('s:grep_timer'), {'repeat' : 1}) + let s:grep_timer_id = timer_start(500, funcref('s:grep_timer'), {'repeat' : 1}) endfunction let s:MPT._handle_fly = function('s:flygrep') From a34d005a43fe0651832d8af90bea00a6d2c6e545 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 7 Jul 2017 21:05:28 +0800 Subject: [PATCH 33/63] Fix lint --- autoload/SpaceVim/plugins/flygrep.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index e8225e7d2..098e71afc 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -19,6 +19,7 @@ let s:grep_expr = '' let s:grep_exe = SpaceVim#mapping#search#default_tool() let s:grep_timer_id = 0 +" @vimlint(EVL103, 1, a:timer) function! s:grep_timer(timer) abort let s:grepid = s:JOB.start(s:get_search_cmd(s:grep_exe, s:grep_expr), { \ 'on_stdout' : function('s:grep_stdout'), @@ -26,6 +27,7 @@ function! s:grep_timer(timer) abort \ 'on_exit' : function('s:grep_exit'), \ }) endfunction +" @vimlint(EVL103, 0, a:timer) function! s:flygrep(expr) abort call s:MPT._build_prompt() From f314dee48f9da0dfeda3a5262aa06196354bd2e9 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 7 Jul 2017 22:08:16 +0800 Subject: [PATCH 34/63] Update readme --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e6a4c01c1..c5e2cae62 100644 --- a/README.md +++ b/README.md @@ -123,20 +123,20 @@ let g:spacevim_max_column = 80 let g:spacevim_plugin_bundle_dir = '~/.cache/vimfiles/' " set SpaceVim colorscheme -let g:spacevim_colorscheme = 'jellybeans' +let g:spacevim_colorscheme = 'gruvbox' " Set plugin manager, you want to use, default is dein.vim let g:spacevim_plugin_manager = 'dein' " neobundle or dein or vim-plug -" use space as `` -let mapleader = "\" - " Set windows shortcut leader [Window], default is `s` let g:spacevim_windows_leader = 's' " Set unite work flow shortcut leader [Unite], default is `f` let g:spacevim_unite_leader = 'f' +" Set Denite work flow shortcut leader [Denite], default is `F` +let g:spacevim_denite_leader = 'F' + " By default, language specific plugins are not loaded. This can be changed " with the following, then the plugins for go development will be loaded. call SpaceVim#layers#load('lang#go') @@ -193,11 +193,6 @@ curl -sLf https://spacevim.org/install.sh | bash **After SpaceVim is installed, launch `vim` and SpaceVim will automatically install plugins** -Once plugins start installing, at the bottom of the vim window, you will see -`[dein] Install started: (YYYY/MM/DD HH:MM:SS)` - -Please wait for all the plugins to complete installing before using vim. Once the plugin installation completes, you will see -`[dein] Done: (YYYY/MM/DD HH:MM:SS) `. At this point you can start using vim. SpaceVim required Vim7.4 above or neovim, here is the installation of neovim/vim with python support: From 489990aeadc775848cf9ffe3ad832d589e9e148d Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 7 Jul 2017 22:17:10 +0800 Subject: [PATCH 35/63] Fix fly grep pattern Problem: grep expr do not update when user input character Solution: update s:grep_expr when input character --- autoload/SpaceVim/plugins/flygrep.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index 098e71afc..b2b8e6905 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -41,6 +41,7 @@ function! s:flygrep(expr) abort endtr exe 'syn match FileNames /' . substitute(a:expr, '\([/\\]\)', '\\\1', 'g') . '/' hi def link FileNames MoreMsg + let s:grep_expr = a:expr let s:grep_timer_id = timer_start(500, funcref('s:grep_timer'), {'repeat' : 1}) endfunction From a7e6ae15a0556490fe61af3db50f4a41c820ba87 Mon Sep 17 00:00:00 2001 From: L-stt <279834419@qq.com> Date: Sat, 8 Jul 2017 16:46:53 +0800 Subject: [PATCH 36/63] Fix windows support --- autoload/SpaceVim/plugins/flygrep.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index b2b8e6905..1f0af78be 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -1,5 +1,6 @@ let s:MPT = SpaceVim#api#import('prompt') let s:JOB = SpaceVim#api#import('job') +let s:SYS = SpaceVim#api#import('system') let s:grepid = 0 @@ -125,11 +126,16 @@ function! s:open_item() abort endif call s:MPT._clear_prompt() let s:MPT._quit = 1 + let isfname = &isfname + if s:SYS.isWindows + set isfname-=: + endif normal! gF let nr = bufnr('%') q exe 'silent b' . nr normal! : + let &isfname = isfname endif endfunction From 474bd1efe75d7a5aed83110627c4e12866be74b9 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 8 Jul 2017 23:02:07 +0800 Subject: [PATCH 37/63] Add mouse support --- autoload/SpaceVim/api/prompt.vim | 2 +- autoload/SpaceVim/plugins/flygrep.vim | 36 +++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/api/prompt.vim b/autoload/SpaceVim/api/prompt.vim index f7583b23c..2d466b67d 100644 --- a/autoload/SpaceVim/api/prompt.vim +++ b/autoload/SpaceVim/api/prompt.vim @@ -43,7 +43,7 @@ func! s:self._handle_input() abort call call(self._function_key[char], []) continue endif - if char ==# "\" || char ==# "\" + if char ==# "\" || char ==# "\" || char2nr(char) == 128 continue endif if char ==# "\" || char == 6 diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index 1f0af78be..5594e325d 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -139,10 +139,46 @@ function! s:open_item() abort endif endfunction +function! s:double_click() abort + if line('.') !=# '' + if s:grepid != 0 + call s:JOB.stop(s:grepid) + endif + call s:MPT._clear_prompt() + let s:MPT._quit = 1 + let isfname = &isfname + if s:SYS.isWindows + set isfname-=: + endif + normal! gF + let nr = bufnr('%') + q + exe 'silent b' . nr + normal! : + let &isfname = isfname + endif +endfunction + +function! s:move_cursor() abort + if v:mouse_win == winnr() + let cl = line('.') + if cl < v:mouse_lnum + exe 'normal! ' . (v:mouse_lnum - cl) . 'j' + elseif cl > v:mouse_lnum + exe 'normal! ' . (cl - v:mouse_lnum) . 'k' + endif + endif + call s:MPT._build_prompt() +endfunction + let s:MPT._function_key = { \ "\" : function('s:next_item'), + \ "\" : function('s:next_item'), \ "\" : function('s:previous_item'), + \ "\" : function('s:previous_item'), \ "\" : function('s:open_item'), + \ "\" : function('s:move_cursor'), + \ "\<2-LeftMouse>" : function('s:double_click'), \ } " statusline api From 1afb6276c53e69d8767319076f02c95befa200f7 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 8 Jul 2017 23:04:20 +0800 Subject: [PATCH 38/63] Fix charactor ignores --- autoload/SpaceVim/api/prompt.vim | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/autoload/SpaceVim/api/prompt.vim b/autoload/SpaceVim/api/prompt.vim index 2d466b67d..79139fb7a 100644 --- a/autoload/SpaceVim/api/prompt.vim +++ b/autoload/SpaceVim/api/prompt.vim @@ -43,9 +43,6 @@ func! s:self._handle_input() abort call call(self._function_key[char], []) continue endif - if char ==# "\" || char ==# "\" || char2nr(char) == 128 - continue - endif if char ==# "\" || char == 6 let self._prompt.begin = self._prompt.begin . self._prompt.cursor let self._prompt.cursor = matchstr(self._prompt.end, '^.') @@ -88,6 +85,8 @@ func! s:self._handle_input() abort elseif char == self._keys.close call self.close() break + elseif char ==# "\" || char ==# "\" || char2nr(char) == 128 + continue else let self._prompt.begin .= char call self._build_prompt() From fe2bf4b59efe716fada651ccf7fdbcfd0e09583f Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 9 Jul 2017 14:28:47 +0800 Subject: [PATCH 39/63] Update doc for prompt api --- autoload/SpaceVim/api/prompt.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autoload/SpaceVim/api/prompt.vim b/autoload/SpaceVim/api/prompt.vim index 79139fb7a..749025476 100644 --- a/autoload/SpaceVim/api/prompt.vim +++ b/autoload/SpaceVim/api/prompt.vim @@ -1,3 +1,12 @@ +"" +" @section cmdlinemenu, api-cmdlinemenu +" @parentsection api +" menu({items}) +" +" Create a cmdline selection menu from a list of {items}, each item should be a +" list of two value in it, first one is the description, and the next one +" should be a funcrc. + let s:self = {} From 5d9e3dbf742f8d61fd14395125a0341d74ed0c7d Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 9 Jul 2017 14:44:19 +0800 Subject: [PATCH 40/63] Update doc for prompt api --- autoload/SpaceVim/api/prompt.vim | 9 ++++----- autoload/SpaceVim/default.vim | 4 ++++ doc/SpaceVim.txt | 13 +++++++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/autoload/SpaceVim/api/prompt.vim b/autoload/SpaceVim/api/prompt.vim index 749025476..78ec3d834 100644 --- a/autoload/SpaceVim/api/prompt.vim +++ b/autoload/SpaceVim/api/prompt.vim @@ -1,11 +1,10 @@ "" -" @section cmdlinemenu, api-cmdlinemenu +" @section prompt, api-prompt " @parentsection api -" menu({items}) +" open() " -" Create a cmdline selection menu from a list of {items}, each item should be a -" list of two value in it, first one is the description, and the next one -" should be a funcrc. +" Create a cmdline prompt, use while loop to get the input from user. The +" default mapping for prompt is: let s:self = {} diff --git a/autoload/SpaceVim/default.vim b/autoload/SpaceVim/default.vim index d1e783725..8b30d62c4 100644 --- a/autoload/SpaceVim/default.vim +++ b/autoload/SpaceVim/default.vim @@ -107,6 +107,10 @@ function! SpaceVim#default#SetOptions() abort set ttimeout set ttimeoutlen=50 set lazyredraw + if has('patch-7.4.314') + " don't give ins-completion-menu messages. + set shortmess+=c + endif endfunction function! SpaceVim#default#SetPlugins() abort diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index f35e77a00..6681c1ad4 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -50,8 +50,9 @@ CONTENTS *SpaceVim-contents* 6. API........................................................|SpaceVim-api| 1. cmdlinemenu................................|SpaceVim-api-cmdlinemenu| 2. data#list....................................|SpaceVim-api-data-list| - 3. sid............................................|SpaceVim-api-vim-sid| - 4. vim#message................................|SpaceVim-api-vim-message| + 3. prompt..........................................|SpaceVim-api-prompt| + 4. sid............................................|SpaceVim-api-vim-sid| + 5. vim#message................................|SpaceVim-api-vim-message| 7. FAQ........................................................|SpaceVim-faq| ============================================================================== @@ -982,6 +983,14 @@ listpart({list}, {start}[, {len}]) The result is a List, which is part of {list}, starting from index {start}, with the length {len} +============================================================================== +PROMPT *SpaceVim-api-prompt* + +open() + +Create a cmdline prompt, use while loop to get the input from user. The +default mapping for prompt is: + ============================================================================== SID *SpaceVim-api-vim-sid* From eac96d094b095dd7bbc498f385af306f50bea385 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 9 Jul 2017 15:29:13 +0800 Subject: [PATCH 41/63] Update doc for prompt mappings --- autoload/SpaceVim/api/prompt.vim | 8 ++++++++ doc/SpaceVim.txt | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/autoload/SpaceVim/api/prompt.vim b/autoload/SpaceVim/api/prompt.vim index 78ec3d834..857569e06 100644 --- a/autoload/SpaceVim/api/prompt.vim +++ b/autoload/SpaceVim/api/prompt.vim @@ -5,6 +5,14 @@ " " Create a cmdline prompt, use while loop to get the input from user. The " default mapping for prompt is: +" > +" remove last character +" remove the Word before the cursor +" remove the Line before the cursor +" remove the Line after the cursor +" / Go to the beginning of the line +" / Go to the end of the line +" < let s:self = {} diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 6681c1ad4..3e16be40a 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -990,6 +990,14 @@ open() Create a cmdline prompt, use while loop to get the input from user. The default mapping for prompt is: +> + remove last character + remove the Word before the cursor + remove the Line before the cursor + remove the Line after the cursor + / Go to the beginning of the line + / Go to the end of the line +< ============================================================================== SID *SpaceVim-api-vim-sid* From 006535b27f4018dcac10ef91bc81e031ba8d084c Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 9 Jul 2017 15:34:14 +0800 Subject: [PATCH 42/63] Fix shortmess option --- config/general.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/general.vim b/config/general.vim index aaf979ba2..a73b2b5d9 100644 --- a/config/general.vim +++ b/config/general.vim @@ -26,7 +26,7 @@ else exec 'colorscheme '. g:spacevim_colorscheme_default endif if g:spacevim_hiddenfileinfo == 1 && has('patch-7.4.1570') - set shortmess=filnxtToOFs + set shortmess+=F endif if !empty(g:spacevim_guifont) exe 'set guifont=' . g:spacevim_guifont From df6c1a1c82b63f5a5b24708d2d787e6735300e94 Mon Sep 17 00:00:00 2001 From: Zym-xx Date: Sun, 9 Jul 2017 16:20:16 +0800 Subject: [PATCH 43/63] Close job/timer when close flygrep buffer --- autoload/SpaceVim/plugins/flygrep.vim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index 5594e325d..4264fdcce 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -49,6 +49,12 @@ endfunction let s:MPT._handle_fly = function('s:flygrep') function! s:close_buffer() abort + if s:grepid != 0 + call s:JOB.stop(s:grepid) + endif + if s:grep_timer_id != 0 + call timer_stop(s:grep_timer_id) + endif q endfunction From 8144d4d8383fbed9a0fe2ba244c6d0e7fa1a1250 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 11 Jul 2017 05:56:14 +0800 Subject: [PATCH 44/63] Fix n/N do not change hl state close #710 --- autoload/SpaceVim/layers/incsearch.vim | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/layers/incsearch.vim b/autoload/SpaceVim/layers/incsearch.vim index f2450cc5d..8be6514f7 100644 --- a/autoload/SpaceVim/layers/incsearch.vim +++ b/autoload/SpaceVim/layers/incsearch.vim @@ -67,10 +67,18 @@ endfunction let s:si_flag = 0 function! s:update_search_index(key) abort if a:key == 'n' - normal! n + if mapcheck("(incsearch-nohl-n)") !=# '' + call feedkeys("\(incsearch-nohl-n)") + else + normal! n + endif normal! ml elseif a:key == 'N' - normal! N + if mapcheck("(incsearch-nohl-n)") !=# '' + call feedkeys("\(incsearch-nohl-N)") + else + normal! N + endif normal! ml endif if s:si_flag == 0 From be329308b0b5e37db027631c98e561c08a0f5643 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 11 Jul 2017 04:21:57 +0800 Subject: [PATCH 45/63] Add SPC c l for toggle comment lines --- autoload/SpaceVim/mapping/space.vim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 29971d82c..16e61bc9d 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -74,7 +74,7 @@ function! SpaceVim#mapping#space#init() abort " " Toggles the comment state of the selected line(s). If the topmost selected " line is commented, all selected lines are uncommented and vice versa. - call SpaceVim#mapping#space#def('nnoremap', ['c', 'l'], 'call NERDComment("n", "Toggle")', 'Toggle comment line(s)', 1) + call SpaceVim#mapping#space#def('nnoremap', ['c', 'l'], 'call feedkeys("\NERDCommenterComment")', 'Toggle comment line(s)', 1, 1) let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'} let g:_spacevim_mappings_space.B = {'name' : '+Global-buffers'} @@ -205,10 +205,11 @@ function! SpaceVim#mapping#space#init() abort \ 'clear search highlight', 1) endfunction -function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd) abort +function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd, ...) abort if s:has_map_to_spc() return endif + let is_visual = a:0 > 0 ? a:1 : 0 if a:is_cmd let cmd = ':' . a:cmd . '' let lcmd = a:cmd @@ -222,6 +223,11 @@ function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd) abort endif endif exe a:m . ' [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g') + if is_visual + if a:m ==# 'nnoremap' + exe 'xnoremap [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g') + endif + endif if len(a:keys) == 2 let g:_spacevim_mappings_space[a:keys[0]][a:keys[1]] = [lcmd, a:desc] elseif len(a:keys) == 3 From 12dd80c664da37eecb1161bad0911af814c5f2d3 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 11 Jul 2017 05:00:45 +0800 Subject: [PATCH 46/63] Add SPC c L for invert comment lines --- autoload/SpaceVim/mapping/space.vim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 16e61bc9d..26e44d008 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -75,6 +75,13 @@ function! SpaceVim#mapping#space#init() abort " Toggles the comment state of the selected line(s). If the topmost selected " line is commented, all selected lines are uncommented and vice versa. call SpaceVim#mapping#space#def('nnoremap', ['c', 'l'], 'call feedkeys("\NERDCommenterComment")', 'Toggle comment line(s)', 1, 1) + call SpaceVim#mapping#space#def('nnoremap', ['c', 'L'], 'call feedkeys("\NERDCommenterInvert")', 'Toggle comment line(s)', 1, 1) + " in nerdcomment if has map to ... the default mapping will be + " disable, so we add it for compatibility + nnoremap cc :call feedkeys("\NERDCommenterComment") + xnoremap cc :call feedkeys("\NERDCommenterComment") + nnoremap ci :call feedkeys("\NERDCommenterInvert") + xnoremap ci :call feedkeys("\NERDCommenterInvert") let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'} let g:_spacevim_mappings_space.B = {'name' : '+Global-buffers'} From ed10d8609fbb24afc5c48be46675a07c4e18e955 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 11 Jul 2017 05:12:37 +0800 Subject: [PATCH 47/63] Add SPC c p/P for comment paragraphs --- autoload/SpaceVim/mapping/space.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 26e44d008..1ce69c934 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -76,6 +76,8 @@ function! SpaceVim#mapping#space#init() abort " line is commented, all selected lines are uncommented and vice versa. call SpaceVim#mapping#space#def('nnoremap', ['c', 'l'], 'call feedkeys("\NERDCommenterComment")', 'Toggle comment line(s)', 1, 1) call SpaceVim#mapping#space#def('nnoremap', ['c', 'L'], 'call feedkeys("\NERDCommenterInvert")', 'Toggle comment line(s)', 1, 1) + call SpaceVim#mapping#space#def('nnoremap', ['c', 'p'], 'call feedkeys("vip\NERDCommenterComment")', 'Toggle comment line(s)', 1) + call SpaceVim#mapping#space#def('nnoremap', ['c', 'P'], 'call feedkeys("vip\NERDCommenterInvert")', 'Toggle comment line(s)', 1) " in nerdcomment if has map to ... the default mapping will be " disable, so we add it for compatibility nnoremap cc :call feedkeys("\NERDCommenterComment") From 1193760c924421b119be2895846cf0e3410474fd Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Wed, 12 Jul 2017 08:08:31 +0800 Subject: [PATCH 48/63] Fix comment mappings --- autoload/SpaceVim/mapping/space.vim | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 1ce69c934..1e07bad75 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -74,16 +74,16 @@ function! SpaceVim#mapping#space#init() abort " " Toggles the comment state of the selected line(s). If the topmost selected " line is commented, all selected lines are uncommented and vice versa. - call SpaceVim#mapping#space#def('nnoremap', ['c', 'l'], 'call feedkeys("\NERDCommenterComment")', 'Toggle comment line(s)', 1, 1) - call SpaceVim#mapping#space#def('nnoremap', ['c', 'L'], 'call feedkeys("\NERDCommenterInvert")', 'Toggle comment line(s)', 1, 1) - call SpaceVim#mapping#space#def('nnoremap', ['c', 'p'], 'call feedkeys("vip\NERDCommenterComment")', 'Toggle comment line(s)', 1) - call SpaceVim#mapping#space#def('nnoremap', ['c', 'P'], 'call feedkeys("vip\NERDCommenterInvert")', 'Toggle comment line(s)', 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'l'], 'NERDCommenterComment', 'comment lines', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'L'], 'NERDCommenterInvert', 'toggle comment lines', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'p'], 'vip\NERDCommenterComment', 'comment paragraphs', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vip\NERDCommenterInvert', 'toggle comment paragraphs', 0, 1) " in nerdcomment if has map to ... the default mapping will be " disable, so we add it for compatibility - nnoremap cc :call feedkeys("\NERDCommenterComment") - xnoremap cc :call feedkeys("\NERDCommenterComment") - nnoremap ci :call feedkeys("\NERDCommenterInvert") - xnoremap ci :call feedkeys("\NERDCommenterInvert") + nmap cc NERDCommenterComment + xmap cc NERDCommenterComment + nmap ci NERDCommenterInvert + xmap ci NERDCommenterInvert let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'} let g:_spacevim_mappings_space.B = {'name' : '+Global-buffers'} @@ -235,6 +235,8 @@ function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd, ...) abort if is_visual if a:m ==# 'nnoremap' exe 'xnoremap [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g') + elseif a:m ==# 'nmap' + exe 'xmap [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g') endif endif if len(a:keys) == 2 From 02bea940097b0b3bff18b3996d406fa2e08df411 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 13 Jul 2017 04:24:00 +0800 Subject: [PATCH 49/63] Fix highlight api --- autoload/SpaceVim/api/vim/highlight.vim | 65 ++++++++++++++----------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/autoload/SpaceVim/api/vim/highlight.vim b/autoload/SpaceVim/api/vim/highlight.vim index 482676a83..036340409 100644 --- a/autoload/SpaceVim/api/vim/highlight.vim +++ b/autoload/SpaceVim/api/vim/highlight.vim @@ -3,7 +3,16 @@ let s:self = {} function! s:self.group2dict(name) abort let id = index(map(range(1999), "synIDattr(v:val, 'name')"), a:name) if id == -1 - return {} + return { + \ 'name' : '', + \ 'ctermbg' : '', + \ 'ctermfg' : '', + \ 'bold' : '', + \ 'italic' : '', + \ 'underline' : '', + \ 'guibg' : '', + \ 'guifg' : '', + \ } endif let rst = { \ 'name' : synIDattr(id, 'name'), @@ -32,35 +41,35 @@ function! s:self.unite(base, target, part) abort endfunction function! s:self.hi(info) abort - if empty(a:info) + if empty(a:info) || get(a:info, 'name', '') ==# '' return endif - let cmd = 'hi! ' . a:info.name - if !empty(a:info.ctermbg) - let cmd .= ' ctermbg=' . a:info.ctermbg - endif - if !empty(a:info.ctermfg) - let cmd .= ' ctermfg=' . a:info.ctermfg - endif - if !empty(a:info.guibg) - let cmd .= ' guibg=' . a:info.guibg - endif - if !empty(a:info.guifg) - let cmd .= ' guifg=' . a:info.guifg - endif - let style = [] - for sty in ['hold', 'italic', 'underline'] - if get(a:info, sty, '') ==# '1' - call add(style, sty) - endif - endfor - if !empty(style) - let cmd .= ' gui=' . join(style, ',') . ' cterm=' . join(style, ',') - endif - try - exe cmd - catch - endtry + let cmd = 'hi! ' . a:info.name + if !empty(a:info.ctermbg) + let cmd .= ' ctermbg=' . a:info.ctermbg + endif + if !empty(a:info.ctermfg) + let cmd .= ' ctermfg=' . a:info.ctermfg + endif + if !empty(a:info.guibg) + let cmd .= ' guibg=' . a:info.guibg + endif + if !empty(a:info.guifg) + let cmd .= ' guifg=' . a:info.guifg + endif + let style = [] + for sty in ['hold', 'italic', 'underline'] + if get(a:info, sty, '') ==# '1' + call add(style, sty) + endif + endfor + if !empty(style) + let cmd .= ' gui=' . join(style, ',') . ' cterm=' . join(style, ',') + endif + try + exe cmd + catch + endtry endfunction function! s:self.hide_in_normal(name) abort From 81053136b3cfd4233467394795662df0288ad4e1 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 13 Jul 2017 04:28:21 +0800 Subject: [PATCH 50/63] Load jedi-vim only when has +py or +py3 --- autoload/SpaceVim/layers/lang/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/lang/python.vim b/autoload/SpaceVim/layers/lang/python.vim index 7c41e0ba5..4ac25f25c 100644 --- a/autoload/SpaceVim/layers/lang/python.vim +++ b/autoload/SpaceVim/layers/lang/python.vim @@ -13,7 +13,7 @@ function! SpaceVim#layers#lang#python#plugins() abort if has('nvim') call add(plugins, ['zchee/deoplete-jedi', { 'on_ft' : 'python'}]) else - call add(plugins, ['davidhalter/jedi-vim', { 'on_ft' : 'python'}]) + call add(plugins, ['davidhalter/jedi-vim', { 'on_ft' : 'python', 'if' : has('python') || has('python3')}]) endif call add(plugins, ['Vimjas/vim-python-pep8-indent', { 'on_ft' : 'python'}]) return plugins From 3516b9fd90e82fba55577f75393b261ed1843bf2 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 13 Jul 2017 04:37:54 +0800 Subject: [PATCH 51/63] Fix comment paragraphs --- autoload/SpaceVim/mapping/space.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 1e07bad75..475bc7055 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -76,8 +76,8 @@ function! SpaceVim#mapping#space#init() abort " line is commented, all selected lines are uncommented and vice versa. call SpaceVim#mapping#space#def('nmap', ['c', 'l'], 'NERDCommenterComment', 'comment lines', 0, 1) call SpaceVim#mapping#space#def('nmap', ['c', 'L'], 'NERDCommenterInvert', 'toggle comment lines', 0, 1) - call SpaceVim#mapping#space#def('nmap', ['c', 'p'], 'vip\NERDCommenterComment', 'comment paragraphs', 0, 1) - call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vip\NERDCommenterInvert', 'toggle comment paragraphs', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'p'], 'vipNERDCommenterComment', 'comment paragraphs', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vipNERDCommenterInvert', 'toggle comment paragraphs', 0, 1) " in nerdcomment if has map to ... the default mapping will be " disable, so we add it for compatibility nmap cc NERDCommenterComment From 5dd469b37fd6de0e49a3746542de735df943db37 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 13 Jul 2017 06:18:41 +0800 Subject: [PATCH 52/63] Add SPC c ; for comment operator --- autoload/SpaceVim/mapping/g.vim | 2 ++ autoload/SpaceVim/mapping/space.vim | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/autoload/SpaceVim/mapping/g.vim b/autoload/SpaceVim/mapping/g.vim index 941267b89..09659f9c0 100644 --- a/autoload/SpaceVim/mapping/g.vim +++ b/autoload/SpaceVim/mapping/g.vim @@ -20,6 +20,8 @@ function! SpaceVim#mapping#g#init() abort nnoremap g, g, let g:_spacevim_mappings_g[';'] = ['call feedkeys("g;", "n")', 'older position in change list'] nnoremap g; g; + let g:_spacevim_mappings_g['@'] = ['call feedkeys("g@", "n")', 'call operatorfunc'] + nnoremap g@ g@ let g:_spacevim_mappings_g['#'] = ['call feedkeys("\(incsearch-nohl-g#)")', 'search under cursor backward'] let g:_spacevim_mappings_g['*'] = ['call feedkeys("\(incsearch-nohl-g*)")', 'search under cursor forward'] diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 475bc7055..9ff8441f7 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -78,6 +78,11 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nmap', ['c', 'L'], 'NERDCommenterInvert', 'toggle comment lines', 0, 1) call SpaceVim#mapping#space#def('nmap', ['c', 'p'], 'vipNERDCommenterComment', 'comment paragraphs', 0, 1) call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vipNERDCommenterInvert', 'toggle comment paragraphs', 0, 1) + + nnoremap CommentOperator :set opfunc=commentOperatorg@ + let g:_spacevim_mappings_space.c[';'] = ['call feedkeys("\CommentOperator")', 'comment operator'] + nmap [SPC]c; CommentOperator + " in nerdcomment if has map to ... the default mapping will be " disable, so we add it for compatibility nmap cc NERDCommenterComment @@ -304,4 +309,25 @@ function! SpaceVim#mapping#space#langSPC(m, keys, cmd, desc, is_cmd) abort call extend(g:_spacevim_mappings_prefixs['[SPC]'], get(g:, '_spacevim_mappings_space', {})) endfunction +function! s:commentOperator(type, ...) + let sel_save = &selection + let &selection = "inclusive" + let reg_save = @@ + + if a:0 " Invoked from Visual mode, use gv command. + silent exe "normal! gv" + call feedkeys("\NERDCommenterComment") + elseif a:type == 'line' + call feedkeys('`[V`]') + call feedkeys("\NERDCommenterComment") + else + call feedkeys('`[v`]') + call feedkeys("\NERDCommenterComment") + endif + + let &selection = sel_save + let @@ = reg_save + set opfunc= +endfunction + " vim:set et sw=2 cc=80: From e40eec9cc4f274cbc45ae48d66a4f68e8bddcd6d Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 13 Jul 2017 06:34:13 +0800 Subject: [PATCH 53/63] Use SPC ; instead of SPC c ; --- autoload/SpaceVim/mapping/space.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 9ff8441f7..2423605a4 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -80,8 +80,8 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vipNERDCommenterInvert', 'toggle comment paragraphs', 0, 1) nnoremap CommentOperator :set opfunc=commentOperatorg@ - let g:_spacevim_mappings_space.c[';'] = ['call feedkeys("\CommentOperator")', 'comment operator'] - nmap [SPC]c; CommentOperator + let g:_spacevim_mappings_space[';'] = ['call feedkeys("\CommentOperator")', 'comment operator'] + nmap [SPC]; CommentOperator " in nerdcomment if has map to ... the default mapping will be " disable, so we add it for compatibility From 0f56158bc7ec42c0cd5182ede51656a072b46333 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Thu, 13 Jul 2017 08:15:37 +0800 Subject: [PATCH 54/63] Comment to line --- autoload/SpaceVim/mapping/space.vim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 2423605a4..af323b11d 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -79,6 +79,11 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nmap', ['c', 'p'], 'vipNERDCommenterComment', 'comment paragraphs', 0, 1) call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vipNERDCommenterInvert', 'toggle comment paragraphs', 0, 1) + nnoremap CommentToLine :comment_to_line(0) + nnoremap CommentToLineInvert :comment_to_line(1) + call SpaceVim#mapping#space#def('nmap', ['c', 't'], 'CommentToLine', 'comment to line', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'T'], 'CommentToLineInvert', 'toggle comment to line', 0, 1) + nnoremap CommentOperator :set opfunc=commentOperatorg@ let g:_spacevim_mappings_space[';'] = ['call feedkeys("\CommentOperator")', 'comment operator'] nmap [SPC]; CommentOperator @@ -330,4 +335,20 @@ function! s:commentOperator(type, ...) set opfunc= endfunction +function! s:comment_to_line(invert) abort + let line = str2nr(input('line number :')) + let ex = line - line('.') + if ex > 0 + exe 'normal! V'. ex .'j' + elseif ex == 0 + else + exe 'normal! V'. ex .'k' + endif + if a:invert + call feedkeys("\NERDCommenterInvert") + else + call feedkeys("\NERDCommenterComment") + endif +endfunction + " vim:set et sw=2 cc=80: From edd3439e65d0890f2f3208e4973880496f76948a Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 14 Jul 2017 04:14:58 +0800 Subject: [PATCH 55/63] Fix SPC c t --- autoload/SpaceVim/mapping/space.vim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index af323b11d..febb9b889 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -79,8 +79,8 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nmap', ['c', 'p'], 'vipNERDCommenterComment', 'comment paragraphs', 0, 1) call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vipNERDCommenterInvert', 'toggle comment paragraphs', 0, 1) - nnoremap CommentToLine :comment_to_line(0) - nnoremap CommentToLineInvert :comment_to_line(1) + nnoremap CommentToLine :call comment_to_line(0) + nnoremap CommentToLineInvert :call comment_to_line(1) call SpaceVim#mapping#space#def('nmap', ['c', 't'], 'CommentToLine', 'comment to line', 0, 1) call SpaceVim#mapping#space#def('nmap', ['c', 'T'], 'CommentToLineInvert', 'toggle comment to line', 0, 1) @@ -336,13 +336,17 @@ function! s:commentOperator(type, ...) endfunction function! s:comment_to_line(invert) abort - let line = str2nr(input('line number :')) + let input = input('line number :') + if empty(input) + return + endif + let line = str2nr(input) let ex = line - line('.') if ex > 0 exe 'normal! V'. ex .'j' elseif ex == 0 else - exe 'normal! V'. ex .'k' + exe 'normal! V'. abs(ex) .'k' endif if a:invert call feedkeys("\NERDCommenterInvert") From ce9e6ee07e4d874b84f73f6d0235617475a29ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Ti=C3=A1?= Date: Thu, 13 Jul 2017 19:18:53 -0600 Subject: [PATCH 56/63] Make explicit is until a line number the commment --- autoload/SpaceVim/mapping/space.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index febb9b889..c6f847131 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -81,8 +81,8 @@ function! SpaceVim#mapping#space#init() abort nnoremap CommentToLine :call comment_to_line(0) nnoremap CommentToLineInvert :call comment_to_line(1) - call SpaceVim#mapping#space#def('nmap', ['c', 't'], 'CommentToLine', 'comment to line', 0, 1) - call SpaceVim#mapping#space#def('nmap', ['c', 'T'], 'CommentToLineInvert', 'toggle comment to line', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 't'], 'CommentToLine', 'comment until the line', 0, 1) + call SpaceVim#mapping#space#def('nmap', ['c', 'T'], 'CommentToLineInvert', 'toggle comment until the line', 0, 1) nnoremap CommentOperator :set opfunc=commentOperatorg@ let g:_spacevim_mappings_space[';'] = ['call feedkeys("\CommentOperator")', 'comment operator'] @@ -336,7 +336,7 @@ function! s:commentOperator(type, ...) endfunction function! s:comment_to_line(invert) abort - let input = input('line number :') + let input = input('line number: ') if empty(input) return endif From 1538b4a41da1dfdc7528405b4294cb61e27e9999 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 15 Jul 2017 05:17:20 +0800 Subject: [PATCH 57/63] Add web api --- autoload/SpaceVim/api/web/html.vim | 53 ++++ autoload/SpaceVim/api/web/http.vim | 478 +++++++++++++++++++++++++++++ autoload/SpaceVim/api/web/xml.vim | 327 ++++++++++++++++++++ 3 files changed, 858 insertions(+) create mode 100644 autoload/SpaceVim/api/web/html.vim create mode 100644 autoload/SpaceVim/api/web/http.vim create mode 100644 autoload/SpaceVim/api/web/xml.vim diff --git a/autoload/SpaceVim/api/web/html.vim b/autoload/SpaceVim/api/web/html.vim new file mode 100644 index 000000000..4b4d152de --- /dev/null +++ b/autoload/SpaceVim/api/web/html.vim @@ -0,0 +1,53 @@ +let s:save_cpo = &cpo +set cpo&vim + +let s:self = {} +let s:XML = SpaceVim#api#import('web#xml') +let s:HTTP = SpaceVim#api#import('web#http') + +function! s:self.decodeEntityReference(str) abort + let str = a:str + let str = substitute(str, '>', '>', 'g') + let str = substitute(str, '<', '<', 'g') + let str = substitute(str, '"', '"', 'g') + let str = substitute(str, ''', "'", 'g') + let str = substitute(str, ' ', ' ', 'g') + let str = substitute(str, '¥', '\¥', 'g') + let str = substitute(str, '&#\(\d\+\);', '\=s:nr2enc_char(submatch(1))', 'g') + let str = substitute(str, '&', '\&', 'g') + let str = substitute(str, '»', '>', 'g') + let str = substitute(str, '«', '<', 'g') + return str +endfunction + +function! s:self.encodeEntityReference(str) abort + let str = a:str + let str = substitute(str, '&', '\&', 'g') + let str = substitute(str, '>', '\>', 'g') + let str = substitute(str, '<', '\<', 'g') + let str = substitute(str, "\n", '\ ', 'g') + let str = substitute(str, '"', '\"', 'g') + let str = substitute(str, "'", '\'', 'g') + let str = substitute(str, ' ', '\ ', 'g') + return str +endfunction + +function! s:self.parse(html) abort + let html = substitute(a:html, '<\(area\|base\|basefont\|br\|nobr\|col\|frame\|hr\|img\|input\|isindex\|link\|meta\|param\|embed\|keygen\|command\)\([^>]*[^/]\|\)>', '<\1\2/>', 'g') + return s:XML.parse(html) +endfunction + +function! s:self.parseFile(file) abort + return self.parse(join(readfile(a:file), "\n")) +endfunction + +function! s:self.parseURL(url) abort + return self.parse(s:HTTP.get(a:url).content) +endfunction + +function! SpaceVim#api#web#html#get() abort + return deepcopy(s:self) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo diff --git a/autoload/SpaceVim/api/web/http.vim b/autoload/SpaceVim/api/web/http.vim new file mode 100644 index 000000000..9b548e498 --- /dev/null +++ b/autoload/SpaceVim/api/web/http.vim @@ -0,0 +1,478 @@ +let s:save_cpo = &cpo +set cpo&vim + +let s:self = {} + +let s:system = function(get(g:, 'webapi#system_function', 'system')) + +function! s:nr2byte(nr) abort + if a:nr < 0x80 + return nr2char(a:nr) + elseif a:nr < 0x800 + return nr2char(a:nr/64+192).nr2char(a:nr%64+128) + elseif a:nr < 0x10000 + return nr2char(a:nr/4096%16+224).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128) + elseif a:nr < 0x200000 + return nr2char(a:nr/262144%16+240).nr2char(a:nr/4096/16+128).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128) + elseif a:nr < 0x4000000 + return nr2char(a:nr/16777216%16+248).nr2char(a:nr/262144%16+128).nr2char(a:nr/4096/16+128).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128) + else + return nr2char(a:nr/1073741824%16+252).nr2char(a:nr/16777216%16+128).nr2char(a:nr/262144%16+128).nr2char(a:nr/4096/16+128).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128) + endif +endfunction + +function! s:nr2enc_char(charcode) abort + if &encoding ==# 'utf-8' + return nr2char(a:charcode) + endif + let char = s:nr2byte(a:charcode) + if strlen(char) > 1 + let char = strtrans(iconv(char, 'utf-8', &encoding)) + endif + return char +endfunction + +function! s:nr2hex(nr) abort + let n = a:nr + let r = '' + while n + let r = '0123456789ABCDEF'[n % 16] . r + let n = n / 16 + endwhile + return r +endfunction + +function! s:urlencode_char(c, ...) abort + let is_binary = get(a:000, 1) + let c = a:c + if !is_binary + let c = iconv(a:c, &encoding, 'utf-8') + if c ==# '' + let c = a:c + endif + endif + let s = '' + for i in range(strlen(c)) + let s .= printf('%%%02X', char2nr(c[i])) + endfor + return s +endfunction + +function! s:self.decodeURI(str) abort + let ret = a:str + let ret = substitute(ret, '+', ' ', 'g') + let ret = substitute(ret, '%\(\x\x\)', '\=printf("%c", str2nr(submatch(1), 16))', 'g') + return ret +endfunction + +function! s:self.escape(str) abort + return substitute(a:str, '[^a-zA-Z0-9_.~/-]', '\=s:urlencode_char(submatch(0))', 'g') +endfunction + +function! s:self.encodeURI(items, ...) abort + let is_binary = get(a:000, 1) + let ret = '' + if type(a:items) == 4 + for key in sort(keys(a:items)) + if strlen(ret) | let ret .= '&' | endif + let ret .= key . '=' . s:self.encodeURI(a:items[key]) + endfor + elseif type(a:items) == 3 + for item in sort(a:items) + if strlen(ret) | let ret .= '&' | endif + let ret .= item + endfor + else + let ret = substitute(a:items, '[^a-zA-Z0-9_.~-]', '\=s:urlencode_char(submatch(0), is_binary)', 'g') + endif + return ret +endfunction + +function! s:self.encodeURIComponent(items) abort + let ret = '' + if type(a:items) == 4 + for key in sort(keys(a:items)) + if strlen(ret) | let ret .= '&' | endif + let ret .= key . '=' . s:self.encodeURIComponent(a:items[key]) + endfor + elseif type(a:items) == 3 + for item in sort(a:items) + if strlen(ret) | let ret .= '&' | endif + let ret .= item + endfor + else + let items = iconv(a:items, &enc, 'utf-8') + let len = strlen(items) + let i = 0 + while i < len + let ch = items[i] + if ch =~# '[0-9A-Za-z-._~!''()*]' + let ret .= ch + elseif ch ==# ' ' + let ret .= '+' + else + let ret .= '%' . substitute('0' . s:nr2hex(char2nr(ch)), '^.*\(..\)$', '\1', '') + endif + let i = i + 1 + endwhile + endif + return ret +endfunction + +function! s:self.get(url, ...) abort + let getdata = a:0 > 0 ? a:000[0] : {} + let headdata = a:0 > 1 ? a:000[1] : {} + let follow = a:0 > 2 ? a:000[2] : 1 + let url = a:url + let getdatastr = self.encodeURI(getdata) + if strlen(getdatastr) + let url .= '?' . getdatastr + endif + if executable('curl') + let command = printf('curl -q %s -s -k -i', follow ? '-L' : '') + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' -H ' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' -H ' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' ' . quote . url . quote + let res = s:system(command) + elseif executable('wget') + let command = printf('wget -O- --save-headers --server-response -q %s', follow ? '-L' : '') + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' --header=' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' --header=' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' ' . quote . url . quote + let res = s:system(command) + else + throw 'require `curl` or `wget` command' + endif + if follow != 0 + let mx = 'HTTP/\%(1\.[01]\|2\%(\.0\)\?\)' + while res =~# '^' . mx . ' 3' || res =~# '^' . mx . ' [0-9]\{3} .\+\n\r\?\n' . mx . ' .\+' + let pos = stridx(res, "\r\n\r\n") + if pos != -1 + let res = strpart(res, pos+4) + else + let pos = stridx(res, "\n\n") + let res = strpart(res, pos+2) + endif + endwhile + endif + let pos = stridx(res, "\r\n\r\n") + if pos != -1 + let content = strpart(res, pos+4) + else + let pos = stridx(res, "\n\n") + let content = strpart(res, pos+2) + endif + let header = split(res[:pos-1], '\r\?\n') + let matched = matchlist(get(header, 0), '^HTTP/\%(1\.[01]\|2\%(\.0\)\?\)\s\+\(\d\+\)\s*\(.*\)') + if !empty(matched) + let [status, message] = matched[1 : 2] + call remove(header, 0) + else + if v:shell_error || len(matched) + let [status, message] = ['500', "Couldn't connect to host"] + else + let [status, message] = ['200', 'OK'] + endif + endif + return { + \ 'status' : status, + \ 'message' : message, + \ 'header' : header, + \ 'content' : content + \} +endfunction + +function! s:self.post(url, ...) abort + let postdata = a:0 > 0 ? a:000[0] : {} + let headdata = a:0 > 1 ? a:000[1] : {} + let method = a:0 > 2 ? a:000[2] : 'POST' + let follow = a:0 > 3 ? a:000[3] : 1 + let url = a:url + if type(postdata) == 4 + let postdatastr = self.encodeURI(postdata) + else + let postdatastr = postdata + endif + let file = tempname() + if executable('curl') + let command = printf('curl -q %s -s -k -i -X %s', (follow ? '-L' : ''), len(method) ? method : 'POST') + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' -H ' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' -H ' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' ' . quote . url . quote + call writefile(split(postdatastr, "\n"), file, 'b') + let res = s:system(command . ' --data-binary @' . quote.file.quote) + elseif executable('wget') + let command = printf('wget -O- --save-headers --server-response -q %s', follow ? '-L' : '') + let headdata['X-HTTP-Method-Override'] = method + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' --header=' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' --header=' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' '.quote.url.quote + call writefile(split(postdatastr, "\n"), file, 'b') + let res = s:system(command . ' --post-data @' . quote.file.quote) + else + throw 'require `curl` or `wget` command' + endif + call delete(file) + if follow != 0 + let mx = 'HTTP/\%(1\.[01]\|2\%(\.0\)\?\)' + while res =~# '^' . mx . ' 3' || res =~# '^' . mx . ' [0-9]\{3} .\+\n\r\?\n' . mx . ' .\+' + let pos = stridx(res, "\r\n\r\n") + if pos != -1 + let res = strpart(res, pos+4) + else + let pos = stridx(res, "\n\n") + let res = strpart(res, pos+2) + endif + endwhile + endif + let pos = stridx(res, "\r\n\r\n") + if pos != -1 + let content = strpart(res, pos+4) + else + let pos = stridx(res, "\n\n") + let content = strpart(res, pos+2) + endif + let header = split(res[:pos-1], '\r\?\n') + let matched = matchlist(get(header, 0), '^HTTP/\%(1\.[01]\|2\%(\.0\)\?\)\s\+\(\d\+\)\s*\(.*\)') + if !empty(matched) + let [status, message] = matched[1 : 2] + call remove(header, 0) + else + if v:shell_error || len(matched) + let [status, message] = ['500', "Couldn't connect to host"] + else + let [status, message] = ['200', 'OK'] + endif + endif + return { + \ 'status' : status, + \ 'message' : message, + \ 'header' : header, + \ 'content' : content + \} +endfunction + +function! s:self.send(req) abort + let postdata = get(a:req, 'data', '') + let method = get(a:req, 'method', postdata ==# '' ? 'GET': 'POST') + let headdata = get(a:req, 'header', {}) + let follow = get(a:req, 'follow', 1) + let url = get(a:req, 'url', '') + if type(postdata) == 4 + let postdatastr = self.encodeURI(postdata) + else + let postdatastr = postdata + endif + if empty(postdatastr) + let file = '' + else + let file = tempname() + endif + if executable('curl') + let command = printf('curl -q %s -s -k -i -X %s', (follow ? '-L' : ''), len(method) ? method : 'POST') + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' -H ' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' -H ' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' ' . quote . url . quote + if file ==# '' + let res = s:system(command) + else + call writefile(split(postdatastr, "\n"), file, 'b') + let res = s:system(command . ' --data-binary @' . quote.file.quote) + call delete(file) + endif + elseif executable('wget') + let command = printf('wget -O- --save-headers --server-response -q %s', follow ? '-L' : '') + let headdata['X-HTTP-Method-Override'] = method + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' --header=' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' --header=' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' '.quote.url.quote + if file ==# '' + let res = s:system(command) + else + call writefile(split(postdatastr, "\n"), file, 'b') + let res = s:system(command . ' --post-data @' . quote.file.quote) + call delete(file) + endif + else + throw 'require `curl` or `wget` command' + endif + if follow != 0 + let mx = 'HTTP/\%(1\.[01]\|2\%(\.0\)\?\)' + while res =~# '^' . mx . ' 3' || res =~# '^' . mx . ' [0-9]\{3} .\+\n\r\?\n' . mx . ' .\+' + let pos = stridx(res, "\r\n\r\n") + if pos != -1 + let res = strpart(res, pos+4) + else + let pos = stridx(res, "\n\n") + let res = strpart(res, pos+2) + endif + endwhile + endif + let pos = stridx(res, "\r\n\r\n") + if pos != -1 + let content = strpart(res, pos+4) + else + let pos = stridx(res, "\n\n") + let content = strpart(res, pos+2) + endif + let header = split(res[:pos-1], '\r\?\n') + let matched = matchlist(get(header, 0), '^HTTP/\%(1\.[01]\|2\%(\.0\)\?\)\s\+\(\d\+\)\s*\(.*\)') + if !empty(matched) + let [status, message] = matched[1 : 2] + call remove(header, 0) + else + if v:shell_error || len(matched) + let [status, message] = ['500', "Couldn't connect to host"] + else + let [status, message] = ['200', 'OK'] + endif + endif + return { + \ 'status' : status, + \ 'message' : message, + \ 'header' : header, + \ 'content' : content + \} +endfunction + +function! s:self.stream(req) abort + let postdata = get(a:req, 'data', '') + let method = get(a:req, 'method', postdata ==# '' ? 'GET': 'POST') + let headdata = get(a:req, 'header', {}) + let follow = get(a:req, 'follow', 1) + let url = get(a:req, 'url', '') + let mode = get(a:req, 'mode', 'nl') + if type(postdata) == 4 + let postdatastr = self.encodeURI(postdata) + else + let postdatastr = postdata + endif + if empty(postdatastr) + let file = '' + else + let file = tempname() + endif + if executable('curl') + let command = printf('curl -q %s -s -k -X %s', (follow ? '-L' : ''), len(method) ? method : 'POST') + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' -H ' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' -H ' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' '.quote . url . quote + if file ==# '' + let job = job_start(command) + else + call writefile(split(postdatastr, "\n"), file, 'b') + let job = job_start(command . ' --data-binary @' . quote.file.quote) + call delete(file) + endif + elseif executable('wget') + let command = printf('wget -O- -q %s', follow ? '-L' : '') + let headdata['X-HTTP-Method-Override'] = method + let quote = &shellxquote ==# '"' ? "'" : '"' + for key in keys(headdata) + if has('win32') + let command .= ' --header=' . quote . key . ': ' . substitute(headdata[key], '"', '"""', 'g') . quote + else + let command .= ' --header=' . quote . key . ': ' . headdata[key] . quote + endif + endfor + let command .= ' '.quote.url.quote + if file ==# '' + let job = job_start(command) + else + call writefile(split(postdatastr, "\n"), file, 'b') + let job = job_start(command . ' --post-data @' . quote.file.quote) + call delete(file) + endif + else + throw 'require `curl` or `wget` command' + endif + call job_setoptions(job, + \{ + \ 'exit_cb': function('webapi#http#exit_cb', [a:req]), + \ 'stoponexit': 'kill', + \}) + let a:req['job'] = job + + let channel = job_getchannel(job) + call ch_setoptions(channel, + \{ + \ 'out_cb': function('webapi#http#out_cb', [a:req]), + \ 'mode': mode, + \}) + let a:req['channel'] = channel + let a:req['file'] = file +endfunction + +" @vimlint(EVL103, 1, a:job) +function! s:self.exit_cb(req, job, code) abort + let file = get(a:req, 'file') + if file !=# '' + call delete(file) + endif + let fexit_cb = get(a:req, 'exit_cb', v:none) + if fexit_cb != v:none + call call(fexit_cb, [a:code]) + endif +endfunction +" @vimlint(EVL103, 0, a:job) + +" @vimlint(EVL103, 1, a:ch) +function! s:self.out_cb(req, ch, data) abort + let fout_cb = get(a:req, 'out_cb', v:none) + if fout_cb != v:none + call Fout_cb(a:data) + call call(fout_cb, [a:data]) + endif +endfunction +" @vimlint(EVL103, 0, a:ch) + +function! SpaceVim#api#web#http#get() abort + return deepcopy(s:self) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et: diff --git a/autoload/SpaceVim/api/web/xml.vim b/autoload/SpaceVim/api/web/xml.vim new file mode 100644 index 000000000..b6317ffdf --- /dev/null +++ b/autoload/SpaceVim/api/web/xml.vim @@ -0,0 +1,327 @@ +let s:save_cpo = &cpo +set cpo&vim + +let s:self = {} +let s:HTTP = SpaceVim#api#import('web#http') + +let s:template = { 'name': '', 'attr': {}, 'child': [] } + +function! s:nr2byte(nr) abort + if a:nr < 0x80 + return nr2char(a:nr) + elseif a:nr < 0x800 + return nr2char(a:nr/64+192).nr2char(a:nr%64+128) + else + return nr2char(a:nr/4096%16+224).nr2char(a:nr/64%64+128).nr2char(a:nr%64+128) + endif +endfunction + +function! s:nr2enc_char(charcode) abort + if &encoding == 'utf-8' + return nr2char(a:charcode) + endif + let char = s:nr2byte(a:charcode) + if strlen(char) > 1 + let char = strtrans(iconv(char, 'utf-8', &encoding)) + endif + return char +endfunction + +function! s:nr2hex(nr) abort + let n = a:nr + let r = "" + while n + let r = '0123456789ABCDEF'[n % 16] . r + let n = n / 16 + endwhile + return r +endfunction + +function! s:decodeEntityReference(str, ...) abort + let str = a:str + let str = substitute(str, '>', '>', 'g') + let str = substitute(str, '<', '<', 'g') + if get(g:, 'webapi#xml#decodeAsHTML', 0) + let str = substitute(str, '"', '"', 'g') + let str = substitute(str, ''', "'", 'g') + let str = substitute(str, ' ', ' ', 'g') + let str = substitute(str, '¥', '\¥', 'g') + endif + let str = substitute(str, '&#x\([0-9a-fA-F]\+\);', '\=s:nr2enc_char("0x".submatch(1))', 'g') + let str = substitute(str, '&#\(\d\+\);', '\=s:nr2enc_char(submatch(1))', 'g') + let str = substitute(str, '&', '\&', 'g') + return str +endfunction + +function! s:encodeEntityReference(str) abort + let str = a:str + let str = substitute(str, '&', '\&', 'g') + let str = substitute(str, '>', '\>', 'g') + let str = substitute(str, '<', '\<', 'g') + let str = substitute(str, '"', '\"', 'g') + "let str = substitute(str, "\n", '\ ', 'g') + "let str = substitute(str, '"', '"', 'g') + "let str = substitute(str, "'", ''', 'g') + "let str = substitute(str, ' ', ' ', 'g') + return str +endfunction + +function! s:matchNode(node, cond) abort + if type(a:cond) == 1 && a:node.name == a:cond + return 1 + endif + if type(a:cond) == 2 + return a:cond(a:node) + endif + if type(a:cond) == 3 + let ret = 1 + for l:R in a:cond + if !s:matchNode(a:node, l:R) | let ret = 0 | endif + unlet l:R + endfor + return ret + endif + if type(a:cond) == 4 + for k in keys(a:cond) + if has_key(a:node.attr, k) && a:node.attr[k] == a:cond[k] | return 1 | endif + endfor + endif + return 0 +endfunction + +function! s:template.childNode(...) dict abort + for c in self.child + if type(c) == 4 && s:matchNode(c, a:000) + return c + endif + unlet c + endfor + return {} +endfunction + +function! s:template.childNodes(...) dict abort + let ret = [] + for c in self.child + if type(c) == 4 && s:matchNode(c, a:000) + let ret += [c] + endif + unlet c + endfor + return ret +endfunction + +function! s:template.value(...) dict abort + if a:0 + let self.child = a:000 + return + endif + let ret = '' + for c in self.child + if type(c) <= 1 || type(c) == 5 + let ret .= c + elseif type(c) == 4 + let ret .= c.value() + endif + unlet c + endfor + return ret +endfunction + +function! s:template.find(...) dict abort + for c in self.child + if type(c) == 4 + if s:matchNode(c, a:000) + return c + endif + unlet! ret + let ret = c.find(a:000) + if !empty(ret) + return ret + endif + endif + unlet c + endfor + return {} +endfunction + +function! s:template.findAll(...) dict abort + let ret = [] + for c in self.child + if type(c) == 4 + if s:matchNode(c, a:000) + call add(ret, c) + endif + let ret += c.findAll(a:000) + endif + unlet c + endfor + return ret +endfunction + +function! s:template.toString() dict abort + let xml = '<' . self.name + for attr in keys(self.attr) + let xml .= ' ' . attr . '="' . s:encodeEntityReference(self.attr[attr]) . '"' + endfor + if len(self.child) + let xml .= '>' + for c in self.child + if type(c) == 4 + let xml .= c.toString() + elseif type(c) > 1 + let xml .= s:encodeEntityReference(string(c)) + else + let xml .= s:encodeEntityReference(c) + endif + unlet c + endfor + let xml .= '' + else + let xml .= ' />' + endif + return xml +endfunction + +function! webapi#xml#createElement(name) abort + let node = deepcopy(s:template) + let node.name = a:name + return node +endfunction + +function! s:parse_tree(ctx, top) abort + let node = a:top + let stack = [a:top] + let pos = 0 + " content accumulates the text only tags + let content = "" + let append_content_to_parent = 'if len(stack) && content != "" | call add(stack[-1].child, content) | let content ="" | endif' + + let mx = '^\s*\(]\+>\)' + if a:ctx['xml'] =~ mx + let match = matchstr(a:ctx['xml'], mx) + let a:ctx['xml'] = a:ctx['xml'][stridx(a:ctx['xml'], match) + len(match):] + let mx = 'encoding\s*=\s*["'']\{0,1}\([^"'' \t]\+\|[^"'']\+\)["'']\{0,1}' + let matches = matchlist(match, mx) + if len(matches) + let encoding = matches[1] + if len(encoding) && len(a:ctx['encoding']) == 0 + let a:ctx['encoding'] = encoding + let a:ctx['xml'] = iconv(a:ctx['xml'], encoding, &encoding) + endif + endif + endif + + " this regex matches + " 1) the remaining until the next tag begins + " 2) maybe closing "/" of tag name + " 3) tagname + " 4) the attributes of the text (optional) + " 5) maybe closing "/" (end of tag name) + " or + " 6) CDATA or '' + " 7) text content of CDATA + " 8) the remaining text after the tag (rest) + " (These numbers correspond to the indexes in matched list m) + let tag_mx = '^\(\_.\{-}\)\%(\%(<\(/\?\)\([^!/>[:space:]]\+\)\(\%([[:space:]]*[^/>=[:space:]]\+[[:space:]]*=[[:space:]]*\%([^"'' >\t]\+\|"[^"]*"\|''[^'']*''\)\|[[:space:]]\+[^/>=[:space:]]\+[[:space:]]*\)*\)[[:space:]]*\(/\?\)>\)\|\%(\)\|\(\)\)' + + while len(a:ctx['xml']) > 0 + let m = matchlist(a:ctx.xml, tag_mx) + if empty(m) | break | endif + let a:ctx.xml = a:ctx.xml[len(m[0]) :] + let is_end_tag = m[2] == '/' && m[5] == '' + let is_start_and_end_tag = m[2] == '' && m[5] == '/' + let tag_name = m[3] + let attrs = m[4] + + if len(m[1]) + let content .= s:decodeEntityReference(m[1]) + endif + + if is_end_tag + " closing tag: pop from stack and continue at upper level + exec append_content_to_parent + + if len(stack) " TODO: checking whether opened tag is exist. + call remove(stack, -1) + endif + continue + endif + + " comment tag + if m[8] != '' + continue + endif + + " if element is a CDATA + if m[6] != '' + let content .= m[7] + continue + endif + + let node = deepcopy(s:template) + let node.name = tag_name + let attr_mx = '\([^=[:space:]]\+\)\s*\%(=\s*''\([^'']*\)''\|=\s*"\([^"]*\)"\|=\s*\(\w\+\)\|\)' + while len(attrs) > 0 + let attr_match = matchlist(attrs, attr_mx) + if len(attr_match) == 0 + break + endif + let name = attr_match[1] + let value = len(attr_match[2]) ? attr_match[2] : len(attr_match[3]) ? attr_match[3] : len(attr_match[4]) ? attr_match[4] : "" + if value == "" + let value = name + endif + let node.attr[name] = s:decodeEntityReference(value) + let attrs = attrs[stridx(attrs, attr_match[0]) + len(attr_match[0]):] + endwhile + + exec append_content_to_parent + + if len(stack) + call add(stack[-1].child, node) + endif + if !is_start_and_end_tag + " opening tag, continue parsing its contents + call add(stack, node) + endif + endwhile +endfunction + + +function! s:self.parse(xml) abort + let top = deepcopy(s:template) + let oldmaxmempattern=&maxmempattern + let oldmaxfuncdepth=&maxfuncdepth + let &maxmempattern=2000000 + let &maxfuncdepth=2000 + "try + call s:parse_tree({'xml': a:xml, 'encoding': ''}, top) + for node in top.child + if type(node) == 4 + return node + endif + unlet node + endfor + "catch /.*/ + "endtry + let &maxmempattern=oldmaxmempattern + let &maxfuncdepth=oldmaxfuncdepth + throw "Parse Error" +endfunction + +function! s:self.parseFile(file) abort + return self.parse(join(readfile(a:file), "\n")) +endfunction + +function! s:self.parseURL(url) abort + return self.parse(s:HTTP.get(a:url).content) +endfunction + +function! SpaceVim#api#web#xml#get() + return deepcopy(s:self) +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim:set et sw=2 cc=80: From e5f6b527b4123afdb702a7efa38374f259483e2a Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sat, 15 Jul 2017 05:24:39 +0800 Subject: [PATCH 58/63] Fix unknown option name: termguicolors close #725 --- autoload/SpaceVim/api/vim/highlight.vim | 2 +- autoload/SpaceVim/layers/ui.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/api/vim/highlight.vim b/autoload/SpaceVim/api/vim/highlight.vim index 036340409..af094a960 100644 --- a/autoload/SpaceVim/api/vim/highlight.vim +++ b/autoload/SpaceVim/api/vim/highlight.vim @@ -77,7 +77,7 @@ function! s:self.hide_in_normal(name) abort if empty(group) return endif - if &termguicolors || has('gui_running') + if (exists('+termguicolors') && &termguicolors ) || has('gui_running') let bg = self.group2dict('Normal').guibg if empty(bg) return diff --git a/autoload/SpaceVim/layers/ui.vim b/autoload/SpaceVim/layers/ui.vim index c319221ee..7e872d871 100644 --- a/autoload/SpaceVim/layers/ui.vim +++ b/autoload/SpaceVim/layers/ui.vim @@ -169,7 +169,7 @@ function! s:toggle_end_of_buffer() abort endif let s:ebflag = 1 else - if &termguicolors || has('gui_running') + if (exists('+termguicolors') && &termguicolors) || has('gui_running') let normalbg = s:HI.group2dict('Normal').guibg else let normalbg = s:HI.group2dict('Normal').ctermbg From a761d83935c73302c389e6f4423465587abccf57 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 16 Jul 2017 04:28:01 +0800 Subject: [PATCH 59/63] Add test for web api --- test/api/web/http.vader | 4 ++++ test/test.sh | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 test/api/web/http.vader create mode 100755 test/test.sh diff --git a/test/api/web/http.vader b/test/api/web/http.vader new file mode 100644 index 000000000..1c62a1f67 --- /dev/null +++ b/test/api/web/http.vader @@ -0,0 +1,4 @@ +Execute (Test web#http api): + let g:test_api_web_http = SpaceVim#api#import('web#http') + let g:test_api_web_http_getresult = g:test_api_web_http.get('spacevim.org') + AssertEqual g:test_api_web_http_getresult.status, '200' diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 000000000..fe81b8074 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,4 @@ +if [ ! -e /tmp/vader ]; then + git clone https://github.com/junegunn/vader.vim.git /tmp/vader +fi +vim -Nu test/test.vim -c 'Vader! test/**' From dc987e3bcd1ef0f0fb395d2833323f660d8035d2 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 16 Jul 2017 04:50:47 +0800 Subject: [PATCH 60/63] Add test for web html api --- autoload/SpaceVim/api/web/xml.vim | 2 +- test/api/web/html.vader | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/api/web/html.vader diff --git a/autoload/SpaceVim/api/web/xml.vim b/autoload/SpaceVim/api/web/xml.vim index b6317ffdf..64b528ba3 100644 --- a/autoload/SpaceVim/api/web/xml.vim +++ b/autoload/SpaceVim/api/web/xml.vim @@ -182,7 +182,7 @@ function! s:template.toString() dict abort return xml endfunction -function! webapi#xml#createElement(name) abort +function! s:self.createElement(name) abort let node = deepcopy(s:template) let node.name = a:name return node diff --git a/test/api/web/html.vader b/test/api/web/html.vader new file mode 100644 index 000000000..d174c41e0 --- /dev/null +++ b/test/api/web/html.vader @@ -0,0 +1,4 @@ +Execute (Test web#http api): + let g:test_api_web_html = SpaceVim#api#import('web#html') + let g:test_api_web_html_paser = g:test_api_web_html.parseURL('spacevim.org') + AssertEqual g:test_api_web_html_paser.child[1].child[21].child[0], 'Home - SpaceVim' From ac253dae23fa1904d9a636ad1def2cb50d7c3208 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 16 Jul 2017 05:16:50 +0800 Subject: [PATCH 61/63] Fix lint --- autoload/SpaceVim/api/web/xml.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/autoload/SpaceVim/api/web/xml.vim b/autoload/SpaceVim/api/web/xml.vim index 64b528ba3..eee5e5926 100644 --- a/autoload/SpaceVim/api/web/xml.vim +++ b/autoload/SpaceVim/api/web/xml.vim @@ -191,9 +191,8 @@ endfunction function! s:parse_tree(ctx, top) abort let node = a:top let stack = [a:top] - let pos = 0 " content accumulates the text only tags - let content = "" + exe 'let content = ""' let append_content_to_parent = 'if len(stack) && content != "" | call add(stack[-1].child, content) | let content ="" | endif' let mx = '^\s*\(]\+>\)' From 19e1e1d9f75c98ddf4e9d9ece02d43e950ea7b2a Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 16 Jul 2017 05:22:13 +0800 Subject: [PATCH 62/63] fixup --- autoload/SpaceVim/api/web/xml.vim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/api/web/xml.vim b/autoload/SpaceVim/api/web/xml.vim index eee5e5926..85b02900f 100644 --- a/autoload/SpaceVim/api/web/xml.vim +++ b/autoload/SpaceVim/api/web/xml.vim @@ -192,7 +192,8 @@ function! s:parse_tree(ctx, top) abort let node = a:top let stack = [a:top] " content accumulates the text only tags - exe 'let content = ""' + " @vimlint(EVL102, 1, l:content) + let content = "" let append_content_to_parent = 'if len(stack) && content != "" | call add(stack[-1].child, content) | let content ="" | endif' let mx = '^\s*\(]\+>\)' @@ -284,6 +285,7 @@ function! s:parse_tree(ctx, top) abort call add(stack, node) endif endwhile + " @vimlint(EVL102, 0, l:content) endfunction From 2e7c81f5d11b4529cc4ee9c87dc485efaba8369c Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 16 Jul 2017 05:31:36 +0800 Subject: [PATCH 63/63] Fix lint --- autoload/SpaceVim/api/web/xml.vim | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/autoload/SpaceVim/api/web/xml.vim b/autoload/SpaceVim/api/web/xml.vim index 85b02900f..aa59fb853 100644 --- a/autoload/SpaceVim/api/web/xml.vim +++ b/autoload/SpaceVim/api/web/xml.vim @@ -17,7 +17,7 @@ function! s:nr2byte(nr) abort endfunction function! s:nr2enc_char(charcode) abort - if &encoding == 'utf-8' + if &encoding ==# 'utf-8' return nr2char(a:charcode) endif let char = s:nr2byte(a:charcode) @@ -29,7 +29,7 @@ endfunction function! s:nr2hex(nr) abort let n = a:nr - let r = "" + let r = '' while n let r = '0123456789ABCDEF'[n % 16] . r let n = n / 16 @@ -188,12 +188,12 @@ function! s:self.createElement(name) abort return node endfunction +" @vimlint(EVL102, 1, l:content) function! s:parse_tree(ctx, top) abort let node = a:top let stack = [a:top] " content accumulates the text only tags - " @vimlint(EVL102, 1, l:content) - let content = "" + let content = '' let append_content_to_parent = 'if len(stack) && content != "" | call add(stack[-1].child, content) | let content ="" | endif' let mx = '^\s*\(]\+>\)' @@ -228,8 +228,8 @@ function! s:parse_tree(ctx, top) abort let m = matchlist(a:ctx.xml, tag_mx) if empty(m) | break | endif let a:ctx.xml = a:ctx.xml[len(m[0]) :] - let is_end_tag = m[2] == '/' && m[5] == '' - let is_start_and_end_tag = m[2] == '' && m[5] == '/' + let is_end_tag = m[2] ==# '/' && m[5] ==# '' + let is_start_and_end_tag = m[2] ==# '' && m[5] ==# '/' let tag_name = m[3] let attrs = m[4] @@ -248,12 +248,12 @@ function! s:parse_tree(ctx, top) abort endif " comment tag - if m[8] != '' + if m[8] !=# '' continue endif " if element is a CDATA - if m[6] != '' + if m[6] !=# '' let content .= m[7] continue endif @@ -267,8 +267,8 @@ function! s:parse_tree(ctx, top) abort break endif let name = attr_match[1] - let value = len(attr_match[2]) ? attr_match[2] : len(attr_match[3]) ? attr_match[3] : len(attr_match[4]) ? attr_match[4] : "" - if value == "" + let value = len(attr_match[2]) ? attr_match[2] : len(attr_match[3]) ? attr_match[3] : len(attr_match[4]) ? attr_match[4] : '' + if value ==# '' let value = name endif let node.attr[name] = s:decodeEntityReference(value) @@ -285,8 +285,8 @@ function! s:parse_tree(ctx, top) abort call add(stack, node) endif endwhile - " @vimlint(EVL102, 0, l:content) endfunction +" @vimlint(EVL102, 0, l:content) function! s:self.parse(xml) abort @@ -307,7 +307,7 @@ function! s:self.parse(xml) abort "endtry let &maxmempattern=oldmaxmempattern let &maxfuncdepth=oldmaxfuncdepth - throw "Parse Error" + throw 'Parse Error' endfunction function! s:self.parseFile(file) abort @@ -318,7 +318,7 @@ function! s:self.parseURL(url) abort return self.parse(s:HTTP.get(a:url).content) endfunction -function! SpaceVim#api#web#xml#get() +function! SpaceVim#api#web#xml#get() abort return deepcopy(s:self) endfunction