Saturday, November 7, 2009

Emacs Configuration .emacs file

Overview
The following is my .emacs file for reference.

.emacs Configuration
;; -*- lisp -*-
;;
;; (c)2009 StoKen Software by uuklanger@gmail.com
;;
;; 2009.11.13 - updated for emacs23
;; 2009.11.14 - added settings for font and height/width
;;
;; ============================================================================
;; Setup Keyboard
;; ============================================================================

(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key [delete] 'delete-char)
(global-set-key [C-home] 'beginning-of-buffer)
(global-set-key [C-end] 'end-of-buffer)

;; ============================================================================
;; Emacs customize section
;; ============================================================================

; Window Colors
(set-background-color "DarkSlateGray")
(set-foreground-color "Wheat")
(set-cursor-color "Orchid")
(set-mouse-color "Orchid")
(set-default-font "DejaVu Sans Mono-8")
(set-frame-height (selected-frame) 50)
(set-frame-width (selected-frame) 80)

; Turn off toolbar (toggle)
(tool-bar-mode)

; Display time
(display-time)

; Show column number
(column-number-mode t)

; Show line numbers
(line-number-mode t)

; FAQ 34: Highlight regions of text
(transient-mark-mode t)

; FAQ 66: font-lock-mode for all major modes
(global-font-lock-mode t)
(setq font-lock-maximum-decoration 't)

; FAQ 67: Only scroll one line when moving past screen
(setq scroll-step 1)
(setq scroll-conservatively 1)

; Dont show the GNU splash screen
(setq inhibit-startup-message t)

; Make all "yes or no" prompts show "y or n" instead
; (fset 'yes-or-no-p 'y-or-n-p)

;; Enable wheelmouse support by default
(cond (window-system
(mwheel-install)
))

; Ensure we stay in UNIX mode for EOL char
(setq inhibit-eol-conversion t)

; if we compile, ensure ouput scrolls
(setq compilation-scroll-output t)

;; ============================================================================
;; My preferred key bindings
;; ============================================================================

; Set C-g to goto-line
(global-set-key "\C-cg" 'goto-line)

;; ============================================================================
;; CC Mode setup
;; ============================================================================

(defun stroustrup-common-hook ()
(c-set-style "cc-mode")
(setq tab-width 4 indent-tabs-mode nil)
)
(add-hook 'c-mode-common-hook 'stroustrup-common-hook)

;; ============================================================================
;; Perl Mode setup
;; ============================================================================

(defun perl-common-hook ()
(setq tab-width 4 indent-tabs-mode nil)
(setq perl-indent-level 4
perl-font-lock t
perl-electric-lbrace-space nil
perl-electric-parens nil
perl-electric-linefeed t
perl-electric-keywords nil
perl-info-on-command-no-prompt t
perl-clobber-lisp-bindings t
perl-lazy-help-time 1)
)
(add-hook 'perl-mode-hook 'perl-common-hook)

;; ============================================================================
;; Other hooks
;; ============================================================================

; turn on auto fill mode when editing text files

(add-hook 'text-mode-hook 'turn-on-auto-fill)

;; ============================================================================
;; Runs Scripting Languages Program using compile key bindings
;;
;; if you have another lanugage, simply create a ____-run defun and add an if
;; statement to script-run()
;; ============================================================================

(defun python-run ()
"Use compile to run python programs"
(interactive)
(message "Running python for buffer %s." (buffer-name))
(compile (concat "python " (buffer-name)))
)
(defun perl-run ()
"Use compile to run perl programs"
(interactive)
(message "Running perl for buffer %s." (buffer-name))
(compile (concat "perl -w " (buffer-name)))
)
(defun script-run ()
"Use to run a script"
(interactive)
(if (equal (file-name-extension(buffer-name)) "py")
(python-run))
(if (equal (file-name-extension(buffer-name)) "pl")
(perl-run))
)
(global-set-key [f5] 'script-run)

;; ============================================================================
;; Printer settings
;; ============================================================================
;; ============================================================================
;; Fun stuff. Functions you can call up from the command line
;; ============================================================================

(defun ascii-table ()
"Print the ascii table. Based on a defun by Alex Schroeder
"
(interactive)
(switch-to-buffer "*ASCII*")
(erase-buffer)
(insert (format "ASCII characters up to number %d.\n" 254))
(let ((i 0))
(while (< i 254)
(setq i (+ i 1))
(insert (format "%4d 0x%02X %c\n" i i i))))
(beginning-of-buffer))
(defun insert-date ()
"Insert date at point."
(interactive)
(insert (format-time-string "%a %b %e, %Y %l:%M %p")))
;;; Convert DOS file format to Unix
;; look at
;; M-x comint-strip-ctrl-m
;; Command: Strip trailing `^M' characters from the current output group.
;; from: elf@ee.ryerson.ca (Luis Fernandes)
;; 22 May 1997
;;; Usage: M-x dos2unix
;;;
(defun dos2unix ()
"Convert this entire buffer from MS-DOS text file format to UNIX."
(interactive)
(save-excursion
(goto-char (point-min))
(replace-regexp "\r$" "" nil)
(goto-char (1- (point-max)))
(if (looking-at "\C-z")
(delete-char 1))))
;; ============================================================================
;; End of file
;; ============================================================================
Final Thoughts
If you use emacs, some of the settings above may help. I have gathered or created these settings and lisp code

No comments: