diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2022-09-18 22:40:59 -0700 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2022-09-18 22:40:59 -0700 |
| commit | db1e15b3783c83d9781a546f37b900ad53576659 (patch) | |
| tree | 63dba1570cd8951d31b0da8400e477c8dfa5468f | |
| parent | a9c729cb248b7863685f04e418d9c0c0a600df0d (diff) | |
Don't activate a major mode in throwaway buffers
This can be slow, even with major mode hooks disabled. Minor mode
hooks may do non-trivial amounts of work.
Instead, just set the syntax table, so we can search the buffer for
definitions accurately.
Fixes #287
| -rw-r--r-- | helpful.el | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -54,6 +54,7 @@ (require 'edebug) (require 'trace) (require 'imenu) +(require 'cc-langs) (defvar-local helpful--sym nil) (defvar-local helpful--callable-p nil) @@ -1385,7 +1386,6 @@ the `emacs-lisp-mode' syntax table active but skip any hooks." (opened nil) ;; Skip running hooks that may prompt the user. (find-file-hook nil) - (after-change-major-mode-hook nil) ;; If we end up opening a buffer, don't bother with file ;; variables. It prompts the user, and we discard the buffer ;; afterwards anyway. @@ -1400,12 +1400,16 @@ the `emacs-lisp-mode' syntax table active but skip any hooks." (unless (-contains-p initial-buffers buf) (setq opened t) - ;; If it's a freshly opened buffer, we need to switch to the - ;; correct mode so we can search correctly. Enable the mode, but - ;; don't bother with mode hooks, because we just need the syntax - ;; table for searching. - (with-current-buffer buf - (delay-mode-hooks (normal-mode t)))) + + (let ((syntax-table emacs-lisp-mode-syntax-table)) + (when (s-ends-with-p ".c" path) + (setq syntax-table (make-syntax-table)) + (c-populate-syntax-table syntax-table)) + + ;; If it's a freshly opened buffer, we need to set the syntax + ;; table so we can search correctly. + (with-current-buffer buf + (set-syntax-table syntax-table)))) (list buf opened))) |
