nixos/home/emacs/modules/custom-ui-config.el

99 lines
3.4 KiB
EmacsLisp

;;; custom-ui-config.el -*- lexical-binding: t; -*-
;; Copyright (C) 2023
;; SPDX-License-Identifier: MIT
;; Author: System Crafters Community
;;; Code:
(when (require 'page-break nil :noerror) (global-page-break-lines-mode +1))
;;;; Help Buffers
;; Make `describe-*' screens more helpful
(when (require 'helpful nil :noerror)
(keymap-set helpful-mode-map "<remap> <revert-buffer>" #'helpful-update)
(keymap-global-set "<remap> <describe-command>" #'helpful-command)
(keymap-global-set "<remap> <describe-function>" #'helpful-callable)
(keymap-global-set "<remap> <describe-key>" #'helpful-key)
(keymap-global-set "<remap> <describe-symbol>" #'helpful-symbol)
(keymap-global-set "<remap> <describe-variable>" #'helpful-variable)
(keymap-global-set "C-h F" #'helpful-function))
;; Bind extra `describe-*' commands
(keymap-global-set "C-h K" #'describe-keymap)
;;;; Line Numbers
(defcustom custom-ui-line-numbers-enabled-modes
'(conf-mode prog-mode)
"Modes which should display line numbers."
:type 'list
:group 'crafted-ui)
(defcustom custom-ui-line-numbers-disabled-modes
'(org-mode)
"Modes which should not display line numbers.
Modes derived from the modes defined in
`custom-ui-line-number-enabled-modes', but should not display line numbers."
:type 'list
:group 'crafted-ui)
(defun custom-ui--enable-line-numbers-mode ()
"Turn on line numbers mode.
Used as hook for modes which should display line numbers."
(display-line-numbers-mode 1))
(defun custom-ui--disable-line-numbers-mode ()
"Turn off line numbers mode.
Used as hook for modes which should not display line numebrs."
(display-line-numbers-mode -1))
(defun custom-ui--update-line-numbers-display ()
"Update configuration for line numbers display."
(if custom-ui-display-line-numbers
(progn
(dolist (mode custom-ui-line-numbers-enabled-modes)
(add-hook (intern (format "%s-hook" mode))
#'custom-ui--enable-line-numbers-mode))
(dolist (mode custom-ui-line-numbers-disabled-modes)
(add-hook (intern (format "%s-hook" mode))
#'custom-ui--disable-line-numbers-mode))
(setq-default
display-line-numbers-grow-only t
display-line-numbers-type t
display-line-numbers-width 2))
(progn
(dolist (mode custom-ui-line-numbers-enabled-modes)
(remove-hook (intern (format "%s-hook" mode))
#'custom-ui--enable-line-numbers-mode))
(dolist (mode custom-ui-line-numbers-disabled-modes)
(remove-hook (intern (format "%s-hook" mode))
#'custom-ui--disable-line-numbers-mode)))))
(defcustom custom-ui-display-line-numbers nil
"Whether line numbers should be enabled."
:type 'boolean
:group 'crafted-ui
:set (lambda (sym val)
(set-default sym val)
(custom-ui--update-line-numbers-display)))
;; add visual pulse when changing focus, like beacon but built-in
;; from from https://karthinks.com/software/batteries-included-with-emacs/
(defun pulse-line (&rest _)
"Pulse the current line."
(pulse-momentary-highlight-one-line (point)))
(dolist (command '(scroll-up-command
scroll-down-command
recenter-top-bottom
other-window))
(advice-add command :after #'pulse-line))
(provide 'custom-ui-config)
;;; custom-ui-config.el ends here