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.

Emacs Lisp is a dialect of the Lisp programming language used as a scripting language by Emacs. It is used for implementing most of the editing functionality built into Emacs, the remainder being written in C (as is the Lisp interpreter itself).

The most common way to customize Emacs is by Emacs Lisp expressions in your init file, ~/.emacs or ~/.emacs.d/init.el.

Emacs packages are also predominantly written in Emacs Lisp. See A guide to learning Emacs Lisp for non-programmers for reference. The Emacs Lisp Reference is also viewable in Emacs with C-him elisp RET.

Use for questions about the language itself, in particular, its relation to other Lisp dialects and differences from them.

Please DO NOT use for questions about using Elisp, e.g., snippets of code in your customizations or questions about how to write an application. Use only for questions about the nature of the language itself.

When available and appropriate, use more specific tags about the aspects of the language, such as elisp-macros, variables, lexical-scoping, etc. You can use such tags for questions about using such things, as well as questions about their nature/meaning.

Wisdom from the Stack

416 questions
89
votes
4 answers

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 through custom.el. I typically use custom.el to…
J David Smith
  • 2,635
  • 1
  • 16
  • 27
56
votes
6 answers

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 then add-to-list again, but I'm wondering whether…
mbork
  • 1,647
  • 1
  • 13
  • 23
55
votes
6 answers

Can I use org-mode to structure my .emacs or other .el configuration file?

My .emacs configuration file gets bigger and bigger and I'd like to get a better overview and structuring by adding headings, subheadings and being able to hide or show them like I can do with Emacs org-mode. I noticed that I can activate org-mode…
MostlyHarmless
  • 1,395
  • 2
  • 13
  • 14
53
votes
3 answers

How to save a keyboard macro as a Lisp function?

Very frequently I would need to perform the set of steps requiring multiple key strokes. For the same session those steps can be recorded in a keyboard macro. An example is saving a frequently executed search/replace operation as a keyboard macro.…
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
46
votes
2 answers

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, variables, and constants with a unique…
Dan
  • 32,584
  • 6
  • 98
  • 168
45
votes
3 answers

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 "some-variable is %s"…
Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
39
votes
2 answers

Optional parameter defaults

Emacs Lisp does not have syntactical support for non-nil defaults of optional parameters. What is the recommended idiom for supplying these parameters? To clarify my point, here is one overly explicit way of doing so. (defun command (a &optional…
Matthew Piziak
  • 5,958
  • 3
  • 29
  • 77
38
votes
3 answers

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 the use case for each would be.
shadowthief
  • 383
  • 1
  • 3
  • 5
38
votes
3 answers

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 me) (with-current-buffer b (do-that (or this (and…
Malabarba
  • 22,878
  • 6
  • 78
  • 163
38
votes
2 answers

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.
Name
  • 7,689
  • 4
  • 38
  • 84
35
votes
4 answers

When to sharp-quote a lambda expression?

Q: When, if ever, is it useful to sharp-quote a lambda, and when, if ever, must we not sharp-quote a lambda? People use lambdas in three ways: plain: (lambda (x) x) quoted: '(lambda (x) x) sharp-quoted: #'(lambda (x) x) This SO thread discusses…
Dan
  • 32,584
  • 6
  • 98
  • 168
34
votes
1 answer

Why do regular expressions created with the regex builder use syntax different from the interactive regular expressions?

So, using the regular expression builder (M-x re-builder), finding lines that end in \ takes "\\$", while in search and replace by regex, it only takes "\$". I would have expected the regex builder to build directly usable expressions, so what…
user2699
  • 2,181
  • 16
  • 32
34
votes
1 answer

What is the difference between ' and #' in front of a symbol?

I'm a little new to Emacs. When looking at some of the configurations, I found there are two types command in "add-hook". (add-hook 'LaTeX-mode-hook #'LaTeX-math-mode) and (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode) This has confused me for a…
X.Arthur
  • 443
  • 4
  • 9
33
votes
3 answers

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 defers the loading to execution time. I've recently…
caisah
  • 4,056
  • 1
  • 23
  • 43
32
votes
4 answers

How can I simulate an arbitary key event from Elisp?

Is it possible to simulate an arbitrary key event from elisp? I am aware of ways that I can find the binding for a given key, and then call that command interactively, but what if that key event is not bound to a command? As one example, what if I…
nispio
  • 8,175
  • 2
  • 35
  • 73
1
2 3
27 28