pauldub / activity-watch-mode

Emacs plugin for automatic time tracking and metrics generated from your programming activity.
https://activitywatch.net
70 stars 9 forks source link

activity-watch-mode assumes projectile is running and crashed if it is not #4

Closed freemin7 closed 4 years ago

freemin7 commented 5 years ago

Running activity-watch with the fixes from #3 and #2 and the setup described in #2 results in the following stack-trace.

Debugger entered--Lisp error: (void-function projectile-project-name)
  (projectile-project-name)
  (let ((project-name (projectile-project-name)) (file-name (buffer-file-name (current-buffer)))) (list (cons 'timestamp (ert--format-time-iso8601 time)) '(duration . 0) (list 'data (cons 'language (if (activity-watch--s-blank (symbol-name major-mode)) "unknown" major-mode)) (cons 'project (if (activity-watch--s-blank project-name) "unknown" project-name)) (cons 'file (if (activity-watch--s-blank file-name) "unknown" file-name)))))
  activity-watch--create-heartbeat((23741 49688 3956 98000))
  (activity-watch--send-heartbeat (activity-watch--create-heartbeat (current-time)))
  (progn (setq activity-watch-last-file-path current-file-path) (setq activity-watch-last-heartbeat-time now) (activity-watch--send-heartbeat (activity-watch--create-heartbeat (current-time))))
  (if (or (not (string= (or activity-watch-last-file-path "") current-file-path)) (< time-delta now)) (progn (setq activity-watch-last-file-path current-file-path) (setq activity-watch-last-heartbeat-time now) (activity-watch--send-heartbeat (activity-watch--create-heartbeat (current-time)))))
  (let ((now (float-time)) (current-file-path (buffer-file-name (current-buffer))) (time-delta (+ (or activity-watch-last-heartbeat-time 0) activity-watch-max-heartbeat-per-sec))) (if (or (not (string= (or activity-watch-last-file-path "") current-file-path)) (< time-delta now)) (progn (setq activity-watch-last-file-path current-file-path) (setq activity-watch-last-heartbeat-time now) (activity-watch--send-heartbeat (activity-watch--create-heartbeat (current-time))))))
  activity-watch--call()
  (progn (activity-watch--call))
  (if (and (buffer-file-name (current-buffer)) (not (auto-save-file-name-p (buffer-file-name (current-buffer))))) (progn (activity-watch--call)))
  activity-watch--save()
  apply(activity-watch--save nil)
  timer-event-handler([t 23741 49690 0 2 activity-watch--save nil nil 0])

Could we check whether projectile is running/loaded before calling projectile functions?

Workaround: Run projectile for example by adding _ to init.el:

(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
pauldub commented 5 years ago

Hello @freemin7 I have thought about the problem and implemented a work around in the form of a new option.

You can see the work here: https://github.com/pauldub/activity-watch-mode/pull/6

I'm not sure what default function would be a good fit in case projectile is not available.

freemin7 commented 5 years ago

Maybe

filename - mayor mode is good. Some simple googling yielded this code: (buffer-file-name (window-buffer (minibuffer-selected-window))) and https://stackoverflow.com/questions/2238418/emacs-lisp-how-to-get-buffer-major-mode/22460428#22460428

pauldub commented 5 years ago

We already send the file name with each heartbeat so leaving the project as unknown maybe the best default.

freemin7 commented 5 years ago

Yeah, leave it as unknown.