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

Is there a concise emacs lisp equivalent of Python's [n:m] list slices?

One thing I find myself missing in emacs lisp is, surprisingly, a particular bit of list manipulation. I miss Python's concise list slicing. >>> mylist = ["foo", "bar", "baz", "qux", "frobnitz"] >>> mylist[1:4] ['bar', 'baz', 'qux'] I see the…
Brighid McDonnell
  • 4,293
  • 4
  • 36
  • 61
23
votes
4 answers

How can I get a substring of a string in Emacs Lisp?

When I have a string like "Test.m", how can I get just the substring "Test" from that via elisp? I'm trying to use this in my .emacs file.
Peter
  • 593
  • 3
  • 7
  • 15
22
votes
2 answers

Is there an Emacs hook that runs after every buffer is created?

I'm looking to run some code every time Emacs creates a buffer. Is there a hook for this? Something with a name like after-make-buffer-functions? Edit: If anyone wants to know what I wanted this for, you can read the relevant portion of my Emacs…
Ryan C. Thompson
  • 40,856
  • 28
  • 97
  • 159
22
votes
2 answers

Elisp split-string function to split a string by . character

I am trying to split a string using 'split-string' function based on the . character. But (split-string "1.2.3" ".") doesn't work at all. It just returns a list of variable number of empty strings. Is . a special character that needs to be escaped…
Guruprasad
  • 1,447
  • 4
  • 16
  • 34
22
votes
4 answers

Why sharp quote lambda expressions?

It is a technique used frequently in On Lisp, which is on Common Lisp: > (mapcar #'(lambda (x) (+ x 10)) '(1 2 3)) (11 12 13) Why is sharp-quote needed or even possible? lambda expressions return function objects, and sharp quoting returns…
djechlin
  • 59,258
  • 35
  • 162
  • 290
22
votes
3 answers

Relative path to absolute path in Elisp

Having a relative path, how do I turn it into an absolute one from the location where the elisp file that I'm loading is. That is, I have an elisp file that I'm loading, it has an relative path and I need an absolute one.
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
22
votes
1 answer

In Emacs, how do I display a message in the minibuffer with font face properties?

I want to display a colored string of text in the minibuffer, but when I use the 'message' function, the text-properties of are stripped.
Aemon Cannon
  • 440
  • 3
  • 8
22
votes
3 answers

Convert decimal <-> hex

Given a list of decimal numbers, how can each number be converted to its equivalent hexadecimal value, and vice versa? For example: (convert2hex 255 64 64); -> (FF 40 40) (convert2dec FF 40 40); -> (255 64 64) (convert2hex 255 64 64 255 64 64…
anon
22
votes
3 answers

In Emacs how do I make a local variable safe to be set in a file for all possible values

In Elisp I have introduced for a special custom mode a variable like: (defvar leo-special-var "") (make-variable-buffer-local 'leo-special-var) Now I set this variable in files I with the lines (in the file to edit): # Local Variables: #…
halloleo
  • 9,216
  • 13
  • 64
  • 122
22
votes
2 answers

Walk up the directory tree

The file tree is as follwing: - foo - lorem - ipsum <- - baz <- - bar - baz The currently visited file is ipsum. Now I want to find the first baz and the directory it is in. How do I walk up the tree from ipsum in elisp?
Reactormonk
  • 21,472
  • 14
  • 74
  • 123
22
votes
2 answers

Emacs auto-minor-mode based on extension

I found this question somewhat on the topic, but is there a way [in emacs] to set a minor mode (or a list thereof) based on extension? For example, it's pretty easy to find out that major modes can be manipulated like so (add-to-list…
Sean Allred
  • 3,558
  • 3
  • 32
  • 71
22
votes
1 answer

How to refer to the file currently being loaded in Emacs Lisp?

I am looking to include a reference to a non-elisp file (a small Python program), and would like to be able to say "it is in the same directory as the current file, but with a different file name." In many scripting languages, there are things like…
haxney
  • 3,358
  • 4
  • 30
  • 31
22
votes
2 answers

Why is "goto-line" in Emacs for interactive use only?

What problem can happen if the goto-line function is used in a non-interactive elisp program? Its docstring gives a warning saying that: This function is usually the wrong thing to use in a Lisp program. What you probably want instead is…
dkim
  • 3,930
  • 1
  • 33
  • 37
21
votes
5 answers

Maximize Emacs on start up? (not the fullscreen)

It's common for me to press alt-f10 (in GNU/Linux) after Emacs start up for maximizing window (in the Emacs terminology, it's actually a frame). Most of the time I press thrice because I was too early to press first alt-f10 which makes some garbage…
kindahero
  • 5,817
  • 3
  • 25
  • 32
21
votes
2 answers

File extension hook in Emacs

I'd like to run a hook for specific file extensions (i.e. not modes). I have zero experience with elisp, so I cargo-cult coded this: (defun set_tab_mode () (when (looking-at-p "\\.cat") (insert "OK") (orgtbl-mode))) (add-hook…
user673592
  • 2,090
  • 1
  • 22
  • 37