Permalink
Browse files

Merge pull request #44 from equalsraf/tb-no-renaming

Don't rename files and use first_line as filename for OpenPad
  • Loading branch information...
2 parents 62a84f2 + 5f4f221 commit 4b82a6caac48e66fe666a5f3e5fcd4bcfe43db83 @fmoralesc committed Jan 18, 2013
Showing with 22 additions and 4 deletions.
  1. +5 −0 doc/pad.txt
  2. +3 −0 plugin/pad.vim
  3. +3 −3 plugin/padlib/handler.py
  4. +9 −0 plugin/padlib/pad.py
  5. +2 −1 plugin/padlib/pad_local.py
View
@@ -169,6 +169,11 @@ When showing the list of notes, vim-pad reads by default 200 chars from the
files, in order to show a summary of the file. You can adjust how many chars
you want vim-pad to read by setting the *g:pad_read_nchars_from_files* variable.
+vim-pad renames files to reflect their contents, using a file name similar to
+the note title. The renames are done automatically when you leave/close a note.
+If you do not want vim-pad to rename the files you can set *g:pad_rename_files*
+to 0.
+
FUNCTIONS *vim-pad-functions*
---------
View
@@ -66,6 +66,9 @@ endif
if !exists('g:pad_default_file_extension')
let g:pad_default_file_extension = ''
endif
+if !exists('g:pad_rename_files')
+ let g:pad_rename_files = 1
+endif
" Base: {{{1
python<<EOF
View
@@ -10,15 +10,15 @@
from subprocess import Popen, PIPE
from padlib.utils import get_save_dir
from padlib.pad import PadInfo
-from padlib.timestamps import timestamp, natural_timestamp
+from padlib.timestamps import natural_timestamp
# globals (caches) {{{1
cached_data = []
cached_timestamps = []
cached_filenames = []
-def open_pad(path=None, first_line=None): # {{{1
+def open_pad(path=None, first_line=""): # {{{1
"""Creates or opens a note.
path: a valid path for a note.
@@ -35,7 +35,7 @@ def open_pad(path=None, first_line=None): # {{{1
# if no path is provided, we create one using the current time
if not path:
path = join(get_save_dir(),
- timestamp() + vim.eval("g:pad_default_file_extension"))
+ PadInfo([first_line]).id + vim.eval("g:pad_default_file_extension"))
path = path.replace(" ", "\ ")
if bool(int(vim.eval("g:pad_open_in_split"))):
View
@@ -9,6 +9,15 @@ class PadInfo(object):
__slots__ = "id", "summary", "body", "isEmpty", "folder"
def __init__(self, source):
+ """
+
+ source can be:
+
+ * a vim buffer
+ * a file object
+ * a list of strings, one per line
+ """
+
nchars = int(vim.eval("g:pad_read_nchars_from_files"))
self.summary = ""
self.body = ""
@@ -15,7 +15,8 @@ def update():
"""
modified = bool(int(vim.eval("b:pad_modified")))
- if modified:
+ can_rename = bool(int(vim.eval("g:pad_rename_files")))
+ if modified and can_rename:
_id = PadInfo(vim.current.buffer).id
old_path = expanduser(vim.current.buffer.name)

0 comments on commit 4b82a6c

Please sign in to comment.