Remove doom-major-mode-names & doom|set-mode-name

And replace it with buffer-local mode-name setters. This is more
explicit and less magical, which is easier for users to discover and
change, if they'd like.
This commit is contained in:
Henrik Lissner 2018-09-18 11:48:16 -04:00
parent e80f5e4c85
commit 4067c8937e
4 changed files with 6 additions and 36 deletions

View file

@ -17,12 +17,6 @@
"Fallback font for unicode glyphs. Is ignored if :feature unicode is active.
Expects a `font-spec'.")
(defvar doom-major-mode-names
'((sh-mode . "sh")
(emacs-lisp-mode . "Elisp"))
"An alist mapping major modes symbols to strings (or functions that will
return a string). This changes the 'long' name of a major-mode, allowing for
shorter major mode name in the mode-line. See `doom|set-mode-name'.")
;;
(defvar doom-init-ui-hook nil
@ -419,14 +413,6 @@ frame's window-system, the theme will be reloaded.")
(add-hook! '(doom-init-ui-hook minibuffer-setup-hook window-configuration-change-hook)
#'doom|no-fringes-in-minibuffer)
(defun doom|set-mode-name ()
"Set the major mode's `mode-name', as dictated by `doom-major-mode-names'."
(when-let* ((name (cdr (assq major-mode doom-major-mode-names))))
(setq mode-name
(cond ((functionp name) (funcall name))
((stringp name) name)
((error "'%s' isn't a valid name for %s" name major-mode))))))
(defun doom|protect-visible-buffer ()
"Don't kill the current buffer if it is visible in another window (bury it
instead). Meant for `kill-buffer-query-functions'."
@ -441,7 +427,6 @@ instead). Meant for `kill-buffer-query-functions'."
"Initialize Doom's user interface by applying all its advice and hooks."
(add-to-list 'kill-buffer-query-functions #'doom|protect-fallback-buffer nil #'eq)
(add-to-list 'kill-buffer-query-functions #'doom|protect-visible-buffer nil #'eq)
(add-hook 'after-change-major-mode-hook #'doom|set-mode-name)
(add-hook 'after-change-major-mode-hook #'doom|highlight-non-default-indentation)
(add-hook 'compilation-filter-hook #'doom|apply-ansi-color-to-compilation-buffer)
(run-hook-wrapped 'doom-init-ui-hook #'doom-try-run-hook))

View file

@ -2,27 +2,6 @@
;;; ../core/test/test-core-ui.el
(describe "core/ui"
(describe "doom|set-mode-name"
:var (doom-major-mode-names after-change-major-mode-hook)
(before-all
(setq doom-major-mode-names
'((text-mode . "abc")
(lisp-mode . (lambda () "xyz"))
(js-mode . t))
after-change-major-mode-hook '(doom|set-mode-name)))
(it "changes `mode-name' to match a given string"
(text-mode)
(expect mode-name :to-equal "abc"))
(it "changes `mode-name' to the result of a function"
(lisp-mode)
(expect mode-name :to-equal "xyz"))
(it "should fail if given an invalid name"
(expect (js-mode) :to-throw 'error)))
(describe "doom|protect-visible-buffer"
:var (kill-buffer-query-functions wconf a b)
(before-each

View file

@ -47,6 +47,9 @@
("add-hook" "remove-hook")
("add-hook!" "remove-hook!")))
;; [pedantry intensifies]
(setq-hook! 'emacs-lisp-mode-hook mode-name "Elisp")
;; variable-width indentation is superior in elisp
(add-to-list 'doom-detect-indentation-excluded-modes 'emacs-lisp-mode nil #'eq)

View file

@ -19,6 +19,9 @@
(setq sh-indent-after-continuation 'always)
;; [pedantry intensifies]
(setq-hook! 'sh-mode-hook mode-name "sh")
;; recognize function names with dashes in them
(add-to-list 'sh-imenu-generic-expression
'(sh (nil "^\\s-*function\\s-+\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*\\(?:()\\)?" 1)