Skip to content

Commit 677a27f

Browse files
committed
First attempt* at support for notes in nested directories (issue #71)
* This might be a little rough around the edges, but it seems to work pretty well, so I currently don't see any reason not to make this the default. Some details I will have to think through a bit more, but they will no doubt become apparent once the feature is released. This change requires the latest version of vim-misc.
1 parent 3246ed6 commit 677a27f

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

autoload/xolox/notes.vim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: June 29, 2014
3+
" Last Change: July 6, 2014
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

9-
let g:xolox#notes#version = '0.23.11'
9+
let g:xolox#notes#version = '0.24'
1010
let g:xolox#notes#url_pattern = '\<\(mailto:\|javascript:\|\w\{3,}://\)\(\S*\w\)\+/\?'
1111
let s:scriptdir = expand('<sfile>:p:h')
1212

@@ -620,10 +620,10 @@ endfunction
620620

621621
function! xolox#notes#buffer_is_note() " {{{2
622622
" Check whether the current buffer is a note (with the correct file type and path).
623-
let bufpath = expand('%:p:h')
623+
let buffer_directory = expand('%:p:h')
624624
if xolox#notes#filetype_is_note(&ft)
625625
for directory in xolox#notes#find_directories(1)
626-
if xolox#misc#path#equals(bufpath, directory)
626+
if xolox#misc#path#starts_with(buffer_directory, directory)
627627
return 1
628628
endif
629629
endfor
@@ -804,7 +804,7 @@ function! xolox#notes#get_fnames(include_shadow_notes) " {{{3
804804
if !s:have_cached_names
805805
let starttime = xolox#misc#timer#start()
806806
for directory in xolox#notes#find_directories(0)
807-
let pattern = xolox#misc#path#merge(directory, '*')
807+
let pattern = xolox#misc#path#merge(directory, '**')
808808
let listing = glob(xolox#misc#path#absolute(pattern))
809809
call extend(s:cached_fnames, filter(split(listing, '\n'), 'filereadable(v:val)'))
810810
endfor
@@ -893,11 +893,11 @@ endfunction
893893

894894
function! xolox#notes#select_directory() " {{{3
895895
" Pick the best suited directory for creating a new note.
896-
let bufdir = expand('%:p:h')
896+
let buffer_directory = expand('%:p:h')
897897
let notes_directories = xolox#notes#find_directories(0)
898898
for directory in notes_directories
899-
if xolox#misc#path#equals(bufdir, directory)
900-
return directory
899+
if xolox#misc#path#starts_with(buffer_directory, directory)
900+
return buffer_directory
901901
endif
902902
endfor
903903
return notes_directories[0]

misc/notes/search-notes.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Python script for fast text file searching using keyword index on disk.
44
#
55
# Author: Peter Odding <peter@peterodding.com>
6-
# Last Change: September 2, 2013
6+
# Last Change: July 6, 2014
77
# URL: http://peterodding.com/code/vim/notes/
88
# License: MIT
99
#
@@ -68,6 +68,9 @@
6868
# unsupported version, the script knows that it should rebuild the index.
6969
INDEX_VERSION = 2
7070

71+
# Filename matching patterns of files to ignore during scans.
72+
PATTERNS_TO_IGNORE = ('.swp', '.s??', '.*.s??', '*~')
73+
7174
class NotesIndex:
7275

7376
def __init__(self):
@@ -178,12 +181,10 @@ def update_index(self):
178181
notes_on_disk = {}
179182
last_count = 0
180183
for directory in self.user_directories:
181-
for filename in os.listdir(directory):
182-
# Vim swap files are ignored.
183-
if (filename != '.swp' and not fnmatch.fnmatch(filename, '.s??')
184-
and not fnmatch.fnmatch(filename, '.*.s??')):
185-
abspath = os.path.join(directory, filename)
186-
if os.path.isfile(abspath):
184+
for root, dirs, files in os.walk(directory):
185+
for filename in files:
186+
if not any(fnmatch.fnmatch(filename, pattern) for pattern in PATTERNS_TO_IGNORE):
187+
abspath = os.path.join(root, filename)
187188
notes_on_disk[abspath] = os.path.getmtime(abspath)
188189
self.logger.info("Found %i notes in %s ..", len(notes_on_disk) - last_count, directory)
189190
last_count = len(notes_on_disk)

0 commit comments

Comments
 (0)