- (list
- (completing-read "Library name: "
- 'locate-file-completion
- (cons (or find-function-source-path load-path)
- (find-library-suffixes)))))
+ (let* ((dirs (or find-function-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))))
+ (when def
+ (setq def (and (locate-file-completion-table
+ dirs suffixes def nil 'lambda)
+ def)))
+ (list
+ (completing-read (if def (format "Library name (default %s): " def)
+ "Library name: ")
+ (apply-partially 'locate-file-completion-table
+ dirs suffixes)
+ nil nil nil nil def))))