emacs/lisp/man-plus.el

66 lines
1.8 KiB
EmacsLisp
Raw Permalink Normal View History

;;; man-plus.el --- Fix the ugly emacs manpages
;;; Commentary:
2022-06-19 14:13:36 -08:00
;; Loosely based on neovim's `man.vim' functionality.
;;
;; Feature goals:
;; - MANWIDTH based on size of new window
;; - Lots of different colors for headings, options,
;; sh snippets, etc
;;; Code:
(defvar man-plus-highlights
(let* (
(manReference "[^()[:space:]]\\\\+(\\\\%([0-9][a-z]*\\\\|[nlpox]\\\\))")
(manSectionHeading "^\\\\S.*$")
(manHeader "^\\\\%1l.*$")
(manSubHeading "^ \\\\{3\\\\}\\\\S.*$")
(manOptionDesc "^\\\\s\\\\+\\\\%(+\\\\|-\\\\)\\\\S\\\\+"))
`(
(,manReference . 'link)
(,manSectionHeading . 'outline-1)
(,manHeader . 'org-document-title)
(,manSubHeading . 'font-lock-function-name-face)
(,manOptionDesc . 'font-lock-constant-face)
)))
(defface manHeader
'((t (:inherit org-document-title)))
"Top-level heading for Man pages..."
:group 'man)
(defface manSectionHeading
'((t (:inherit outline-1)))
"Man section titles..."
:group 'man)
(defface manOptionDesc
'((t (:inherit font-lock-constant-face)))
"Man option descriptions..."
:group 'man)
(defface manReference
'((t (:inherit link)))
"Man references to other pages..."
:group 'man)
(defface manSubHeading
'((t (:inherit font-lock-function-name-face)))
"Manual sub headings..."
:group 'man)
2022-06-19 14:13:36 -08:00
(defun man-plus-setall ()
"Do all of the things that Man wants. To be run as `Man-mode-hook'."
(interactive)
(setq font-lock-defaults '(man-plus-highlights)))
(add-hook 'man-common-hook #'man-plus-setall)
(add-hook 'man-common-hook #'turn-off-line-numbers)
2022-06-19 14:13:36 -08:00
(define-derived-mode man-plus-mode man-common "ManPlus"
"Custom child mode for man mode, structured like the `nvim' builtin plugin."
(buffer-disable-undo)
(auto-fill-mode -1)
(man-plus-setall)
(turn-off-line-numbers))
2022-06-19 14:13:36 -08:00
(provide 'man-plus)
;;; man-plus.el ends here