Skip to content

Commit 826f8c2

Browse files
frances-cofmount
frances-co
authored andcommittedAug 17, 2019
Move note cbox mappings in a separeted function
Since we need to enable the cbox mappings in different scenarios (e.g. :e *.notes), a default cbox mapping is moved in an appropriate function, so we can control the phase that occur when a *BufRead* or a *BufNewFile* event is received. This change also includes the ability to enable and disable the plugin default key mapping and it exposes a global variable to meet the requirements. We also changed the default keybindings to add cbox(es) to something more specific, providing an example section in the README file. In order to have a minimum amount of acceptance tests, this commit adds the cbox checklist that must pass to allow a PR to get merged. We improved our automation on PR events adding mergify with the following rules: 1. Test passed (travis) 2. Approvers >=2 Signed-off-by: fmount <[email protected]>
1 parent 6a2f491 commit 826f8c2

10 files changed

+248
-31
lines changed
 

‎.mergify.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
pull_request_rules:
2+
- name: automatic merge
3+
conditions:
4+
- label!=DNM
5+
- '#approved-reviews-by>=1'
6+
- 'status-success=Testing: Travis CI - Pull Request'
7+
actions:
8+
merge:
9+
method: rebase
10+
rebase_fallback: merge
11+
strict: smart
12+
dismiss_reviews: {}
13+
delete_head_branch: {}
14+
- name: automatic merge on skip ci
15+
conditions:
16+
- label!=DNM
17+
- title~=\[skip ci\]
18+
- '#approved-reviews-by>=2'
19+
actions:
20+
merge:
21+
method: rebase
22+
rebase_fallback: merge
23+
strict: smart
24+
dismiss_reviews: {}
25+
delete_head_branch: {}

‎contrib.markdown ‎CONTRIB.md

File renamed without changes.

‎README.md

+45-11
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,67 @@ Vim-Notes
44
_Yet another note plugin for VIM_
55

66
_Working in progress..._
7-
________
7+
______
88
Commands
99
---
1010
| Command | Description |
1111
|---|---|
1212
|**:Note**&nbsp;_filename_ | This command creates a new Note buffer. This is saved in a new file inside the folder g:notes_folder (set to ~/.notes by default). If no extension is specified the new file will be created with '.note' and it will be processed in the editor using the _markdown_ syntax highlighting. |
1313
|**:NoteList** | Shows all the notes available inside the folder g:notes_folder |
14-
|**:NoteDelete**&nbsp;_filename_ </code>| Delete a note |
14+
|**:NoteDelete**&nbsp;_filename_| Delete a note |
1515
|**:NoteAutoSaveToggle** | Activate/Deactivate automatic save for the current _.note_ buffer |
1616

1717
______
1818
Parameters
1919
---
2020
| Parameter | Default Value | Description |
21-
|-----------|---------------|-------------|
21+
|-----------|:-------------:|-------------|
2222
|g:notes_folder| ~/.notes | Folder containing the notes |
2323
|g:notes_autosave| 0 | Enable/Disable the autosave of the notes |
2424
|g:notes_autosave_time| 30 | Defines the minimum interval between 2 successive automatic saves |
25-
________
25+
|g:notes_compiler| markdown | Defines the compiler for note files |
26+
|g:notes_export_folder| ~/.notes/md2html | Folder containing the exported notes |
27+
|g:default_keymap| 1 | Load the default plugin keymap |
28+
29+
30+
______
2631

2732

