User Tools

Site Tools


development:emacs:init

A useful Emacs init file for C/C++ programmers

For C/C++ programmers Emacs is a very useful environment. But for beginners it seems to be difficult to select the right (and most useful) packages and commands. Therefore i want to present my initialization file default.el and the associated key bindings as a PDF. The initialization file should work with Emacs 23.x and 24.x under Linux and Windows.

There are some additional (sub-) initialization files, which are loaded by default.el (but only if found in load-path):

  • Emacs customization file init-custom.el,
  • localization file init-locale.el (for German language),
  • default (fallback) theme file rho-theme.el,
  • site file init-site.el (loaded last).

In my Emacs setup the file ~/.emacs is only a simple stub, which ensures loading of default.el. It looks like that piece of code:

;; -*- mode: emacs-lisp; coding: utf-8-emacs -*-
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Emacs start-up file ~/.emacs
;; Copyright (C) 2020 Ralf Hoppe <ralf@dfcgen.de>
;;
;; NOTE: This file is only a simple stub, which sets the `load-path' and some
;; start-up variables.  I use default.el as the user's initialization file.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
(setq inhibit-splash-screen t
      inhibit-default-init nil) ; process default.el (anywhere in `load-path')
 
;; EMACSLOADPATH="$HOME/<path-to-default-el>:"
(push "~/<path-to-default-el>" load-path)

There are some (main) principles i follow in default.el:

  • use the Emacs server/client architecture to reduce start-up time;
  • open buffers, which are not associated with source code files, in another frame (e.g. Help, Completions, Grep, Tags/CScope);
  • try to give equal key bindings the same meaning in different major modes;
  • do not use project centric packages (like EDE, Semantic, …);
  • stay compatible with at least two Emacs releases on Linux and one at Win32;
  • the init file must also work on a text mode terminal (minor limitations are allowed).

For C/C++ software development i use the following features/modes (aside of CC Mode):

I also use some office-like packages, like calendar and diary, bbdb v3 (incl. bbdb-vcard and the cl-lib for Emacs23), message and gnus. But all that stuff is separated into my site file and so not presented here.

Last a screenshot of my (default) theme rho:

development/emacs/init.txt · Last modified: 2023/02/22 16:53 by Ralf H.