Questions tagged [elisp]

*ONLY* for questions about Emacs Lisp as a language, compared to other languages, in particular, compared to other Lisp dialects. That is, it is for questions *about the language* itself. *DO NOT USE IT* for questions about *using* Emacs Lisp, because most questions here are about using Elisp, and adding this tag to them is redundant. Emacs Lisp is the scripting and programming language that the Emacs editor is built on.

Filter by
Sorted by
Tagged with
0 votes
1 answer
57 views

How to print and read a list to(from) a file?

I'd like to save a (extremely minimal) database made of a lisp list and then read it back. The list will look like something as follows: (:foo "bar" :baz "foobar" :foobaz "baz&...
ygy's user avatar
  • 103
9 votes
3 answers
444 views

Lambda in `defun` Captures the Lexical Environment, But in `let` It Doesn't

My example is simplified: (defvar wtf 10) (defun f (wtf) (lambda () (cl-incf wtf))) (setq f (f 20)) (setq g (let ((wtf 30)) (lambda () (cl-incf wtf)))) (list (funcall f) ...
shynur's user avatar
  • 5,174
4 votes
1 answer
590 views

Is it faster to add an element at the beginning of a list with add-to-list than at the end?

I've noticed that some people use a t at the end of this code: (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) that t makes it append at the end of ...
Zoli's user avatar
  • 421
1 vote
2 answers
190 views

the term “constant” in Elisp

The definition of the term “constant” is clarified in the GNU Emacs Lisp Reference Manual, section 6.2: For purposes of evaluation, the array is a constant—i.e., it evaluates to itself. In the ...
shynur's user avatar
  • 5,174
7 votes
1 answer
133 views

“(equal a b)⇒t” whereas “(equal b a)⇒error”

GNU Emacs Lisp Reference Manual, 2.8 Equality Predicates: Comparing circular lists may therefore cause deep recursion that leads to an error, and this may result in counterintuitive behavior such as (...
shynur's user avatar
  • 5,174
4 votes
3 answers
236 views

the Term “Hash Notation“ in the Elisp Manual

I'm reading GNU Emacs Lisp Reference Manual, and I see the phrase "hash notation". Two places in the document seem to have different interpretations, so I have 2 questions. 2.1 Printed ...
shynur's user avatar
  • 5,174
4 votes
2 answers
640 views

Is there any function that allows me to execute code on the run?

I'm a Vim user who is trying to migrate to emacs. On Vim, I've been using the following vimscript function to execute code: function! ExecuteOnTerminal(type) range if (&ft=='bash' || &ft=='...
raylight's user avatar
  • 217
1 vote
0 answers
35 views

Insert output of slow external process in current buffer, character-by-character

Imagine in the current buffer I have the text: Hello Bye I want to call an external program and add the output of it at the end of the buffer. The tricky thing is that the external program provides ...
scaramouche's user avatar
  • 1,734
4 votes
4 answers
4k views

How can I create block (multiline) comments in Lisp code?

How can I do multiline / block comments in Lisp code - e.g. in the init.el. In Python I would do it like this """Block comment """ In C/C++ like this /* Block comment */ ...
buhtz's user avatar
  • 719
1 vote
1 answer
235 views

Validating Arguments to a Function

I would like to validate the argument to a function before its action is executed. The main concern is the passing of a void variable. How can I trap this? (defun is-it-bound(item) (if (boundp 'item)...
naugiedoggie's user avatar
1 vote
1 answer
230 views

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

Does elisp have a way to jump to (goto) labels in the code, ala common lisp's go? (tagbody (setq val 2) (go lp) (incf val 3) lp (incf val 4)) => NIL val => 6 PS: This is a ...
HappyFace's user avatar
  • 830
1 vote
1 answer
116 views

Access hash table by value, not key?

Q: how can I access a hash table by its value, not its key? Association lists can be accessed via either their key or their value: (setq alist '((a .1) (b . 2) (c . 3))) (assoc 'a alist) ...
Dan's user avatar
  • 32.9k
6 votes
2 answers
1k views

Underscore in if-let

I often find myself wanting to do something like this: (if-let* ((foo (get-foo)) (_ (conditionp foo)) (bar (get-bar-from-foo foo))) ...) As an alternative to: (let ((foo (get-...
C4ffeine Add1ct's user avatar
2 votes
4 answers
985 views

Equivalent of `continue' in `cl-loop'?

Does the cl-loop macro implement an equivalent to the continue keyword of other languages? The behavior of break can be achieved by using until or while clauses by placing them in the middle of cl-...
kdb's user avatar
  • 1,561
1 vote
1 answer
279 views

How to use face-remap-set-base to substitute a face for another?

I'd like to locally remap a face to other custom face. The docstring reads: (face-remap-set-base FACE &rest SPECS) Set the base remapping of FACE in the current buffer to SPECS. This causes the ...
Michaël's user avatar
  • 314
2 votes
1 answer
104 views

Why can't I directly invoke the result of apply-partially?

I'm confused about return value of apply-partially. Documentation states that it returns a function, and source of the function shows that it actually retruns a lambda. But I can't invoke the return ...
Rogach's user avatar
  • 267
6 votes
1 answer
308 views

What's really behind an assignment in Emacs lisp?

[Warning : these are noob questions.] I'm a beginner in Emacs Lisp and I would like to be sure that I understand well what I'm really doing when I set a value to a variable with setq or let. Here is ...
Philopolis's user avatar
  • 1,134
4 votes
1 answer
1k views

Difference between pcase-let & cl-destructuring-bind?

I noticed both pcase-let and cl-destructuring-bind seem to perform the same operation. Is there any difference or reason to use one instead of the other? eg: (pcase-let ((`(,filename ,buf) (pop ...
ideasman42's user avatar
  • 8,736
4 votes
1 answer
525 views

Why does `make-symbol` work in macro expansion, just as `gensym` works?

In the dash library I noticed the use of make-symbol to avoid symbol conflicts during macro expansion. (defmacro --filter (form list) "Anaphoric form of `-filter'. See also: `--remove'." (declare ...
Aquaactress's user avatar
  • 1,443
0 votes
2 answers
215 views

What is #'eq and how does it differ from 'eq [duplicate]

I've seen a few snippets of code where symbols were prepended by #' instead '. like the following snippet (seq-count #'not (seq-mapn #'eq seq1 seq2)) What is the difference and why couldn't I just ...
GreenLlama's user avatar
8 votes
3 answers
3k views

Are local nested functions possible in elisp?

It it possible to declare functions whose names are only available in the scope of another function, similar to let? e.g.: (defun my-fn (x y) (let ((my-local-fn (lambda (a b) (message "%S" (- a b)...
ideasman42's user avatar
  • 8,736
2 votes
0 answers
125 views

Has elisp some object inspector? [closed]

Do you know about some elisp object inspector? I want object tree view similar to ones in javascript consoles in browsers. Object: (list (list "foo" "bar" "baz") "some" "thing") Inspector: list | ...
dev1223's user avatar
  • 241
1 vote
1 answer
235 views

Updating code from lexical-let to lexical-binding: t

This code shows an elisp function (third example) using lexical-let, which is now passe as I understand. How would it be written today with lexical scope now being a quasi-built-in feature of elisp? ...
147pm's user avatar
  • 2,957
5 votes
1 answer
492 views

About closure creation

After reading this article about readable closures, I check that: Since closures are byte-code function objects, they print readably. You can capture an environment in a closure, serialize it, ...
anquegi's user avatar
  • 749
2 votes
2 answers
299 views

Evaluating symbol in function arguments affected by destructive operations?

While evaluating a function call, the arguments is from left to right. For example, (let ((x '(1 2 3))) (list (nreverse x) x)) ;; => ((3 2 1) (1)) The first argument (nreverse x) evaluates to (...
xuchunyang's user avatar
  • 14.5k
1 vote
1 answer
166 views

are braces `{` and `}` used at all in elisp?

What is the convention for using { and } characters in Emacs Lisp if they are used at all? Do macros make use of them?
zcaudate's user avatar
  • 637
1 vote
1 answer
247 views

Return Value of apply-partially

I'm playing around with apply-partially and I'm confused about what gets returned when calling this function. The documentation states that apply-partially returns a function, but then I'd expect to ...
flooose's user avatar
  • 521
10 votes
3 answers
377 views

Why does defvar scoping work differently without an initvalue?

Suppose I have a file named elisp-defvar-test.el containing: ;;; elisp-defvar-test.el --- -*- lexical-binding: t -*- (defvar my-dynamic-var) (defun f1 (x) "Should return X." (let ((my-dynamic-...
Ryan C. Thompson's user avatar
1 vote
1 answer
365 views

What paradigm shift of my thinking must happen to understand the essence of Emacs/Emacs Lisp? [closed]

I've always had "AHA!"-moments when encountering new concepts or ideas in programming. That's when things start clicking for me. And I think I haven't yet had that moment with Emacs/Emacs Lisp yet. ...
John DeBord's user avatar
4 votes
1 answer
203 views

is there a function that can partially apply arguments on a function with order?

apply-partially cannot specify the order. Is there one from the default Emacs installation that can specify order?
FunkyBaby's user avatar
  • 797
5 votes
2 answers
241 views

How can I define new places for setf?

Q: how do I teach setf about new places it can set? In common lisp, one uses the macro defsetf to tell setf about new places it can set. In elisp, that macro exists in in the cl library, but, as far ...
Dan's user avatar
  • 32.9k
21 votes
2 answers
3k views

When should sharp quotes be used?

I see sharp quotes being used in other people's eLisp code, and I use them myself, but I'm not completely clear on when they are appropriate and when not. Could anyone clarify on exactly when it's ...
izkon's user avatar
  • 1,858
4 votes
0 answers
319 views

Is there an ELISP decompiler?

I'm thinking of writing one so that when I get those horrible tracebacks from bytecode files, I can better see where I was at. Is there one already? Are there any other tools for showing an error ...
rocky's user avatar
  • 898
7 votes
3 answers
1k views

Is there an equivalent for defparameter on emacs-lisp?

I know we have defvar and setq. defvar has a special meaning on defining global variables because the assignment only happens once. So I was thinking about use setq to get the desired behavior of ...
Manoel Vilela's user avatar
2 votes
1 answer
704 views

How to use custom macro indentation in elisp?

This blog post shows that its possible to indent like this: (lispy-dotimes arg (when (= (point) (point-max)) (error "Reached end of buffer")) (forward-list)) Instead of this: (lispy-dotimes ...
ideasman42's user avatar
  • 8,736
3 votes
1 answer
231 views

practical relevance of storing value and function into one symbol

With Emacs Lisp it is possible to store a value and a function within the same symbol. (setq foo 6) (defun foo () (message "blah %d" foo))) Then you can do: (symbol-function 'foo) which returns the ...
jue's user avatar
  • 4,556
1 vote
1 answer
190 views

How to print a quoted sexp using '... (reader syntax) instead of using (quote ...)?

The result of (print 'foo) is (quote foo). Is there a similar function whose result is 'foo, which is what people generally write?
Nova's user avatar
  • 1,109
0 votes
0 answers
102 views

Byte Compiling Functions Using `defalias` for `progn`

The following code: (defalias 'new-progn 'progn) (defun foo () (new-progn "foo")) (byte-compile 'foo) (foo) gives this error: Debugger entered--Lisp error: (invalid-function #<subr progn>) ...
cutejumper's user avatar
5 votes
0 answers
276 views

Structure-preserving copying of sequences

The form (cl-copy-tree TREE t) returns a deep-copy of a sequence TREE. The the Common Lisp Hyper Spec explains that copy-tree does not preserve circularities and sharing of substructures. I.e., even ...
Tobias's user avatar
  • 33.1k
0 votes
2 answers
386 views

Wrapper objects / types for Emacs Lisp primitives?

I'm curious if there's any precedent for wrapper objects or types in Emacs Lisp. Javascript notably has built-in types that wrap built-in literal types and those objects can largely be used in the ...
ebpa's user avatar
  • 7,439
7 votes
2 answers
996 views

The default value of buffer-local variable not set until first `setq`

Say I define a buffer-local variable foo, and its default value is "a": (defvar foo "a") (make-variable-buffer-local 'foo) (default-value 'foo) ;; => "a" Immediately after this I run the ...
cutejumper's user avatar
2 votes
1 answer
1k views

Passing a symbol as an argument to a function

I'm trying to understand why this doesn't work, and how to make it work: (defvar test/var-1 nil) (defvar test/var-2 nil) (defun make-setter (var-to-set) (lambda (val-to-set) (setq var-to-set ...
Gastove's user avatar
  • 1,551
4 votes
3 answers
533 views

Reflection on function argument signatures

Is there anything built into elisp for reflection on function argument signatures? I have used (length (cadr (symbol-function #'my/function))), but this notably fails on built-in C functions. I'm ...
ebpa's user avatar
  • 7,439
0 votes
1 answer
110 views

converting xemacs lisp to run in emacs [closed]

I have used xemacs for years and have a lot of lisp code I have written. Now I want to switch to emacs and convert all the lisp code over to work in emacs. This is on an winXP machine. I'm sure I am ...
skm's user avatar
  • 3
11 votes
2 answers
1k views

An efficient set data structure in elisp

Does elisp provide a builtin efficient set data structure, similar to set in Python and std::set in C++?
xuhdev's user avatar
  • 1,899
3 votes
2 answers
292 views

How to evaluate a symbol in a lambda function when defining it?

For example, (lambda () (message "%s" x))) But I would like x to be evaluated -- the lambda function should always use that value, instead of the current value of x. How should I do it? Preferably ...
xuhdev's user avatar
  • 1,899
2 votes
1 answer
176 views

When is it not possible to quote nil? [duplicate]

I've never quoted nil before, as I can't see any sense in doing that, but I just played around with some code and it seems that in most cases it is possible to quote nil without any effect. However ...
bertfred's user avatar
  • 1,729
12 votes
1 answer
1k views

Meaning of period in (. 123)

I learnt . /path/to/file in bash is used to execute a file. Just out of curiosity, I eval something like the following in Emacs (. 123) ⇒ 123 (read "(. 123)") ⇒ 123 It looks like Emacs ...
xuchunyang's user avatar
  • 14.5k
5 votes
2 answers
422 views

apply partially last arg

Is there something like apply-partially (apply-partially FUN &rest ARGS) Return a function that is a partial application of FUN to ARGS. ARGS is a list of the first N arguments to pass to FUN. ...
JAre's user avatar
  • 185
4 votes
2 answers
572 views

Elisp backquote comma eval puts a space in between

Here's an example: (defmacro test (arg) `(message foo-,arg)) (defmacro test-with-space (arg) `(message foo- ,arg)) (macroexpand-1 '(test-with-space bar)) (macroexpand-1 '(test bar)) Both eval ...
Russ Kiselev's user avatar

1
2 3 4 5
9