forked from MFreidank/AnkiVim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Moritz Rocholl
committed
Feb 16, 2018
1 parent
1deed5c
commit 5530d45
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" Using VIM to generate textfiles which are directly anki-importable. """ | ||
|
||
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 | ||
import argparse | ||
from os import getenv | ||
from os.path import abspath, join as path_join | ||
|
||
from ankivim.cards import create_card | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Use VIM (or the editor of your choice) " | ||
"to comfortably and quickly write textfiles " | ||
"which are directly anki-importable. " | ||
) | ||
|
||
parser.add_argument( | ||
"deck", help='Name of the deck to write cards for.' | ||
) | ||
|
||
parser.add_argument( | ||
"-e", "--editor", | ||
help="Force using EDITOR, overwriting default behaviours.\n" | ||
"If set to anything else but vim(1), '--editor-args' must " | ||
"also be specified.\n" | ||
"Default behaviour for editor choices:\n" | ||
"1. read environment variable $EDITOR \n" | ||
"2. fall back to vim(1) if $EDITOR is not set.", | ||
action="store", dest="editor", default=None | ||
) | ||
|
||
parser.add_argument( | ||
"--editor-args", | ||
help="Arguments to pass to the editor upon calling. " | ||
"Must be specified (simplest case: empty string) when '--editor' " | ||
"is set.\n" | ||
'Expected format:"--arg1 VALUE1 --arg2 VALUE2 ..."\t\n' | ||
"(mind the quotes!)", | ||
action="store", dest="editor_args", default=None | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
if args.editor is not None and args.editor_args is None: | ||
raise ValueError() | ||
|
||
if args.editor is None: | ||
editor = getenv("EDITOR", "vim") | ||
else: | ||
editor = args.editor | ||
|
||
if args.editor_args is None: | ||
# editor args below target vim 7.4, overwrite for other editor choices. | ||
editor_args = ( | ||
# set cursor below headers | ||
"-c {}".format(r'/\v\%\n\zs(^$|^[^\%]{1}.*$)'), | ||
# use anki_vim snippets | ||
"-c set filetype=anki_vim", | ||
# latex syntax highlighting | ||
"-c set syntax=tex" | ||
) | ||
else: | ||
if args.editor_args == "": | ||
editor_args = () | ||
else: | ||
editor_args = args.editor_args.split(",") | ||
|
||
deckpath = path_join(abspath("./decks"), args.deck) | ||
|
||
content_added = True | ||
while content_added: | ||
# If a card is closed without content or changes, stop | ||
content_added = create_card( | ||
deckpath=deckpath, editor=editor, editor_args=editor_args | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
url="https://github.com/MFreidank/VimForAnki", | ||
download_url="https://github.com/MFreidank/VimForAnki/tarball/{}".format(VERSION), | ||
description="Use vim to rapidly write textfiles immediately importable into anki(1).", | ||
scripts=['script/anki-vim'], | ||
long_description=long_description, | ||
author="Moritz Freidank", | ||
author_email="[email protected]", | ||
|