aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-12-22 08:46:37 +0000
committerWilfred Hughes <me@wilfred.me.uk>2017-12-22 08:47:52 +0000
commita786bc3330fdc796949dadf14f969e3b4cf95967 (patch)
tree071a109671116e0492b232d3e3d87cc6f075f3b1
parentb319ead3aee714f1c21c08ce57fe08662ea5b47b (diff)
Speedup opening helpful buffers for primitive functions
Previously we would spend a lot of time executing mode hooks when Emacs source code was loaded.
-rw-r--r--CHANGELOG.md3
-rw-r--r--helpful.el22
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