From bb64e3a7985c5473f7b15ebcfe5f6b87d2237d92 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 18 Nov 2023 10:13:37 +0200 Subject: [PATCH] Avoid loading cl-lib as result of invoking 'load-library' * lisp/emacs-lisp/find-func.el (find-function--any-subform-p): Don't use 'cl-destructuring-bind'. (find-library--from-load-history): Don't use 'cl-loop'. * lisp/thingatpt.el (thing-at-point): Don't use 'cl-loop'. This avoids loading cl-lib whenever thingatpt.el is loaded, for example, as result of "M-x load-library". --- lisp/emacs-lisp/find-func.el | 25 +++++++++++++++---------- lisp/thingatpt.el | 14 ++++++++------ 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el index d393ccc759a..24d31fefd7d 100644 --- a/lisp/emacs-lisp/find-func.el +++ b/lisp/emacs-lisp/find-func.el @@ -42,8 +42,6 @@ ;;; Code: -(eval-when-compile (require 'cl-lib)) - ;;; User variables: (defgroup find-function nil @@ -247,13 +245,19 @@ LIBRARY should be a string (the name of the library)." ;; LIBRARY may be "foo.el" or "foo". (let ((load-re (concat "\\(" (regexp-quote (file-name-sans-extension library)) "\\)" - (regexp-opt (get-load-suffixes)) "\\'"))) - (cl-loop - for (file . _) in load-history thereis - (and (stringp file) (string-match load-re file) - (let ((dir (substring file 0 (match-beginning 1))) - (basename (match-string 1 file))) - (locate-file basename (list dir) (find-library-suffixes))))))) + (regexp-opt (get-load-suffixes)) "\\'")) + (alist load-history) + elt file found) + (while (and alist (null found)) + (setq elt (car alist) + alist (cdr alist) + file (car elt) + found (and (stringp file) (string-match load-re file) + (let ((dir (substring file 0 (match-beginning 1))) + (basename (match-string 1 file))) + (locate-file basename (list dir) + (find-library-suffixes)))))) + found)) (defvar find-function-C-source-directory (let ((dir (expand-file-name "src" source-directory))) @@ -469,7 +473,8 @@ Return t if any PRED returns t." ((not (consp form)) nil) ((funcall pred form) t) (t - (cl-destructuring-bind (left-child . right-child) form + (let ((left-child (car form)) + (right-child (cdr form))) (or (find-function--any-subform-p left-child pred) (find-function--any-subform-p right-child pred)))))) diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 5d4f4df9131..88efbf73beb 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -52,7 +52,6 @@ ;;; Code: -(require 'cl-lib) (provide 'thingatpt) (defvar thing-at-point-provider-alist nil @@ -175,11 +174,14 @@ See the file `thingatpt.el' for documentation on how to define a symbol as a valid THING." (let ((text (cond - ((cl-loop for (pthing . function) in thing-at-point-provider-alist - when (eq pthing thing) - for result = (funcall function) - when result - return result)) + ((let ((alist thing-at-point-provider-alist) + elt result) + (while (and alist (null result)) + (setq elt (car alist) + alist (cdr alist)) + (and (eq (car elt) thing) + (setq result (funcall (cdr elt))))) + result)) ((get thing 'thing-at-point) (funcall (get thing 'thing-at-point))) (t -- 2.39.2