From 5314adaa4028f2f45e4bf43669fcf94adba75b53 Mon Sep 17 00:00:00 2001 From: wmassa Date: Tue, 24 Jun 2014 17:06:07 +0200 Subject: [PATCH 1/4] Enable notebook specification when creating a new note. The format for creating a note is now as follows: Title Notebook: prefered notebook Tags: tag1, tag2, .. The text of the note. When no note is given the default notebook is used. This default notebook can be set with g:evervim_defaultnotebook . --- autoload/evervim.vim | 3 ++- doc/evervim.txt | 10 ++++++++-- plugin/py/evervim_editor.py | 28 ++++++++++++++++++++++------ plugin/py/evervim_editor_test.py | 20 ++++++++++---------- plugin/py/evervimmer.py | 1 + 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/autoload/evervim.vim b/autoload/evervim.vim index dfffede..7e43896 100644 --- a/autoload/evervim.vim +++ b/autoload/evervim.vim @@ -182,7 +182,8 @@ function! evervim#createNoteBuf() " {{{ " clear buffer call append(0, "") - call append(1, "Tags:") + call append(1, "Notebook:") + call append(2, "Tags:") call cursor(1,0) setlocal nomodified diff --git a/doc/evervim.txt b/doc/evervim.txt index 7a39940..a8eb039 100644 --- a/doc/evervim.txt +++ b/doc/evervim.txt @@ -71,8 +71,9 @@ choice one and too, the note will be displayd. Note is formatted 1 line is Title - 2 line is Tags (comma deliminated) - 3 line after body + 2 line is Notebook (when empty the default notebook is used) + 3 line is Tags (comma deliminated) + 4 line after body If OpenBrowser plugin installed, you can open note on browser. (http://www.vim.org/scripts/script.php?script_id=3133) @@ -181,6 +182,11 @@ g:evervim_splitoption *g:evervim_splitoption* Default is 'v'. It means open vertical. +g:evervim_defaultnotebook + Contains the name of the default notebook. If no notebook is + specified when a note is created, the note is saved to this + notebook. + Edit note on markdown or XML. diff --git a/plugin/py/evervim_editor.py b/plugin/py/evervim_editor.py index cc1b891..c24b623 100644 --- a/plugin/py/evervim_editor.py +++ b/plugin/py/evervim_editor.py @@ -25,6 +25,7 @@ def __init__(self): self.encoding = None self.asyncupdate = None self.enscriptpath = None + self.defaultnotebook = None @classmethod def getInstance(self): @@ -59,36 +60,51 @@ def setAPI(self): def note2buffer(self, note): """ return strings array for buffer from note. """ - """ note has attribute title, tagNames, content """ + """ note has attribute title, notebook, tagNames, content """ bufStrings = [] pref = EvervimPref.getInstance() doc = minidom.parseString(note.content) ennote = doc.getElementsByTagName("en-note")[0] + notebooks = self.api.listNotebooks() + notebook = next((n for n in notebooks if n.guid == note.notebookGuid), None) + notebookName = notebook.name if notebook is not None else "" + if pref.usemarkdown == '0': bufStrings.append(note.title) + bufStrings.append("Notebook:" + notebookName) bufStrings.append("Tags:" + ",".join(note.tagNames)) contentxml = ennote.toprettyxml(indent=pref.xmlindent, encoding='utf-8') contentxml = re.sub('^' + pref.xmlindent, '', contentxml, flags=re.MULTILINE) bufStrings.extend([line for line in contentxml.splitlines()[1:-1] if line.strip()]) else: bufStrings.append('# ' + note.title) + bufStrings.append("Notebook:" + notebookName) bufStrings.append("Tags:" + ",".join(note.tagNames)) content = markdownAndENML.parseENML(ennote).encode('utf-8') bufStrings.extend(content.splitlines()) return bufStrings def buffer2note(self, note, buflines): - """ return note that set title, tags, content from buftext """ + """ return note that set title, notebook, tags, content from buftext """ pref = EvervimPref.getInstance() if pref.usemarkdown == '0': note.title = buflines[0] - note = self.api.editTag(note, buflines[1].replace('Tags:', '')) - note.content = EvernoteAPI.NOTECONTENT_HEADER + "\n".join(buflines[2:]) + EvernoteAPI.NOTECONTENT_FOOTER + note.content = EvernoteAPI.NOTECONTENT_HEADER + "\n".join(buflines[3:]) + EvernoteAPI.NOTECONTENT_FOOTER else: note.title = re.sub(r'^#', '',buflines[0]).strip() - note = self.api.editTag(note, buflines[1].replace('Tags:', '')) - parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[2:])) + parsedContent = markdownAndENML.parseMarkdown("\n".join(buflines[3:])) note.content = EvernoteAPI.NOTECONTENT_HEADER + parsedContent.encode('utf-8') + EvernoteAPI.NOTECONTENT_FOOTER + notebookName = buflines[1].replace('Notebook:', '').strip() + if notebookName == "" and pref.defaultnotebook is not None: + notebookName = pref.defaultnotebook + + notebooks = self.api.listNotebooks() + notebook = next((n for n in notebooks if n.name == notebookName), None) + if notebook is not None: + note.notebookGuid = notebook.guid + + note = self.api.editTag(note, buflines[2].replace('Tags:', '')) + return note diff --git a/plugin/py/evervim_editor_test.py b/plugin/py/evervim_editor_test.py index 6a2d4fb..f6c1544 100644 --- a/plugin/py/evervim_editor_test.py +++ b/plugin/py/evervim_editor_test.py @@ -67,20 +67,20 @@ def testNote2buffer(self): # {{{ EvervimPref.getInstance().xmlindent = ' ' # default ts=4 xmlStrings = editor.note2buffer(note) self.assertEqual(u'タイトルテスト'.encode('utf-8'), xmlStrings[0]) - self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[1]) - self.assertEqual('this is content'.encode('utf-8'), xmlStrings[2]) # this is content - self.assertEqual('本文テスト'.encode('utf-8'), xmlStrings[3]) # 本文テスト - self.assertEqual('

