From ffc16a64b2d594b713580194558cf997c3e5ebad Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 20 Jan 2018 11:22:12 +0000 Subject: Be defensive against missing primitive source code If find-function-C-source-directory isn't set, or if it's set to a directory that contains source to a different Emacs version, just return nil from helpful--definition. --- CHANGELOG.md | 2 ++ helpful.el | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11dfdab..22851a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Fixed a crash on functions defined in a .elc when the .el file is not available. +Fixed some crashes on primitive functions. + Better handling of docstrings: * All strings in quotes are highlighted. For example, previously diff --git a/helpful.el b/helpful.el index 711bb7f..640d408 100644 --- a/helpful.el +++ b/helpful.el @@ -790,7 +790,7 @@ buffer." ;; `base-sym' is the underlying symbol if `sym' is an alias. (setq sym base-sym) (setq path src-path))) - (when (and primitive-p path) + (when (and primitive-p path find-function-C-source-directory) ;; Convert "src/foo.c" to "". (setq path (f-expand path (f-parent find-function-C-source-directory)))) @@ -849,7 +849,12 @@ buffer." (-let [(sym-buf . sym-pos) (find-definition-noselect sym 'defvar)] (setq buf sym-buf) (setq pos sym-pos)) - (search-failed nil)))) + (search-failed nil) + ;; If your current Emacs instance doesn't match the source + ;; code configured in find-function-C-source-directory, we can + ;; get an error about not finding source. Try + ;; `default-tab-width' against Emacs trunk. + (error nil)))) (list buf pos opened))) (defun helpful--source-path (sym callable-p) -- cgit v1.0