;; -*-lisp-*- make emacs load this file in lisp mode ;; .emacs file by Simon Nielsen ;; ;; $Id: dot-emacs,v 1.24 2004/12/26 23:48:47 simon Exp $ ;; This file is originally based on a .emacs file from DIKU ;; Add local emacs dir to load path ;; Note that we prefer our own emacs directory over the system directory (setq load-path (append (list "~/emacs/") load-path)) ;; Default vars to be overriden in emacs.local (defvar have-psgml nil) (defvar have-python-mode nil) (defvar have-send-pr nil) (defvar have-sml-mode nil) (defvar have-tex-mode nil) (defvar have-xsl-mode nil) (defvar use-old-psgml nil) (if (file-readable-p (expand-file-name "~/.emacs.local")) (load-file (expand-file-name "~/.emacs.local")) nil) ;; Goto line ;; Please note, that this will override the function ;; ``facemenu-keymap'' normally used to change fonts. ;; M-g runs `M-x goto-line' (global-set-key "\M-g" 'goto-line) ;; Make the `Delete' key work like C-d, that is, delete the char under ;; the cursor (global-set-key [delete] 'delete-char) ; Unsetting keybindings which makes me iconify frames by mistake. (global-unset-key [(control z)]) (global-unset-key [(control x) (control z)]) ;; Turn on column numbering in status line (column-number-mode t) ;; Make marked block visible (transient-mark-mode t) ;; When using X Windows, you can request a more powerful alternative kind ;; of automatic parenthesis matching by enabling Show Paren mode. This ;; mode turns off the usual kind of matching parenthesis display and ;; instead uses highlighting to show what matches. Whenever point is ;; after a close parenthesis, the close parenthesis and its matching open ;; parenthesis are both highlighted; otherwise, if point is before an ;; open parenthesis, the matching close parenthesis is ;; highlighted. (There is no need to highlight the open parenthesis after ;; point because the cursor appears on top of that character.) Use the ;; command M-x show-paren-mode to enable or disable this mode. (show-paren-mode t) ;; Font Lock mode is a minor mode, always local to a particular buffer, ;; which highlights (or "fontifies") using various faces according to the ;; syntax of the text you are editing. It can recognize comments and ;; strings in most languages; in several languages, it can also recognize ;; and properly highlight various other important constructs--for ;; example, names of functions being defined or reserved keywords. (global-font-lock-mode t) ;; Visible bell is a mode, which will usual signal the bell by some ;; black stuff in the top and bottum of the emacs window (setq visible-bell t) ;; Stop "down"-arrow from adding CR to end of file (setq next-line-add-newlines nil) ;; Use spaces instead of tabs ;(setq-default indent-tabs-mode t) ;; Show trailing whitespace (setq-default show-trailing-whitespace t) ;; Don't show the gnu splash screen (setq inhibit-startup-message t) ;; Make all "yes or no" prompts "y-or-n" (fset 'yes-or-no-p 'y-or-n-p) ;; Misc customize commands (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. '(diff-switches "-u") '(sh-indent-comment t) '(sh-indent-for-case-alt (quote +)) '(sh-indent-for-case-label 0) '(tool-bar-mode nil nil (tool-bar))) ;; Set window title (setq frame-title-format (concat invocation-name "@" system-name " - %b") ) ;; Syntax higlightning (require 'font-lock) global-font-lock-mode ;; Ident with 4 chars in cperl (setq-default cperl-indent-level 4) ;; Display european characters in text-mode ; Emacs 21 ; (standard-display-european t) ; Emacs 22 (set-language-environment 'Latin-1) (set-input-mode (car (current-input-mode)) (nth 1 (current-input-mode)) 0) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Keys ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; F10 reload .emacs (global-set-key [f10] 'regogol) ;; Shift F10 Open .emacs in buffer (global-set-key [(shift f10)] 'open-dot-emacs) ;; F9 ;(global-set-key [f9] 'use-tab-tab) ;; Shift F9 ;(global-set-key [(shift f9)] 'use-tab-space) ;; Turn on autofill (linewrap) in (La)Tex modes (add-hook 'tex-mode-hook 'turn-on-auto-fill) (add-hook 'latex-mode-hook 'turn-on-auto-fill) ;; Makes home/end go to beginning/end of line instead of top/bottom of buffer (define-key global-map [home] 'beginning-of-line) (define-key global-map [end] 'end-of-line) ;; Makes control + home/end go to beginning/end of buffer (define-key global-map [C-home] 'beginning-of-buffer) (define-key global-map [C-end] 'end-of-buffer) ;; Makes shift+up/down arrow keys scroll one line at the time (define-key global-map [S-up] 'scroll-down-1) (define-key global-map [S-down] 'scroll-up-1) ;; Make control+pageup/down scroll the other buffer ;; (when you have two buffers open in the same frame) (global-set-key [(control next)] 'scroll-other-window) (global-set-key [(control prior)] 'scroll-other-window-down) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Misc modes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Recentf ;(require 'recentf) ;(recentf-mode 1) ;; SNMP mode (setq auto-mode-alist (append '(("\\.asn$" . snmp-mode) ("\\.mib$" . snmp-mode) ("\\.smi$" . snmp-mode) ("\\.as2$" . snmpv2-mode) ("\\.mi2$" . snmpv2-mode) ("\\.sm2$" . snmpv2-mode) ("-MIB\\.txt$" . snmpv2-mode) ) auto-mode-alist)) (autoload 'snmp-mode "snmp-mode" "Mode for editing SNMP MIBs" t) (autoload 'snmpv2-mode "snmp-mode" "Mode for editing SNMPv2 MIBs" t) ;; CTypes (add-hook 'c-mode-hook 'ctype-c-mode-hook) (add-hook 'c++-mode-hook 'ctype-c-mode-hook) (defun ctype-c-mode-hook () (require 'ctypes) (turn-on-font-lock) (setq ctypes-write-types-at-exit t) (ctypes-read-file nil nil t t) (ctypes-auto-parse-mode 1) ) ;; Make rc.* files default to shell-script-mode (setq auto-mode-alist (append '(("rc\\." . shell-script-mode)) '(("make.conf" . makefile-mode)) auto-mode-alist)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Various functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Convert DOS cr-lf to UNIX newline (defun dos-unix () (interactive) (goto-char (point-min)) (while (search-forward "\r" nil t) (replace-match ""))) ;; Convert UNIX newline to DOS cr-lf (defun unix-dos () (interactive) (goto-char (point-min)) (while (search-forward "\n" nil t) (replace-match "\r\n"))) ;; For shift arrow keys for scrolling (defun scroll-up-1 () (interactive) (scroll-up 1)) (defun scroll-down-1 () (interactive) (scroll-down 1)) ;; Reload .emacs (defun regogol () "reload ~/.emacs" (interactive) (load-file (expand-file-name "~/.emacs")) ) ;; Open the .emacs file (defun open-dot-emacs () "opening-dot-emacs" (interactive) ;this makes the function a command too (find-file "~/.emacs") ) (defun use-tab-tab () (interactive) (setq indent-tabs-mode t) ) (defun use-tab-space () (interactive) (setq indent-tabs-mode nil) ) ;(fset 'comment ; "\C-n\C-a#") (global-font-lock-mode t) (require 'php-mode) ;; Perforce ;(load-library "p4") ;; Doxygen (require 'doxygen) ;; Ruby (require 'ruby-mode) (setq auto-mode-alist (append '(("\\.rb$" . ruby-mode) ) auto-mode-alist)) ;; Subversion (require 'psvn) (add-to-list 'vc-handled-backends 'SVN) ;; Basis utils (autoload 'simon-insert-std-copyright-c "simon-basis-utils" "Insert the standard copyright - c style." t) (autoload 'simon-insert-std-copyright-sh "simon-basis-utils" "Insert the standard copyright - sh style." t) (autoload 'simon-insert-std-copyright-man "simon-basis-utils" "Insert the standard copyright - man style." t) ;; CSS (autoload 'css-mode "css-mode") (setq auto-mode-alist (cons '("\\.css\\'" . css-mode) auto-mode-alist)) ;; VC ; hg-vc will need emacs 22.1 ; (require 'vc-hg) ; (add-to-list 'vc-handled-backends 'hg) (setq vc-dired-terse-display nil) ;; Make Emacs make better names when you have more files with the same name open (require 'uniquify) (setq uniquify-buffer-name-style 'post-forward) ;; Default .h files to C++ ;(setq auto-mode-alist ; (append (list '("\\.h\\'" . c++-mode)) ; auto-mode-alist)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Some VI like stuff ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Make the % key jump to the matching {}[]() if on another, like VI (global-set-key "%" 'match-paren) (defun match-paren (arg) "Go to the matching parenthesis if on parenthesis otherwise insert %." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1))))) ;; This allows you to keep a tags stack and push and pop your way ;; around the source code. This feature is present in both XEmacs and ;; VI. Pop tag is mapped to M-*. (global-set-key (read-kbd-macro "M-*") 'tags-return) (defvar tags-stack nil) (defun tags-stack-push (el) (setq tags-stack (cons el tags-stack))) (defun tags-stack-pop () (let ((el (car tags-stack))) (setq tags-stack (cdr tags-stack)) el)) (defadvice find-tag (before push-tag activate) (or (ad-get-arg 1) (tags-stack-push (cons (current-buffer) (point))))) (defadvice tags-search (before push-tag activate) (tags-stack-push (cons (current-buffer) (point)))) (defun tags-return () (interactive) (let* ((el (tags-stack-pop)) (buffer (car el)) (point (cdr el))) (if buffer (switch-to-buffer buffer)) (if point (goto-char point)))) ;; http://docs.freebsd.org/cgi/getmsg.cgi?fetch=26277+0+archive/2001/freebsd-standards/20011230.freebsd-standards (defun bsd-c-mode-user-setup () "Hacks" (interactive) (c-set-style "bsd") (setq c-basic-offset 8 c-conditional-key c-C++-conditional-key indent-tabs-mode t c-tab-always-indent nil) (setq c-cleanup-list (append c-cleanup-list (list 'brace-else-brace))) (c-set-offset 'arglist-close 0) (c-set-offset 'arglist-cont-nonempty 4) (c-set-offset 'inline-open 0) (c-set-offset 'case-label 0) (c-set-offset 'statement-cont 4)) ;(c-toggle-auto-state 1) (defun sysinstall-c-mode-user-setup () "Hacks" (interactive) (c-set-style "bsd") (setq c-basic-offset 4) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Load optional modules ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Psgml (cond ((equal have-psgml t) (setq-default sgml-auto-activate-dtd t) (setq-default sgml-set-face t) (setq-default sgml-indent-data t) (setq-default sgml-omittag nil) (setq-default sgml-always-quote-attributes: t) (require 'psgml-startup) ;; Find catalogs (setq sgml-local-catalogs nil) (if (file-readable-p "/usr/local/share/sgml/docbook/catalog") (setq sgml-local-catalogs (append '("/usr/local/share/sgml/docbook/catalog") sgml-local-catalogs)) nil) ;;(if (file-readable-p "/FreeBSD/doc/share/sgml/catalog") ;; (setq sgml-local-catalogs (append '("/FreeBSD/doc/share/sgml/catalog") ;; sgml-local-catalogs)) ;; nil) ;;(if (file-readable-p "/FreeBSD/doc/en_US.ISO8859-1/share/sgml/catalog") ;; (setq sgml-local-catalogs (append '("/FreeBSD/doc/en_US.ISO8859-1/share/sgml/catalog") ;; sgml-local-catalogs)) ;; nil) (if (file-readable-p "/usr/local/share/sgml/html/catalog") (setq sgml-local-catalogs (append '("/usr/local/share/sgml/html/catalog") sgml-local-catalogs)) nil) ;;(if (file-readable-p "/FreeBSD/CURRENT/release/doc/share/sgml/catalog") ;; (setq sgml-local-catalogs (append '("/FreeBSD/CURRENT/release/doc/share/sgml/catalog") ;; sgml-local-catalogs)) ;;nil) (if (file-readable-p "/usr/local/share/xml/dtd/vuxml/catalog") (setq sgml-local-catalogs (append '("/usr/local/share/xml/dtd/vuxml/catalog") sgml-local-catalogs)) nil) (if (file-readable-p "/usr/local/share/xml/dtd/xhtml-basic/xhtml-basic10.cat") (setq sgml-local-catalogs (append '("/usr/local/share/xml/dtd/xhtml-basic/xhtml-basic10.cat") sgml-local-catalogs)) nil) (if (file-readable-p "/usr/local/share/xml/dtd/xhtml-modularization/xhtml.cat") (setq sgml-local-catalogs (append '("/usr/local/share/xml/dtd/xhtml-modularization/xhtml.cat") sgml-local-catalogs)) nil) ; (if (file-readable-p "/usr/local/share/xml/xhtml/1.1/xhtml11.cat") ; (setq sgml-local-catalogs (append '("/usr/local/share/xml/xhtml/1.1/xhtml11.cat") ; sgml-local-catalogs)) ; nil) (setq auto-mode-alist (append (list '("\\.page" . xml-mode)) auto-mode-alist)) ) (t nil)) ;; Show whitespace mode (require 'show-whitespace-mode) ;; Python mode (cond ((equal have-python-mode t) (require 'python-mode) ) (t nil)) ;; SML mode (cond ((equal have-sml-mode t) (require 'sml-site) ) (t nil)) ;; Tex mode (cond ((equal have-tex-mode t) (require 'tex-site) ) (t nil)) ;; send-pr (cond ((equal have-send-pr t) (require 'send-pr) ) (t nil)) ;; XSL mode (cond ((equal have-xsl-mode t) (autoload 'xsl-mode "xslide" "Major mode for XSL stylesheets." t) ;; Turn on font lock when in XSL mode (add-hook 'xsl-mode-hook 'turn-on-font-lock) (setq auto-mode-alist (append (list '("\\.fo" . xsl-mode) '("\\.xsl" . xsl-mode)) auto-mode-alist)) ) ;; Uncomment if using abbreviations ;; (abbrev-mode t) (t nil)) ; Matlab ;(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) ;; Temp test (defface extra-whitespace-face '((t (:background "dark olive green"))) "Used for tabs and such.") (defvar my-extra-keywords '(("\t" . 'extra-whitespace-face))) (add-hook 'text-mode-hook (lambda () (font-lock-add-keywords nil my-extra-keywords))) (add-hook 'sgml-mode-hook (lambda () (font-lock-add-keywords nil my-extra-keywords))) ;; Colors ;; Need to be last to work right. (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. '(diff-added-face ((t (:inherit diff-changed-face :foreground "DeepSkyBlue")))) '(diff-removed-face ((t (:inherit diff-changed-face :foreground "Chocolate1")))) '(p4-depot-added-face ((t (:foreground "DeepSkyBlue")))) '(p4-depot-deleted-face ((t (:foreground "Chocolate1")))) '(p4-depot-unmapped-face ((t (:background "black" :foreground "grey")))) '(p4-diff-del-face ((t (:inherit diff-removed-face)))) '(p4-diff-file-face ((t (:inherit diff-file-header-face)))) '(p4-diff-head-face ((t (:inherit diff-hunk-header-face)))) '(p4-diff-ins-face ((t (:inherit diff-added-face)))) '(sgml-comment-face ((t (:foreground "chocolate1"))) t) '(sgml-doctype-face ((t (:foreground "Cyan"))) t) '(sgml-end-tag-face ((t (:foreground "DeepSkyBlue"))) t) '(sgml-entity-face ((t (:foreground "LightGoldenrod"))) t) '(sgml-pi-face ((t (:background "lightblue" :foreground "maroon"))) t) '(sgml-start-tag-face ((t (:foreground "DeepSkyBlue"))) t))