;; ;; Akkana's old and grizzled GNU Emacs initialization file ;; ;; Show errors in this file: (setq debug-on-error t) (setq stack-trace-on-error t) (setq load-path (cons "~/.emacs-lisp/" load-path)) ;; Automatically uncompress .gz files (auto-compression-mode) ;; ;; Basic key bindings ;; (global-set-key "\C-h" 'delete-backward-char) (global-set-key "\C-w" 'backward-kill-word) (global-set-key "\C-x\C-c" 'save-buffers-kill-emacs) (global-set-key "\C-x\C-v" 'find-file-other-window) (global-set-key "\C-xs" 'save-buffer) (global-set-key "\M-w" 'kill-region) (global-set-key "\C-m" 'newline-and-indent) ;(global-set-key [C-return] 'newline-and-indent) (global-set-key "\M-n" 'goto-line) (global-set-key "\M-N" 'what-line) (global-set-key "\M-?" 'help-for-help) (global-set-key "\C-x\C-k" 'kill-buffer) ;; (global-set-key "\M-/" 'apropos) (global-set-key "\C-c\C-c" 'kill-emacs) (global-set-key "\C-r" 'isearch-backward) (global-set-key "\C-c\C-r" 'revert-buffer) (global-set-key "\C-x\C-i" 'indent-region) (global-set-key "\C-c\C-i" 'indent-region) ;; Use home/end to go to beginning/end of file, not line; ;; because ^A/^E are easy to hit but M-<> are not ;; (especially on a mini laptop). (global-set-key [home] 'beginning-of-buffer) (global-set-key [end] 'end-of-buffer) ;; I keep hitting ^Z accidentally, and at the same time I can ;; never remember what undo is normally bound to. ;; Unfortunately this will suck if I run emacs from the shell, ;; so I'd really like to run this only if we're in GUI mode. (global-set-key "\C-z" 'undo) ;; Make space do what tab does when autocompleting, ;; NOT stopping at punctuation: (define-key minibuffer-local-completion-map " " 'minibuffer-complete) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Turning off annoyances ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; I'd rather not force this, since I occasionally edit binary files, ;; but it's just too annoying how emacs asks, then doesn't actually ;; add the newline so I have to go and do it myself. ;; Ideally I should do this only for text and Fundamental modes. ;; But -- sigh -- this doesn't work anyway. (setq require-final-newline t) ;; My KVM switch uses scroll lock, and emacs complains about it. ;; So silence that. (global-set-key [scroll-lock] 'noop) ;; Get rid of keys I hit accidentally: (global-unset-key "\M-c") ; don't want the capitalize thing ;; undefine the keys that do narrow-to-page and narrow-to-region, ;; because who would ever want such a stupid function?? (global-unset-key "\C-xp") (global-unset-key "\C-xn") ;; Recent versions of emacs always blink the cursor. Yuck! ;(blink-cursor-mode nil) (customize-set-variable 'blink-cursor nil) ;; thanks to sachac! ;; Turn off that big useless toolbar (tool-bar-mode -1) (menu-bar-mode -1) ;; Emacs's html mode always wants to ask email address. Why?? (setq query-user-mail-address nil) ;; xemacs v21 is forever leaving .saves- files with long names ;; which screw up my directory listings. Make it put them ;; somewhere else: (setq auto-save-list-file-prefix "~/.emacs-saves/.saves-") ;; or not do it at all (I can ^X^S frequently): (setq auto-save-default nil) ;; make sure the tab width is right: ;(set-variable "tab-width" 8) ;(set-variable "default-tab-width" 8) ;(set-variable "indent-tabs-mode" nil) (setq-default indent-tabs-mode nil) (setq tabify nil) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; End annoyances ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;(setq default-case-fold-search nil) (setq delete-auto-save-files t) (setq make-backup-files nil) ;; and some extensions for SGI's additions to c++-mode (setq c++-hanging-member-init-colon t) ;(setq default-major-mode 'text-mode) (setq fill-column 73) ;;; Set the mode format at the bottom ;;; Used to be "%*%*%* " emacs-version " %b %M %[(%m)%] line=%5l %3p %-" ;(setq default-modeline-format ; (list "%*%*%* %b %M %[(%m)%] line=%5l %3p %-")) (setq line-number-mode t) ;(setq mode-line-format default-mode-line-format) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Useful utilities ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Replace Windows/Mac newslines in current buffer. ;; Thanks to slamm for the original! ;; Rewritten by Akkana to handle Mac newlines as well. ;; Note: Mike Tsao says in his weblog that C-x [ENTER] f unix [ENTER] ;; converts DOS line endings to Unix. (defun fixm () "Delete ^M from buffer." (interactive) ;; Remember where we were (let ((old-point (point))) ;; Move to top (set-window-point (get-buffer-window (current-buffer)) 0) ;; Replace ^M's (while (search-forward "\C-M" nil t) (replace-match "\r\n" "\n") (replace-match "\r" "\n") ) ;; Move back to the old point (set-window-point (get-buffer-window (current-buffer)) old-point) ) ) ;; For mac files (defun showmac () "Show the file with mac newline encoding" (interactive) (let ((coding-system-for-read 'mac)) (revert-buffer nil t))) ;; Call lxr on an identifier ;;Select an identifier as the region, then C-c C-l i (defun lxr-ident (start end) (interactive "r") (let ((ident (buffer-substring start end))) (shell-command (concat "mozilla-remote --newwin http://lxr.mozilla.org/seamonkey/ident\?i=" ident)))) (global-set-key "\C-c\C-li" 'lxr-ident) ;; Kill All Buffers without prompting. ;; Modified from kill-some-buffers in files.el, which prompts too much. (defun kill-all-buffers () "Kill all buffers without prompting." (interactive) (let ((list (buffer-list))) (while list (let* ((buffer (car list)) (name (buffer-name buffer))) (kill-buffer buffer)) (setq list (cdr list))))) ;; ;; For composing in emacs then pasting into a word processor, ;; this un-fills all the paragraphs (i.e. turns each paragraph ;; into one very long line) and removes any blank lines that ;; previously separated paragraphs. ;; (defun wp-munge () "un-fill paragraphs and remove blank lines" (interactive) (let ((save-fill-column fill-column)) (set-fill-column 1000000) (mark-whole-buffer) (fill-individual-paragraphs (point-min) (point-max)) (delete-matching-lines "^$") (set-fill-column save-fill-column) )) ;; ;; Derived C modes, setting different styles for different files. ;; (define-derived-mode gnu-c-mode c-mode "GNU C mode" (c-set-style "gnu")) (define-derived-mode linux-c-mode c-mode "GNU C mode" (c-set-style "linux")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Special code for html and text files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Want auto-fill-mode for some text and html files, but not all. ;; So define two derived modes for that, and we'll use auto-mode-alist ;; to choose them based on filename. (define-derived-mode html-wrap-mode html-mode "HTML wrap mode" (auto-fill-mode)) (define-derived-mode text-wrap-mode text-mode "Text wrap mode" (auto-fill-mode)) ;; In text mode, I don't want it auto-indenting for the first ;; line in the file, or lines following blank lines. ;; Everywhere else is okay. (defun newline-and-text-indent () "Insert a newline, then indent the next line sensibly for text" (interactive) (cond ;; Beginning of buffer, or beginning of an existing line, don't indent: ((or (bobp) (bolp)) (newline)) ;; If we're on a whitespace-only line, ((and (eolp) (save-excursion (re-search-backward "^\\(\\s \\)*$" (line-beginning-position) t))) ;; ... delete the whitespace, then add another newline: (kill-line 0) (newline)) ;; Else (not on whitespace-only) insert the appropriate indent: (t (newline-and-indent)) )) (defun text-indent-hook () (local-set-key "\C-m" 'newline-and-text-indent) ) (setq text-mode-hook 'text-indent-hook) ;; Long lines mode: emacs doesn't have a way comparable to ;; vim's "set linebreak" to show long lines as wrapped visually, ;; without changing the file. longlines-mode adds a minor mode ;; to change the file upon reading it in, then change it back ;; when it's saved. Ick, but that's apparently all emacs can do. ;; http://www.emacswiki.org/elisp/longlines.el ;(autoload 'longlines-mode ; "longlines.el" ; "Minor mode for automatically wrapping long lines." t) ;(setq longlines-wrap-follows-window-size t) ;(setq longlines-show-hard-newlines t) ;; Some modes, like Python, override my "\C-c\C-r" 'revert-buffer binding (defun reset-revert-buffer () (define-key py-mode-map "\C-c\C-r" 'revert-buffer) ) (setq python-mode-hook 'reset-revert-buffer) ; Ruby (autoload 'ruby-mode "ruby-mode" "Load ruby-mode") (defun ruby-stuff-hook () (local-set-key "\C-m" 'newline-and-text-indent) (turn-on-font-lock) ) (add-hook 'ruby-mode-hook 'ruby-stuff-hook) (setq auto-mode-alist (cons '("\\.rb$" . ruby-mode) (cons '("\\.scm$" . scheme-mode) (cons '("\\.blx$" . html-wrap-mode) (cons '("blogstuff/" . html-wrap-mode) (cons '("Docs/.*.html$" . html-wrap-mode) (cons '("Docs/gimp/book/notes" . text-wrap-mode) ;; Next two were longlines-mode (cons '("Docs/bio14/" . text-wrap-mode) (cons '("Docs/gimp/book/" . text-wrap-mode) (cons '("Docs/" . text-wrap-mode) (cons '("linux-.*/" . linux-c-mode) auto-mode-alist) ) ) ) ) ) ) ) ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Autocomplete stuff ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq completion-ignored-extensions '(".xpt" ".a" ".so" ".o" ".d" ".elc" ".class" "~" ".ckp" ".bak" ".imp" ".lpt" ".bin" ".otl" ".err" ".lib" ".x9700" ".aux" )) ;; make command completion complete as far as possible, not just first word ;; unfortunately, this doesn't work ;(define-key minibuffer-local-must-match-map " " minibuffer-complete) ;; This is supposed to prevent the excessive making of local backup files. ;; http://jamesthornton.com/emacs/chapter/emacs_16.html#SEC150 (setq vc-cvs-stay-local nil) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; C and related modes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; TAB in C-mode should always insert a tab (setq c-tab-always-indent nil) ;; C-mode variables for Britton-Lee coding standards (See bcx's paper) (setq c-indent-level 4) (setq c-continued-statement-offset 4) (setq c-brace-offset -4) (setq c-brace-imaginary-offset 0) (setq c-argdecl-indent 0) (setq c-label-offset -2) ;; C++-mode variables for Netscape and cc-mode.el: ;; see /tools/ns/share/emacs/19.33/lisp/cc-mode.el for more details. (autoload 'c-add-style "cc-mode" "C++ Editing Mode" t) (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t) (autoload 'c-mode "cc-mode" "C Editing Mode" t) (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t) (autoload 'java-mode "cc-mode" "Java Editing Mode" t) (autoload 'archive-mode "arc-mode" "Zip and Jar Mode" t) ;; Style stuff for the old c-mode, now outmoded: ;(c-add-style "akkana" ; '((c-basic-offset . 4) ; (c-comment-only-line-offset . 0) ; (c-offsets-alist . ((statement-block-intro . +) ; (knr-argdecl-intro . +) ; (substatement-open . 0) ; (label . 0) ; (statement-cont . +) ; (case-label . 2) ; )))) ;(c-set-style "akkana") ; Here's the new way, for cc-mode: (setq c-default-style '((java-mode . "java") (other . "stroustrup"))) ;; ;; Ah, glorious linux C-mode! (from val@mnt.edu) ;; (defun linux-c-mode () "C mode with adjusted defaults for use with the Linux kernel." (interactive) ; (setq tabify t) (c-mode) (c-set-style "K&R") (setq c-basic-offset 8) (setq indent-tabs-mode t) ) ;; Recent Emacsen have a bug where the block cursor disappears sometimes, ;; like if you go to the beginning of an existing line and delete backward. ;; Changing to a bar cursor fixes it. Hope you like a bar cursor! ;; See http://6v8.gamboni.org/Emacs-and-OS-X.html (happens on linux too). (setq initial-frame-alist (cons '(cursor-type . bar) (copy-alist initial-frame-alist) ) ) (setq default-frame-alist (cons '(cursor-type . bar) (copy-alist default-frame-alist) ) ) (put 'eval-expression 'disabled nil) ; (autoload 'pmodify "ptools" "ptools utilities" t) ; Load a better man package (autoload 'manual-entry "man-background" "Run UNIX man in the background. When it's finished, a man entry window pops up." t) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Turn debugging back off. Put any questionable code after these lines! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq debug-on-error nil) (setq stack-trace-on-error nil) ; (load-library "paren") ;;; ;;; KEYPAD BINDINGS: ;;; Argh! The names of the keypad keys change with every emacs release!! ;;; Put this at END of .emacs so that if it bombs, at least it won't ;;; put us in error-debug mode. ;;; ;;; I think the most common reason for it bombing is changing ;;; keyboard maps. Judicious control over the keymap used at boot ;;; time helps this quite a bit. ;;; ;; ;; How this works: ;; The keypad arrow keys let you move in the four directions. ;; The middle key (5) is used as a prefix, like ESC. ;; Arrow alone moves one character/line in the indicated direction. ;; Prefix-Arrow moves one "unit": word or page. ;; Prefix-Prefix-Arrow moves as far as possible (end of line, end of buffer). ;; (defvar middle-key-map nil "") (defvar double-middle-key-map nil "") (cond ((or (string-match "XEmacs" emacs-version) (and (boundp 'emacs-major-version) (or (and (= emacs-major-version 19) (>= emacs-minor-version 14)) (>= emacs-major-version 20)))) ;; (fboundp 'load-options-file)) ; Arrow keys are already set, no need to set them again. ;; Oops, in debian they're not set because all the keypad ;; keys have different names. I love emacs and keyboard maps. (global-set-key [kp-8] 'previous-line) (global-set-key [kp-2] 'next-line) (global-set-key [kp-4] 'previous-character) (global-set-key [kp-6] 'next-character) ;; (global-set-key [kp-next] 're-search-forward) ;; (global-set-key [kp-prior] 're-search-backward) ;; (global-set-key [kp-end] 'query-replace) (setq middle-key-map (make-sparse-keymap)) (suppress-keymap middle-key-map t) ; (global-set-key [kp-5] nil) ;(global-set-key (append [kp-4] [kp-5]) 'backward-word) (define-key global-map [begin] 'middle-key-prefix) (define-key global-map [kp-5] 'middle-key-prefix) ; (global-set-key [kp-5] 'middle-key-map) (fset 'middle-key-prefix middle-key-map) (define-key middle-key-map [kp-left] 'backward-word) (define-key middle-key-map [kp-right] 'forward-word) (define-key middle-key-map [kp-up] 'scroll-down) (define-key middle-key-map [kp-down] 'scroll-up) ;; (define-key middle-key-map [kp-next] 'replace-regexp) (define-key middle-key-map [kp-4] 'backward-word) (define-key middle-key-map [kp-6] 'forward-word) (define-key middle-key-map [kp-8] 'scroll-down) (define-key middle-key-map [kp-2] 'scroll-up) (setq double-middle-key-map (make-sparse-keymap)) (suppress-keymap double-middle-key-map t) (define-key middle-key-map [kp-begin] 'double-middle-key-prefix) (define-key middle-key-map [kp-5] 'double-middle-key-prefix) (fset 'double-middle-key-prefix double-middle-key-map) (define-key double-middle-key-map [kp-left] 'beginning-of-line) (define-key double-middle-key-map [kp-right] 'end-of-line) (define-key double-middle-key-map [kp-up] 'beginning-of-buffer) (define-key double-middle-key-map [kp-down] 'end-of-buffer) (define-key double-middle-key-map [kp-4] 'beginning-of-line) (define-key double-middle-key-map [kp-6] 'end-of-line) (define-key double-middle-key-map [kp-8] 'beginning-of-buffer) (define-key double-middle-key-map [kp-2] 'end-of-buffer) )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; End keypad bindings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Is this really required any more? (require 'mwheel) (mwheel-install) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Syntax Highlight and Colors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (require 'font-lock) ;(setq font-lock-auto-fontify t) ;(setq font-lock-support-mode 'lazy-lock-mode) (if (fboundp 'global-font-lock-mode) (global-font-lock-mode 1)) ;; Cool code from alecf to do mozilla-specific syntax highlighting: ;; Options Menu Settings ;; ===================== (cond ((or (string-match "XEmacs" emacs-version) (and (boundp 'eeemacs-major-version) (or (and (= emacs-major-version 19) (>= emacs-minor-version 14)) (>= emacs-major-version 20)))) ;; Syntax colorizing (setq-default teach-extended-commands-p t) (setq-default teach-extended-commands-timeout 4) ;(setq-default font-lock-use-colors '(color)) (require 'font-lock) ;(remove-hook 'font-lock-mode-hook 'turn-on-fast-lock) ;(remove-hook 'font-lock-mode-hook 'turn-on-lazy-shot) (add-hook 'c-mode-common-hook 'turn-on-font-lock) ;; From hober on #emacs: ;(setq font-lock-auto-fontify t) ;(setq font-lock-support-mode 'lazy-lock-mode) ;(set-face-foreground 'font-lock-comment-face "cadetblue") ;(set-face-foreground 'font-lock-keyword-face "darkred") ;(set-face-foreground 'font-lock-string-face "blue") ;(set-face-foreground 'font-lock-type-face "forestgreen") ;(set-face-foreground 'font-lock-variable-name-face "purple") ;(set-face-foreground 'font-lock-function-name-face "red") ;(set-face-foreground 'font-lock-warning-face "yellow") ;(set-face-foreground 'font-lock-constant-face "darkyellow") ;(set-face-foreground 'font-lock-builtin-face "firebrick") ;; These used to work, but don't any more (maybe they're .XEmacs stuff): ;(cond ((string-match "XEmacs" emacs-version) ; (set-face-foreground 'font-lock-preprocessor-face "darkred") ; (set-face-foreground 'font-lock-reference-face "yellow") ; (set-face-foreground 'font-lock-doc-string-face "purple"))) ;(custom-set-faces) (setq moz-font-lock-keywords ;; nspr types '(("\\<\\(PR\\(\\(Ui\\|I\\)nt\\(16\\|32\\|64\\)\\|\\(Packed\\|\\)Bool\\)\\)\\>" . font-lock-type-face) ;; nspr special values ("\\" . font-lock-reference-face) ;; PRUnichar ("PR_Unichar" . font-lock-type-face) ;; string types ("\\" . font-lock-type-face) ;; XPCOM types ("\\" . font-lock-type-face) ("\\" . font-lock-type-face) ;; XPCOM special values ("\\" . font-lock-preprocessor-face) ("\\" . font-lock-keyword-face) ("\\" . font-lock-type-face))) ;; End of cool mozilla code from alecf (defun my-c-mode-hook () (progn (setq font-lock-keywords (append moz-font-lock-keywords c-font-lock-keywords-2)) ;; Turn off obnoxious electric-indent modes: (define-key c++-mode-map ";" 'self-insert-command) (define-key c++-mode-map "/" 'self-insert-command) (define-key c++-mode-map "*" 'self-insert-command) (define-key c++-mode-map "{" 'self-insert-command) ; (define-key c++-mode-map "}" 'self-insert-command) (define-key c++-mode-map "," 'self-insert-command) )) (setq c++-mode-hook 'my-c-mode-hook) )) ;; end XEmacs- and emacs 19.14+ specific code ;; Match paren. from http://grok2.tripod.com/ (defun match-paren (arg) "Go to the matching paren if on a paren; otherwise insert %." (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))))) (global-set-key "\C-x%" 'match-paren) ;; Color themes: search for color-theme.el (load "color-theme-akk.el") (color-theme-akk) ;; ;; tramp-mode is lovely for remote editing, but it sure does take a ;; lot of hand-holding. Thanks, Val. ;; (setq tramp-debug-buffer t) ;(setq tramp-default-method "scp") (setq tramp-rcp-program "scp") ;; Orig nonworking pattern ;;(setq tramp-shell-prompt-pattern ;; "^[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*" ) ;; ;; Works, kinda ;; (setq tramp-shell-prompt-pattern "^\e\[[0-9]*[a-z]([a-z\.\')-\e\[[0-9]*[a-z] " ) ;; ;; For some reason, sshd on rainbow puts in this extra "Response:" ;line ;; ;;(setq tramp-password-prompt-regexp ;; "^.*\\([pP]assword\\|Response\\|passphrase.*\\):\^@? *" )