Permalink
Browse files

Version 0.7.0

- add vim help file
- add custom sort orders
- add -o option to open note for given key directly
- show notes tags in the list view
  • Loading branch information...
mrtazz authored and vim-scripts committed Oct 21, 2012
1 parent 3850fac commit c9f9118027d4c5340d842225b7f44af4a4582767
Showing with 275 additions and 11 deletions.
  1. +6 −0 CHANGELOG.md
  2. +20 −1 README
  3. +20 −0 README.md
  4. +94 −9 autoload/simplenote.vim
  5. +112 −0 doc/simplenote.txt
  6. +21 −0 doc/tags
  7. +2 −1 plugin/simplenote.vim
View
@@ -1,5 +1,11 @@
# Changelog
+## 0.7.0 (10/21/2012)
+- add vim help file
+- add custom sort orders
+- add -o option to open note for given key directly
+- show notes tags in the list view
+
## 0.6.0 (09/30/2012)
- add the possibility to restrict note listing to tags
View
21 README
@@ -70,6 +70,26 @@ existing comma-separated tags for the note, which you can then edit. Tags have
to be comma separated and hitting `Enter` will then update the note with the
new tag list.
+There is also an option to open notes directly from a given key:
+
+ :Simplenote -o <notekey>
+
+While this is not very useful in everyday usage, it can be used very
+effectively to create shortcuts to notes you use often. Example:
+
+ " add :Todo command
+ command Todo Simplenote -o <yourtodonotekey>
+
+Now you can jump to your todo note directly with `:Todo` in vim.
+
+## Note sorting
+simplenote.vim supports simple note ordering. Per default the sort order is
+pinned notes first followed by modified date from newest to oldest. The order
+can be changed by setting the `g:SimplenoteSortOrder` variable. It should be
+set to a comma separated list of values which represents the sort order.
+Allowed values are `pinned` (pinned before unpinned), `tags` (notes with tags
+before untagged ones), `modifydate` and `createdate` (both newer before older).
+
## Dependencies
Version 2 of the SimpleNote API relies heavily on JSON. As JSON and VimL don't
really play nice together, basic parts of this plugin are implemented in
@@ -83,7 +103,6 @@ add these lines (with the correct values) to your `.vimrc`:
let $HTTP_PROXY = 'http://<proxyuser&gt;:<proxypassword>@<proxyurl>:<proxyport>'
let $HTTPS_PROXY = 'http://<proxyuser&gt;:<proxypassword>@<proxyurl>:<proxyport>'
-
## Development
- [Bugs and issue tracker](https://github.com/mrtazz/simplenote.vim/issues)
View
@@ -68,6 +68,26 @@ existing comma-separated tags for the note, which you can then edit. Tags have
to be comma separated and hitting `Enter` will then update the note with the
new tag list.
+There is also an option to open notes directly from a given key:
+
+ :Simplenote -o <notekey>
+
+While this is not very useful in everyday usage, it can be used very
+effectively to create shortcuts to notes you use often. Example:
+
+ " add :Todo command
+ command Todo Simplenote -o <yourtodonotekey>
+
+Now you can jump to your todo note directly with `:Todo` in vim.
+
+## Note sorting
+simplenote.vim supports simple note ordering. Per default the sort order is
+pinned notes first followed by modified date from newest to oldest. The order
+can be changed by setting the `g:SimplenoteSortOrder` variable. It should be
+set to a comma separated list of values which represents the sort order.
+Allowed values are `pinned` (pinned before unpinned), `tags` (notes with tags
+before untagged ones), `modifydate` and `createdate` (both newer before older).
+
## Dependencies
Version 2 of the SimpleNote API relies heavily on JSON. As JSON and VimL don't
really play nice together, basic parts of this plugin are implemented in
View
@@ -45,6 +45,12 @@ else
let s:lineheight = 0
endif
+" line height
+if exists("g:SimplenoteSortOrder")
+ let s:sortorder = g:SimplenoteSortOrder
+else
+ let s:sortorder = "pinned, modifydate"
+endif
if (s:user == "") || (s:password == "")
let errmsg = "Simplenote credentials missing. Set g:SimplenoteUsername and "
@@ -455,6 +461,8 @@ class SimplenoteVimInterface(object):
width -= max(m.floor(m.log(len(vim.current.buffer))) + 2, 5)
width = int(width)
+ # get note tags
+ tags = "[%s]" % ",".join([t.encode('utf-8') for t in note["tags"]])
# format date
mt = time.localtime(float(note["modifydate"]))
@@ -465,14 +473,16 @@ class SimplenoteVimInterface(object):
else:
title = str(note["key"])
+
# Compress everything into the appropriate number of columns
- title_width = width - len(mod_time) - 1
+ title_meta_length = len(tags) + len(mod_time) + 1
+ title_width = width - title_meta_length
if len(title) > title_width:
title = title[:title_width]
elif len(title) < title_width:
title = title.ljust(title_width)
- return "%s %s" % (title, mod_time)
+ return "%s %s %s" % (title, tags, mod_time)
def get_notes_from_keys(self, key_list):
@@ -502,14 +512,17 @@ class SimplenoteVimInterface(object):
"""
vim.command("call s:ScratchBufferOpen('%s')" % sb_name)
- def display_note_in_scratch_buffer(self):
+ def display_note_in_scratch_buffer(self, note_id=None):
""" displays the note corresponding to the given key in the scratch
buffer
"""
- # get the notes id which is shown in brackets in the current line
- line, col = vim.current.window.cursor
- note_id = self.note_index[int(line) - 1]
- # store it as a global script variable
+ # get the notes id which is shown in brackets in the current line if we
+ # didn't got passed a key
+ if note_id is None:
+ line, col = vim.current.window.cursor
+ note_id = self.note_index[int(line) - 1]
+
+ # get note and open it in scratch buffer
note, status = self.simplenote.get_note(note_id)
vim.command("""call s:ScratchBufferOpen("%s")""" % note_id)
self.set_current_note(note_id)
@@ -601,8 +614,7 @@ class SimplenoteVimInterface(object):
if status == 0:
note_titles = []
notes = self.get_notes_from_keys([n['key'] for n in note_list])
- notes.sort(key=lambda k: (('pinned' in k['systemtags']), k['modifydate']))
- notes.reverse()
+ notes.sort(cmp=compare_notes)
note_titles = [self.format_title(n) for n in notes]
self.note_index = [n["key"] for n in notes]
buffer[:] = note_titles
@@ -616,6 +628,73 @@ class SimplenoteVimInterface(object):
vim.command("nnoremap <buffer><silent> <CR> <Esc>:call <SID>GetNoteToCurrentBuffer()<CR>")
+
+def compare_notes(note1, note2):
+ """ determine the sort order for two passed in notes
+
+ Parameters:
+ note1 - first note object
+ note2 - second note object
+
+ Returns -1 if the first note is considered smaller, 0 for equal
+ notes and 1 if the first note is considered larger
+ """
+ # setup compare functions
+ def compare_pinned(note1, note2):
+ if ("pinned" in note1["systemtags"] and
+ "pinned" not in note2["systemtags"]):
+ return -1
+ elif ("pinned" in note2["systemtags"] and
+ "pinned" not in note1["systemtags"]):
+ return 1
+ else:
+ return 0
+
+
+ def compare_modified(note1, note2):
+ if float(note1["modifydate"]) < float(note2["modifydate"]):
+ return 1
+ elif float(note1["modifydate"]) > float(note2["modifydate"]):
+ return -1
+ else:
+ return 0
+
+ def compare_created(note1, note2):
+ if float(note1["createdate"]) < float(note2["createdate"]):
+ return 1
+ elif float(note1["createdate"]) > float(note2["createdate"]):
+ return -1
+ else:
+ return 0
+
+ def compare_tags(note1, note2):
+ if note1["tags"] < note2["tags"]:
+ return 1
+ if note1["tags"] > note2["tags"]:
+ return -1
+ else:
+ return 0
+
+ # dict for dynamically calling compare functions
+ sortfuncs = { "pinned": compare_pinned,
+ "createdate": compare_created,
+ "modifydate": compare_modified,
+ "tags": compare_tags
+ }
+
+ sortorder = vim.eval("s:sortorder").split(",")
+
+ for key in sortorder:
+ res = sortfuncs.get(key.strip(),lambda x,y: 0)(note1, note2)
+ if res != 0:
+ return res
+
+ # return equal if no comparison hit
+ return 0
+
+
+
+
class NoteFetcher(Thread):
""" class to fetch a note running in a thread
@@ -689,6 +768,12 @@ elif param == "-D":
elif param == "-t":
interface.set_tags_for_current_note()
+elif param == "-o":
+ if optionsexist:
+ interface.display_note_in_scratch_buffer(vim.eval("a:1"))
+ else:
+ print "No notekey given."
+
else:
print "Unknown argument"
View
@@ -0,0 +1,112 @@
+*simplenote.txt* A vim plugin to interact with the Simplenote API.
+*simplenote*
+
+==============================================================================
+CONTENTS *simplenote-contents*
+
+ 1.Intro...................................|simplenote-intro|
+ 2.Commands................................|simplenote-commands|
+ 3.Configuration...........................|simplenote-configuration|
+ 4.Bugs....................................|simplenote-bugs|
+
+==============================================================================
+1. Intro *simplenote-intro*
+
+A vim plugin to interact with the Simplenote API. You can create an
+account at https://simple-note.appspot.com/create if you don't already
+have one. The plugin needs vim to be compiled with python support.
+
+Now you can take simple notes directly from your favourite editor.
+
+==============================================================================
+2. Commands *simplenote-commands*
+
+:Simplenote -l {num|tags} *:SimplenoteList*
+ List {num} notes or all notes with {tags} where {tags} is a comma separated
+ list of tags. When the parameter is omitted, all notes are fetched. This
+ command opens a split window to list notes. In the appearing split window,
+ notes can be selected with the cursor line and are opened in a new split
+ window with {CR}.
+
+:Simplenote -u *:SimplenoteUpdate*
+ Update the currently opened note in the online service. The note is also
+ automatically updated when the buffer is written.
+
+:Simplenote -d *:SimplenoteTrash*
+ Move the currently open note into the trash. The open buffer is
+ automatically closed after success.
+
+:Simplenote -D *:SimplenoteDelete*
+ Delete the currently open note. The open buffer is automatically closed
+ after success.
+
+:Simplenote -n *:SimplenoteNew*
+ Create a new note with the contents of the current buffer.
+
+:Simplenote -t *:SimplenoteTags*
+ Show an input field to add tags to the note in the current buffer. The
+ input field is prepopulated with existing note tags.
+
+:Simplenote -o {notekey} *:SimplenoteOpen*
+ Opens the note corresponding to the given {notekey}. This is useful for
+ configuring shortcuts to specific notes, e.g. >
+ " add :Todo command
+ command Todo Simplenote -o <yourtodonotekey>
+<
+
+==============================================================================
+3. Configuration *simplenote-configuration*
+
+ *'simplenote_username'*
+Default: not set
+Set the username for the Simplenote account to use. >
+ g:SimplenoteUsername="foo@example.com"
+<
+
+ *'simplenote_password'*
+Default: not set
+Set the Password for the Simplenote account to use. >
+ g:SimplenotePassword="verysecret"
+<
+
+ *'simplenote_list_height'*
+Default: 50% of the current buffer
+If set, the split windows will be opened with the given height in lines. >
+ g:SimplenoteListHeight=30
+<
+
+ *'simplenote_vertical'*
+Default: 0
+If set, the split windows will be opened vertical instead of horizontal. >
+ g:SimplenoteVertical=1
+<
+
+ *'simplenote_sort_order'*
+Default: "pinned,modifydate"
+Sets the sort order by which notes should be listed. Dates are sorted from
+newest to oldest and pinned and tags from existing to non-existing. Supported
+values are {pinned}, {tags}, {modifydate}, {createdate}. >
+ g:SimplenoteSortOrder="pinned,tags"
+<
+
+ *'simplenote_filetype'*
+Default: "txt"
+Set the default vim filetype for notes. >
+ g:SimplenoteFiletype="markdown"
+<
+
+
+ *'simplenote_proxy'*
+Default: Off
+If you are behind a proxy set these to the correct values. >
+ let $HTTP_PROXY = 'http://<user>:<password>@<proxyurl>:<proxyport>'
+ let $HTTPS_PROXY = 'http://<user>:<password>@<proxyurl>:<proxyport>'
+<
+
+==============================================================================
+4. Bugs *simplenote-bugs*
+
+For known bugs or to submit a new one, please visit
+https://github.com/mrtazz/simplenote.vim/issues
+
+vim: syntax=help nospell
View
@@ -0,0 +1,21 @@
+'simplenote_filetype' simplenote.txt /*'simplenote_filetype'*
+'simplenote_list_height' simplenote.txt /*'simplenote_list_height'*
+'simplenote_password' simplenote.txt /*'simplenote_password'*
+'simplenote_proxy' simplenote.txt /*'simplenote_proxy'*
+'simplenote_sort_order' simplenote.txt /*'simplenote_sort_order'*
+'simplenote_username' simplenote.txt /*'simplenote_username'*
+'simplenote_vertical' simplenote.txt /*'simplenote_vertical'*
+:SimplenoteDelete simplenote.txt /*:SimplenoteDelete*
+:SimplenoteList simplenote.txt /*:SimplenoteList*
+:SimplenoteNew simplenote.txt /*:SimplenoteNew*
+:SimplenoteOpen simplenote.txt /*:SimplenoteOpen*
+:SimplenoteTags simplenote.txt /*:SimplenoteTags*
+:SimplenoteTrash simplenote.txt /*:SimplenoteTrash*
+:SimplenoteUpdate simplenote.txt /*:SimplenoteUpdate*
+simplenote simplenote.txt /*simplenote*
+simplenote-bugs simplenote.txt /*simplenote-bugs*
+simplenote-commands simplenote.txt /*simplenote-commands*
+simplenote-configuration simplenote.txt /*simplenote-configuration*
+simplenote-contents simplenote.txt /*simplenote-contents*
+simplenote-intro simplenote.txt /*simplenote-intro*
+simplenote.txt simplenote.txt /*simplenote.txt*
View
@@ -4,7 +4,7 @@
" Author: Daniel Schauenberg <d@unwiredcouch.com>
" WebPage: http://github.com/mrtazz/simplenote.vim
" License: MIT
-" Version: 0.6.0
+" Version: 0.7.0
" Usage:
" :Simplenote -l X => list X number of notes; omit X to list all
" :Simplenote -l tags,moretags => list notes which feature one of the tags
@@ -13,6 +13,7 @@
" :Simplenote -n => create new note from buffer
" :Simplenote -D => delete note in current buffer
" :Simplenote -t => tag note in current buffer
+" :Simplenote -o key => open note with given key directly
"
" This is only the interface part of the script. For the actual implementation
" see plugin/simplenote.vim

0 comments on commit c9f9118

Please sign in to comment.