diff --git a/lisp/man.el b/lisp/man.el index 103131fbb34..9bfd9307bc7 100644 --- a/lisp/man.el +++ b/lisp/man.el @@ -2028,18 +2028,19 @@ Specify which REFERENCE to use; default is based on word at point." (error "You're looking at the first manpage in the buffer")))) ;; Header file support +(defun man--find-header-files (file) + (delq nil + (mapcar (lambda (path) + (let ((complete-path (expand-file-name file path))) + (and (file-readable-p complete-path) + complete-path))) + (Man-header-file-path)))) + (defun Man-view-header-file (file) "View a header file specified by FILE from `Man-header-file-path'." - (let ((path (Man-header-file-path)) - complete-path) - (while path - (setq complete-path (expand-file-name file (car path)) - path (cdr path)) - (if (file-readable-p complete-path) - (progn (view-file complete-path) - (setq path nil)) - (setq complete-path nil))) - complete-path)) + (when-let ((match (man--find-header-files file))) + (view-file (car match)) + (car match))) ;;; Bookmark Man Support (declare-function bookmark-make-record-default diff --git a/test/lisp/man-tests.el b/test/lisp/man-tests.el index 5557c423a7a..f076439e802 100644 --- a/test/lisp/man-tests.el +++ b/test/lisp/man-tests.el @@ -179,6 +179,15 @@ DESCRIPTION "\"-k\" \"basename\"" "-k basename")))) +(ert-deftest man-tests-find-header-file () + ;; We should be able to find header files on any system with a C + ;; compiler, I think. + (skip-unless (or (executable-find "cc") + (executable-find "gcc") + (executable-find "clang"))) + (should (file-exists-p (car (man--find-header-files "math.h")))) + (should-not (man--find-header-files "nonexistent-header-does-not-exist.h"))) + (provide 'man-tests) ;;; man-tests.el ends here