Emacs Tips 1

September 9, 2013
Updated: March 31, 2017

In this post I will be sharing my personal hacks on how I use Emacs for my day-to-day stuff.

Table of contents


This command deletes a region if one is active, or deletes the character underneath the cursor.

(defun delete-char-or-region (&optional arg)
  (interactive "p")
  (if (region-active-p)
      (delete-region (region-beginning)
      (if (fboundp 'sp-delete-char)
          (sp-delete-char arg)
          (delete-forward-char arg))))


I use this command frequently, and I use it from typesetting LaTeX documents, compiling Scribble documents, compiling code, and just about anything that I can use make with.

(defun compile-file ()
  (compile "make -k"))


I want to have a command that explicitly saves the input ring of Geiser:

(defun geiser-save ()

I also have the following, because I want to align the λ symbol nicely.

(defun my-scheme-mode-hook ()
  (put 'λ 'scheme-indent-function 1))

(add-hook 'scheme-mode-hook 'my-scheme-mode-hook)


This snippet ensures that the Emacs server, the one that emacsclient connects to:

(require 'server)

(unless (server-running-p)

Alternatively, you may run Emacs in daemon mode from the command-line:

$ emacs --daemon


I want a way to kill the current buffer, without being asked what buffer to kill. I will only get prompted if the current has been modified.

(defun kill-current-buffer ()
  (kill-buffer (current-buffer)))


There have been plenty of times in the past when I needed a function that just marks a line. What I have is below. Executing it multiple times, marks multiple lines.

(defun mark-line (&optional arg)
  (interactive "p")
  (if (not mark-active)
        (setq mark-active t)))
  (forward-line arg))

Key bindings

The key bindings for the commands above, are listed below:

 :map global-map
 ("<delete>" . delete-char-or-region)
 ("C-x C-k" . kill-current-buffer)
 ("C-x c" . compile-file)
 ("M-z" . mark-line))

 :map scheme-mode-map
 ("C-c <tab>" . completion-at-point))

Closing remarks

I hope you’ll be able to find use of any of them. The rest of the configuration can be found here.