Questions tagged [elisp]

Emacs Lisp is the extension language for the GNU Emacs text editor, and in fact, most of the functionality of Emacs is implemented using Emacs Lisp. Users generally customize Emacs' behavior by adding Emacs Lisp statements to their `~/.emacs`, or writing separate packages.

Emacs Lisp is the extension language for the GNU Emacs text editor, and in fact, most of the functionality of Emacs is implemented using Emacs Lisp. Users generally customize Emacs' behavior by adding Emacs Lisp statements to their ~/.emacs or ~/.emacs.d/init.el file, or writing separate packages. A guide to learning Emacs Lisp for non-programmers can be found here.

Emacs Lisp differs from most other lisps in two main ways:

  1. It has special features for scanning and parsing text, as well as features for handling files, buffers, arrays, displays, and subprocesses. This is due to the fact that it is designed to be used in a text editor.
  2. It uses primarily dynamic scope as opposed to lexical scope. This was done very intentionally, the reasons are well explained in the 1981 paper on Emacs. Lexical scope has been introduced only recently and, while not yet widely adopted, is expected to become increasingly important in future versions according to the manual.

Wisdom from the Stack

Emacs on Stack Exchange

3773 questions
38
votes
7 answers

How to sum a list of numbers in Emacs Lisp?

This works: (+ 1 2 3) 6 This doesn't work: (+ '(1 2 3)) This works if 'cl-*' is loaded: (reduce '+ '(1 2 3)) 6 If reduce were always available I could write: (defun sum (L) (reduce '+ L)) (sum '(1 2 3)) 6 What is the best practice for…
jfs
  • 399,953
  • 195
  • 994
  • 1,670
38
votes
3 answers

What is the difference between setq and set-variable in emacs?

What is the difference between setq and set-variable in emacs lisp. When should I use setq and when should I set-variable.
Nate
  • 6,779
  • 8
  • 28
  • 21
38
votes
2 answers

How to periodically run a task within emacs?

Is there a way to periodically run an elisp function in a long-running emacs, similar to cron, but within the emacs process? For example I want to "automatically run (recentf-save-list) every half hour" because it otherwise only runs on exit, which…
Jonathan Swartz
  • 1,913
  • 2
  • 17
  • 28
37
votes
6 answers

Show Keys In Emacs Keymap Value

When I query the current value of the keymap, eg with M-: (current-local-map), it shows me something along these lines: Value: (keymap (S-mouse-2 . muse-follow-name-at-mouse-other-window) (mouse-2 . muse-follow-name-at-mouse) (33554445 .…
EvgeniySharapov
  • 3,078
  • 3
  • 27
  • 38
36
votes
3 answers

emacs lisp listing files with glob expansion

Are there any library or function that performs a bash-like glob expansion for emacs lisp? For example: (directory-files-glob "~/Desktop/*") > ("/home/user/Desktop/file1" "/home/user/Desktop/file2") If there isn't such a function are there any…
pygabriel
  • 9,840
  • 4
  • 41
  • 54
36
votes
4 answers

Is there a function that joins a list of strings into a delimited string?

Is there a function in Emacs Lisp that does the opposite of split-string, i.e. joins the elements of a list into string delimited by a given delimiter? In other words, is there a function that given a list, e.g. ("foo" "bar" "baz"), and a delimiter,…
N.N.
  • 8,336
  • 12
  • 54
  • 94
35
votes
2 answers

What does the double minus (--) convention in function names mean in Emacs Lisp

I've been reading through a number of Emacs Lisp packages and have come across the convention of some functions being declared with -- after the library prefix, e.g.: (defun eproject--combine-regexps (regexp-list) I'm wondering if this a convention…
stsquad
  • 5,712
  • 3
  • 36
  • 54
35
votes
8 answers

How do I write a regular expression that excludes rather than matches, e.g., not (this|string)?

I am stumped trying to create an Emacs regular-expression that excludes groups. [^] excludes individual characters in a set, but I want to exclude specific sequences of characters: something like [^(not|this)], so that strings containing "not" or…
Anycorn
  • 50,217
  • 42
  • 167
  • 261
35
votes
2 answers

How to run setq interactively

Specifically I want to do the same thing as (setq frame-title-format ...) would do in my config file, but from the M-x interactive command. M-x setq does not seem to work.
sligocki
  • 6,246
  • 5
  • 38
  • 47
35
votes
8 answers

Add CREATED date property to TODOs in org-mode

I read the org-mode manual but couldn't find an easy way to add a CREATED field to newly created TODOs. In combination with org-log-done one could then compute the time it took to close a particular TODO. This is especially useful when using archive…
Renke Grunwald
  • 855
  • 1
  • 9
  • 15
34
votes
7 answers

Converting from camelcase to _ in emacs

Is there an emacs function to convert a camel-cased word to underscore? Something, like: longVariableName M-x to-underscore long_variable_name
David Nehme
  • 21,379
  • 8
  • 78
  • 117
33
votes
10 answers

How can I emulate Vim's * search in GNU Emacs?

In Vim the * key in normal mode searches for the word under the cursor. In GNU Emacs the closest native equivalent would be: C-s C-w But that isn't quite the same. It opens up the incremental search mini buffer and copies from the cursor in the…
richq
  • 55,548
  • 20
  • 150
  • 144
33
votes
4 answers

In Lisp (Clojure, Emacs Lisp), what is the difference between list and quote?

From reading introductory material on Lisp, I now consider the following to be identical: (list 1 2 3) '(1 2 3) However, judging from problems I face when using the quoted form in both Clojure and Emacs Lisp, they are not the same. Can you tell me…
neo
  • 333
  • 3
  • 4
33
votes
1 answer

Unset key binding in emacs

For example, in the codes of zen-coding, the "C-j" shadows the normal behavior of "C-j" (newline-and-indent) (define-key zencoding-mode-keymap (kbd "C-j") 'zencoding-expand-line) Then how can I unset this keybinding and use C-j for…
Hanfei Sun
  • 45,281
  • 39
  • 129
  • 237
33
votes
5 answers

how to delete the repeat lines in emacs

I have a text with a lots of lines, my question is how to delete the repeat lines in emacs? using the command in emacs or elisp packages without external utils. for example: this is line a this is line b this is line a to remove the 3rd line (same…
toolchainX
  • 1,998
  • 3
  • 27
  • 43