Skip to content

Miscellaneous Settings for a .emacs File

Here are a few miscellaneous settings:

  • Set the shape and color of the mouse cursor:

    emacs-lisp
    ; Cursor shapes are defined in
    ; '/usr/include/X11/cursorfont.h';
    ; for example, the 'target' cursor is number 128;
    ; the 'top_left_arrow' cursor is number 132.
    emacs-lisp
    (let ((mpointer (x-get-resource "*mpointer"
                                    "*emacs*mpointer")))
      ;; If you have not set your mouse pointer
      ;;     then set it, otherwise leave as is:
      (if (eq mpointer nil)
          (setq mpointer "132")) ; top_left_arrow
    emacs-lisp
      (setq x-pointer-shape (string-to-number mpointer))
      (set-mouse-color "white"))
  • Or you can set the values of a variety of features in an alist, like this:

    emacs-lisp
    (setq-default
     default-frame-alist
     '((cursor-color . "white")
       (mouse-color . "white")
       (foreground-color . "white")
       (background-color . "DodgerBlue4")
       ;; (cursor-type . bar)
       (cursor-type . box)
    emacs-lisp
       (tool-bar-lines . 0)
       (menu-bar-lines . 1)
       (width . 80)
       (height . 58)
       (font .
             "-Misc-Fixed-Medium-R-Normal--20-200-75-75-C-100-ISO8859-1")
       ))
  • Convert CTRL-h into DEL and DEL into CTRL-h.
    (Some older keyboards needed this, although I have not seen the problem recently.)

    emacs-lisp
    ;; Translate 'C-h' to <DEL>.
    ; (keyboard-translate ?\C-h ?\C-?)
    
    ;; Translate <DEL> to 'C-h'.
    (keyboard-translate ?\C-? ?\C-h)
  • Turn off a blinking cursor!

    emacs-lisp
    (if (fboundp 'blink-cursor-mode)
        (blink-cursor-mode -1))

    or start GNU Emacs with the command emacs -nbc.

  • When using grep
    -i

    Ignore case distinctions
    -n

    Prefix each line of output with line number
    -H

    Print the filename for each match.
    -e

    Protect patterns beginning with a hyphen character, ‘-

    emacs-lisp
    (setq grep-command "grep -i -nH -e ")
  • Find an existing buffer, even if it has a different name
    This avoids problems with symbolic links.

    emacs-lisp
    (setq find-file-existing-other-name t)
  • Set your language environment and default input method

    emacs-lisp
    (set-language-environment "latin-1")
    ;; Remember you can enable or disable multilingual text input
    ;; with the toggle-input-method' (C-\) command
    (setq default-input-method "latin-1-prefix")

    If you want to write with Chinese GB characters, set this instead:

    emacs-lisp
    (set-language-environment "Chinese-GB")
    (setq default-input-method "chinese-tonepy")

Fixing Unpleasant Key Bindings

Some systems bind keys unpleasantly. Sometimes, for example, the CTRL key appears in an awkward spot rather than at the far left of the home row.

Usually, when people fix these sorts of key bindings, they do not change their ~/.emacs file. Instead, they bind the proper keys on their consoles with the loadkeys or install-keymap commands in their boot script and then include xmodmap commands in their .xinitrc or .Xsession file for X Windows.

For a boot script:

bash
loadkeys /usr/share/keymaps/i386/qwerty/emacs2.kmap.gz
or
install-keymap emacs2

For a .xinitrc or .Xsession file when the Caps Lock key is at the far left of the home row:

bash
# Bind the key labeled 'Caps Lock' to 'Control'
# (Such a broken user interface suggests that keyboard manufacturers
# think that computers are typewriters from 1885.)

xmodmap -e "clear Lock"
xmodmap -e "add Control = Caps_Lock"

In a .xinitrc or .Xsession file, to convert an ALT key to a META key:

bash
# Some ill designed keyboards have a key labeled ALT and no Meta
xmodmap -e "keysym Alt_L = Meta_L Alt_L"