From 11b37a4167d2eee4cb1f467a7f8ebaa6c8667ce9 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 25 Mar 2020 14:09:48 -0400 Subject: [PATCH] * lisp/textmodes/conf-mode.el (conf-mode): Fix last change `delay-mode-hooks` cannot be tested from within `define-derived-mode` because it's always non-nil in there, so arrange to test it before we enter the body. --- lisp/textmodes/conf-mode.el | 46 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lisp/textmodes/conf-mode.el b/lisp/textmodes/conf-mode.el index 79312757a2d..722fc0a3137 100644 --- a/lisp/textmodes/conf-mode.el +++ b/lisp/textmodes/conf-mode.el @@ -405,27 +405,31 @@ See also `conf-space-mode', `conf-colon-mode', `conf-javaprop-mode', \\{conf-mode-map}" - ;; `conf-mode' plays two roles: it's the parent of several sub-modes - ;; but it's also the function that chooses between those submodes. - ;; To tell the difference between those two cases where the function - ;; might be called, we check `delay-mode-hooks'. - ;; (adopted from tex-mode.el) - (if (not delay-mode-hooks) - (funcall (conf--guess-mode)) - - (setq-local font-lock-defaults '(conf-font-lock-keywords nil t nil nil)) - ;; Let newcomment.el decide this for itself. - ;; (setq-local comment-use-syntax t) - (setq-local parse-sexp-ignore-comments t) - (setq-local outline-regexp "[ \t]*\\(?:\\[\\|.+[ \t\n]*{\\)") - (setq-local outline-heading-end-regexp "[\n}]") - (setq-local outline-level #'conf-outline-level) - (setq-local imenu-generic-expression - '(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*=" 1) - ;; [section] - (nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1) - ;; section { ... } - (nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1))))) + (setq-local font-lock-defaults '(conf-font-lock-keywords nil t nil nil)) + ;; Let newcomment.el decide this for itself. + ;; (setq-local comment-use-syntax t) + (setq-local parse-sexp-ignore-comments t) + (setq-local outline-regexp "[ \t]*\\(?:\\[\\|.+[ \t\n]*{\\)") + (setq-local outline-heading-end-regexp "[\n}]") + (setq-local outline-level #'conf-outline-level) + (setq-local imenu-generic-expression + '(("Parameters" "^[ \t]*\\(.+?\\)[ \t]*=" 1) + ;; [section] + (nil "^[ \t]*\\[[ \t]*\\(.+\\)[ \t]*\\]" 1) + ;; section { ... } + (nil "^[ \t]*\\([^=:{} \t\n][^=:{}\n]+\\)[ \t\n]*{" 1)))) + +;; `conf-mode' plays two roles: it's the parent of several sub-modes +;; but it's also the function that chooses between those submodes. +;; To tell the difference between those two cases where the function +;; might be called, we check `delay-mode-hooks'. +;; (inspired from tex-mode.el) +(advice-add 'conf-mode :around + (lambda (orig-fun) + "Redirect to one of the submodes when called directly." + (funcall (if delay-mode-hooks orig-fun (conf--guess-mode))))) + + (defun conf-mode-initialize (comment &optional font-lock) "Initializations for sub-modes of `conf-mode'. -- 2.39.2