2021-03-16 16:16:21 +00:00
|
|
|
;;; acdw-modeline.el -*- lexical-binding: t; coding: utf-8-unix -*-
|
2021-03-15 04:48:40 +00:00
|
|
|
;; Author: Case Duckworth <acdw@acdw.net>
|
|
|
|
;; Created: Sometime during Covid-19, 2020
|
|
|
|
;; Keywords: configuration
|
|
|
|
;; URL: https://tildegit.org/acdw/emacs
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-15 04:48:40 +00:00
|
|
|
;; This file is NOT part of GNU Emacs.
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-15 04:48:40 +00:00
|
|
|
;;; License:
|
|
|
|
;; Everyone is permitted to do whatever with this software, without
|
|
|
|
;; limitation. This software comes without any warranty whatsoever,
|
|
|
|
;; but with two pieces of advice:
|
|
|
|
;; - Don't hurt yourself.
|
|
|
|
;; - Make good choices.
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-15 04:48:40 +00:00
|
|
|
;;; Commentary:
|
|
|
|
;; `acdw-modeline' is a dumping ground for extra modeline functions, so they
|
|
|
|
;; don't clutter up `init.el'.
|
2021-03-16 16:16:21 +00:00
|
|
|
|
2021-03-15 04:48:40 +00:00
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'simple-modeline)
|
|
|
|
(require 'minions)
|
|
|
|
|
2021-08-28 05:25:26 +00:00
|
|
|
(defcustom acdw-modeline/word-count-modes
|
|
|
|
(mapcar (lambda (m) (cons m nil)) simple-modeline-word-count-modes)
|
|
|
|
"Alist of modes to functions that `acdw-modeline/word-count' should dispatch.
|
|
|
|
If the cdr of the cons cell is nil, use the default function (`count-words').
|
|
|
|
Otherwise, cdr should be a function that takes two points (see `count-words')."
|
|
|
|
:type '(alist :key-type (symbol :tag "Major-Mode")
|
|
|
|
:value-type function)
|
|
|
|
:group 'simple-modeline)
|
|
|
|
|
2021-04-29 17:16:03 +00:00
|
|
|
(defun acdw-modeline/buffer-name () ; gonsie
|
2021-08-10 19:47:33 +00:00
|
|
|
"Display the buffer name in a face reflecting its modified status."
|
2021-04-29 17:16:03 +00:00
|
|
|
(propertize " %b "
|
|
|
|
'face
|
|
|
|
(if (buffer-modified-p)
|
|
|
|
'font-lock-warning-face
|
|
|
|
'font-lock-type-face)
|
|
|
|
'help-echo (buffer-file-name)))
|
|
|
|
|
2021-05-22 21:41:10 +00:00
|
|
|
(defun acdw-modeline/erc ()
|
|
|
|
"ERC indicator for the modeline."
|
2021-08-26 21:04:40 +00:00
|
|
|
(when (and (bound-and-true-p erc-track-mode)
|
|
|
|
(boundp 'erc-modified-channels-object))
|
2021-05-24 22:08:32 +00:00
|
|
|
(format-mode-line erc-modified-channels-object)))
|
2021-05-22 21:41:10 +00:00
|
|
|
|
2021-04-29 17:16:03 +00:00
|
|
|
(defun acdw-modeline/god-mode-indicator ()
|
2021-08-10 19:47:33 +00:00
|
|
|
"Display an indicator if `god-local-mode' is active."
|
2021-04-29 17:16:03 +00:00
|
|
|
(when (bound-and-true-p god-local-mode)
|
2021-08-28 05:23:56 +00:00
|
|
|
" Ω"))
|
|
|
|
|
|
|
|
(defun acdw-modeline/major-mode ()
|
|
|
|
"Displays the current major mode in the mode-line."
|
|
|
|
(propertize
|
|
|
|
(concat " "
|
|
|
|
(or (and (boundp 'delighted-modes)
|
|
|
|
(cadr (assq major-mode delighted-modes)))
|
|
|
|
(format-mode-line mode-name)))
|
|
|
|
'face 'bold
|
|
|
|
'keymap mode-line-major-mode-keymap
|
|
|
|
'mouse-face 'mode-line-highlight))
|
|
|
|
|
|
|
|
(defun acdw-modeline/minions () ; by me
|
|
|
|
"Display a button for `minions-minor-modes-menu'."
|
|
|
|
(concat
|
|
|
|
" "
|
|
|
|
(propertize
|
|
|
|
"&"
|
|
|
|
'help-echo (format
|
|
|
|
"Minor modes menu\nmouse-1: show menu.")
|
|
|
|
'local-map (purecopy (simple-modeline-make-mouse-map
|
|
|
|
'mouse-1
|
|
|
|
(lambda (event)
|
|
|
|
(interactive "e")
|
|
|
|
(with-selected-window (posn-window
|
|
|
|
(event-start event))
|
|
|
|
(minions-minor-modes-menu)))))
|
|
|
|
'mouse-face 'mode-line-highlight)))
|
2021-04-29 17:16:03 +00:00
|
|
|
|
|
|
|
(defun acdw-modeline/modified () ; modified from `simple-modeline'
|
|
|
|
"Displays a color-coded buffer modification/read-only
|
2021-03-15 04:48:40 +00:00
|
|
|
indicator in the mode-line."
|
2021-04-29 17:16:03 +00:00
|
|
|
(if (not (string-match-p "\\*.*\\*" (buffer-name)))
|
|
|
|
(let* ((read-only (and buffer-read-only (buffer-file-name)))
|
2021-03-25 17:21:37 +00:00
|
|
|
(modified (buffer-modified-p)))
|
|
|
|
(propertize
|
2021-09-03 04:51:52 +00:00
|
|
|
(concat " "
|
|
|
|
(cond
|
|
|
|
((derived-mode-p 'special-mode
|
|
|
|
'lui-mode)
|
|
|
|
"~")
|
|
|
|
(read-only "=")
|
|
|
|
(modified "+")
|
|
|
|
(t "-")))
|
2021-03-25 17:21:37 +00:00
|
|
|
'help-echo (format
|
2021-04-29 17:16:03 +00:00
|
|
|
(concat "Buffer is %s and %smodified\n"
|
|
|
|
"mouse-1: Toggle read-only status.")
|
|
|
|
(if read-only "read-only" "writable")
|
|
|
|
(if modified "" "not "))
|
2021-03-25 17:21:37 +00:00
|
|
|
'local-map (purecopy (simple-modeline-make-mouse-map
|
2021-04-29 17:16:03 +00:00
|
|
|
'mouse-1
|
|
|
|
(lambda (event)
|
|
|
|
(interactive "e")
|
|
|
|
(with-selected-window
|
|
|
|
(posn-window (event-start event))
|
|
|
|
(read-only-mode 'toggle)))))
|
2021-03-25 17:21:37 +00:00
|
|
|
'mouse-face 'mode-line-highlight))))
|
2021-03-15 04:48:40 +00:00
|
|
|
|
2021-08-07 21:59:56 +00:00
|
|
|
(defun acdw-modeline/narrowed ()
|
|
|
|
"Display an indication if the buffer is narrowed."
|
|
|
|
(when (buffer-narrowed-p)
|
|
|
|
(concat
|
|
|
|
""
|
|
|
|
(propertize
|
|
|
|
"N"
|
|
|
|
'help-echo (format "%s\n%s"
|
|
|
|
"Buffer is narrowed"
|
|
|
|
"mouse-2: widen buffer.")
|
|
|
|
'local-map (purecopy (simple-modeline-make-mouse-map
|
|
|
|
'mouse-2 #'mode-line-widen))
|
|
|
|
'mouse-face 'mode-line-highlight))))
|
|
|
|
|
2021-08-10 19:47:00 +00:00
|
|
|
(defun acdw-modeline/position ()
|
|
|
|
"Displays the current cursor position in the mode-line.
|
|
|
|
|
|
|
|
Unlike `simple-modeline-segment-position', this changes the first
|
|
|
|
character from '+' to '-' if the region goes 'backward' -- that
|
|
|
|
is, if point < mark."
|
|
|
|
`((line-number-mode
|
|
|
|
((column-number-mode
|
|
|
|
(column-number-indicator-zero-based
|
|
|
|
(8 " %l:%c")
|
|
|
|
(8 " %l:%C"))
|
|
|
|
(5 " L%l")))
|
|
|
|
((column-number-mode
|
|
|
|
(column-number-indicator-zero-based
|
|
|
|
(5 " C%c")
|
|
|
|
(5 " C%C")))))
|
|
|
|
,(if (region-active-p)
|
|
|
|
(propertize (format "%s%s"
|
|
|
|
(if (and (mark)
|
|
|
|
(< (point) (mark)))
|
|
|
|
"-"
|
|
|
|
"+")
|
|
|
|
(apply #'+ (mapcar
|
|
|
|
(lambda (pos)
|
|
|
|
(- (cdr pos)
|
|
|
|
(car pos)))
|
|
|
|
(region-bounds))))
|
|
|
|
'font-lock-face 'font-lock-variable-name-face))))
|
|
|
|
|
2021-04-30 17:49:58 +00:00
|
|
|
(defun acdw-modeline/text-scale ()
|
2021-08-10 19:47:33 +00:00
|
|
|
"Display the text scaling from the modeline, if scaled."
|
2021-04-30 17:49:58 +00:00
|
|
|
;; adapted from https://github.com/seagle0128/doom-modeline
|
|
|
|
(when (and (boundp 'text-scale-mode-amount)
|
|
|
|
(/= text-scale-mode-amount 0))
|
|
|
|
(format
|
|
|
|
(if (> text-scale-mode-amount 0)
|
|
|
|
" (%+d)"
|
|
|
|
" (%-d)")
|
|
|
|
text-scale-mode-amount)))
|
|
|
|
|
2021-08-29 04:08:17 +00:00
|
|
|
(defun acdw-modeline/track ()
|
|
|
|
"Display `tracking-mode' information."
|
|
|
|
(when tracking-mode
|
|
|
|
tracking-mode-line-buffers))
|
|
|
|
|
2021-03-15 04:48:40 +00:00
|
|
|
(defun acdw-modeline/vc-branch ()
|
2021-08-10 19:47:33 +00:00
|
|
|
"Display the version control branch of the current buffer in the modeline."
|
2021-04-29 17:16:03 +00:00
|
|
|
;; from https://www.gonsie.com/blorg/modeline.html, from Doom
|
2021-03-30 16:58:37 +00:00
|
|
|
(if-let ((backend (vc-backend buffer-file-name)))
|
2021-04-29 17:16:03 +00:00
|
|
|
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))
|
2021-03-15 04:48:40 +00:00
|
|
|
|
2021-09-04 02:49:48 +00:00
|
|
|
(defun acdw-modeline/wc ()
|
|
|
|
"Display current `wc-buffer-stats'."
|
|
|
|
(when (bound-and-true-p wc-mode)
|
|
|
|
(or wc-buffer-stats "[w]")))
|
|
|
|
|
2021-05-03 20:12:44 +00:00
|
|
|
(defun acdw-modeline/winum ()
|
2021-08-10 19:47:33 +00:00
|
|
|
"Show the `winum' number of the current window in the modeline.
|
|
|
|
Only shows if there is more than one window."
|
2021-05-03 20:12:44 +00:00
|
|
|
(when (and (bound-and-true-p winum-mode)
|
|
|
|
(> winum--window-count 1))
|
|
|
|
(format winum-format (winum-get-number-string))))
|
|
|
|
|
2021-05-19 20:28:58 +00:00
|
|
|
(defun acdw-modeline/word-count ()
|
|
|
|
"Display a buffer word count, depending on the major mode.
|
|
|
|
Uses `acdw-modeline/word-count-modes' to determine which function to use."
|
|
|
|
(when-let ((modefun
|
|
|
|
(assoc major-mode acdw-modeline/word-count-modes #'equal)))
|
2021-08-10 13:30:49 +00:00
|
|
|
(let* ((fn (or (cdr modefun)
|
|
|
|
#'count-words))
|
|
|
|
(r (region-active-p))
|
|
|
|
(min (if r (region-beginning) (point-min)))
|
|
|
|
(max (if r (region-end) (point-max))))
|
|
|
|
(format " %s%dW" (if r "+" "") (funcall fn min max)))))
|
2021-05-19 20:28:58 +00:00
|
|
|
|
2021-03-15 04:48:40 +00:00
|
|
|
(provide 'acdw-modeline)
|