Last active
May 4, 2026 22:51
-
-
Save hwpplayer1/e877465bec113b6af56a3e73daab8e6d to your computer and use it in GitHub Desktop.
Display History in Emacs Buffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Copyright (C) 2024 PSD Authors | |
| ;; | |
| ;; This program is free software: you can redistribute it and/or modify | |
| ;; it under the terms of the GNU Affero General Public License as published | |
| ;; by the Free Software Foundation, either version 3 of the License, or | |
| ;; (at your option) any later version. | |
| ;; | |
| ;; This program is distributed in the hope that it will be useful, | |
| ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| ;; GNU Affero General Public License for more details. | |
| ;; | |
| ;; You should have received a copy of the GNU Affero General Public License | |
| ;; along with this program. If not, see <https://gnu.org>. | |
| ;; 1. Basic Settings and Language Selection | |
| (setq system-time-locale "en_US.UTF-8") | |
| (setq display-time-interval 1) ;; ENSURES THE CLOCK UPDATES EVERY SECOND | |
| (display-time-mode 1) | |
| ;; 2. Appearance Definition | |
| (defface mode-line-clock-face | |
| '((t :foreground "yellow" :weight bold)) | |
| "Yellow face for the clock and date in the modeline.") | |
| ;; 3. Logging and Buffer Functions | |
| (defun log-current-time-to-history () | |
| "Adds the current time to the *display-history* buffer and keeps the last 1000 lines." | |
| (let ((current-time-string (format-time-string "%H:%M:%S | %Y.%m.%d | Week %V | %A | %Z"))) | |
| (with-current-buffer (get-buffer-create "*display-history*") | |
| (let ((inhibit-read-only t)) | |
| (save-excursion | |
| (goto-char (point-max)) | |
| (insert (concat "[" current-time-string "]\n")) | |
| ;; Limit buffer size to 1000 lines for performance | |
| (when (> (count-lines (point-min) (point-max)) 1000) | |
| (goto-char (point-min)) | |
| (forward-line (- (count-lines (point-min) (point-max)) 1000)) | |
| (delete-region (point-min) (point)))))))) | |
| (defun display-history () | |
| "Displays the time history buffer on the screen." | |
| (interactive) | |
| (display-buffer (get-buffer-create "*display-history*"))) | |
| ;; 4. Modeline Format | |
| (setq display-time-string-forms | |
| '((propertize (format-time-string "%H:%M:%S | %Y.%m.%d | Week %V | %A | %Z") | |
| 'face 'mode-line-clock-face))) | |
| ;; 5. Start Timers | |
| ;; Clear existing timers for a clean start | |
| (cancel-function-timers 'log-current-time-to-history) | |
| (run-at-time t 1 (lambda () | |
| (log-current-time-to-history) | |
| (force-mode-line-update t))) ;; 't' parameter forces update across all windows | |
| ;; 6. Shortcut Configuration: Control + F12 | |
| (global-set-key (kbd "C-<f12>") 'display-history) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment