Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
;;; cl-lib.el --- Common Lisp extensions for Emacs -*- lexical-binding: t -*-
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2025-01-01 07:39:17 +00:00
|
|
|
;; Copyright (C) 1993, 2001-2025 Free Software Foundation, Inc.
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
;; Author: Dave Gillespie <daveg@synaptics.com>
|
2012-11-16 10:59:40 -05:00
|
|
|
;; Version: 1.0
|
2012-06-03 21:05:17 -04:00
|
|
|
;; Keywords: extensions
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; These are extensions to Emacs Lisp that provide a degree of
|
|
|
|
;; Common Lisp compatibility, beyond what is already built-in
|
|
|
|
;; in Emacs Lisp.
|
|
|
|
;;
|
|
|
|
;; This package was written by Dave Gillespie; it is a complete
|
|
|
|
;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
|
|
|
|
;;
|
|
|
|
;; Bug reports, comments, and suggestions are welcome!
|
|
|
|
|
|
|
|
;; This file contains the portions of the Common Lisp extensions
|
|
|
|
;; package which should always be present.
|
|
|
|
|
|
|
|
|
|
|
|
;;; Change Log:
|
|
|
|
|
|
|
|
;; Version 2.02 (30 Jul 93):
|
|
|
|
;; * Added "cl-compat.el" file, extra compatibility with old package.
|
|
|
|
;; * Added `lexical-let' and `lexical-let*'.
|
|
|
|
;; * Added `define-modify-macro', `callf', and `callf2'.
|
|
|
|
;; * Added `ignore-errors'.
|
|
|
|
;; * Changed `(setf (nthcdr N PLACE) X)' to work when N is zero.
|
|
|
|
;; * Merged `*gentemp-counter*' into `*gensym-counter*'.
|
|
|
|
;; * Extended `subseq' to allow negative START and END like `substring'.
|
|
|
|
;; * Added `in-ref', `across-ref', `elements of-ref' loop clauses.
|
|
|
|
;; * Added `concat', `vconcat' loop clauses.
|
|
|
|
;; * Cleaned up a number of compiler warnings.
|
|
|
|
|
|
|
|
;; Version 2.01 (7 Jul 93):
|
|
|
|
;; * Added support for FSF version of Emacs 19.
|
|
|
|
;; * Added `add-hook' for Emacs 18 users.
|
|
|
|
;; * Added `defsubst*' and `symbol-macrolet'.
|
|
|
|
;; * Added `maplist', `mapc', `mapl', `mapcan', `mapcon'.
|
|
|
|
;; * Added `map', `concatenate', `reduce', `merge'.
|
|
|
|
;; * Added `revappend', `nreconc', `tailp', `tree-equal'.
|
|
|
|
;; * Added `assert', `check-type', `typecase', `typep', and `deftype'.
|
|
|
|
;; * Added destructuring and `&environment' support to `defmacro*'.
|
|
|
|
;; * Added destructuring to `loop', and added the following clauses:
|
|
|
|
;; `elements', `frames', `overlays', `intervals', `buffers', `key-seqs'.
|
|
|
|
;; * Renamed `delete' to `delete*' and `remove' to `remove*'.
|
|
|
|
;; * Completed support for all keywords in `remove*', `substitute', etc.
|
|
|
|
;; * Added `most-positive-float' and company.
|
|
|
|
;; * Fixed hash tables to work with latest Lucid Emacs.
|
|
|
|
;; * `proclaim' forms are no longer compile-time-evaluating; use `declaim'.
|
|
|
|
;; * Syntax for `warn' declarations has changed.
|
|
|
|
;; * Improved implementation of `random*'.
|
|
|
|
;; * Moved most sequence functions to a new file, cl-seq.el.
|
|
|
|
;; * Moved `eval-when' into cl-macs.el.
|
|
|
|
;; * Moved `pushnew' and `adjoin' to cl.el for most common cases.
|
|
|
|
;; * Moved `provide' forms down to ends of files.
|
|
|
|
;; * Changed expansion of `pop' to something that compiles to better code.
|
|
|
|
;; * Changed so that no patch is required for Emacs 19 byte compiler.
|
|
|
|
;; * Made more things dependent on `optimize' declarations.
|
|
|
|
;; * Added a partial implementation of struct print functions.
|
|
|
|
;; * Miscellaneous minor changes.
|
|
|
|
|
|
|
|
;; Version 2.00:
|
|
|
|
;; * First public release of this package.
|
|
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2012-06-30 08:52:08 -04:00
|
|
|
(require 'macroexp)
|
2012-06-30 08:05:22 -04:00
|
|
|
|
2012-12-06 16:29:29 -05:00
|
|
|
(defvar cl--optimize-speed 1)
|
|
|
|
(defvar cl--optimize-safety 1)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defvar cl-custom-print-functions nil
|
|
|
|
"This is a list of functions that format user objects for printing.
|
|
|
|
Each function is called in turn with three arguments: the object, the
|
|
|
|
stream, and the print level (currently ignored). If it is able to
|
|
|
|
print the object it returns true; otherwise it returns nil and the
|
|
|
|
printer proceeds to the next function on the list.
|
|
|
|
|
|
|
|
This variable is not used at present, but it is defined in hopes that
|
|
|
|
a future Emacs interpreter will be able to use it.")
|
|
|
|
|
|
|
|
;;; Generalized variables.
|
|
|
|
;; These macros are defined here so that they
|
2012-09-17 13:41:04 +08:00
|
|
|
;; can safely be used in init files.
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2019-08-30 12:20:30 +02:00
|
|
|
;;;###autoload
|
New macros incf and decf
* lisp/emacs-lisp/cl-lib.el (cl-incf, cl-decf): Move macros from here...
* lisp/emacs-lisp/gv.el (incf, decf): ...to here. Make old names into
aliases, documented as deprecated.
* lisp/obsolete/cl.el: Don't alias incf and decf.
* test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-test-incf)
(cl-lib-test-decf): Move tests from here...
* test/lisp/emacs-lisp/gv-tests.el (gv-incf, gv-decf): ...to here.
* doc/lispref/numbers.texi (Arithmetic Operations):
* lisp/emacs-lisp/shortdoc.el (number): Document incf and decf.
* doc/lispref/variables.texi (Multisession Variables):
* doc/misc/cl.texi (Organization, Modify Macros, Modify Macros)
(Modify Macros, Macro Bindings, For Clauses, Property Lists)
(Structures, Efficiency Concerns, Obsolete Setf Customization): Delete
cl-incf and cl-decf documentation, moving any relevant parts to lispref.
Delete some parts that seem to primarily regard implementation details
that do not warrant inclusion in lispref. Update all examples to use
incf/decf.
2025-02-22 17:32:31 +01:00
|
|
|
(defalias 'cl-incf #'incf
|
2012-06-03 21:05:17 -04:00
|
|
|
"Increment PLACE by X (1 by default).
|
Provide generalized variables in core Elisp.
* lisp/emacs-lisp/gv.el: New file.
* lisp/subr.el (push, pop): Extend to generalized variables.
* lisp/loadup.el (macroexp): Unload if preloaded and uncompiled.
* lisp/emacs-lisp/cl-lib.el (cl-pop, cl-push, cl--set-nthcdr): Remove.
* lisp/emacs-lisp/cl-macs.el: Require gv. Use gv-define-setter,
gv-define-simple-setter, and gv-define-expander.
Remove setf-methods defined in gv. Rename cl-setf -> setf.
(cl-setf, cl-do-pop, cl-get-setf-method): Remove.
(cl-letf, cl-letf*, cl-define-modify-macro, cl-defsetf)
(cl-define-setf-expander, cl-struct-setf-expander): Move to cl.el.
(cl-remf, cl-shiftf, cl-rotatef, cl-callf, cl-callf2): Rewrite with
gv-letplace.
(cl-defstruct): Don't define setf-method any more.
* lisp/emacs-lisp/cl.el (flet): Don't autoload.
(cl--letf, letf, cl--letf*, letf*, cl--gv-adapt)
(define-setf-expander, defsetf, define-modify-macro)
(cl-struct-setf-expander): Move from cl-lib.el.
* lisp/emacs-lisp/syntax.el:
* lisp/emacs-lisp/ewoc.el:
* lisp/emacs-lisp/smie.el:
* lisp/emacs-lisp/cconv.el:
* lisp/emacs-lisp/timer.el: Rename cl-setf -> setf, cl-push -> push.
(timer--time): Use gv-define-simple-setter.
* lisp/emacs-lisp/macroexp.el (macroexp-let2): Rename from macroexp-let²
to avoid coding-system problems in subr.el. Adjust all users.
(macroexp--maxsize, macroexp-small-p): New functions.
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Don't use cl-letf.
* lisp/scroll-bar.el (scroll-bar-mode):
* lisp/simple.el (auto-fill-mode, overwrite-mode, binary-overwrite-mode)
(normal-erase-is-backspace-mode): Don't use the `eq' place.
* lisp/winner.el (winner-configuration, winner-make-point-alist)
(winner-set-conf, winner-get-point, winner-set): Don't abuse letf.
* lisp/files.el (locate-file-completion-table): Avoid list*.
Fixes: debbugs:11657
2012-06-22 09:42:38 -04:00
|
|
|
PLACE may be a symbol, or any generalized variable allowed by `setf'.
|
2022-04-21 15:11:25 +02:00
|
|
|
The return value is the incremented value of PLACE.
|
|
|
|
|
|
|
|
If X is specified, it should be an expression that should
|
New macros incf and decf
* lisp/emacs-lisp/cl-lib.el (cl-incf, cl-decf): Move macros from here...
* lisp/emacs-lisp/gv.el (incf, decf): ...to here. Make old names into
aliases, documented as deprecated.
* lisp/obsolete/cl.el: Don't alias incf and decf.
* test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-test-incf)
(cl-lib-test-decf): Move tests from here...
* test/lisp/emacs-lisp/gv-tests.el (gv-incf, gv-decf): ...to here.
* doc/lispref/numbers.texi (Arithmetic Operations):
* lisp/emacs-lisp/shortdoc.el (number): Document incf and decf.
* doc/lispref/variables.texi (Multisession Variables):
* doc/misc/cl.texi (Organization, Modify Macros, Modify Macros)
(Modify Macros, Macro Bindings, For Clauses, Property Lists)
(Structures, Efficiency Concerns, Obsolete Setf Customization): Delete
cl-incf and cl-decf documentation, moving any relevant parts to lispref.
Delete some parts that seem to primarily regard implementation details
that do not warrant inclusion in lispref. Update all examples to use
incf/decf.
2025-02-22 17:32:31 +01:00
|
|
|
evaluate to a number.
|
2012-06-03 21:05:17 -04:00
|
|
|
|
New macros incf and decf
* lisp/emacs-lisp/cl-lib.el (cl-incf, cl-decf): Move macros from here...
* lisp/emacs-lisp/gv.el (incf, decf): ...to here. Make old names into
aliases, documented as deprecated.
* lisp/obsolete/cl.el: Don't alias incf and decf.
* test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-test-incf)
(cl-lib-test-decf): Move tests from here...
* test/lisp/emacs-lisp/gv-tests.el (gv-incf, gv-decf): ...to here.
* doc/lispref/numbers.texi (Arithmetic Operations):
* lisp/emacs-lisp/shortdoc.el (number): Document incf and decf.
* doc/lispref/variables.texi (Multisession Variables):
* doc/misc/cl.texi (Organization, Modify Macros, Modify Macros)
(Modify Macros, Macro Bindings, For Clauses, Property Lists)
(Structures, Efficiency Concerns, Obsolete Setf Customization): Delete
cl-incf and cl-decf documentation, moving any relevant parts to lispref.
Delete some parts that seem to primarily regard implementation details
that do not warrant inclusion in lispref. Update all examples to use
incf/decf.
2025-02-22 17:32:31 +01:00
|
|
|
This macro is considered deprecated in favor of the built-in macro
|
|
|
|
`incf' that was added in Emacs 31.1.")
|
|
|
|
|
|
|
|
(defalias 'cl-decf #'decf
|
2012-06-03 21:05:17 -04:00
|
|
|
"Decrement PLACE by X (1 by default).
|
Provide generalized variables in core Elisp.
* lisp/emacs-lisp/gv.el: New file.
* lisp/subr.el (push, pop): Extend to generalized variables.
* lisp/loadup.el (macroexp): Unload if preloaded and uncompiled.
* lisp/emacs-lisp/cl-lib.el (cl-pop, cl-push, cl--set-nthcdr): Remove.
* lisp/emacs-lisp/cl-macs.el: Require gv. Use gv-define-setter,
gv-define-simple-setter, and gv-define-expander.
Remove setf-methods defined in gv. Rename cl-setf -> setf.
(cl-setf, cl-do-pop, cl-get-setf-method): Remove.
(cl-letf, cl-letf*, cl-define-modify-macro, cl-defsetf)
(cl-define-setf-expander, cl-struct-setf-expander): Move to cl.el.
(cl-remf, cl-shiftf, cl-rotatef, cl-callf, cl-callf2): Rewrite with
gv-letplace.
(cl-defstruct): Don't define setf-method any more.
* lisp/emacs-lisp/cl.el (flet): Don't autoload.
(cl--letf, letf, cl--letf*, letf*, cl--gv-adapt)
(define-setf-expander, defsetf, define-modify-macro)
(cl-struct-setf-expander): Move from cl-lib.el.
* lisp/emacs-lisp/syntax.el:
* lisp/emacs-lisp/ewoc.el:
* lisp/emacs-lisp/smie.el:
* lisp/emacs-lisp/cconv.el:
* lisp/emacs-lisp/timer.el: Rename cl-setf -> setf, cl-push -> push.
(timer--time): Use gv-define-simple-setter.
* lisp/emacs-lisp/macroexp.el (macroexp-let2): Rename from macroexp-let²
to avoid coding-system problems in subr.el. Adjust all users.
(macroexp--maxsize, macroexp-small-p): New functions.
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Don't use cl-letf.
* lisp/scroll-bar.el (scroll-bar-mode):
* lisp/simple.el (auto-fill-mode, overwrite-mode, binary-overwrite-mode)
(normal-erase-is-backspace-mode): Don't use the `eq' place.
* lisp/winner.el (winner-configuration, winner-make-point-alist)
(winner-set-conf, winner-get-point, winner-set): Don't abuse letf.
* lisp/files.el (locate-file-completion-table): Avoid list*.
Fixes: debbugs:11657
2012-06-22 09:42:38 -04:00
|
|
|
PLACE may be a symbol, or any generalized variable allowed by `setf'.
|
2022-04-21 15:11:25 +02:00
|
|
|
The return value is the decremented value of PLACE.
|
|
|
|
|
|
|
|
If X is specified, it should be an expression that should
|
New macros incf and decf
* lisp/emacs-lisp/cl-lib.el (cl-incf, cl-decf): Move macros from here...
* lisp/emacs-lisp/gv.el (incf, decf): ...to here. Make old names into
aliases, documented as deprecated.
* lisp/obsolete/cl.el: Don't alias incf and decf.
* test/lisp/emacs-lisp/cl-lib-tests.el (cl-lib-test-incf)
(cl-lib-test-decf): Move tests from here...
* test/lisp/emacs-lisp/gv-tests.el (gv-incf, gv-decf): ...to here.
* doc/lispref/numbers.texi (Arithmetic Operations):
* lisp/emacs-lisp/shortdoc.el (number): Document incf and decf.
* doc/lispref/variables.texi (Multisession Variables):
* doc/misc/cl.texi (Organization, Modify Macros, Modify Macros)
(Modify Macros, Macro Bindings, For Clauses, Property Lists)
(Structures, Efficiency Concerns, Obsolete Setf Customization): Delete
cl-incf and cl-decf documentation, moving any relevant parts to lispref.
Delete some parts that seem to primarily regard implementation details
that do not warrant inclusion in lispref. Update all examples to use
incf/decf.
2025-02-22 17:32:31 +01:00
|
|
|
evaluate to a number.
|
|
|
|
|
|
|
|
This macro is considered deprecated in favor of the built-in macro
|
|
|
|
`decf' that was added in Emacs 31.1.")
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
(defmacro cl-pushnew (x place &rest keys)
|
2019-08-23 11:43:30 +03:00
|
|
|
"Add X to the list stored in PLACE unless X is already in the list.
|
2019-08-23 06:12:44 +02:00
|
|
|
PLACE is a generalized variable that stores a list.
|
|
|
|
|
2019-08-23 11:43:30 +03:00
|
|
|
Like (push X PLACE), except that PLACE is unmodified if X is `eql'
|
|
|
|
to an element already in the list stored in PLACE.
|
2019-08-23 06:12:44 +02:00
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
\nKeywords supported: :test :test-not :key
|
|
|
|
\n(fn X PLACE [KEYWORD VALUE]...)"
|
|
|
|
(declare (debug
|
|
|
|
(form place &rest
|
2021-02-12 16:08:01 -05:00
|
|
|
&or [[&or ":test" ":test-not" ":key"] form]
|
2012-06-03 21:05:17 -04:00
|
|
|
[keywordp form])))
|
|
|
|
(if (symbolp place)
|
|
|
|
(if (null keys)
|
2012-06-29 22:00:08 -04:00
|
|
|
(macroexp-let2 nil var x
|
|
|
|
`(if (memql ,var ,place)
|
|
|
|
;; This symbol may later on expand to actual code which then
|
|
|
|
;; trigger warnings like "value unused" since cl-pushnew's
|
|
|
|
;; return value is rarely used. It should not matter that
|
|
|
|
;; other warnings may be silenced, since `place' is used
|
|
|
|
;; earlier and should have triggered them already.
|
|
|
|
(with-no-warnings ,place)
|
|
|
|
(setq ,place (cons ,var ,place))))
|
2013-06-04 22:35:40 -04:00
|
|
|
`(setq ,place (cl-adjoin ,x ,place ,@keys)))
|
|
|
|
`(cl-callf2 cl-adjoin ,x ,place ,@keys)))
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2025-03-28 01:01:17 -04:00
|
|
|
(defun cl--set-buffer-substring (start end val &optional inherit)
|
2023-10-29 21:56:54 +00:00
|
|
|
"Delete region from START to END and insert VAL."
|
2025-03-28 01:01:17 -04:00
|
|
|
(replace-region-contents start end val 0 nil inherit)
|
|
|
|
val)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(defun cl--set-substring (str start end val)
|
Prefer incf to cl-incf in emacs-lisp/*.el
* lisp/emacs-lisp/backtrace.el (backtrace--print-func-and-args):
* lisp/emacs-lisp/bindat.el (bindat--type):
* lisp/emacs-lisp/bytecomp.el (byte-recompile-directory):
* lisp/emacs-lisp/chart.el (chart-file-count):
* lisp/emacs-lisp/cl-extra.el (cl-parse-integer, cl--print-table):
* lisp/emacs-lisp/cl-generic.el (cl--defmethod-doc-pos):
* lisp/emacs-lisp/cl-indent.el (common-lisp-loop-part-indentation)
(common-lisp-indent-function-1, lisp-indent-defmethod):
* lisp/emacs-lisp/cl-lib.el (cl--set-substring):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-preloaded.el (cl-struct-define):
* lisp/emacs-lisp/cl-print.el (cl-print--cons-tail)
(cl-print--vector-contents, cl-print--struct-contents)
(cl-print--string-props):
* lisp/emacs-lisp/cl-seq.el (cl-substitute):
* lisp/emacs-lisp/comp-cstr.el (comp--range-union)
(comp--range-intersection):
* lisp/emacs-lisp/comp.el (comp-vec-append, comp--gen-counter)
(comp--op-case, comp--limplify-lap-inst, comp--limplify-block)
(comp--limplify-function, comp--maybe-add-vmvar, comp--fwprop*):
* lisp/emacs-lisp/edebug.el (edebug--called-interactively-skip):
* lisp/emacs-lisp/eldoc.el (eldoc--invoke-strategy):
* lisp/emacs-lisp/elp.el (elp--make-wrapper):
* lisp/emacs-lisp/ert-x.el (ert-kill-all-test-buffers):
* lisp/emacs-lisp/ert.el (ert--stats-set-test-and-result)
(ert-write-junit-test-summary-report):
* lisp/emacs-lisp/memory-report.el (memory-report--symbol-plist)
(memory-report--object-size-1):
* lisp/emacs-lisp/oclosure.el (oclosure--index-table)
(oclosure--define-functions):
* lisp/emacs-lisp/package.el (package-menu--perform-transaction):
* lisp/emacs-lisp/smie.el (smie-set-prec2tab, smie-prec2->grammar)
(smie-config--guess, smie-config--guess-1):
* lisp/emacs-lisp/syntax.el (syntax-propertize-rules)
(syntax-ppss--update-stats):
* lisp/emacs-lisp/track-changes.el (track-changes--after): Prefer incf
to cl-incf.
2025-02-23 00:13:21 +01:00
|
|
|
(if end (if (< end 0) (incf end (length str)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(setq end (length str)))
|
Prefer incf to cl-incf in emacs-lisp/*.el
* lisp/emacs-lisp/backtrace.el (backtrace--print-func-and-args):
* lisp/emacs-lisp/bindat.el (bindat--type):
* lisp/emacs-lisp/bytecomp.el (byte-recompile-directory):
* lisp/emacs-lisp/chart.el (chart-file-count):
* lisp/emacs-lisp/cl-extra.el (cl-parse-integer, cl--print-table):
* lisp/emacs-lisp/cl-generic.el (cl--defmethod-doc-pos):
* lisp/emacs-lisp/cl-indent.el (common-lisp-loop-part-indentation)
(common-lisp-indent-function-1, lisp-indent-defmethod):
* lisp/emacs-lisp/cl-lib.el (cl--set-substring):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-preloaded.el (cl-struct-define):
* lisp/emacs-lisp/cl-print.el (cl-print--cons-tail)
(cl-print--vector-contents, cl-print--struct-contents)
(cl-print--string-props):
* lisp/emacs-lisp/cl-seq.el (cl-substitute):
* lisp/emacs-lisp/comp-cstr.el (comp--range-union)
(comp--range-intersection):
* lisp/emacs-lisp/comp.el (comp-vec-append, comp--gen-counter)
(comp--op-case, comp--limplify-lap-inst, comp--limplify-block)
(comp--limplify-function, comp--maybe-add-vmvar, comp--fwprop*):
* lisp/emacs-lisp/edebug.el (edebug--called-interactively-skip):
* lisp/emacs-lisp/eldoc.el (eldoc--invoke-strategy):
* lisp/emacs-lisp/elp.el (elp--make-wrapper):
* lisp/emacs-lisp/ert-x.el (ert-kill-all-test-buffers):
* lisp/emacs-lisp/ert.el (ert--stats-set-test-and-result)
(ert-write-junit-test-summary-report):
* lisp/emacs-lisp/memory-report.el (memory-report--symbol-plist)
(memory-report--object-size-1):
* lisp/emacs-lisp/oclosure.el (oclosure--index-table)
(oclosure--define-functions):
* lisp/emacs-lisp/package.el (package-menu--perform-transaction):
* lisp/emacs-lisp/smie.el (smie-set-prec2tab, smie-prec2->grammar)
(smie-config--guess, smie-config--guess-1):
* lisp/emacs-lisp/syntax.el (syntax-propertize-rules)
(syntax-ppss--update-stats):
* lisp/emacs-lisp/track-changes.el (track-changes--after): Prefer incf
to cl-incf.
2025-02-23 00:13:21 +01:00
|
|
|
(if (< start 0) (incf start (length str)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(concat (and (> start 0) (substring str 0 start))
|
|
|
|
val
|
|
|
|
(and (< end (length str)) (substring str end))))
|
|
|
|
|
2023-09-04 16:39:55 -04:00
|
|
|
(gv-define-expander substring
|
|
|
|
(lambda (do place from &optional to)
|
|
|
|
(gv-letplace (getter setter) place
|
|
|
|
(macroexp-let2* nil ((start from) (end to))
|
|
|
|
(funcall do `(substring ,getter ,start ,end)
|
|
|
|
(lambda (v)
|
|
|
|
(macroexp-let2 nil v v
|
|
|
|
`(progn
|
|
|
|
,(funcall setter `(cl--set-substring
|
|
|
|
,getter ,start ,end ,v))
|
|
|
|
,v))))))))
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
;;; Blocks and exits.
|
|
|
|
|
2025-02-13 03:59:30 +01:00
|
|
|
(defalias 'cl--block-wrapper #'identity)
|
|
|
|
(defalias 'cl--block-throw #'throw)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;; Multiple values.
|
|
|
|
;; True multiple values are not supported, or even
|
|
|
|
;; simulated. Instead, cl-multiple-value-bind and friends simply expect
|
|
|
|
;; the target form to return the values as a list.
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defun cl--defalias (cl-f el-f &optional doc)
|
2023-10-29 21:56:54 +00:00
|
|
|
"Define function CL-F as definition EL-F.
|
2023-10-30 18:50:47 -04:00
|
|
|
Like `defalias' but marks the alias itself as inlinable."
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defalias cl-f el-f doc)
|
|
|
|
(put cl-f 'byte-optimizer 'byte-compile-inline-expand))
|
|
|
|
|
|
|
|
(cl--defalias 'cl-values #'list
|
2012-06-03 21:05:17 -04:00
|
|
|
"Return multiple values, Common Lisp style.
|
|
|
|
The arguments of `cl-values' are the values
|
|
|
|
that the containing function should return.
|
|
|
|
|
|
|
|
\(fn &rest VALUES)")
|
|
|
|
|
2019-07-28 14:14:46 +02:00
|
|
|
(defun cl-values-list (list)
|
2012-06-03 21:05:17 -04:00
|
|
|
"Return multiple values, Common Lisp style, taken from a list.
|
2019-07-28 14:14:46 +02:00
|
|
|
LIST specifies the list of values that the containing function
|
|
|
|
should return.
|
|
|
|
|
|
|
|
Note that Emacs Lisp doesn't really support multiple values, so
|
|
|
|
all this function does is return LIST."
|
|
|
|
(unless (listp list)
|
2023-01-03 14:03:58 +01:00
|
|
|
(signal 'wrong-type-argument (list list)))
|
2019-07-28 14:14:46 +02:00
|
|
|
list)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
(defsubst cl-multiple-value-list (expression)
|
|
|
|
"Return a list of the multiple values produced by EXPRESSION.
|
|
|
|
This handles multiple values in Common Lisp style, but it does not
|
|
|
|
work right when EXPRESSION calls an ordinary Emacs Lisp function
|
|
|
|
that returns just one value."
|
|
|
|
expression)
|
|
|
|
|
|
|
|
(defsubst cl-multiple-value-apply (function expression)
|
|
|
|
"Evaluate EXPRESSION to get multiple values and apply FUNCTION to them.
|
|
|
|
This handles multiple values in Common Lisp style, but it does not work
|
|
|
|
right when EXPRESSION calls an ordinary Emacs Lisp function that returns just
|
|
|
|
one value."
|
|
|
|
(apply function expression))
|
|
|
|
|
2025-02-13 03:59:30 +01:00
|
|
|
(defalias 'cl-multiple-value-call #'apply
|
2012-06-03 21:05:17 -04:00
|
|
|
"Apply FUNCTION to ARGUMENTS, taking multiple values into account.
|
|
|
|
This implementation only handles the case where there is only one argument.")
|
|
|
|
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
(cl--defalias 'cl-nth-value #'nth
|
2012-06-03 21:05:17 -04:00
|
|
|
"Evaluate EXPRESSION to get multiple values and return the Nth one.
|
|
|
|
This handles multiple values in Common Lisp style, but it does not work
|
|
|
|
right when EXPRESSION calls an ordinary Emacs Lisp function that returns just
|
More CL cleanups and reduction of use of cl.el.
* woman.el, winner.el, vc/vc-rcs.el, vc/vc-hooks.el, vc/vc-hg.el:
* vc/vc-git.el, vc/vc-dir.el, vc/vc-bzr.el, vc/vc-annotate.el:
* textmodes/tex-mode.el, textmodes/sgml-mode.el, tar-mode.el:
* strokes.el, ses.el, server.el, progmodes/js.el, progmodes/gdb-mi.el:
* progmodes/flymake.el, progmodes/ebrowse.el, progmodes/compile.el:
* play/tetris.el, play/snake.el, play/pong.el, play/landmark.el:
* play/hanoi.el, play/decipher.el, play/5x5.el, nxml/nxml-mode.el:
* net/secrets.el, net/quickurl.el, midnight.el, mail/footnote.el:
* image-dired.el, ibuffer.el, ibuf-macs.el, ibuf-ext.el, hexl.el:
* eshell/eshell.el, eshell/esh-io.el, eshell/esh-ext.el:
* eshell/esh-cmd.el, eshell/em-ls.el, eshell/em-hist.el:
* eshell/em-cmpl.el, eshell/em-banner.el:
* url/url.el, url/url-queue.el, url/url-parse.el, url/url-http.el:
* url/url-future.el, url/url-dav.el, url/url-cookie.el:
* calendar/parse-time.el, test/eshell.el: Use cl-lib.
* wid-browse.el, wdired.el, vc/vc.el, vc/vc-mtn.el, vc/vc-cvs.el:
* vc/vc-arch.el, tree-widget.el, textmodes/texinfo.el:
* textmodes/refill.el, textmodes/css-mode.el, term/tvi970.el:
* term/ns-win.el, term.el, shell.el, ps-samp.el:
* progmodes/perl-mode.el, progmodes/pascal.el, progmodes/gud.el:
* progmodes/glasses.el, progmodes/etags.el, progmodes/cwarn.el:
* play/gamegrid.el, play/bubbles.el, novice.el, notifications.el:
* net/zeroconf.el, net/xesam.el, net/snmp-mode.el, net/mairix.el:
* net/ldap.el, net/eudc.el, net/browse-url.el, man.el:
* mail/mailheader.el, mail/feedmail.el:
* url/url-util.el, url/url-privacy.el, url/url-nfs.el, url/url-misc.el:
* url/url-methods.el, url/url-gw.el, url/url-file.el, url/url-expand.el:
Dont use CL.
* ibuf-ext.el (ibuffer-mark-old-buffers): Use float-time.
* eshell/esh-opt.el (eshell-eval-using-options): Quote code with
`lambda' rather than with `quote'.
(eshell-do-opt): Adjust accordingly.
(eshell-process-option): Simplify.
* eshell/esh-var.el:
* eshell/em-script.el: Require `esh-opt' for eshell-eval-using-options.
* emacs-pcase.el (pcase--dontcare-upats, pcase--let*)
(pcase--expand, pcase--u1): Rename pcase's internal `dontcare' pattern
to `pcase--dontcare'.
* emacs-cl.el (labels): Mark obsolete.
(cl--letf, letf): Move to cl-lib.
(cl--letf*, letf*): Remove.
* emacs-cl-lib.el (cl-nth-value): Use defalias.
* emacs-cl-macs.el (cl-dolist, cl-dotimes): Add indent rule.
(cl-progv): Rewrite.
(cl--letf, cl-letf): Move from cl.el.
(cl-letf*): New macro.
* emacs-cl-extra.el (cl--progv-before, cl--progv-after): Remove.
2012-07-11 19:13:41 -04:00
|
|
|
one value.
|
|
|
|
|
|
|
|
\(fn N EXPRESSION)")
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
;;; Declarations.
|
|
|
|
|
2021-02-24 13:52:45 -05:00
|
|
|
(define-obsolete-function-alias 'cl--compiling-file
|
|
|
|
#'macroexp-compiling-p "28.1")
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2012-12-06 16:29:29 -05:00
|
|
|
(defvar cl--proclaims-deferred nil)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
(defun cl-proclaim (spec)
|
2012-11-05 00:29:12 -08:00
|
|
|
"Record a global declaration specified by SPEC."
|
2012-12-06 16:29:29 -05:00
|
|
|
(if (fboundp 'cl--do-proclaim) (cl--do-proclaim spec t)
|
|
|
|
(push spec cl--proclaims-deferred))
|
2012-06-03 21:05:17 -04:00
|
|
|
nil)
|
|
|
|
|
|
|
|
(defmacro cl-declaim (&rest specs)
|
2012-11-05 00:29:12 -08:00
|
|
|
"Like `cl-proclaim', but takes any number of unevaluated, unquoted arguments.
|
|
|
|
Puts `(cl-eval-when (compile load eval) ...)' around the declarations
|
|
|
|
so that they are registered at compile-time as well as run-time."
|
2012-12-09 20:32:36 -05:00
|
|
|
(let ((body (mapcar (lambda (x) `(cl-proclaim ',x)) specs)))
|
2021-02-24 13:52:45 -05:00
|
|
|
(if (macroexp-compiling-p) `(cl-eval-when (compile load eval) ,@body)
|
2012-12-06 16:29:29 -05:00
|
|
|
`(progn ,@body)))) ; Avoid loading cl-macs.el for cl-eval-when.
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;; Numbers.
|
|
|
|
|
2013-02-19 21:07:07 -05:00
|
|
|
(define-obsolete-function-alias 'cl-floatp-safe 'floatp "24.4")
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2025-02-17 21:58:53 +01:00
|
|
|
(defalias 'cl-plusp #'plusp
|
|
|
|
"Return t if NUMBER is positive.
|
|
|
|
|
|
|
|
This function is considered deprecated in favor of the built-in function
|
|
|
|
`plusp' that was added in Emacs 31.1.")
|
|
|
|
|
|
|
|
(defalias 'cl-minusp #'minusp
|
|
|
|
"Return t if NUMBER is negative.
|
|
|
|
|
|
|
|
This function is considered deprecated in favor of the built-in function
|
|
|
|
`minusp' that was added in Emacs 31.1.")
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2025-02-17 00:52:45 +01:00
|
|
|
(defalias 'cl-oddp #'oddp
|
|
|
|
"Return t if INTEGER is odd.
|
|
|
|
|
|
|
|
This function is considered deprecated in favor of the built-in function
|
2025-01-19 13:59:13 +01:00
|
|
|
`oddp' that was added in Emacs 31.1.")
|
2025-02-17 00:52:45 +01:00
|
|
|
|
|
|
|
(defalias 'cl-evenp #'evenp
|
|
|
|
"Return t if INTEGER is even.
|
|
|
|
|
|
|
|
This function is considered deprecated in favor of the built-in function
|
|
|
|
`evenp' that was added in Emacs 31.1.")
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2014-09-26 08:15:21 +08:00
|
|
|
(defconst cl-digit-char-table
|
|
|
|
(let* ((digits (make-vector 256 nil))
|
|
|
|
(populate (lambda (start end base)
|
|
|
|
(mapc (lambda (i)
|
|
|
|
(aset digits i (+ base (- i start))))
|
|
|
|
(number-sequence start end)))))
|
|
|
|
(funcall populate ?0 ?9 0)
|
|
|
|
(funcall populate ?A ?Z 10)
|
|
|
|
(funcall populate ?a ?z 10)
|
|
|
|
digits))
|
|
|
|
|
|
|
|
(defun cl-digit-char-p (char &optional radix)
|
|
|
|
"Test if CHAR is a digit in the specified RADIX (default 10).
|
|
|
|
If true return the decimal value of digit CHAR in RADIX."
|
|
|
|
(or (<= 2 (or radix 10) 36)
|
|
|
|
(signal 'args-out-of-range (list 'radix radix '(2 36))))
|
|
|
|
(let ((n (aref cl-digit-char-table char)))
|
|
|
|
(and n (< n (or radix 10)) n)))
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
(defconst cl-most-positive-float nil
|
|
|
|
"The largest value that a Lisp float can hold.
|
|
|
|
If your system supports infinities, this is the largest finite value.
|
2019-11-10 15:01:06 -08:00
|
|
|
For Emacs, this equals 1.7976931348623157e+308.
|
2012-06-03 21:05:17 -04:00
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
(defconst cl-most-negative-float nil
|
|
|
|
"The largest negative value that a Lisp float can hold.
|
|
|
|
This is simply -`cl-most-positive-float'.
|
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
(defconst cl-least-positive-float nil
|
|
|
|
"The smallest value greater than zero that a Lisp float can hold.
|
2019-11-10 15:01:06 -08:00
|
|
|
For Emacs, this equals 5e-324 if subnormal numbers are supported,
|
|
|
|
`cl-least-positive-normalized-float' if they are not.
|
2012-06-03 21:05:17 -04:00
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
(defconst cl-least-negative-float nil
|
|
|
|
"The smallest value less than zero that a Lisp float can hold.
|
|
|
|
This is simply -`cl-least-positive-float'.
|
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
(defconst cl-least-positive-normalized-float nil
|
|
|
|
"The smallest normalized Lisp float greater than zero.
|
2019-11-10 15:01:06 -08:00
|
|
|
This is the smallest value that has full precision.
|
|
|
|
For Emacs, this equals 2.2250738585072014e-308.
|
2012-06-03 21:05:17 -04:00
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
(defconst cl-least-negative-normalized-float nil
|
|
|
|
"The smallest normalized Lisp float less than zero.
|
|
|
|
This is simply -`cl-least-positive-normalized-float'.
|
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
(defconst cl-float-epsilon nil
|
|
|
|
"The smallest positive float that adds to 1.0 to give a distinct value.
|
|
|
|
Adding a number less than this to 1.0 returns 1.0 due to roundoff.
|
2019-11-10 15:01:06 -08:00
|
|
|
For Emacs, this equals 2.220446049250313e-16.
|
2012-06-03 21:05:17 -04:00
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
(defconst cl-float-negative-epsilon nil
|
|
|
|
"The smallest positive float that subtracts from 1.0 to give a distinct value.
|
2019-11-10 15:01:06 -08:00
|
|
|
For Emacs, this equals 1.1102230246251565e-16.
|
2012-06-03 21:05:17 -04:00
|
|
|
Call `cl-float-limits' to set this.")
|
|
|
|
|
|
|
|
|
|
|
|
;;; Sequence functions.
|
|
|
|
|
2025-02-13 03:59:30 +01:00
|
|
|
(cl--defalias 'cl-copy-seq #'copy-sequence)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2017-02-27 16:32:10 +09:00
|
|
|
(declare-function cl--mapcar-many "cl-extra" (cl-func cl-seqs &optional acc))
|
2012-06-03 21:05:17 -04:00
|
|
|
|
Clean up 'cl-' prefixes for local variables
The 'cl-' prefixes used for let-bound variables and argument names is a
holdover from the dynbind days. They are no longer necessary, and make
the code hard to read. This was partially cleaned up in the past; let's
finish the job now.
* lisp/emacs-lisp/cl-extra.el (cl--mapcar-many, cl-map, cl-maplist)
(cl-mapc, cl-mapl, cl-mapcan, cl-mapcon, cl-some, cl-every, cl-notany)
(cl-notevery, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst)
(cl--do-subst):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-fill, cl-replace, cl-remove)
(cl-remove-if, cl-remove-if-not, cl-delete, cl-delete-if)
(cl-delete-if-not, cl-remove-duplicates, cl-delete-duplicates)
(cl--delete-duplicates, cl-substitute, cl-substitute-if)
(cl-substitute-if-not, cl-nsubstitute, cl-nsubstitute-if)
(cl-nsubstitute-if-not, cl-find, cl-find-if, cl-find-if-not)
(cl-position, cl--position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl--adjoin, cl-assoc, cl-assoc-if, cl-assoc-if-not)
(cl-rassoc, cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion)
(cl-intersection, cl-nintersection, cl-set-difference)
(cl-nset-difference, cl-set-exclusive-or, cl-nset-exclusive-or)
(cl-subsetp, cl-subst-if, cl-subst-if-not, cl-nsubst, cl-nsubst-if)
(cl-nsubst-if-not, cl-sublis, cl--sublis-rec, cl-nsublis)
(cl--nsublis-rec, cl-tree-equal, cl--tree-equal-rec): Clean up 'cl-'
prefixes for let-bound variables and arguments.
2025-03-05 02:42:10 +01:00
|
|
|
(defun cl-mapcar (func x &rest rest)
|
2012-06-03 21:05:17 -04:00
|
|
|
"Apply FUNCTION to each element of SEQ, and make a list of the results.
|
|
|
|
If there are several SEQs, FUNCTION is called with that many arguments,
|
|
|
|
and mapping stops as soon as the shortest list runs out. With just one
|
|
|
|
SEQ, this is like `mapcar'. With several, it is like the Common Lisp
|
|
|
|
`mapcar' function extended to arbitrary sequence types.
|
|
|
|
\n(fn FUNCTION SEQ...)"
|
Inline important-return-value declarations in cl-lib.el
These declarations are now properly added to 'cl-lib.el' itself, or to
'cl-loaddefs.el'. This means that they will now correctly show up
immediately when loading 'cl-lib.el', instead of only after 'cl-macs.el'
is pulled in by an autoload. C.f. Bug#76247.
I did not considered worth reproducing everywhere the list saying which
functions among the below belong to these two categories:
1. Functions that are side-effect-free except for the behavior of
functions passed as argument.
2. Functions that mutate and return a list.
AFAIU, this is not actionable with our current byte-compiler, i.e. we
can't add any extra declarations based on it. However, if the list
should be needed at some point, for example due to improvements in the
compiler, this commit will be where to find it. In the worst case, and
with more work, it's also deducible from the source code itself.
* lisp/emacs-lisp/cl-macs.el: Move important-return-value declarations
from here...
* lisp/emacs-lisp/cl-extra.el (cl-map, cl-maplist, cl-mapcan)
(cl-mapcon, cl-some, cl-every, cl-notany, cl-notevery, cl-nreconc):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-remove, cl-remove-if)
(cl-remove-if-not, cl-delete, cl-delete-if, cl-delete-if-not)
(cl-remove-duplicates, cl-delete-duplicates, cl-substitute)
(cl-substitute-if, cl-substitute-if-not, cl-nsubstitute)
(cl-nsubstitute-if, cl-nsubstitute-if-not, cl-find, cl-find-if)
(cl-find-if-not, cl-position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl-assoc, cl-assoc-if, cl-assoc-if-not, cl-rassoc)
(cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion, cl-intersection)
(cl-nintersection, cl-set-difference, cl-nset-difference)
(cl-set-exclusive-or, cl-nset-exclusive-or, cl-subsetp, cl-subst-if)
(cl-subst-if-not, cl-nsubst, cl-nsubst-if, cl-nsubst-if-not, cl-sublis)
(cl-nsublis, cl-tree-equal): ...to have them inline here.
2025-02-14 22:46:07 +01:00
|
|
|
(declare (important-return-value t))
|
Clean up 'cl-' prefixes for local variables
The 'cl-' prefixes used for let-bound variables and argument names is a
holdover from the dynbind days. They are no longer necessary, and make
the code hard to read. This was partially cleaned up in the past; let's
finish the job now.
* lisp/emacs-lisp/cl-extra.el (cl--mapcar-many, cl-map, cl-maplist)
(cl-mapc, cl-mapl, cl-mapcan, cl-mapcon, cl-some, cl-every, cl-notany)
(cl-notevery, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst)
(cl--do-subst):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-fill, cl-replace, cl-remove)
(cl-remove-if, cl-remove-if-not, cl-delete, cl-delete-if)
(cl-delete-if-not, cl-remove-duplicates, cl-delete-duplicates)
(cl--delete-duplicates, cl-substitute, cl-substitute-if)
(cl-substitute-if-not, cl-nsubstitute, cl-nsubstitute-if)
(cl-nsubstitute-if-not, cl-find, cl-find-if, cl-find-if-not)
(cl-position, cl--position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl--adjoin, cl-assoc, cl-assoc-if, cl-assoc-if-not)
(cl-rassoc, cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion)
(cl-intersection, cl-nintersection, cl-set-difference)
(cl-nset-difference, cl-set-exclusive-or, cl-nset-exclusive-or)
(cl-subsetp, cl-subst-if, cl-subst-if-not, cl-nsubst, cl-nsubst-if)
(cl-nsubst-if-not, cl-sublis, cl--sublis-rec, cl-nsublis)
(cl--nsublis-rec, cl-tree-equal, cl--tree-equal-rec): Clean up 'cl-'
prefixes for let-bound variables and arguments.
2025-03-05 02:42:10 +01:00
|
|
|
(if rest
|
|
|
|
(if (or (cdr rest) (nlistp x) (nlistp (car rest)))
|
|
|
|
(cl--mapcar-many func (cons x rest) 'accumulate)
|
|
|
|
(let ((res nil) (y (car rest)))
|
|
|
|
(while (and x y)
|
|
|
|
(push (funcall func (pop x) (pop y)) res))
|
|
|
|
(nreverse res)))
|
|
|
|
(mapcar func x)))
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2025-02-13 03:59:30 +01:00
|
|
|
(cl--defalias 'cl-svref #'aref)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
;;; List functions.
|
|
|
|
|
2025-02-13 03:59:30 +01:00
|
|
|
(cl--defalias 'cl-first #'car)
|
|
|
|
(cl--defalias 'cl-second #'cadr)
|
|
|
|
(cl--defalias 'cl-rest #'cdr)
|
2014-05-20 00:08:40 +08:00
|
|
|
|
2022-08-03 01:40:32 +02:00
|
|
|
(cl--defalias 'cl-third #'caddr "Return the third element of the list X.")
|
|
|
|
(cl--defalias 'cl-fourth #'cadddr "Return the fourth element of the list X.")
|
2012-06-03 21:05:17 -04:00
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defsubst cl-fifth (x)
|
|
|
|
"Return the fifth element of the list X."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t)
|
|
|
|
(gv-setter (lambda (store) `(setcar (nthcdr 4 ,x) ,store))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(nth 4 x))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defsubst cl-sixth (x)
|
|
|
|
"Return the sixth element of the list X."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t)
|
|
|
|
(gv-setter (lambda (store) `(setcar (nthcdr 5 ,x) ,store))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(nth 5 x))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defsubst cl-seventh (x)
|
|
|
|
"Return the seventh element of the list X."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t)
|
|
|
|
(gv-setter (lambda (store) `(setcar (nthcdr 6 ,x) ,store))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(nth 6 x))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defsubst cl-eighth (x)
|
|
|
|
"Return the eighth element of the list X."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t)
|
|
|
|
(gv-setter (lambda (store) `(setcar (nthcdr 7 ,x) ,store))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(nth 7 x))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defsubst cl-ninth (x)
|
|
|
|
"Return the ninth element of the list X."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t)
|
|
|
|
(gv-setter (lambda (store) `(setcar (nthcdr 8 ,x) ,store))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(nth 8 x))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
(defsubst cl-tenth (x)
|
|
|
|
"Return the tenth element of the list X."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t)
|
|
|
|
(gv-setter (lambda (store) `(setcar (nthcdr 9 ,x) ,store))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(nth 9 x))
|
|
|
|
|
2025-02-13 03:59:30 +01:00
|
|
|
(defalias 'cl-caaar #'caaar)
|
|
|
|
(defalias 'cl-caadr #'caadr)
|
|
|
|
(defalias 'cl-cadar #'cadar)
|
|
|
|
(defalias 'cl-caddr #'caddr)
|
|
|
|
(defalias 'cl-cdaar #'cdaar)
|
|
|
|
(defalias 'cl-cdadr #'cdadr)
|
|
|
|
(defalias 'cl-cddar #'cddar)
|
|
|
|
(defalias 'cl-cdddr #'cdddr)
|
|
|
|
(defalias 'cl-caaaar #'caaaar)
|
|
|
|
(defalias 'cl-caaadr #'caaadr)
|
|
|
|
(defalias 'cl-caadar #'caadar)
|
|
|
|
(defalias 'cl-caaddr #'caaddr)
|
|
|
|
(defalias 'cl-cadaar #'cadaar)
|
|
|
|
(defalias 'cl-cadadr #'cadadr)
|
|
|
|
(defalias 'cl-caddar #'caddar)
|
|
|
|
(defalias 'cl-cadddr #'cadddr)
|
|
|
|
(defalias 'cl-cdaaar #'cdaaar)
|
|
|
|
(defalias 'cl-cdaadr #'cdaadr)
|
|
|
|
(defalias 'cl-cdadar #'cdadar)
|
|
|
|
(defalias 'cl-cdaddr #'cdaddr)
|
|
|
|
(defalias 'cl-cddaar #'cddaar)
|
|
|
|
(defalias 'cl-cddadr #'cddadr)
|
|
|
|
(defalias 'cl-cdddar #'cdddar)
|
|
|
|
(defalias 'cl-cddddr #'cddddr)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
|
|
|
;;(defun last* (x &optional n)
|
|
|
|
;; "Returns the last link in the list LIST.
|
|
|
|
;;With optional argument N, returns Nth-to-last link (default 1)."
|
|
|
|
;; (if n
|
|
|
|
;; (let ((m 0) (p x))
|
Prefer incf to cl-incf in emacs-lisp/*.el
* lisp/emacs-lisp/backtrace.el (backtrace--print-func-and-args):
* lisp/emacs-lisp/bindat.el (bindat--type):
* lisp/emacs-lisp/bytecomp.el (byte-recompile-directory):
* lisp/emacs-lisp/chart.el (chart-file-count):
* lisp/emacs-lisp/cl-extra.el (cl-parse-integer, cl--print-table):
* lisp/emacs-lisp/cl-generic.el (cl--defmethod-doc-pos):
* lisp/emacs-lisp/cl-indent.el (common-lisp-loop-part-indentation)
(common-lisp-indent-function-1, lisp-indent-defmethod):
* lisp/emacs-lisp/cl-lib.el (cl--set-substring):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-preloaded.el (cl-struct-define):
* lisp/emacs-lisp/cl-print.el (cl-print--cons-tail)
(cl-print--vector-contents, cl-print--struct-contents)
(cl-print--string-props):
* lisp/emacs-lisp/cl-seq.el (cl-substitute):
* lisp/emacs-lisp/comp-cstr.el (comp--range-union)
(comp--range-intersection):
* lisp/emacs-lisp/comp.el (comp-vec-append, comp--gen-counter)
(comp--op-case, comp--limplify-lap-inst, comp--limplify-block)
(comp--limplify-function, comp--maybe-add-vmvar, comp--fwprop*):
* lisp/emacs-lisp/edebug.el (edebug--called-interactively-skip):
* lisp/emacs-lisp/eldoc.el (eldoc--invoke-strategy):
* lisp/emacs-lisp/elp.el (elp--make-wrapper):
* lisp/emacs-lisp/ert-x.el (ert-kill-all-test-buffers):
* lisp/emacs-lisp/ert.el (ert--stats-set-test-and-result)
(ert-write-junit-test-summary-report):
* lisp/emacs-lisp/memory-report.el (memory-report--symbol-plist)
(memory-report--object-size-1):
* lisp/emacs-lisp/oclosure.el (oclosure--index-table)
(oclosure--define-functions):
* lisp/emacs-lisp/package.el (package-menu--perform-transaction):
* lisp/emacs-lisp/smie.el (smie-set-prec2tab, smie-prec2->grammar)
(smie-config--guess, smie-config--guess-1):
* lisp/emacs-lisp/syntax.el (syntax-propertize-rules)
(syntax-ppss--update-stats):
* lisp/emacs-lisp/track-changes.el (track-changes--after): Prefer incf
to cl-incf.
2025-02-23 00:13:21 +01:00
|
|
|
;; (while (consp p) (incf m) (pop p))
|
2012-06-03 21:05:17 -04:00
|
|
|
;; (if (<= n 0) p
|
|
|
|
;; (if (< n m) (nthcdr (- m n) x) x)))
|
|
|
|
;; (while (consp (cdr x)) (pop x))
|
|
|
|
;; x))
|
|
|
|
|
2012-06-08 22:26:47 -04:00
|
|
|
(defun cl-list* (arg &rest rest)
|
2012-06-03 21:05:17 -04:00
|
|
|
"Return a new list with specified ARGs as elements, consed to last ARG.
|
|
|
|
Thus, `(cl-list* A B C D)' is equivalent to `(nconc (list A B C) D)', or to
|
|
|
|
`(cons A (cons B (cons C D)))'.
|
|
|
|
\n(fn ARG...)"
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free error-free)
|
|
|
|
(compiler-macro cl--compiler-macro-list*))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cond ((not rest) arg)
|
|
|
|
((not (cdr rest)) (cons arg (car rest)))
|
|
|
|
(t (let* ((n (length rest))
|
|
|
|
(copy (copy-sequence rest))
|
|
|
|
(last (nthcdr (- n 2) copy)))
|
|
|
|
(setcdr last (car (cdr last)))
|
|
|
|
(cons arg copy)))))
|
|
|
|
|
|
|
|
(defun cl-ldiff (list sublist)
|
|
|
|
"Return a copy of LIST with the tail SUBLIST removed."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t))
|
2012-06-03 21:05:17 -04:00
|
|
|
(let ((res nil))
|
|
|
|
(while (and (consp list) (not (eq list sublist)))
|
|
|
|
(push (pop list) res))
|
|
|
|
(nreverse res)))
|
|
|
|
|
|
|
|
(defun cl-copy-list (list)
|
|
|
|
"Return a copy of LIST, which may be a dotted list.
|
|
|
|
The elements of LIST are not copied, just the list structure itself."
|
2023-04-09 13:54:17 +02:00
|
|
|
(declare (side-effect-free error-free))
|
2012-06-03 21:05:17 -04:00
|
|
|
(if (consp list)
|
|
|
|
(let ((res nil))
|
|
|
|
(while (consp list) (push (pop list) res))
|
|
|
|
(prog1 (nreverse res) (setcdr res list)))
|
|
|
|
(car list)))
|
|
|
|
|
|
|
|
;; Autoloaded, but we have not loaded cl-loaddefs yet.
|
|
|
|
(declare-function cl-floor "cl-extra" (x &optional y))
|
|
|
|
(declare-function cl-ceiling "cl-extra" (x &optional y))
|
|
|
|
(declare-function cl-truncate "cl-extra" (x &optional y))
|
|
|
|
(declare-function cl-round "cl-extra" (x &optional y))
|
|
|
|
(declare-function cl-mod "cl-extra" (x y))
|
|
|
|
|
Clean up 'cl-' prefixes for local variables
The 'cl-' prefixes used for let-bound variables and argument names is a
holdover from the dynbind days. They are no longer necessary, and make
the code hard to read. This was partially cleaned up in the past; let's
finish the job now.
* lisp/emacs-lisp/cl-extra.el (cl--mapcar-many, cl-map, cl-maplist)
(cl-mapc, cl-mapl, cl-mapcan, cl-mapcon, cl-some, cl-every, cl-notany)
(cl-notevery, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst)
(cl--do-subst):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-fill, cl-replace, cl-remove)
(cl-remove-if, cl-remove-if-not, cl-delete, cl-delete-if)
(cl-delete-if-not, cl-remove-duplicates, cl-delete-duplicates)
(cl--delete-duplicates, cl-substitute, cl-substitute-if)
(cl-substitute-if-not, cl-nsubstitute, cl-nsubstitute-if)
(cl-nsubstitute-if-not, cl-find, cl-find-if, cl-find-if-not)
(cl-position, cl--position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl--adjoin, cl-assoc, cl-assoc-if, cl-assoc-if-not)
(cl-rassoc, cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion)
(cl-intersection, cl-nintersection, cl-set-difference)
(cl-nset-difference, cl-set-exclusive-or, cl-nset-exclusive-or)
(cl-subsetp, cl-subst-if, cl-subst-if-not, cl-nsubst, cl-nsubst-if)
(cl-nsubst-if-not, cl-sublis, cl--sublis-rec, cl-nsublis)
(cl--nsublis-rec, cl-tree-equal, cl--tree-equal-rec): Clean up 'cl-'
prefixes for let-bound variables and arguments.
2025-03-05 02:42:10 +01:00
|
|
|
(defun cl-adjoin (item list &rest keys)
|
2012-06-03 21:05:17 -04:00
|
|
|
"Return ITEM consed onto the front of LIST only if it's not already there.
|
|
|
|
Otherwise, return LIST unmodified.
|
|
|
|
\nKeywords supported: :test :test-not :key
|
|
|
|
\n(fn ITEM LIST [KEYWORD VALUE]...)"
|
Inline important-return-value declarations in cl-lib.el
These declarations are now properly added to 'cl-lib.el' itself, or to
'cl-loaddefs.el'. This means that they will now correctly show up
immediately when loading 'cl-lib.el', instead of only after 'cl-macs.el'
is pulled in by an autoload. C.f. Bug#76247.
I did not considered worth reproducing everywhere the list saying which
functions among the below belong to these two categories:
1. Functions that are side-effect-free except for the behavior of
functions passed as argument.
2. Functions that mutate and return a list.
AFAIU, this is not actionable with our current byte-compiler, i.e. we
can't add any extra declarations based on it. However, if the list
should be needed at some point, for example due to improvements in the
compiler, this commit will be where to find it. In the worst case, and
with more work, it's also deducible from the source code itself.
* lisp/emacs-lisp/cl-macs.el: Move important-return-value declarations
from here...
* lisp/emacs-lisp/cl-extra.el (cl-map, cl-maplist, cl-mapcan)
(cl-mapcon, cl-some, cl-every, cl-notany, cl-notevery, cl-nreconc):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-remove, cl-remove-if)
(cl-remove-if-not, cl-delete, cl-delete-if, cl-delete-if-not)
(cl-remove-duplicates, cl-delete-duplicates, cl-substitute)
(cl-substitute-if, cl-substitute-if-not, cl-nsubstitute)
(cl-nsubstitute-if, cl-nsubstitute-if-not, cl-find, cl-find-if)
(cl-find-if-not, cl-position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl-assoc, cl-assoc-if, cl-assoc-if-not, cl-rassoc)
(cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion, cl-intersection)
(cl-nintersection, cl-set-difference, cl-nset-difference)
(cl-set-exclusive-or, cl-nset-exclusive-or, cl-subsetp, cl-subst-if)
(cl-subst-if-not, cl-nsubst, cl-nsubst-if, cl-nsubst-if-not, cl-sublis)
(cl-nsublis, cl-tree-equal): ...to have them inline here.
2025-02-14 22:46:07 +01:00
|
|
|
(declare (important-return-value t)
|
|
|
|
(compiler-macro cl--compiler-macro-adjoin))
|
Clean up 'cl-' prefixes for local variables
The 'cl-' prefixes used for let-bound variables and argument names is a
holdover from the dynbind days. They are no longer necessary, and make
the code hard to read. This was partially cleaned up in the past; let's
finish the job now.
* lisp/emacs-lisp/cl-extra.el (cl--mapcar-many, cl-map, cl-maplist)
(cl-mapc, cl-mapl, cl-mapcan, cl-mapcon, cl-some, cl-every, cl-notany)
(cl-notevery, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst)
(cl--do-subst):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-fill, cl-replace, cl-remove)
(cl-remove-if, cl-remove-if-not, cl-delete, cl-delete-if)
(cl-delete-if-not, cl-remove-duplicates, cl-delete-duplicates)
(cl--delete-duplicates, cl-substitute, cl-substitute-if)
(cl-substitute-if-not, cl-nsubstitute, cl-nsubstitute-if)
(cl-nsubstitute-if-not, cl-find, cl-find-if, cl-find-if-not)
(cl-position, cl--position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl--adjoin, cl-assoc, cl-assoc-if, cl-assoc-if-not)
(cl-rassoc, cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion)
(cl-intersection, cl-nintersection, cl-set-difference)
(cl-nset-difference, cl-set-exclusive-or, cl-nset-exclusive-or)
(cl-subsetp, cl-subst-if, cl-subst-if-not, cl-nsubst, cl-nsubst-if)
(cl-nsubst-if-not, cl-sublis, cl--sublis-rec, cl-nsublis)
(cl--nsublis-rec, cl-tree-equal, cl--tree-equal-rec): Clean up 'cl-'
prefixes for let-bound variables and arguments.
2025-03-05 02:42:10 +01:00
|
|
|
(cond ((or (equal keys '(:test eq))
|
|
|
|
(and (null keys) (not (numberp item))))
|
|
|
|
(if (memq item list) list (cons item list)))
|
|
|
|
((or (equal keys '(:test equal)) (null keys))
|
|
|
|
(if (member item list) list (cons item list)))
|
|
|
|
(t (apply 'cl--adjoin item list keys))))
|
|
|
|
|
|
|
|
(defun cl-subst (new old tree &rest keys)
|
2012-06-03 21:05:17 -04:00
|
|
|
"Substitute NEW for OLD everywhere in TREE (non-destructively).
|
|
|
|
Return a copy of TREE with all elements `eql' to OLD replaced by NEW.
|
|
|
|
\nKeywords supported: :test :test-not :key
|
|
|
|
\n(fn NEW OLD TREE [KEYWORD VALUE]...)"
|
Inline important-return-value declarations in cl-lib.el
These declarations are now properly added to 'cl-lib.el' itself, or to
'cl-loaddefs.el'. This means that they will now correctly show up
immediately when loading 'cl-lib.el', instead of only after 'cl-macs.el'
is pulled in by an autoload. C.f. Bug#76247.
I did not considered worth reproducing everywhere the list saying which
functions among the below belong to these two categories:
1. Functions that are side-effect-free except for the behavior of
functions passed as argument.
2. Functions that mutate and return a list.
AFAIU, this is not actionable with our current byte-compiler, i.e. we
can't add any extra declarations based on it. However, if the list
should be needed at some point, for example due to improvements in the
compiler, this commit will be where to find it. In the worst case, and
with more work, it's also deducible from the source code itself.
* lisp/emacs-lisp/cl-macs.el: Move important-return-value declarations
from here...
* lisp/emacs-lisp/cl-extra.el (cl-map, cl-maplist, cl-mapcan)
(cl-mapcon, cl-some, cl-every, cl-notany, cl-notevery, cl-nreconc):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-remove, cl-remove-if)
(cl-remove-if-not, cl-delete, cl-delete-if, cl-delete-if-not)
(cl-remove-duplicates, cl-delete-duplicates, cl-substitute)
(cl-substitute-if, cl-substitute-if-not, cl-nsubstitute)
(cl-nsubstitute-if, cl-nsubstitute-if-not, cl-find, cl-find-if)
(cl-find-if-not, cl-position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl-assoc, cl-assoc-if, cl-assoc-if-not, cl-rassoc)
(cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion, cl-intersection)
(cl-nintersection, cl-set-difference, cl-nset-difference)
(cl-set-exclusive-or, cl-nset-exclusive-or, cl-subsetp, cl-subst-if)
(cl-subst-if-not, cl-nsubst, cl-nsubst-if, cl-nsubst-if-not, cl-sublis)
(cl-nsublis, cl-tree-equal): ...to have them inline here.
2025-02-14 22:46:07 +01:00
|
|
|
(declare (important-return-value t))
|
Clean up 'cl-' prefixes for local variables
The 'cl-' prefixes used for let-bound variables and argument names is a
holdover from the dynbind days. They are no longer necessary, and make
the code hard to read. This was partially cleaned up in the past; let's
finish the job now.
* lisp/emacs-lisp/cl-extra.el (cl--mapcar-many, cl-map, cl-maplist)
(cl-mapc, cl-mapl, cl-mapcan, cl-mapcon, cl-some, cl-every, cl-notany)
(cl-notevery, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays):
* lisp/emacs-lisp/cl-lib.el (cl-mapcar, cl-adjoin, cl-subst)
(cl--do-subst):
* lisp/emacs-lisp/cl-macs.el (cl--parse-loop-clause):
* lisp/emacs-lisp/cl-seq.el (cl-reduce, cl-fill, cl-replace, cl-remove)
(cl-remove-if, cl-remove-if-not, cl-delete, cl-delete-if)
(cl-delete-if-not, cl-remove-duplicates, cl-delete-duplicates)
(cl--delete-duplicates, cl-substitute, cl-substitute-if)
(cl-substitute-if-not, cl-nsubstitute, cl-nsubstitute-if)
(cl-nsubstitute-if-not, cl-find, cl-find-if, cl-find-if-not)
(cl-position, cl--position, cl-position-if, cl-position-if-not)
(cl-count, cl-count-if, cl-count-if-not, cl-mismatch, cl-search)
(cl-sort, cl-stable-sort, cl-merge, cl-member, cl-member-if)
(cl-member-if-not, cl--adjoin, cl-assoc, cl-assoc-if, cl-assoc-if-not)
(cl-rassoc, cl-rassoc-if, cl-rassoc-if-not, cl-union, cl-nunion)
(cl-intersection, cl-nintersection, cl-set-difference)
(cl-nset-difference, cl-set-exclusive-or, cl-nset-exclusive-or)
(cl-subsetp, cl-subst-if, cl-subst-if-not, cl-nsubst, cl-nsubst-if)
(cl-nsubst-if-not, cl-sublis, cl--sublis-rec, cl-nsublis)
(cl--nsublis-rec, cl-tree-equal, cl--tree-equal-rec): Clean up 'cl-'
prefixes for let-bound variables and arguments.
2025-03-05 02:42:10 +01:00
|
|
|
(if (or keys (and (numberp old) (not (integerp old))))
|
|
|
|
(apply 'cl-sublis (list (cons old new)) tree keys)
|
|
|
|
(cl--do-subst new old tree)))
|
|
|
|
|
|
|
|
(defun cl--do-subst (new old tree)
|
|
|
|
(cond ((eq tree old) new)
|
|
|
|
((consp tree)
|
|
|
|
(let ((a (cl--do-subst new old (car tree)))
|
|
|
|
(d (cl--do-subst new old (cdr tree))))
|
|
|
|
(if (and (eq a (car tree)) (eq d (cdr tree)))
|
|
|
|
tree (cons a d))))
|
|
|
|
(t tree)))
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2025-02-15 00:40:52 +01:00
|
|
|
(defsubst cl-acons (key value alist)
|
2012-06-03 21:05:17 -04:00
|
|
|
"Add KEY and VALUE to ALIST.
|
|
|
|
Return a new list with (cons KEY VALUE) as car and ALIST as cdr."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free error-free))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cons (cons key value) alist))
|
|
|
|
|
|
|
|
(defun cl-pairlis (keys values &optional alist)
|
|
|
|
"Make an alist from KEYS and VALUES.
|
|
|
|
Return a new alist composed by associating KEYS to corresponding VALUES;
|
|
|
|
the process stops as soon as KEYS or VALUES run out.
|
|
|
|
If ALIST is non-nil, the new pairs are prepended to it."
|
Inline side-effect-free declarations in cl-lib.el
* lisp/emacs-lisp/cl-macs.el: Move side-effect-free declarations from
here...
* lisp/emacs-lisp/cl-extra.el (cl-gcd, cl-lcm, cl-isqrt, cl-floor)
(cl-ceiling, cl-truncate, cl-round, cl-mod, cl-rem, cl-signum)
(cl-subseq, cl-list-length, cl-get, cl-getf):
* lisp/emacs-lisp/cl-lib.el (cl-plusp, cl-minusp, cl-oddp, cl-evenp)
(cl-fifth, cl-sixth, cl-seventh, cl-eighth, cl-ninth, cl-tenth)
(cl-ldiff, cl-pairlis):
* lisp/emacs-lisp/cl-seq.el (cl-endp): ...to have them inline here.
* lisp/emacs-lisp/cl-macs.el: Move side-effect-and-error-free
declarations from here...
* lisp/emacs-lisp/cl-extra.el (cl-equalp, cl-random-state-p):
* lisp/emacs-lisp/cl-lib.el (cl-list*, cl-acons): ...to have them inline
here. (Bug#76247)
2025-02-13 04:24:05 +01:00
|
|
|
(declare (side-effect-free t))
|
2012-06-03 21:05:17 -04:00
|
|
|
(nconc (cl-mapcar 'cons keys values) alist))
|
|
|
|
|
|
|
|
;;; Miscellaneous.
|
|
|
|
|
|
|
|
(provide 'cl-lib)
|
2015-05-13 19:02:31 -04:00
|
|
|
(unless (load "cl-loaddefs" 'noerror 'quiet)
|
|
|
|
;; When bootstrapping, cl-loaddefs hasn't been built yet!
|
|
|
|
(require 'cl-macs)
|
2023-10-31 19:20:58 -04:00
|
|
|
(require 'cl-seq)
|
|
|
|
;; FIXME: Arguably we should also load `cl-extra', except that this
|
|
|
|
;; currently causes more bootstrap troubles, and `cl-extra' is
|
|
|
|
;; rarely used, so instead we explicitly (require 'cl-extra) at
|
|
|
|
;; those rare places where we do need it.
|
|
|
|
)
|
2012-06-03 21:05:17 -04:00
|
|
|
|
2025-05-07 23:26:40 -04:00
|
|
|
(when (fboundp 'cl-generic-define-method)
|
|
|
|
;; `cl-generic' requires `cl-lib' at compile-time, so `cl-lib' can't
|
|
|
|
;; use `cl-defmethod' before `cl-generic' has been loaded.
|
|
|
|
;; Also, there is no mechanism to autoload methods, so this can't be
|
|
|
|
;; moved to `cl-extra.el'.
|
2025-05-07 13:24:07 -04:00
|
|
|
(declare-function cl--derived-type-generalizers "cl-extra" (type))
|
|
|
|
(cl-defmethod cl-generic-generalizers :extra "derived-types" (type)
|
|
|
|
"Support for dispatch on derived types, i.e. defined with `cl-deftype'."
|
2025-05-08 17:11:05 -04:00
|
|
|
(if (and (symbolp type) (cl-derived-type-class-p (cl--find-class type)))
|
2025-05-07 13:24:07 -04:00
|
|
|
(cl--derived-type-generalizers type)
|
2025-05-06 22:53:01 -04:00
|
|
|
(cl-call-next-method))))
|
2025-05-05 23:18:56 -04:00
|
|
|
|
2017-03-24 09:21:52 -04:00
|
|
|
(defun cl--old-struct-type-of (orig-fun object)
|
2017-07-18 12:01:27 -04:00
|
|
|
(or (and (vectorp object) (> (length object) 0)
|
2017-03-24 09:21:52 -04:00
|
|
|
(let ((tag (aref object 0)))
|
|
|
|
(when (and (symbolp tag)
|
|
|
|
(string-prefix-p "cl-struct-" (symbol-name tag)))
|
|
|
|
(unless (eq (symbol-function tag)
|
|
|
|
:quick-object-witness-check)
|
|
|
|
;; Old-style old-style struct:
|
|
|
|
;; Convert to new-style old-style struct!
|
|
|
|
(let* ((type (intern (substring (symbol-name tag)
|
|
|
|
(length "cl-struct-"))))
|
|
|
|
(class (cl--struct-get-class type)))
|
|
|
|
;; If the `cl-defstruct' was recompiled after the code
|
|
|
|
;; which constructed `object', `cl--struct-get-class' may
|
|
|
|
;; not have called `cl-struct-define' and setup the tag
|
|
|
|
;; symbol for us.
|
|
|
|
(unless (eq (symbol-function tag)
|
|
|
|
:quick-object-witness-check)
|
|
|
|
(set tag class)
|
|
|
|
(fset tag :quick-object-witness-check))))
|
|
|
|
(cl--class-name (symbol-value tag)))))
|
|
|
|
(funcall orig-fun object)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode cl-old-struct-compat-mode
|
|
|
|
"Enable backward compatibility with old-style structs.
|
|
|
|
This can be needed when using code byte-compiled using the old
|
|
|
|
macro-expansion of `cl-defstruct' that used vectors objects instead
|
|
|
|
of record objects."
|
|
|
|
:global t
|
2020-09-12 15:06:58 +02:00
|
|
|
:group 'tools
|
2017-03-24 09:21:52 -04:00
|
|
|
(cond
|
|
|
|
(cl-old-struct-compat-mode
|
|
|
|
(advice-add 'type-of :around #'cl--old-struct-type-of))
|
|
|
|
(t
|
|
|
|
(advice-remove 'type-of #'cl--old-struct-type-of))))
|
2023-09-05 12:56:13 -04:00
|
|
|
(make-obsolete 'cl-old-struct-compat-mode nil "30.1")
|
2017-03-24 09:21:52 -04:00
|
|
|
|
2021-12-02 10:19:10 +01:00
|
|
|
(defun cl-constantly (value)
|
|
|
|
"Return a function that takes any number of arguments, but returns VALUE."
|
|
|
|
(lambda (&rest _)
|
|
|
|
value))
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
;;; cl-lib.el ends here
|