;; This is the Aquamacs Preferences file. ;; Add Emacs-Lisp code here that should be executed whenever ;; you start Aquamacs Emacs. If errors occur, Aquamacs will stop ;; evaluating this file and print errors in the *Messags* buffer. ;; Use this file in place of ~/.emacs (which is loaded as well.) (iconify-frame) (server-start) (tool-bar-mode 0) (setq auto-mode-alist (append '(("\\.sql$" . sql-mode) ("\\.c\\+\\+$" . c++-mode) ("\\.cxx$" . c++-mode) ("\\.cc$" . c++-mode) ("\\.C$" . c++-mode) ("\\.in$" . c++-mode) ("\\.i$" . c++-mode) ("\\.rpc$" . c-mode) ("\\.uil$" . c-mode) ("\\.c$" . c-mode) ("\\.m$" . c-mode) ("\\.h$" . c++-mode) ("\\.a$" . ada-mode) ("\\.emacs$" . emacs-lisp-mode) ("\\.el$" . emacs-lisp-mode) ("\\.tmpl$" . makefile-mode) ("/bash-fc-[0-9]*$" . sh-mode) ("\\.out$" . compilation-mode) ("\\.[0-9]+$" . text-mode) ("\\.r[0-9]+$" . text-mode) ;svn conflicts ("\\.tmp$" . text-mode) ;svn comments ;;("\\.html$" . html-helper-mode) ("\\.jsp$" . html-mode) ("\\.vm$" . html-mode) ("\\.xml$" . html-mode) ("\\.xsd$" . html-mode) ("\\.html?\\.[a-z][a-z]$" . html-mode) ("\\.js$" . java-mode) ("xrdb.txt" . xrdb-mode) ) auto-mode-alist )) (prefer-coding-system 'utf-8-unix) (setq diff-switches "-u" tab-width 4 exec-path (append (list (expand-file-name "~/bin") "/sw/bin" "/usr/local/bin" ) exec-path)) ;;{{{ align-eq (defun align-eq (start end) "Align assignment/comparison operators in region." (interactive "*r") ;; in case some mode stole it ;; (local-set-key "\C\M=" 'align-eq) (save-excursion (save-restriction ;; be sure we have BOL for first line (goto-char start) (beginning-of-line) (setq start (point)) ;; be sure we have EOL for last line (goto-char end) (end-of-line) (setq end (point)) (narrow-to-region start end) (save-excursion (goto-char (point-min)) (while (> (point-max) (point)) (and (looking-at "[^=\n]*=") (goto-char (match-end 0)) (fixup-whitespace) (skip-syntax-backward ".") (fixup-whitespace)) (beginning-of-line 2))) (let ((goalcol 0) thiscol) (goto-char (point-min)) (while (> (point-max) (point)) (and (looking-at "[^=\n]*=") (goto-char (match-end 0)) (setq thiscol (current-column)) (> thiscol goalcol) (setq goalcol thiscol) ) (beginning-of-line 2)) (goto-char (point-min)) (while (> (point-max) (point)) (cond ((and (looking-at "[^=\n]*=") (goto-char (match-end 0)) (setq thiscol (current-column)) (< thiscol goalcol)) (backward-char) (while (looking-at "[=!><~+-*/^&|.]") (backward-char) (setq thiscol (1- thiscol))) (forward-char) (setq thiscol (1+ thiscol)) (insert (make-string (- goalcol thiscol) ? )))) (beginning-of-line 2)))))) ;;}}} ;;{{{ my-spell-word (defun my-spell-word (arg) "Calls ispell-word, or with ARG, ispell-buffer." (interactive "P") (require 'ispell) (if arg (ispell-message) (ispell-word))) ;;}}} ;;{{{ my-save-buffer-kill-frame (defun my-save-buffer-kill-frame (arg) "Saves buffer, if necessary (with ARG, w/o asking), and then kills it and its frame." (interactive "P") (let ((buf (current-buffer)) (delete-frame nil) (kill-buffer nil)) (if (and (buffer-file-name buf) (buffer-modified-p) (or arg (y-or-n-p (format "Save buffer %s? " (buffer-name))))) (save-buffer nil)) (setq kill-buffer (or (not (buffer-modified-p buf)) (not (buffer-file-name buf)) (yes-or-no-p (concat "Buffer " (buffer-name buf) " modified; kill anyway? ")))) (setq delete-frame (if (and (one-window-p) (or arg (unwind-protect (y-or-n-p "Delete frame as well? ") (message "")))) (selected-frame) nil)) (delete-windows-on buf) (if kill-buffer (progn (save-excursion (set-buffer buf) (set-buffer-modified-p nil)) (kill-buffer buf))) (if delete-frame (if (> (length (frame-list)) 1) (delete-frame (selected-frame)) (iconify-frame (selected-frame)))))) ;;}}} ;;{{{ path-expand (defun path-expand () "Expand the word around point as a command name take from $PATH." (interactive "*") (let* ((fake-outs '(?- ?@ ?. ?_)) (old-fakes (mapcar '(lambda (char) (cons char (char-syntax char))) fake-outs)) start end) (unwind-protect (progn (mapcar '(lambda (char) (modify-syntax-entry char "w")) fake-outs) (if (not (looking-at "\\<")) (forward-word -1)) ; (mark-word) unworks, why? (setq start (point)) (forward-word) (setq end (point)) (shell-command-on-region start end (concat "which " (buffer-substring start end)) t) (delete-char -1) ; burn newline ) (mapcar '(lambda (char-val) (modify-syntax-entry (car char-val) (char-to-string (cdr char-val)))) old-fakes)))) ;;}}} ;;{{{ toggle-line-wrap (defun toggle-line-wrap () "Toggles the line-wrap (or line-truncate, depending on yourperspective) function. Covers (and equates) both horizontal andvertical splits." (interactive) (longlines-mode) (recenter (- (count-lines (window-start) (point)) (if (bolp) 0 1)))) ;;}}} ;;{{{ Script creation and debugging ;;{{{ make-cee-script (defun make-cee-script (arg) "Make the current buffer into a cee script. With arg, nukes first." (interactive "*P") (cond ((or arg (= (- (point-min) (point-max)) 0)) (python-mode) (erase-buffer) (insert-file-contents-literally "~/bin/ceetplt.py"))) (save-buffer) (shell-command (concat "chmod a+x " (shell-quote-argument (buffer-file-name)))) (goto-char (point-min)) (search-forward "Your Documentation Goes Here" nil t)) ;;}}} ;;{{{ make-perl-script (defun make-perl-script (arg) "Make the current buffer into a perl script. With arg, nukes first." (interactive "*P") (cond ((or arg (= (- (point-min) (point-max)) 0)) (perl-mode) (erase-buffer) (insert-file-contents-literally "~/bin/debug.pl"))) (if (search-forward "gud-perldb-history: " nil t) (insert (concat "(\"perl " (shell-quote-argument (file-name-nondirectory (buffer-file-name))) "\")"))) (goto-char (point-min)) (when (search-forward "perl -cw " nil t) (let ((beginning (set-marker (make-marker) (point)))) (save-restriction (save-excursion (insert (buffer-file-name)) (narrow-to-region beginning (point)) (goto-char (point-min)) (when (looking-at "^[a-z]:") (while (search-forward "\\" nil t) (replace-match "/" nil t))) (goto-char (point-max)) (insert "\\\"")))) (insert "\\\"") ) (save-buffer) (shell-command (concat "chmod a+x " (shell-quote-argument (buffer-file-name)))) (goto-char (point-min)) (search-forward "print STDERR \"Usage: $me: [-\", join(\" | -\", @opts), \"]" nil t)) ;;}}} ;;{{{ make-python-script (defun make-python-script (arg) "Make the current buffer into a python script. With arg, nukes first." (interactive "*P") (cond ((or arg (= (- (point-min) (point-max)) 0)) (python-mode) (insert-file-contents-literally "~/bin/debug.py" nil nil nil t))) (save-buffer) (shell-command (concat "/bin/chmod a+x " (shell-quote-argument (buffer-file-name)))) (shell-command (concat "/usr/local/bin/svn add " (shell-quote-argument (buffer-file-name)))) (shell-command (concat "/usr/local/bin/svn pset svn:eol-style native " (shell-quote-argument (buffer-file-name)))) (shell-command (concat "/usr/local/bin/svn pset svn:executable 1 " (shell-quote-argument (buffer-file-name)))) (shell-command (concat "/usr/local/bin/svn pset svn:keywords 'Id URL Author Date Rev' " (shell-quote-argument (buffer-file-name)))) (goto-char (point-min)) (search-forward "XXX" nil t)) ;;}}} ;;{{{ make-shell-script (defun make-shell-script (arg) "Make the current buffer into a ksh script. With arg, nukes first." (interactive "*P") (cond ((or arg (= (- (point-min) (point-max)) 0)) (sh-mode) (erase-buffer) (insert-file-contents-literally "~/bin/debug.bash") (sh-set-shell "/bin/bash" t nil) (if (search-forward "# eval: (if (fboundp 'sh-mode) (sh-mode))\n" nil t) (insert "# compile-command: \"" (shell-quote-argument (file-name-nondirectory (buffer-file-name))) " -n \"\n")))) (save-buffer) (shell-command (concat "chmod a+x " (shell-quote-argument (buffer-file-name)))) (goto-char (point-min)) (search-forward "usage=\"Usage: $0 \[-$flags\]" nil t)) ;;}}} ;;{{{ Global key bindings (require 'sgml-mode) (global-set-key "\M-z" 'advertised-undo) ; Remove zap-to-char!!!! (global-unset-key "\C-z") ; Remove iconify-or-deiconify-frame (global-set-key [(meta ctrl =)] 'align-eq) (global-set-key [(ctrl meta z)] 'pp-window-configuration) (global-set-key "\C-\\" 'compare-windows) (global-set-key "\C-c\`" 'find-this-error) (global-set-key "\C-r" 'isearch-backward-regexp) (global-set-key "\C-s" 'isearch-forward-regexp) (global-set-key "\C-c/" 'sgml-close-tag) ;;(global-set-key "\C-x4k" 'kill-buffer-other-window) (global-set-key "\C-x\C-e" 'compile) (global-set-key "\C-x\C-k" 'kill-compilation) (global-set-key "\C-x\M-\e" 'electric-command-history) (global-unset-key "\C-xm") (global-set-key "\C-xw" 'toggle-line-wrap) (global-set-key "\M-$" 'my-spell-word) (global-set-key "\M-?" 'tags-search) (global-set-key "\M-%" 'query-replace-regexp) (global-set-key "\M-{" 'insert-braces) (global-set-key "\M-G" 'goto-line) ;;(global-set-key "\M-\C-\\" 'two-window-command) (global-set-key "\M-\C-g" 'what-line) ;; (global-set-key "\M-\C-r" 'append-rtn-addr-to-paragraph) (global-set-key "\M-\C-s" 'isearch-forward) (global-set-key "\M-\C-t" 'insert-time-stamp) (global-set-key "\M-\C-u" 'up-list) (global-set-key "\M-\\" 'fixup-whitespace) (global-set-key "\M-`" 'next-error) (global-set-key "\M-g" 'goto-line) (global-set-key "\M-s" 'center-line) (global-set-key [f1] 'advertised-undo) (global-set-key [f2] 'x-kill-primary-selection) (global-set-key [f3] 'x-copy-primary-selection) (global-set-key [control f11] 'call-last-kbd-macro) (global-set-key [control button4] 'scroll-down) (global-set-key [control button5] 'scroll-up) (global-set-key [button4] (function (lambda (arg) (interactive "P") (scroll-down 1)))) (global-set-key [button5] (function (lambda (arg) (interactive "P") (scroll-up 1)))) (when window-system (substitute-key-definition 'save-buffer-kill-buffer 'my-save-buffer-kill-frame (current-global-map)) (substitute-key-definition 'save-buffer-kill-buffer 'save-buffers-kill-emacs (current-global-map)) (substitute-key-definition 'save-buffers-kill-emacs 'my-save-buffer-kill-frame (current-global-map))) ;;}}} ;;{{{ ibuff-menu (setq ibuff-initial-sublist-modes "fdpk" ibuff-bury-buffers-regexp (concat "^\\(" (mapconcat 'identity (list " .*" "sent .*" "\\*ftp .*" "\\*vc.*" "\\.ibuff-.*" "\\+.*" "\\*Help\\*" "\\*Directory\\*" "\\*Completions\\*" "\\*Dired log\\*" "\\*Compile-Log\\*" "\\.infonotes" "\\.newsrc") "\\|") "\\)$") ibuff-hide-buffers-regexp "^\\( \\|show-\\+\\|\\*info\\*\\|diary\\)" ibuff-preserve-match-and-mode t) ;; (autoload 'ibuff-menu "ibuff-menu" "Edit the buffer list." t) (global-set-key "\C-x\C-b" (or (and (condition-case nil (require 'ibuff-menu) (error nil)) 'ibuff-menu) (and (require 'ebuff-menu) 'electric-buffer-list))) ;;}}} (autoload 'electric-command-history "echistory" t) ;;{{{ pp-window-configuration (defvar pp-window-configuration () "Holds the stack of former window configurations. Form: (list (list window-configuration point-in-current) ...)") (defun pp-window-configuration (arg &optional thunk) "Save current window config (with ARG, restore ; with ARG>=16,flush) ; Optional THUNK on save executed after eventual restore." (interactive "p") (cond ((and (numberp arg) (>= arg 16)) (setq pp-window-configuration nil) (message "Window configuration stack cleared.")) ((or (not (numberp arg)) (and (numberp arg) (> arg 1))) ;; Push current window configuration (setq pp-window-configuration (append (list (list (current-window-configuration) (point-marker) thunk)) pp-window-configuration)) (message "Window configuration %d saved." (length pp-window-configuration))) (t ;; Pop a prior window configuration (if any) (if (= 0 (length pp-window-configuration)) (message "Window configuration stack is empty.") (let* ((ppwc (car pp-window-configuration)) (wc (nth 0 ppwc)) (p (nth 1 ppwc)) (thunk (nth 2 ppwc))) (setq pp-window-configuration (cdr pp-window-configuration)) (set-window-configuration wc) (goto-char p) (eval thunk)) (message "Window configuration %d restored" (length pp-window-configuration)))))) ;;}}} ;;{{{ Advice (setq ad-start-advice-on-load t ad-activate-on-definition t) (require 'advice) ;;{{{ crontab (defadvice crontab-get (before pp-for-crontab activate) "Stack window configuration" (pp-window-configuration t)) (defadvice crontab-save (after pp-for-crontab activate) "Unstack window configuration" (pp-window-configuration nil)) ;;}}} ;;{{{ find-tag (defadvice find-tag (before pp-for-tags activate) "Stack window configuration, as with function calls." (unless (and (boundp 'inhibit-pp-for-tags) inhibit-pp-for-tags) (pp-window-configuration t))) ;;}}} ;;{{{ tags-apropos (defadvice tags-apropos (before pp-for-tags activate) "Stack window configuration, as with function calls." (unless (and (boundp 'inhibit-pp-for-tags) inhibit-pp-for-tags) (pp-window-configuration t))) ;;}}} ;;{{{ tags-continue (defadvice tags-loop-continue (around inhibit-pp-for-tags activate) "Avoid pp-for-tags in helpers." (let ((inhibit-pp-for-tags t)) ad-do-it)) ;;}}} ;;{{{ tags-search (defadvice tags-search (before pp-for-tags activate) "Stack window configuration, as with function calls." (unless (and (boundp 'inhibit-pp-for-tags) inhibit-pp-for-tags) (pp-window-configuration t))) ;;}}} ;;}}} ;;{{{ insert-time-stamp (defun insert-time-stamp () "Insert current date and time." (interactive "*") (insert (current-time-string))) ;;}}} ;;{{{ insert-braces ;;; Dave Brennan has a copy ;;; might as well forward ;;; him any improvements as well! (defun insert-braces (arg) "Insert matched braces, leave point inside. With ARG, all on one line." (interactive "*P") (if arg (progn (insert "{}") (backward-char)) (let (blink-paren-function) ;nil it temporarily (execute-kbd-macro "{ }")) (backward-sexp 1) (end-of-line) (execute-kbd-macro " "))) ;;}}} ;;{{{ my-fundamental-mode-hook (defun my-fundamental-mode-hook nil "If editing a crontab file, don't backup-by-copying." (if (string-match "^/tmp/crontab\\..*" (buffer-file-name)) (setq make-backup-files nil)) ) ;;}}} ;;{{{ my-dired-mode-hook (defun my-dired-mode-hook () "Make common find-file gestures be \"other window\"." (local-set-key "e" 'my-dired-find-file-other-frame) ) (defun my-dired-find-file-other-frame (arg) "My extension to dired." (interactive "P") (find-file-other-frame (dired-get-file-for-visit))) ;;}}} ;;{{{ my-lisp-hook (defun my-lisp-hook () ;;(local-set-key "\033q" 'indent-sexp) ;;(local-set-key "\033j" 'indent-sexp) (local-set-key "\M-\C-d" 'edebug-defun) ;;(local-set-key "\M-\C-r" 'eval-region) (local-set-key "\C-x\C-e" 'byte-compile-file) (make-local-variable 'edebug-all-defuns); when set, eval-region edebugs (setq byte-compile-warnings '(unused-vars unresolved callargs redefine obsolete)) (auto-fill-mode 1)) ;;}}} ;;{{{ my-lisp-interaction-mode-hook (defun my-lisp-interaction-mode-hook () (local-set-key "\r" 'newline-and-indent)) ;;}}} ;;{{{ my-sh-mode-hook (defun my-sh-mode-hook () (if (eq 'sh-shell-file nil) (sh-set-shell "/bin/bash" t nil))) ;;}}} ;;{{{ my-text-hook (defun my-text-hook () (auto-fill-mode 1) (setq adaptive-fill-mode 1) (make-local-variable 'indent-line-function) (local-set-key "\C-?" 'backward-delete-char-untabify) ;; (local-set-key "\M-\C-q" 'quote-paragraph) (local-set-key "\C-i" 'indent-relative) ;; (local-set-key "\M-\C-r" 'append-rtn-addr-to-paragraph) ;; (setq indent-line-function 'indent-relative-maybe) (setq paragraph-separate "^$\\|^ \\|^ *$\\|^-+$" paragraph-start paragraph-separate) (setq fill-column 64) (modify-syntax-entry ?\" "\"")) ;;}}} ;;{{{ my-write-file-hook (defun my-write-file-hook () (save-restriction (save-excursion (widen) (goto-char (point-min)) (let ((date-pattern (concat "[a-z]\\{3\\} " "[a-z]\\{3\\} " "[ 0-9]\\{2\\} " "[:0-9]\\{8\\} " "[0-9]\\{4\\}[ap]?")) (case-fold-search t)) (if (re-search-forward (cond ((eq major-mode 'text-mode) (concat "\\(\\s *Modified:\\s *\\)" date-pattern "\\(.*\\)")) ((eq major-mode 'c-mode) (concat "\\(\\s *\\*\\s *Modified:\\s *\\)" date-pattern "\\(.*\\)")) ((eq major-mode 'jde-mode) (concat "\\(//\\s *Modified:\\s *\\)" date-pattern "\\(.*\\)")) (t (concat "\\(\\s<\\s *Modified:\\s *\\)" date-pattern "\\(\\s>*\\)"))) nil t) (replace-match (concat "\\1" (current-time-string) "\\2")))) (cond ((memq major-mode (list 'perl-mode 'jde-mode)) ;; SourceCast standards are: no tabs (untabify (point-min) (point-max)) ;; (clear-ws-eol (point-min) (point-max)) )))) (time-stamp) nil) ;;}}} ;;; Hooks (add-hook 'text-mode-hook 'my-text-hook) (add-hook 'dired-mode-hook 'my-dired-mode-hook) (add-hook 'emacs-lisp-mode-hook 'my-lisp-hook) (add-hook 'lisp-mode-hook 'my-lisp-hook) (add-hook 'lisp-interaction-mode-hook 'my-lisp-interaction-mode-hook) (add-hook 'find-file-hooks 'my-fundamental-mode-hook)