From a786bc3330fdc796949dadf14f969e3b4cf95967 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Fri, 22 Dec 2017 08:46:37 +0000 Subject: Speedup opening helpful buffers for primitive functions Previously we would spend a lot of time executing mode hooks when Emacs source code was loaded. --- CHANGELOG.md | 3 +++ helpful.el | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da13e81..f2ef499 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ too (see `set-mark-command` for an example). Helpful now shows all aliases for callables and variables, and highlights which aliases are obsolete. +Improved helpful performance for primitives when Emacs source code is +loaded. + ## recentf bug Helpful had an issue where it would call find-file with propertized diff --git a/helpful.el b/helpful.el index b71812a..687d063 100644 --- a/helpful.el +++ b/helpful.el @@ -667,17 +667,25 @@ buffer." ((and callable-p path) ;; Open `path' ourselves, so we can widen before searching. - ;; TODO: this is slow, because when we open large .c files, such - ;; as data.c (e.g. when looking at `defalias'), we run all the - ;; mode hooks. If the user hasn't opened the buffer, we should - ;; just open a temporary buffer. This would require - ;; reimplementing `find-function-C-source', which is just a - ;; regexp search anyway. - (setq buf (find-file-noselect (find-library-name path))) + ;; Opening large.c files can be slow (e.g. when looking at + ;; `defalias'), especially if the user has configured mode hooks. + ;; + ;; Bind `auto-mode-alist' to nil, so we open the buffer in + ;; `fundamental-mode' if it isn't already open. + (let (auto-mode-alist) + (setq buf (find-file-noselect (find-library-name path)))) (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. + (when opened + (with-current-buffer buf + (delay-mode-hooks (normal-mode)))) + ;; Based on `find-function-noselect'. (with-current-buffer buf ;; `find-function-search-for-symbol' moves point. Prevent -- cgit v1.0