Saturday, January 18, 2014

Emacs configuration file

I’ve recently started using Emacs at work. I have used that at school earlier and then had to go to VI because none of the platforms that I worked on had enough space to support an Emacs editor. Emacs need some basic customisation before it can be used efficiently.

Here is a sample configuration file that I use. The comments provide explanation of the function of the various lines.



    ;;; Emacs Load Path
    (setq load-path (cons "~/emacs-config" load-path))
    ;;;(keyboard-translate ?\C-h ?\C-?)
    (global-set-key [(control h)] 'delete-backward-char)
    (global-set-key (kbd "C-^") 'help-command)
    (load "~/emacs-config/line-number")
    (load "~/emacs-config/whitespace-mode")
    (require 'whitespace)
    (setq whitespace-style '(face empty tabs lines-tail trailing))
    (global-whitespace-mode t)
    ;; Set emacs default C style to linux
    ;; Recommended https://www.kernel.org/doc/Documentation/CodingStyle
    (setq c-default-style "k&r")
    ;; Rationalize the undo operation in emacs
    (require 'redo+)
    (define-key global-map (kbd "C-q") 'undo)
    (define-key global-map (kbd "C-x C-q") 'redo)
    ;;; always print line numbers in the left margin
    (global-linum-mode t)
    ;;; Put backup files in a temp directory
    (setq backup-directory-alist
      `((".*" . ,temporary-file-directory)))
   (setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t)))
    (show-paren-mode 1)
    ;;; Use spaces instead of tabs
    (setq-default indent-tabs-mode nil)
    ;; save desktop
    (desktop-save-mode 1)
    ;; speedbar in the same frame
    (require 'sr-speedbar)
    (load "~/emacs-config/sr-speedbar")
    ;; open speedbar on startup
    (sr-speedbar-open)
    ;; Make speedbar list C functions
    (add-to-list 'speedbar-fetch-etags-parse-list
         '("\\.c" . speedbar-parse-c-or-c++tag))
    ;; windmove for easier switch between windows
    (when (fboundp 'windmove-default-keybindings)
     (windmove-default-keybindings))
    ;; emacs dev IDE
    (global-ede-mode 1)
    (require 'semantic/sb)
    (semantic-mode 1)
    ;;;; This snippet enables lua-mode
    ;; This line is not necessary, if lua-mode.el is already on your load-path
   (autoload 'lua-mode "lua-mode" "Lua editing mode." t)
   (add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
   (add-to-list 'interpreter-mode-alist '("lua" . lua-mode))
    ;; set tab width
    (setq default-tab-width 4)
    (setq tab-stop-list (number-sequence 4 200 4))
    ;; Goto a particular line
    (global-set-key "\C-xg" 'goto-line)
     (add-to-list 'load-path "~/emacs-config/anything-config")
    (require 'anything-config)
    (setq anything-sources
       (list anything-c-source-buffers
          anything-c-source-file-name-history
          anything-c-source-locate))
     (setq frame-title-format '("USER1"))
     ;;(setq frame-title-format (list "%b - " (getenv "USERNAME") "@" (getenv "USERDOMAIN")))
    ;; prevent checking for files changed on disk because vmplayer does not sync
    ;; http://stackoverflow.com/questions/2284703/emacs-how-to-disable-file-changed-on-disk-checking
    (defun ask-user-about-supersession-threat (fn)
      "blatantly ignore files that changed on disk"
      )
    (defun ask-user-about-lock (file opponent)
      "always grab lock"
      t)
 (global-set-key (kbd "<S-tab>") 'un-indent-by-removing-4-spaces)
 (defun un-indent-by-removing-4-spaces ()
  "remove 4 spaces from beginning of of line"
  (interactive)
  (save-excursion
   (save-match-data
    (beginning-of-line)
    ;; get rid of tabs at beginning of line
    (when (looking-at "^\\s-+")
     (untabify (match-beginning 0) (match-end 0)))
    (when (looking-at "^  ")
     (replace-match "")))))
 (custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
  '(column-number-mode t)
  '(show-paren-mode t)
  '(tool-bar-mode nil))
 (custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
  '(default ((t (:inherit nil :stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 98 :width normal :foundry "unknown" :family "DejaVu Sans Mono"))))

No comments:

Post a Comment