'.encode('utf-8'), xmlStrings[4]) #

- self.assertEqual(' たぐ3'.encode('utf-8'), xmlStrings[5]) # たぐ3 - self.assertEqual('

'.encode('utf-8'), xmlStrings[6]) # + self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[2]) + self.assertEqual('this is content'.encode('utf-8'), xmlStrings[3]) # this is content + self.assertEqual('本文テスト'.encode('utf-8'), xmlStrings[4]) # 本文テスト + self.assertEqual('

'.encode('utf-8'), xmlStrings[5]) #

+ self.assertEqual(' たぐ3'.encode('utf-8'), xmlStrings[6]) # たぐ3 + self.assertEqual('

'.encode('utf-8'), xmlStrings[7]) # EvervimPref.getInstance().usemarkdown = '1' # dont use markdown mkdStrings = editor.note2buffer(note) self.assertEqual(u'# タイトルテスト'.encode('utf-8'), mkdStrings[0]) - self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[1]) - self.assertEqual('this is content'.encode('utf-8'), mkdStrings[2]) - self.assertEqual('本文テスト'.encode('utf-8'), mkdStrings[3]) - self.assertEqual('### たぐ3'.encode('utf-8'), mkdStrings[4]) + self.assertEqual(u'Tags:タグ1,*タグ2'.encode('utf-8'), xmlStrings[2]) + self.assertEqual('this is content'.encode('utf-8'), mkdStrings[3]) + self.assertEqual('本文テスト'.encode('utf-8'), mkdStrings[4]) + self.assertEqual('### たぐ3'.encode('utf-8'), mkdStrings[5]) # }}} def testBuffer2note(self): # {{{ diff --git a/plugin/py/evervimmer.py b/plugin/py/evervimmer.py index 0ca04e5..1a22694 100644 --- a/plugin/py/evervimmer.py +++ b/plugin/py/evervimmer.py @@ -52,6 +52,7 @@ def setPref(self): # {{{ self.pref.asyncupdate = vim.eval("g:evervim_asyncupdate") self.pref.encoding = vim.eval('&enc') self.pref.enscriptpath = None + self.pref.defaultnotebook = vim.eval("g:evervim_defaultnotebook") # }}} def setAPI(self): # {{{ From 23feca5ffcb345dae2486d67ac4cc4ac159d3e57 Mon Sep 17 00:00:00 2001 From: "David W. Harks" Date: Sun, 1 Mar 2015 09:27:28 -0600 Subject: [PATCH 2/4] Cleaned up the English documentation --- doc/evervim.txt | 95 +++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/doc/evervim.txt b/doc/evervim.txt index 7a39940..fc07318 100644 --- a/doc/evervim.txt +++ b/doc/evervim.txt @@ -20,25 +20,25 @@ Changelog |evervim-changelog| ============================================================================== INTRODUCTION *evervim-introduction* -*evervim* (or *evervim.vim* ) is plugin for edit evernote(http://www.evernote.com) -on vim. This plugin can edit evernote by markdown or law XML. -See |:g:evervim_usemarkdown| . +*evervim* (or *evervim.vim* ) is plugin for editing +evernote(http://www.evernote.com) on vim. This plugin can edit evernote by +markdown or raw XML. See |:g:evervim_usemarkdown| . ============================================================================== REQUIRES *evervim-requires* Python and vim with compiled +python and "markdown" package for python. -Check Python is enable or not, +To check if Python is enabled or not, > :echo has('python') < -When display '1', then python is enable. -check "markdown" package is installed, +When the result is '1', then python is enabled. +To check whether the "markdown" package is installed, > :python import markdown < -When no error occured, markdown is already installed. -How to install markdown, see below url. +When no error occurs, markdown is already installed. +To install markdown, see the following url: http://packages.python.org/Markdown/install.html ============================================================================== @@ -46,18 +46,19 @@ INSTALL *evervim-install* Install files into Vim script directory. -Get "Developer Tokens" from Evernote Web(https://www.evernote.com/api/DeveloperToken.action) -and set g:evervim_devtoken, evervim will initialize on start VIM. +Get "Developer Tokens" from Evernote Web +(https://www.evernote.com/api/DeveloperToken.action) and set +g:evervim_devtoken. Evervim will initialize on VIM startup. vimrc example: let g:evervim_devtoken='S=s999:U=9ee99c9:E=999d9999c99:C=99a99a99999:P=9cd:A=en-devtoken:H=cd99999de9999c99b999d99d999cb9f9' -Initialize is not yet, set g:evervim_devtoken and do +After setting g:evervim_devtoken, use this command: > :EvervimSetup < -command, initialize evervim. -(after initialized, added some command for evervim) +to initialize evervim. You only need to do this once (or if you change the +devtoken). Once initialized, the Evervim commands will be available. ============================================================================== USAGE *evervim-usage* @@ -65,16 +66,16 @@ Display NotebookList > :EvervimNotebookList < -NotebookList is displayed, choice one and , -notes in notebook will be listed. -choice one and too, the note will be displayd. +The NotebookList is displayed; choose one and , +and a split with notes in the selected notebook will be shown. +Choose one and ; the note will be displayed. -Note is formatted +A Note is formatted as follows: 1 line is Title - 2 line is Tags (comma deliminated) - 3 line after body + 2 line is Tags (comma delimited) + 3 line and after is the note body -If OpenBrowser plugin installed, you can open note on browser. +If the OpenBrowser plugin installed, you can open the note in your browser. (http://www.vim.org/scripts/script.php?script_id=3133) see |:EvervimOpenBrowser|. ============================================================================== @@ -106,31 +107,31 @@ COMMAND *evervim-commands* :EvervimCreateNote *:EvervimCreateNote* Open new buffer to edit new note. - when buffer saved, note is saved on evernote. + When the buffer is written, note is saved on evernote. :EvervimOpenBrowser *:EvervimOpenBrowser* - Open note on your browser. Use this command when open single - note or set cursor on notes list. - This command is defined only "OpenBrowser" plugin is installed. + Open note in your browser. Use this command from a buffer + containing a single note or on a selected note in a notes list. + This command is defined only if "OpenBrowser" plugin is installed. (http://www.vim.org/scripts/script.php?script_id=3133) :EvervimOpenClient *:EvervimOpenClient* - Open note on your windows client. - This command is defined only vim on windows. + Open note in your windows client. + This command is defined only for VIM on windows. :EvervimSetup *:EvervimSetup* Setup acccount. :EvervimReloadPref *:EvervimReloadPref* - Reload variables. Generally, It will be not used. + Reload variables. Generally, should not be used. ------------------------------------------------------------------------------ variables *evervim-variables* g:evervim_devtoken *g:evervim_devtoken* - It is "Developer Tokens" string to get from Evernote Web at below. + The "Developer Token" string from Evernote Web at below. https://www.evernote.com/api/DeveloperToken.action - Default is empty string. + Default is empty string. g:evervim_workdir *g:evervim_workdir* Work directory. @@ -138,52 +139,52 @@ g:evervim_workdir *g:evervim_workdir* Default is $HOME/.evervim g:evervim_usemarkdown *g:evervim_usemarkdown* - Edit note on markdown or XML. + Edit note in markdown or XML. - ** WARNNING: Markdown format is not keep design tags. - If you open already edited note (not evervim ex:web clipped note) - and save it on evervim, the design tags will be loss. ** + ** WARNING: Markdown format does not preserve design tags. If + you open already an existing note (not created with evervim, i.e. a + web-clipped note) and save it in evervim, the design tags will be lost. ** - defalult is '1'. It means use markdown. + Default is '1'. It means use markdown. g:evervim_sortbooks *g:evervim_sortnotebooks* Sort pattern of notebooks. It can use below values. (name | serviceCreated | serviceUpdated) (asc | desc) Default is 'name asc'. - It means name desc. + It means the list is sorted by name in ascending (A-Z) order. g:evervim_sorttags *g:evervim_sorttags* Sort pattern of tags. It can use below values. (name) (asc | desc) Default is 'name asc'. - It means name desc. + It means the tags are sorted by name in ascending (A-Z) order g:evervim_xmlindent *g:evervim_xmlindent* - When you edit note on XML, indent of XML. + When you edit a note in XML, use this string for each indent of the XML. Default is ' '. g:evervim_asyncupdate *g:evervim_asyncupdate* - This value means When save note, - asynchronous update to evernote or not. + This value enables or disables asynchronous update to evernote + when saving notes. - Default is '0'. It means not asynchronous update. - Asynchronous update is not runnning multi. - So if one thread runnning, not update to evernote. - Next timing of saving buffer, update to evernote. + Default is '0', or synchronous updates. + NOTE: With asynchronous updates on, Evervim will not perform + multiple updates simultaneously; if one update thread is + already runnning, Evervim will skip the update to Evernote. + You will need to write the buffer again to update the buffer on Evernote. g:evervim_splitoption *g:evervim_splitoption* Open ListWindowmode, if let g:evervim_splitoption='' - open listwindow horizontal. + Evervim will open listwindows using a horizontal split. - Default is 'v'. It means open vertical. + Default is 'v'. It means open list windows using vertical + splits. -Edit note on markdown or XML. - ============================================================================== TODO *evervim-todo* ・Improve English document.(You know, I'm not use English well, I needs help!) From c47c362cffb9cd18ca5ddd64331835080d5bc251 Mon Sep 17 00:00:00 2001 From: "David W. Harks" Date: Sun, 1 Mar 2015 09:29:37 -0600 Subject: [PATCH 3/4] Tweak README for English --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5609b22..fbcd693 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # evervim.vim ## description: -edit evernote on vim. +Search, create, and edit notes on Evernote in vim! ## requires: * python From c0c08a3a66e837cae28d64f577d0138f39595f0c Mon Sep 17 00:00:00 2001 From: "David W. Harks" Date: Sun, 7 Jun 2015 15:53:53 -0500 Subject: [PATCH 4/4] Add support for Evernote To-Do tags --- plugin/py/markdownAndENML.py | 33 ++++++++++++++++++++-- plugin/py/markdownAndENML_test.py | 46 +++++++++++++++---------------- 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/plugin/py/markdownAndENML.py b/plugin/py/markdownAndENML.py index 3d8bae0..87277ad 100644 --- a/plugin/py/markdownAndENML.py +++ b/plugin/py/markdownAndENML.py @@ -5,7 +5,28 @@ import markdown import xml.sax.saxutils import re +from markdown.extensions import Extension +from markdown.inlinepatterns import Pattern +from markdown.util import etree +import logging +TODOPATTERN= r'\[(X| )\]' +class ENMLToDoPattern(Pattern): + + def handleMatch(self, m): + el = etree.Element("en-todo") + logging.debug("Groups: {}".format(m.groups())) + if m.group(2) == 'X': + el.set("checked", "true") + return el + + +class ENMLExtension(Extension): + + def extendMarkdown(self, md, md_globals): + + md.inlinePatterns.add( + 'enml', ENMLToDoPattern(TODOPATTERN), "') - self.assertEqual(lines[9], u'チェックボックス') - self.assertEqual(lines[10], u'') - self.assertEqual(lines[11], u'チェック済み') - self.assertEqual(lines[12], u'1. 数字付1') - self.assertEqual(lines[13], u'2. 同じく2') - self.assertEqual(lines[14], u'3. おまけに3') - self.assertEqual(lines[15], u'') - self.assertEqual(lines[16], u'1. list2-1') - self.assertEqual(lines[17], u'2. list2-2') - self.assertEqual(lines[18], u'') - self.assertEqual(lines[19], u'> インデント') - self.assertEqual(lines[20], u'> インデント2') + self.assertEqual(lines[8] , u'[ ] チェックボックス') + self.assertEqual(lines[9], u'[X] チェック済み') + self.assertEqual(lines[10], u'1. 数字付1') + self.assertEqual(lines[11], u'2. 同じく2') + self.assertEqual(lines[12], u'3. おまけに3') + self.assertEqual(lines[13], u'') + self.assertEqual(lines[14], u'1. list2-1') + self.assertEqual(lines[15], u'2. list2-2') + self.assertEqual(lines[16], u'') + self.assertEqual(lines[17], u'> インデント') + self.assertEqual(lines[18], u'> インデント2') + self.assertEqual(lines[19], u'') + self.assertEqual(lines[20], u'> > 2重インデント 2重インデント2') self.assertEqual(lines[21], u'') - self.assertEqual(lines[22], u'> > 2重インデント 2重インデント2') + self.assertEqual(lines[22], u'') self.assertEqual(lines[23], u'') - self.assertEqual(lines[24], u'') + self.assertEqual(lines[24], u'normal line') self.assertEqual(lines[25], u'') - self.assertEqual(lines[26], u'normal line') - self.assertEqual(lines[27], u'') - self.assertEqual(lines[28], u' def haruhi(self):') - self.assertEqual(lines[29], u' pass test ') - self.assertEqual(lines[30], u' > >') - self.assertEqual(lines[31], u'') - self.assertEqual(lines[32], u'### asuka.langley') - self.assertEqual(lines[33], u'test backtick') - self.assertEqual(lines[34], u'`import markdown`test') + self.assertEqual(lines[26], u' def haruhi(self):') + self.assertEqual(lines[27], u' pass test ') + self.assertEqual(lines[28], u' > >') + self.assertEqual(lines[29], u'') + self.assertEqual(lines[30], u'### asuka.langley') + self.assertEqual(lines[31], u'test backtick') + self.assertEqual(lines[32], u'`import markdown`test') # }}} if __name__ == '__main__':