al-calendar.el 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ;;; al-calendar.el --- Additional functionality for calendar, diary, etc.
  2. ;; Copyright © 2014-2016, 2018 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'calendar)
  17. (require 'solar)
  18. (require 'al-misc)
  19. (defvar al/calendar-date-display-form calendar-date-display-form
  20. "Variable used in `al/diary-insert-entry'.")
  21. ;;;###autoload
  22. (defun al/diary-insert-entry (arg &optional event)
  23. "Replacement for `diary-insert-entry'.
  24. Use `al/calendar-date-display-form' for inserted entry instead
  25. of `calendar-date-display-form'."
  26. (interactive
  27. (list current-prefix-arg last-nonmenu-event))
  28. (let ((calendar-date-display-form al/calendar-date-display-form))
  29. (diary-insert-entry arg event)))
  30. ;;;###autoload
  31. (defun al/diary-file ()
  32. "Visit `diary-file'."
  33. (interactive)
  34. (find-file diary-file))
  35. ;;; Sunrise, sunset
  36. (defun al/solar-time-string (&optional type)
  37. "Return time string of today's sunrise or sunset.
  38. TYPE should be a symbol `sunrise' (default) or `sunset'."
  39. (if (and calendar-latitude
  40. calendar-longitude)
  41. (let* ((solar-data (solar-sunrise-sunset (calendar-current-date)))
  42. (solar-time (funcall (if (eq type 'sunset) #'cadr #'car)
  43. solar-data)))
  44. (concat (format-time-string "%F ")
  45. (apply #'solar-time-string solar-time)))
  46. (al/warning "\
  47. Set `calendar-latitude' and `calendar-longitude' at first!")))
  48. (defun al/solar-time (&optional type)
  49. "Return time value of today's sunrise or sunset.
  50. See `al/solar-time-string' for the meaning of TYPE."
  51. (date-to-time (al/solar-time-string type)))
  52. (provide 'al-calendar)
  53. ;;; al-calendar.el ends here