The first is the old library, the second is the new one.
The old one defines things like defstruct, symbol-macrolet, incf, whereas the second defines instead cl-defstruct, cl-symbol-macrolet, and cl-incf.
The old one is deprecated because it does not obey the general rule that packages should use a "package prefix" for all their definitions to try and ...
To get the same behavior you're used to with flet, use cl-letf to change a symbols function value.
(cl-letf (((symbol-function 'pop-to-buffer)
(lambda (buffer &rest _) (switch-to-buffer buffer))))
(compilation-next-error-function n reset))
If you were to roll your own flet, the easy way would be macro that expands to a cl-letf form.
Artur Malabarba wrote this up recently, in Understanding letf and how it replaces flet.
letf is an alias for cl-letf, and while it's most likely what you want, there's a minor caveat which Artur points out:
Unfortunately, cl-flet is not identical to the original flet—it's lexical, not dynamic.
(Nic's noflet package provides extended functionality along ...
There is no constantly equivalent in Emacs (except ignore is like (constantly nil)), but dash provides one called -const as part of the dash-functional package.
Return a function that returns c ignoring any additional arguments.
In types: a -> b -> a
(funcall (-const 2) 1 3 "foo") ;; => 2
(-map (-const 1) '("a" "b" "c" "d")) ;; =&...
The function cl-macroexpand-all has been obsoleted in Emacs 24.3; you are now supposed to use macroexpand-all instead, which is part of core Emacs, not the CL library.
The CL library defines cl-macroexpand-all as an alias for macroexpand-all, so in principle you could do
in your init file to fix the problem. However, the cl library itself ...
Emacs lisp is a programming language designed to be used to provide Emacs extensions and to program Emacs. Common Lisp is a programming language that was designed to be practical Lisp useful as production language. Therefore, Emacs Lisp is sometimes "a bit strange"(this may be an opinion), since you have to care about environment - Emacs - while Common Lisp ...
Emacs Lisp doesn't really have "Best Practices". Judging from all the code I've read so far, people instead go for what is most convenient for them. And given that Emacs Lisp and Common Lisp are reasonably close (both are of the Lisp-2 variety), it is no wonder either the older and unprefixed cl.el or the newer and prefixed cl-lib library are used when the ...
Simply require library cl at compile time, to get the use of its macros (and not get any runtime load). That is where macro lexical-let is defined.
So all you need is this, to use lexical-let:
(eval-when-compile (require 'cl)) ;; lexical-let
(I put the stuff I use from the library in a comment like that, just to let me know what I'm using from it.)
cl and cl-lib are not "either or". The former requires the latter and defines lexical-let.
If you want lexical bindings, you can turn them on using the variable lexical-binding.
You can also set it on a per-file basis using file variables.
While waiting for a better answer, I wrote a with-slots macro that seems to work with defstruct instances:
(defmacro my-with-slots (class-name slots obj &rest body)
"Bind slot names SLOTS in an instance OBJ of class CLASS-NAME, and execute BODY."
(declare (indent 3))
,(cl-loop for slot in slots
Actually, the cl-defstruct macro does preserve enough info to make such a function possible, but I don't think anyone has written such a beast yet.
The way this info is stored has changed in Emacs-25: now the macro expands to various other things plus a call to cl-struct-define which creates a class object (itself a struct). You can inspect it with C-h o ...
;; Checking accounts can have a negative balance
;; Savings accounts can't
(cl-defstruct checking-account balance)
(cl-defstruct savings-account balance)
;; A generic `withdraw' method
(cl-defgeneric withdraw (account amount)
(:documentation "Withdraw AMOUNT from ACCOUNT balance.
Give an error for savings accounts ...
Thanks to bpalmer in #emacs for helping me solve this. The issue was with the and after for start...; instead, it needed to be another for (or as). I chose to use as instead of the other fors since it seems a bit more intuitive, but either will work.
The correct code is:
(cl-loop for ref across (cdr (assq 'refs data))
as start = (1+ (cdr (assq ...
It's not necessary to use cl-labels, but note that recursing over *hx/group-recurse imposes some overhead in that it must test (> 0 group-size) every call, when obviously that is not needed beyond the original call. Using labels keeps the recursive part simpler, which is generally desirable. For such reasons it's very common to see a pair of functions ...
This is not possible with the current codebase, there is an open bug for it. Fixing it should be a matter of copying the functionality from cl-indent.el without getting the misindenting of defcustom, define-minor-mode, etc.
Define the indentation for a given function/macro etc. by putting the indentation spec on the function etc. symbol as property common-lisp-indent-function. As one possible example:
'((&whole 4 &rest (&whole 1 &lambda &body)) &body))
As ocoh2 points out, cl-lib is not autoloaded, the only way to get it is to require it or have it indirectly autoloaded (some autoloaded package requires it).
It must be the Debugger that loads cl-lib. With emacs -Q --eval '(cl-evenp 2)', there is an error but no debugger and cl-lib is not loaded. cl-lib only gets loaded after the Debugger pops up once ...
You can usually avoid the use of constantly by writing the equivalent lambda-term inline. For example, in Common Lisp you could generate a list of 42s of the same length as a given list with
(mapcar (constantly 42) '(1 2 3))
In Emacs Lisp, you can do just the same with an explicit lambda-term:
(mapcar #'(lambda (_) 42) '(1 2 3))
Barely longer, and much ...
There is no predefined Emacs-Lisp function for this, as far as I know.
Here is a definition - the same as is shown in the Common Lisp standard:
(defun constantly (object)
(lambda (&rest arguments) object))
You need to have lexical-binding turned on (non-nil) for that definition. If you have it turned off (nil) then you can use this definition ...