mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-21 18:40:26 +10:00
Adding 12-month calendar to Doom Emacs; clickable date widget on xmobar.
This commit is contained in:
@@ -3,6 +3,65 @@
|
||||
:desc "List bookmarks" "L" #'list-bookmarks
|
||||
:desc "Save current bookmarks to bookmark file" "w" #'bookmark-save))
|
||||
|
||||
;; https://stackoverflow.com/questions/9547912/emacs-calendar-show-more-than-3-months
|
||||
(defun dt/year-calendar (&optional year)
|
||||
(interactive)
|
||||
(require 'calendar)
|
||||
(let* (
|
||||
(current-year (number-to-string (nth 5 (decode-time (current-time)))))
|
||||
(month 0)
|
||||
(year (if year year (string-to-number (format-time-string "%Y" (current-time))))))
|
||||
(switch-to-buffer (get-buffer-create calendar-buffer))
|
||||
(when (not (eq major-mode 'calendar-mode))
|
||||
(calendar-mode))
|
||||
(setq displayed-month month)
|
||||
(setq displayed-year year)
|
||||
(setq buffer-read-only nil)
|
||||
(erase-buffer)
|
||||
;; horizontal rows
|
||||
(dotimes (j 4)
|
||||
;; vertical columns
|
||||
(dotimes (i 3)
|
||||
(calendar-generate-month
|
||||
(setq month (+ month 1))
|
||||
year
|
||||
;; indentation / spacing between months
|
||||
(+ 5 (* 25 i))))
|
||||
(goto-char (point-max))
|
||||
(insert (make-string (- 10 (count-lines (point-min) (point-max))) ?\n))
|
||||
(widen)
|
||||
(goto-char (point-max))
|
||||
(narrow-to-region (point-max) (point-max)))
|
||||
(widen)
|
||||
(goto-char (point-min))
|
||||
(setq buffer-read-only t)))
|
||||
|
||||
(defun dt/scroll-year-calendar-forward (&optional arg event)
|
||||
"Scroll the yearly calendar by year in a forward direction."
|
||||
(interactive (list (prefix-numeric-value current-prefix-arg)
|
||||
last-nonmenu-event))
|
||||
(unless arg (setq arg 0))
|
||||
(save-selected-window
|
||||
(if (setq event (event-start event)) (select-window (posn-window event)))
|
||||
(unless (zerop arg)
|
||||
(let* (
|
||||
(year (+ displayed-year arg)))
|
||||
(dt/year-calendar year)))
|
||||
(goto-char (point-min))
|
||||
(run-hooks 'calendar-move-hook)))
|
||||
|
||||
(defun dt/scroll-year-calendar-backward (&optional arg event)
|
||||
"Scroll the yearly calendar by year in a backward direction."
|
||||
(interactive (list (prefix-numeric-value current-prefix-arg)
|
||||
last-nonmenu-event))
|
||||
(dt/scroll-year-calendar-forward (- (or arg 1)) event))
|
||||
|
||||
(map! :leader
|
||||
:desc "Scroll year calendar backward" "<left>" #'dt/scroll-year-calendar-backward
|
||||
:desc "Scroll year calendar forward" "<right>" #'dt/scroll-year-calendar-forward)
|
||||
|
||||
(defalias 'year-calendar 'dt/year-calendar)
|
||||
|
||||
(setq centaur-tabs-set-bar 'over
|
||||
centaur-tabs-set-icons t
|
||||
centaur-tabs-gray-out-icons 'buffer
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* TABLE OF CONTENTS :toc:
|
||||
- [[#about-this-config][ABOUT THIS CONFIG]]
|
||||
- [[#bookmarks-and-buffers][BOOKMARKS AND BUFFERS]]
|
||||
- [[#calendar][CALENDAR]]
|
||||
- [[#centaur-tabs][CENTAUR-TABS]]
|
||||
- [[#dashboard][DASHBOARD]]
|
||||
- [[#configuring-dashboard][Configuring Dashboard]]
|
||||
@@ -52,6 +53,73 @@ Doom Emacs uses 'SPC b' for keybindings related to bookmarks and buffers. Bookm
|
||||
:desc "Save current bookmarks to bookmark file" "w" #'bookmark-save))
|
||||
#+END_SRC
|
||||
|
||||
* CALENDAR
|
||||
Let's make a 12-month calendar available. Nice to have so that when we click on time/date in xmobar, we get a nice 12-month calendar to view.
|
||||
|
||||
This is a modification of: http://homepage3.nifty.com/oatu/emacs/calendar.html
|
||||
See also: https://stackoverflow.com/questions/9547912/emacs-calendar-show-more-than-3-months
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
;; https://stackoverflow.com/questions/9547912/emacs-calendar-show-more-than-3-months
|
||||
(defun dt/year-calendar (&optional year)
|
||||
(interactive)
|
||||
(require 'calendar)
|
||||
(let* (
|
||||
(current-year (number-to-string (nth 5 (decode-time (current-time)))))
|
||||
(month 0)
|
||||
(year (if year year (string-to-number (format-time-string "%Y" (current-time))))))
|
||||
(switch-to-buffer (get-buffer-create calendar-buffer))
|
||||
(when (not (eq major-mode 'calendar-mode))
|
||||
(calendar-mode))
|
||||
(setq displayed-month month)
|
||||
(setq displayed-year year)
|
||||
(setq buffer-read-only nil)
|
||||
(erase-buffer)
|
||||
;; horizontal rows
|
||||
(dotimes (j 4)
|
||||
;; vertical columns
|
||||
(dotimes (i 3)
|
||||
(calendar-generate-month
|
||||
(setq month (+ month 1))
|
||||
year
|
||||
;; indentation / spacing between months
|
||||
(+ 5 (* 25 i))))
|
||||
(goto-char (point-max))
|
||||
(insert (make-string (- 10 (count-lines (point-min) (point-max))) ?\n))
|
||||
(widen)
|
||||
(goto-char (point-max))
|
||||
(narrow-to-region (point-max) (point-max)))
|
||||
(widen)
|
||||
(goto-char (point-min))
|
||||
(setq buffer-read-only t)))
|
||||
|
||||
(defun dt/scroll-year-calendar-forward (&optional arg event)
|
||||
"Scroll the yearly calendar by year in a forward direction."
|
||||
(interactive (list (prefix-numeric-value current-prefix-arg)
|
||||
last-nonmenu-event))
|
||||
(unless arg (setq arg 0))
|
||||
(save-selected-window
|
||||
(if (setq event (event-start event)) (select-window (posn-window event)))
|
||||
(unless (zerop arg)
|
||||
(let* (
|
||||
(year (+ displayed-year arg)))
|
||||
(dt/year-calendar year)))
|
||||
(goto-char (point-min))
|
||||
(run-hooks 'calendar-move-hook)))
|
||||
|
||||
(defun dt/scroll-year-calendar-backward (&optional arg event)
|
||||
"Scroll the yearly calendar by year in a backward direction."
|
||||
(interactive (list (prefix-numeric-value current-prefix-arg)
|
||||
last-nonmenu-event))
|
||||
(dt/scroll-year-calendar-forward (- (or arg 1)) event))
|
||||
|
||||
(map! :leader
|
||||
:desc "Scroll year calendar backward" "<left>" #'dt/scroll-year-calendar-backward
|
||||
:desc "Scroll year calendar forward" "<right>" #'dt/scroll-year-calendar-forward)
|
||||
|
||||
(defalias 'year-calendar 'dt/year-calendar)
|
||||
#+end_src
|
||||
|
||||
* CENTAUR-TABS
|
||||
To use tabs in Doom Emacs, be sure to uncomment "tabs" in Doom's init.el. Displays tabs at the top of the window similar to tabbed web browsers such as Firefox. I don't actually use tabs in Emacs. I placed this in my config to help others who may want tabs. In the default configuration of Doom Emacs, 'SPC t' is used for "toggle" keybindings, so I choose 'SPC t c' to toggle centaur-tabs. The "g" prefix for keybindings is used for a bunch of evil keybindings in Doom, but "g" plus the arrow keys were not used, so I thought I would bind those for tab navigation. But I did leave the default "g t" and "g T" intact if you prefer to use those for centaur-tabs-forward/backward.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user