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
32
votes
7 answers

How to determine whether a package is installed in elisp?

I want to customize environment while the specific package is installed properly. How to check whether some package is installed in elisp? Something like this?: (if (require 'ecb) (progn (setq ....)) (message "ECB not installed!"))
Vivodo
  • 1,542
  • 2
  • 17
  • 31
32
votes
7 answers

How do I do closures in Emacs Lisp?

I'm trying to create a function on the fly that would return one constant value. In JavaScript and other modern imperative languages I would use closures: function id(a) { return function() {return a;}; } but Emacs lisp doesn't support those. I…
vava
  • 24,851
  • 11
  • 64
  • 79
32
votes
6 answers

Auto install emacs packages with MELPA

I want to declare all packages that I want to use in emacs in a init.el file. I wonder if its possible to load the missing packages with e.g. MELPA when I startup emacs without going through the list and mark the ones I want to install?
Objective
  • 848
  • 1
  • 12
  • 27
32
votes
3 answers

Tracking down max-specpdl-size errors in emacs

I've been randomly getting the following error in emacs: Variable binding depth exceeds max-specpdl-size ...and I've been getting it at very random moments. After researching this, it seems as though some elisp somewhere is recursing too deeply. …
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
32
votes
6 answers

Replace item in association list in elisp

I have an alist in emacs lisp like: (setq a1 '((:k1 . 1) (:k2 . 2) (:k3 . 3))) and i want to change value of :k1 to 10, like (:k1 . 10). How do i do that? I tried (setf (assoc :k1 a1) '(:k1 . 10)) - it didn't work.
Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
31
votes
6 answers

How can I "URL decode" a string in Emacs Lisp?

I've got a string like "foo%20bar" and I want "foo bar" out of it. I know there's got to be a built-in function to decode a URL-encoded string (query string) in Emacs Lisp, but for the life of me I can't find it today, either in my lisp/ folder or…
Ken
  • 5,074
  • 6
  • 30
  • 26
31
votes
2 answers

wrong type argument: stringp, nil

Before now I've just been cutting and pasting code into my .emacs file, but then I decided to add some maven functionality to emacs. Now, I don't see how I was able to mess this up, but last night I kept getting the error I put in the title when I…
HahaHortness
  • 1,570
  • 1
  • 15
  • 16
31
votes
3 answers

What's the equivalent of foldr, foldl in Emacs Lisp?

What's the equivalent of foldr, foldl in Emacs Lisp?
Thomas
  • 17,016
  • 4
  • 46
  • 70
31
votes
8 answers

How to go about learning Common Lisp and Emacs Lisp?

The last few months I've been using Emacs extensively as my main development environment and I've now come to a point at which I'd like to learn it's own Emacs Lisp to write my own little stuff for Emacs and extend it to my personal needs. Having…
serk01
  • 343
  • 3
  • 8
31
votes
5 answers

.emacs global-set-key and calling interactive function with argument

In my .emacs i have the following function that transposes a line (defun move-line (n) "Move the current line up or down by N lines." (interactive "p") (let ((col (current-column)) start end) (beginning-of-line) …
yrral
  • 949
  • 1
  • 7
  • 11
30
votes
2 answers

emacs mode-specific custom key bindings: local-set-key vs define-key

After a few years customizing my .emacs file, I find I used two different kinds of constructs to setup major-mode-specific key bindings: 1. using a hook and local-set-key. For example: (defun my/bindkey-recompile () "Bind to `recompile'." …
François Févotte
  • 19,520
  • 4
  • 51
  • 74
30
votes
5 answers

Stripping duplicate elements in a list of strings in elisp

Given a list such as (list "foo" "bar" nil "moo" "bar" "moo" nil "affe") how would I build a new list with the duplicate strings removed, as well as the nils stripped, i.e. (list "foo" "bar" "moo" "affe") The order of the elements needs to be…
rafl
  • 11,980
  • 2
  • 55
  • 77
30
votes
5 answers

What does ^L in (Emacs Lisp) source code mean?

Several times I see ^L in (mostly Emacs Lisp) source codes that looks like are separators of larger logical groups. Is it their real purpose? And if so, how can I use them? Is there a built-in Emacs functionality that utilize it?
viam0Zah
  • 25,949
  • 8
  • 77
  • 100
29
votes
1 answer

emacs interactive commands with default value

I am wondering how is that some interactive commands in emacs present default value while others don't. For instance when I am in C file and cursor stands on printf, running manual-entry will suggest showing manual page for printf by default. I…
Alexander Sandler
  • 2,078
  • 2
  • 19
  • 21
29
votes
4 answers

Elisp - Loop over an alist

What's the best way to loop over an alist and do something with each pair in Emacs Lisp? I suppose a macro wouldn't be difficult, I'm just wondering if this is built in somewhere. Is there a more elegant way than below? (setq my-list '((a . 1) …
Joe
  • 3,370
  • 4
  • 33
  • 56