Department of Engineering

IT Services

Using the .emacs file

If you have an .emacs file in your HOME directory, this will be read when emacs starts up. This file contains Lisp calls. Here are some examples of things you can do

  • Make searches case-sensitive
    (setq-default case-fold-search nil)
  • Sets autofill on in text mode automatically.
    (setq text-mode-hook
          '(lambda() (auto-fill-mode 1)))
    or
      (setq text-mode-hook 'turn-on-auto-fill)
  • Set text rather than Lisp to be the default mode.

    (setq default-major-mode 'text-mode)
  • Arrange for the syntactic elements of C, fortran, pascal and LaTeX files to be displayed in different colors that display ok in a window with a light background (the CUED default is a dark background).

    (setq inhibit-default-init 1)
    (cond (window-system
           (setq hilit-mode-enable-list  '(not text-mode)
                 hilit-background-mode   'light
                 hilit-inhibit-hooks     nil
                 hilit-inhibit-rebinding nil)
           
           (require 'hilit19)
           ))
  • Disable coloring
    (setq inhibit-default-init 1)
  • Use matlab-mode for matlab files
    (setq ispell-highlight-face 'region)
    (global-set-key [f1] 'goto-line)  ;; goto line number
    (global-set-key [select] 'set-mark-command)  ;; set mark
    
    
    (autoload 'matlab-mode "matlab" "Enter Matlab mode." t)
    (setq auto-mode-alist (cons '("\\.m\\'" . matlab-mode) auto-mode-alist))
    (autoload 'matlab-shell "matlab" "Interactive Matlab mode." t)
    
    (setq auto-mode-alist
          (append
           '((".*\.p$" . fundamental-mode)
             (".*\.f$" . fundamental-mode))
           auto-mode-alist))
    (cond (window-system
    (global-font-lock-mode t)
    )
    )
    (setq inhibit-default-init 1)
    
  • Stop C-s freezing the screen when using emacs in a windowless environment
    (enable-flow-control)
  • Don't show the startup message
    (setq inhibit-startup-message t)
  • Set colors (as in ~/.Xdefaults).
    (set-border-color "lightblue")
    (set-border-color "blue")
    (set-cursor-color "red")
    (set-foreground-color "black")
    (set-mouse-color "red")
  • Display the time in the status line
    (load "time" t t)
    (display-time)
  • If you want to customise menus, look at the example files in the directory /usr/src/editors/emacs/site-lisp. Putting the following into your .emacs file will give you long menus by default
       (load "/usr/src/editors/emacs/site-lisp/.long_menus.el")
       (setq inhibit-default-init 1)