2018-06-07 18:33:00 +02:00
|
|
|
;;; tools/wakatime/autoload.el -*- lexical-binding: t; -*-
|
|
|
|
|
2018-06-24 14:44:09 +02:00
|
|
|
(defvar +wakatime-api-file (concat doom-cache-dir "wakatime.el")
|
|
|
|
"Where the wakatime api key is cached.")
|
|
|
|
|
2018-06-07 18:33:00 +02:00
|
|
|
;;;###autoload
|
2018-06-13 09:50:09 +10:00
|
|
|
(add-hook 'doom-after-switch-buffer-hook #'+wakatime|autostart)
|
2018-06-07 18:33:00 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2018-06-24 14:44:09 +02:00
|
|
|
(advice-add 'after-find-file :before #'wakatime|autostart)
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +wakatime/setup ()
|
|
|
|
"Setup Wakatime in Emacs and start `global-wakatime-mode'.
|
|
|
|
|
|
|
|
This will prompt you for your api key. You only need to run this when your api
|
|
|
|
changes."
|
|
|
|
(interactive)
|
|
|
|
(when (y-or-n-p "No API key is registered. Open a browser on the wakatime api key page?")
|
|
|
|
(browse-url "https://wakatime.com/settings/api-key"))
|
|
|
|
(let ((api-key (read-string "Enter your wakatime API key: ")))
|
|
|
|
(unless api-key
|
|
|
|
(user-error "No api key was received."))
|
|
|
|
(setq wakatime-api-key api-key)
|
|
|
|
(with-temp-file +wakatime-api-file
|
|
|
|
(princ `(setq wakatime-api-key ,api-key)
|
|
|
|
(current-buffer)))
|
|
|
|
(require 'wakatime-mode)
|
|
|
|
(global-wakatime-mode +1)))
|
2018-06-13 09:50:09 +10:00
|
|
|
|
|
|
|
;;;###autoload
|
2018-06-24 14:44:09 +02:00
|
|
|
(defun +wakatime|autostart (&rest _)
|
2018-06-07 18:33:00 +02:00
|
|
|
"Initialize wakatime (if `wakatime-api-key' is set, otherwise no-op with a
|
|
|
|
warning)."
|
2018-06-11 12:28:03 +10:00
|
|
|
(interactive)
|
2018-06-24 14:44:09 +02:00
|
|
|
(when (and (not (bound-and-true-p wakatime-api-key))
|
|
|
|
(file-exists-p +wakatime-api-file))
|
|
|
|
(load +wakatime-api-file nil t))
|
|
|
|
(if (bound-and-true-p wakatime-api-key)
|
2018-06-07 18:33:00 +02:00
|
|
|
(global-wakatime-mode +1)
|
2018-06-24 14:44:09 +02:00
|
|
|
(message "wakatime-mode isn't set up. Run `M-x +wakatime/start' to do so (only necessary once)."))
|
|
|
|
;;
|
|
|
|
(remove-hook 'doom-after-switch-buffer-hook #'+wakatime|autostart)
|
|
|
|
(advice-remove 'after-find-file #'wakatime|autostart))
|