A global minor mode for Emacs that writes org-clock status to a FIFO
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

org-clock-fifo.el 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;; org-clock-fifo.el -- Write org-clock status to a FIFO.
  2. ;; Copyright (C) 2019 Peter Jones <pjones@devalot.com>
  3. ;; Author: Peter Jones <pjones@devalot.com>
  4. ;; Homepage: https://github.com/pjones/org-clock-fifo
  5. ;; Package-Requires: ((emacs "24.4"))
  6. ;; Version: 0.1.0
  7. ;;
  8. ;; This file is not part of GNU Emacs.
  9. ;;; Commentary:
  10. ;;
  11. ;; This file defines a global minor mode called `org-clock-fifo-mode'.
  12. ;;
  13. ;; When active, this mode will write `org-clock' status messages to a
  14. ;; FIFO, creating the file if necessary. You can then have some other
  15. ;; tool, say a desktop panel, read the file to get the latest status.
  16. ;;; License:
  17. ;;
  18. ;; Permission is hereby granted, free of charge, to any person obtaining
  19. ;; a copy of this software and associated documentation files (the
  20. ;; "Software"), to deal in the Software without restriction, including
  21. ;; without limitation the rights to use, copy, modify, merge, publish,
  22. ;; distribute, sublicense, and/or sell copies of the Software, and to
  23. ;; permit persons to whom the Software is furnished to do so, subject to
  24. ;; the following conditions:
  25. ;;
  26. ;; The above copyright notice and this permission notice shall be
  27. ;; included in all copies or substantial portions of the Software.
  28. ;;
  29. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  32. ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  33. ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  34. ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  35. ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. ;;; Code:
  37. (require 'org-clock)
  38. (defcustom org-clock-fifo-filename
  39. (concat (file-name-as-directory user-emacs-directory) "org-clock-fifo")
  40. "The file name to use for the FIFO."
  41. :group 'org-clock
  42. :type 'string)
  43. (defvar org-clock-fifo-timer nil
  44. "Timer used to update the FIFO.")
  45. (defun org-clock-fifo-update ()
  46. "Update the FIFO."
  47. (unless (file-exists-p org-clock-fifo-filename)
  48. (call-process "mkfifo" nil nil nil org-clock-fifo-filename))
  49. (let ((inhibit-message t)
  50. (msg (if (org-clocking-p)
  51. (substring-no-properties org-mode-line-string)
  52. "")))
  53. (with-temp-buffer
  54. (insert (concat msg "\n"))
  55. (write-region nil nil org-clock-fifo-filename t)))
  56. (if (and (null org-clock-fifo-timer) (org-clocking-p))
  57. (setq org-clock-fifo-timer
  58. (run-at-time t 10 #'org-clock-fifo-update))
  59. (unless (org-clocking-p)
  60. (if org-clock-fifo-timer (cancel-timer org-clock-fifo-timer))
  61. (setq org-clock-fifo-timer nil))))
  62. (define-minor-mode org-clock-fifo-mode
  63. "A minor mode that writes `org-clock' status information to a FIFO."
  64. :global t
  65. (let ((hooks '( org-clock-in-hook
  66. org-clock-out-hook
  67. org-clock-cancel-hook )))
  68. (if org-clock-fifo-mode
  69. (progn
  70. (dolist (hook hooks)
  71. (add-hook hook #'org-clock-fifo-update))
  72. (org-clock-fifo-update))
  73. (dolist (hook hooks)
  74. (remove-hook hook #'org-clock-fifo-update)))))
  75. (provide 'org-clock-fifo)
  76. ;;; org-clock-fifo.el ends here