;; -*- emacs-lisp -*- ;;; dot.emacs --- emacs configuration file ;; Author: Mark Triggs ;; $Id: dot.emacs,v 1.618 2006/10/02 04:45:00 mst Exp $ ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;; Requires: try-require.el (require 'cl) ;;; Code: (push (expand-file-name "~/.elisp") load-path) (push (expand-file-name "~/.elisp/dist") load-path) (push (expand-file-name "~/.elisp/homebrew") load-path) (push (expand-file-name "~/.elisp/site-lisp") load-path) (require 'try-require) (try-require 'mst-site-start) (cond ((and (not noninteractive) (try-require 'timerfunctions) (try-require 'idledo)) (setq idledo-interval 0) (setq idledo-interval-small 0) (setq idledo-subsequent-interval 0) (setq idledo-done-interval 0) (setq idledo-verbosity -100) (when (not idledo-active-p) (idledo-start))) (t ;; Adding idle actions will not work. Execute delayed code immediately ;; instead. (defun idledo-add-action (code) (eval code)))) (try-require 'mst-guess-indentation 'emacs-homebrew 'workspaces 'highlight-fixmes-mode 'filladapt 'parenface 'face-list 'emacs-wiki 'planner 'planner-gnus 'planner-erc 'planner-xtla 'fstree 'mst-point 'mst-planner 'mst-arch 'teatime 'slime 'hyperspec-addon 'w3m 'highlight-long-lines-mode 'incr-at-point 'buffer-ring 'iswitchb-narrow 'frenchspacing-mode 'dired 'unit-test 'lambda-mode) ;;(load "/home/mst/projects/dvc/++build/dvc-load.el") ;;(setq dvc-tips-enabled nil) ;; Load these when we get a moment. (idledo-add-action '(try-require 'color-theme 'w3m-type-ahead 'ascii-table 'tramp 'crypt++ 'multi-shell 'jka-compr 'ftp-el 'gnuserv-compat 'gnuserv 'mmm-mode)) (define-key global-map [?\e f1] 'workspace-goto-current) (define-key global-map [M-f1] 'workspace-goto-current) (define-key global-map [f11] 'workspace-controller) (defvar dotemacs-loaded-hook nil "A hook run after ~/.emacs has been loaded") (defvar main-screen nil) (when (try-require 'escreen) (setq escreen-max-screens 30) (escreen-create-screen) (setq main-screen escreen-current-screen-number)) ;;;; Personalised variables ;;;; (require 'emacs-user-settings) ;;;; Pretty emacs ;;;; (menu-bar-mode 0) (when (fboundp 'blink-cursor-mode) (blink-cursor-mode nil)) (when (fboundp 'fringe-mode) (fringe-mode '(5 . 5))) ;;;; X Specific settings ;;;; (when (fboundp 'mouse-wheel-mode) (mouse-wheel-mode)) (when (fboundp 'display-time) (display-time)) (when (fboundp 'tool-bar-mode) (tool-bar-mode -1)) ; Disable toolbar (setq mouse-yank-at-point t) (scroll-bar-mode -1) ; Disable scrollbar (mouse-avoidance-mode 'exile) ;;;; Hooks ;;;; (add-hook 'write-file-hooks 'time-stamp) ;; (define-key global-map (kbd "C-x k") ;; (lambda () ;; (interactive) ;; (save-window-excursion ;; (diff-buffer-if-modified) ;; (if (and (buffer-file-name) (buffer-modified-p)) ;; (when (y-or-n-p (format "Buffer %s modified; kill anyway? " ;; (current-buffer))) ;; (kill-buffer nil)) ;; (kill-buffer nil)) ;; (ignore-errors (kill-buffer "*Changes*"))))) (defcustom mst-quit-nagging-me-you-bastard nil "Set this to non-nil to disable the 'nagging quit' feature") (add-hook 'kill-emacs-hook (lambda () (when (and (not noninteractive) (not mst-quit-nagging-me-you-bastard)) (unless (y-or-n-p "Really Quit?? ") (signal 'quit nil))))) ;;;; General Settings ;;;; (fset 'yes-or-no-p 'y-or-n-p) (show-paren-mode 1) (transient-mark-mode 1) ; show regions (put 'upcase-region 'disabled nil) ; Enable c-x c-u (put 'downcase-region 'disabled nil) ; Enable c-x c-l (put 'narrow-to-region 'disabled nil) ; Enable narrow-to-region (put 'set-goal-column 'disabled nil) (idledo-add-action '(global-font-lock-mode t)) ; syntax highlighting (setq inhibit-startup-message t kill-ring-max 500 ; bah, I've got memory enable-recursive-minibuffers t insert-default-directory nil ispell-program-name "aspell" sentence-end (concat "\\(?:[.?!]\\|[;:]o[)P(]\\)[]\"')}]*" "\\($\\| $\\| \\| \\| \\)[ \n]*") require-final-newline t ; End file with newline next-line-add-newlines nil ; Beep when we hit the end of the buffer search-highlight t ; Highlight search matches column-number-mode t ; show columns isearch-allow-scroll t diff-switches "-urN" eval-expression-print-level nil ; show me the whole sexp sentence-end-double-space t blink-matching-paren-distance 10000 show-paren-style 'parenthesis custom-file "~/.elisp/custom" ; Store customised stuff elsewhere custom-buffer-done-function 'kill-buffer) (setq backup-by-copying t backup-directory-alist '(("." . "~/.saves/")) delete-old-versions t kept-new-versions 6 kept-old-versions 2 make-backup-files t version-control t) ;;;; Key Bindings ;;;; (define-key global-map (kbd "C-c d") (lambda () (interactive) (require 'time-stamp) (insert (time-stamp-string "%:a %:b %:d, %Y")))) (define-key global-map (kbd "C-x k") 'kill-buffer-show-diff) (define-key global-map (kbd "C-M-y") 'browse-kill-ring) ;; Boxquote a region, or set a title if there is already a boxquote under the ;; point. (when (try-require 'boxquote) (define-key global-map (kbd "C-c b") (lambda () (interactive) (if (boxquote-points) (call-interactively 'boxquote-title) (call-interactively 'boxquote-region))))) (define-key global-map (kbd "C-c f") 'dired-cwd-other-window) (define-key global-map (kbd "M-g") 'goto-line) (define-key global-map (kbd "C-c g") 'goto-line) (define-key global-map (kbd "C-c m") 'man) (define-key global-map (kbd "C-c r") 'replace-regexp) (define-key global-map (kbd "C-c i") 'imenu) (define-key global-map (kbd "C-c ;") 'reselect-last-region) (define-key global-map (kbd "C-c =") 'diff-buffer-with-file) (define-key global-map (kbd "C-c z") 'cycle-zippy) (define-key global-map (kbd "C-c j") 'tiny-xmms) (define-key global-map (kbd "M-=") 'enlarge-window) (define-key global-map (kbd "M-+") (lambda () (interactive) (enlarge-window -1))) (define-key global-map (kbd "C-") 'workspace-controller) (define-key global-map (kbd "C-c _") (lambda () (interactive) (end-of-line) (let ((end (current-column))) (newline) (loop repeat end do (insert "-")) (newline)))) (define-key global-map (kbd "C-c S") 'toggle-flyspell) (defun toggle-flyspell () (interactive) (when (not (boundp 'flyspell-status)) (make-variable-buffer-local 'flyspell-status)) (cond (flyspell-status (setq flyspell-status nil) (flyspell-mode-off)) (t (setq flyspell-status (not flyspell-status)) (flyspell-buffer) (flyspell-mode)))) (define-key global-map (kbd "C-c /") 'fstree-switch) (define-key global-map (kbd "C-c s") 'ispell-buffer) (define-key global-map (kbd "C-c u") 'browse-url) (define-key global-map (kbd "C-x m") 'mail-use-gnus) (define-key global-map (kbd "C-c c") 'comment-region) (define-key global-map (kbd "C-c C") 'uncomment-region) (define-key global-map (kbd "C-z") nil) (let ((url-map (make-sparse-keymap))) (define-key url-map (kbd "g") 'google) (define-key url-map (kbd "w") 'wikipedia) (define-key url-map (kbd "n") 'google-groups) (define-key url-map (kbd "d") (lambda () (interactive) (escreen-goto-screen w3m-screen) (w3m-goto-url-new-session "http://www.cs.utexas.edu/users/EWD/"))) (define-key url-map (kbd "c") (lambda () (interactive) (escreen-goto-screen w3m-screen) (w3m-goto-url-new-session "http://www.c2.com/cgi/wiki/RecentChanges?RecentChanges"))) (define-key url-map (kbd "a") (lambda () (interactive) (let ((url (read-from-minibuffer "Url?: " (thing-at-point 'url)))) (escreen-goto-screen w3m-screen) (w3m-goto-url-new-session (if (string-match "://" url) url (concat "http://" url)))))) (define-key global-map (kbd "C-c w") url-map)) (define-key global-map [M-left] 'escreen-goto-prev-screen) (define-key global-map [M-right] 'escreen-goto-next-screen) (define-key global-map [M-up] 'increment-number-at-point) (define-key global-map [M-down] (lambda (&optional n) (interactive "p") (increment-number-at-point (or (- (abs n)) -1)))) (when (featurep 'escreen) (defvar scratch-screen (progn (escreen-create-screen) escreen-current-screen-number) "The screen used for miscellaneous scratching!") (escreen-goto-screen main-screen) (define-key global-map [M-f5] (lambda () (interactive) (if (= escreen-current-screen-number scratch-screen) (switch-to-buffer "*scratch*") (escreen-goto-screen scratch-screen))))) (define-key global-map [f1] (lambda () (interactive) (if current-prefix-arg (switch-to-buffer "*scratch*") (if (string= (buffer-name (current-buffer)) ".NOTES") (bury-buffer) (find-file "~/.NOTES"))))) (push '("code-plans" ("~/.code-plans" :default "index" :major-mode planner-mode :visit-link planner-visit-link)) muse-project-alist) (define-minor-mode code-todo-mode "Code TODO list" nil nil nil (let ((planner-plan-page-template (concat "**;; Press 'a' to add a new task**\n" "**;; Press 'c' to mark a task as complete**\n" "**;; Press 'q' to hide this buffer**\n\n"))) (planner-mode)) (let ((map (copy-keymap (current-local-map)))) (define-key map (kbd "a") (lambda () (interactive) (let ((task (read-from-minibuffer "Task?: "))) (save-excursion (goto-char (point-max)) (insert (format "#A _ %s\n" task)))))) (define-key map (kbd "q") (lambda () (interactive) (save-buffer) (delete-window))) (define-key map (kbd "c") (lambda () (interactive) (save-excursion (beginning-of-line) (search-forward "_") (delete-backward-char 1) (insert "C")))) (use-local-map map))) (defun code-todo () (interactive) (let ((buf (find-file-noselect "~/.code-todo"))) (with-current-buffer buf (goto-char (point-max))) (pop-to-buffer buf))) (define-key global-map [f2] 'code-todo) (define-key global-map [f3] 'run-scratch) (defun run-scratch (&optional extension) (interactive) (if current-prefix-arg (find-file (format "~/.scratch.%s" (completing-read "Scratch type: " (mapcar (lambda (f) (list (file-name-extension f))) (directory-files "~/" nil ".scratch."))))) (cl-scratch))) (defvar *cl-screen* nil) (defun cl-scratch () (interactive) (labels ((prepare-lisp () (slime) (find-file "~/.scratch.lisp") (delete-other-windows))) (cond ((and *cl-screen* (escreen-screen-defined *cl-screen*)) (if (= escreen-current-screen-number *cl-screen*) (find-file "~/.scratch.lisp") (escreen-goto-screen *cl-screen*)) (unless (and (buffer-exists-p ".scratch.lisp") (buffer-exists-p "*slime-repl")) (prepare-lisp))) (t (escreen-create-screen) (prepare-lisp) (setq *cl-screen* escreen-current-screen-number))))) (define-key global-map [f4] 'bbdb) (define-key global-map [f5] (lambda () (interactive) (call-interactively 'dict-lookup-words) (other-window 1) (with-current-buffer "dict" (let ((map (copy-keymap (current-local-map)))) (define-key map (kbd "q") 'kill-buffer-and-window) (view-mode -1) (use-local-map map))))) (when (featurep 'emacs-wiki) (define-key global-map [f6] (lambda () (interactive) (wiki)))) (defun buffer-exists-p (name) "Is there a buffer whose name is 'name'?" (some (lambda (b) (string-match name b)) (mapcar 'buffer-name (buffer-list)))) (define-key global-map [f7] 'calendar) (define-key global-map [f8] 'mst-planner-create-task) (when (try-require 'escreen) (defvar w3m-screen nil) (escreen-create-screen) (setq w3m-screen escreen-current-screen-number) (escreen-goto-screen main-screen) (eval-after-load "w3m" '(progn (defun w3m-open-link-in-tab () (interactive) (let ((buf (current-buffer))) (w3m-view-this-url-new-session) (switch-to-buffer buf) (w3m-select-buffer-update))) (setq w3m-fill-column 80) (define-key global-map (kbd "C-c a") 'jump-to-w3m) (define-key w3m-mode-map [S-return] 'w3m-open-link-in-tab) (define-key w3m-mode-map (kbd "M-RET") 'w3m-open-link-in-tab) (define-key w3m-mode-map (kbd "q") 'mst-kill-w3m-buffer) (defun mst-kill-w3m-buffer () (interactive) (when (y-or-n-p "Kill this buffer? ") (let ((next-buffer (cadr (memq (current-buffer) (w3m-list-buffers))))) (w3m-kill-buffer nil) (when next-buffer (switch-to-buffer next-buffer)) (when (null (w3m-list-buffers)) (ignore-errors (kill-buffer "*w3m-type-ahead*")))))) (defun jump-to-w3m () (interactive) (cond ((or (null (w3m-list-buffers)) (and (= escreen-current-screen-number w3m-screen) (w3m-buffer-number (current-buffer)))) (let ((url (read-from-minibuffer "Url?: " (thing-at-point 'url)))) (escreen-goto-screen w3m-screen) (w3m-goto-url-new-session (if (string-match "://" url) url (concat "http://" url))))) (t (escreen-goto-screen w3m-screen) (unless (w3m-buffer-number (current-buffer)) (switch-to-buffer (car (w3m-list-buffers)))))))))) (defvar stored-window-configuration nil) (define-key global-map [f9] (lambda () (interactive) (push (current-window-configuration) stored-window-configuration) (message "Window configuration saved"))) (define-key global-map [f10] (lambda () (interactive) (cond (stored-window-configuration (set-window-configuration (pop stored-window-configuration)) (message "Window configuration loaded")) (t (message "No window configurations found"))))) (define-key global-map [f12] 'compile) (setq compilation-ask-about-save nil) (define-key global-map (kbd "C-M-/") 'hippie-expand) ;; allow multiple compilations to run at once. (setq compilation-buffer-name-function (lambda (mode-name) (concat "*compile " (downcase (buffer-name)) "*"))) ;;;; Major/Minor Modes ;;;; ;; Auto Insert Mode ;; (when (fboundp 'auto-insert-mode) (auto-insert-mode t) ;; Just insert the template; don't ask me if it's OK. (setq auto-insert-query nil) (when (file-exists-p (expand-file-name "~/.t")) (setq auto-insert-directory "~/.t/")) ;; python (mst-add-template "\\.py$" "#!/usr/bin/env python") ;; perl (mst-add-template "\\.pl$" "#!/usr/bin/perl -w" "use strict;") ;; ruby (mst-add-template "\\.rb$") ;; lisp shell scripts (mst-add-template "\\.cl$" (concat "#!/usr/bin/env clisp -M /home/mst/.bin/shell.mem " "-q -ansi -E ISO8859-1")) ;; eiffel (mst-add-template "\\.e$" nil ''(format "class %s\n\ncreation\n\nfeature\n\nend -- class %s" (upcase (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))) (upcase (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))))) ;; C (mst-add-template "\\.c$" nil "#include ") ;; haskell (mst-add-template "\\.hs$" nil nil) ;; sawfish (mst-add-template "\\.jl$" nil nil) ;; bash (mst-add-template "\\.sh$" "#!/bin/bash") ;; common lisp (mst-add-template "\\.lisp$" nil nil) ;; java (mst-add-template "\\.java$" nil nil) ;; html (when (file-exists-p (concat auto-insert-directory "html")) (add-to-list 'auto-insert-alist '(("\\.html\\|\\.htm$" . "html") . "html"))) ;; latex (when (file-exists-p (concat auto-insert-directory "tex")) (add-to-list 'auto-insert-alist '(("\\.tex$" . "tex") . "tex")))) ;; Text Mode ;; ;; Set the default major mode to text, and enable word wrapping (setq default-major-mode 'text-mode) (setq tab-width 2) (setq-default filladapt-mode t auto-fill-function 'do-auto-fill) (add-hook 'minibuffer-setup-hook (lambda () (auto-fill-mode -1))) (setq-default default-fill-column 72) ; Set word wrap margin to 72 ;; Set tabs to regular spaces (setq tab-stop-list (loop for x from tab-width to 200 by tab-width collect x)) ;; (define-key text-mode-map (kbd "TAB") 'indent-relative) (define-key text-mode-map (kbd "TAB") 'tab-to-tab-stop) (add-hook 'text-mode-hook (lambda () (global-set-key '[(control meta q)] 'fill-this-line) (setq indent-tabs-mode nil) (define-key text-mode-map (kbd "M-*") (lambda () (interactive) (if (string-match "TAGS" (buffer-name)) (pop-tag-mark) (call-interactively 'mst-point)))) (define-key text-mode-map [C-M-return] (lambda () (interactive) (mst-point 2))) (and (fboundp 'footnote-mode) (footnote-mode)))) ;; C mode ;; (defun c-reindent-defun () (interactive) (if (c-literal-limits) (call-interactively 'c-fill-paragraph) (save-excursion (beginning-of-defun) (c-indent-exp)))) (eval-after-load "cc-mode" '(progn (define-key c-mode-base-map (kbd "C-c C-c") 'compile) (define-key c-mode-base-map (kbd "C-c C-r") 'recompile) (define-key c-mode-base-map (kbd "C-;") (lambda () (interactive) (insert ";"))) (configure-parens-for-map java-mode-map) (configure-parens-for-map c-mode-map) (define-key c-mode-map (kbd "M-q") 'c-reindent-defun) (define-key c-mode-map (kbd "C-c C-l") (lambda () (interactive) (let ((old compile-command)) (compile (format "splint %s" (buffer-file-name))) (setq compile-command old)))) (defadvice c-newline-and-indent (before c-remove-trailing-ws activate) "Remove trailing whitespace before moving to a newline" (save-excursion (end-of-line) (delete-horizontal-space))) (defun java-top-level-p () (let ((location (c-guess-basic-syntax))) (find 'topmost-intro location :key 'car))) (setq java-api-index "~/media/share/reference/jdk-1.5/api/index") (setq java-api-base "~/media/share/reference/jdk-1.5/api") (when (try-require 'c-braces) (define-c-braces-mode java java-top-level-p (lambda () (and (not (java-top-level-p)) (or (save-excursion (c-braces-backward-list-maybe) (progn (condition-case err (progn (backward-sexp) (looking-at (regexp-opt '("if" "for" "while" "do" "else" "try" "catch")))) (error () nil)))) (looking-back ") *")))))) (define-key java-mode-map (kbd "{") 'java-insert-braces) (define-key java-mode-map (kbd "}") 'java-closing-brace) (when (try-require 'c-braces) (define-c-braces-mode c (lambda () (find 'topmost-intro (c-guess-basic-syntax) :key 'car)) (lambda () (save-excursion (c-braces-backward-list-maybe) (progn (backward-sexp) (looking-at (regexp-opt '("if" "for" "while" "do" "else"))))))) (define-key c-mode-map (kbd "{") 'c-insert-braces) (define-key c-mode-map (kbd "}") 'c-closing-brace) ;; my preferred code settings (c-add-style "mst" (list "K&R" (cons 'c-basic-offset 4) (cons 'c-offsets-alist '((defun-open . 0) (inline-open . 0) (brace-entry-open . 0))) (cons 'c-hanging-braces-alist '((block-close before) (brace-list-open) (brace-list-close) (brace-entry-open) (statement-cont) (substatement-open after) (extern-lang-open after) (namespace-open after) (module-open after) (composition-open after) (inexpr-class-open after) (inexpr-class-close before))))) ;; I think this is closer to the standards described in the info page. (c-add-style "gnu2" (list "gnu" (cons 'c-hanging-braces-alist '((block-open after))))) (add-hook 'c-mode-hook (lambda () (c-set-style "mst") (gtags-mode) (setq gdb-show-main t) (set (make-local-variable 'comment-padding) " ") (mst-code-settings 4 nil))) (add-hook 'c-mode-common-hook (lambda () (c-toggle-auto-state 1) (setq comment-style 'extra-line) (mst-code-settings 4 nil)))))) (autoload 'csharp-mode "csharp-mode" t t) (push '("\\.cs\\'" . csharp-mode) auto-mode-alist) (push '("\\.php3?\\'" . html-helper-mode) auto-mode-alist) (autoload 'php-mode "php-mode" t t) (eval-after-load "php-mode" '(progn (push '("\\.php3?\\'" . html-helper-mode) auto-mode-alist) (put 'php-mode 'c-mode-prefix "php-") (add-hook 'php-mode-hook (lambda () (mst-code-settings 4 nil))))) ;; Java (eval-after-load "cc-mode" '(progn (defun java-handle-exceptions (start end) (interactive "r") (let ((end-mark (save-excursion (goto-char end) (point-marker)))) (goto-char start) (beginning-of-line) (open-line 1) (indent-according-to-mode) (insert "try ") (let ((mark-active t) (start (point))) (flet ((region-beginning () start) (region-end () (marker-position end-mark))) (java-insert-braces))) (up-list) (insert " catch (Exception e)") (let ((mark-active nil)) (java-insert-braces)) (insert "throw new RuntimeException ();"))) (when (try-require 'pabbrev) (add-hook 'java-mode-hook 'pabbrev-mode)) (add-hook 'java-mode-hook (lambda () (c-set-style "mst") (autoload 'camelCase-mode "camelCase-mode" nil t) (camelCase-mode 1) (define-key java-mode-map (kbd "M-TAB") 'jde-complete-minibuf) (mst-code-settings 4 nil) ;; override the keys normally bound to info-lookup-symbol (define-key java-mode-map (kbd "C-h S") 'java-class-lookup) (define-key java-mode-map (kbd "C-c C-r") 'java-handle-exceptions) (define-key java-mode-map (kbd "C-c C-e") 'bsh-send-defun-or-line) (define-key java-mode-map (kbd "M-q") 'c-reindent-defun) (if (or (file-exists-p "Makefile") (file-exists-p "makefile")) (setq compile-command "make -k") (setq compile-command (format "javac %s" (buffer-file-name)))))))) (when (fboundp 'jde-mode) (setq auto-mode-alist (append '(("\\.java\\'" . jde-mode)) auto-mode-alist))) ;; Shell scripts (Bash) ;; (eval-after-load "sh-script" '(add-hook 'sh-mode-hook (lambda () (mst-code-settings 4 nil)))) (eval-after-load "ruby-mode" '(progn (require 'compile) (when (try-require 'pabbrev) (add-hook 'ruby-mode-hook 'pabbrev-mode)) (when (boundp 'compilation-error-regexp-alist-alist) (push '(ruby "\\(/.*\\):\\([0-9]+\\)" 1 2) compilation-error-regexp-alist-alist) (push 'ruby compilation-error-regexp-alist)) (add-hook 'ruby-mode-hook (lambda () (mst-code-settings 4 nil))))) ;; SQL ;; (eval-after-load "sql-mode" '(add-hook 'sql-mode-hook (lambda () (mst-code-settings)))) ;; Python ;; (autoload 'python-mode "python-mode" t t) (autoload 'url-cookie-parse-file "w3" t t) (setq auto-mode-alist (append '(("\\.py\\'" . python-mode)) auto-mode-alist)) (eval-after-load "python-mode" '(progn (defadvice py-electric-colon (after py-colon-newline activate) "Insert newlines after colons unless they are part of a lambda" (unless (or (py-in-literal) (save-excursion (backward-char) ; move back over the colon (or (progn (backward-sexp) (looking-at "lambda")) (progn (backward-sexp) (looking-at "lambda")))) (save-excursion (beginning-of-line) (looking-at "^[ \t]*#"))) (py-newline-and-indent))) (setq py-shell-alist '(("jpython" quote jpython) ("jython" quote jpython) ("python" 1))) (setq py-default-interpreter 1) (when (try-require 'pabbrev) (add-hook 'python-mode-hook 'pabbrev-mode)) (add-hook 'python-mode-hook (lambda () (define-key py-mode-map (kbd "C-c !") 'python-start) (define-key py-mode-map [backtab] (lambda () (interactive) (save-excursion (back-to-indentation) (when (>= (current-column) py-indent-offset) (delete-backward-char py-indent-offset))))) (define-key py-mode-map [S-left] (maybe-with-region 'py-shift-region-left)) (define-key py-mode-map (kbd "C-c C-d") (lambda (beg end) (interactive "r") (python-send-command (format "dir (%s)" (buffer-substring beg end))))) (define-key py-mode-map (kbd "C-c C-i") (lambda (beg end) (interactive "r") (python-send-command (format "print %s.__doc__" (buffer-substring beg end))))) (define-key py-mode-map [S-right] (maybe-with-region 'py-shift-region-right)) (define-key py-mode-map (kbd "C-c C-c") 'python-send-defun-or-line) (mst-code-settings 4 nil) (setq py-temp-directory "/tmp"))))) ;; My stamp program ;; (autoload 'mst-stamp "mst-stamp" t t) ;; Dict Frontend (autoload 'dict-lookup-words "dict" t t) ;; Browse-url ;; (eval-after-load "browse-url" (setq browse-url-browser-function 'browse-url-mozilla browse-url-mozilla-new-window-is-tab t browse-url-new-window-flag t browse-url-usr1-signal nil)) ;; Eiffel ;; (autoload 'eiffel-mode "eiffel" t t) (setq auto-mode-alist (append '(("\\.e\\'" . eiffel-mode)) auto-mode-alist)) (eval-after-load "eiffel" '(progn (setq eif-compile-options "-clean") (add-hook 'eiffel-mode-hook (lambda () (mst-code-settings))))) (setq TeX-parse-self t) ; Enable parse on load. (setq TeX-auto-save t) ; Enable parse on save. (defvar LaTeX-star-sections nil "Use \[sub][sub]section*{}") (add-hook 'Texinfo-mode-hook (lambda () (highlight-fixmes-mode 1))) (add-hook 'LaTeX-mode-hook (lambda () (highlight-fixmes-mode 1) (make-local-variable 'LaTeX-star-sections) (setq LaTeX-star-sections nil) (push `("^dvi$" "." ,(format "DISPLAY=%s xdvi %%d" (or (frame-parameter (selected-frame) 'display) (getenv "DISPLAY")))) TeX-output-view-style) (push `("^pdf$" "." ,(format "DISPLAY=%s acroread.sh %%o" (or (frame-parameter (selected-frame) 'display) (getenv "DISPLAY")))) TeX-output-view-style) (setq TeX-view-style (list (list "." (format "DISPLAY=%s xdvi %%d" (or (frame-parameter (selected-frame) 'display) (getenv "DISPLAY")))))) (filladapt-mode -1) (define-key LaTeX-mode-map (kbd "C-c ;") nil) ; I need this! (define-key LaTeX-mode-map (kbd ".") (lambda () (interactive) (insert ".") (when (and (not (in-comment-p)) (looking-back "\\.\\.\\.")) (delete-backward-char 3) (insert "\\ldots")))) (define-key LaTeX-mode-map (kbd "C-c C-n") 'LaTeX-find-matching-end) (labels ((add (item) (beginning-of-line) (newline) (previous-line 1) (delete-blank-lines) (let ((map (copy-keymap (current-local-map)))) (define-key map (kbd "RET") 'exit-minibuffer) (insert (format "\n\n\\%s%s{%s}\n\n\n" item (if LaTeX-star-sections "*" "") (read-from-minibuffer "Name?: " nil map)))) (previous-line 1))) (define-key LaTeX-mode-map (kbd "C-c 1") (lambda () (interactive) (add "section"))) (define-key LaTeX-mode-map (kbd "C-c 2") (lambda () (interactive) (add "subsection"))) (define-key LaTeX-mode-map (kbd "C-c 3") (lambda () (interactive) (add "subsubsection")))) (define-key LaTeX-mode-map (kbd "C-c n") (lambda () (interactive) (unless (looking-at "^") (end-of-line) (newline)) (delete-blank-lines) (insert "\n\n\\newpage\n\n\n"))) (define-key LaTeX-mode-map (kbd "M-RET") 'LaTeX-insert-item) (define-key LaTeX-mode-map [(control c) (control i)] (lambda () (interactive) (end-of-line) (if (looking-at "^") (newline) (newline 2)) (LaTeX-insert-environment "itemize") (insert "\\item ") (indent-for-tab-command))) (define-key LaTeX-mode-map [(control c) (control o)] (lambda () (interactive) (end-of-line) (if (looking-at "^") (newline) (newline 2)) (LaTeX-insert-environment "enumerate") (insert "\\item ") (indent-for-tab-command))))) ;; Lisp mode ;; (define-key esc-map (kbd "C-)") (lambda () (interactive) (up-list) (just-one-space))) (define-key esc-map "\"" (lambda (&optional arg) (interactive "P") (insert-pair arg ?\" ?\"))) (set-face-background 'trailing-whitespace "gray80") (add-hook 'emacs-lisp-mode-hook (lambda () (mst-code-settings) (setq tab-width 8) (setq show-trailing-whitespace t) (setq comment-start ";;") (eldoc-mode))) (setq auto-mode-alist (append '(("\\.gnus\\'" . emacs-lisp-mode)) auto-mode-alist)) ;; Gnuserv (when (and (fboundp 'gnuserv-start) (not noninteractive)) (gnuserv-start)) (eval-after-load "gnuserv" '(setq server-kill-new-buffers nil gnuserv-temp-file-regexp ".*")) ;; Flyspell ;; (eval-after-load "flyspell" '(progn (setq flyspell-default-dictionary "british") (define-key flyspell-mode-map (kbd "M-TAB") 'flyspell-goto-next-error))) ;; Calendar mode ;; (eval-after-load "calendar" '(setq cal-tex-diary t diary-file "~/.diary" calendar-date-display-form '(day "/" month "/" year) cal-tex-holidays nil)) (setq european-calendar-style t) (eval-after-load "diary-lib" '(progn (setq diary-date-forms '((day "/" month "[^/0-9]") (day "/" month "/" year "[^0-9]") (monthname " *" day "[^,0-9]") (monthname " *" day ", *" year "[^0-9]") (dayname "\\W"))) (setq mark-diary-entries-in-calendar t number-of-diary-entries 30) (add-hook 'diary-display-hook 'fancy-diary-display) (add-hook 'today-visible-calendar-hook 'calendar-mark-today))) ;; PS-Print ;; (eval-after-load "ps-print" '(progn (defun ps-get-page-title () ps-print-page-title) (add-hook 'ps-print-hook (lambda () (setq ps-print-page-title (read-from-minibuffer "Page title?: ")))) (setq ps-font-size '(7 . 9.5) ps-left-header '(ps-get-page-title) ps-right-header (list "/pagenumberstring load") ps-print-color-p nil ps-paper-type 'a4 ps-default-bg "white" ps-default-fg "black"))) ;; W3 ;; (eval-after-load "w3-cus" '(setq w3-user-colors-take-precedence t w3-user-fonts-take-precedence t w3-delay-image-loads t)) ;; BBDB ;; (eval-after-load "bbdb" '(progn (bbdb-initialize) (setq bbdb-expand-mail-aliases t bbdb-use-pop-up nil bbdb-offer-save 'auto bbdb-dwim-net-address-allow-redundancy t bbdb-quiet-about-name-mismatches nil bbdb-pop-up-target-lines 1 bbdb-new-nets-always-primary nil bbdb-canonicalize-redundant-nets-p t bbdb-pop-up-elided-display nil bbdb/gnus-summary-prefer-real-names t bbdb/gnus-summary-show-bbdb-names t bbdb/gnus-summary-known-poster-mark nil bbdb-complete-name-allow-cycling t bbdb-north-american-phone-numbers-p nil bbdb-print-omit-fields '(omit tex-name aka mail-alias gnus-group creation-date timestamp) bbdb-completion-display-record nil))) ;; jka-compr (eval-after-load "jka-compr" '(auto-compression-mode t)) ;; Tramp ;; (eval-after-load "tramp" '(setq tramp-default-method (cond ((executable-find "ssh") "ssh") ((executable-find "plink") "plink") (t nil)))) ;; Wiki ;; (eval-after-load "emacs-wiki" '(try-require "emacs-wiki-settings")) (defun wiki (&optional arg) (interactive "P") (if arg (call-interactively 'emacs-wiki-find-file) (emacs-wiki-find-file emacs-wiki-default-page))) ;; Crypt++ ;; (eval-after-load "crypt++" '(progn (modify-coding-system-alist 'file "\\.bz\\'" 'no-conversion) (modify-coding-system-alist 'file "\\.bz2\\'" 'no-conversion) (modify-coding-system-alist 'file "\\.gpg\\'" 'no-conversion) (modify-coding-system-alist 'file "\\.asc\\'" 'no-conversion) (modify-coding-system-alist 'file "\\.gz\\'" 'no-conversion) (modify-coding-system-alist 'file "\\.Z\\'" 'no-conversion) (modify-coding-system-alist 'file "\\Secure\\'" 'no-conversion) (setq crypt-encryption-type 'gpg-pub) (setq crypt-encryption-file-extension (concat "\\(Secure\\)$\\|\\(\\.enc\\)$" "\\|\\(\\.asc\\)$")) (crypt-rebuild-tables) (crypt-bind-insert-file))) ;; CPerl mode ;; (setq interpreter-mode-alist (cons (cons "perl" 'cperl-mode) (remove-if (lambda (e) (eq (cdr e) 'perl-mode)) interpreter-mode-alist))) (setq auto-mode-alist (append '(("\\.pl\\'" . cperl-mode) ("\\.pm\\'" . cperl-mode)) (remove-if (lambda (e) (eq (cdr e) 'perl-mode)) auto-mode-alist))) (eval-after-load "cperl-mode" '(progn (require 'compile) (when (boundp 'compilation-error-regexp-alist-alist) (push '(perl-test ".*Failed test (\\(.*\\) at line \\([0-9]+\\)).*" 1 2) compilation-error-regexp-alist-alist) (push 'perl-test compilation-error-regexp-alist)) (add-hook 'cperl-mode-hook (lambda () (set (make-local-variable 'eldoc-documentation-function) (lambda () (car (let ((cperl-message-on-help-error nil)) (cperl-get-help)))) 'my-cperl-eldoc-documentation-function))) (when (try-require 'c-braces) (define-c-braces-mode cperl (lambda () (save-excursion (beginning-of-line) (or (looking-at "[ \t]*sub") (looking-at "^$")))) (lambda () (or (and (save-excursion (ignore-errors (backward-list) t)) (save-excursion (beginning-of-line) (looking-at "^[ \t]*foreach"))) (save-excursion (c-braces-backward-list-maybe) (condition-case err (progn (backward-sexp) (or (looking-at (regexp-opt '("when " "unless " "if " "while " "until " "foreach " "for " "elsif "))) (looking-at (concat (regexp-opt '("do" "else" "eval")) " *$")))) (error () nil)))))) (define-key cperl-mode-map (kbd "{") 'cperl-insert-braces) (define-key cperl-mode-map (kbd "}") 'cperl-closing-brace)) (add-hook 'cperl-mode-hook (lambda () (setq cperl-lazy-help-time 0.5) (cperl-lazy-install) (cperl-set-style "K&R") (set (make-local-variable 'beginning-of-defun-function) 'cperl-beginning-of-function) (set (make-local-variable 'end-of-defun-function) 'cperl-end-of-function) (setq cperl-auto-newline t) (font-lock-add-keywords nil '(("\\<\\(define_test\\)\\>" 1 font-lock-keyword-face t)) t) (configure-parens-for-map cperl-mode-map) (define-key cperl-mode-map (kbd "C-c C-c") 'compile) (define-key cperl-mode-map (kbd "M-q") 'cperl-reindent-defun) (define-key cperl-mode-map (kbd "C-;") (lambda () (interactive) (insert ";"))) (set (make-local-variable 'compile-command) (concat "perl -c " (buffer-file-name (current-buffer)))) (define-key cperl-mode-map (kbd "C-c C-r") 'cperl-send-region) (define-key cperl-mode-map (kbd "C-c C-e") 'cperl-send-function) (define-key cperl-mode-map (kbd "C-c C-c") 'cperl-send-line) (define-key cperl-mode-map (kbd "C-c C-z") 'cperl-show) (define-key cperl-mode-map (kbd "C-c !") 'cperl-repl) (define-key cperl-mode-map (kbd "C-{") 'self-insert-command) (define-key cperl-mode-map (kbd "C-}") 'self-insert-command) (mst-code-settings 4 nil))))) (autoload 'html-helper-mode "html-helper-mode" "HTML" t) (eval-after-load "html-helper-mode" '(progn ;; Indent tables (setq html-helper-any-list-start (concat html-helper-any-list-start "\\|\\|\\|
") html-helper-any-list-end (concat html-helper-any-list-end "\\|
\\|\\|") html-helper-any-list (format "\\(%s\\)\\|\\(%s\\)\\|\\(%s\\)" html-helper-any-list-item html-helper-any-list-start html-helper-any-list-end)) (define-key html-helper-mode-map (kbd "C-c C-f C-e") 'tempo-template-html-italic) (define-key html-helper-mode-map (kbd "C-c C-f C-b") 'tempo-template-html-bold) (define-key html-helper-mode-map (kbd "C-c C-s") 'mst-html-section) (define-key html-helper-mode-map (kbd "C-c C-e") 'mst-html-environment) (define-key html-helper-mode-map (kbd "C-c i") 'tempo-template-html-unordered-list) (define-key html-helper-mode-map (kbd "C-c o") 'tempo-template-html-ordered-list) (define-key html-helper-mode-map (kbd "M-RET") 'mst-html-helper-paragraph-or-item) (define-key html-helper-mode-map (kbd "C-c 1") (lambda () (interactive) (mst-html-section "section"))) (define-key html-helper-mode-map (kbd "C-c 2") (lambda () (interactive) (mst-html-section "subsection"))) (define-key html-helper-mode-map (kbd "C-c 3") (lambda () (interactive) (mst-html-section "subsubsection"))) (defun mst-html-helper-paragraph-or-item () (interactive) (if (eq (car (html-helper-guess-context)) 'item) (tempo-template-html-item) (tempo-template-html-paragraph))) (defvar mst-html-environments '((quote . tempo-template-html-blockquote) (pre . tempo-template-html-preformatted))) (defun mst-html-environment (&optional type) (interactive) (let ((type (or type (completing-read "Environment: " mst-html-environments)))) (funcall (cdr (assoc (intern type) mst-html-environments))))) (defun insert-heading (level) (interactive) (insert (format "%s\n" level (read-from-minibuffer "Title: ") level))) (defvar mst-html-sections '((section . (lambda () (insert-heading 1))) (subsection . (lambda () (insert-heading 2))) (subsubsection . (lambda () (insert-heading 3))) (paragraph . tempo-template-html-paragraph))) (defun mst-html-section (&optional type) (interactive) (let ((type (or type (completing-read "Section: " mst-html-sections)))) (funcall (cdr (assoc (intern type) mst-html-sections))))) ;; taken from html-helper-mode.el and refactored a little (defun html-helper-indent () "indentation workhorse function." (unless html-helper-never-indent ;; unindent the line (let ((m (point-marker))) (beginning-of-line) (delete-horizontal-space) (let* ((where (html-helper-guess-context)) (context (car where)) (previ (cdr where)) (newi (cond ((eq context 'end) previ) ((eq context 'item) previ) ((eq context 'start) (+ previ html-helper-basic-offset)) (t previ)))) ;; newi is set to the basic indentation, now adjust indentation ;; based on what the current line is. (if (looking-at html-helper-any-list) (cond ;; list token and last line was an end? ;; Probably inside a continued item - go backwards. ((and (match-beginning 1) (eq context 'end)) (setq newi (- newi html-helper-item-continue-indent))) ;; end of list and last line was an end? ;; Probably inside a continued item - go backwards twice ((and (match-beginning 3) (eq context 'end)) (setq newi (- newi html-helper-basic-offset))) ;; Any other end of list? ;; Indent negative ((match-beginning 3) (setq newi (- newi html-helper-basic-offset))) ;; start of list and last line ;; Beginning of continued item - go forwards ((and (match-beginning 2) (eq context 'item)) (setq newi (+ newi html-helper-item-continue-indent)))) ;; we're not any sort of item, must be text. (cond ;; last line an item? ;; Beginning of continued item - go forward ((eq context 'item) (setq newi (+ newi html-helper-item-continue-indent))))) (if html-helper-print-indent-info (message "Context: %s, Previous: %s New: %s" context previ newi)) ;; just in case (if (< newi 0) (setq newi 0)) (indent-to newi newi) (unless (= (marker-position m) (line-beginning-position)) (goto-char (marker-position m))))))))) ;; Asm mode ;; (setq auto-mode-alist (append '(("\\.ass\\'" . asm-mode)) auto-mode-alist)) ;; HTML ;; (setq auto-mode-alist (append '(("\\.html$" . html-helper-mode)) auto-mode-alist)) ;; Dict ;; (eval-after-load "dict" '(setq dict-server-host nil)) ;; Dired ;; (eval-after-load "dired" '(progn ;; (defadvice dired-advertised-find-file ;; (around dired-kill-last-buffer activate) ;; (let ((old-dired-buffer (current-buffer))) ;; ad-do-it ;; (kill-buffer old-dired-buffer))) (defadvice dired-up-directory (around dired-up-directory-kill-last-buffer activate) (let ((old-dired-buffer (current-buffer))) ad-do-it (unless (eql (current-buffer) old-dired-buffer) (kill-buffer old-dired-buffer)))) (add-hook 'dired-mode-hook (lambda () (require 'dired-x) (local-set-key (kbd "C-c e t") 'run-unit-tests) (when (fboundp 'dired-omit-mode) (dired-omit-mode -1)) (setq dired-recursive-copies 'always) (setq dired-recursive-deletes 'top))))) ;; Haskell ;; (eval-after-load "haskell-mode" '(progn (require 'haskell-ref) (define-key haskell-mode-map (kbd "C-c C-d") 'haskell-reference-lookup) (add-hook 'haskell-mode-hook (lambda () (glasses-mode) (define-key haskell-mode-map (kbd "C-c C-l") 'hugs-load) (mst-code-settings)) t))) ;; iswitchb ;; (when (try-require 'iswitchb) (iswitchb-default-keybindings) (define-key global-map (kbd "C-x b") 'iswitchb-with-narrowing) (setq iswitchb-default-method 'samewindow iswitchb-method 'samewindow) (setq iswitchb-mst-to-end-regexp (concat "\\*scratch\\*\\|\\*Messages\\*\\|\\*Apropos\\*\\|\\*Help\\*\\|.bbdb" "\\|Completions\\|dribble\\|Output\\*$\\|\\*TeX silent\\*\\|Result\\*" "\\|\\*MailCrypt\\*\\|\\*vc\\*\\|log"))) ;; SLIME hacks (defun lisp-reindent-defun () (interactive) (save-excursion (when (search-backward-regexp "\n\n\\((\\)") (goto-char (match-beginning 1)) (indent-sexp)))) (defun lisp-comment-dwim (arg) (interactive "P") (comment-dwim arg) (when (and (not arg) (looking-back ".;;")) (delete-char -1) (insert " "))) (define-key lisp-interaction-mode-map (kbd "M-q") 'lisp-reindent-defun) (define-key lisp-mode-map (kbd "M-q") 'lisp-reindent-defun) (define-key emacs-lisp-mode-map (kbd "M-q") 'lisp-reindent-defun) (define-key lisp-mode-map (kbd "M-;") 'lisp-comment-dwim) (define-key emacs-lisp-mode-map (kbd "M-;") 'lisp-comment-dwim) (defvar in-string-recognisers '((cperl-mode (lambda () (if (and (looking-back "(") (looking-at ")")) nil (require 'thingatpt) (in-string-p)))))) (defvar in-comment-recognisers '((emacs-lisp-mode (lambda () (looking-back ";;.*"))) (lisp-mode (lambda () (looking-back ";;.*"))) (cperl-mode (lambda () (looking-back "#.*"))) (latex-mode (lambda () (looking-back "%.*"))) ((c-mode java-mode jde-mode) (lambda () (c-in-literal))))) (defun in-comment-p () (require 'thingatpt) (or (if (assoc major-mode in-string-recognisers) (funcall (cadr (assoc major-mode in-string-recognisers))) (in-string-p)) (let ((fn (cadr (find-if (lambda (recogniser) (or (eql major-mode (car recogniser)) (and (listp (car recogniser)) (member major-mode (car recogniser))))) in-comment-recognisers)))) (if fn (funcall fn) nil)))) (defun open-paren (&optional arg) "Same as `insert-parentheses', but when the mark is active, wraps the contained SEXPs in parens and positions the point after the opening one." (interactive "P") (if (in-comment-p) (insert "(") (if mark-active (let ((contents (delete-and-extract-region (region-beginning) (region-end))) (paren-count (or arg 1))) (insert (format "%s%s" (make-string paren-count (string-to-char "(")) contents)) (push-mark) (insert (make-string paren-count (string-to-char ")"))) (backward-sexp 1) (forward-char paren-count)) (insert-parentheses arg)))) (defun close-paren () (interactive) (if (in-comment-p) (insert ")") (condition-case err (progn (save-excursion (up-list) (unless (eql (char-before) (string-to-char ")")) (error))) (up-list) (save-excursion (backward-char 1) (delete-horizontal-space) (when (bolp) (while (eql (char-before) (string-to-char "\n")) (delete-backward-char 1)) (delete-horizontal-space)) (forward-char 1))) (error () (insert ")"))))) (defun configure-parens-for-map (map) (define-key map (kbd "(") 'open-paren) (define-key map (kbd ")") 'close-paren) (define-key map (kbd "M-(") (lambda () (interactive) (insert "("))) (define-key map (kbd "M-)") (lambda () (interactive) (insert ")")))) (mapc 'configure-parens-for-map (list emacs-lisp-mode-map lisp-mode-map lisp-interaction-mode-map)) (eval-after-load "slime" '(progn (define-key global-map (kbd "C-c ?") 'slime-selector) (setq slime-show-last-output-function 'slime-show-last-output-region) (setq slime-repl-enable-presentations nil) (defun slime-mst-unit-test (&optional arg) (interactive "P") (let ((command (if arg (let ((group (completing-read "Run which test group?: " (mapcar (lambda (s) (format "%s" s)) (slime-mst-sync-eval-hack "(unittest-suites)"))))) (format "(unittest-run-suite '%s)" group)) "(unittest-run-tests)"))) (slime-eval-with-transcript `(swank:interactive-eval ,command) `(lambda (result) (let ((result (car (read-from-string (replace-regexp-in-string "^=> " "" result))))) (with-current-buffer ,(current-buffer) (cond ((and (zerop (getf result :FAILED)) (zerop (getf result :ERRORS))) (show-test-status 'passed) (message "%s" (cddr result))) (t (show-test-status 'failed) (setq foobar result) (message "%s\n\n%s" (mapconcat 'identity (getf result :OUTPUT) "\n") (cddr result)))))))) 'handled)) (defun slime-mst-eval-and-insert-last-expr () (interactive) (let ((expr (slime-last-expression))) (slime-insert-transcript-delimiter expr) (slime-eval-with-transcript `(swank:interactive-eval ,expr) `(lambda (s) (with-current-buffer ,(current-buffer) (insert (format " %s" s))))))) (defun slime-mst-eval () (interactive) (if current-prefix-arg (call-interactively 'slime-mst-eval-and-insert-last-expr) (call-interactively 'slime-eval-last-expression))) (defun semantic-default-elisp-setup ()) (add-hook 'lisp-mode-hook (lambda () (slime-mode t) ;; Show unit tests in bold. (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) (font-lock-add-keywords nil '(("\\<\\(\\define-test[s]?\\)\\>" 1 font-lock-keyword-face t)) t) (font-lock-add-keywords nil '(("\\<\\(\\undefine-test[s]?\\)\\>" 1 font-lock-warning-face t)) t) (font-lock-add-keywords nil '(("\\<\\(\\disable-test[s]?\\)\\>" 1 font-lock-function-name-face t)) t) (slime-define-key "\C-c\C-e" 'slime-mst-eval :allow-other-keys t) (slime-define-key "\C-x\C-e" 'slime-mst-eval :allow-other-keys t) (slime-define-key "\C-c\C-q" (lambda () (interactive) (slime-arglist (current-function-name)))) (setq common-lisp-hyperspec-root "file:/usr/share/doc/hyperspec/"))) (add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t))) (defun slime-mst-sync-eval-hack (form-string) (let ((result (list nil))) (slime-eval-with-transcript `(cl:eval (cl:read-from-string ,form-string)) `(lambda (f) (setcar ',result f) (setcdr ',result 'done))) (while (not (cdr result)) (sleep-for 0.1)) (car result))) (add-hook 'slime-mode-hook (lambda () (setq unit-test-command 'slime-mst-unit-test))) (add-hook 'lisp-mode-hook '(lambda () (setq comment-start ";;") (mst-code-settings) (set (make-local-variable lisp-indent-function) 'common-lisp-indent-function) (if (eq window-system 'x) (setq lisp-font-lock-keywords lisp-font-lock-keywords-2)))) (put 'testcase 'lisp-indent-function 2) (defadvice common-lisp-hyperspec (around hyperspec-lookup-w3m () activate) (require 'w3m) (let ((browse-url-browser-function 'w3m-with-saved-window-configuration)) ad-do-it)))) (add-hook 'iswitchb-make-buflist-hook 'iswitchb-sort-by-age) (require 'time-date) (defun iswitchb-sort-by-age () (flet ((buffer-age-seconds (b) (with-current-buffer b (if buffer-display-time (time-to-seconds buffer-display-time) most-positive-fixnum)))) (setq iswitchb-temp-buflist (let ((l (mapcar 'buffer-name (sort (mapcar 'get-buffer iswitchb-temp-buflist) (lambda (b1 b2) (> (buffer-age-seconds b1) (buffer-age-seconds b2))))))) (append (reverse (subseq l 0 2)) (subseq l 2)))))) ;; Buffers matching the above regexp are pushed to the end (add-hook 'iswitchb-make-buflist-hook 'iswitchb-mst-summaries-to-end t nil) (define-key global-map (kbd "C-c '") (lambda () (interactive) (let ((path (or (buffer-file-name) default-directory))) (kill-new path) (message path)))) (define-key global-map (kbd "C-M-!") 'remote-shell-command) ;; w3m ;; (eval-after-load "w3m" '(progn (define-key w3m-mode-map (kbd "/") 'w3m-type-ahead) (setq w3m-use-cookies t))) ;; etags ;; (defvar mst-last-tag nil "the last tag searched for") (defadvice find-tag (around find-tag-mst () activate) (if (file-exists-p "TAGS") (when (not (member "TAGS" tags-table-list)) (setq tags-table-list (cons "TAGS" tags-table-list))) (setq tags-table-list (remove "TAGS" tags-table-list))) (if tagname (setq mst-last-tag tagname) (setq tagname mst-last-tag)) ;; Sort of experimental. Allow M-. to jump to elisp functions if nothing was ;; found in the tag table. (if (ignore-errors (find-tag-noselect tagname next-p regexp-p)) ad-do-it (cond ((and (fboundp (intern tagname)) (subrp (symbol-function (intern tagname)))) (message (concat tagname " is a builtin"))) ((fboundp (intern tagname)) (find-function (intern tagname))) ((boundp (intern tagname)) (find-variable (intern tagname)))))) ;; angeftp (setq ange-ftp-default-user "anonymous") ;; O'Caml (eval-after-load "caml" '(progn (require 'caml-font) (define-key caml-mode-map (kbd "M-TAB") 'caml-complete))) (add-to-list 'auto-mode-alist '("\\.ml$" . caml-mode)) ;; glasses-mode (eval-after-load "glasses" '(progn ;; make caps stand out a little more (autoload 'camelCase-mode "camelCase-mode" nil t) (make-face 'camelcap) (set-face-attribute 'camelcap nil :underline "gray70" :overline nil) (setq glasses-face 'camelcap glasses-separator "" glasses-separate-parentheses-p nil glasses-uncapitalize-p nil) (glasses-set-overlay-properties) (add-hook 'glasses-mode-hook (lambda () (camelCase-mode 1))))) ;;; XMMS controls (define-key global-map (kbd "C-c ") (lambda () (interactive) (shell-command "xmms -r"))) (define-key global-map (kbd "C-c ") (lambda () (interactive) (shell-command "xmms -f"))) (define-key global-map (kbd "C-c ") (lambda () (interactive) (shell-command "xmms -p"))) (define-key global-map (kbd "C-c ") (lambda () (interactive) (shell-command "xmms -s"))) (setq default-input-method "english-dvorak") (add-hook 'write-file-functions 'break-symlink-maybe) (defvar keep-this-symlink nil) (make-variable-buffer-local 'keep-this-symlink) (defun break-symlink-maybe () (when (and (not keep-this-symlink) (file-symlink-p (buffer-file-name))) (cond ((y-or-n-p "This file is a symlink. Follow when writing? ") (setq keep-this-symlink t) nil) (t (let ((dest (file-truename (buffer-file-name)))) (delete-file (buffer-file-name)) (write-file (buffer-file-name)) (message "Symlink broken") t))))) ;; Don't try to auto-save files aren't writable. (add-hook 'find-file-hook (lambda () (when (buffer-file-name) (unless (file-writable-p (buffer-file-name)) (auto-save-mode -1))))) (add-to-list 'auto-mode-alist '("\\.y\\'" . c-mode)) (autoload 'bison-mode "bison-mode" t t) (defadvice mmm-update-submode-region (around fix-cmode-problems () activate) (when (mmm-update-current-submode) (flet ((mmm-update-current-submode () t)) ad-do-it) (when (member major-mode '(c-mode php-mode c++-mode java-mode)) (c-basic-common-init major-mode "mst") (require 'cc-vars) (c-init-language-vars-for 'c-mode) (c-set-style "mst") (c-toggle-auto-state 1) (c-font-lock-init) (mst-code-settings 4) (font-lock-mode 1)))) (eval-after-load "mmm-mode" '(progn (mmm-add-mode-ext-class nil "\\.y" 'bison) (mmm-add-mode-ext-class nil "\\.php3?" 'php) (mmm-add-mode-ext-class nil "\\.html" 'javascript) (setq mmm-global-mode 'maybe) (setq mmm-submode-decoration-level 2) (push 'indent-region-function mmm-save-local-variables) (mmm-add-classes '((bison :submode bison-mode :front "%%" :back "%%") ;; Not sure why I'm setting these up. I don't even use them :oP (php :submode php-mode :front "<\\?" :back "\\?>") (javascript :submode c-mode :front "$" :back ""))))) (eval-after-load "bison-mode" '(progn (setq bison-rule-enumeration-column 6) (setq bison-rule-separator-column 4) (fset 'bison-format-block "\213\C-c{\C-y\C-a\C-k\274\C-k\C-xh\234\C-k\C-c\C-c") (define-key bison-mode-map (kbd "C-c .") 'bison-format-block) (define-key bison-mode-map (kbd "C-c {") 'bison--type-action-block))) ;; Ediff (eval-after-load "ediff" '(setq ediff-window-setup-function 'ediff-setup-windows-plain)) (eval-after-load "newcomment" '(progn (defadvice comment-region (around nuke-whitespace activate) (let ((first (progn (goto-char beg) (point-marker))) (last (progn (goto-char end) (point-marker)))) ad-do-it (save-excursion (flet ((message (&rest args) nil)) (replace-regexp " +$" "" nil (marker-position first) (marker-position last)))))))) (autoload 'turtle-mode "turtle-mode" t t) (add-to-list 'auto-mode-alist '("\\.turtle$" . turtle-mode)) ;; Frenchspacing (add-hook 'text-mode-hook 'frenchspacing-mode) ;; Tiny XMMS (autoload 'tiny-xmms "tiny-xmms" t t) ;; Ada mode (defun ada-smart-indent (&rest args) (interactive) (if (ada-in-comment-p) (apply 'ada-fill-comment-paragraph args) (indent-region (point-min) (point-max)) (ada-tab) (ada-adjust-case-buffer))) (eval-after-load "ada-mode" '(progn (defadvice ada-complete-identifier (around ada-complete-identifier-bugfix activate) (let ((p (point)) (word (thing-at-point 'sexp))) (ignore-errors ad-do-it) (when (< (point) p) (insert word) (message "No completions")))) (add-hook 'ada-mode-hook (lambda () (glasses-mode 1) (filladapt-mode -1) (mst-code-settings-mode) (setq fill-paragraph-function 'ada-smart-indent))) (define-key ada-mode-map (kbd "M-TAB") 'ada-complete-identifier) (define-key ada-mode-map [C-tab] nil))) (setq tla-use-forward-option t tla-three-way-merge nil tla-revisions-shows-merges t) (defadvice tla--run-arch (around use-display activate) (with-frame-display ad-do-it)) (defadvice tla--run-tla-async (around use-display activate) (with-frame-display ad-do-it)) (defadvice tla--run-tla-sync (around use-display activate) (with-frame-display ad-do-it)) (defun tla-buffers () (interactive) (flet ((iswitchb-ignore-buffername-p (name) (not (string-match "tla" name)))) (iswitchb))) (defadvice tla-buffer-quit (after nuke-window activate) (when (and (eq tla-switch-to-buffer-mode 'pop-to-buffer) (cdr (window-list nil))) (delete-window))) (setq comment-empty-lines t) ;; SGML mode (eval-after-load "sgml-mode" '(progn (define-key sgml-mode-map (kbd "TAB") 'indent-according-to-mode))) (add-to-list 'auto-mode-alist '("\\.xsd\\'" . xml-mode)) ;; gtags mode (autoload 'gtags-mode "gtags" "" t) (eval-after-load "gtags" '(define-key gtags-mode-map (kbd "C-M-.") 'gtags-find-symbol)) ;; locate (eval-after-load "locate" '(progn (defun locate-update (&rest ignored) nil))) (eval-after-load "edict" '(progn (push "/usr/share/edict/" edict-dictionary-path))) (defun set-buffer-display () "Set the DISPLAY environment variable to the current frame's display." (add-to-list (make-local-variable 'process-environment) (format "DISPLAY=%s" (frame-parameter nil 'display)))) (add-hook 'find-file-hook 'set-buffer-display) (add-hook 'dired-mode-hook 'set-buffer-display) ;; Preserve the process-environment when running async commands. ;; This lets me set my "DISPLAY" environment variable local to each buffer and ;; have programs load on the correct display. (defadvice shell-command (before shell-command-preserving-display activate) (when (and (string-match "[ \t]*&[ \t]*\\'" command) (not output-buffer)) (let ((env process-environment)) (with-current-buffer (get-buffer-create "*Async Shell Command*") (set (make-local-variable 'process-environment) env))))) ;; Don't warn me (setq byte-compile-interactive-only-functions '()) (eval-after-load "eshell" '(progn (add-hook 'eshell-mode-hook (lambda () (set (make-local-variable 'process-environment) (cons (format "DISPLAY=%s" (frame-parameter nil 'display)) process-environment)) (define-key eshell-mode-map (kbd "C-a") 'eshell-bol) (add-to-list 'eshell-output-filter-functions 'eshell-handle-control-codes) (add-hook (make-local-variable 'window-scroll-functions) (lambda (window pos) (goto-char (point-max)) (recenter -2))))))) (eval-after-load "jde" '(progn (require 'cedet) (setq jde-jdk-registry '(("1.4.2" . "/usr/local/j2sdk1.4.2_01/"))) (setq jde-jdk '("1.4.2")))) (eval-after-load "hideshow" '(progn (push '(latex-mode "^\\\\begin" "^\\\\end" "^%" (lambda (&optional ignored) (search-forward-regexp "\\\\begin{\\([^}]*\\)}") (beginning-of-line) (search-forward-regexp (format "^\\\\end{%s}" (match-string 1))) (next-line -1)) nil) hs-special-modes-alist))) (eval-after-load "highlight-fixmes-mode" '(progn (defun buffer-has-fixmes () (some (lambda (o) (eq (overlay-get o 'type) 'fixme)) (overlays-in (point-min) (point-max)))) (add-hook 'highlight-fixmes-mode-hook (lambda () (let ((block '(:eval (if (buffer-has-fixmes) (format " [%s]" (propertize (concat "FI" "XME") 'face 'bold)) "")))) (unless (member block mode-line-format) (setq mode-line-format (append (butlast mode-line-format) '((:eval (if (buffer-has-fixmes) (format " [%s]" (propertize (concat "FI" "XME") 'face 'bold)) ""))) (last mode-line-format))) (force-mode-line-update))))))) (defvar warn-buffers '("*scratch*")) (defun warn-before-killing-buffer () (when (and (member (buffer-name (current-buffer)) warn-buffers) (< (point-min) (point-max))) (unless (y-or-n-p (format "Really kill buffer %s? " (current-buffer))) (error "Not killing %s" (current-buffer))))) (add-hook 'kill-buffer-hook 'warn-before-killing-buffer) (when (featurep 'ascii-table) (defadvice ascii-table (before ascii-table-mst activate) (pop-to-buffer "*ASCII*"))) (when (try-require 'fold-dwim) (define-key global-map (kbd "C-c TAB") 'fold-dwim-toggle) (define-key global-map (kbd "C-c +") 'fold-dwim-show-all) (define-key global-map (kbd "C-c -") 'fold-dwim-hide-all)) (when (try-require 'uniquify) (setq uniquify-buffer-name-style nil)) ;; This should always be at the end (when (boundp 'dotemacs-loaded-hook) (run-hooks 'dotemacs-loaded-hook)) (custom-set-variables '(load-home-init-file t t)) (custom-set-faces)