-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-time-metric.el
67 lines (57 loc) · 2.15 KB
/
git-time-metric.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
;;; git-time-metric.el --- Provide function to record time with gtm ( git time metric )
;; Copyright (C) 2018 Anton Sivolapov
;; This package uses the MIT License.
;; See the LICENSE file.
;; Author: Anton Sivolapov <anton.sivolapov@gmail.com>
;; Version: 1.0
;; Package-Requires: ()
;; Keywords: tools, gtm, productivity, time
;; URL: https://github.com/c301/gtm-emacs-plugin
;;; Commentary:
;;
;; This file provides `git-time-metric-record', which records time with gtm. Essentially it calls `gtm record [options] <file_name>'.
;;
;; Usage:
;; M-x git-time-metric-record
;;
;; To automatically record time after saving:
;; (Choose depending on your favorite mode.)
;;
;; (eval-after-load 'js-mode
;; '(add-hook 'js-mode-hook (lambda () (add-hook 'after-save-hook 'git-time-metric-record))))
;;
;; (eval-after-load 'js2-mode
;; '(add-hook 'js-mode-hook (lambda () (add-hook 'after-save-hook 'git-time-metric-record))))
;;
;; Or track all your files:
;;
;; (add-hook 'after-save-hook 'git-time-metric-record)
;;; Code:
(defgroup git-time-metric nil
"Record time to gtm with ‘git-time-metric-record’."
:link '(function-link git-time-metric-record)
:tag "Git Time Metric (gtm)"
:group 'tools)
(defcustom git-time-metric-executable "gtm"
"Set gtm executable to use."
:tag "Git Time Metric (gtm) Executable"
:type 'string)
(defcustom git-time-metric-executable-options nil
"Additional options to pass to gtm (e.g. “-status=false”)."
:tag "Git Time Metric (gtm) Options"
:type '(repeat string))
;;;###autoload
(defun git-time-metric-record()
"Record to gtm (git time metric), ie call ‘gtm record <file_name>’."
(interactive)
(unless buffer-file-name
(error "Git Time Metric requires a file-visiting buffer"))
(let ((gtm (executable-find git-time-metric-executable))
(options (append (list "record")
git-time-metric-executable-options
(list buffer-file-name))))
(unless gtm
(error "Executable ‘%s’ not found" git-time-metric-executable))
(apply 'call-process gtm nil "*gtm Errors*" nil options)))
(provide 'git-time-metric)
;;; git-time-metric.el ends here