;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; ;;; Emacs Configuration File (-*- emacs-lisp -*-) ;;; ;;; ;;; ;;; Copyright (C) 2003-2007 Francesco Nidito ;;; ;;; Last updated(YYYY-MM-DD): 2007-12-07 ;;; ;;; ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;; ;;; General set-up ;;; ;;;;;;;;;;;;;;;;;;;;;; ;; To allign vars inside buffers (if (file-exists-p "/usr/share/emacs/22.1/lisp/align.elc") (require 'align)) ;; I don't want backup files to mess up my hard links' identity: (setq backup-by-copying t) (setq save-abbrevs nil) (setq backup-directory-alist (cons '("." . "~/emacs-backups") backup-directory-alist)) ;; I prefer to read man pages within the single Emacs frame I use, and not to ;; waste horizontal space: (setq woman-use-own-frame nil) (setq woman-fill-frame t) ;; Start GNUServe process when starting up. This lets us send new files ;; to previously spawned emacs process. (if (file-exists-p "/usr/share/emacs/site-lisp/gnuserv") (progn (add-to-list 'load-path "/usr/share/emacs/site-lisp/gnuserv") (load "gnuserv-compat") (load-library "gnuserv") (gnuserv-start))) ;; When loading files reuse existing frames. (setq gnuserv-frame (car (frame-list))) ;; Colorfull emacs (set-background-color "Black") (set-foreground-color "AntiqueWhite2") (set-cursor-color "Red") (setq woman-always-colour-faces t) (setq woman-fill-frame t) (global-font-lock-mode t) (setq font-lock-maximum-decoration t) (setq-default transient-mark-mode t) (show-paren-mode t) (setq scalable-fonts-allowed t) ;; These are damn useful (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) ;; I prefer no tabs: "Tabs are anachronistic" (and for wimps too) (setq-default indent-tabs-mode nil) ;; I like it large... I'm vicious (set-fill-column 80) ;; Mouse wheel mode (when window-system (progn (mouse-wheel-mode t) (scroll-bar-mode t) ; show the scroll bar ... (set-scroll-bar-mode 'right) ; ... on the right side )) ;; We dont't want a startup message (setq-default inhibit-startup-message t) ;; Paste at point NOT at cursor (setq mouse-yank-at-point 't) ;; Scrollbar (global-set-key [vertical-scroll-bar down-mouse-1] 'scroll-bar-drag) (delete-selection-mode t) ; delete the selection area with a keypress (setq scroll-step 1) ; scroll one line at a time ;; Just say no to toolbars (tool-bar-mode 0) ;; Show line/column numbers (line-number-mode 1) (column-number-mode 1) ;; Fonts... I like them small (set-default-font "-misc-fixed-medium-r-semicondensed--13-*-*-*-c-60-iso8859-1") ;; Load ispell (if (file-exists-p "/usr/share/emacs/site-lisp/dictionaries-common/ispell.el") (ispell-change-dictionary "american" t)) ;; Ignore extensions in completion (setq completion-ignored-extensions '(".o" ".lo" ".mh" ".elc" "~" ".bin" ".lbin" ".fasl" ".dvi" ".toc" ".aux" ".lof" ".blg" ".bbl" ".glo" ".idx" ".lot")) ;; Now, I feel better... (fset 'yes-or-no-p 'y-or-n-p) ;; Turn on auto-fill in `text-mode' and derived modes (mail, news, etc) (add-hook 'text-mode-hook 'turn-on-auto-fill) ;; I wanto to edit files also if they are in a galaxy far far away... (require 'tramp) (setq tramp-default-method "ssh") (tramp-set-completion-function "ssh" '((tramp-parse-sconfig "/etc/ssh_config") (tramp-parse-sconfig "~/.ssh/config"))) ;;;;;;;;;;;;; ;;; Modes ;;; ;;;;;;;;;;;;; ;; Where to find other modes (setq load-path (cons "~/emacs/lisp/" load-path)) ;; Set main c-mode (defun my-c-mode-common-hook () ;; use Ellemtel style for all C like languages (c-set-style "ellemtel") ) (add-hook 'c-mode-common-hook 'my-c-mode-common-hook) ;; scsh mode (add-to-list 'interpreter-mode-alist '("scsh" . scheme-mode)) ;; cperl (fset 'perl-mode 'cperl-mode) (add-hook 'cperl-mode-hook 'outline-minor-mode) (setq outline-minor-mode-prefix "\C-co") ;; Bind extension to mode (setq auto-mode-alist (append '(("\\.C$" . c++-mode) ("\\.cc$" . c++-mode) ("\\.cpp$" . c++-mode) ("\\.cxx$" . c++-mode) ("\\.hxx$" . c++-mode) ("\\.hpp$" . c++-mode) ("\\.h$" . c++-mode) ("\\.hh$" . c++-mode) ("\\.idl$" . c++-mode) ("\\.ipp$" . c++-mode) ("\\.c$" . c-mode) ("\\.pl$" . perl-mode) ("\\.pm$" . perl-mode) ("\\.java$" . java-mode) ("\\.txt$" . text-mode) ("\\.scsh$" . scheme-mode)) auto-mode-alist)) ;;;;;;;;;;;;;; ;;; AucTeX ;;; ;;;;;;;;;;;;;; ;; If you fing it, you load it... (if (file-exists-p "/usr/share/emacs/site-lisp/auctex") (progn (require 'tex-site) (setq TeX-auto-save t) (setq TeX-parse-self t) (setq-default TeX-master nil) (add-to-list 'load-path "/usr/share/emacs/22.1/lisp/textmodes/") (add-hook 'LaTeX-mode-hook 'turn-on-reftex))) ;;;;;;;;;;;;;;;;; ;;; Functions ;;; ;;;;;;;;;;;;;;;;; ;; This function will format the whole file for you (defun indent-whole-buffer () (interactive) (indent-region (point-min) (point-max) nil)) ;; Dosify a path /foo/bar -> \foo\bar (defun dosify () (interactive) (let (end) (end-of-line) (setq end (point)) (beginning-of-line) (replace-string "/" "\\") (comint-send-input))) ;; Unixify a path \foo\bar -> /foo/bar (defun unixify () (interactive) (let (end) (end-of-line) (setq end (point)) (beginning-of-line) (replace-string "\\" "/") (comint-send-input))) ;; Aligns all variable declarations in this buffer (defun align-vars-buffer() "Aligns c/c++ variable declaration names on the same column in this buffer." (interactive) (save-excursion (let (beg end) (beginning-of-buffer) (setq beg (point)) (end-of-buffer) (setq end (point)) (align-vars beg end)))) ;; Tabs to space (defun untabify-buffer () "Untabify the whole (accessible part of the) current buffer" (interactive) (save-excursion (untabify (point-min) (point-max)))) ;; Word count (defun count-words-buffer () "Count the number of words in the current buffer; print a message in the minibuffer with the result." (interactive) (save-excursion (let ((count 0)) (goto-char (point-min)) (while (< (point) (point-max)) (forward-word 1) (setq count (1+ count))) (message "buffer contains %d words." count)))) ;; Buffers navigation (defun yic-ignore (str) (or ;;buffers I don't want to switch to (string-match "\\*Buffer List\\*" str) (string-match "^TAGS" str) (string-match "^\\*Messages\\*$" str) (string-match "^\\*Completions\\*$" str) (string-match "^\\*scratch\\*$" str) (string-match "^\\*ESS\\*$" str) (string-match "^ " str) (string-match "Mew message" str) (string-match "output\\*$" str) (string-match "compilation" str) (string-match "^\\*TeX silent\\*$" str) (string-match "+inbox" str) )) (defun yic-next (ls) "Switch to next buffer in ls skipping unwanted ones." (let* ((ptr ls) bf bn go ) (while (and ptr (null go)) (setq bf (car ptr) bn (buffer-name bf)) (if (null (yic-ignore bn)) (setq go bf) (setq ptr (cdr ptr)) ) ) (if go (switch-to-buffer go)))) (defun yic-prev-buffer () "Switch to previous buffer in current window." (interactive) (yic-next (reverse (buffer-list)))) (defun yic-next-buffer () "Switch to the other buffer (2nd in list-buffer) in current window." (interactive) (bury-buffer (current-buffer)) (yic-next (buffer-list))) ;; Kill all the damn '\r' chars... (defun dos2unix () "Convert a buffer from dos ^M end of lines to unix end of lines" (interactive) (goto-char (point-min)) (while (search-forward "\r" nil t) (replace-match ""))) ;; no... wait... I like them! (defun unix2dos () "Opposite of dos2unix" (interactive) (goto-char (point-min)) (while (search-forward "\n" nil t) (replace-match "\r\n"))) ;; Truncate lines (defun toggle-truncate-lines () "toggle the variable truncate-lines between true and false" (interactive) (if (eq truncate-lines 't) (set-variable 'truncate-lines nil) (set-variable 'truncate-lines 't))) ;;;;;;;;;;;;;;;;;;;; ;;; key-bindings ;;; ;;;;;;;;;;;;;;;;;;;; (global-set-key [f1] 'manual-entry) (global-set-key [f2] 'count-words-buffer) (global-set-key [f3] 'font-lock-fontify-buffer) ;f3 for rehiliting (global-set-key [f4] 'compile) (global-set-key [f5] 'switch-to-buffer) (global-set-key [f7] 'yic-next-buffer) (global-set-key [f8] 'yic-prev-buffer) (global-set-key [f9] 'ispell-buffer) (global-set-key [f10] 'toggle-truncate-lines) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; FIXME and TODO mode (c and c++) ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (mapcar (lambda (mode) (font-lock-add-keywords mode '(("\\<\\(FIXME\\|TODO\\):" 1 font-lock-warning-face t)))) '(c-mode c++mode)) ;;;;;;;;;;;;;; ;;; OpenGL ;;; ;;;;;;;;;;;;;; (mapcar (lambda (mode) (progn ;; gl.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-function-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))) ;; glu.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-function-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))) ;; glx.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-function-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))) ;; glut.h (font-lock-add-keywords mode '(("\\" . 'font-lock-type-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-function-name-face))) (font-lock-add-keywords mode '(("\\" . 'font-lock-constant-face))))) '(c-mode c++mode)) ;;; That's all folks!!