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
0
votes
1answer
25 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
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
14 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
48 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 ...
1
vote
1answer
25 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 ...
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 ...
5
votes
3answers
331 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 ...
21
votes
3answers
4k views

How to choose between nil and 0, or t and 1 when setting variables or enabling modes

I understand that nil, 0 and/or -1 are used for disabling some features and t, 1 and/or +1 are used for enabling some features. When assigning variables or enabling/disabling minor modes, which ...
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) ...
1
vote
4answers
152 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-...
5
votes
3answers
585 views

How to implement remove-key to completely undo the effect of define-key

A long time ago I implemented remove-key to completely undo the effect of define-key, but when I just tried that implementation, it did not work reliably. How would you implement remove-key so that ...
11
votes
3answers
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
3answers
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
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 ...
33
votes
3answers
5k 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 ...
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. ...
11
votes
3answers
2k views

String equality, ignore case?

Q: how does one test string equality but ignore case? I've got a situation in which I'd like to compare strings but ignore case. Case is significant for string-equal, and apparently is insensitive ...
29
votes
3answers
9k 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 ...
7
votes
4answers
237 views

Tracking when variables get updated

I have a problem with org-mode's agenda view. While I've set org-agenda-files to '("~/org/") invariably when I finally spin up M-x org-agenda I find that org-agenda-files just points to one org-file. ...
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 ...
41
votes
3answers
8k views

How to know when or when not to use the single quote before variable names?

I have the below: (setq some-variable "less") I am confused why I have to use the single quote with boundp but not with bound-and-true-p. Example 1: (when (boundp 'some-variable) (message "...
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 ...
6
votes
2answers
605 views

Discard stderr in start-process

I'm using start-process to run mplayer and when playing videos I get a ton of output to stderr from "vdp_...". On the command line I usually just 2>/dev/null but start-process runs it directly without ...
8
votes
4answers
4k views

How to programmatically execute a command in eshell?

I want to execute simple commands in eshell without explicitly typing them into the prompt, using something like with-current-buffer How can I do this?
18
votes
4answers
7k 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 ...
8
votes
2answers
2k views

Passing a variable to template function in org-capture-templates

I'm using org-capture to insert expenses into a Ledger file with this template, along with auto-completion for the various expense categories: (setq ledger-expense-completions (list "" ;; ...
15
votes
2answers
3k views

"and" vs "when" for conditionals

This is a follow-up on the comments on this answer. The following bits of code seem to be equivalent: (and a b) (when a b) Of course and lets you put more conditions: (and a b c d) means (when (and ...
30
votes
3answers
3k views

Reset custom variable to default value programmatically

Q: Using Elisp, how can I reset a variable to its default value without knowing what that value is? I tried to figure out how to do this by bringing up the Customize interface for a variable I set to ...
18
votes
2answers
702 views

Why do setq and set quote act differently on let-bound variables with lexical scope?

I had a bug in one of my extensions that eventually turned out to be caused by set not working as I expected: ;; -*- lexical-binding: t -*- (let ((a nil)) (setq a t) (print a)) (let ((a nil)) ...
2
votes
1answer
211 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 ...
32
votes
3answers
2k views

Why is `let' faster with lexical scope?

While reading through the source code for the dolist macro, I ran into the following comment. ;; This is not a reliable test, but it does not matter because both semantics are acceptable, tho one ...
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 ...
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)...
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?
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
471 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
112 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 ...
26
votes
6answers
7k views

How can I get an org-mode outline in a 2nd buffer as a dynamic table of contents?

When I edit large documents, I would like to see where I'm at by seeing the outline (with no-content) in a separate buffer. Like when you read a PDF file there is a TOC on the left. (see below) In ...
8
votes
3answers
1k views

Writing portable Elisp

Ideally, I would like to be able to store the entire contents of my .emacs.d directory and have it "just work" on any Emacs I load it into, but still take advantage of any features of the specific ...
20
votes
1answer
5k views

Get content of a buffer

So buffer-string gets the content of the current buffer. But it doesn't allow specifying other buffers. How can I get around that? Do I need something like save-window-excursion to make it work?
19
votes
5answers
5k views

How can I evaluate elisp in an orgmode file when it is opened?

I have elisp code I'd like to run in orgmode files when they load (different for different files, and defined in the file itself). Is there a way to do this? I didn't see anything in http://orgmode....
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)
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 ...
13
votes
7answers
2k views

Elisp code to check for internet connection

When I open Emacs, it evaluates my init file, which includes refreshing my package archives via internet connection. This is problematic when I don't have an internet connection, thus I need to ...
16
votes
5answers
2k views

How can I map over a vector and get a vector?

The only thing I've found that works is (eval `(vector ,@(mapcar #'1+ [1 2 3 4]))) => [2 3 4 5] but that seems far too complicated to be the 'right' way.

1
2 3 4 5
9