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
43
votes
4 answers

elisp regexp search in strings, not buffers

I have been searching everywhere in the emacs lisp documentation for how to regular expressions search into a string. All I find is how to do this in buffers. Is there something I'm missing? Should I just spit my string into a temporary buffer and…
Eli
  • 2,041
  • 4
  • 18
  • 20
43
votes
5 answers

Bind key to increase / decrease font size in emacs

In my terminal (I have terminator) I can use the key combinations Ctrl + and Ctrl - to increase / decrease the font size. In emacs I can do the following to set the font-height: (set-face-attribute 'default nil :height 70) But I do not know how to…
blueFast
  • 41,341
  • 63
  • 198
  • 344
43
votes
2 answers

Get rid of "reference to free variable" byte-compilation warnings

I'm writing an emacs major mode, which uses buffer-local variables to store some state: (defun foo-mode () "My nice major mode" (interactive) (kill-all-local-variables) (setq mode-name "foo") (setq major-mode 'foo-mode) (set…
François Févotte
  • 19,520
  • 4
  • 51
  • 74
43
votes
3 answers

Hiding markup elements in org-mode

There are plenty structural markup elements in org-mode like *bold* or /italic/, but they are visible in the org-mode text, which is good, if the file is intended for export, and bad, if it is intended for semi-WYSIWYG editing. I want to hide these…
Mirzhan Irkegulov
  • 17,660
  • 12
  • 105
  • 166
42
votes
7 answers

lisp filter out results from list not matching predicate

I am trying to learn lisp, using emacs dialect and I have a question. let us say list has some members, for which predicate evaluates to false. how do I create a new list without those members? something like { A in L: p(A) is true }. in python…
Anycorn
  • 50,217
  • 42
  • 167
  • 261
41
votes
1 answer

Emacs: same buffer, two windows, one narrowed, one not

I find the narrow-to-region command useful, however it applies to the buffer and not to the current window. I'd like to have one window display a narrowed version of the buffer, while the buffer is displayed widened if it occurs in any other…
EoghanM
  • 25,161
  • 23
  • 90
  • 123
41
votes
1 answer

What is "with-eval-after-load" in Emacs Lisp

I came across the macro with-eval-after-load when trying to install persp-mode from here. But I am unable to find the macro inside Emacs and/or on Google. Where is it defined? Is it part of standard Emacs Lisp?
Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135
41
votes
6 answers

How to invoke an interactive elisp interpreter in Emacs?

Right now I write expressions in the *scratch* buffer and test them by evaluating with C-x C-e. I would really appreciate having an interactive interpreter like SLIME or irb, in which I could test Emacs Lisp expressions.
Michał Kwiatkowski
  • 9,196
  • 2
  • 25
  • 20
40
votes
4 answers

How to copy to clipboard in Emacs Lisp

I want to copy a string to the clipboard (not a region of any particular buffer, just a plain string). It would be nice if it were also added to the kill-ring. Here's an example: (copy-to-clipboard "Hello World") Does this function exist? If so,…
User1
  • 39,458
  • 69
  • 187
  • 265
40
votes
5 answers

How to convert list to string in Emacs Lisp

How can I convert a list to string so I can call insert or message with it? I need to display c-offsets-alist but I got Wrong type argument: char-or-string-p for insert or Wrong type argument: stringp for message.
jcubic
  • 61,973
  • 54
  • 229
  • 402
40
votes
4 answers

let and flet in emacs lisp

I don't know if you would call it the canonical formulation, but to bind a local function I am advised by the GNU manual to use 'flet': (defun adder-with-flet (x) (flet ( (f (x) (+ x 3)) ) (f x)) ) However, by accident I tried (after having…
hatmatrix
  • 42,883
  • 45
  • 137
  • 231
39
votes
2 answers

Emacs, how to get directory of current buffer?

In emacs there is buffer-file-name that gives the full path to a file. But is there a way to get only the directory of the file loaded in the current buffer?
Leo Ufimtsev
  • 6,240
  • 5
  • 40
  • 48
39
votes
5 answers

How to check if a string is empty in Emacs Lisp?

I would like to write an if statement that will do something base on whether a string is empty. For example: (defun prepend-dot-if-not-empty (user-str) (interactive "s") (if (is-empty user-str) (setq user-str (concat "." user-str))) …
oneself
  • 38,641
  • 34
  • 96
  • 120
38
votes
2 answers

What is the difference between `global-set-key` and `define-key global-map` in Emacs

If you had two snippets: (global-set-key "\C-d" delete-char) and (define-key global-map "\C-d" delete-char) Is there a difference between the two? If so, when would you use one over the other?
haxney
  • 3,358
  • 4
  • 30
  • 31
38
votes
6 answers

C++11 mode or settings for emacs?

I'm running Emacs 23.3.1 (Ubuntu, Oneiric package) and emacs doesn't appear to understand any of the new C++11 keywords, constexpr, thread_local, etc. Also it doesn't understand that '>>' is now permitted in template parameters, or the new 'enum…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165