From aacd40d6adbf9bfb510e40b7ddb93678e7cecbcd Mon Sep 17 00:00:00 2001 From: TCCQ Date: Wed, 9 Apr 2025 19:53:47 -0700 Subject: emacs to add single top header and move some (global) info there --- emacs/init.el | 9 ++++++-- emacs/site-lisp/exwm-pref.el | 38 +++++++++++++++------------------- emacs/site-lisp/modeline-config.el | 30 +++------------------------ emacs/site-lisp/my-funcs.el | 13 ++++++++++++ emacs/site-lisp/single-header.el | 42 ++++---------------------------------- 5 files changed, 43 insertions(+), 89 deletions(-) (limited to 'emacs') diff --git a/emacs/init.el b/emacs/init.el index 93a4552..4b47b96 100644 --- a/emacs/init.el +++ b/emacs/init.el @@ -341,6 +341,8 @@ ;; (use-package tempel-collection ;; :after tempel) +(use-package magit) + (use-package which-key :init (which-key-mode)) @@ -418,8 +420,10 @@ (use-package eat :init - (add-hook 'eshell-load-hook #'eat-eshell-mode) - (add-hook 'eshell-load-hook #'eat-eshell-visual-command-mode)) + (eat-eshell-mode) + (eat-eshell-visual-command-mode)) + +(use-package hl-todo) ;; file browser (use-package treemacs @@ -446,6 +450,7 @@ (require 'coding-config) (require 'modeline-config) (require 'general-text) +(require 'single-header) (require 'exwm-pref) (require 'irc-config) diff --git a/emacs/site-lisp/exwm-pref.el b/emacs/site-lisp/exwm-pref.el index f03711c..c6d51d1 100644 --- a/emacs/site-lisp/exwm-pref.el +++ b/emacs/site-lisp/exwm-pref.el @@ -27,29 +27,20 @@ (setq exwm-manage-force-tiling t) + (defun b3n-exwm-set-buffer-name () - (if (and exwm-title (string-match "\\`http[^ ]+" exwm-title)) - (let ((url (match-string 0 exwm-title))) - (setq-local buffer-file-name url) - (setq-local exwm-title (replace-regexp-in-string - (concat (regexp-quote url) " - ") - "" - exwm-title)) - (setq-local exwm-title (replace-regexp-in-string - " - Mozilla Firefox" - "" - exwm-title)))) - - (setq-local exwm-title - (concat - exwm-class-name - "<" - ;; (if (<= (length exwm-title) exwm-title-length) - exwm-title - ;; (concat (substring exwm-title 0 exwm-title-length) "…")) - ">")) - - (exwm-workspace-rename-buffer exwm-title)) + (if exwm-title + (let* ((shortened-title (replace-regexp-in-string + " - Mozilla Firefox" + "" + exwm-title)) + (class-and-title (concat + exwm-class-name + "<" + shortened-title + ">"))) + (setq-local exwm-title class-and-title) + (exwm-workspace-rename-buffer exwm-title)))) (add-hook 'exwm-update-class-hook 'b3n-exwm-set-buffer-name) (add-hook 'exwm-update-title-hook 'b3n-exwm-set-buffer-name) @@ -189,6 +180,9 @@ ;; (start-process-shell-command command nil command))) ;; browser ([?\s-e] . (lambda () + (interactive) + (start-process-shell-command "vimb" nil "vimb"))) + ([?\s-E] . (lambda () (interactive) (start-process-shell-command "firefox" nil "firefox"))) ;; ([?\M-e] . (lambda () diff --git a/emacs/site-lisp/modeline-config.el b/emacs/site-lisp/modeline-config.el index b74a15d..5b1f7e5 100644 --- a/emacs/site-lisp/modeline-config.el +++ b/emacs/site-lisp/modeline-config.el @@ -2,9 +2,6 @@ (provide 'modeline-config) -;; (require 'battery) -;; (display-battery-mode 1) - (use-package doom-modeline :init (doom-modeline-mode 1)) @@ -14,30 +11,9 @@ :custom (minions-prominent-modes '(persp-mode auto-fill-mode eldoc-mode eglot-mode lsp-mode))) -(require 'time) -(setq display-time-day-and-date t) -;; Set up the time timer. -(defun enable-display-time-backend () - "Do the internal bit of `display-time-mode` but without adding it to the -global mode string" - (and display-time-timer (cancel-timer display-time-timer)) - (setq display-time-timer nil) - (setq display-time-string "") - (setq display-time-load-average display-time-default-load-average) - (progn - ;; (or (memq 'display-time-string global-mode-string) - ;; (setq global-mode-string - ;; (append global-mode-string '(display-time-string)))) - ;; Set up the time timer. - (setq display-time-timer - (run-at-time t display-time-interval - 'display-time-event-handler)) - ;; Make the time appear right away. - (display-time-update))) - -;; (enable-display-time-backend) -(display-time-mode 1) -;; there is more in the single-header file +(setq-default global-mode-string '("" (:eval (concat (with-face (format " [%s] " (shorten-path default-directory)) + :weight 'bold + :foreground "green2"))))) ;; ----------------------------------------------------------------------------- ;; telephone line stuff diff --git a/emacs/site-lisp/my-funcs.el b/emacs/site-lisp/my-funcs.el index 8bed290..01bf5cc 100644 --- a/emacs/site-lisp/my-funcs.el +++ b/emacs/site-lisp/my-funcs.el @@ -143,3 +143,16 @@ BEG and END define the region." (defun dired-do-find-marked-files () (interactive) (seq-do 'find-file (dired-get-marked-files))) + +(defun shorten-path (path) + "Shortens each directory in PATH except for the last directory to its first character." + (let* ((components (split-string path "/")) ; Split the path into components + (last-component (-last (lambda (s) (not (string-empty-p s))) components)) ; Extract the last component + (shortened-components ; Shorten all components except the last + (mapcar (lambda (comp) + (if (or (string-equal comp last-component) (string-empty-p comp)) + comp + (substring comp 0 1))) + components))) + (mapconcat 'identity shortened-components "/"))) ; Recombine components into a path + diff --git a/emacs/site-lisp/single-header.el b/emacs/site-lisp/single-header.el index 1196ea0..796a637 100755 --- a/emacs/site-lisp/single-header.el +++ b/emacs/site-lisp/single-header.el @@ -1,3 +1,5 @@ +(provide 'single-header) + (defvar single-header--current-header-buffer nil "Read the name") (defvar single-header-format '(make-header-info-string) "evaluated to fill the header") @@ -9,23 +11,6 @@ (add-face-text-property 0 (length str) face-plist t str) str) -;; disable normal emms-state and move it to the header -;; (require 'emms-state) -;; (setq single-header-emms-state-format-string -;; '(emms-state -;; (" " emms-state -;; (emms-state-current-playing-time -;; (" " -;; (:propertize emms-state-current-playing-time -;; face emms-state-current-playing-time))) -;; (emms-state-total-playing-time -;; ("(" -;; (:propertize emms-state-total-playing-time -;; face emms-state-total-playing-time) -;; ")")) -;; emms-mode-line-string))) -;; (setq emms-state-mode-line-string "") - (defun make-header-info-string () "generates the mode line string that contains all the info to the right" (let ((win (when (buffer-live-p single-header--current-header-buffer) @@ -45,7 +30,6 @@ :foreground "#00ced1") (with-face (battery-format "[%b%p%%] " (and battery-status-function (funcall battery-status-function))) :weight 'bold) - ;; (format-mode-line single-header-emms-state-format-string) ))) (setq str (concat str (cond (win (make-string @@ -54,23 +38,6 @@ )) (with-face str 'single-header))) - -(defun shorten-path (path) - "Shortens each directory in PATH except for the last directory to its first character." - (let* ((components (split-string path "/")) ; Split the path into components - (last-component (-last (lambda (s) (not (string-empty-p s))) components)) ; Extract the last component - (shortened-components ; Shorten all components except the last - (mapcar (lambda (comp) - (if (or (string-equal comp last-component) (string-empty-p comp)) - comp - (substring comp 0 1))) - components))) - (mapconcat 'identity shortened-components "/"))) ; Recombine components into a path - -;; (setq global-mode-string '("" (:eval (concat (with-face (format " [%s] " (shorten-path default-directory)) -;; :weight 'bold -;; :foreground "green2"))))) - (defun single-header-init-buffer (buf) (with-current-buffer buf (insert "header test") @@ -138,6 +105,5 @@ ;; (single-header-show single-header--current-header-buffer)))) ;; do init frame seperately -;; (single-header-show single-header--current-header-buffer) -;; (run-with-timer 0 1 'single-header-update) - +(single-header-show single-header--current-header-buffer) +(run-with-timer 0 1 'single-header-update) -- cgit v1.2.3