Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
refactor, close #25
Browse files Browse the repository at this point in the history
* remove cmdline input, use coc_todolist split window only

* remove useless notification methods, use coc buildin notification

* use eslintrc.js instead of tslint.json

* remap j,k,gg,G,etc. in coc_todolist edit window

* use events.ts to add BufWriteCmd
  • Loading branch information
voldikss committed Dec 30, 2020
1 parent 7649e47 commit c1bfd84
Show file tree
Hide file tree
Showing 22 changed files with 443 additions and 681 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/events.ts
17 changes: 17 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
env: {
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
}
83 changes: 22 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coc-todolist

Todolist/task manager extension for [coc.nvim](https://github.com/neoclide/coc.nvim)
Todolist manager extension for [coc.nvim](https://github.com/neoclide/coc.nvim)

![](https://user-images.githubusercontent.com/20282795/61593014-d1be3780-ac0c-11e9-96cc-e3b787a27f46.png)

Expand All @@ -13,72 +13,21 @@ Todolist/task manager extension for [coc.nvim](https://github.com/neoclide/coc.n
## Features

- Allow to set a reminder for a todo item
- Auto sync your todolist with gist(require github token: [click here to generate](https://github.com/settings/tokens/new?scopes=gist&description=coc-todolist%20gist))
- Manage your todolist using CocList
- Auto upload/download todolists with gist(require github token: [click to generate](https://github.com/settings/tokens/new?scopes=gist&description=coc-todolist%20gist))
- Manage your todolist with CocList

## Configuration

```jsonc
"todolist.enable": {
"type": "boolean",
"default": true,
"description": "whether enable this extension"
},
"todolist.maxsize": {
"type": "number",
"default": 5000,
"description": "maxsize of todolist"
},
"todolist.dateFormat": {
"type": "string",
"default": "YYYY-MM-DD HH:mm",
"description": "dates format"
},
"todolist.autoUpload": {
"type": "boolean",
"default": false,
"description": "upload your todolist every day"
},
"todolist.monitor": {
"type": "boolean",
"default": false,
"description": "monitor the todolist and remind you at the time"
},
"todolist.promptForReminder": {
"type": "boolean",
"default": true,
"description": "whether to ask users to set a reminder for every new todo item"
},
"todolist.easyMode": {
"type": "boolean",
"default": false,
"description": "Open a todo edit window when create/edit a todo item"
},
"todolist.floatwin.background": {
"type": "string",
"default": "",
"description": "notification floating window background(e.g. #000000)"
},
"todolist.floatwin.winblend": {
"type": "number",
"default": 0,
"description": "opacity of notification floating window"
},
"todolist.floatwin.width": {
"type": "number",
"default": 30,
"description": "width of notification floating window"
},
"todolist.notify": {
"type": "string",
"default": "floating",
"description": "how to notify you",
"enum": [
"floating",
"virtual",
"echo",
"none"
]
}
```

Expand All @@ -88,7 +37,6 @@ Todolist/task manager extension for [coc.nvim](https://github.com/neoclide/coc.n
- `:CocCommand todolist.upload`: upload todolist to gist
- `:CocCommand todolist.download`: download todolist from gist
- `:CocCommand todolist.export`: export todolist as a json/yaml file
- `:CocCommand todolist.closeNotice`: close notifications
- `:CocCommand todolist.clear`: clear all todos
- `:CocCommand todolist.browserOpenGist`: open todolist gist in [gist.github.com](https://gist.github.com/)

Expand All @@ -106,13 +54,26 @@ run `:CocList todolist` to open the todolist

Q: Where is the todolist data stored?

A: Normally the data is saved in `~/.config/coc/extensions/coc-todolist-data/`, but if you set `g:coc_extension_root` to another location, it will change as well
A: Normally the data is saved in `~/.config/coc/extensions/coc-todolist-data/`,
but if you set `g:coc_extension_root` to another location, it will change as
well

## License
Q: coc-todolist is not loaded after upgrading

MIT
A: Remove `todolist.json`(normally
`~/.config/coc/extensions/coc-todolist-data/todolist.json`). Don't forget to
backup it if necessary.

## More Demos
Q: I want to create a persistent todolist item

![](https://user-images.githubusercontent.com/20282795/84150252-2d4b1b00-aa94-11ea-8701-b0be44f5d507.png)
![](https://user-images.githubusercontent.com/20282795/61623340-08499000-aca9-11e9-9be1-e6d951b075c2.gif)
A: Leave `due` value empty or let `due` be the same as `date` value(default)

## TODO

- sync
- Log
- UI

## License

MIT
15 changes: 15 additions & 0 deletions autoload/coc_todolist.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
" ============================================================================
" FileName: coc_todolist.vim
" Author: voldikss <[email protected]>
" GitHub: https://github.com/voldikss
" ============================================================================

" https://stackoverflow.com/a/26318602/8554147
function! coc_todolist#get_buf_info() abort
let save_virtualedit = &virtualedit
set virtualedit=all
norm! g$
let width = virtcol('.')
let &virtualedit = save_virtualedit
return [bufnr('%'), width]
endfunction
59 changes: 59 additions & 0 deletions ftplugin/coc_todolist.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
" ============================================================================
" FileName: coc_todolist.vim
" Author: voldikss <[email protected]>
" GitHub: https://github.com/voldikss
" ============================================================================

let s:pattern = '─\w\+─'

function! s:map_down() abort
if search(s:pattern, 'W') != 0
normal! j
normal! 0
endif
call s:rematch()
endfunction

function! s:map_up() abort
call search(s:pattern, 'bW')
call search(s:pattern, 'bW')
normal! j
normal! 0
call s:rematch()
endfunction

function! s:map_gg() abort
normal! gg
call search(s:pattern, 'W')
normal! j
normal! 0
call s:rematch()
endfunction

function! s:map_G() abort
normal! G
call search(s:pattern, 'bW')
normal! j
normal! 0
call s:rematch()
endfunction

function! s:rematch() abort
call clearmatches()
let toplnum = line('.')
let botlnum = search(s:pattern, 'nW')
if botlnum == 0
let botlnum = line('$')
else
let botlnum -= 1
endif
let pattern = join(map(range(toplnum, botlnum), { k,v -> '\%' . v . 'l.*' }), '\|')
call matchadd('CocTodolistSelect', pattern)
endfunction

nmap <buffer><silent> j :<C-u>call <SID>map_down()<CR>
nmap <buffer><silent> k :<C-u>call <SID>map_up()<CR>
nmap <buffer><silent> <down> :<C-u>call <SID>map_down()<CR>
nmap <buffer><silent> <up> :<C-u>call <SID>map_up()<CR>
nmap <buffer><silent> gg :<C-u>call <SID>map_gg()<CR>
nmap <buffer><silent> G :<C-u>call <SID>map_G()<CR>
85 changes: 17 additions & 68 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
"todolist"
],
"engines": {
"coc": "^0.0.74"
"coc": "^0.0.80"
},
"scripts": {
"clean": "rimraf lib",
"watch": "webpack --watch",
"build": "webpack"
"build": "webpack",
"prepare": "npx npm-run-all clean build"
},
"activationEvents": [
"*"
Expand All @@ -27,66 +28,15 @@
"configuration": {
"type": "object",
"properties": {
"todolist.enable": {
"type": "boolean",
"default": true,
"description": "whether enable this extension"
},
"todolist.maxsize": {
"type": "number",
"default": 5000,
"description": "maxsize of todolist"
},
"todolist.dateFormat": {
"type": "string",
"default": "YYYY-MM-DD HH:mm",
"description": "dates format"
},
"todolist.autoUpload": {
"type": "boolean",
"default": false,
"description": "upload your todolist every day"
},
"todolist.monitor": {
"type": "boolean",
"default": false,
"description": "monitor the todolist and remind you at the time"
},
"todolist.promptForReminder": {
"type": "boolean",
"default": true,
"description": "whether to ask users to set a reminder for every new todo item"
},
"todolist.easyMode": {
"type": "boolean",
"default": false,
"description": "Open a todo edit window when create/edit a todo item"
},
"todolist.floatwin.background": {
"type": "string",
"default": "",
"description": "notification floating window background(e.g. #000000)"
},
"todolist.floatwin.winblend": {
"type": "number",
"default": 0,
"description": "opacity of notification floating window"
},
"todolist.floatwin.width": {
"type": "number",
"default": 30,
"description": "width of notification floating window"
},
"todolist.notify": {
"type": "string",
"default": "floating",
"description": "how to notify you",
"enum": [
"floating",
"virtual",
"echo",
"none"
]
}
}
},
Expand All @@ -107,39 +57,38 @@
"title": "export todolist as a json or yaml file",
"command": "todolist.export"
},
{
"title": "close notification",
"command": "todolist.closeNotice"
},
{
"title": "clear all todos",
"command": "todolist.clear"
},
{
"title": "clear notification",
"title": "clear open todolist gist",
"command": "todolist.browserOpenGist"
}
]
},
"author": "[email protected]",
"license": "MIT",
"devDependencies": {
"@chemzqm/neovim": "^5.2.10",
"@types/js-yaml": "^3.12.5",
"@types/node": "^14.14.10",
"@types/node": "^14.14.16",
"@types/uuid": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^4.11.1",
"@typescript-eslint/parser": "^4.11.1",
"@voldikss/tsconfig": "^1.0.0",
"@voldikss/tslint-config": "^1.0.6",
"coc.nvim": "^0.0.79",
"js-yaml": "^3.14.0",
"coc.nvim": "^0.0.80",
"eslint": "^7.16.0",
"js-yaml": "^3.14.1",
"moment": "^2.29.1",
"moment-timezone": "^0.5.32",
"path": "^0.12.7",
"request-light": "^0.4.0",
"rimraf": "^3.0.2",
"ts-loader": "^8.0.11",
"tslint": "^6.1.3",
"typescript": "^4.1.2",
"uuid": "^8.3.1",
"webpack": "^5.8.0",
"webpack-cli": "^4.2.0"
"ts-loader": "^8.0.12",
"typescript": "^4.1.3",
"uuid": "^8.3.2",
"webpack": "^5.11.1",
"webpack-cli": "^4.3.0"
}
}
22 changes: 13 additions & 9 deletions plugin/coc_todolist.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
" GitHub: https://github.com/voldikss
" ============================================================================

augroup coc_todolist
function! s:CocTodolistActionAsync(name, ...)
return call(
\ 'CocActionAsync',
\ extend(['runCommand', 'todolist.' . a:name], a:000)
\ )
endfunction

augroup CocTodolistInternal
autocmd!
autocmd BufWriteCmd __coc_todolist__ call s:Autocmd('BufWriteCmd', +expand('<abuf>'))
autocmd BufWriteCmd * call s:CocTodolistActionAsync(
\ 'internal.didVimEvent',
\ 'BufWriteCmd',
\ +expand('<abuf>')
\ )
augroup END

function! s:Autocmd(...) abort
if !get(g:,'coc_workspace_initialized', 0)
return
endif
call coc#rpc#notify('CocAutocmd', a:000)
endfunction
Loading

0 comments on commit c1bfd84

Please sign in to comment.