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
4 votes
3 answers
2k views

Alternative to lexical-let

I'd rather not use cl-lib and cl at the same time. However, I really like using lexical-let to specify the usage of lexical binding on a more granular level. Is there any equivalent in cl-lib or ...
11 votes
4 answers
3k views

Is there a better way to handle multiline docstrings in elisp?

I hate the way that elisp (not sure if LISP in general) handles multiline docstrings. (defun foo () "This is a multi liner docstring" (do-stuff)) I sure do wish that I could do something like (...
4 votes
3 answers
408 views

How do I get the name (string) of a compiled function?

I have this advice in place that executes the called function over the whole buffer if a region is not selected. But I would also like to print a message that tells the user that the function they ...
6 votes
1 answer
2k views

How to get a list of all the buffers in elisp?

I am trying to get a list of buffers through elisp. So I created the following function: (mapcar (function buffer-name) (buffer-list)) This works when I do something like: (minibuffer-message (mapcar ...
6 votes
3 answers
2k views

Can I add highlighting in a minor mode?

I'm trying to understand minor modes with the goal of adding a minor mode for Jinja2 syntax highlighting (from jinja2-mode) to stuff like YAML. I'm running into problems though. When following a ...
10 votes
1 answer
823 views

How to toggle Org-mode source code block ":eval no" status

I often limit or unlimit the evaluation of specific code blocks in org-mode babel using :eval header argument. Here's an example: #+BEGIN_SRC emacs-lisp :results value scalar :eval no (+ 1 1) #+...
8 votes
3 answers
1k views

display in the mode-line the number of characters in the selection

I'm used to have display of the number of selected characters in the mode line when there is an active selection (in vim). Is it possible to achieve this in emacs? I managed to display the column ...
0 votes
1 answer
77 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&...
11 votes
3 answers
475 views

How to use while-no-input?

From the docstring: 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. If ...
38 votes
3 answers
13k views

How to check in elisp if a string is a substring of another string?

How to check if a string s1 is a substring of another string s2? For example (test-substring "f t" "df tj") --> t, (test-substring "ft" "df tj") --> nil.
90 votes
5 answers
21k views

Advantages of setting variables with setq instead of custom.el?

I see a lot of people (extension authors and others) give configuration examples with setq: (setq foo 'bar) These parameters are often defined with defcustom, making them available for customization ...
16 votes
4 answers
3k views

Run a Function Only Once, Though a Hook Many Times

The context I'm using the after-make-frame-functions hook to load properly the themes in an emacs client/server configuration. Specifically this is the code snippet that I use to make that (based in ...
46 votes
2 answers
5k views

Why does elisp not have namespaces?

Q: Why does elisp not have namespaces, and how could we get them? Elisp does not have namespaces other than the global one, which has led to the coding convention of prefixing all global functions, ...
40 votes
3 answers
17k views

Command that formats (prettifies) Elisp code

Let's say I have a function that looks like the following (as is often the case when printing elisp output). (defun my-example-function () (let ((a (do-something)) (b (do-something))) (setq someone ...
4 votes
3 answers
255 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 ...
9 votes
3 answers
453 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) ...
7 votes
1 answer
134 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 (...
4 votes
1 answer
608 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 ...
1 vote
2 answers
209 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 ...
20 votes
4 answers
3k views

Why does lisp-interaction-mode exist, and do we ever need it?

Q: Why does lisp-interaction-mode exist, and are there any reasons to use it instead of emacs-lisp-mode? The manual states that emacs-lisp-mode and lisp-interaction-mode are identical except that the ...
4 votes
2 answers
643 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=='...
1 vote
0 answers
36 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 ...
7 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-...
12 votes
2 answers
2k views

How can I modify Elisp's reader?

Modifying the reader would allow introducing new read-syntax (such as #(hash table) and '(quoted)). Many Lisps have this​​​​​ capability, but no such facility seems to exist for elisp.
1 vote
1 answer
115 views

Scheme-like lambda expressions?

Scheme syntax seems very lambda-expression-friendly. I can do this (define blah (lambda (n) (* n n))) But this isn't possible in elisp. I can do this (defun simple (x) ((lambda (n) (* n n)) x))...
4 votes
1 answer
189 views

Does Elisp replay on hash lookups every time code require access to symbol value?

I go across blog post: http://blog.cdleary.com/2010/09/picing-on-javascript-for-fun-and-profit/ It is about JS performance on accessing object properties and tricks that help reduce that time. Usual ...
6 votes
2 answers
1k views

How to write assertions

How does one write assertions in Emacs Lisp? I know that cl-macs.el has cl-assert and cl-check-type, but I'm wondering if there's a native Emacs way to perform something that basic.
1 vote
2 answers
1k views

Dolist not modifying the list

I'm trying to prepend each substring of split-string with numbering (1.,2.,3.,..) then return all the substrings concatenated with a newline (defun japanese-get-definition (dictentry) "Get a ...
3 votes
2 answers
293 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
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 ...
2 votes
2 answers
304 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 (...
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 ...
2 votes
4 answers
1k 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-...
1 vote
1 answer
293 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 ...
57 votes
6 answers
11k views

How to replace an element of an alist?

I have this by default in my auto-mode-alist: ("\\.js\\'" . javascript-mode) (even with emacs -Q). I'd like to substitute js2-mode for javascript-mode. Of course, I could use assq-delete-all and ...
21 votes
2 answers
9k views

How do you return from a function at an arbitrary point?

How do you return early from a function before it's ended? For example: (defun my-func () "for example." (unless something (return nil)) ; continue as usual... (+ 42 1))
7 votes
2 answers
614 views

helm - adding helm-M-x to helm sources

I am able to add few extra sources to helm like this (setq helm-mini-default-sources '(helm-source-buffers-list helm-source-recentf ...
22 votes
4 answers
9k views

How to get element number in a list?

Q: how do I get the element number in a list? nth gets element number n from a list: (nth 2 '(a b c d)) ; => c I'd like to do the reverse: get the element number given the ...
12 votes
2 answers
834 views

Elisp reimplementations

Emacs implements an interpreter for elisp in C which serves as the de facto reference implementation. Are there any other implementations of elisp in other languages (particularly Javascript)? What ...
9 votes
4 answers
2k views

How to control where the org todo keywords buffer displays?

Q: how can I control where the org todo keywords buffer appears? Entering a todo keyword with C-c C-t (org-todo) opens a new buffer with the keyword options and then closes it again after I select ...
39 votes
3 answers
21k views

What's the difference between push and add-to-list?

I've found that different packages in their installation instructions use either push or add-to-list (For example adding a directory to load-path) and I was wondering what the difference is and what ...
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 */ ...
1 vote
1 answer
243 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
1 answer
234 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 ...
6 votes
3 answers
531 views

One-time advice

I've been trying to a macro to put one-time advice on a function. What I mean by one-time advice is advice which removes itself after it is called – so that when you add the advice and run the ...
1 vote
1 answer
118 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) ...
11 votes
3 answers
2k views

hl-line-mode hide background, how to avoid this?

With: (when window-system (set-face-background 'hl-line "light yellow") (global-hl-line-mode 1)) current line highlighted by yellow background, but if text has background properties it also ...
22 votes
3 answers
4k views

A faster method to obtain `line-number-at-pos` in large buffers

The function line-number-at-pos (when repeated about 50 times) is causing a noticeable slow-down in semi-large buffers -- e.g., 50,000 lines -- when point is near the end of the buffer. By slow-down, ...
4 votes
3 answers
542 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 ...
34 votes
3 answers
7k views

When should I use autoload instead of require?

From what I understand require is used to load large chunks of code (something like modules) although it can also load individual functions. Autoload on the other side, only registers functions and ...

1
2 3 4 5
9