Browse files

Basic support for @tags (suggested by Jonathan Reeve)

  • Loading branch information...
1 parent 7a9e923 commit 677cd70569067ee718e03e68f99de0f0abc1b31a @xolox committed Jun 4, 2011
Showing with 62 additions and 11 deletions.
  1. +1 −0 README.md
  2. +25 −7 autoload/xolox/notes.vim
  3. +4 −0 doc/notes.txt
  4. +24 −0 misc/notes/shadow/Note taking commands
  5. +3 −3 plugin/notes.vim
  6. +5 −1 syntax/notes.vim
View
1 README.md
@@ -7,6 +7,7 @@ The notes.vim plug-in for the [Vim text editor] [vim] makes it easy to manage yo
* **Editing existing notes:** Execute `:Note anything` to edit a note containing `anything` in its title (if no notes are found a new one is created with its title set to `anything`)
* **Deleting notes:** The `:DeleteNote` command enables you to delete the current note
* **Searching notes:** `:SearchNotes keyword …` searches for keywords and `:SearchNotes /pattern/` searches for regular expressions
+ * **Smart defaults:** Without an argument `:SearchNotes` searches for the word under the cursor (if the word starts with `@` that character will be included in the search, this means you can easily search for *@tagged* notes)
* **Back-references:** The `:RelatedNotes` command find all notes referencing the current file
* A [Python 2] [python] script is included that accelerates keyword searches using an [SQLite] [sqlite] database
* **Navigating between notes:** The included file type plug-in redefines [gf] [gf] to jump between notes and the syntax script highlights note names as hyper links
View
32 autoload/xolox/notes.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 22, 2011
+" Last Change: June 4, 2011
" URL: http://peterodding.com/code/vim/notes/
" Note: This file is encoded in UTF-8 including a byte order mark so
@@ -169,17 +169,25 @@ function! xolox#notes#delete(bang) " {{{1
endfunction
function! xolox#notes#search(bang, input) " {{{1
- " Search all notes for the pattern or keywords {input}.
- if a:input =~ '^/.\+/$'
- call s:internal_search(a:bang, a:input, '', '')
+ " Search all notes for the pattern or keywords {input} (current word if none given).
+ let input = a:input
+ if input == ''
+ let input = s:tag_under_cursor()
+ if input == ''
+ call xolox#misc#msg#warn("No string under cursor")
+ return
+ endif
+ endif
+ if input =~ '^/.\+/$'
+ call s:internal_search(a:bang, input, '', '')
if &buftype == 'quickfix'
- let w:quickfix_title = 'Notes matching the pattern ' . a:input
+ let w:quickfix_title = 'Notes matching the pattern ' . input
endif
else
- let keywords = split(a:input)
+ let keywords = split(input)
let all_keywords = s:match_all_keywords(keywords)
let any_keyword = s:match_any_keyword(keywords)
- call s:internal_search(a:bang, all_keywords, a:input, any_keyword)
+ call s:internal_search(a:bang, all_keywords, input, any_keyword)
if &buftype == 'quickfix'
call map(keywords, '"`" . v:val . "''"')
let w:quickfix_title = printf('Notes containing the word%s %s', len(keywords) == 1 ? '' : 's',
@@ -188,6 +196,16 @@ function! xolox#notes#search(bang, input) " {{{1
endif
endfunction
+function! s:tag_under_cursor() " {{{2
+ try
+ let isk_save = &isk
+ set iskeyword+=@-@
+ return expand('<cword>')
+ finally
+ let &isk = isk_save
+ endtry
+endfunction
+
function! s:match_all_keywords(keywords) " {{{2
" Create a regex that matches when a file contains all {keywords}.
let results = copy(a:keywords)
View
4 doc/notes.txt
@@ -21,6 +21,10 @@ notes in Vim:
- Searching notes: ':SearchNotes keyword …' searches for keywords and
':SearchNotes /pattern/' searches for regular expressions
+ - Smart defaults: Without an argument ':SearchNotes' searches for the word
+ under the cursor (if the word starts with '@' that character will be
+ included in the search, this means you can easily search for @tagged notes)
+
- Back-references: The ':RelatedNotes' command find all notes referencing the
current file
View
24 misc/notes/shadow/Note taking commands
@@ -38,6 +38,30 @@ notes containing all of the given keywords:
:SearchNotes syntax highlighting
+## :SearchNotes understands @tags
+
+If you don’t pass any arguments to the :SearchNotes command it will search for
+the word under the cursor. If the word under the cursor starts with ‘@’ this
+character will be included in the search, which makes it possible to easily
+add @tags to your @notes and then search for those tags. To make searching for
+tags even easier you can create key mappings for the :SearchNotes command:
+ {{{vim
+ " Make the C-] combination search for @tags:
+ imap <C-]> <C-o>:SearchNotes<CR>
+ nmap <C-]> :SearchNotes<CR>
+
+ " Make double mouse click search for @tags. This is actually quite a lot of
+ " fun if you don’t use the mouse for text selections anyway; you can click
+ " between notes as if you’re in a web browser:
+ imap <2-LeftMouse> <C-o>:SearchNotes<CR>
+ nmap <2-LeftMouse> :SearchNotes<CR>
+ }}}
+These mappings are currently not enabled by default because they conflict with
+already useful key mappings, but if you have any suggestions for alternatives
+feel free to contact me through GitHub or at peter@peterodding.com.
+
+## Accelerated searching with Python and SQLite
+
After collecting a fair amount of notes (say >= 5 MB) you will probably start
to get annoyed at how long it takes Vim to search through all of your notes. To
make searching more scalable the notes plug-in includes a Python script which
View
6 plugin/notes.vim
@@ -1,9 +1,9 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 22, 2011
+" Last Change: June 4, 2011
" URL: http://peterodding.com/code/vim/notes/
" License: MIT
-" Version: 0.8.7
+" Version: 0.8.8
" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3375 1 :AutoInstall: notes.zip
@@ -39,7 +39,7 @@ endif
" User commands to create, delete and search notes.
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#complete Note call xolox#notes#edit(<q-bang>, <q-args>)
command! -bar -bang DeleteNote call xolox#notes#delete(<q-bang>)
-command! -bar -bang -nargs=1 SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
+command! -bar -bang -nargs=? SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
" Automatic commands to enable the :edit note:… shortcut and load the notes file type.
View
6 syntax/notes.vim
@@ -1,6 +1,6 @@
" Vim syntax script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: May 22, 2011
+" Last Change: June 4, 2011
" URL: http://peterodding.com/code/vim/notes/
" Note: This file is encoded in UTF-8 including a byte order mark so
@@ -27,6 +27,10 @@ call xolox#notes#highlight_names(1)
syntax cluster notesInline add=notesName
highlight def link notesName Underlined
+" Highlight @tags as hyperlinks. {{{2
+syntax match notesTagName /\(^\|\s\)\@<=@\w\+/
+highlight def link notesTagName Underlined
+
" Highlight list bullets and numbers. {{{2
syntax match notesListBullet /^\s*\zs\(•\|\*\)/
highlight def link notesListBullet Comment

0 comments on commit 677cd70

Please sign in to comment.