From 569d26fd88fada5c79acc2b6e2c3200b781ba981 Mon Sep 17 00:00:00 2001 From: Derek Taylor Date: Mon, 26 Apr 2021 13:58:12 -0500 Subject: [PATCH] Adding 12-month calendar to Doom Emacs; clickable date widget on xmobar. --- .config/doom/config.el | 59 ++++++++++++++++++++++++++++++++++ .config/doom/config.org | 68 ++++++++++++++++++++++++++++++++++++++++ .config/xmobar/xmobarrc0 | 2 +- .config/xmobar/xmobarrc1 | 2 +- .config/xmobar/xmobarrc2 | 2 +- 5 files changed, 130 insertions(+), 3 deletions(-) diff --git a/.config/doom/config.el b/.config/doom/config.el index e7dbf74..ca42a62 100644 --- a/.config/doom/config.el +++ b/.config/doom/config.el @@ -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" "" #'dt/scroll-year-calendar-backward + :desc "Scroll year calendar forward" "" #'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 diff --git a/.config/doom/config.org b/.config/doom/config.org index 72ad93a..f52c558 100644 --- a/.config/doom/config.org +++ b/.config/doom/config.org @@ -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" "" #'dt/scroll-year-calendar-backward + :desc "Scroll year calendar forward" "" #'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. diff --git a/.config/xmobar/xmobarrc0 b/.config/xmobar/xmobarrc0 index e89c3a8..60a1469 100755 --- a/.config/xmobar/xmobarrc0 +++ b/.config/xmobar/xmobarrc0 @@ -38,5 +38,5 @@ Config { font = "xft:Ubuntu:weight=bold:pixelsize=11:antialias=true:hinting=t ] , sepChar = "%" , alignSep = "}{" - , template = " | %UnsafeStdinReader% }{ | %uname% | %cpu% | %memory% | %disku% | %enp6s0% | %pacupdate% | %date% " + , template = " | %UnsafeStdinReader% }{ | %uname% | %cpu% | %memory% | %disku% | %enp6s0% | %pacupdate% | %date% " } diff --git a/.config/xmobar/xmobarrc1 b/.config/xmobar/xmobarrc1 index 5c7c8ec..db4b042 100755 --- a/.config/xmobar/xmobarrc1 +++ b/.config/xmobar/xmobarrc1 @@ -38,5 +38,5 @@ Config { font = "xft:Ubuntu:weight=bold:pixelsize=11:antialias=true:hinting=t ] , sepChar = "%" , alignSep = "}{" - , template = " | %UnsafeStdinReader% }{ | %uname% | %cpu% | %memory% | %disku% | %enp6s0% | %pacupdate% | %date% | %trayerpad%" + , template = " | %UnsafeStdinReader% }{ | %uname% | %cpu% | %memory% | %disku% | %enp6s0% | %pacupdate% | %date% | %trayerpad%" } diff --git a/.config/xmobar/xmobarrc2 b/.config/xmobar/xmobarrc2 index bb95d8f..b75580b 100755 --- a/.config/xmobar/xmobarrc2 +++ b/.config/xmobar/xmobarrc2 @@ -36,5 +36,5 @@ Config { font = "xft:Ubuntu:weight=bold:pixelsize=11:antialias=true:hinting=t ] , sepChar = "%" , alignSep = "}{" - , template = " | %UnsafeStdinReader% }{ | %uname% | %cpu% | %memory% | %disku% | %enp6s0% | %pacupdate% | %date% " + , template = " | %UnsafeStdinReader% }{ | %uname% | %cpu% | %memory% | %disku% | %enp6s0% | %pacupdate% | %date% " }