From f0febf681490412709be7b494232de8c41253769 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 5 May 2022 18:41:42 -0500 Subject: [PATCH] Change modeline --- init.el | 14 +++++++--- lisp/+Info.el | 67 ++++++++++++++++++++++++++++++++++++++++++++++ lisp/+modeline.el | 68 +++++++++++++++++++++++++++-------------------- 3 files changed, 116 insertions(+), 33 deletions(-) diff --git a/init.el b/init.el index 8b1c43e..61b2858 100644 --- a/init.el +++ b/init.el @@ -429,6 +429,8 @@ (add-to-list 'Info-additional-directory-list dir)) (:with-mode Info-mode ; -_- (:hook #'reading-mode) + (:local-set +modeline-buffer-position #'+Info-modeline-breadcrumbs + +modeline-position-function #'ignore) (:bind "c" #'+Info-copy-current-node-name "w" #'+Info-copy-current-node-name))) @@ -1712,6 +1714,8 @@ (setup (:straight info+) (:load-after info) (:option Info-fontify-isolated-quote-flag nil + Info-breadcrumbs-in-mode-line-mode nil + Info-fontify-emphasis-flag nil Info-fontify-quotations nil Info-saved-history-file (.etc "info-history")) (add-hook 'Info-mode-hook #'Info-variable-pitch-text-mode)) @@ -1802,6 +1806,7 @@ (cond ((string-match-p "hmm@" (buffer-name)) "🤔 "))) + file-percentage-mode nil wrap-prefix (make-string +jabber-ws-prefix ?\ ))) (:+leader "C-j" jabber-global-keymap) (advice-add 'jabber-activity-add :after #'+jabber-tracking-add) @@ -2173,7 +2178,7 @@ (readonly . "=") (modified . "+") (t . "-")) - +modeline-minions-icon ";" + +modeline-minions-icon "&" +modeline-buffer-name-max-length 0.35) ;; Segments (:option simple-modeline-segments @@ -2182,9 +2187,6 @@ +modeline-modified +modeline-buffer-name (lambda () (+modeline-vc " : ")) - ,(+modeline-concat - '(+modeline-minions - +modeline-major-mode)) +modeline-anzu ) ( ; right @@ -2203,6 +2205,10 @@ ",") +modeline-input-method +modeline-position + ,(+modeline-concat + '(+modeline-minions + +modeline-major-mode)) + +modeline-file-percentage ))) (simple-modeline-mode +1)) diff --git a/lisp/+Info.el b/lisp/+Info.el index a3c2fcd..46bd5f8 100644 --- a/lisp/+Info.el +++ b/lisp/+Info.el @@ -13,5 +13,72 @@ arg reversed." (interactive "P" Info-mode) (Info-copy-current-node-name (unless arg 0))) +(defun +Info-modeline-breadcrumbs () + (let ((nodes (Info-toc-nodes Info-current-file)) + (node Info-current-node) + (crumbs ()) + (depth Info-breadcrumbs-depth-internal) + (text "")) + ;; Get ancestors from the cached parent-children node info + (while (and (not (equal "Top" node)) (> depth 0)) + (setq node (nth 1 (assoc node nodes))) + (when node (push node crumbs)) + (setq depth (1- depth))) + ;; Add bottom node. + (setq crumbs (nconc crumbs (list Info-current-node))) + (when crumbs + ;; Add top node (and continuation if needed). + (setq crumbs (cons "Top" (if (member (pop crumbs) '(nil "Top")) + crumbs + (cons nil crumbs)))) + (dolist (node crumbs) + (let ((crumbs-map (make-sparse-keymap)) + (menu-map (make-sparse-keymap "Breadcrumbs in Mode Line"))) + (define-key crumbs-map [mode-line mouse-3] menu-map) + (when node + (define-key menu-map [Info-prev] + `(menu-item "Previous Node" Info-prev + :visible ,(Info-check-pointer "prev[ious]*") :help "Go to the previous node")) + (define-key menu-map [Info-next] + `(menu-item "Next Node" Info-next + :visible ,(Info-check-pointer "next") :help "Go to the next node")) + (define-key menu-map [separator] '("--")) + (define-key menu-map [Info-breadcrumbs-in-mode-line-mode] + `(menu-item "Toggle Breadcrumbs" Info-breadcrumbs-in-mode-line-mode + :help "Toggle displaying breadcrumbs in the Info mode-line" + :button (:toggle . Info-breadcrumbs-in-mode-line-mode))) + (define-key menu-map [Info-set-breadcrumbs-depth] + `(menu-item "Set Breadcrumbs Depth" Info-set-breadcrumbs-depth + :help "Set depth of breadcrumbs to show in the mode-line")) + (setq node (if (equal node Info-current-node) + (propertize + (replace-regexp-in-string "%" "%%" Info-current-node) + 'face 'mode-line-buffer-id + 'help-echo "mouse-1: Scroll back, mouse-2: Scroll forward, mouse-3: Menu" + 'mouse-face 'mode-line-highlight + 'local-map + (progn + (define-key crumbs-map [mode-line mouse-1] 'Info-mouse-scroll-down) + (define-key crumbs-map [mode-line mouse-2] 'Info-mouse-scroll-up) + crumbs-map)) + (propertize + node + 'local-map (progn (define-key crumbs-map [mode-line mouse-1] + `(lambda () (interactive) (Info-goto-node ,node))) + (define-key crumbs-map [mode-line mouse-2] + `(lambda () (interactive) (Info-goto-node ,node))) + crumbs-map) + 'mouse-face 'mode-line-highlight + 'help-echo "mouse-1, mouse-2: Go to this node; mouse-3: Menu"))))) + (let ((nodetext (if (not (equal node "Top")) + node + (concat (format "(%s)" (if (stringp Info-current-file) + (file-name-nondirectory Info-current-file) + ;; Some legacy code can still use a symbol. + Info-current-file)) + node)))) + (setq text (concat text (if (equal node "Top") "" " > ") (if node nodetext "..."))))) + text))) + (provide '+Info) ;;; +Info.el ends here diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 3a922e3..e5b5bc6 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el @@ -72,26 +72,34 @@ and appended with `truncate-string-ellipsis'." (natnum :tag "Number of characters") (float :tag "Fraction of window's width"))) +(defcustom +modeline-buffer-position nil + "What to put in the `+modeline-buffer-name' position." + :type 'function + :local t) + (defun +modeline-buffer-name (&optional spacer) ; gonsie "Display the buffer name." (let ((bufname (string-trim (string-replace "%" "" (buffer-name))))) (concat (or spacer +modeline-default-spacer) - (propertize (cond - ((ignore-errors - (and (> +modeline-buffer-name-max-length 0) - (< +modeline-buffer-name-max-length 1))) - (truncate-string-to-width bufname - (* (window-total-width) +modeline-buffer-name-max-length) - nil nil t)) - ((ignore-errors - (> +modeline-buffer-name-max-length 1)) - (truncate-string-to-width bufname - +modeline-buffer-name-max-length - nil nil t)) - (t bufname)) - 'help-echo (or (buffer-file-name) - (buffer-name)) - 'mouse-face 'mode-line-highlight)))) + (if (and +modeline-buffer-position (fboundp +modeline-buffer-position)) + (funcall +modeline-buffer-position) + (propertize (cond + ((ignore-errors + (and (> +modeline-buffer-name-max-length 0) + (< +modeline-buffer-name-max-length 1))) + (truncate-string-to-width bufname + (* (window-total-width) + +modeline-buffer-name-max-length) + nil nil t)) + ((ignore-errors + (> +modeline-buffer-name-max-length 1)) + (truncate-string-to-width bufname + +modeline-buffer-name-max-length + nil nil t)) + (t bufname)) + 'help-echo (or (buffer-file-name) + (buffer-name)) + 'mouse-face 'mode-line-highlight))))) (defcustom +modeline-minions-icon "&" "The \"icon\" for `+modeline-minions' button." @@ -152,17 +160,17 @@ The order of elements matters: whichever one matches first is applied." (defun +modeline-modified (&optional spacer) ; modified from `simple-modeline-status-modified' "Display a color-coded \"icon\" indicator for the buffer's status." (let* ((icon (catch :icon - (dolist (cell +modeline-modified-icon-alist) - (when (pcase (car cell) - ('ephemeral (not (buffer-file-name))) - ('readonly buffer-read-only) - ('modified (buffer-modified-p)) - ('special - (apply 'derived-mode-p - +modeline-modified-icon-special-modes)) - ('t t) - (_ nil)) - (throw :icon cell)))))) + (dolist (cell +modeline-modified-icon-alist) + (when (pcase (car cell) + ('ephemeral (not (buffer-file-name))) + ('readonly buffer-read-only) + ('modified (buffer-modified-p)) + ('special + (apply 'derived-mode-p + +modeline-modified-icon-special-modes)) + ('t t) + (_ nil)) + (throw :icon cell)))))) (concat (or spacer +modeline-default-spacer) (propertize (or (cdr-safe icon) "") 'help-echo (format "Buffer \"%s\" is %s." @@ -244,7 +252,8 @@ The order of elements matters: whichever one matches first is applied." perc (unless (seq-some (lambda (s) (string= perc s)) '("Top" "Bot" "All")) - "%%%%"))))) + "%%%%") + " ")))) (defun +modeline-file-percentage-icon (&optional spacer) "Display the position in the current file as an icon." @@ -312,7 +321,8 @@ to a function in the current buffer, call that function instead." +modeline-position-function (+modeline-concat '(+modeline-region +modeline-line-column - +modeline-file-percentage))))) + ;; +modeline-file-percentage + ))))) (defun +modeline-vc (&optional spacer) "Display the version control branch of the current buffer in the modeline."