28-
ToDo
33+
Editing key mapping
2934
---
30-
- Autosave
31-
- Proper README
32-
- Fast CheckBox
33-
- Scratch notes
34-
- Fast Export
35-
- Synchronization
35+
|Combination | Modes | Name function | Description |
36+
|------------| :-----: | :-----------: | ----------- |
37+
|&lt;_leader_&gt;&nbsp;+&nbsp;[i| I / N | note-new-cbox-inline | Create a new checkbox inline |
38+
|&lt;_leader_&gt;&nbsp;+&nbsp;[o| I / N | note-new-cbox-below | Create a new checkbox in the line below the current one|
39+
|&lt;_leader_&gt;&nbsp;+&nbsp;[O| I / N | note-new-cbox-above | Create a new checkbox in the line above the current one|
40+
|&lt;_leader_&gt;&nbsp;+&nbsp;[x| N | notes#toggle_checkbox | Toggle the state of the checkbox between done and undone ([x]/[ ])|
41+
42+
______
43+
44+
45+
Fast Export key mapping
46+
---
47+
|Combination | Modes | Name function | Description |
48+
|------------| :-----: | :-----------: | ----------- |
49+
|&lt;_leader_&gt;&nbsp;+&nbsp;[e| N | notes#export | Export the current note buffer in a specified folder|
50+
51+
52+
Key mapping override
53+
---
54+
The plugin sets by default all the described key mappings, but this can be easily disabled.
55+
For instance, if you want your set of customized keybindings, you can just edit the vimrc as follows:
56+
57+
"Disable the default key mapping
58+
let g:default_keymap = 0
3659

60+
"Apply your own key mapping
61+
nmap <Leader>ni (note-new-cbox-inline)
62+
nmap <Leader>ni (note-new-cbox-inline)
63+
imap <Leader>ni (note-new-cbox-inline)
64+
nmap <Leader>no (note-new-cbox-below)
65+
imap <Leader>no (note-new-cbox-below)
66+
nmap <Leader>nO (note-new-cbox-above)
67+
imap <Leader>nO (note-new-cbox-above)
68+
nmap <Leader>nx :call notes#toggle_checkbox(line('.'))<cr>
69+
" Fast Export function
70+
nmap <leader>ne :call notes#export() <cr>

‎Rakefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ RSpec::Core::RakeTask.new(:spec) do |t|
44
t.pattern = 'spec/vim_notes_spec.rb'
55
end
66

7-
task :default => :spec
7+
RSpec::Core::RakeTask.new(:cbox) do |t|
8+
t.pattern = 'spec/fast_export_spec.rb'
9+
end
810

11+
task :default => :spec
912

‎TODO

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
TODO
2+
---
3+
4+
~ Autosave ~
5+
- Proper README ~
6+
- Fast CheckBox ~
7+
- Fast Export ~
8+
- Scratch notes
9+
- Synchronization

‎autoload/notes.vim

+54-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
1+
" notes.vim - A vim plugin to take notes easily
2+
" Mantainers: fmount,saro
3+
" Version: 1.0
4+
" AutoInstall: notes.vim
5+
" ====== Enjoy ======
16

7+
" Print the current version
28
function notes#version()
3-
echom "version " . g:notes_version
9+
echom "version " . g:notes_version
410
endfunction
511

12+
" This function is called when a buffer is created
13+
" or opened and pushes some default keybindings for
14+
" the plugin.
15+
" Set 'g:default_keymap = 0' to turn off the default
16+
" keybindings
17+
function notes#defaultkeymap()
18+
" Add checkbox creating/marking key maps
19+
nmap <buffer> <Leader>[i (note-new-cbox-inline)
20+
imap <buffer> <Leader>[i (note-new-cbox-inline)
21+
nmap <buffer> <Leader>[o (note-new-cbox-below)
22+
imap <buffer> <Leader>[o (note-new-cbox-below)
23+
nmap <buffer> <Leader>[O (note-new-cbox-above)
24+
imap <buffer> <Leader>[O (note-new-cbox-above)
25+
nmap <buffer> <Leader>[x :call notes#toggle_checkbox(line('.'))<cr>
26+
" Fast Export function
27+
nmap <leader>[e :call notes#export() <cr>
28+
endfunction
629

30+
" Create a new note or open an existing one
731
function notes#edit(filename)
832
let l:dir = expand(g:notes_folder)
933
let l:tmpfilename = a:filename
@@ -47,7 +71,6 @@ endfunction
4771
function notes#delete(...)
4872
if(exists('a:1'))
4973
let note = a:1
50-
5174
"Check for the working directory
5275
if(expand(g:notes_folder) != fnamemodify(expand(note, '/'), ':h'))
5376
echomsg "Working directory doesn't match"
@@ -71,20 +94,19 @@ function notes#delete(...)
7194
echo "Failed to delete " . note
7295
echohl None
7396
endif
74-
7597
return delStatus
7698
endfunction
7799

78100

79-
" Autosave for buffered notes
101+
" Autosave for buffered notes
80102
function notes#update_buffer()
81103
"echomsg "Time elapsed: ".(localtime()-b:notes_start_time) "DEBUG TIME
82104
let l:note_time_elapsed = localtime() - b:notes_start_time
83105

84106
" check for the time elapsed, the value of the autosave variable and
85107
" the current file type (through the .note extension)
86108
if(matchstr(expand('%.t'),'\^*.note$') != "" && g:notes_autosave >= 1
87-
\&& l:note_time_elapsed >= g:notes_autosave_time)
109+
\&& l:note_time_elapsed >= g:notes_autosave_time)
88110

89111
"Try to update the buffer if modified
90112
let was_modified = &modified
@@ -94,7 +116,6 @@ function notes#update_buffer()
94116
echomsg "(AutoSaved at " . strftime("%H:%M:%S") . ")"
95117
let b:notes_start_time = localtime()
96118
endif
97-
98119
endif
99120
endfunction
100121

@@ -109,3 +130,30 @@ function notes#autosave_toggle()
109130
endif
110131
endfunction
111132

133+
" Fill or clean the checkbox where the cursor is present
134+
function notes#toggle_checkbox(linenr)
135+
if (empty(matchstr(getline(a:linenr), '^\s*\[\s\].*$')) == 0)
136+
:s/^\s*\[\s\]/\1[x]
137+
elseif (empty(matchstr(getline(a:linenr), '^\s*\[x\].*$')) == 0)
138+
:s/^\s*\[x\]/\1[ ]
139+
endif
140+
endfunction
141+
142+
" Markdown2HTML export function
143+
function notes#export()
144+
let l:dest_dir = expand(g:notes_export_folder)
145+
if executable(g:notes_compiler)
146+
" Create g:notes_export_folder if not existing
147+
if !isdirectory(l:dest_dir)
148+
call mkdir(l:dest_dir,'p')
149+
endif
150+
if(matchstr(bufname('%'),'\^*.note$') != "")
151+
echom system(g:notes_compiler . " " . bufname('%') . ">> " . g:notes_export_folder . "/" . expand('%:t:r') . '.html')
152+
else
153+
echom 'Provide a .note file'
154+
endif
155+
else
156+
echom "No " . g:notes_compiler . " found"
157+
endif
158+
echom "Note " . bufname('%') . " exported"
159+
endfunction

‎plugin/notes.vim

+36-12
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,68 @@
11
" notes.vim - A vim plugin to take notes easily
2-
" Mantainer: fmount
2+
" Mantainer: fmount, saro
33
" Version: 1.0
44
" AutoInstall: notes.vim
55
" ====== Enjoy ======
6-
"
76

8-
if exists('g:loaded_notes') || &cp
7+
"For security reasons check the vim version
8+
if v:version < 702
9+
echomsg 'notes: You need at least Vim 7.2'
910
finish
1011
endif
1112

12-
let g:loaded_notes = 0
13-
let g:notes_version = '1.0'
14-
15-
"For security reasons..
16-
"if v:version < 702
17-
" echomsg 'notes: You need at least Vim 7.2'
13+
"if exists('g:loaded_notes') || &cp
1814
" finish
1915
"endif
2016

2117
if !exists('g:notes_folder')
2218
let g:notes_folder = "~/.notes"
2319
endif
2420

25-
if !exists("g:notes_autosave")
21+
if !exists('g:notes_autosave')
2622
let g:notes_autosave = 0
2723
let g:notes_autosave_time = 10 "seconds
2824
endif
2925

26+
if !exists('g:notes_compiler')
27+
let g:notes_compiler = 'markdown'
28+
endif
29+
30+
if !exists('g:notes_export_folder')
31+
let g:notes_export_folder = '~/.notes/md2html'
32+
endif
33+
34+
if !exists('g:default_keymap')
35+
let g:default_keymap = 1
36+
endif
37+
38+
"let g:loaded_notes = 0
39+
let g:notes_version = '1.0'
40+
"let g:default_keymap = 1
41+
42+
" Create a new item
43+
nnore (note-new-cbox-inline) I[ ]<space>
44+
inore (note-new-cbox-inline) <Esc>I[ ]<space>
45+
46+
" Create a new item below
47+
nnore (note-new-cbox-below) $o[ ]<space>
48+
inore (note-new-cbox-below) <Esc>$o[ ]<space>
49+
50+
" Create a new item above
51+
nnore (note-new-cbox-above) $O[ ]<space>
52+
inore (note-new-cbox-above) <Esc>$O[ ]<space>
53+
3054
augroup bufferset
3155
autocmd!
3256
autocmd BufRead,BufNewFile *.note set filetype=markdown
57+
autocmd BufRead,BufNewFile *.note if g:default_keymap | call notes#defaultkeymap() | endif
3358
autocmd BufRead,BufNewFile *.note let b:notes_start_time=localtime()
34-
"autocmd BufRead,BufNewFile *.* syntax on
3559
"Autosave settings
3660
autocmd CursorHold,BufRead *.note call notes#update_buffer()
3761
autocmd BufWritePre *.note let b:notes_start_time = localtime()
3862
augroup END
3963

40-
4164
command! -complete=customlist,notes#navigate -nargs=1 Note call notes#edit(<f-args>)
4265
command! -complete=customlist, NoteList call notes#list()
4366
command! -complete=customlist,notes#navigate -nargs=1 NoteDelete call notes#delete(<f-args>) | bdelete!
4467
command! NoteAutoSaveToggle :call notes#autosave_toggle()
68+

‎spec/fast_export_spec.rb

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- encoding: utf-8 -*-
2+
require 'spec_helper'
3+
4+
describe "notes#cboxes" do
5+
let(:filename) { 'test.note' }
6+
specify "#create item inline" do
7+
before <<-EOF
8+
EOF
9+
vim.normal 'I[ ]'
10+
after <<-EOF
11+
[ ]
12+
EOF
13+
end
14+
specify "#create item below" do
15+
before <<-EOF
16+
[ ]
17+
EOF
18+
vim.normal 'o[ ]'
19+
after <<-EOF
20+
[ ]
21+
[ ]
22+
EOF
23+
end
24+
specify "#create item above" do
25+
before <<-EOF
26+
[ ]
27+
EOF
28+
vim.normal 'O[ ]'
29+
after <<-EOF
30+
[ ]
31+
[ ]
32+
EOF
33+
end
34+
specify "#toggle checkbox" do
35+
before <<-EOF
36+
[ ]
37+
EOF
38+
vim.command("call notes#toggle_checkbox(line('.'))")
39+
after <<-EOF
40+
[x]
41+
EOF
42+
end
43+
end
44+

‎spec/spec_helper.rb

+30
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
require 'vimrunner'
22
require 'vimrunner/rspec'
33

4+
def set_file_content(string)
5+
string = normalize_string_indent(string)
6+
File.open(filename, 'w'){ |f| f.write(string) }
7+
vim.edit filename
8+
end
9+
10+
def get_file_content()
11+
vim.write
12+
IO.read(filename).strip
13+
end
14+
15+
def before(string)
16+
set_file_content(string)
17+
end
18+
19+
def after(string)
20+
get_file_content().should eq normalize_string_indent(string)
21+
type ":q<CR>"
22+
end
23+
24+
def type(string)
25+
string.scan(/<.*?>|./).each do |key|
26+
if /<.*>/.match(key)
27+
vim.feedkeys "\\#{key}"
28+
else
29+
vim.feedkeys key
30+
end
31+
end
32+
end
33+
434
Vimrunner::RSpec.configure do |config|
535

636
# Use a single Vim instance for the test suite. Set to false to use an

‎spec/vim_notes_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
describe "notes#edit" do
55
it "returns a new Note if you open a new buffer" do
66
vim.command('call notes#edit("test")')
7-
vim.edit "test.note"
7+
#vim.edit "test.note"
88
vim.insert("This is a simple test note")
99
vim.write
1010
end

0 commit comments

Comments
 (0)
Please sign in to comment.