;; WELCOME TO MY .EMACS ---------------------------------------- ;;; uncomment this line to disable loading of "default.el" at startup (setq inhibit-default-init t) (add-to-list 'load-path "/home/jconnors") (fset 'yes-or-no-p 'y-or-n-p) ;replace y-e-s by y ;; various external packages (require 'icomplete) (require 'ffap) (require 'hippie-exp) (require 'color-theme) (require 'etags-select) (setq color-theme-is-global nil) (defun random-color-theme () (interactive) (random t) (funcall (car (nth (random (length color-themes)) color-themes)))) (color-theme-calm-forest) (setq frame-title-format "%F: %b <%f %t %i> (%m)") (setq visible-bell 't) ;; enable visual feedback on selections (setq transient-mark-mode) (icomplete-mode 99) (partial-completion-mode 1) (setenv "CVSROOT" ":pserver:jconnors@jupiter:/cvsroot") ;; read in stuff that has changed.. (global-auto-revert-mode) ;; -- INDENTATION -------------------------------------------------------------------- (defun indent-buffer() "Indent the whole buffer from point-min to point-max using the command indent-region" (interactive) (indent-region 0 (point-max) nil)) ;; -- POINT STACK ----------------------------------------------------------------------- (defvar point-stack nil) (defun point-stack-push () "Push current location and buffer info onto stack." (interactive) (message "Location marked.") (ring-insert find-tag-marker-ring (point-marker))) (defun point-stack-pop () "Pop a location off the stack and move to buffer" (interactive) (pop-tag-mark)) (defun push-point-and-switch-to-buffer () "Mark current location and switch to buffer." (interactive) (let* ((dest-buffer-name (completing-read "Buffer: " (mapcar 'buffer-name (buffer-list)))) (dest-buffer (get-buffer dest-buffer-name))) (point-stack-push) (switch-to-buffer buffer))) ;; -- CUSTOM BEHAVIOUR ---------------------------------------- (defun goto-match-paren (arg) "Go to the matching parenthesis if on parenthesis, otherwise insert %. vi style of % jumping to matching brace." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((looking-at "\\s\)") (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1))))) (defun zap-upto-char (arg char) "Kill up to but not including ARG'th occurrence of CHAR. Case is ignored if `case-fold-search' is non-nil in the current buffer. Goes backward if ARG is negative; error if CHAR not found." (interactive "p\ncZap upto char: ") (if (char-table-p translation-table-for-input) (setq char (or (aref translation-table-for-input char) char))) (kill-region (point) (progn (search-forward (char-to-string char) nil nil arg) (if (minusp arg) (forward-char 1) (backward-char 1)) (point)))) (defun copy-to-char (arg char) "Copy region as Kill up and including ARG'th occurrence of CHAR. Case is ignored if `case-fold-search' is non-nil in the current buffer. Goes backward if ARG is negative; error if CHAR not found." (interactive "p\ncCopy upto char: ") (if (char-table-p translation-table-for-input) (setq char (or (aref translation-table-for-input char) char))) (copy-region-as-kill (point) (progn (search-forward (char-to-string char) nil nil arg) (point)))) (defun kill-syntax-forward () "Kill characters with syntax at point." (interactive) (kill-region (point) (progn (skip-syntax-forward (string (char-syntax (char-after)))) (point)))) (defun kill-syntax-backward () "Kill characters with syntax at point." (interactive) (kill-region (point) (progn (skip-syntax-backward (string (char-syntax (char-before)))) (point)))) (defun switch-to-minibuffer () (interactive) (select-window (minibuffer-window))) (defun switch-from-minibuffer () (interactive) (select-window (minibuffer-selected-window))) ;; -- KEYBINDINGS ---------------------------------------- (windmove-default-keybindings 'super) (ffap-bindings) ;; to do -- point stack pop other window ;; keybindings (global-set-key [(f3)] 'search-forward) (global-set-key [(control f3)] 'search-backward) (global-set-key [(meta f3)] 'search-forward-regexp) (global-set-key [(control meta f3)] 'search-backward-regexp) ;; unbind keys that piss me off (global-unset-key [(control z)]) ;; these keep causing problems (global-unset-key [(meta \')]) (global-unset-key [(meta @)]) (global-set-key [(meta \#)] 'push-point-and-switch-to-buffer) (global-set-key [(meta \')] 'point-stack-push) (global-set-key [(f4)] 'replace-string) (global-set-key [(shift f4)] 'query-replace) (global-set-key [(meta f4)] 'replace-regexp) (global-set-key [(shift meta f4)] 'query-replace-regexp) (global-set-key [(f12)] 'bs-show) (global-set-key [(super return)] 'balance-windows) (global-set-key [(meta kp-subtract)] 'shrink-window) (global-set-key [(meta kp-add)] 'enlarge-window) (global-set-key [(super kp-add)] 'split-window-vertically) (global-set-key [(super kp-multiply)] 'split-window-horizontally) (global-set-key [(super kp-subtract)] 'delete-window) (global-set-key [(mouse-3)] 'mouse-buffer-menu) (global-set-key [(shift mouse-3)] 'mouse-major-mode-menu) (global-set-key [(super .)] 'point-stack-push) (global-set-key [(super ,)] 'point-stack-pop) (global-set-key [(meta .)] 'etags-select-find-tag-at-point) (global-set-key [(meta ,)] 'pop-tag-mark) (global-set-key [(meta \?)] 'tags-loop-continue) (global-set-key [(meta k)] 'kill-syntax-forward) (global-set-key [(super K)] 'kill-syntax-backward) (global-set-key [(super s)] 'shell) (global-set-key [(super \\)] 'switch-cc-to-h) (global-set-key [f7] 'compile) (global-set-key [(super z)] 'undo) ;; this is a bad habit - windows incompatible (global-unset-key [(control w)]) (global-unset-key [(control y)]) ;; -- ENVIRONMENT ----------------------------------------------------------------------- (setenv "PATH" (concat "/home/jconnors/ffa_dev_linux/SVIPro/SVIPro/Linux64/debug" path-separator (getenv "PATH"))) ;; -- C++ ------------------------------------------------------------------------------ (setq ffap-c-path '("/usr/include" "/usr/local/include" "/home/jconnors/ffa_dev_linux/cimages3d" "/home/jconnors/ffa_dev_linux/SVIPro")) (require 'cc-mode) (load "c-function-signature.el") (defun he-tag-beg () (let ((p (save-excursion (backward-word 1) (point)))) p)) (defun try-expand-tag (old) (unless old (he-init-string (he-tag-beg) (point)) (setq he-expand-list (sort (all-completions he-search-string 'tags-complete-tag) 'string-lessp))) (while (and he-expand-list (he-string-member (car he-expand-list) he-tried-table)) (setq he-expand-list (cdr he-expand-list))) (if (null he-expand-list) (progn (when old (he-reset-string)) ()) (he-substitute-string (car he-expand-list)) (setq he-expand-list (cdr he-expand-list)) t)) (defconst ffa-c-style ;; Always indent c/c++ sources, never insert tabs '((c-tab-always-indent . t) ;; Offset for line only comments (c-basic-offset . 4) (c-comment-only-line-offset . 0) ;; Controls the insertion of newlines before and after braces. (c-hanging-braces-alist . ((substatement-open after) (brace-list-open))) ;; Controls the insertion of newlines before and after certain colons. (c-hanging-colons-alist . ((member-init-intro before) (inher-intro) (case-label after) (label after) (access-label after))) ;; List of various C/C++/ObjC constructs to "clean up". (c-cleanup-list . (scope-operator empty-defun-braces defun-close-semi)) ;; Association list of syntactic element symbols and indentation offsets. (c-offsets-alist . ((arglist-close . c-lineup-arglist) (substatement-open . 0) (case-label . +) (block-open . 0) (block-close . 0) (access-label . -) (inline-open . 0) (inline-close . 0) (label . 0) (innamespace . 0) (inher-cont . +) (knr-argdecl-intro . -))) (c-echo-syntactic-information-p . t) ) "FFa C/C++ Programming Style") (c-add-style "ffa" ffa-c-style) (add-hook 'c-mode-common-hook (lambda () ;; Do not check for old-style (K&R) function declarations; ;; this speeds up indenting a lot. (color-theme-blue-mood) (c-set-style "ffa") (setq c-recognize-knr-p nil) (setq c-basic-offset 4) (local-set-key [(control c) t] 'switch-cc-to-h) (local-set-key [(meta /)] (make-hippie-expand-function '(try-expand-dabbrev-visible try-expand-dabbrev-from-kill try-expand-dabbrev-all-buffers try-expand-tag try-complete-file-name-partially try-complete-file-name))))) (add-to-list 'auto-mode-alist '("\\.h$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.inl$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.xrc$" . xml-mode)) (add-to-list 'auto-mode-alist '("\\.asd$" . lisp-mode)) (add-to-list 'auto-mode-alist '("SConscript" . python-mode)) (add-to-list 'auto-mode-alist '("SConstruct" . python-mode)) (defun kill-c-scope () (interactive) (let ((inital-point (point))) (save-excursion (let ((beg (progn (c-beginning-of-defun) (point)))) (goto-char inital-point) (let ((end (progn (c-end-of-defun) (point)))) (kill-region beg end)))))) (defun c-wx-lineup-topmost-intro-cont (langelem) (save-excursion (beginning-of-line) (if (re-search-forward "EVT_" (line-end-position) t) 'c-basic-offset (c-lineup-topmost-intro-cont langelem)))) (add-to-list 'c++-font-lock-extra-types "\bwx[A-Z][a-z][a-zA-Z]*?\b" "\bSo[A-Z][a-z][a-zA-Z]*?\b") (add-hook 'c++-mode-hook (lambda () (c-set-style "ffa") ;; automatic indent on return in cc-mode (local-set-key "\r" 'newline-and-indent) (local-set-key [(super k)] 'kill-c-scope) (setq c-recognize-knr-p nil) (setq c-basic-offset 4) (turn-on-eldoc-mode) (c-set-offset 'topmost-intro-cont 'c-wx-lineup-topmost-intro-cont))) ;; Switch fromm *. to *. and vice versa (defun switch-cc-to-h () (interactive) (when (string-match "^\\(.*\\)\\.\\([^.]*\\)$" buffer-file-name) (let ((name (match-string 1 buffer-file-name)) (suffix (match-string 2 buffer-file-name))) (cond ((string-match suffix "c\\|cc\\|C\\|cpp") (cond ((file-exists-p (concat name ".h")) (find-file (concat name ".h"))) ((file-exists-p (concat name ".hh")) (find-file (concat name ".hh"))))) ((string-match suffix "h\\|hh") (cond ((file-exists-p (concat name ".cc")) (find-file (concat name ".cc"))) ((file-exists-p (concat name ".inl")) (find-file (concat name ".inl"))) ((file-exists-p (concat name ".C")) (find-file (concat name ".C"))) ((file-exists-p (concat name ".cpp")) (find-file (concat name ".cpp"))) ((file-exists-p (concat name ".c")) (find-file (concat name ".c"))))))))) ;; I hate semantic (load-file "/home/jconnors/cedet/common/cedet.el") (semantic-load-enable-minimum-features) ;; but I love ecb (add-to-list 'load-path "/home/jconnors/ecb") (require 'ecb) (defun insert-header-guard (buffer-name) (let* ((split-name (split-string buffer-name "[-_.]")) (guard-def (concat "H_" (mapconcat (lambda (x) (upcase x)) split-name "_")))) (save-excursion (progn (goto-char 0) (insert "#if !defined(") (insert guard-def) (insert ")\n") (insert "#define ") (insert guard-def) (insert "\n\n\n") (insert "#endif\n\n"))))) (defun make-guard () (interactive) (let ((header-name (file-name-nondirectory (file-name-sans-extension (buffer-file-name (current-buffer)))))) (if (string= (downcase (file-name-extension (buffer-file-name (current-buffer)))) "h") (insert-header-guard header-name)))) ;; to do -- make this customizable? (defvar *svi-pro-dir* "ffa_dev_linux") (defvar *svi-pro-branch* "BRANCH_DEV_SVIPRO_2_1_LINUX") (defvar *svi-pro-branch-history* '("BRANCH_DEV_SVIPRO_2_1_LINUX")) (defun svi-pro-root (suffix) (let ((result (concat "/home/jconnors/" *svi-pro-dir*))) (when suffix (setq result (concat result "/" suffix))) result)) (setq ffap-c-path (list (concat (svi-pro-root "SVIPro") (svi-pro-root "cimages3d")))) (defun update-svi-pro () (cd (svi-pro-root)) (shell-command "cvs update -dP")) (defun switch-svi-pro-branch () (interactive) (setq *svi-pro-dir* (read-directory-name "Directory? " "/")) (setq *svi-pro-branch* (completing-read "Branch? " nil nil nil *svi-pro-branch-history*)) (setq ffap-c-path (list (concat (svi-pro-root "SVIPro") (svi-pro-root "cimages3d")))) (add-to-list '*svi-pro-branch-history* *svi-pro-branch*)) ;; -- TAGGING ------------------------------------------------------------------------------ ;; Tagging (defun tag-svi-pro () (interactive) (shell-command (concat "find " (svi-pro-root "SVIPro") " -name \"*.h\" -o -name \"*.cpp\" | ectags --verbose -e -o " (svi-pro-root "SVIPro/TAGS") " --language-force=c++ --c++-kinds=cfnstunedm --extra=+q --options=/home/jconnors/ectags.cnf -L -&"))) (defun tag-segy () (interactive) (shell-command (concat "find " (svi-pro-root "SEGY") " -name \"*.h\" -o -name \"*.cpp\" | ectags --verbose -e -o " (svi-pro-root "SEGY/TAGS") " --language-force=c++ --c++-kinds=cfnstunedm --extra=+q --options=/home/jconnors/ectags.cnf -L -&"))) (defun tag-cimages3d () (interactive) (shell-command (concat "find " (svi-pro-root "cimages3d") " -name \"*.inl\" -name \"*.h\" -o -name \"*.cpp\" | ectags --verbose -e -o " (svi-pro-root "cimages3d/TAGS") " --language-force=c++ --c++-kinds=cfnstunedm --extra=+q --options=/home/jconnors/ectags.cnf -L -&"))) (defun tag-locals () (interactive) (shell-command "find /usr/local/include -name \"*.h\" | ectags --verbose -e -o /home/jconnors/TAGS --options=/home/jconnors/ectags.cnf -L -&")) ;; -- COMMON LISP ------------------------------------------------------------------------------ (add-to-list 'load-path "/home/jconnors/packages/clbuild/source/slime") (add-to-list 'load-path "/home/jconnors/packages/clbuild/source/slime/contrib") (require 'paredit) (autoload 'paredit-mode "paredit" "Minor mode for pseudo-structurally editing Lisp code." t) (require 'slime) (slime-setup '(slime-autodoc slime-asdf)) (add-hook 'slime-mode-hook (lambda () (color-theme-lawrence) (paredit-mode +1))) (add-hook 'lisp-mode-hook (lambda () (color-theme-lawrence) (paredit-mode +1))) (add-hook 'slime-repl-mode-hook (lambda () (paredit-mode +1))) (setq inferior-lisp-program "sbcl") ;; Paredit mode (define-key paredit-mode-map (kbd "(") 'paredit-open-parenthesis) (define-key paredit-mode-map (kbd ")") 'paredit-close-parenthesis) (define-key paredit-mode-map (kbd "M-(") (lambda () (interactive) (insert "("))) (define-key paredit-mode-map (kbd "M-)") (lambda () (interactive) (insert ")"))) (define-key paredit-mode-map (kbd "M-j") 'paredit-newline) (define-key paredit-mode-map (kbd "RET") nil) (define-key paredit-mode-map (kbd "C-i") 'slime-indent-and-complete-symbol) (define-key paredit-mode-map (kbd "C-t") 'transpose-sexps) (define-key paredit-mode-map (kbd "C-M-t") 'transpose-chars) (define-key paredit-mode-map (kbd "C-b") 'backward-sexp) (define-key paredit-mode-map (kbd "C-M-b") 'backward-char) (define-key paredit-mode-map (kbd "C-f") 'forward-sexp) (define-key paredit-mode-map (kbd "C-M-f") 'forward-char) (defslime-repl-shortcut slime-max-debug ("max-debug") (:handler (lambda () (interactive) (insert "(declaim (optimize (debug 3) (speed 0) (safety 3) (compilation-speed 0)))") (slime-repl-send-input))) (:one-liner "Declaim max debug properties")) (defslime-repl-shortcut slime-max-speed ("max-speed") (:handler (lambda () (interactive) (insert "(declaim (optimize (debug 0) (speed 3) (safety 0) (compilation-speed 0)))") (slime-repl-send-input))) (:one-liner "Declaim max speed optimisation properties")) (defslime-repl-shortcut slime-max-sanity ("max-sanity") (:handler (lambda () (interactive) (insert "(declaim (optimize (debug 2) (speed 2) (safety 2) (compilation-speed 2)))") (slime-repl-send-input))) (:one-liner "Declaim sane optimisation properties")) (global-set-key [(f8)] 'slime-selector) ;; -- CUSTOM STUFF ------------------------------------------------------------------------------ (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(PC-include-file-path (quote ("/usr/include" "/usr/local/include" "/home/jconnors/ffa_dev_linux/cimages3d" "/home/jconnors/ffa_dev_linux/SVIPro"))) '(backup-directory-alist (quote (("." . "/home/jconnors/.backups")))) '(c-basic-offset 4) '(c-default-style (quote ((c-mode . "ffa") (c++-mode . "ffa") (java-mode . "java") (awk-mode . "awk") (other . "gnu")))) '(c-doc-comment-style (quote ((c-mode . autodoc) (c++-mode . autodoc) (java-mode . javadoc) (pike-mode . autodoc)))) '(column-number-mode t) '(compile-command "ant -e -Darch=Linux64 -Dconfig=debug") '(completion-auto-help t) '(completion-show-help nil) '(cua-mode t nil (cua-base)) '(ecb-layout-window-sizes (quote (("right1" (0.2569832402234637 . 0.2876712328767123) (0.2569832402234637 . 0.3424657534246575) (0.2569832402234637 . 0.3561643835616438)) ("left14" (0.2011173184357542 . 0.7397260273972602) (0.2011173184357542 . 0.2465753424657534))))) '(ecb-options-version "2.33beta1") '(ecb-source-path (quote ("/usr/include" ("/home/jconnors" "home") "/home/jconnors/ffa_dev_linux"))) '(find-tag-marker-ring-length 256) '(grep-files-aliases (quote (("el" . "*.el") ("ch" . "*.[ch]") ("c" . "*.c") ("h" . "*.h") ("asm" . "*.[sS]") ("m" . "[Mm]akefile*") ("l" . "[Cc]hange[Ll]og*") ("tex" . "*.tex") ("texi" . "*.texi") ("cpp" . "*.cpp *.inl *.h")))) '(grep-highlight-matches t) '(grep-scroll-output t) '(gud-gdb-command-name "gdb --fullname --cd /home/jconnors/ffa_dev_linux/SVIPro") '(history-length 255) '(indent-tabs-mode nil) '(minibuffer-auto-raise t) '(partial-completion-mode t) '(rcirc-default-nick "ZabaQ") '(rcirc-default-user-full-name "John Connors") '(rcirc-default-user-name "ZabaQ") '(save-place t nil (saveplace)) '(scroll-bar-mode nil) '(scroll-conservatively 1) '(scroll-step 1) '(show-paren-mode t) '(size-indication-mode t) '(slime-compilation-finished-hook nil) '(slime-display-compilation-output nil) '(tab-width 4) '(tags-table-list (quote ("/home/jconnors/TAGS" "/home/jconnors/ffa_dev_linux/SVIPro/TAGS" "/home/jconnors/ffa_dev_linux/cimages3d/TAGS"))) '(tool-bar-mode nil) '(transient-mark-mode t) '(uniquify-buffer-name-style (quote forward) nil (uniquify)) '(use-file-dialog nil) '(warning-suppress-types (quote ((undo discard-info))))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) (put 'downcase-region 'disabled nil)