How to make "todo" markdown in sublime text?
I am sublime text
migrating to with markdownediting from emacs orgmode
. With help markdownediting
, sublime excellent markdown. But I don't know how to make a TODO list and switch between TODO and DONE. Is there a way to do this? or does any plugin work well with markdownediting
?
source to share
I have installed the mdTodo plugin for Sublime text.
It works, but the TODO list shows up as a bulletin list (in html) on GitHub, which doesn't look very good.
I found that GitHub maintains a orgmode
-style TODO list :
https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments
https://github.com/blog/1825-task-lists-in-all-markdown-documents
Exploration of the solar system, 1950s - 1960s
- [] Mercury
- [x] Venus
- [x] Earth (orbit / moon)
- [x] Mars
- [] Jupiter
- [] Saturn
- [] Uranus
- [] Neptune
- [] Comet Haley
So, I changed the original code mdTodo
, makes it work with orgmode style TODO list.
Here is my modification: (mdTodo.py in package folder)
import sublime, sublime_plugin
from datetime import datetime
class ItodoBase(sublime_plugin.TextCommand):
def run(self, edit):
filename = self.view.file_name()
# list of allowed filetypes
allowed_filetypes = ('.md', '.markdown', '.mdown')
if filename is None or not filename.endswith(allowed_filetypes):
return False
self.runCommand(edit)
class NewCommand(ItodoBase):
def runCommand(self, edit):
for region in self.view.sel():
lines = self.view.lines(region)
lines.reverse()
for line in lines:
# don't add a newline when creating new item with cursor is at an empty line
if not line:
line_contents = '-'
self.view.insert(edit, line.begin(), line_contents)
# add a newline when creating new item when cursor is at another line
else:
line_contents = self.view.substr(line) + '\n-'
self.view.replace(edit, line, line_contents)
class CompleteCommand(ItodoBase):
def runCommand(self, edit):
for region in self.view.sel():
lines = self.view.lines(region)
lines.reverse()
for line in lines:
line_head = self.view.find("- \[[x ]\]", line.begin())
line_contents = self.view.substr(line).strip()
# prepend @done if item is ongoing
if line_contents.startswith("- [ ]"):
self.view.insert(edit, line.end(), " @done (%s)" % datetime.now().strftime("%Y-%m-%d %H:%M"))
self.view.replace(edit, line_head, "- [x]")
# undo @todo
elif line_contents.startswith('- [x]'):
subfix = self.view.find('(\s)*@done(.)+\)$', line.begin())
self.view.erase(edit, subfix)
self.view.replace(edit, line_head, "- [ ]")
I hope this would be useful for those who brought text from Emacs (org-mode) to Sublime.
Update
The default shortcut ctrl+shift+dconflicts with the duplicate line
default command .
Decision:
path_to_sublime\Sublime Text 3\Packages\mdTodo\Default (Windows).sublime-keymap
Comment this line
[ // iTodo plugin
{ "keys": ["ctrl+shift+d"], "command": "complete" }
]
and change it in your custom keywords file.
I tied it to:
{ "keys": ["ctrl+alt+d"], "command": "complete" }
source to share