-
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
Showing
4 changed files
with
68 additions
and
8 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 |
---|---|---|
@@ -1,5 +1,12 @@ | ||
# klog for Sublime Text | ||
|
||
This packages provides syntax-highlighting and some sensible default settings for working with [klog](https://klog.jotaen.net) files. | ||
This packages provides support for working with [klog time tracking](https://klog.jotaen.net) files in the Sublime Text editor: | ||
|
||
- Syntax highlighting | ||
+ If you use the Mariana or Monokai theme, it also assigns meaningful colouring. | ||
- Smart completion for inserting the current date or time. For example: | ||
+ Typing `today` completes to the current date | ||
+ Typing `now` completes to the current time | ||
- A few sensible default settings for the `.klg` file format | ||
|
||
![A klog file with sample data](resources/example.png) |
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
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
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,58 @@ | ||
import sublime | ||
import sublime_plugin | ||
import datetime | ||
import re | ||
|
||
|
||
INDENT_PATTERN = re.compile('^( {2,4}|\t)') | ||
NOT_INDENTED_PATTERN = re.compile('^[^\s]$') | ||
|
||
|
||
def complete(trigger, value, details): | ||
return sublime.CompletionItem( | ||
trigger, | ||
annotation=value, | ||
completion=value, | ||
completion_format=sublime.COMPLETION_FORMAT_SNIPPET, | ||
kind=(sublime.KIND_ID_AMBIGUOUS, '⏱', 'klog'), | ||
details=details, | ||
) | ||
|
||
|
||
def date_completions(): | ||
DATEFMT = '%Y-%m-%d' | ||
today = datetime.datetime.now() | ||
yesterday = today - datetime.timedelta(days=1) | ||
tomorrow = today + datetime.timedelta(days=1) | ||
|
||
return sublime.CompletionList([ | ||
complete('today', today.strftime(DATEFMT), 'Insert today’s date'), | ||
complete('yesterday', yesterday.strftime(DATEFMT), 'Insert yesterday’s date'), | ||
complete('tomorrow', tomorrow.strftime(DATEFMT), 'Insert tomorrow’s date'), | ||
]) | ||
|
||
|
||
def time_completions(): | ||
TIMEFMT = '%H:%M' | ||
now = datetime.datetime.now() | ||
return sublime.CompletionList([ | ||
complete('now', now.strftime(TIMEFMT), 'Insert current time'), | ||
complete('start', now.strftime(TIMEFMT) + ' - ?', 'Insert open range'), | ||
]) | ||
|
||
|
||
class KlogEventListener(sublime_plugin.EventListener): | ||
def on_query_completions(self, view, prefix, locations): | ||
if not view.match_selector(locations[0], 'source.klog'): | ||
return | ||
|
||
cursor = view.line(view.sel()[0]) | ||
preceding_text = view.substr(cursor) | ||
|
||
# If the cursor is not indented | ||
if NOT_INDENTED_PATTERN.match(preceding_text): | ||
return date_completions() | ||
|
||
# If the cursor is on an indented line, offer times. | ||
if INDENT_PATTERN.match(preceding_text): | ||
return time_completions() |