2018-06-07 18:33:00 +02:00
|
|
|
;;; tools/wakatime/autoload.el -*- lexical-binding: t; -*-
|
|
|
|
|
2018-06-26 17:55:20 +02:00
|
|
|
(defvar +wakatime-home (concat doom-cache-dir "wakatime/")
|
|
|
|
"Path to the directory where wakatime files are stored.")
|
|
|
|
|
2018-06-24 23:22:25 +02:00
|
|
|
(defvar +wakatime-hide-filenames nil
|
|
|
|
"If non-nil, obfuscate files and only show what projects you're working on.")
|
|
|
|
|
2018-06-07 18:33:00 +02:00
|
|
|
;;;###autoload
|
2019-07-23 00:01:13 +02:00
|
|
|
(add-hook 'doom-init-modules-hook #'+wakatime-delayed-autostart-h)
|
2018-06-24 14:44:09 +02:00
|
|
|
|
|
|
|
;;;###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."))
|
|
|
|
(require 'wakatime-mode)
|
2018-06-26 18:01:47 +02:00
|
|
|
(customize-set-variable 'wakatime-api-key api-key)
|
|
|
|
(customize-save-customized)
|
2018-06-25 19:38:32 +02:00
|
|
|
(unless (or (and wakatime-cli-path (file-executable-p wakatime-cli-path))
|
|
|
|
(not (equal (wakatime-find-binary "wakatime") "wakatime")))
|
|
|
|
(user-error "Couldn't find wakatime executable (%s)"
|
|
|
|
(or wakatime-cli-path "wakatime")))
|
2018-06-24 23:03:17 +02:00
|
|
|
(global-wakatime-mode +1)
|
|
|
|
(message "Wakatime enabled. You're good to go!")))
|
2018-06-13 09:50:09 +10:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-23 00:01:13 +02:00
|
|
|
(defun +wakatime-autostart-h (&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-27 02:52:06 +02:00
|
|
|
(require 'wakatime-mode)
|
|
|
|
(if (not wakatime-api-key)
|
2018-06-26 17:55:20 +02:00
|
|
|
(message "wakatime-mode isn't set up. Run `M-x +wakatime/setup' to do so.")
|
|
|
|
(when +wakatime-home
|
|
|
|
(unless (file-directory-p +wakatime-home)
|
|
|
|
(make-directory +wakatime-home t)))
|
|
|
|
(global-wakatime-mode +1))
|
2018-06-24 14:44:09 +02:00
|
|
|
;;
|
2019-07-23 00:01:13 +02:00
|
|
|
(remove-hook 'doom-switch-buffer-hook #'+wakatime-autostart-h)
|
|
|
|
(advice-remove 'after-find-file #'+wakatime-autostart-h))
|
2018-06-24 22:33:30 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2019-07-23 00:01:13 +02:00
|
|
|
(defun +wakatime-delayed-autostart-h (&rest _)
|
2018-06-24 22:33:30 +02:00
|
|
|
"Lazily initialize `wakatime-mode' until the next time you switch buffers or
|
|
|
|
open a file."
|
2019-07-23 00:01:13 +02:00
|
|
|
(add-hook 'doom-switch-buffer-hook #'+wakatime-autostart-h)
|
2018-06-24 22:33:30 +02:00
|
|
|
;; this is necessary in case the user opens emacs with file arguments
|
2019-07-23 00:01:13 +02:00
|
|
|
(advice-add 'after-find-file :before #'+wakatime-autostart-h))
|
2018-06-24 23:22:25 +02:00
|
|
|
|
2019-07-23 17:24:56 +02:00
|
|
|
(defadvice! +wakatime--append-options-a (ret)
|
2018-06-26 17:55:20 +02:00
|
|
|
"Modifies the wakatime command string so that `+wakatime-hide-filenames' and
|
|
|
|
`+wakatime-home' are respected."
|
2019-07-23 00:01:13 +02:00
|
|
|
:filter-return #'wakatime-client-command
|
2018-06-26 17:55:20 +02:00
|
|
|
(concat (when +wakatime-home
|
|
|
|
(format "WAKATIME_HOME=%s " (shell-quote-argument +wakatime-home)))
|
|
|
|
ret
|
|
|
|
(if +wakatime-hide-filenames " --hide-filenames")))
|