Permalink
Browse files

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.
  • Loading branch information...
1 parent 3246ed6 commit 677a27fecc4aef6acbbb6b3ed68d6066a5daa7c3 @xolox committed Jul 6, 2014
Showing with 16 additions and 15 deletions.
  1. +8 −8 autoload/xolox/notes.vim
  2. +8 −7 misc/notes/search-notes.py
View
@@ -1,12 +1,12 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 29, 2014
+" Last Change: July 6, 2014
" URL: http://peterodding.com/code/vim/notes/
" Note: This file is encoded in UTF-8 including a byte order mark so
" that Vim loads the script using the right encoding transparently.
-let g:xolox#notes#version = '0.23.11'
+let g:xolox#notes#version = '0.24'
let g:xolox#notes#url_pattern = '\<\(mailto:\|javascript:\|\w\{3,}://\)\(\S*\w\)\+/\?'
let s:scriptdir = expand('<sfile>:p:h')
@@ -620,10 +620,10 @@ endfunction
function! xolox#notes#buffer_is_note() " {{{2
" Check whether the current buffer is a note (with the correct file type and path).
- let bufpath = expand('%:p:h')
+ let buffer_directory = expand('%:p:h')
if xolox#notes#filetype_is_note(&ft)
for directory in xolox#notes#find_directories(1)
- if xolox#misc#path#equals(bufpath, directory)
+ if xolox#misc#path#starts_with(buffer_directory, directory)
return 1
endif
endfor
@@ -804,7 +804,7 @@ function! xolox#notes#get_fnames(include_shadow_notes) " {{{3
if !s:have_cached_names
let starttime = xolox#misc#timer#start()
for directory in xolox#notes#find_directories(0)
- let pattern = xolox#misc#path#merge(directory, '*')
+ let pattern = xolox#misc#path#merge(directory, '**')
let listing = glob(xolox#misc#path#absolute(pattern))
call extend(s:cached_fnames, filter(split(listing, '\n'), 'filereadable(v:val)'))
endfor
@@ -893,11 +893,11 @@ endfunction
function! xolox#notes#select_directory() " {{{3
" Pick the best suited directory for creating a new note.
- let bufdir = expand('%:p:h')
+ let buffer_directory = expand('%:p:h')
let notes_directories = xolox#notes#find_directories(0)
for directory in notes_directories
- if xolox#misc#path#equals(bufdir, directory)
- return directory
+ if xolox#misc#path#starts_with(buffer_directory, directory)
+ return buffer_directory
endif
endfor
return notes_directories[0]
View
@@ -3,7 +3,7 @@
# Python script for fast text file searching using keyword index on disk.
#
# Author: Peter Odding <peter@peterodding.com>
-# Last Change: September 2, 2013
+# Last Change: July 6, 2014
# URL: http://peterodding.com/code/vim/notes/
# License: MIT
#
@@ -68,6 +68,9 @@
# unsupported version, the script knows that it should rebuild the index.
INDEX_VERSION = 2
+# Filename matching patterns of files to ignore during scans.
+PATTERNS_TO_IGNORE = ('.swp', '.s??', '.*.s??', '*~')
+
class NotesIndex:
def __init__(self):
@@ -178,12 +181,10 @@ def update_index(self):
notes_on_disk = {}
last_count = 0
for directory in self.user_directories:
- for filename in os.listdir(directory):
- # Vim swap files are ignored.
- if (filename != '.swp' and not fnmatch.fnmatch(filename, '.s??')
- and not fnmatch.fnmatch(filename, '.*.s??')):
- abspath = os.path.join(directory, filename)
- if os.path.isfile(abspath):
+ for root, dirs, files in os.walk(directory):
+ for filename in files:
+ if not any(fnmatch.fnmatch(filename, pattern) for pattern in PATTERNS_TO_IGNORE):
+ abspath = os.path.join(root, filename)
notes_on_disk[abspath] = os.path.getmtime(abspath)
self.logger.info("Found %i notes in %s ..", len(notes_on_disk) - last_count, directory)
last_count = len(notes_on_disk)

0 comments on commit 677a27f

Please sign in to comment.