From 699fce296b13d7db386b1cb5cecf2710e5196691 Mon Sep 17 00:00:00 2001 From: Johan Claesson Date: Wed, 26 Jun 2019 16:05:54 +0200 Subject: [PATCH] help-C-file-name shouldn't error out if we can't find the name * lisp/help-fns.el (help-C-file-name): Make help-C-file-name return nil instead of signalling an error if we can't find the file name (bug#17250). Copyright-paperwork-exempt: yes --- lisp/help-fns.el | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index 949def1bbe7..baef5a789ae 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -196,7 +196,8 @@ When called from lisp, FUNCTION may also be a function object." ;;;###autoload (defun help-C-file-name (subr-or-var kind) "Return the name of the C file where SUBR-OR-VAR is defined. -KIND should be `var' for a variable or `subr' for a subroutine." +KIND should be `var' for a variable or `subr' for a subroutine. +If we can't find the file name, nil is returned." (let ((docbuf (get-buffer-create " *DOC*")) (name (if (eq 'var kind) (concat "V" (symbol-name subr-or-var)) @@ -208,19 +209,24 @@ KIND should be `var' for a variable or `subr' for a subroutine." (expand-file-name internal-doc-file-name doc-directory))) (let ((file (catch 'loop (while t - (let ((pnt (search-forward (concat "\^_" name "\n")))) - (re-search-backward "\^_S\\(.*\\)") - (let ((file (match-string 1))) - (if (member file build-files) - (throw 'loop file) - (goto-char pnt)))))))) - (if (string-match "^ns.*\\(\\.o\\|obj\\)\\'" file) - (setq file (replace-match ".m" t t file 1)) - (if (string-match "\\.\\(o\\|obj\\)\\'" file) - (setq file (replace-match ".c" t t file)))) - (if (string-match "\\.\\(c\\|m\\)\\'" file) - (concat "src/" file) - file))))) + (let ((pnt (search-forward (concat "\^_" name "\n") + nil t))) + (if (not pnt) + (throw 'loop nil) + (re-search-backward "\^_S\\(.*\\)") + (let ((file (match-string 1))) + (if (member file build-files) + (throw 'loop file) + (goto-char pnt))))))))) + (if (not file) + nil + (if (string-match "^ns.*\\(\\.o\\|obj\\)\\'" file) + (setq file (replace-match ".m" t t file 1)) + (if (string-match "\\.\\(o\\|obj\\)\\'" file) + (setq file (replace-match ".c" t t file)))) + (if (string-match "\\.\\(c\\|m\\)\\'" file) + (concat "src/" file) + file)))))) (defcustom help-downcase-arguments nil "If non-nil, argument names in *Help* buffers are downcased." -- 2.39.5