Skip to main content
24 votes
Accepted

require 'cl or require 'cl-lib

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-...
Stefan's user avatar
  • 26.4k
12 votes
Accepted

`case` doesn't switch correctly with strings

cl-case uses eql for comparisons, so string get tested for identity not for equality in the sense of string=. You can fix this by just switching to pcase (or, if you really want to use case, convert ...
Omar's user avatar
  • 4,812
11 votes
Accepted

cl-destructuring-bind on partial plist?

Since cl-destructuring-bind uses CommonLisp's arglist convention, you should be able to do: (cl-destructuring-bind (&key a b &allow-other-keys) '(:a "foo" :b 13 :c "bar") (list a ...
Stefan's user avatar
  • 26.4k
7 votes

Is there an equivalent for defparameter on emacs-lisp?

Not as far as I can tell, no. I've always questioned the usefulness of having both defvar and defparameter in Common Lisp. If you don't mind, leave a comment explaining why having both forms is ...
Jeff Spaulding's user avatar
7 votes
Accepted

Why does Emacs indent my Lisp LOOP construct weirdly?

You can use indentation provided by a SLIME contribution: (require 'slime-cl-indent) You may want to add that to the list slime-contribs- see Loading Contribs in the SLIME manual. One can add it to ...
Rainer Joswig's user avatar
6 votes

Is using cl-lib crucial for writing good Emacs Lisp code?

No, it's definitely not crucial: A quick sed | sort | uniq -c says that within Emacs's own code we have: [...] 20 (cl-ecase 24 (cl-labels 26 (cl-callf 26 (cl-defmacro 26 (cl-dolist 26 (cl-...
Stefan's user avatar
  • 26.4k
6 votes
Accepted

Is there an equivalent for defparameter on emacs-lisp?

In Emacs Lisp, defconst doesn't actually enforce constness, and therefore works pretty much like Common Lisp's defparameter: it unconditionally sets the variable; it marks it as special; it avoids ...
jch's user avatar
  • 5,740
5 votes

`case` doesn't switch correctly with strings

Your second version would more typically be written as a cond form: (cond ((string= system-name "HP") (setq package-user-dir (concat user-emacs-directory "packages/hp"))) ((string= ...
phils's user avatar
  • 51.3k
5 votes

How can I define new places for setf?

Drew's answer is correct, but it should also be mentioned that the reason cl-lib doesn't include a cl-defsetf (or cl-setf) is because the setf machinery has been moved to gv.el. The docstring of ...
npostavs's user avatar
  • 9,203
4 votes
Accepted

How to use cl-labels?

Use #' for quoting: (defun test () (cl-labels ((square (x) (* x x))) (mapcar #'square '(1 2 3)))) (test) ;; => ;; (1 4 9)
abo-abo's user avatar
  • 14.1k
4 votes
Accepted

How can I define new places for setf?

Where does it say that you're not supposed to use library cl.el? That would be silly (IMHO). The text you quote says that code distributed with GNU Emacs must not load cl at runtime. That does not say ...
Drew's user avatar
  • 77.7k
3 votes

Does elisp have a way to jump to (goto) labels in the code, ala common lisp's go?

It works exactly the same, we just need to use cl-tagbody instead. (cl-tagbody (setq val 2) (go lp) (incf val 3) lp (incf val 4)) val 6
HappyFace's user avatar
  • 830
3 votes
Accepted

Adjusting indenting for lisp if statements

Why is Emacs so weird? Emacs indents lisp code as if it were Emacs Lisp, where if accepts unlimited else forms; unlike in Common Lisp, where if accepts at most 3 arguments. What to do? Tell Emacs ...
sds's user avatar
  • 6,124
3 votes

idiomatic way to lexically scope variables in a cl-loop body

Your problem is that the timer runs the function when the loop has finished. The lexically bound variables index and value have for all calls the values after the last iteration. One solution is to ...
Tobias's user avatar
  • 33.2k
3 votes

Why does Emacs indent my Lisp LOOP construct weirdly?

I found, it is more appropriate to add into contribs 'slime-indentation. it will load slime-cl-indent. And after that, you can use this code to choose required indentation style: (setq lisp-indent-...
Alexander Artemenko's user avatar
3 votes
Accepted

Error while trying to set a slot of a cl-struct

Use setf instead of setq. (setf (foo-name bar) 'jim)
syohex's user avatar
  • 456
2 votes
Accepted

How to change Org-mode Babel lisp source code block from SLIME to SLY?

The easiest way is to parametrize the call slime-eval, using funcall and a defvar/defcustom and take advantage use of sly's retro contrib, which allows the user to refer to the slynk pacage by the ...
PuercoPop's user avatar
  • 396
2 votes

cl-destructuring-bind on partial plist?

see definition of cl-defmacro: (VAR... ...
Kevin Krausse's user avatar
2 votes
Accepted

Why does this function stub not work using cl-letf?

If you indent your code, you should end up with the following: (ert-deftest pp-test-process-function () (setq dc-current-buffer "/") (cl-letf (((symbol-function 'dc-process) (lambda ...
npostavs's user avatar
  • 9,203
2 votes

idiomatic way to lexically scope variables in a cl-loop body

Another option is to use backquoting to substitute the values for each loop iteration directly into the lambda form: ;;; foo.el --- -*- lexical-binding: t; -*- (let ((my-...
phils's user avatar
  • 51.3k
2 votes

What's the purpose of `cl-lib` in emacs?

Emacs doesn't (or didn't1) need it, in the sense that everything in cl-lib.el is ultimately implemented in terms of standard Emacs Lisp, and therefore things using cl-lib could do the same. That doesn'...
phils's user avatar
  • 51.3k
2 votes
Accepted

How can I configure Slime to use case sensitive symbols?

Common Lisps Reader converts all symbols to uppercase, when reading them. To use lowercase symbols in Common Lisp you have to escape them with | | or \. So this is not an SLIME/SLY issue at all. CL-...
jue's user avatar
  • 4,576
2 votes
Accepted

Reading Common Lisp Source Code Inside Emacs?

One part of this puzzle to to get comfortable access to the Common Lisp HyperSpec. This snippet from my init explains how to get an info version with index: ;; Set up hyperspec lookup. This is ...
Fran Burstall's user avatar
2 votes

getting macro calls to indent correctly (like defun instead of functions) in common lisp code?

It's because I used &rest body instead of &body body. Once I used the latter, the indentation automatically worked fine in both places, no declare needed. Probably &body was not a thing ...
xdavidliu's user avatar
  • 213
1 vote

Reading Common Lisp Source Code Inside Emacs?

Perhaps someone will answer that there's a 3rd-party package that helps with what you ask: interact with the Common Lisp doc using some C-h key(s). I'm not aware of any (but you can use eww to browse ...
Drew's user avatar
  • 77.7k
1 vote
Accepted

Highlight labels/flet/macrolet definitions in lisp-mode

In the code from https://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00322.html the pushes are in wrong order. The code below with corrected order of the pushes works as it is expected to work. ...
Tobias's user avatar
  • 33.2k
1 vote

Syntax Highlighting of Common Lisp User-Defined Macros in Emacs

I have been able to solve my issue above by looking through the Emacs source code, specifically font-lock.el. It is recommended that one use regex-opt to generate a suitable regular expression to be ...
Rama Lakshmanan's user avatar
1 vote
Accepted

How do I change the default indentation of 'if' for Common Lisp and Scheme?

Yes, there is. There are a few customization suggestions for common-lisp-indent-function inside cl-indent.el. The same mechanism is used for scheme-indent-function. Place the following in your init ...
wasamasa's user avatar
  • 22.2k
1 vote
Accepted

Company-yasnippet doesn't see yasnippet template in lisp

Firstly, (make-local-variable 'company-backends) is outdated, with newest company and other packages, we only need to set one global company-backends. That's because all backends do check whether it's ...
JJPandari's user avatar
  • 261
1 vote

idiomatic way to lexically scope variables in a cl-loop body

One way is to create a macro: (defmacro lexical-save (vars &rest body) `(lexical-let ,(mapcar (lambda (var) (list var var)) vars) ,@body)) You can use it is follows: (let ((my-list '(a b ...
Harald Hanche-Olsen's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible