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
80
votes
2 answers

How can you write multiple statements in elisp 'if' statement?

In elisp, there is an 'if' case where I would like to perform many different things: (if condition (do-something) (do-another-thing) ...) However, (do-another-thing) is executed in the else-case only. How can you specify a block of…
Martin Cote
  • 28,864
  • 15
  • 75
  • 99
80
votes
1 answer

eval-after-load vs. mode hook

Is there a difference between setting things for a mode using eval-after-load and using the mode hook? I've seen some code where define-key is used inside a major mode hook, and some other code where define-key is used in eval-after-load…
Yoo
  • 17,526
  • 6
  • 41
  • 47
78
votes
6 answers

Command to clear shell while using emacs shell

Is there a builtin command to clear shell while using shell in emacs? If not, is there an elisp function to achieve the same?
keeda
  • 2,605
  • 5
  • 28
  • 27
75
votes
3 answers

Filtering text through a shell command in Emacs

In vi[m] there is the ! command which lets me pipe text through a shell command -- like sort or indent -- and get the filtered text back into the buffer. Is there an equivalent in emacs?
Rohit
  • 7,449
  • 9
  • 45
  • 55
74
votes
3 answers

How can I check if a file exists using Emacs Lisp?

I would like emacs to mark files that are generated as read-only when they're opened. The part of the puzzle that I'm missing is how to check if a file "exists". I currently have the following: ;; ;; get file extension ;; (defun get-ext…
Richard Corden
  • 21,389
  • 8
  • 58
  • 85
72
votes
15 answers

How do I create an empty file in emacs?

How can I create an empty file from emacs, ideally from within a dired buffer? For example, I've just opened a Python module in dired mode, created a new directory, opened that in dired, and now need to add an empty __init__.py file in the…
Singletoned
  • 5,089
  • 3
  • 30
  • 32
68
votes
8 answers

What is the correct way to join multiple path components into a single complete path in emacs lisp?

Suppose I have variables dir and file containing strings representing a directory and a filename, respectively . What is the proper way in emacs lisp to join them into a full path to the file? For example, if dir is "/usr/bin" and file is "ls", then…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
68
votes
5 answers

How to debug elisp?

Normally the easiest way to debug is using printf. What can I do to debug emacs-lisp? How can I print something to emacs editor from elisp? Or is there any way to debug elisp code? For example, how can I check if the following code is run in .emacs…
prosseek
  • 182,215
  • 215
  • 566
  • 871
63
votes
4 answers

REPL for Emacs Lisp

What are some REPLs for Emacs Lisp? Is there only one that is within Emacs? Are there some that run inside terminal outside Emacs?
Tim
  • 1
  • 141
  • 372
  • 590
60
votes
7 answers

emacs lisp, how to get buffer major mode?

I have tried to search Google and look in the manual, but still cannot find how to get major mode of a buffer object. Can you help me with an example or a reference. Thanks only solution I could find was to query major-mode after changing the…
Anycorn
  • 50,217
  • 42
  • 167
  • 261
58
votes
10 answers

How to live with Emacs Lisp dynamic scoping?

I've learned Clojure previously and really like the language. I also love Emacs and have hacked some simple stuff with Emacs Lisp. There is one thing which prevents me mentally from doing anything more substantial with Elisp though. It's the concept…
auramo
  • 13,167
  • 13
  • 66
  • 88
56
votes
2 answers

What are the major differences between Emacs Lisp and Common Lisp?

I want to learn the lisp language, since my editor is emacs, I prefer emacs lisp. Can anyone give me some suggestions to learn lisp, emacs lisp, or common lisp? What are the major differences between those two?
user1087032
  • 755
  • 1
  • 6
  • 8
56
votes
3 answers

Concatenate strings in elisp

I need to concatenate path string as follows, so I added the following lines to my .emacs file: (setq org_base_path "~/smcho/time/") (setq org-default-notes-file-path (concatenate 'string org_base_path "notes.org")) (setq todo-file-path (concatenate…
prosseek
  • 182,215
  • 215
  • 566
  • 871
55
votes
3 answers

How can I get Emacs to revert all unchanged buffers when switching branches in git?

Often, when I switch branches in git, if the files are open in emacs, then emacs asks if I want to revert them (as it thinks they've changed on disk) even though the contents are identical. Firstly I'd like to find a way for emacs to not ask me…
Singletoned
  • 5,089
  • 3
  • 30
  • 32
53
votes
29 answers

What's in your .emacs?

I've switched computers a few times recently, and somewhere along the way I lost my .emacs. I'm trying to build it up again, but while I'm at it, I thought I'd pick up other good configurations that other people use. So, if you use Emacs, what's in…
A. Rex
  • 31,633
  • 21
  • 89
  • 96