pfm: .plan, site map, about

GNU Emacs

Website: GNU Emacs.

Emacs is an extremely powerful editor. It’s been around for several decades and I think every software engineer should at least try it, because it can have great impact on how we work with the source code.


I’ve split my ~/.emacs.d/init.el file into following sections:

Most basic settings

This is where I keep sources of (M)ELPA packages and maintain load-path, the list of directories searched for extensions.


Key goal is to adjust the environment to my preferences and habits.

Inhibit unnecessary announcements:

(eval '(inhibit-startup-echo-area-message "USERNAME"))
(setq inhibit-startup-message t
      initial-scratch-message "")

I use built–in version–tracking that Emacs provides:

(setq version-control t
      delete-old-versions t
      kept-old-versions 10
      kept-new-versions 5
      dired-kept-versions 5)

I want buffers to have reasonably unique names, but without too long substrings to be typed or completed. I also prefer moving by logical instead of visual lines. Also: no beeping please!

(setq uniquify-buffer-name-style 'post-forward-angle-brackets
      uniquify-strip-common-suffix t
      line-move-visual nil
      history-length 200
      visible-bell t)

I like being able to use history of files, expressions and commands shared across my Emacs sessions.

(savehist-mode 1)

I don’t use GNU/Linux, so my /bin/ls doesn’t support --dired option. Following setting disables unnecessary checks.

(setq dired-use-ls-dired nil)

User information

I use this section only to set up only user-mail-address and user-full-name.

User interface

First, some localisation. I’m a fan of ISO dates and sometimes I plan using week numbers. However, my mode–line only includes day number with a short month name to take less space. Of course I use UTF–8.

(calendar-set-date-style 'iso)
(set-language-environment "Polish")
(set-default-coding-systems 'utf-8)
(setq calendar-week-start-day 1
      display-time-format "%H:%M (%d%^b, W%0V)")

Then, some things need to be hidden to leave more space for the text I work with.

(menu-bar-mode -1)
(tool-bar-mode -1)
(blink-cursor-mode 1)
(display-time-mode 1)
(display-battery-mode 1)

I want the cursor to be easy to locate on the screen, so it blinks forever, not just ten times or something.

(setq blink-cursor-blinks -1)

I want long lines to be visible in their entirety, not truncated at the window edge.

(setq-default truncate-lines nil)

Some commands are disabled by default. Well, of course I use them:

(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'scroll-left 'disabled nil)

Several global key definitions:

(global-set-key (kbd "<mouse-3>") 'imenu)
(global-set-key (kbd "C-x C-b") 'bs-show)
(global-set-key (kbd "<f3>") 'ffap)
(global-set-key (kbd "<f7>") 'compile)
(global-set-key (kbd "M-<f7>") 'recompile)
(global-set-key (kbd "C-c b") 'bury-buffer)

Highlighting parenthesis is a very useful feature:

(show-paren-mode t)
(setq show-paren-style 'parenthesis
      show-paren-delay 0.3)

And of course, sometimes I track appointments with Emacs:

(appt-activate 1)

I use hunspell to spell–check:

(setq ispell-program-name "hunspell")

Buffer-mode support

I use the following snippet to define per-mode settings:

(defmacro define-mode-settings (mode-name &rest body)
  (let ((settings-name (pfm-concat-symbols mode-name 'settings))
	(hook-name (pfm-concat-symbols mode-name 'hook)))
       (defun ,settings-name ()
      (add-hook ',hook-name ',settings-name))))

Above snippet can be used like that:

(define-mode-settings markdown-mode
  (set (make-local-variable 'parens-require-spaces) nil))

Since many projects include a README and LICENSE files, I use text-mode in them. I put these definitions at the end of auto-mode-alist in case other rules matched better.

(add-to-list 'auto-mode-alist '("\\<README\\|LICEN[CS]E\\'" . text-mode) t)

At the end of the file, there’s a section for Customize, Emacs self–configuration package that can be used to adjust a lot of the user-configurable parameters. I don’t document this section here, because it’s not particularly readable.

Additional modules

I use the following additional modes and tools:

Modules used in the past

I used to use Org–mode, but it was too bloated for me. I like simplicity and markdown-mode gives it to me, so I’ve switched with all my notes and projects to plain old markdown, or even plain text.

At some point I was also experimenting with muse, but as it’s no longer actively maintained, I’ve given up.

Finally, I’m a great fan of Gnus, but it doesn’t support sending email from several accounts (requires dirty tricks with From:–based account selection), so I’m not using it actively at the moment. I may return to using it, because in my opinion it provides unparalleled user experience.

My own additions

In text modes, I like using non-breaking space to be inserted in certain conditions to avoid orphans. The following snippet does that:

(defun pfm-point-back (n)
  (let ((p (- (point) n)))
    (if (< p (point-min))

(defun pfm-insert-non-breaking-space (arg)
  (interactive "p")
  (insert-char #xa0 arg))

(defun pfm-insert-space-dwim (arg)
  (interactive "p")
  (cond ((looking-back "\\<\\w" (pfm-point-back 2))
         (pfm-insert-non-breaking-space arg))
         (self-insert-command arg))))

With the followingn line in mode’s settings, my spacebar inserts the appropriate type of space for the given context.

(local-set-key (kbd "SPC") 'pfm-insert-space-dwim)

Of course in HTML mode, this could insert &nbsp; instead, but using UTF-8 character (U+00A0) seems reasonable to me most of the time.

This work by Piotr Mieszkowski is licensed under CC-BY-SA 4.0