Louis' Blog

Table of Contents


Recently, I fell in love with Emacs. Here I share some of my first snippets of Emacs Lisp code I use to customize my workflow.

2022-04-30 Emacs Lisp as a general programming language

Today, I was researching about Emacs Lisp as a general programming language. I wanted to get some impressions from other people who tried or are using Emacs Lisp for other purposes than just configuring Emacs.

I found a discussion on Reddit talking about this, also mentioning that once the German Air Traffic Control was running some stuff on Emacs.

After reading some other discussions or blogs, my impression is that most people don't recommend Emacs Lisp for general programming. However, their arguments are often vage, referencing weaknesses of Emacs Lisp from times long gone. But then there are some neutral to it, saying: If it does that job, go for it. Emacs Lisp now has lexical scoping, native compilation, threading, and a plethora of packages/libraries to use.

In fact, there are already some outstanding examples, like Magit, clearly showing that Emacs Lisp can be used to develop advanced tools. Also, as of Emacs 28.1, there is now native compilation, which speeds up the execution of Lisp code in order of magnitutes.

There is also a very comprehensive library to support a more functional programming style, called dash.el, offering functions like map, reduce, etc. I will definitely give it a try.

2022-04-29 Kill a buffer and delete the file

I often find myself wanting to kill (close) a buffer and delete the associated file along with it:

(defun my/kill-buffer-and-delete-file ()
  "Kill current buffer and move associated file to system's trash"
(let ((file (buffer-file-name)))
  (move-file-to-trash file)))

The file will be moved to the trash, so you will still be able to recover it. Also, Emacs will prompt you if the file has unsaved changes.

Update 2202-05-02: I've discovered a flaw in my function: if the visited file from the buffer didn't exist (i.e. for a newly created file or buffers without a real file) I got an error message telling me that the file could not be deleted.

Here is the second version, which fixes that:

(defun my/kill-buffer-and-delete-file ()
  "Kill the current buffer and delete associated file"
  (let ((file (buffer-file-name)))
    (when (kill-buffer)
      (when (file-exists-p file)
        (move-file-to-trash file)))))

2022-04-28 Open Emacs-config file quickly

I'm hacking on my Emacs config often. So I mapped a little function that opens the config file to a custom keybinding C-c i:

(defun my/visit-emacs-init ()
  "Open Emacs init file in a new buffer. If there is already a buffer open with the init file, use it."
  (find-file "~/.emacs.d/init.el"))

(global-set-key (kbd "C-c i") 'my/visit-emacs-init)

Contact me


I'm active on XahLee's Discord server. My username is louis77.


Follow me on Twitter. It belongs to Elon Musk now.


Created: 2022-05-02 Mo 20:41

Emacs 29.0.50 (Org mode 9.5.3)