Skip to content

Instantly share code, notes, and snippets.

@rougier
Created January 6, 2023 18:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rougier/078a570af2739d6ff1311b0e6432eca9 to your computer and use it in GitHub Desktop.
Save rougier/078a570af2739d6ff1311b0e6432eca9 to your computer and use it in GitHub Desktop.
Emacs / Generate a month view
(defun org-calendar-face (date)
'default)
(defun org-calendar-generate-month (year month)
(let* ((first (calendar-day-of-week (list month 1 year)))
(first (+ (mod (+ (- first 1) 7) 7) 1)) ;; Week starts on Monday
(last (+ first (calendar-last-day-of-month month year)))
(days ""))
(dotimes (row 6)
(dotimes (col 7)
(let* ((index (+ 1 col (* row 7)))
(day (- index first -1))
(date (encode-time 0 0 0 day month year)))
(if (or (< index first) (>= index last))
(setq days (concat days " "))
(setq days (concat days
(propertize (format "%2d " day)
'face (org-calendar-face date)))))))
(when (< row 5)
(setq days (concat days "\n"))))
(concat
(propertize
(s-center 20 (format "%s %d" (calendar-month-name month) year))
'face 'org-calendar-month-header)
" \n"
(propertize
(mapconcat #'(lambda (day)
(substring (calendar-day-name day t t) 0 2))
'(1 2 3 4 5) " ")
'face 'calendar-weekday-header)
" "
(propertize
(mapconcat #'(lambda (day)
(substring (calendar-day-name day t t) 0 2))
'(6 0) " ")
'face 'calendar-weekend-header)
" \n"
days)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment