Skip to content
Browse files

adding actions to move pads to folders and back to g:pad_dir

  • Loading branch information...
1 parent 721289e commit 351f96fbff2aa58fc59531f3b510bdee1d07b9d0 @fmoralesc committed Jul 26, 2012
Showing with 77 additions and 24 deletions.
  1. +22 −0 autoload/pad.vim
  2. +4 −2 ftplugin/pad.vim
  3. +2 −0 plugin/padlib/handler.py
  4. +26 −12 plugin/padlib/list_local.py
  5. +14 −9 plugin/padlib/pad_local.py
  6. +9 −1 plugin/padlib/utils.py
View
22 autoload/pad.vim
@@ -34,6 +34,8 @@ endfunction
" Operations: {{{1
if has("python")
+" Global {{{2
+
function! pad#OpenPad()
python padlib.handler.open_pad()
endfunction
@@ -46,6 +48,8 @@ function! pad#SearchPads()
python padlib.handler.search_pads()
endfunction
+" Pad local {{{2
+
function! pad#UpdatePad()
python padlib.pad_local.update()
endfunction
@@ -58,6 +62,14 @@ function! pad#AddModeline()
python padlib.pad_local.add_modeline()
endfunction
+function! pad#MoveToFolder()
+ python padlib.pad_local.move_to_folder()
+endfunction
+
+function! pad#MoveToSaveDir()
+ python padlib.pad_local.move_to_savedir()
+endfunction
+
function! pad#Archive()
python padlib.pad_local.archive()
endfunction
@@ -66,6 +78,8 @@ function! pad#Unarchive()
python padlib.pad_local.unarchive()
endfunction
+" List local {{{2
+
function! pad#EditPad()
python padlib.list_local.edit_pad()
endfunction
@@ -74,6 +88,14 @@ function! pad#DeletePad()
python padlib.list_local.delete_pad()
endfunction
+function! pad#MovePad()
+ python padlib.list_local.move_to_folder()
+endfunction
+
+function! pad#MovePadToSaveDir()
+ python padlib.list_local.move_to_savedir()
+endfunction
+
function! pad#ArchivePad()
python padlib.list_local.archive_pad()
endfunction
View
6 ftplugin/pad.vim
@@ -12,8 +12,10 @@ if has("gui_running")
else
noremap <buffer> <silent> dd :call pad#DeletePad()<cr>
endif
-noremap <buffer> <silent> <leader>+a :call pad#ArchivePad()<cr>
-noremap <buffer> <silent> <leader>-a :call pad#UnarchivePad()<cr>
+noremap <buffer> <silent> <localleader>+a :call pad#ArchivePad()<cr>
+noremap <buffer> <silent> <localleader>-a :call pad#UnarchivePad()<cr>
+noremap <buffer> <silent> <localleader>+f :call pad#MovePad()<cr>
+noremap <buffer> <silent> <localleader>-f :call pad#MovePadToSaveDir()<cr>
noremap <buffer> <silent> <esc> :bw<cr>
noremap <buffer> <silent> <S-f> :call pad#IncrementalSearch()<cr>
View
2 plugin/padlib/handler.py
@@ -46,6 +46,8 @@ def open_pad(path=None, first_line=None): #{{{1
vim.command("noremap <silent> <buffer> <localleader>dd :call pad#DeleteThis()<cr>")
vim.command("noremap <silent> <buffer> <localleader>+m :call pad#AddModeline()<cr>")
+ vim.command("noremap <silent> <buffer> <localleader>+f :call pad#MoveToFolder()<cr>")
+ vim.command("noremap <silent> <buffer> <localleader>-f :call pad#MoveToSaveDir()<cr>")
vim.command("noremap <silent> <buffer> <localleader>+a :call pad#Archive()<cr>")
vim.command("noremap <silent> <buffer> <localleader>-a :call pad#Unarchive()<cr>")
View
38 plugin/padlib/list_local.py
@@ -8,11 +8,12 @@
from os.path import join, basename, exists
from shutil import move
from padlib.handler import open_pad, get_filelist, fill_list
-from padlib.utils import get_save_dir
+from padlib.utils import get_save_dir, make_sure_dir_is_empty
-def get_selected_path():
+def get_selected_path(): #{{{1
return join(get_save_dir(), vim.current.line.split(" @")[0])
+
def edit_pad(): #{{{1
""" Opens the currently selected note in the __pad__ buffer.
"""
@@ -27,25 +28,38 @@ def delete_pad(): #{{{1
if confirm in ("y", "Y"):
path = get_selected_path()
remove(path)
- vim.command("bd")
+ make_sure_dir_is_empty(path)
+ vim.command("ListPads")
+ vim.command("redraw!")
+
+def move_to_folder(path=None): #{{{1
+ """ Moves the selected pad to a subfolder of g:pad_dir
+ """
+ selected_path = get_selected_path()
+ if path == None:
+ path = vim.eval('input("move to: ")')
+ if not exists(join(get_save_dir(), path)):
+ mkdir(join(get_save_dir(), path))
+ move(selected_path, join(get_save_dir(), path, basename(selected_path)))
+ make_sure_dir_is_empty(path)
+ vim.command("ListPads")
+ if path == None:
vim.command("redraw!")
+def move_to_savedir(): #{{{1
+ """ Moves a note to g:pad_dir
+ """
+ move_to_folder("")
+
def archive_pad(): #{{{1
""" Archives the currently selected note
"""
- path = get_selected_path()
- if not exists(join(get_save_dir(), "archive")):
- mkdir(join(get_save_dir(), "archive"))
- move(path, join(get_save_dir(), "archive", basename(path)))
- vim.command("bd")
+ move_to_folder("archive")
def unarchive_pad(): #{{{1
""" Unarchives the currently selected note
"""
- path = get_selected_path()
- move(path, join(get_save_dir(), basename(path)))
- vim.command("bd")
-
+ move_to_savedir()
def incremental_search(): #{{{1
""" Provides incremental search within the __pad__ buffer.
View
23 plugin/padlib/pad_local.py
@@ -51,15 +51,20 @@ def add_modeline():
vim.command("set filetype=" + mode)
vim.command("set nomodified")
-def archive():
- new_path = join(get_save_dir(), "archive", basename(vim.current.buffer.name))
- if not exists(join(get_save_dir(), "archive")):
- mkdir(join(get_save_dir(), "archive"))
+def move_to_folder(path=None):
+ if path == None:
+ path = vim.eval("input('move to: ')")
+ new_path = join(get_save_dir(), path, basename(vim.current.buffer.name))
+ if not exists(join(get_save_dir(), path)):
+ mkdir(join(get_save_dir(), path))
move(vim.current.buffer.name, new_path)
- vim.command("q")
+ vim.command("bd")
-def unarchive():
- new_path = join(get_save_dir(), basename(vim.current.buffer.name))
- move(vim.current.buffer.name, new_path)
- vim.command("q")
+def move_to_savedir():
+ move_to_folder("")
+def archive():
+ move_to_folder("archive")
+
+def unarchive():
+ move_to_savedir()
View
10 plugin/padlib/utils.py
@@ -1,5 +1,13 @@
import vim
-from os.path import expanduser
+from os import rmdir
+from os.path import expanduser, split
def get_save_dir():
return expanduser(vim.eval("g:pad_dir")).replace("\\", "\\\\")
+
+def make_sure_dir_is_empty(path): #{{{1
+ try:
+ rmdir(split(path)[0])
+ except:
+ pass
+

0 comments on commit 351f96f

Please sign in to comment.
Something went wrong with that request. Please try again.