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. Emacs Lisp is the scripting and programming language that the Emacs editor is built on.

Filter by
Sorted by
Tagged with
1
vote
1answer
12 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)...
1
vote
0answers
40 views

Emacs org mode WYSIWYG editing

Intro Is it possible to replicate the following rendering of org mode blocks like in LogSeq? I have done some research but failed to find any kind of solution that would achieve it and I have a ...
0
votes
1answer
22 views

How to disable evil insert key in read only mode

I want to disable evil insert key such as a, i, o in read-only mode (keep navigation key such as j and k), my idea is to disable these keys in local buffer when enabling read-only mode and enable ...
1
vote
1answer
24 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 ...
0
votes
1answer
42 views

Any Elisp equivalent of Python's inspect.cleandoc?

When working with code generation, Python's inspect.cleandoc is quite useful, as it allows to write inline code in a multi-line string and then automatically adjust the indentation. # -- Input: def ...
1
vote
1answer
30 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) ...
3
votes
1answer
82 views

How to distinguish input from the return value of body in while-no-input?

(while-no-input &rest BODY) Execute BODY only as long as there's no pending input. If input arrives, that ends the execution of BODY, and while-no-input returns t. Quitting makes it return nil. ...
0
votes
2answers
93 views

copy string at point func

I'm trying to build a simple proc that copies the text on which the point is set and returns the point to where it was, but can't make it work properly. Before you say "thing-at-point" - I ...
1
vote
4answers
150 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-...
0
votes
1answer
62 views

How to run shrink-window-horizontally multiple times, or how to repeat a function multiple times in general?

I wanted to define a function to execute a command multiple times and ended up using fset: (fset 'my-shrink (kbd "C-u 43 C-x {")) Now, I want to include this in a function, like this: (...
0
votes
0answers
33 views

How to turn the result returned by `org-sbe an-src-block` into list (of lists)?

In MWE.org, the source blocks list-files, summarize-files-1, and summarize-files-2 are defined to summarize files. The list-files source block gives the filenames. The summarize-files-1 and the ...
1
vote
1answer
145 views

Vim-like EOL behavior in Emacs

I'm trying to get Emacs to imitate Vim's EOL behavior. Namely at the end of line ("\n"), the cursor comes to a halt instead of progressing to the start of the next line. The following works ...
1
vote
1answer
58 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 ...
2
votes
1answer
209 views

How can I make `setf` work with `plist-get`?

There's no built-in setter for plist-get. Example: (let ((pl '(:what (one)))) (push 'two (plist-get pl :what)) pl) Error: let*: Symbol’s function definition is void: \(setf\ plist-get\) How can I ...
2
votes
1answer
61 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 ...
6
votes
1answer
188 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 ...
2
votes
1answer
461 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 ...
3
votes
1answer
201 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 ...
0
votes
2answers
110 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 ...
6
votes
3answers
2k 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)...
2
votes
0answers
79 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 | ...
1
vote
2answers
64 views

' versus #' what are the differences and when should I choose one over the other? [duplicate]

Both seem to work equally well when mapping a function over a list, for example. (mapcar #'1+ (list 1 2 3)) ;; => (2 3 4) (mapcar '1+ (list 1 2 3)) ;; => (2 3 4)
1
vote
1answer
172 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? ...
5
votes
1answer
279 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, ...
2
votes
2answers
217 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 (...
1
vote
1answer
131 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?
1
vote
1answer
173 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 ...
10
votes
3answers
283 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-...
1
vote
1answer
335 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. ...
3
votes
1answer
143 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?
5
votes
2answers
160 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 ...
17
votes
2answers
2k 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 ...
4
votes
0answers
252 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 ...
7
votes
3answers
855 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 ...
2
votes
1answer
488 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 ...
2
votes
1answer
123 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 ...
1
vote
1answer
128 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?
0
votes
0answers
81 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>) ...
5
votes
0answers
203 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 ...
0
votes
2answers
298 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 ...
7
votes
2answers
774 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 ...
1
vote
1answer
925 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 ...
0
votes
2answers
156 views

Warning assigning variables

I'm rebuilding my emacs configuration, and trying to compile without warnings. I'm using also cask. I have this case: (require 'magit) ;; Enable a right limit of 70 chars for git logs (add-hook '...
4
votes
3answers
400 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 ...
0
votes
1answer
101 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 ...
6
votes
2answers
576 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++?
3
votes
2answers
220 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 ...
2
votes
1answer
114 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 ...
12
votes
1answer
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 ...
2
votes
3answers
264 views

Bringing a function into a lexical environment

I'm using a closure to keep track of some stuff to do with state; I want to be able to ‘include’ a function into that closure, so it can access the state. The only way this is possible is by creating ...

1
2 3 4 5
9