From d0c8423b1fee38ac1e2c9d35705622c1734c0473 Mon Sep 17 00:00:00 2001 From: Blake Romero Date: Sun, 12 Oct 2025 14:43:14 +0100 Subject: Add read-only construct --- modally.el | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/modally.el b/modally.el index fdc45b4..69dfca0 100644 --- a/modally.el +++ b/modally.el @@ -22,11 +22,12 @@ ;; ;;; Code: -(require 'subr-x) -(require 'cl-lib) -(require 'vc-git) -(require 'flymake) -(require 'org-timer) +;; (require 'subr-x) +;; (require 'cl-lib) +;; (require 'vc-git) +;; (require 'flymake) +;; (require 'org-timer) +(autoload 'org-timer-start "org-timer") (require 'modally-faces) @@ -34,8 +35,14 @@ (defun modally--seperator () "Return a propertized separator." (propertize "┃" 'face (if (mode-line-window-selected-p) - '(t :foreground "#444444") - '(t :foreground "#222222")))) + 'modally-active + 'modally-inactive))) + +(defun modally--read-only-status () + "Return a string to display read-only status." + (format "%s %s" + (if buffer-read-only " RO" " RW") + (modally--seperator))) (defun modally--buffer-name () "Return a propertized buffer name string." @@ -44,15 +51,14 @@ ((buffer-modified-p) 'modally-buffer-modified) (buffer-read-only 'modally-buffer-readonly) ('modally-buffer))) - (buffer-name (concat (if buffer-read-only "🔒 " "✏️ ") - (if buffer-file-name - (if (string-match "^\\(/home/[^/]+\\)\\(.+\\)" - buffer-file-name) - (concat "~" (match-string 2 buffer-file-name)) - buffer-file-name) - (buffer-name (current-buffer))))) + (buffer-name + (if buffer-file-name + (if (string-match "^\\(/home/[^/]+\\)\\(.+\\)" + buffer-file-name) + (concat "~" (match-string 2 buffer-file-name)) + buffer-file-name) + (buffer-name (current-buffer)))) (spath (string-split buffer-name "/"))) - ;; Format (if (> (length spath) 1) ;; if buffer has a path @@ -145,6 +151,7 @@ (defun modally--org-timer () "Return a timer from `org-timer'." (when (and + (featurep 'org-timer) (or org-timer-mode-line-timer org-timer-pause-time) (mode-line-window-selected-p)) @@ -161,6 +168,10 @@ )))) ;; VARIABLES +(defvar modally-display-read-only + '(:eval (modally--read-only-status)) + "Modeline construct to display the read-only status.") + (defvar modally-display-buffer-name '(:eval (modally--buffer-name)) "Modeline construct to display the buffer name.") @@ -196,7 +207,8 @@ "Modeline construct to display `org-timer' info.") ;; set as risky local variable -(dolist (construct '(modally-display-buffer-name +(dolist (construct '(modally-display-read-only + modally-display-buffer-name modally-display-major-mode modally-display-git-branch modally-display-line-row @@ -209,6 +221,7 @@ ;; FORMATS (defvar modally-format-default `("%e" + modally-display-read-only modally-display-buffer-name mode-line-format-right-align modally-display-org-timer -- cgit