From e2a4c891c12e001e3851ef4cfcf05020f9cfef11 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sat, 14 Jul 2018 12:51:22 -0700 Subject: [PATCH] [Emacs] Add major mode blacklisting macro --- dotfiles/emacs.d/README.org | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/dotfiles/emacs.d/README.org b/dotfiles/emacs.d/README.org index bc56184d..bb264fee 100644 --- a/dotfiles/emacs.d/README.org +++ b/dotfiles/emacs.d/README.org @@ -933,6 +933,26 @@ This was stolen from https://github.com/jwiegley/dot-emacs (imalison:disable-mode-hook nlinum-mode) (imalison:disable-mode-hook yas-minor-mode) #+END_SRC +** Add a blacklist to a major mode +Sometimes a major mode's syntax highlighting can take a really long time to load +in certain buffers. Usually you can just set a header to tell emacs not to run +the major mode, but for cases where you can't always edit the file ahead of time +this macro allows you to define a blacklist for your major mode that will +prevent the major mode from being enabled on that file. +#+begin_src emacs-lisp +(defmacro imalison:add-blacklist-to-major (major-mode-fn-symbol) + (let ((blacklist-var-symbol (imalison:concat-symbols major-mode-fn-symbol "-blacklist")) + (check-blacklist-symbol (imalison:concat-symbols major-mode-fn-symbol "-check-blacklist"))) + `(progn + (defvar ,blacklist-var-symbol nil) + (defun ,check-blacklist-symbol (mode-fn &rest args) + (unless (and (not (equal major-mode (quote ,major-mode-fn-symbol))) + (equal nil args) + (cl-loop for blacklist-regex in ,blacklist-var-symbol + thereis (string-match blacklist-regex (buffer-name)))) + (apply mode-fn args))) + (advice-add (quote ,major-mode-fn-symbol) :around (quote ,check-blacklist-symbol))))) +#+end_src ** Other The stuff in this section is pretty crusty. I don't think its used anywhere, but I keep it around just in case I need it.