;; -*- Mode: Emacs-Lisp -*- ;; malcy emacs customization 1997-2000 ;; $Id: dot.emacs,v 1.6 2002/04/30 02:44:40 malc Exp $ ;; $Log: dot.emacs,v $ ;; Revision 1.6 2002/04/30 02:44:40 malc ;; Cleanups, fume extension, Haskell, Clean ;; ;; Revision 1.5 2001/08/01 22:52:40 malc ;; Various Bergen extensions ;; ;; Revision 1.4 2000/11/15 02:47:11 malc ;; Added Emacs bkdir, tuareg, some Emacs be like XEmacs advices, ;; right-align-* functions etc ;; ;; Revision 1.3 2000/06/30 23:01:12 malc ;; Cleaned up a bit ;; ;; Revision 1.2 2000/06/30 22:19:55 malc ;; Lots ;; (setq completion-auto-help t;; I want as much help as I can get completion-auto-exit t;; Don't want to always hit return track-eol t print-escape-newlines t inhibit-startup-message t default-major-mode 'text-mode garbage-collection-messages t ;; show position line-number-mode t column-number-mode t next-line-add-newlines nil require-final-newline t indent-tabs-mode nil signal-error-on-buffer-boundary nil ;; autosave auto-save-directory (expand-file-name "~/autosave/") auto-save-directory-fallback auto-save-directory auto-save-hash-p nil efs-auto-save t efs-auto-save-remotely nil efs-nslookup-program "/usr/bin/nslookup -silent" ;; now that we have auto-save-timeout, let's crank this up ;; for better interactive response. auto-save-interval 0 auto-save-timeout 0 ;; preffer konqueror/kfmclient here browse-url-browser-function 'browse-url-kde ;; little compilation window compilation-window-height 9 ;; remove anoying bell bell-volume 0 ;; bs-default-sort-name "by mode" ;; said to improve remote speed interprogram-cut-function nil interprogram-paste-function nil ;; gc var gc-cons-threshold 5000000) (setq-default font-lock-maximum-decoration t) (defvar running-xemacs (string-match "XEmacs" (emacs-version))) (defvar running-fsfemacs (string-match "GNU Emacs" (emacs-version))) (defvar running-windows (eq window-system 'windows)) ;; This is here to avoid hitting X FSF bytecode incompatibilities ;; *.el in ~/lib/emacs is simply ln -s'ed to X or FSF subdir and ;; then bytecompiled (setq my-lib-path (if running-xemacs (expand-file-name "~/lib/emacs/X") (expand-file-name "~/lib/emacs/FSF"))) (setq load-path (cons my-lib-path load-path)) (defun byte-compile-specific-files () (dolist (name (directory-files my-lib-path t ".el$")) (byte-compile-file name))) ;; Misc (defun re-kill-buffers (re) (interactive "sRegexp: \n") (dolist (b (mapcan (lambda (e) (if (string-match re (buffer-name e)) (list e) ())) (buffer-list))) (kill-buffer b))) (defun right-align-region-str (what beg end) (interactive "sWhat to look for: \nr") (let ((ps '()) (max-point -1) (slen (string-width what)) (bpat (concat "[^ ] *" what))) (save-excursion (goto-char beg) (while (and (< (point) end) (re-search-forward what end t)) (let ((bol (point-at-bol)) (pm (1- (point)))) (re-search-backward bpat bol t) (forward-char) (let ((pw (point))) (setq ps (cons (cons pm pw) ps)) (setq max-point (max (- pw bol) max-point)))) (forward-line 1)) (if (= max-point -1) (message "%s not found in region" what) (dolist (pp ps) (let* ((pm (car pp)) (pw (cdr pp)) (xx (goto-char pw)) (pd (+ (- pw pm) (- max-point (- pw (point-at-bol))) slen))) (goto-char pw) (if (> pd 0) (insert-char ?\ pd) (delete-backward-char pd)))))))) (defun right-align-= (beg end) (interactive "r") (right-align-region-str "=" beg end)) (defun right-align-> (beg end) (interactive "r") (right-align-region-str "->" beg end)) (cond (running-fsfemacs (pc-selection-mode) (pc-bindings-mode) (global-font-lock-mode t) (setq font-lock-maximum-decoration t) (global-set-key [C-delete] 'kill-word) (setq auto-mode-alist (append auto-mode-alist '(("\\.py$" . python-mode)))) (autoload 'python-mode "python-mode" "Major mode for editing python scripts." t) (defun describe-function-at-point () (interactive) (describe-function (function-called-at-point))) (defun describe-variable-at-point () (interactive) (variable-at-point)))) (cond (running-xemacs ;; Shift + keys select region, ;; shift-del shift-ins ctrl-del ctrl-ins operate on region (require 'crypt) (require 'pc-select) (pc-select-mode) ;; font lock (require 'font-lock) ;; (global-set-key [(control delete)] 'kill-word) ;; (global-set-key [(meta backspace)] 'undo) ;; (global-set-key [(control backspace)] 'backward-kill-word) (setq delete-key-deletes-forward t complex-buffers-menu-p t mouse-yank-at-point t) ; think ;; modify frame title to show what exactly we are editing (setq frame-title-format '("%S: " (buffer-file-name "%f" (diired-directory dired-directory "%b")))))) (defun my-delete-window () (interactive) (if (> (count-windows) 1) (delete-window))) (defun good-buffer-p (&optional buffer) (let ((buffer-name (buffer-name buffer))) (or (member buffer-name '("*scratch*" "*cvs*")) (not (string-match "^ ?\\*.*\\*$" buffer-name))))) (defun my-kill-this-buffer-and-window () (interactive) (kill-this-buffer) (if (= (count-windows) 2) (delete-window)) (or (good-buffer-p) (switch-to-buffer (or (find-if 'good-buffer-p (buffer-list)) "*scratch*")))) (defun my-recompile () (interactive) (let ((compilation-ask-about-save nil)) (recompile))) ;; buffer cycling (autoload 'cycle-buffer "cycle-buffer" "Cycle forward." t) (autoload 'cycle-buffer-backward "cycle-buffer" "Cycle backward." t) (autoload 'cycle-buffer-permissive "cycle-buffer" "Cycle forward allowing *buffers*." t) (autoload 'cycle-buffer-backward-permissive "cycle-buffer" "Cycle backward allowing *buffers*." t) (autoload 'cycle-buffer-toggle-interesting "cycle-buffer" "Toggle if this buffer will be considered." t) ;; ********************************************************************** ;; hooks ;; ********************************************************************** (defun my-lisp-mode-hook () (put 'stateless-bean 'scheme-indent-function 'defun) (put 'with-slots 'lisp-indent-function 2) (put 'with-open-file 'lisp-indent-function 'defun) (put 'with-open-stream 'lisp-indent-function 'defun)) (add-hook 'lisp-mode-hook 'my-lisp-mode-hook) (add-hook 'emacs-lisp-mode-hook 'my-lisp-mode-hook) (defun my-c-mode-hook () (local-set-key [(return)] 'newline-and-indent) (c-set-style "bsd") (setq c-basic-offset 2) (c-set-offset 'case-label '+)) (add-hook 'c-mode-hook 'my-c-mode-hook) (add-hook 'c++-mode-hook 'my-c-mode-hook) (add-hook 'jde-mode-hook 'my-c-mode-hook) ;;; ======================================================================= ;;; borrowed from sample.emacs from XEmacs distro (with minor modifications) ;;; ======================================================================= ;;; ******************** ;;; Load the default-dir.el package which installs fancy handling ;;; of the initial contents in the minibuffer when reading ;;; file names. (if (and running-xemacs (or (and (>= emacs-major-version 20) (>= emacs-minor-version 1)) (and (>= emacs-major-version 19) (>= emacs-minor-version 15)))) (require 'default-dir)) ;;; ******************** ;;; Load the auto-save.el package, which lets you put all of your autosave ;;; files in one place, instead of scattering them around the file system. ;;; ;; We load this afterwards because it checks to make sure the ;; auto-save-directory exists (creating it if not) when it's loaded. ;;; ******************** ;;; resize-minibuffer-mode makes the minibuffer automatically ;;; resize as necessary when it's too big to hold its contents. (when running-xemacs (autoload 'resize-minibuffer-mode "rsz-minibuf" nil t) (resize-minibuffer-mode) (setq resize-minibuffer-window-exactly nil)) (custom-set-variables '(tuareg-use-abbrev-mode nil) '(tuareg-in-indent 0) '(tuareg-library-path "/usr/lib/ocaml/") '(tuareg-let-always-indent nil) '(tuareg-type-indent 0) '(toolbar-visible-p nil) '(tuareg-manual-url "") '(sml-program-name "mosml") '(user-mail-address "malc@pulsesoft.com" t) '(query-user-mail-address nil) '(indent-tabs-mode nil) '(semanticdb-persistent-path (list (quote never))) '(tuareg-with-indent 0)) (when running-xemacs (require 'backup-dir) (setq bkup-backup-directory-info '((t "/home/malc/.backups" ok-create full-path prepend-name)))) (defun my-add-message (arg) ;;;;- Tue Sep 5 09:36:23 2000 by Malcy - added to .emacs (interactive "sMessage: ") (forward-line 0) (insert-string (concat " - " (current-time-string) " by " (user-full-name) " - " arg " ")) (newline) (backward-to-indentation 1) (indent-according-to-mode) (comment-region (point) (point-at-eol)) (forward-line 1) (indent-according-to-mode)) ;;; ********************************************************************** ;;; OCaml ;;; ********************************************************************** (setq completion-ignored-extensions (append '(".cmo" ".cmx" ".cma" ".cmxa" ".cmi") completion-ignored-extensions)) (defun caml-comment-till-end-of-line (&optional arg) (interactive "P") (save-excursion (if (looking-at search-whitespace-regexp) (re-search-forward search-whitespace-regexp)) (comment-region (point) (progn (end-of-line) (point)) arg))) (defun my-caml-mode-hook () (setq compilation-window-height 9)) (require 'caml) (require 'caml-font) (setq auto-mode-alist (cons '("\\.ml[iylp]?$" . caml-mode) auto-mode-alist)) (add-hook 'caml-mode-hook 'my-caml-mode-hook) ;;; ********************************************************************** ;;; SML ;;; ********************************************************************** (defun my-sml-mode-hook () (setq sml-indent-rule (cdr sml-indent-rule))) (autoload 'sml-mode "sml-mode" "Major mode for editing SML." t) (autoload 'run-sml "sml-proc" "Run an inferior SML process." t) (setq auto-mode-alist (cons '("\\.sml$" . sml-mode) auto-mode-alist)) (add-hook 'sml-mode-hook 'my-sml-mode-hook) ;;; ********************************************************************** ;;; Haskel ;;; ********************************************************************** (defun my-haskell-mode-hook () (define-key haskell-mode-map [(delete)] 'delete-char)) (setq auto-mode-alist (append auto-mode-alist '(("\\.[id]cl$" . haskell-mode) ; clean really ("\\.[hg]s$" . haskell-mode) ("\\.hi$" . haskell-mode) ("\\.l[hg]s$" . literate-haskell-mode)))) (autoload 'haskell-mode "haskell-mode" "Major mode for editing Haskell scripts." t) (autoload 'literate-haskell-mode "haskell-mode" "Major mode for editing literate Haskell scripts." t) (add-hook 'haskell-mode-hook 'my-haskell-mode-hook) (add-hook 'haskell-mode-hook 'turn-on-haskell-font-lock) (add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan) (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) (add-hook 'haskell-mode-hook 'turn-on-haskell-indent) (add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent) (add-hook 'haskell-mode-hook 'turn-on-haskell-hugs) ;;; ;;; ;;; (defun inside (p) (save-excursion (if (re-search-backward "^[^\"]*\\(\"[^\"]*\"\\)*[^\"]*\"" (point-at-bol) t) (progn (message "%d:%d" (match-end 0) p) (not (= p (match-end 0)))) t))) (defun match-paren (arg) "Go to the matching parenthesis if on parenthesis otherwise insert %." (interactive "p") (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1)) ((and (looking-at "\\s\)") (inside (point))) (forward-char 1) (backward-list 1)) (t (self-insert-command (or arg 1))))) (when running-fsfemacs (defadvice describe-key (after dcxba activate) (switch-to-buffer-other-window "*Help*")) (defadvice describe-mode (after dmxba activate) (switch-to-buffer-other-window "*Help*")) (defadvice describe-function (after dfxba activate) (switch-to-buffer-other-window "*Help*")) (defadvice apropos-command (after acba activate) (switch-to-buffer "*Apropos*") (delete-other-windows))) (autoload 'nuke-trailing-whitespace "whitespace" "Remove empty space" t) (autoload 'mwheel-install "mwheel" "Scroll with wheel" t) (require 'bs) (mwheel-install) (defvar jode-program nil) (defun jode (arg) (interactive "FClass: ") (let* ((cname (file-name-sans-extension (file-name-nondirectory arg))) (bname (concat cname ".java"))) (shell-command (concat jode-program " " cname) bname) (delete-window) (java-mode) (font-lock-mode) (font-lock-fontify-buffer))) (defun insert-quotes () (interactive) (insert "\"\"")) ;; redefine global and mode specific key sequences (global-set-key "%" 'match-paren) (global-set-key "\C-x\C-b" 'bs-show) (global-set-key [(f8)] 'bs-show) (global-set-key [(f5)] 'compile) (global-set-key [(f6)] 'my-recompile) (global-set-key [(alt ?9)] 'insert-parentheses) (global-set-key [(alt ?')] 'insert-quotes) (global-set-key [(alt q)] 'my-kill-this-buffer-and-window) (global-set-key [(alt w)] 'my-delete-window) (global-set-key [(f11)] 'describe-function-at-point) (global-set-key [(f12)] 'describe-variable-at-point) (global-set-key [(alt right)] 'cycle-buffer) (global-set-key [(alt left)] 'cycle-buffer-backward) (global-set-key [(alt shift right)] 'cycle-buffer-permissive) (global-set-key [(alt shift left)] 'cycle-buffer-backward-permissive) (global-set-key [(alt ?\;)] 'caml-comment-till-end-of-line) (define-key lisp-mode-map [(return)] 'newline-and-indent) (define-key lisp-mode-map "\C-c\C-c" 'comment-region) (define-key caml-mode-map [(return)] 'newline-and-indent) (define-key caml-mode-map [(delete)] 'delete-char) (define-key caml-mode-map "\C-c\C-c" 'comment-region) ;; Add hot keys to common menu options ;; and F10 as global menu accesser (when running-xemacs (relabel-menu-item '("File") "%_File") (relabel-menu-item '("Edit") "%_Edit") (relabel-menu-item '("Apps") "%_Apps") (relabel-menu-item '("Options") "%_Options") (relabel-menu-item '("Buffers") "%_Buffers") (relabel-menu-item '("Tools") "%_Tools") (relabel-menu-item '("Help") "%_Help") (setq menu-accelerator-enabled 'menu-fallback) (setq menu-accelerator-modifiers '(alt)) (setq menu-accelerator-prefix nil) (define-key global-map 'f10 'accelerate-menu)) (require 'uniquify) (setq uniquify-buffer-name-style 'post-forward-angle-brackets) (setq uniquify-after-kill-buffer-p t) ;; ====================================================================== ;; Function menu + Caml support ;; ====================================================================== (when running-xemacs (require 'func-menu) (define-key fume-list-mode-map "/" 'isearch-forward) (define-key fume-list-mode-map "?" 'isearch-backward) (define-key fume-list-mode-map [(f7)] 'fume-list-functions-quit) (define-key fume-list-mode-map "r" 'fume-rescan-buffer) (define-key fume-list-mode-map [(return)] 'fume-prompt-function-goto-one-window) (global-set-key [(f7)] 'fume-list-functions) (defvar fume-function-name-regexp-ocaml (concat "^\\(let\\(\\s-+rec\\)?" "\\|and" "\\|\\s-*val\\(\\s-+mutable\\)?" "\\|\\s-*method\\(\\s-+virtual\\|\\s-+private\\)?" "\\|\\s-*value\\(\\s-+rec\\)?\\)" "\\s-+\\([a-z_][A-Za-z0-9_']*\\)") "Expression to get ocaml function/variable names") (defun fume-find-next-ocaml-function-name (buffer) ;;- Wed Sep 26 15:05:27 2001 by Malcy - incorrectly assumes that and belongs to let "Searches for the next ocaml function in BUFFER." (set-buffer buffer) (if (re-search-forward fume-function-name-regexp-ocaml nil t) (let* ((fst (match-beginning 0)) (pos (match-beginning 6)) (sop (match-end 6)) (name (buffer-substring pos sop))) (if (or (string-equal name "_") (caml-in-comment-p)) (fume-find-next-ocaml-function-name buffer) (save-excursion (goto-char fst) (let ((delim (cond ((looking-at "\\s-*method") ":") ((looking-at "\\s-*val") "::")))) (cond ((and delim (re-search-backward (concat "^\\s-*class" "\\(\\s-+type\\|\\s-+type\\s-+virtual\\|\\s-+virtual\\)?" "\\(\\s-+\\[[ \t,'a-zA-Z0-9]+\\]\\)?" "\\s-+\\([a-z_[A-Za-z0-9_']*\\)") nil t)) (setq name (concat (buffer-substring (match-beginning 3) (match-end 3)) delim name))))) (cons name pos)))))) (setq fume-function-name-regexp-alist (append '((tuareg-mode . fume-function-name-regexp-ocaml) (caml-mode . fume-function-name-regexp-ocaml)) fume-function-name-regexp-alist) fume-find-function-name-method-alist (append '((tuareg-mode . fume-find-next-ocaml-function-name) (caml-mode . fume-find-next-ocaml-function-name)) fume-find-function-name-method-alist))) (defun insert-clipboard-or-x-yank () (interactive "") (condition-case nil (yank-clipboard-selection) (error (x-insert-selection)))) (setq desktop-globals-to-save '(desktop-missing-file-warning)) (require 'session) (require 'desktop) (add-hook 'after-init-hook (lambda () (session-initialize) (desktop-load-default) (desktop-read))) (make-face 'font-lock-number-face) (set-face-foreground 'font-lock-number-face "DodgerBlue4") (setq font-lock-number-face 'font-lock-number-face) (defvar font-lock-number "[0-9]+\\([eE][+-]?[0-9]*\\)?") (defvar font-lock-hexnumber "0[xX][0-9a-fA-F]+") (add-hook 'font-lock-mode-hook (function (lambda () (setq font-lock-keywords (append font-lock-keywords (list (list (concat "\\<\\(" font-lock-number "\\)\\>" ) (list 0 font-lock-number-face)) (list (concat "\\<\\(" font-lock-hexnumber "\\)\\>" ) (list 0 font-lock-number-face)))))))) ;(when running-xemacs ; (add-to-list 'load-path "/mnt/big/npf/incoming/semantic-1.4beta11") ; (setq semantic-load-turn-everything-on t) ; (require 'semantic-load) ; (add-hook 'senator-minor-mode-on-hook ; (lambda () ; (relabel-menu-item '("Tokens") "T%_okens") ; (relabel-menu-item '("Senator") "%_Senator")))) (autoload 'setnu-mode "setnu" "Line numbers mode" t) (require 'ru-keys) ;;; ;;; AUC TeX ;;; (require 'tex-site) (add-hook 'tex-mode-hook #'(lambda () (auto-fill-mode) (refill-mode) (flyspell-mode t))) ;;; Local Variables: ;;; End: