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
26
votes
1 answer

Getting a list of running Emacs timers

I've created a timer and stored a reference to it in Emacs with (setq my-timer-store (run-at-time "1 min" 900 'my-func)) I usually execute this elisp in the morning and then stop it from running overnight by executing (cancel-timer…
Carcophan
  • 1,508
  • 2
  • 18
  • 38
25
votes
4 answers

show org-mode outline up to a certain heading level

I'm making an outline for my thesis using org-mode, and I'd like to show all headings up to a certain level (e.g. all level-1 and level-2 headings). I haven't found anything about that in the org-mode manual. Cycling shows either only level-1…
daniel kullmann
  • 13,653
  • 8
  • 51
  • 67
25
votes
7 answers

How can I access the path to the current directory in an emacs directory variable file?

According to the Emacs documentation, Directory Variables apply to all files below a directory that contains an .dir-locals.el file. How can I, in that file, set a variable to the full path that contains the file? For example: ((nil .…
Chris R
  • 17,546
  • 23
  • 105
  • 172
25
votes
3 answers

How to Create a Temporary Function in Emacs Lisp

I'm making some tedious calls to a bunch of functions, but the parameters will be determined at runtime. I wrote a simple function to keep my code DRY but giving it a name is unnecessary. I don't use this function anywhere else. I'm trying to do it…
Cristian
  • 42,563
  • 25
  • 88
  • 99
25
votes
1 answer

Run elisp program without Emacs?

elisp is a good language, I find it can handle all kind of jobs, but can I use it like a shell script? i.e. execute some *.el files from the console, without launching Emacs. Or launch Emacs, but don't enter interactive mode.
Dean Chen
  • 3,800
  • 8
  • 45
  • 70
24
votes
7 answers

In Emacs can you evaluate an Emacs Lisp expression and replace it with the result?

For example if I have the text: Sum of items is (+ 1 2 3) I want to move to the end of the line, evaluate the expression and replace it with the result, so that it reads: Sum of items is 6
justinhj
  • 11,147
  • 11
  • 58
  • 104
24
votes
2 answers

Writing "Hello World" in Emacs?

I would like to write a few Unix scripts in Emacs Lisp. However, there doesn't seem to be a clean way to write to STDOUT so I can redirect the results to a file or pipe the output to another command. The print function places double quotes around…
anon
24
votes
2 answers

Convert Emacs macro into Elisp

Is there a way to convert an emacs macro into elisp, not like what M-x insert-kbd-macro does, the actual activity becoming elisp statements. Thanks for your help.
Sahas
  • 10,637
  • 9
  • 41
  • 51
24
votes
2 answers

difference between (defalias 'A (symbol-function 'B)) and (defalias 'A 'B)

I was reading subr.el and saw this code: (defalias 'backward-delete-char 'delete-backward-char) (defalias 'search-forward-regexp (symbol-function 're-search-forward)) Interestingly, the first line doesn't use symbol-function while the second line…
Yoo
  • 17,526
  • 6
  • 41
  • 47
24
votes
5 answers

How to automatically save files on lose focus in Emacs

Is it possible to configure Emacs, so that it saves all files when the emacs window loses focus?
Rockiger
  • 422
  • 3
  • 11
24
votes
2 answers

How do I get the region (selection) programmatically in Emacs Lisp?

I need to access the selection in Emacs buffer. I have found this article How do I access the contents of the current region in Emacs Lisp? and it helps me a lot. But there is a problem. The first time I select (highlight) a region, it works okay,…
sailing
  • 455
  • 1
  • 5
  • 12
23
votes
6 answers

How do I apply "or" to a list in elisp

In elisp I can evaluate or as a function just like +. (or nil 0 nil) ==> 0 (+ 1 0 1) ==> 2 I can use apply to apply + to a list (apply '+ '(1 0 1)) ==> 2 So, I would think or would work the same way, but it doesn't. (apply 'or '(nil 0 nil)) ==>…
Eponymous
  • 6,143
  • 4
  • 43
  • 43
23
votes
2 answers

PPRINT in Emacs Lisp?

Emacs Lisp does not seem to have a PPRINT function. How do you pretty print an S-EXP in elisp the way you can in Common Lisp?
anthonyf
  • 231
  • 2
  • 4
23
votes
4 answers

How to delete variable/forms in Lisp?

In Python we have the del statement for deleting variables. E.g: a = 1 del a What the equivalent of this in Lisp? (setq foo 1) ;; (del foo) ?
Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74
23
votes
3 answers

Emacs lisp "shell-command-on-region"

In GNU Emacs, I want to run a program, figlet, on the currently selected text. I then want to comment the region which is produced. I have figured out how to do it using the standard Emacs commands: set mark with C- at the start of the…
user181548