;;; .emacs --- Phil Hollenback's ultra emacs config file ;; Copyright (c) 2000 Philip J. Hollenback ;; ;; Based on Jeff Jones' .emacs and various other sources ;; off the web. ;; ;; Everyone's .emacs rips off someone else's... ;; ;; $Id: .emacs.el,v 1.26 2000/09/07 22:00:08 philip Exp philip $ ;; Commentary: An amalgamation of ideas from many sources. First, notice the ;; section headers - they look like that for use in outline-mode. Type C-c @ ;; C-t to get a listing of all the headings, type the usual motion keys to ;; move among them, & type C-c @ C-a to see all the text again. I remap the ;; outline-minor-mode-prefix to C-c C-k, which I find easier to type. A ;; "Local Variables" section at the end of this file sets up outline mode ;; appropriately. ;; ;; This file is completely cross-compatible between XEmacs and GNU Emacs, ;; although I am considering dropping GNU Emacs compatibility as I never use ;; it and that would make this file much simpler. ;; ;; I place all my emacs packages in ~/.emacstuff, and furthermore there are ;; links to ~/.Xdefaults and ~/.emacs there. That way I can tar up the whole ;; directory and move it easily. ;; ;; My key bindings are similar to what a lot of other folks use, and in ;; addition I try to cover all the cases on a remote xterm, where regular ;; keybindings seem to fail. ;; ;; I include extensive cc-mode and vc-mode customizations that make program ;; editing very pleasant. Most of these changes were contributed by Harvey ;; Thompson at Lutris, a company I used to work for. ;;;; Global Settings ;;;; ;; Provide a useful error trace if loading this monster fails. (setq debug-on-error t) ;; Put all my collected emacs packages and files in my-emacs-dir ;; Note that I also put my .emacs in there and link to ~/.emacs. ;; That way I can easily bundle the dir and give it to others. (if (boundp 'running-xemacs) ; Xemacs doesn't understand ~ expansion directly. (setq my-emacs-dir (expand-file-name "~/.emacstuff/")) ;(else GNU Emacs (setq my-emacs-dir "~/.emacstuff/") ;concat this to dir names. ) (setq load-path (cons my-emacs-dir load-path)) ;; Load my defaults from another file. Again, makes distributing this file ;; easier. These defaults are things like my name and email address. (load (expand-file-name "~/.private.el")) ;;;;; Global Functions ;;;;; ;; Some functions that change global behaviors, so they should be at top of ;; file. (defun mark-line-and-copy () "Copy the current line into the kill ring." (interactive) (beginning-of-line) (push-mark) (forward-line 1) (kill-ring-save (region-beginning) (region-end)) (message "line copied")) (defun duplicate-line () "Copy this line under it; put point on copy in current column." (interactive) (let ((start-column (current-column))) (save-excursion (mark-line-and-copy) ;save-excursion restores mark (yank)) (forward-line 1) (move-to-column start-column)) (message "line dup'ed")) (defun duplicate-region () "Copy this region after itself." (interactive) (let ((start (dot-marker))) (kill-ring-save (region-beginning) (region-end)) (yank) (goto-char start)) (message"region dup'ed")) ;; Get rid of that annoying prompt that requires one to type ;; in Y-E-S and then press the friggin enter key to confirm. (defun yes-or-no-p (PROMPT) (beep) (y-or-n-p PROMPT)) ;;;;; Global Keybindings ;;;;;; ; Now the functions are defined, we can assign them to keys. (global-set-key (kbd "C-c C-y") 'duplicate-line) (global-set-key (kbd "C-c y") 'duplicate-region) (global-set-key (kbd "C-c Y") 'duplicate-line) (global-set-key (kbd "C-c C-l") 'mark-line-and-copy) ;has many modal ;remappings (global-set-key (kbd "C-c l") 'mark-line-and-copy) ;; keyboard mods not specific to any mode. ;; note the use of kbd function to make these work in emacs or ;; xemacs. (global-set-key (kbd "C-h") 'delete-backward-char) ;backspace, not help! (global-set-key (kbd "C-c g") 'goto-line) (global-set-key (kbd "") 'beginning-of-line) ;instead of top-of-screen (global-set-key (kbd "") 'end-of-line) ;inactive by default? (global-set-key (kbd "C-") 'beginning-of-buffer) ;M$-style beginning and (global-set-key (kbd "C-") 'end-of-buffer) ;same bindings for (global-set-key (kbd "") 'delete-char) ; delete char, don't ; move cursor. (global-set-key (kbd "M-C-h") 'backward-kill-word) (global-set-key (kbd "") 'other-window) ;convenient shortcuts. (global-set-key (kbd "") 'kill-this-buffer) (global-set-key (kbd "") 'speedbar-get-focus) ;jump to the speedbar. (global-unset-key (kbd "ESC ESC")) ;eval-expr gets in my way. (global-set-key (kbd "C-x C-u") 'undo) ;bind to something useful. (global-set-key (kbd "C-`") 'capitalize-word) ;I want c-~, but ;that's too ;hard to type. ;; Duplicates of some of the keys above so everything works ;; properly on remote xterms. (global-set-key "\eOH" 'beginning-of-line) (global-set-key "\eOF" 'end-of-line) (global-set-key "\e[1~" 'beginning-of-line) (global-set-key "\e[4~" 'end-of-line) (global-set-key "\e[1^" 'beginning-of-buffer) (global-set-key "\e[4^" 'end-of-buffer) (global-set-key "\e[11~" 'help) (global-set-key "\e[12~" 'other-window) (global-set-key "\e[13~" 'kill-this-buffer) (global-unset-key "\e\e") ;; Keys that Jeff likes - maybe I'll try them too. (global-set-key (kbd "C-x C-k") 'compile) (global-set-key (kbd "C-x C-j") 'fill-paragraph) ;; Make the sequence "C-x w" execute the `what-line' command, which ;; prints the current line number in the echo area. (global-set-key (kbd "C-x w") 'what-line) ; Unfortunately there's no common way to bind mouse events in the ; different emacsen. (if (boundp 'running-xemacs) (global-set-key [(shift button2)] ;-mouse2 to load 'browse-url-at-mouse) ;url at point into ;netscape. ;(else GNU Emacs (global-set-key [(shift down-mouse-2)] ;-mouse2 to load 'browse-url-at-mouse) ;url at point into netscape. ) ;;;;; Global Settings ;;;;; ;; Miscellaneous settings (setq global-font-lock-mode t) ;fontify everything. (setq inhibit-startup-message t) ;don't need it anymore. (setq transient-mark-mode t) ;where's that selection? (setq lpr-command "a2ps") ;use my favorite print program. (setq lpr-switches nil) (setq mouse-yank-at-point t) ;paste at point NOT at cursor (setq next-line-add-newlines nil) ;no newlines if I cursor past EOF. (standard-display-european t) ;disable multibyte support. (setq minibuffer-max-depth nil) ;enable multiple minibuffers: ;I didn't understand this for a long time - if you don't set this, ;you can't do things like search the minibuffer history with M-s ;(cause that requires another minibuffer) (setq browse-url-browser-function ;call netscape on URLs. (quote browse-url-netscape)) (setq browse-url-new-window-p t) ;open a fresh netscape window. (if (boundp 'running-xemacs) (progn ;make the modeline time display show up on dark background. (setq display-time-display-time-foreground "tomato") ;I put my mail in a non-standard location. (setq display-time-mail-file (expand-file-name "~/nsmail/Inbox")) ; Make sure delete key always deletes forward in cc mode. (setq delete-key-deletes-forward t) ) ) ;; Don't truncate lines in vertically split windows (suggested by Jeff). (setq truncate-partial-width-windows nil) ;; Set up default editing mode. (setq default-major-mode 'indented-text-mode) (toggle-text-mode-auto-fill) ;always auto-fill in text mode, ;mein fuehrer!! ;; Turn off the menu bar if we're not in a window system (if (not (boundp 'running-xemacs)) (menu-bar-mode (if window-system 1 -1)) ) ;; Some window system specific settings. (cond (window-system (display-time) (setq line-number-mode t) (setq column-number-mode t) ) ) ;;;; Package Load and Configuration ;;;; ;;;;; gnuclient / emacsclient ;;;;; ;; Start the server to enable emacsclient or gnuclient ;; (only under X, so skip if on the console). (cond (window-system ; Make server available for emacsclient or gnuclient. (if (boundp 'running-xemacs) (gnuserv-start) ;(else GNU Emacs (progn ; Cause emacsclient to bring up files in a new window. ; Otherwise you have to hunt for open emacsen. (defun my-make-frame (&optional parameters) "Create a new frame, displaying the current buffer, and switch to the new frame" (interactive) (make-frame parameters) (other-frame 1)) (defun my-server-visit-hook () ;my-make-frame keeps old frame from getting copy ; of buffer as well. (my-make-frame) ; Force fontification (font-lock-fontify-buffer)) (add-hook 'server-visit-hook 'my-server-visit-hook) (defun my-server-done-hook () ; Clean up by removing frame. (delete-frame)) (add-hook 'server-done-hook 'my-server-done-hook) (server-start) (message "emacs server started")) ) )) ;end window-system cond. ;;;;; outline-mode ;;;;; (setq outline-minor-mode-prefix (kbd "C-c C-k")) ;default is "^C@"; "\C-c\C-@" fails mysteriously (setq-default paragraph-separate "[ \t]*$\\|====\\|שששש\\|^ ") (setq-default paragraph-start "[ \t]*$\\|====\\|שששש\\|[ \t]+[+>]\\|^ ") (setq parse-sexp-ignore-comments t) ;;;;; filladapt-mode ;;;;; ;; (filladapt.el) Augment the standard fill-mode ;; with more smarts - handles multiply quoted mail text, for example. (require 'filladapt) ; always use filladapt in several modes (add-hook 'text-mode-hook 'turn-on-filladapt-mode) (add-hook 'emacs-lisp-mode 'turn-on-filladapt-mode) ;;;;; uniquify ;;;;; ;; give buffers more intelligent names. ;; standard emacs/xemacs package. (require 'uniquify) ; create unique buffer names with shared directoy components. (setq uniquify-buffer-name-style 'forward) ;;;;; crypt ;;;;; ;; transparently open compress or encrypted files. ;; standard emacs/xemacs package. (require 'crypt) ;;;;; a2ps-print ;;;;; ;; print buffer or region using a2ps (load "a2ps-print") (global-set-key (kbd "") 'a2ps-buffer) (global-set-key "\e[15~" 'a2ps-buffer) (global-set-key (kbd "S-") 'a2ps-region-1) (global-set-key "\e[28~" 'a2ps-region-1) ;;;;; iswitchb ;;;;; ;; A quicker way to switch between buffers. C-xb will ;; give a list of buffers, and what you then type is matched as a ;; substring. One of those things that is hard to explain, but very ;; easy to use. Standard GNU Emacs package. (iswitchb-default-keybindings) ;;;;; rsz-minibuf ;;;;; ;; Enable dynamic minibuffer resizing. (if (boundp 'running-xemacs) (require 'rsz-minibuf) ;(else GNU Emacs (require 'rsz-mini) ) ; Fix problem with yes-or-no-p not showing enough text. (setq resize-minibuffer-window-exactly nil) ; Turn on automatic minibuffer resize. (resize-minibuffer-mode 1) ;;;;; php-mode ;;;;; ;; Add a mode for editing php code. ;; http://www.ontosys.com/reports/PHP.html (autoload 'php-mode "php-mode" "PHP editing mode" t) (add-to-list 'auto-mode-alist '("\\.php\\'" . php-mode)) (add-to-list 'auto-mode-alist '("\\.php3\\'" . php-mode)) (add-to-list 'auto-mode-alist '("\\.php4\\'" . php-mode)) ;;;;; redo ;;;; ;; Handy little redo function (redo.el) ;; http://www.wonderworks.com/ (require 'redo) (global-set-key (kbd "C-x C-r") 'redo) ;consistent with my undo. ;;;;; whitespace ;;;;; ;; An extremely powerful package to strip whitespace from a file. If all ;; developers would use this, diff problems would be eliminated and code ;; would be cleaner. (whitespace.el). ;; http://www.splode.com/users/friedman/software/emacs-lisp/ (autoload 'nuke-trailing-whitespace "whitespace" nil t) ; Strip whitespace when saving files. whitespace.el contains a list ; of modes to operate in. ; This appears to cause console GNU Emacs to segfault, you have been ; warned... (add-hook 'write-file-hooks 'nuke-trailing-whitespace) ;;;;; rect-mark ;;;;; ;; Support for marking a rectangle of text with highlighting (rect-mark.el). ; Only needed for emacs - xemacs has something similar built in. ; ftp://ls6-ftp.cs.uni-dortmund.de/pub/src/emacs/ (if (boundp 'running-xemacs) ; Just bind mouse rectangle select similarly to rect-mark.el on GNU Emacs. ; Note you can't show a rectangular region during keyboard select - ; only during mouse select. (progn (global-set-key [(shift button1)] 'mouse-track-do-rectangle) (global-set-key (kbd "C-x r C-SPC") 'set-mark-command) (global-set-key (kbd "C-x r C-x") 'exchange-point-and-mark) (global-set-key (kbd "C-x r C-w") 'kill-rectangle) ) ;(else GNU Emacs (progn (global-set-key (kbd "C-x r C-SPC") 'rm-set-mark) (global-set-key (kbd "C-x r C-x") 'rm-exchange-point-and-mark) (global-set-key (kbd "C-x r C-w") 'rm-kill-region) (global-set-key (kbd "C-x r M-w") 'rm-kill-ring-save) ;- now does a rectangular mark. (global-set-key [(shift down-mouse-1)] 'rm-mouse-drag-region) (autoload 'rm-set-mark "rect-mark" "Set mark for rectangle." t) (autoload 'rm-exchange-point-and-mark "rect-mark" "Exchange point and mark for rectangle." t) (autoload 'rm-kill-region "rect-mark" "Kill a rectangular region and save it in the kill ring." t) (autoload 'rm-kill-ring-save "rect-mark" "Copy a rectangular region to the kill ring." t) (autoload 'rm-mouse-drag-region "rect-mark" "Drag out a rectangular region with the mouse." t) ) ) ;;;;; ldap ;;;;; ;; Emacs Unified Directory Client - ldap, bbdb, etc. client (if (boundp 'running-xemacs) (progn (require 'eudc) ; Control the order eudc client searches for matches. This seems to ; catch everything I want. Note that if you want wildcard searches, ; you have to create them yourself, i.e. type in "phi*" to match ; everyone who's name starts with phi. (eudc-protocol-set 'eudc-inline-query-format '((cn) (cn cn) (cn cn cn) (sn) (givenname) (uid) (mail)) 'ldap) ; Be a little looser in matching. (setq eudc-strict-return-matches nil) ; Bind C-c for inline email address expansion in several modes. (eval-after-load "message" '(define-key message-mode-map (kbd "C-c TAB") 'eudc-expand-inline)) (eval-after-load "sendmail" '(define-key mail-mode-map (kbd "C-c TAB") 'eudc-expand-inline)) (eval-after-load "post" '(define-key post-mode-map (kbd "C-c TAB") 'eudc-expand-inline)) ) ) ;;;;; sql ;;;;; (autoload 'sql-oracle "sql" "Interactive SQL mode." t) (add-hook 'sql-mode-hook 'turn-on-font-lock) (add-to-list 'auto-mode-alist '("\\.sql\\'" . sql-mode)) ; Add sql-indent for better indentation control. (eval-after-load "sql" (progn (load-library "sql-indent") (setq sql-indent-offset 4))) (setq sql-electric-stuff (quote semicolon)) (setq sql-indent-offset 4) (setq sql-indent-offset 4) ;;;;; catdoc ;;;;; ;; Wrapper for catdoc to convert word files into text (catdoc.el). ;; http://www.tardis.ed.ac.uk/~skx/win/catdoc.el (require 'catdoc) ;;;;; dired-a ;;;;; ;; Some dired extensions (dired-a.el) ;; Only works with GNU Emacs. ;; http://www.deja.com/getdoc.xp?AN=522707065&fmt=raw (if (not (boundp 'running-xemacs)) (require 'dired-a) ) ;;;;; post ;;;;; ;; mutt mail message editing mode (post.el) ;; http://astro.utoronto.ca/~reid/mutt/ (require 'post) ;; Add an informative message when editing mail messages under post.el. ;; I should combine these cases more elegantly. (if (boundp 'running-xemacs) (defadvice gnuserv-process-filter (after post-mode-message first activate) "If the buffer is in post mode, overwrite the server-edit message with a post-save-current-buffer-and-exit message." (if (eq major-mode 'post-mode) (message (substitute-command-keys "Type \\[describe-mode] for help composing; \ \\[post-save-current-buffer-and-exit] when done.")))) ;(else GNU Emacs (defadvice server-process-filter (after post-mode-message first activate) "If the buffer is in post mode, overwrite the server-edit message with a post-save-current-buffer-and-exit message." (if (eq major-mode 'post-mode) (message (substitute-command-keys "Type \\[describe-mode] for help composing; \ \\[post-save-current-buffer-and-exit] when done.")))) ) ; Make sure we get moved to the message body when using gnuclient ; or emacsclient. (if (boundp 'running-xemacs) (add-hook 'gnuserv-visit-hook (function (lambda() (cond ((string-match "Post" mode-name) (post-goto-body)))))) ;(else GNU Emacs (add-hook 'server-switch-hook (function (lambda() (cond ((string-match "Post" mode-name) (post-goto-body)))))) ) ;; Customize post mode a bit. (defun my-post-mode-hook () ;Turn on abbrev mode ; (sort of a simple auto-correct for common mispellings). (setq abbrev-mode t) (read-abbrev-file (concat my-emacs-dir ".post_abbrev_defs")) (setq save-abbrevs t) ;Add a key binding for ispell-buffer. (local-set-key (kbd "C-c C-i") 'ispell-buffer) ;Put the cursor just where I want it - at the beginning of the body ;text. (post-goto-body) (beginning-of-line) ;(insert "\n") ;Bind ldap lookup to a key. (local-set-key (kbd "C-c C-m") 'insert-ldap-mail-search) ) (add-hook 'post-mode-hook 'my-post-mode-hook) ;;;;; psgml ;;;;; ;; Configure sgml/xml modes (psgml.el). (require 'psgml) (setq sgml-set-face t) ;set face of parsed markup. (setq sgml-indent-step nil) ;how much to increment ;indent for each level. (setq sgml-live-element-indicator t) ;display element name in ;modeline. (setq sgml-auto-activate-dtd t) ;parse document ;automatically when loaded. (setq sgml-balanced-tag-edit t) ;always insert start-end ;tag pairs. (setq sgml-auto-insert-required-elements t) ;insert required elements. (setq sgml-normalize-trims t) ;remove trailing ;whitespace before ;inserting tags. (setq sgml-auto-activate-dtd t) ;; Recognize Lutris Enhydra doml files as xml. (add-to-list 'auto-mode-alist '("\\.doml$" . xml-mode)) ; Make a custom dtd available on the DTD menu so we can insert it into ; doml files which lack a DTD line. (setq sgml-custom-dtd '(("Enhydra doml" ""))) ; Necessary because sgml-mode redefines some mappings which should be ; reserved for the user. (add-to-list 'sgml-mode-hook '(lambda () (local-set-key (kbd "C-c l") 'mark-line-and-copy)) ) (add-to-list 'sgml-mode-hook '(lambda () (local-set-key (kbd "C-c o") 'delete-other-windows)) ) (add-to-list 'sgml-mode-hook ; Automatically indent on '(lambda () (local-set-key (kbd "RET") 'newline-and-indent)) ) (setq sgml-markup-faces (quote ((start-tag . font-lock-variable-name-face) (end-tag . font-lock-variable-name-face) (comment . font-lock-comment-face) (pi . font-lock-keyword-face) (sgml . bold) (doctype . font-lock-preprocessor-face) (entity . bold-italic) (shortref . bold)))) ;;;;; dictionary ;;;;; ;; Enable dictionary mode (dictionary.el). With this, you can do a ;; M-x dictionary-search and search a number of free ;; dictionaries on the web for a definition. Works great. ;; http://www.in-berlin.de/User/myrkr/dictionary.html (autoload 'dictionary-search "dictionary" "Ask for a word and search it in all dictionaries" t) (autoload 'dictionary-match-words "dictionary" "Ask for a word and search all matching words in the dictionaries" t) (autoload 'dictionary "dictionary" "Create a new dictionary buffer" t) ; Assign keyboard shortcuts C-c s and C-c m. (global-set-key (kbd "C-c s") 'dictionary-search) (global-set-key (kbd "C-c m") 'dictionary-match-words) ;;;;; cc-mode ;;;;; ;; Customize cc-mode. ; Use the newest version of cc-mode (currently doesn't work with emacs 20.7). ;(if (boundp 'running-xemacs) ; (setq load-path (cons ; (concat my-emacs-dir "cc-mode-5.27" ) load-path)) ;) (defun c-newline-and-perhaps-comment (&optional soft) "Insert a newline and continue commenting if inside a C style comment. This function usually inserts a newline character. However it has several other actions; If point is within a one line comment /* ... */ then point is moved to the next line of code . If point is directly after /* then a multi-line comment block is written and point placed on the first line. If point is within a multi-line comment, then a newline starting with a '*' is added at the correct indentation. If point is after an empty line, any remaining white space is removed. If c-auto-newline is on, then the correct indentation is placed on the next line regardless. The inserted newline is marked hard if `use-hard-newlines' is true, unless optional argument SOFT is non-nil." (interactive) (let ((auto-fill-function nil)) (save-match-data (cond (;; ;; Inside a one line comment? ;; (and (save-excursion (end-of-line) (let ((eol-pos (point))) (beginning-of-line) (re-search-forward "/\\*.*\\*/" eol-pos t))) (>= (point) (match-beginning 0)) (<= (point) (match-end 0))) ;; ;; Then goto next line. ;; (end-of-line) (if soft (insert ?\n) (newline)) (if c-auto-newline (indent-according-to-mode))) (;; ;; Inside a block comment? ;; (save-excursion (and (re-search-backward "/\\*\\|\\*/" 0 t) (string= "/*" (buffer-substring (match-beginning 0) (match-end 0))))) ;; ;; Check if we just wrote "/*", if so build a comment block. ;; (if (save-excursion (end-of-line) (re-search-backward "/\\*\\([^ \t]*\\)\\(.*\\)" (save-excursion (beginning-of-line) (point)) t)) (let ((col (save-excursion (goto-char (match-beginning 0)) (current-column))) (start (buffer-substring (match-beginning 1) (match-end 1))) (text (buffer-substring (match-beginning 2) (match-end 2)))) (if (/= (length text) 0) (delete-region (match-beginning 2) (match-end 2)) (setq text " ")) (if soft (insert ?\n) (newline)) (indent-to-column col) (insert " *" text) (if soft (insert ?\n) (newline)) (indent-to-column col) (if (/= (length start) 1) (insert " ")) ;; ;; Handle JavaDoc convention correctly. (ie. /** ... */) ;; (if (string-equal start "*") (insert " ") (insert start)) (insert "*/") (previous-line 1) (end-of-line)) ;; ;; Otherwise continue the comment block. ;; (if soft (insert ?\n) (newline)) (indent-according-to-mode) (insert "*") (indent-relative))) (;; ;; After an empty line? ;; (save-excursion (beginning-of-line) (looking-at "[ ]+$")) (delete-region (match-beginning 0) (match-end 0)) (if soft (insert ?\n) (newline)) (if c-auto-newline (indent-according-to-mode))) (;; ;; Otherwise just do a normal newline. ;; (if soft (insert ?\n) (newline)) (if c-auto-newline (indent-according-to-mode))) )))) (defun parse-file-name (filename) "Returns a list of strings which are the directory and file components of the FILENAME. If the first element of the list is the empty string, the FILENAME was absolute. Note that the filename is not canonicalized (ie. no redundant information is removed." (if (string-match "/" filename) (cons (substring filename 0 (match-beginning 0)) (parse-file-name (substring filename (match-end 0)))) (cons filename nil))) (defun file-name-containing-directory (filename &optional n) "Returns containing directory of FILENAME. With the optional Nth argument, gives that many containing directories, where 0 means return empty string." (let* ((dir (file-name-directory filename)) (comp (parse-file-name (directory-file-name (if dir dir ""))))) (mapconcat '(lambda (x) x) (nthcdr (- (length comp) (if n n 1)) comp) "/"))) (defun c-unique-file-identifier (form &optional upper basename dirs) "Create a unique file identifier based on FORM, which should be compatible with `format'. If optional argument UPPER is true, then produce in upper case, if optional BASENAME is true, then remove trailing suffix (after last `.'), if optional DIRS is non-zero then also include that many prefix directories." (let ((name (if (and basename (string-match "\.[^.]*$" (buffer-file-name))) (substring (buffer-file-name) 0 (match-beginning 0)) (buffer-file-name)))) (setq name (if (and dirs (> dirs 0)) (concat (file-name-containing-directory name dirs) "/" (file-name-nondirectory name)) (file-name-nondirectory name))) (format form (mapconcat '(lambda (ch) (cond ((and (>= ch ?a) (<= ch ?z)) (make-string 1 (if upper (+ ch (- ?A ?a)) ch))) ((and (>= ch ?A) (<= ch ?Z)) (make-string 1 ch)) (t "_"))) name "")))) (defun c-insert-conditional-include (&optional dirs) "Inserts cpp directives to only include this file once. With optional DIRS argument (or with a prefix argument) that many containing directories are also included." (interactive "P") (if (and dirs (not (numberp dirs))) (setq dirs (/ (logb (prefix-numeric-value dirs)) 2))) (save-excursion (let ((name (c-unique-file-identifier "_%s_" t nil dirs))) (beginning-of-buffer) (insert "#ifndef " name "\n#define " name "\n") (end-of-buffer) (insert "\n#endif /* " name " */\n")))) (defun c-narrow-to-function () "Narrows to the function which the point is in." (interactive) (save-excursion (narrow-to-region (progn (beginning-of-defun) (beginning-of-line) (while (not (or (looking-at "^[ \t]*$") (bobp))) (forward-line -1)) (if (looking-at "^[ \t]*$") (forward-line)) (point)) (progn (end-of-defun) (point))))) (defun c-insert-seperating-comment () "Inserts a seperating comment line." (interactive) (indent-according-to-mode) (insert "/* ") (insert-char ?= (- 73 (current-column))) (insert " */\n")) (defun c-insert-line-comment () "Inserts a seperating comment line." (interactive) (indent-according-to-mode) (insert "/* ") (insert-char ?- (- 73 (current-column))) (insert " */\n")) (defun c-mode-common-setup () (define-key c-mode-map (kbd "RET") 'c-newline-and-perhaps-comment) (setq comment-line-break-function 'c-newline-and-perhaps-comment) (turn-on-auto-fill) (setq fill-column 76) (define-key c-mode-map (kbd "C-c I") 'c-insert-conditional-include) (define-key c-mode-map (kbd "C-c F") 'c-narrow-to-function) (define-key c-mode-map (kbd "C-c S") 'c-insert-seperating-comment) (define-key c-mode-map (kbd "C-c L") 'c-insert-line-comment) (setq c-tab-always-indent nil) ; Tell cc-mode not to check for old-style (K&R) function ; declarations. This speeds up indenting a lot (I hear). (setq c-recognize-knr-p nil) ; Automatically go to newline and indent at end of each statement. (setq c-auto-newline t) ; Enable use of filladapt (filladapt.el) for better comment filling. (c-setup-filladapt) (filladapt-mode 1) ) (add-hook 'c-mode-common-hook 'c-mode-common-setup) ;;;;; java ;;;;; ;; Customize java modes. (defun java-mode-setup () (c-set-style "java") (define-key java-mode-map (kbd "RET") 'c-newline-and-perhaps-comment) (setq comment-line-break-function 'c-newline-and-perhaps-comment) (turn-on-auto-fill) (setq fill-column 76) (define-key java-mode-map (kbd "C-c S") 'c-insert-seperating-comment) (define-key java-mode-map (kbd "C-c L") 'c-insert-line-comment) (c-set-offset 'func-decl-cont '++) (setq c-tab-always-indent nil) ) (add-hook 'java-mode-hook 'java-mode-setup) ;;;;;; jde ;;;;;; ;; Load up the Java Dev Environment ;; http://sunsite.auc.dk/jde/ ;(setq load-path ; (nconc (list (concat my-emacs-dir "jde-2.2.0/lisp" )) load-path)) ;; The JDE require current versions of semantic bovinator and speedbar. ;; http://www.ultranet.com/~zappo/ ;(setq load-path (cons ; (concat my-emacs-dir "semantic-1.2.1" ) load-path)) ;(setq load-path (cons ; (concat my-emacs-dir "speedbar-0.12") load-path)) ;; Make XEmacs recognize jar files as compressed files (so you can ;; dired them). Already set up in GNU Emacs. (if (boundp 'running-xemacs) (add-to-list'auto-mode-alist '("\\.jar\\'" . archive-mode)) ) ;; Force auto-newline (defun my-jde-hook () (setq c-auto-newline t)) (add-hook 'jde-mode-hook 'my-jde-hook) ; Now actually load the jde. ;(require 'jde) ;;;;; html-mode ;;;;; ;; Enable html-helper-mode for editing html files. ;; http://www.gest.unipd.it/~saint/hth.html ;; Set some defaults. ;; XEmacs seems to come preconfigured with a good html-helper mode. (if (not (boundp 'running-xemacs)) (progn (autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t) )) ; Update file timestamps automatically (setq html-helper-do-write-file-hooks t) ; Insert template into new files. (setq html-helper-build-new-buffer t) ; Ask for tag data in the minibuffer. (setq tempo-interactive t) ; Turn on bigger menu. (setq html-helper-use-expert-menu t) (setq html-helper-address-string (concat "" user-full-name "" )) ; Add a custom DTD so you can easily insert one if missing from HTML file. (add-to-list 'sgml-custom-dtd '("HTML 4.01 Transitional" "")) ; Automatically indent when I press return in html-mode ;(defun my-html-helper-load-hook () ; (define-key html-mode-map (kbd "RET") 'newline-and-indent) ;) ;(add-hook 'html-helper-load-hook 'my-html-helper-load-hook) ;;;;; jiggle ;;;;; ;; jiggle.el - a mode which jiggles the cursor whenever you do things ;; like change buffers. Just a little visual reminder of where that ;; thing went. ;; http://www.eskimo.com/~seldon (require 'jiggle) (jiggle-mode 1) (setq jiggle-how-many-times 5) (jiggle-searches-too 1) ;;;;; auto-save ;;;;; ;; 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. ;; ftp://archive.cis.ohio-state.edu/pub/emacs-lisp/misc/auto-save.el.Z (setq auto-save-directory (expand-file-name (concat my-emacs-dir "autosave")) auto-save-directory-fallback auto-save-directory auto-save-hash-p nil efs-auto-save t efs-auto-save-remotely nil ;; now that we have auto-save-timeout, let's crank this up ;; for better interactive response. auto-save-interval 2000 ) ;; We load this afterwards because it checks to make sure the ;; auto-save-directory exists (creating it if not) when it's loaded. (require 'auto-save) ;;;;; diminish ;;;;; ;; diminish.el - change modeline displays for minor modes. If you ;; enable a lot of minor modes at once, the modeline goes off the end ;; off the screen. This allows you to give the minor modes shorter ;; display names. ;; Note that one side-effect of this under XEmacs is to change the ;; color of minor mode indicators to the same as major modes. ;; http://www.eskimo.com/~seldon (require 'diminish) (diminish 'abbrev-mode "Abv") (diminish 'auto-fill-function " F") (diminish 'font-lock-mode "Fn") (diminish 'jiggle-mode) (if (boundp 'running-xemacs) (progn (diminish 'filladapt-mode "FA") (cond (window-system (diminish 'gnuserv-minor-mode) ) ) (diminish 'header-mode "Hed") ) ) ;;;;; vc ;;;;; ;; Get version-control (vc) loaded in Xemacs on startup. (require 'vc) ;; Customize vc (version-contol) mode. ;; Special thanks to Harvey Thompson for this one. (defun vc-unregister-file (file) "Mark file as not having a VC master file." (interactive "fUnregister file? ") ;; (let ((vc-file (vc-file-getprop file 'vc-name))) ;; (if (yes-or-no-p "Delete VC master file ") ;; (delete-file vc-file)) (vc-file-setprop file 'vc-name nil) (vc-file-setprop file 'vc-latest-version nil) (vc-file-setprop file 'vc-your-latest-version nil) (if (get-buffer "*vc-info*") (kill-buffer "*vc-info*")) ;; ) ) (defun vc-unregister-buffer (buffer) "Mark buffer as not having a VC master file." (interactive "bUnregister buffer? ") (let ((file (buffer-file-name (get-buffer buffer)))) (vc-unregister-file file) ;; (find-alternate-file file) )) (defvar vc-reload-buffer-hooks nil "* Hooks to run after reloading a version controlled file.") ; (defadvice vc-revert-buffer1 (after vc-reload-buffer-hooks activate) ; "Run vc-reload-buffer-hooks after reloading a version controlled file." ; (run-hooks 'vc-reload-buffer-hooks)) ; ; (defun vc-reload-buffer-refontify () ; "Re-fontify buffer after doing a vc reload operation." ; (cond ((and (boundp 'lazy-lock-mode) lazy-lock-mode) ; (lazy-lock-fontify-window)) ; ((and (boundp 'font-lock-mode) font-lock-mode) ; (font-lock-fontify-buffer)))) ; ; (add-hook 'vc-reload-buffer-hooks 'vc-reload-buffer-refontify) ; (defun vc-checkin-and-lock-hook () "Check out a writable file if vc-checkin-checkout-writable is set." (if (memq (current-buffer) vc-checkin-checkout-writable-list) (progn (setq vc-checkin-checkout-writable-list (delq (current-buffer) vc-checkin-checkout-writable-list)) (setq vc-reload-buffer-font-lock nil) (vc-checkout-writable-buffer)))) (setq vc-checkin-checkout-writable-list nil) ;; ;; This seems to be missing from the end of vc-register! ;; (defadvice vc-register (after vc-register-fix-mode-line activate) "Make sure mode line is correct on vc-register." (vc-find-file-hook)) (defun vc-checkin-and-lock () "Check in and then checkout a locked version." (interactive) (let ((file (buffer-file-name))) (if (vc-backend file) (let ((vc-file (vc-name file)) (vc-type (vc-backend file)) owner) (if (and vc-file (not (eq vc-type 'CVS)) (setq owner (vc-locking-user file)) (string-equal owner (user-login-name))) (progn (setq vc-checkin-checkout-writable-list (cons (current-buffer) vc-checkin-checkout-writable-list)) (vc-next-action nil)) (message "Current buffer is not locked by yourself"))) ;; ;; This seems to be an error. ;; (vc-register) (vc-next-action nil)))) (add-hook 'vc-checkin-hook 'vc-checkin-and-lock-hook) (defvar vc-log-mode-add-diffs t "*If non-nil, a VC check-in operation will automatically add the diffs of the file being checked in into the log buffer.") (defvar vc-log-mode-add-diffs-context t "*If non-nil, any diffs added during a VC check-in operation will be context style diffs, otherwise normal diffs.") (defvar vc-log-mode-add-diffs-flags "-cp" "*Flags to pass to diff when adding log diffs.") (defun vc-log-mode-add-diffs-hook () "Adds the vc-diff for the buffer being checked in to the log buffer." (if vc-log-mode-add-diffs (let ((buf (current-buffer))) ;; Go to who we're from (while vc-parent-buffer (set-buffer vc-parent-buffer)) (if (vc-name buffer-file-name) (progn ;; Copy the diffs into the change buffer (let ((diff-switches vc-log-mode-add-diffs-flags)) (vc-backend-diff buffer-file-name nil nil (not vc-log-mode-add-diffs-context)) ) (set-buffer "*vc-diff*") (copy-to-buffer buf (point-min) (point-max)) (set-buffer buf) (beginning-of-buffer) (insert "DIFF: Lines begging with DIFF: are removed\n") (insert "DIFF: \n") (while (not (eobp)) (beginning-of-line) (insert "DIFF: ") (forward-line)) (beginning-of-buffer)) (set-buffer buf))))) (defadvice vc-finish-logentry (before vc-finish-logentry-filter activate) "Remove comment lines beginning with DIFF: from log before entering." (if (not (ad-get-arg 0)) (save-excursion (beginning-of-buffer) (delete-matching-lines "^DIFF:[ \t]")))) (add-hook 'vc-log-mode-hook 'vc-log-mode-add-diffs-hook) ;; ;; Extra VC Commands ;; (define-key vc-prefix-map (kbd "\C-u") 'vc-unregister-buffer) (define-key vc-prefix-map (kbd "\C-l") 'vc-checkin-and-lock) (define-key vc-prefix-map (kbd "\C-i") 'vc-checkin-and-lock) ;;;;; font-lock ;;;;; ;; Font-Lock is a syntax-highlighting package. (setq font-lock-use-default-fonts nil) (setq font-lock-use-default-colors nil) (require 'font-lock) ;; Mess around with the faces a bit. Note that you have ;; to change the font-lock-use-default-* variables *before* ;; loading font-lock, and wait till *after* loading font-lock ;; to customize the faces. ;; string face is green (set-face-foreground 'font-lock-string-face "yellow") ;; function names are bold green (copy-face 'bold 'font-lock-function-name-face) (set-face-foreground 'font-lock-function-name-face "green") ;; comments are green2 (copy-face 'font-lock-comment-face 'font-lock-doc-string-face) (set-face-foreground 'font-lock-comment-face "green2") ;; misc. faces (copy-face 'italic 'font-lock-type-face) (set-face-foreground 'font-lock-keyword-face "orchid") (set-face-foreground 'font-lock-variable-name-face "white") (set-face-foreground 'font-lock-type-face "yellow") ;; fast-lock is a package which speeds up the highlighting of files ;; by saving information about a font-locked buffer to a file and ;; loading that information when the file is loaded again. ;; ;; Normally fast-lock puts the cache file (the filename appended with ;; .flc) in the same directory as the file it caches. You can ;; specify an alternate directory to use by setting the variable ;; fast-lock-cache-directories. (add-hook 'font-lock-mode-hook 'turn-on-fast-lock) (setq fast-lock-cache-directories (list (concat my-emacs-dir "fastlock"))) ;;;;; colors ;;;;; ;; Set other display colors. (set-face-foreground 'highlight "blue") (set-face-background 'highlight "darkseagreen2") ; Some faces which only exist on Xemacs. (if (boundp 'running-xemacs) (progn (set-face-foreground 'primary-selection "white") (set-face-background 'primary-selection "blue") (set-face-foreground 'secondary-selection "white") (set-face-background 'secondary-selection "steelblue") (set-face-foreground 'isearch "green") (set-face-background 'isearch "royalblue") (set-face-foreground 'red "tomato") (set-face-foreground 'modeline-mousable "skyblue") (set-face-foreground 'modeline-mousable-minor-mode "green") (set-face-foreground 'list-mode-item-selected "purple") (set-face-foreground 'zmacs-region "white") (set-face-background 'zmacs-region "blue") ; These seem to cause random problems... ; (set-face-foreground 'widget-button-pressed-face "coral") ; (set-face-foreground 'speedbar-selected-face "salmon") ;Make sure we don't set the modeline foreground invisible on ; the console, set some faces that only exist under X? (if window-system (progn (set-face-foreground 'modeline-buffer-id "white") (set-face-foreground 'display-time-time-balloon-face "pink") (set-face-foreground 'display-time-mail-balloon-enhance-face "snow1") (set-face-background 'display-time-mail-balloon-enhance-face "orangered") ) (set-face-foreground 'modeline-buffer-id "blue") ) ) ;(else GNU Emacs (progn ;Set modeline to yellow on black if running emacs. (set-face-foreground 'modeline "yellow") (set-face-background 'modeline "black") ; I think region is zmacs-region on Xemacs. (set-face-foreground 'region "white") (set-face-background 'region "blue") ) ) ;;;; Custom Set Variables ;;;; ; Turning off the XEmacs toolbar only works as a custom set! ; Same with jde variables. (custom-set-variables '(ldap-host-parameters-alist (quote (("mail.lutris.com" base "ou=People,o=lutris.com")))) '(bsh-startup-timeout 5) '(mouse-avoidance-mode (quote exile) nil (avoid)) '(jde-global-classpath (quote ("/usr/local/jdk1.2.2/lib/tools.jar" "/usr/local/jswdk-1.0.1/lib/servlet.jar" "/usr/local/enhydra3.0.1/lib/enhydra.jar" "."))) '(jde-bug-jdk-directory "/usr/local/jdk1.2.2") '(jde-bug-jpda-directory "/usr/local/jdk1.2.2") '(toolbar-visible-p nil) '(jde-enable-abbrev-mode t) '(sql-pop-to-buffer-after-send-region t) '(jde-db-debugger (quote ("JDEbug" "jdb" . "Executable"))) '(jde-db-source-directories (quote ("/home/philip/java" "/home/philip/projects/BookShelf/bookShelf/presentation" "/home/philip/projects/BookShelf/bookShelf/presentation/bookMgmt")))) ; Put mouse-avoid diminish down here to run after custom-set variables. (if (boundp 'running-xemacs) (diminish 'mouse-avoidance-mode "Av") ) ; Turn off debug-on-error now that file loaded. (setq debug-on-error nil) ;;;; Emacs Control ;;;; ;; Local Variables: ;; mode: outline-minor ;; center-line-decoration-char: ?- ;; center-line-padding-length: 1 ;; center-line-leader: ";;;; " ;; fill-column: 77 ;; line-move-ignore-invisible: t ;; outline-regexp: ";;;;+" ;; page-delimiter: "^;;;;" ;; End: ;;; End of my .emacs ;;;; Revision Control Log ;;;; ;; $Log: .emacs.el,v $ ;; Revision 1.26 2000/09/07 22:00:08 philip ;; Many structural changes. Added outline-mode headers for easier naviagation. ;; Turn on debug mode for duration of .emacs loading. ;; Put my user defaults in a separate file. ;; Move global functions to a central location. ;; turn off truncate-partial-width-windows ;; Revamped all keyboard shortcuts to hopefully be consistent. ;; Configured ldap parameters ;; ;; Revision 1.25 2000/08/12 00:03:12 philip ;; Big and little changes: ;; Corrected movement key bindings to hopefully work properly on xterms. ;; Set uniquify to actually do something (default setting was no buffer ;; name changes. ;; Corrected a2ps.el keys to work on xterm. ;; Dropped todo mode, as I don't actually use it. ;; Tweaked a few html-helper settings. ;; Added jiggle-mode to make cursor more visible sometimes. ;; Added diminish-mode to make minor mode line indicators briefer. ;; Got rid of widget-button and speedbar-selected faces which don't seem ;; to exist all the time. ;; ;; Revision 1.24 2000/08/09 20:12:24 philip ;; Changed sgml options slightly. ;; turned tempo-interactive on for html-helper in xemacs ;; ;; Revision 1.23 2000/08/04 23:26:38 philip ;; Turned on uniqify to give more intelligent names to buffers. ;; Enabled crypt mode to transparently open encrypted and compressed files. ;; Added a2ps.el for convenient printing of buffer via a2ps. Bound to f5. ;; Added a few customizations for psgml. ;; Only load my own html-helper if under GNU Emacs (html mode with xemacs ;; is already good). ;; ;; Revision 1.22 2000/08/01 20:00:52 philip ;; Added some keys suggested by Jeff Jones. ;; Twekaed faces a bit. :;; Change mosue-avoidance mode. ;; ;; Revision 1.21 2000/07/31 21:41:55 philip ;; Removed redundant text-mode setup commands. ;; Removed cycle-buffers function, since I nver use it. ;; Converted cc-mode keyboard bindings to use "kbd" macro. ;; ;; Revision 1.20 2000/07/31 19:31:15 philip ;; Added filladapt.el for better paragraph filling. Upgraded to latest ;; (5.27) cc-mode. Tweaked jde and cc modes. ;; ;; Revision 1.19 2000/07/25 00:06:54 philip ;; Got rid of all those GNUEmacs/XEmacs macros, as they were cumbersome ;; and created some weird problems. Added a keyboard command for ;; capitialize-word. Added todo-mode for tracking todo items. ;; ;; Revision 1.18 2000/07/24 20:28:53 philip ;; GNU Emacs needs rsz-mini instead of rsz-minibuf. Changed browse-url to open a ;; fresh netscape window. Re-enabled catdoc in xemacs as I fixed its problems. ;; Turned on rsz-minibuf. ;; ;; Revision 1.17 2000/07/21 20:36:32 philip ;; Corrected load of mouse-avoid - it must be custom-set. Added auto ;; minibuffer-resize functionality. Added a whole bunch of vc, cc, and ;; java mode improvements suggested by Harvey Thompson. ;; ;; Revision 1.16 2000/07/20 20:05:53 philip ;; Corrected xemacs mouse button for browse-url. Set mouse-avoid to ;; animate.