;;; $Id: .emacs.el,v 1.11 2008/05/18 06:53:39 minh Exp minh $ ;;; Copyright (c) 2006-2008 Nhat Minh Lê ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; 1. Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; 2. Redistributions in binary form must reproduce the above ;;; copyright notice, this list of conditions and the following ;;; disclaimer in the documentation and/or other materials provided ;;; with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; Minh's .emacs ;; TODO: ;; - Work on a DWIM path handler. (most useful) ;; - Integrate the settings in ".emacs-custom.el" into a theme. ;; - Correct a bug in the desktop buffer that makes it display an ;; incorrect layout (the one we switched from) when launched for ;; the first time. ;; - Work on the desktop mode. (Clean up with text properties and ;; read-only buffer.) (low priority) ;; - Correct the buffer group preset to ignore ;; non-commands. (Aborted: mgroup.el not currently in use.) ;; - Work on window configuration stacks. (Obseleted? by ratpoison.) ;; ;; Environment (add-to-list 'load-path "~/lisp") (load "/usr/share/emacs/site-lisp/site-gentoo") ;;(require 'site-gentoo) (setq custom-file (cond ((not (version< emacs-version "23")) "~/.emacs-custom-23.el") ((null window-system) "~/.emacs-custom-tty.el") (t "~/.emacs-custom-x.el"))) (load custom-file) (require 'uptimes nil t) (setq gc-cons-threshold 2000000) (set-language-environment "UTF-8") (load "~/.emacs-auth.el") (setq ring-bell-function 'ignore) (setq message-log-max 200) (ispell-change-dictionary "francais" t) (global-font-lock-mode t) ;;(setq font-lock-maximum-decoration '((c-mode . 1) (t . 2))) (setq font-lock-maximum-decoration 2) (auto-compression-mode t) (setq make-backup-files nil) (require 'uniquify) (setq uniquify-buffer-name-style 'forward) (setq speedbar-show-unknown-files t) (require 'minh-xkeys) (if (null window-system) (minh-setup-xterm-keys) (minh-setup-x-control-keys)) (blink-cursor-mode nil) ;; used by the .ratpoisonrc (global-unset-key [?\C-z]) (global-unset-key [?\C-/]) ;; ;; Window management (require 'minh-ws) (when (null window-system) (minh-setup-tty-ws)) (minh-setup-x-ws) (setq frame-inherited-parameters '(font background-color foreground-color)) (when (eq window-system 'x) (setq initial-frame-alist '((name . "main"))) (setq default-minibuffer-frame (selected-frame)) (make-frame '((name . "aux")))) (global-set-key [(control tab)] 'other-window) (global-set-key [?\C-c ?v] 'view-file) (global-set-key [?\C-c ?o] 'bury-buffer) (global-set-key [?\C-c ?k] 'kill-this-buffer) (iswitchb-mode t) (setq iswitchb-use-frame-buffer-list t) (setq iswitchb-max-to-show 20) ;; (require 'mgroup) ;; (mgroup-minor-mode t) ;; ;; Basic editing (require 'paren) (require 'misc) (defun just-no-space () "Delete every whitespaces around point, leaving no blanks at all." (interactive) (save-excursion (if (re-search-backward "[^ \t\r\n\f]" nil t) (goto-char (1+ (point)))) (re-search-forward "[ \t\r\n\f]*") (delete-region (match-beginning 0) (match-end 0)))) (defun minh-kill-surrounding-parens () "Delete the pair of matching characters around the sexp after point." (interactive) (down-list) (backward-char) (let ((pt (point)) npt) (forward-sexp) (backward-delete-char 1) (goto-char pt) (delete-char 1))) (setq enable-recursive-minibuffers t) (show-paren-mode t) (setq-default show-trailing-whitespace t) (setq set-mark-command-repeat-pop t) ;;(setq-default fill-column 60) (setq fill-individual-varying-indent t) (setq fill-nobreak-predicate '(fill-french-nobreak-p)) (put 'erase-buffer 'disabled nil) (put 'narrow-to-region 'disabled nil) (global-set-key (kbd "C-M-l") 'minh-kill-surrounding-parens) (global-set-key [?\C-c ?z] 'just-no-space) (global-set-key [?\M-z] 'zap-to-char) (global-set-key [?\C-\M-z] 'zap-up-to-char) (global-set-key [?\C-c ?x ?d] 'delete-region) (global-set-key [?\C-c ?r] 'search-backward-regexp) (global-set-key [?\C-c ?s] 'search-forward-regexp) (global-set-key [?\C-c ?h] 'replace-string) (global-set-key [?\C-c ?j] 'replace-regexp) (global-set-key [?\C-c ?l] 'delete-indentation) (global-set-key [?\C-c ?x ?\;] 'comment-region) (global-set-key [?\C-c ?x ?d] 'delete-region) (add-hook 'text-mode-hook (lambda () (setq indent-tabs-mode nil))) ;; ;; Programming (setq standard-indent 8) (setq skeleton-pair t) (global-set-key "\"" 'skeleton-pair-insert-maybe) (global-set-key (kbd "«") 'skeleton-pair-insert-maybe) (global-set-key "(" 'skeleton-pair-insert-maybe) (global-set-key "[" 'skeleton-pair-insert-maybe) (global-set-key "{" 'skeleton-pair-insert-maybe) (defun minh-hungry-delete-forward (n) "Delete all whitespace up to the next non-whitespace character." (interactive "P") (save-excursion (if (or n (not (memq (char-after) '(?\ ?\t ?\r ?\n ?\f)))) (delete-char (if n n 1)) (let ((pt (point))) (skip-chars-forward " \t\r\n\f") (delete-region pt (point)))))) (defun minh-hungry-delete-backward (n) "Delete all whitespace back to the previous non-whitespace character." (interactive "P") (save-excursion (if (or n (not (memq (char-before) '(?\ ?\t ?\r ?\n ?\f)))) (backward-delete-char (if n n 1)) (let ((pt (point))) (skip-chars-backward " \t\r\n\f") (delete-region (point) pt))))) (global-set-key [remap backward-delete-char-untabify] 'minh-hungry-delete-backward) (global-set-key [remap backward-delete-char] 'minh-hungry-delete-backward) (global-set-key [remap delete-backward-char] 'minh-hungry-delete-backward) (global-set-key [remap delete-char] 'minh-hungry-delete-forward) (setq tab-width 8) (setq c-default-style "k&r" c-block-comment-prefix "" c-basic-offset 8) (setq-default c-offsets-alist '((substatement-label . 0) (label . 0) (statement-cont . +) (statement-case-open . +))) (defconst minhdoc-font-lock-keywords `((,(lambda (limit) (c-font-lock-doc-comments "/\\*\\*" limit nil))))) (setq-default c-doc-comment-style 'minhdoc) (add-hook 'c-mode-hook (lambda () (c-toggle-hungry-state) (define-key c-mode-map "'" 'skeleton-pair-insert-maybe))) (setq compilation-window-height 10) (global-set-key [?\C-c ?m] 'compile) (defun minh-search-forward-defun (name) "Searches forward for a function definition. The heuristic is to find a line containing NAME that does not begin with a blank or a hash character, that is, not a code or preprocessor line." (interactive "sFunction name: ") (let ((pos (point))) (if (re-search-forward (concat "^\\(?:[^# \t\r\n\f].*\\)?" name) nil t) (push-mark pos) (error (concat "Function not found: " name))))) (global-set-key (kbd "C-c f") 'minh-search-forward-defun) (setq sh-basic-offset 8) (setq sh-indent-for-case-label 0) (setq sh-indent-for-case-alt '+) (setq sh-indent-for-continuation 4) ;; ;; Typesetting (setq LaTeX-verbatim-regexp "[vV]erbatim\\*?") (setq font-latex-verbatim-environments '("verbatim" "verbatim*" "Verbatim")) (add-hook 'LaTeX-math-mode-hook (lambda () (define-key LaTeX-math-mode-map "@" LaTeX-math-keymap) (define-key LaTeX-math-keymap "@" 'self-insert-command))) (add-hook 'metapost-mode-hook (lambda () (define-key meta-mode-map [?\C-m] 'newline))) ;; ;; Algebra ;; XXX: experimental (setq load-path (cons "/usr/share/maxima/5.9.1/emacs" load-path)) (autoload 'maxima-mode "maxima" "Maxima mode" t) (autoload 'maxima "maxima" "Maxima interactive" t) (setq auto-mode-alist (cons '("\\.max" . maxima-mode) auto-mode-alist)) (autoload 'emaxima-mode "emaxima" "EMaxima" t) (add-hook 'emaxima-mode-hook 'emaxima-mark-file-as-emaxima) ;; ;; Mail (load "~/.emacs-mail") ;; ;; File browsing ;; long options must come first, else it will bug (setq dired-listing-switches "--time-style=iso -lhDF") (setq dired-ls-F-marks-symlinks t) ;; ;; Chat (load "~/.emacs-chat") ;;; WWW ;;(setq browse-url-mozilla-program "seamonkey") ;;(global-set-key [?\C-c ?g] 'browse-url-mozilla) (global-set-key [?\C-c ?g] 'browse-url-firefox) (when (version< emacs-version "23") (add-hook 'w3m-mode-hook (function (lambda () (require 'w3m-type-ahead) (w3m-type-ahead-mode) (define-key w3m-mode-map [?\C-x ?b] nil)))) (setq w3m-use-cookies t) (setq w3m-terminal-coding-system 'utf-8) (setq w3m-use-tab nil)) ;; (setq w3m-make-new-session t) ;; Code below is unusable because 'w3m-popup-window-p' is really a ;; macro. ;; (defadvice w3m-popup-window-p (after always-popup) ;; "We always want to pop even though we are usin tabs." ;; (setq ad-return-value t)) ;; (add-hook 'w3m-mode-hook ;; (function (lambda () (ad-activate 'w3m-popup-window-p)))) ;; (setq browse-url-browser-function 'w3m) ;;; Multimedia: (when (require 'emms-setup nil t) (emms-standard) (emms-default-players) (global-set-key [?\C-c ?a ?f] 'emms-play-file) (global-set-key [?\C-c ?a ?z] 'emms-stop) (global-set-key [?\C-c ?a ?r] 'emms-start) (global-set-key [?\C-c ?a ?s] 'emms-show) (defun minh-emms-play-file-at-point () "Plays the current file in Dired listing." (interactive) (emms-play-file (dired-get-filename))) (add-hook 'dired-mode-hook (function (lambda () (define-key dired-mode-map [?\C-c ?a ?f] 'minh-emms-play-file-at-point))))) ;; XXX: kludgy, find a better way to detect if amixer is present (when (file-executable-p "/usr/bin/amixer") (require 'mamixer) (mamixer-minor-mode t) (global-set-key [?\C-c ?a ?-] 'mamixer-decrease-volume) (global-set-key [?\C-c ?a ?+] 'mamixer-increase-volume) (global-set-key [f7] 'mamixer-decrease-volume) (global-set-key [f8] 'mamixer-increase-volume)) ;;; Look & theme: (setq inhibit-startup-message t) (setq display-time-string-forms '((if mail "Mail-") 24-hours ":" minutes)) (setq display-time-mail-file 0) (display-time-mode t) (menu-bar-mode -1) (when (equal window-system 'x) (tool-bar-mode -1) (scroll-bar-mode -1)) (column-number-mode t) (setq line-number-display-limit 2000000) (line-number-mode t) (setq ediff-window-setup-function 'ediff-setup-windows-plain) (setq truncate-partial-width-windows nil) (setq split-window-preferred-function (function (lambda (&optional window size) (split-window window size t)))) (defvar minh-mode-string "" "Custom mode string.") (put 'minh-mode-string 'risky-local-variable t) (setq minh-mode-string '("" minh-mail-mode-string (:eval (char-to-string (upcase minh-current-layout))) ;; (:eval (minh-bitlbee-status-string)) "-")) (setq global-mode-string (cons '(t minh-mode-string) global-mode-string)) (defun minh-tty-color-theme () "Good old color theme for the TTY." (set-face-attribute 'font-lock-builtin-face nil :foreground "default" :weight 'normal) (set-face-attribute 'font-lock-preprocessor-face nil :foreground "cyan" :weight 'normal) (set-face-attribute 'font-lock-comment-delimiter-face nil :foreground "red") (set-face-attribute 'font-lock-constant-face nil :foreground "default") (set-face-attribute 'font-lock-function-name-face nil :foreground "default" :weight 'normal) (set-face-attribute 'font-lock-keyword-face nil :foreground "blue" :weight 'bold) (set-face-attribute 'font-lock-type-face nil :foreground "default") (set-face-attribute 'font-lock-variable-name-face nil :foreground "default") (set-face-attribute 'font-lock-string-face nil :foreground "green") (set-face-attribute 'font-lock-warning-face nil :foreground "default" :background "red")) (defun minh-x-color-theme () "Color theme for X." ;; XXX ) (cond ((null window-system) (minh-tty-color-theme)) ;; ((equal window-system 'x) (minh-x-color-theme)) ) ;;; Daemon: (server-start)