Function: read-library-name

read-library-name is an autoloaded and byte-compiled function defined in find-func.el.gz.

Signature

(read-library-name)

Documentation

Read and return a library name, defaulting to the one near point.

A library name is the filename of an Emacs Lisp library located in a directory under load-path (or find-library-source-path, if non-nil).

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/find-func.el.gz
;;;###autoload
(defun read-library-name ()
  "Read and return a library name, defaulting to the one near point.

A library name is the filename of an Emacs Lisp library located
in a directory under `load-path' (or `find-library-source-path',
if non-nil)."
  (let* ((dirs (or find-library-source-path load-path))
         (suffixes (find-library-suffixes))
         (def (if (eq (function-called-at-point) 'require)
                  ;; `function-called-at-point' may return 'require
                  ;; with `point' anywhere on this line.  So wrap the
                  ;; `save-excursion' below in a `condition-case' to
                  ;; avoid reporting a scan-error here.
                  (condition-case nil
                      (save-excursion
                        (backward-up-list)
                        (forward-char)
                        (forward-sexp 2)
                        (thing-at-point 'symbol))
                    (error nil))
                (thing-at-point 'symbol))))
    (if find-library-include-other-files
        (let ((table (apply-partially #'locate-file-completion-table
                                      dirs suffixes)))
          (when (and def (not (test-completion def table)))
            (setq def nil))
          (completing-read (format-prompt "Library name" def)
                           table nil nil nil
                           'find-function--read-history-library def))
      (let ((files (read-library-name--find-files dirs suffixes)))
        (when (and def (not (member def files)))
          (setq def nil))
        (completing-read (format-prompt "Library name" def)
                         files nil t nil
                         'find-function--read-history-library def)))))