122 lines
4.5 KiB
EmacsLisp
122 lines
4.5 KiB
EmacsLisp
;;; acdw-modeline.el -*- lexical-binding: t; coding: utf-8-unix -*-
|
|
;; Author: Case Duckworth <acdw@acdw.net>
|
|
;; Created: Sometime during Covid-19, 2020
|
|
;; Keywords: configuration
|
|
;; URL: https://tildegit.org/acdw/emacs
|
|
|
|
;; This file is NOT part of GNU Emacs.
|
|
|
|
;;; 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.
|
|
|
|
;;; Commentary:
|
|
;; `acdw-modeline' is a dumping ground for extra modeline functions, so they
|
|
;; don't clutter up `init.el'.
|
|
|
|
;;; Code:
|
|
|
|
(require 'simple-modeline)
|
|
(require 'minions)
|
|
|
|
(defun acdw-modeline/buffer-name () ; gonsie
|
|
(propertize " %b "
|
|
'face
|
|
(if (buffer-modified-p)
|
|
'font-lock-warning-face
|
|
'font-lock-type-face)
|
|
'help-echo (buffer-file-name)))
|
|
|
|
(defun acdw-modeline/erc ()
|
|
"ERC indicator for the modeline."
|
|
(when (boundp 'erc-modified-channels-object)
|
|
(format-mode-line erc-modified-channels-object)))
|
|
|
|
(defun acdw-modeline/god-mode-indicator ()
|
|
(when (bound-and-true-p god-local-mode)
|
|
" God"))
|
|
|
|
(defun acdw-modeline/modified () ; modified from `simple-modeline'
|
|
"Displays a color-coded buffer modification/read-only
|
|
indicator in the mode-line."
|
|
(if (not (string-match-p "\\*.*\\*" (buffer-name)))
|
|
(let* ((read-only (and buffer-read-only (buffer-file-name)))
|
|
(modified (buffer-modified-p)))
|
|
(propertize
|
|
(if read-only " =" (if modified " +" " -"))
|
|
'help-echo (format
|
|
(concat "Buffer is %s and %smodified\n"
|
|
"mouse-1: Toggle read-only status.")
|
|
(if read-only "read-only" "writable")
|
|
(if modified "" "not "))
|
|
'local-map (purecopy (simple-modeline-make-mouse-map
|
|
'mouse-1
|
|
(lambda (event)
|
|
(interactive "e")
|
|
(with-selected-window
|
|
(posn-window (event-start event))
|
|
(read-only-mode 'toggle)))))
|
|
'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)))
|
|
|
|
(defun acdw-modeline/text-scale ()
|
|
;; 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)))
|
|
|
|
(defun acdw-modeline/vc-branch ()
|
|
;; from https://www.gonsie.com/blorg/modeline.html, from Doom
|
|
(if-let ((backend (vc-backend buffer-file-name)))
|
|
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))
|
|
|
|
(defun acdw-modeline/winum ()
|
|
(when (and (bound-and-true-p winum-mode)
|
|
(> winum--window-count 1))
|
|
(format winum-format (winum-get-number-string))))
|
|
|
|
(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)
|
|
|
|
(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)))
|
|
(let ((fn (or (cdr modefun)
|
|
#'count-words))
|
|
(min (if (region-active-p) (region-beginning) (point-min)))
|
|
(max (if (region-active-p) (region-end) (point-max))))
|
|
(format "%dW" (funcall fn min max)))))
|
|
|
|
(provide 'acdw-modeline)
|