-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtog.el
147 lines (117 loc) · 3.96 KB
/
tog.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
;;; tog.el --- NLP data tagging utilities -*- lexical-binding: t; -*-
;; Copyright (c) 2019 Abhinav Tushar
;; Author: Abhinav Tushar <[email protected]>
;; Version: 0.3.3
;; Package-Requires: ((emacs "26") (ov "1.0.6") (s "1.12.0") (f "0.20.0") (dash "2.15.0") (helm "3.2"))
;; URL: https://github.com/lepisma/tog
;;; Commentary:
;; NLP data tagging utilities
;; This file is not a part of GNU Emacs.
;;; License:
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(require 'cl-lib)
(require 'f)
(require 's)
(require 'tog-base)
(require 'tog-hl)
(require 'tog-input)
(require 'tog-io)
(require 'tog-parse)
(require 'tog-player)
(require 'tog-progress)
(require 'tog-timer)
(require 'tog-utils)
(defcustom tog-buffer-name "*tog*"
"Name of the tagging buffer. This is the shared buffer for all
kind of tagging. Note that only one kind of tagging can happen at
a given time.")
(defcustom tog-nav-hook nil
"Hook for any navigation event.")
(defcustom tog-annotate-hook (list #'tog-timer-update)
"Hook after a tag is applied.")
(defvar tog-loader nil
"Data loader for current task")
(defmacro deftog-nav (name lambda-list docstring &rest body)
"Macro for creating interactive navigation command. This makes
sure that the current item is re-rendered and navigation hooks
are called."
(declare (indent defun))
`(defun ,name ,lambda-list
,docstring
(interactive)
,@body
(tog-show (oref tog-loader :current-item))
(run-hooks 'tog-nav-hook)))
(deftog-nav tog-goto (idx)
"Jump to idx item for tagging. Boundary handling is done in
this function so the caller need not worry about anything other
+/-."
(tog-io-goto tog-loader idx))
(deftog-nav tog-next ()
"Go to next item for tagging."
(tog-io-next tog-loader))
(deftog-nav tog-prev ()
"Go to previous item for tagging."
(tog-io-prev tog-loader))
(deftog-nav tog-next-untagged ()
"Go to next item which is untagged, ignoring current one."
(tog-io-next-untagged tog-loader))
(deftog-nav tog-prev-untagged ()
"Go to previous item which is untagged, ignoring current one."
(tog-io-prev-untagged tog-loader))
(deftog-nav tog-last-tagged ()
"Go to the last tagged item"
(tog-io-last-tagged tog-loader))
(defun tog-save-tags ()
(interactive)
(tog-io-save-tags tog-loader))
(defun tog-load-tags ()
(interactive)
(tog-io-load-tags tog-loader))
;;;###autoload
(define-derived-mode tog-mode org-mode "tog"
"Major mode for togging."
:after-hook (setq header-line-format '(:eval (tog-progress-build-header tog-loader)))
(read-only-mode))
;;;###autoload
(defun tog ()
"Start tagging."
(interactive)
(if (null tog-loader)
(message "tog-loader is null. Try creating a loader.")
(tog-timer-start)
(tog-next)))
(defun tog-tag ()
"Command to initiate tag collection for current tog-item."
(interactive)
(with-current-tog-item
(tog-annotate current-item)
(tog-show current-item)))
(defun tog-clear ()
"Command to clear tag for current item."
(interactive)
(with-current-tog-item
(tog-clear-tag current-item)
(tog-show current-item)))
;;;###autoload
(defun tog-quit ()
"Exit and cleanup. We don't save before exiting by default
since this might do bad things to tag file because of certain
screw ups while tagging."
(interactive)
(when (get-buffer tog-buffer-name)
(kill-buffer tog-buffer-name))
(setq tog-loader nil)
(tog-timer-reset))
(provide 'tog)
;;; tog.el ends here