;;; .emacs --- Edward O'Connor's Emacs configuration -*- emacs-lisp -*- ;; Copyright (C) 1997 -- 2011 Edward O'Connor ;; Author: Edward O'Connor ;; Keywords: local ;; This file is NOT part of GNU Emacs. ;; This is free software; you can redistribute it and/or modify it under ;; the terms of the GNU General Public License as published by the Free ;; Software Foundation; either version 2, or (at your option) any later ;; version. ;; This file is distributed in the hope that it will be useful, but ;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with Emacs; see the file COPYING, or type `C-h C-c'. If not, ;; write to the Free Software Foundation at this address: ;; Free Software Foundation ;; 51 Franklin Street, Fifth Floor ;; Boston, MA 02110-1301 ;; USA ;;; Code: (require 'cl) (unless (featurep 'xemacs) (provide 'emacs)) ;;; Compatibility. Checking for the availability of various functions ;;; which I'll be using later on. ;; Not defined in Emacs. (if (fboundp 'variable-obsolete-p) (defalias 'ted-variable-obsolete-p 'variable-obsolete-p) (defsubst ted-variable-obsolete-p (variable) "Non-nil if VARIABLE is marked as obsolete." (get variable 'byte-obsolete-variable))) ;; Not defined in XEmacs. (unless (fboundp 'turn-off-auto-fill) (defun turn-off-auto-fill () "Unconditionally turn off Auto Fill mode." (interactive) (auto-fill-mode -1))) ;; Not defined in XEmacs. (unless (fboundp 'propertize) (defun propertize (string &rest props) "Propertize STRING with PROPS. Copied from `erc-propertize'." (let ((length (length string))) (while props (put-text-property 0 length (car props) (cadr props) string) (setq props (cddr props)))) string)) ;; Not defined in non-Mule XEmacs. (if (fboundp 'coding-system-p) (defalias 'ted-coding-system-p 'coding-system-p) (defalias 'ted-coding-system-p 'ignore)) ;; Not defined in older Emacsen. (unless (fboundp 'custom-autoload) (defun custom-autoload (symbol load) "Mark SYMBOL as autoloaded custom variable and add dependency LOAD." (put symbol 'custom-autoload t) (custom-add-load symbol load))) ;; The function `exectuable-find' isn't autoloaded in older XEmacsen. (unless (fboundp 'executable-find) (autoload 'executable-find "executable")) (cond ((fboundp 'set-frame-parameter) (defalias 'ted-set-frame-parameter 'set-frame-parameter)) ((fboundp 'set-frame-property) (defalias 'ted-set-frame-parameter 'set-frame-property))) ;; Defined in multi-tty Emacs (if (fboundp 'window-system) (defalias 'ted-window-system 'window-system) (defun ted-window-system (&optional frame) window-system)) (cond ((fboundp 'frame-display) ;; Multi-TTY Emacs (defalias 'ted-frame-display 'frame-display)) ((fboundp 'frame-device) ;; XEmacs (defalias 'ted-frame-display 'frame-device)) (t (defalias 'ted-frame-display 'ignore))) ;; I use `assoc-default' in `ted-find-mode'. (unless (fboundp 'assoc-default) (warn "This Emacs does not define `assoc-default'!") (defun assoc-default (key alist &optional test default) "Find object KEY in ALIST." (let ((thing (assoc* key alist :test (lambda (a b) (funcall test b a))))) (if (consp thing) (cdr thing) default)))) ;;; Utilities. (defsubst ted-alist (list) "Given LIST of the form (A B .. Z), create an alist of the form \((A . A) (B . B) .. (Z . Z)). If LIST is nil, return nil. Useful for making arguments for `completing-read'." (mapcar (lambda (item) (cons item item)) list)) (defun ted-add-to-list* (list-var &rest directories) "Add to the value of LIST-VAR each existing directory in DIRECTORIES. Effectively a multi-argument version of `add-to-list', but custom-made for variables like `load-path' and `Info-default-directory-list'." (mapc (lambda (directory) (when (file-directory-p directory) (add-to-list list-var (file-name-as-directory directory)))) directories)) (put 'ted-add-to-list* 'lisp-indent-function 1) ;;; Frob the Emacs command line. (defvar ted-server-emacs t "If non-null, this emacs should run an edit server. By edit server, I mean the bit that emacsclient or gnuclient talk to.") (add-to-list 'command-switch-alist '("gnus" . (lambda (&rest ignore) (setq ted-server-emacs nil) ;; Exit Emacs after quitting Gnus (add-hook 'gnus-after-exiting-gnus-hook 'save-buffers-kill-emacs) ;; Start Gnus when Emacs starts (add-hook 'emacs-startup-hook 'gnus t)))) ;;; Frobbing `load-path' and checking for any third-party elisp files on ;;; this machine. (defconst ted-elisp-dir "~/elisp" "Where I keep local copies of elisp files, both my own and others'.") (defconst ted-multiboot-mac-elisp-dir "/Volumes/Data/elisp/" "Where I keep local copies of elisp files on multiboot Mac systems.") (defconst ted-local-elisp-config (expand-file-name "local.el" ted-elisp-dir) "Local elisp configuration file for overriding stuff in ~/.emacs.") (defconst ted-workspace "~/code" "Where I check out CVS modules (and other version-controlled things). So this is where CVS versions of things like ERC and Gnus live.") (dolist (dir (list "~/web/entries/elisp/" "~/web/lib/")) (when (file-directory-p dir) (add-to-list 'load-path dir))) (ted-add-to-list* 'load-path (expand-file-name ted-elisp-dir)) (ted-add-to-list* 'load-path (expand-file-name ted-multiboot-mac-elisp-dir)) (defsubst ted-file-in-workspace (file) (expand-file-name file ted-workspace)) (apply 'ted-add-to-list* 'load-path (mapcar 'ted-file-in-workspace '("facebook-el" "gitsum" "ljupdate" "mediawiki-el" "slime"))) ;; Ducking the incompatible byte-code issue. (unless (featurep 'xemacs) (apply 'ted-add-to-list* 'load-path (mapcar 'ted-file-in-workspace '("37emacs" "auctex" "bbdb/lisp" "circe" "emacs-w3m" "erc" "g-client" "gnus/lisp" "js2-mode/build" "nxml" "selftest-el")))) (apply 'ted-add-to-list* 'Info-default-directory-list (mapcar 'ted-file-in-workspace '("auctex/doc""bbdb/texinfo" "emacs-w3m/doc" "gnus/texi"))) (let ((default-directory ted-elisp-dir)) (load "./subdirs.el" t)) ;; Let's make sure we load the right version of Gnus. (ignore-errors (require 'gnus-load)) (defun ted-score-path (path) "Score PATH for sorting `exec-path' entries." (+ (if (string-match (regexp-quote (expand-file-name "~")) path) 100 0) (length path))) (defun ted-cmp-path (p1 p2) "Non-nil iff P1 should appear before P2 in `exec-path'." (> (ted-score-path p1) (ted-score-path p2))) (defun ted-path-fixup () "Update `exec-path' with my preferred ordering." (setq exec-path (sort (delete-duplicates (mapcar (lambda (p) (file-name-as-directory (expand-file-name p))) exec-path) :test 'string-equal) 'ted-cmp-path)) (setenv "PATH" (mapconcat 'identity exec-path path-separator))) (add-hook 'after-init-hook 'ted-path-fixup) ;;; Define various constants and predicates that will be used throughout ;;; this .emacs file to conditionalize code. For instance, I define ;;; `ted-tty-p' so that I can specify particular Emacs configuration ;;; bits for TTYs only. (defvar ted-oort+-flag nil "Non-nil means this Emacs is equipped with Oort Gnus (or later).") (when (or (featurep 'xemacs) (not (fboundp 'display-graphic-p))) (defun display-graphic-p (&optional display) "Is DISPLAY is a graphical display?" (ted-window-system display))) ;; Not defined in XEmacs. (unless (fboundp 'display-color-p) (defun display-color-p (&optional display) "Does this display support colors?" (or (featurep 'xemacs) (display-graphic-p display)))) (if (fboundp 'console-type) (defun ted-tty-p (&rest ignore) "Is this a TTY that we're on?" (eq (console-type) 'tty)) (defun ted-tty-p (&optional display) "Is this a TTY that we're on?" (not (display-graphic-p display)))) (defun ted-xterm-p (&optional display) "Non-nil if DISPLAY is an xterm. If DISPLAY is nil, the current displaly is used." (and (ted-tty-p display) (let ((TERM (getenv "TERM"))) (if TERM (string-match "^xterm.*\\'" TERM) nil)))) (defun ted-w32-window-system-p (&optional frame) "Non-nil if FRAME is on a Microsoft Windows display. If FRAME is nil, the current frame is used." (memq (ted-window-system frame) '(w32 win32))) (defun ted-aqua-p (&optional frame) "Non-nil if FRAME is on a Mac OS X display. If FRAME is nil, the current frame is used." (memq (ted-window-system frame) '(mac ns))) (defun ted-menu-bar-lines (&optional frame) "Returns the number of menu bar lines to be used on FRAME." (if (ted-aqua-p frame) 1 0)) (defconst ted-w32-flag (eq system-type 'windows-nt) "Are we running under Microsoft Windows?") (defconst ted-sufficiently-bsd-like-flag (memq system-type '(berkeley-unix darwin)) "Are we running on a sufficiently BSD-like system?") (defconst ted-snow-leopard-flag (and (eq system-type 'darwin) (version<= operating-system-release "10.6")) "Are we running on Mac OS X Snow Leopard?") (defconst ted-lion-flag (and (eq system-type 'darwin) (version<= operating-system-release "11")) "Are we running on Mac OS X Lion?") (defconst ted-emacs-name (let ((version-int (number-to-string emacs-major-version))) (cond ((featurep 'xemacs) (concat "XEmacs-" version-int "." (number-to-string emacs-minor-version))) (t (concat "Emacs-" version-int)))) "The name of this Emacs.") ;;; Work-arounds for things I find annoying in their default state, and ;;; basic customizations. (setq read-file-name-completion-ignore-case t) (when (and (eq system-type 'darwin) (featurep 'emacs) (require 'osx-plist nil t) (file-exists-p "~/.MacOSX/environment.plist")) (osx-plist-update-environment)) (setq ns-use-system-highlight-color nil) (defun ted-run-after-make-frame-functions (&optional frame) (run-hook-with-args 'after-make-frame-functions (or frame (selected-frame)))) (add-hook 'emacs-startup-hook 'ted-run-after-make-frame-functions) ;; Make sure that XEmacs doesn't try to move this file somewhere else. (setq load-home-init-file t) (setq inhibit-startup-message t initial-major-mode 'lisp-interaction-mode) (setq cd-path '("./" "~/" "~/code/")) (setenv "CDPATH" (mapconcat 'identity cd-path path-separator)) (add-to-list 'exec-path (expand-file-name "~/bin/")) (when ted-w32-flag (defun ted-fix-w32-pathname (dir) "Munge DIR to be a real dir name." (setq dir (or dir "")) ;; FIXME: an example of why I do this would be nice. (if (string-match "^[\"]\\(.*\\)[\"]/\\'" dir) (file-name-as-directory (match-string 1 dir)) dir)) (let ((path (parse-colon-path (getenv "PATH")))) (setenv "PATH" (mapconcat 'ted-fix-w32-pathname path path-separator)))) (global-set-key (kbd "C-c l") 'goto-line) (setq ring-bell-function 'ignore visible-bell nil) (defun ted-ding () "Like `ding', but always makes a noise." (let ((visual-bell nil) (ring-bell-function nil)) (ding))) (setq require-final-newline t) (setq inhibit-default-init t) (defun ted-warn-about-default-init () (when (locate-library "default") (message "Warning: `default.el' not loaded") (sit-for 2))) (add-hook 'emacs-startup-hook 'ted-warn-about-default-init) (setq change-log-default-name "ChangeLog") (when (featurep 'aquamacs) (cua-mode 0)) (setq zmacs-regions t) (when (fboundp 'transient-mark-mode) (transient-mark-mode 1) (setq highlight-nonselected-windows nil mark-even-if-inactive t)) (mapc (lambda (sym) (put sym 'disabled nil)) '(downcase-region erase-buffer eval-expression narrow-to-page narrow-to-region upcase-region)) (setq minibuffer-max-depth nil ; XEmacs enable-recursive-minibuffers t) ; Emacs (when (featurep 'emacs) (require 'mb-depth nil t) (cond ((fboundp 'minibuffer-depth-indicate-mode) (minibuffer-depth-indicate-mode 1)) ((fboundp 'minibuffer-indicate-depth-mode) (minibuffer-indicate-depth-mode 1)))) (put 'overwrite-mode 'disabled t) (setq sentence-end-double-space nil) (defvar ted-sentence-end-re "\\(\\w+\\)\\([.?!]\\)\\B" "Regular expression which matches potential sentence endings.") (defvar ted-abbreviations '("Mr" "Mrs" "St") "Abbreviations which should not be considered to end sentences.") (defun ted-sentence-end () "Returns the location of the next sentence-end in the current buffer. Resorts to `point-max' if it can't find a sentence end." (or (catch 'found (while (re-search-forward ted-sentence-end-re nil t) (when (or (member (match-string 2) '("?" "!")) (not (member (match-string 1) ted-abbreviations))) (throw 'found (point))))) (point-max))) (defalias 'yes-or-no-p 'y-or-n-p) (setq-default indent-tabs-mode nil) (setq truncate-partial-width-windows nil) (setq-default truncate-lines t) (let ((foo (lambda () (setq truncate-lines nil)))) (mapc (lambda (hook) (add-hook hook foo)) '(term-mode-hook eshell-mode-hook html-mode-hook))) (when (fboundp 'blink-cursor-mode) (blink-cursor-mode -1)) (setq visible-cursor nil) ; Emacs 22 (setq-default scroll-step 1 scroll-conservatively most-positive-fixnum scroll-up-aggressively 0.0 scroll-down-aggressively 0.0) (when (require 'multi-region nil t) (global-set-key (kbd "C-c 2") multi-region-map)) (when (fboundp 'minibuffer-electric-default-mode) (minibuffer-electric-default-mode 1)) (when (fboundp 'temp-buffer-resize-mode) (temp-buffer-resize-mode 1)) (cond ((not (ted-variable-obsolete-p 'resize-minibuffer-window-exactly)) (setq resize-minibuffer-window-exactly t) (when (fboundp 'resize-minibuffer-mode) (resize-minibuffer-mode 1))) (t (setq max-mini-window-height 0.30) (setq resize-mini-window t))) (when (ignore-errors (require 'uniquify)) (setq-default uniquify-buffer-name-style 'forward)) (line-number-mode 1) (when (fboundp 'column-number-mode) (column-number-mode 1)) (add-hook 'comint-output-filter-functions 'comint-watch-for-password-prompt) (setcar (cdr (assq 'abbrev-mode minor-mode-alist)) " A") (setcar (cdr (assq 'auto-fill-function minor-mode-alist)) " F") (let ((el-hook (lambda () (setq mode-name "el")))) (add-hook 'emacs-lisp-mode-hook el-hook) (add-hook 'lisp-interaction-mode-hook el-hook)) (add-hook 'sh-mode-hook (lambda () (setq mode-name "sh"))) (when (and (eq system-type 'darwin) (boundp 'mac-apple-event-map) (keymapp mac-apple-event-map)) (define-key mac-apple-event-map [core-event reopen-application] 'raise-frame)) ;; Fix sort order in dired, ls, etc. (setenv "LC_COLLATE" "C") (setq comment-style 'indent) (setq auto-mode-case-fold t) (defun ted-insert-local-variables-spec () "Insert a minimal local variables spec for this buffer." (interactive) (save-excursion (save-restriction (widen) (goto-char (point-min)) ;; FIXME: only strip the last 5 characters when they're "-mode" (insert (format "-*- mode: %s; coding: %s -*-" (substring (symbol-name major-mode) 0 -5) buffer-file-coding-system)) ;; If there's some kind of local comment syntax, ensure the local ;; variables spec lives in one. (when comment-start (comment-region (point-min) (point))) (insert "\n")))) (setq apropos-do-all t) (setenv "GIT_PAGER" "cat") (setq completion-ignore-case t) ;; completion (define-key minibuffer-local-completion-map (kbd "SPC") nil) (when (locate-library "pcomplete") (setq pcomplete-cycle-completions nil)) (when (locate-library "longlines") (setq longlines-wrap-follows-window-size t)) (setq search-highlight t) (setq isearch-highlight-all-matches t) ; XEmacs (setq-default case-fold-search t) (eval-after-load "isearch" '(define-key isearch-mode-map (kbd "C-h") 'isearch-mode-help)) (setq-default abbrev-mode t) (when (file-exists-p abbrev-file-name) (quietly-read-abbrev-file)) (add-hook 'mail-setup-hook 'mail-abbrevs-setup) (when (fboundp 'show-paren-mode) (show-paren-mode 1) (make-variable-buffer-local 'show-paren-mode)) ;; to make paredit behave. (setq blink-matching-paren-on-screen nil) (setq blink-matching-delay 0.125) ;; Emacs.app (Cocoa/GNUStep port) uses mic-paren by default (when (featurep 'mic-paren) (setq paren-sexp-mode nil)) (setq-default auto-fill-function 'do-auto-fill) (mapc (lambda (mode-hook) (add-hook mode-hook 'turn-off-auto-fill)) '(emacs-lisp-mode-hook sh-mode-hook comint-mode-hook shell-mode-hook lisp-mode-hook erc-mode-hook ruby-mode-hook)) (setq-default fill-column 72) (setq emacs-lisp-docstring-fill-column 72) (if (boundp 'show-trailing-whitespace) (progn (setq-default show-trailing-whitespace t) (defun ted-hide-trailing-whitespace () "Do not highlight trailing whitespace in this buffer." (interactive) (setq show-trailing-whitespace nil)) (defun ted-show-trailing-whitespace () "Highlight trailing whitespace in this buffer." (interactive) (setq show-trailing-whitespace t)) (defun ted-toggle-show-trailing-whitespace () "Highlight trailing whitespace in this buffer." (interactive) (setq show-trailing-whitespace (not show-trailing-whitespace))) (mapc (lambda (mode-hook) (add-hook mode-hook 'ted-hide-trailing-whitespace)) '(Buffer-menu-mode-hook custom-mode-hook text-mode-hook term-mode-hook Info-mode-hook comint-mode-hook buffer-menu-mode-hook apropos-mode-hook tooltip-show-hook gnus-article-mode-hook mail-mode-hook gnus-summary-mode-hook message-mode-hook gnus-group-mode-hook eshell-mode-hook w3-mode-hook initial-calendar-window-hook)) (mapc (lambda (mode-hook) (add-hook mode-hook (lambda () (setq show-trailing-whitespace t)))) '(latex-mode-hook LaTeX-mode-hook html-mode-hook))) (defalias 'ted-hide-trailing-whitespace 'ignore)) (setq user-mail-address "hober0@gmail.com" ;% user-full-name "Edward O'Connor") (setq message-log-max most-positive-fixnum) (defun ted-clear (&optional prefix) "Move the line containing point to the top of the window. With PREFIX, move the line containing point to line PREFIX of the window." (interactive "P") (recenter (or prefix 0))) (global-set-key (kbd "C-c c") 'ted-clear) (add-hook 'write-file-hooks 'time-stamp) (when (fboundp 'goto-address) (setq goto-address-fontify-maximum-size most-positive-fixnum) (add-hook 'find-file-hooks 'goto-address)) (defun ted-thingatpt-install-rdar-uri-scheme () (add-to-list 'thing-at-point-uri-schemes "rdar://") (setq thing-at-point-url-regexp (concat "\\<\\(" (mapconcat 'identity thing-at-point-uri-schemes "\\|") "\\)" thing-at-point-url-path-regexp))) (eval-after-load "thingatpt" '(ted-thingatpt-install-rdar-uri-scheme)) (setq-default indicate-empty-lines t indicate-buffer-boundaries t) (let ((hook (lambda () (setq indicate-empty-lines nil indicate-buffer-boundaries nil))) (mode-hooks '(shell-mode-hook term-mode-hook gnus-article-mode-hook gnus-summary-mode-hook gnus-group-mode-hook eshell-mode-hook))) (mapc (lambda (mode-hook) (add-hook mode-hook hook)) mode-hooks)) (when (fboundp 'auto-insert-mode) (auto-insert-mode 1) (setq auto-insert-query nil) (setq auto-insert-directory "~/templates/") (let ((py-template "template.py")) (when (file-exists-p (expand-file-name py-template auto-insert-directory)) (add-to-list 'auto-insert-alist `(("\\.py\\'" . "Python") . ,py-template)))) (let ((latex-template "template.tex")) (when (file-exists-p (expand-file-name latex-template auto-insert-directory)) (add-to-list 'auto-insert-alist `(("\\.tex\\'" . "LaTeX") . ,latex-template)))) (let ((css-template "template.css")) (when (file-exists-p (expand-file-name css-template auto-insert-directory)) (add-to-list 'auto-insert-alist `(("\\.css\\'" . "CSS") . ,css-template)))) (let ((js-template "template.js")) (when (file-exists-p (expand-file-name js-template auto-insert-directory)) (add-to-list 'auto-insert-alist `(("\\.js\\'" . "JS") . ,js-template)))) (let ((atom-template "template.atom")) (when (file-exists-p (expand-file-name atom-template auto-insert-directory)) (add-to-list 'auto-insert-alist `(("\\.atom\\'" . "Atom") . ,atom-template)))) (let ((html-template "template.html")) (when (file-exists-p (expand-file-name html-template auto-insert-directory)) (add-to-list 'auto-insert-alist `(("\\.html\\'" . "HTML") . ,html-template))))) (defun kr-major-mode-p (symbol) "Return non-nil if SYMBOL is a major mode. Used in `interactive' forms to read major mode names from the user." (and (fboundp symbol) (let ((function-name (symbol-name symbol))) (and (string-match "-mode\\'" function-name) (not (string-match "\\`turn-\\(on\\|off\\)-" function-name)))) (not (assq symbol minor-mode-alist)))) (defun ted-read-major-mode () "Read a major mode from the user, and return it. Based on Kevin Rogers' `edit-region' interactive spec." (intern (completing-read (format "Major mode (default `%s'): " major-mode) obarray 'kr-major-mode-p t nil nil (symbol-name major-mode)))) (defun kr-edit-region (&optional edit-mode) "Edit the current region in a separate buffer. With a prefix arg, change `major-mode' to EDIT-MODE." (interactive (list (when current-prefix-arg (ted-read-major-mode)))) (clone-indirect-buffer nil t) (narrow-to-region (region-beginning) (region-end)) (shrink-window-if-larger-than-buffer) (when edit-mode (funcall edit-mode))) (defun ted-kill-mode-buffers (&optional mode) "Kill all buffers of this major mode. With optional argument MODE, all buffers in major mode MODE are killed instead." (interactive (list (when current-prefix-arg (ted-read-major-mode)))) (setq mode (or mode major-mode)) (when (or current-prefix-arg (y-or-n-p (format "Really kill all %s buffers? " mode))) (mapc (lambda (buffer) (when (with-current-buffer buffer (eq major-mode mode)) (kill-buffer buffer))) (buffer-list)))) (defun help-default-arg-highlight (arg) "Upcase and fontify ARG for use with `eldoc-mode' and help." (propertize (upcase arg) 'face 'font-lock-variable-name-face)) (defun ted-find-mode (extension &optional interactive) "Returns the mode in which a file with EXTENSION would be opened." (interactive "sExtension: \np") (let ((mode (assoc-default (concat "." extension) auto-mode-alist 'string-match default-major-mode))) (when interactive (message "A file with extension .%s would be opened with mode %s" extension mode)) mode)) (defun ted-wash-smart-quotes () "Replace MS smart quotes with normal quotes in this buffer." (interactive) (save-excursion (let ((fixes '((342396 . "\"") (342392 . "'") (342387 . "--") (342397 . "\"") (342393 . "'")))) (goto-char (point-min)) (while (/= (point) (point-max)) (let* ((this (char-after (point))) (match (assq this fixes))) (when match (delete-char 1) (insert (cdr match)))) (forward-char 1))))) ;; linum from g.e.s -- much better than setnu (when (and (locate-library "linum") (facep 'fringe)) (setq linum-format (propertize "%5d " 'face 'fringe))) (add-to-list 'auto-mode-alist '("\\.egg\\'" . archive-mode)) (setq woman-use-own-frame nil) ;; Customizations particular to XEmacs. (when (featurep 'xemacs) (when (fboundp 'make-indirect-buffer) (make-indirect-buffer " *Message-Log*" "*Messages*")) (setq shifted-motion-keys-select-region nil unshifted-motion-keys-deselect-region nil) (setq display-warning-minimum-level 'error log-warning-minimal-level 'info) (setq paren-mode 'paren)) ;; Customizations which we only want to happen when we're using ;; Emacs on a TTY. (add-hook 'after-make-frame-functions (lambda (frame) (when (ted-tty-p (ted-frame-display frame)) (when (fboundp 'set-terminal-coding-system) (set-terminal-coding-system 'iso-8859-1)) (let ((hober-keymap (getenv "HOBER_KEYMAP")) (term (getenv "TERM"))) (when (and hober-keymap (string-equal hober-keymap "YES") term (string-equal term "cons25")) (when (fboundp 'normal-erase-is-backspace-mode) (normal-erase-is-backspace-mode -1)) (define-key function-key-map (kbd "ESC [ }") (kbd "")) ;% (define-key function-key-map (kbd "ESC [ J") 'event-apply-super-modifier) (define-key function-key-map (kbd "ESC [ ~") 'event-apply-hyper-modifier))) (setq browse-url-browser-function 'browse-url-lynx-emacs)))) ;;; Easy installing of third-party elisp. ;; `locate-file' isn't defined in Emacs 21. (when (and (not (featurep 'aquamacs)) (locate-library "install.el") (fboundp 'locate-file)) ;; install.el `require's em-glob.el (part of Eshell). There's a bug in ;; XEmacs' em-glob.el: it depends on esh-util.el but does not ;; `require' it. So we `require' it here. (require 'esh-util) ;; XEmacs doesn't bind `site-run-file' or `load-suffixes' by default, ;; and install.el assumes they're both bound. (let ((site-run-file (if (boundp 'site-run-file) site-run-file nil)) (load-suffixes (if (boundp 'load-suffixes) load-suffixes '(".elc" ".elc.gz" ".el" ".el.gz")))) (require 'install)) ;; Under Emacs, install.el figures out a good value of ;; `install-home-dir' by itself, but under XEmacs, it doesn't guess ;; correctly, so I explicitly set `install-home-dir' now. (setq install-home-dir ted-elisp-dir install-home-file ted-local-elisp-config) ;; don't automatically byte-compile under XEmacs. FIXME. (setq install-byte-compile (featurep 'emacs)) ;; install.el calls `update-directory-autoloads', which isn't defined ;; under XEmacs. So I defalias it here. ;; (XEmacs only has `batch-update-directory-autoloads'.) (unless (fboundp 'update-directory-autoloads) (defalias 'update-directory-autoloads 'ignore)) (defun ted-install-url (url) (interactive "sURL: ") (let ((filename (car (last (split-string url "/"))))) (when (= 0 (shell-command (format "curl -o %s \"%s\"" filename url))) (install-file filename)))) (defun ted-install-url-at-point () (interactive) (ted-install-url (thing-at-point-url-at-point)))) ;;; Various buffer-switching enhancements. (setq mouse-buffer-menu-mode-mult 1) (cond ((fboundp 'iswitchb-mode) (iswitchb-mode 1)) ((fboundp 'iswitchb-default-keybindings) (iswitchb-default-keybindings))) (add-hook 'iswitchb-define-mode-map-hook (lambda () (mapc (lambda (key) (define-key iswitchb-mode-map key nil)) (list (kbd "C-n") (kbd "C-k"))))) (add-to-list 'iswitchb-buffer-ignore "[*]Completions[*]") (setq ibuffer-fontification-alist '(;; read-only buffers (10 buffer-read-only eshell-ls-readonly-face) ;; emacs' "special" buffers (15 (string-match "^*" (buffer-name)) eshell-ls-special-face) ;; hidden buffers (20 (and (string-match "^ " (buffer-name)) (null buffer-file-name)) eshell-ls-symlink-face) ;; help buffers (25 (memq major-mode ibuffer-help-buffer-modes) eshell-ls-archive-face) ;; IRC buffers (30 (eq major-mode 'erc-mode) erc-notice-face) ;; dired buffers (35 (eq major-mode 'dired-mode) eshell-ls-directory-face))) ;;; gnuclient / emacsclient / remote editing (cond ((and (not (featurep 'multi-tty)) (locate-library "gnuserv")) (when (and (featurep 'emacs) ted-sufficiently-bsd-like-flag) (require 'gnuserv-compat nil t)) (unless (fboundp 'gnuserv-start) (require 'gnuserv)) (add-hook 'emacs-startup-hook (lambda () (when ted-server-emacs (gnuserv-start)))) (add-hook 'emacs-startup-hook (lambda () (setq gnuserv-frame (selected-frame))))) ((not ted-w32-flag) (setq display-buffer-reuse-frames t) (when (or (fboundp 'make-network-process) (file-executable-p (expand-file-name "emacsserver" exec-directory))) (add-hook 'emacs-startup-hook (lambda () (when ted-server-emacs (server-start))))))) (when (locate-library "tramp") (setq tramp-default-method "sudo")) ;;; Key bindings. (when (featurep 'multi-tty) (defun ted-delete-frame-or-kill-emacs () (interactive) (if (cdr (frame-list)) ; (> (length (frame-list)) 1) (delete-frame) (save-buffers-kill-emacs))) (global-set-key (kbd "C-x C-c") 'ted-delete-frame-or-kill-emacs)) (add-hook 'after-make-frame-functions (lambda (frame) (when (ted-w32-window-system-p frame) (setq w32-pass-lwindow-to-system nil w32-pass-rwindow-to-system nil w32-pass-alt-to-system nil w32-alt-is-meta t w32-pass-apps-to-system nil w32-lwindow-modifier 'super w32-rwindow-modifier 'hyper w32-apps-modifier nil) (define-key function-key-map (kbd "") (kbd ""))) (when (ted-aqua-p frame) (setq ns-alternate-modifier 'super ;; ns-function-modifier 'SOMETHING ;; ns-control-modifier 'SOMETHING ns-command-modifier 'meta)))) (mapc (lambda (key) (global-set-key key 'bury-buffer)) (list (kbd "s-z") (kbd "A-z") (kbd "M-z"))) (global-set-key (kbd " ") 'next-buffer) (global-set-key (kbd " ") 'previous-buffer) (when (fboundp 'list-text-properties-at) (global-set-key (kbd "C-c p") 'list-text-properties-at)) (when (fboundp 'find-function-setup-keys) (find-function-setup-keys)) (global-set-key (kbd "C-c u") 'ucs-insert) (global-set-key [SunPowerSwitch] 'save-buffers-kill-emacs) (global-set-key [SunCut] 'clipboard-kill-region) (global-set-key [SunCopy] 'clipboard-kill-ring-save) (global-set-key [SunPaste] 'clipboard-yank) (global-set-key [find] 'apropos) (global-set-key [SunOpen] 'find-file) (global-set-key [cancel] 'keyboard-quit) (global-set-key [SunProps] 'list-text-properties-at) (global-set-key [f14] 'undo) (global-set-key [f12] 'repeat) (global-set-key [f19] 'apropos) (global-set-key [f17] 'find-file) (global-set-key [f11] 'keyboard-quit) (global-set-key [insertchar] 'overwrite-mode) (when (fboundp 'find-file-at-point) (global-set-key (kbd "C-c F") 'find-file-at-point)) (global-set-key (kbd "C-x C-b") 'iswitchb-buffer) (global-set-key (kbd "C-x C-g") 'keyboard-quit) (global-set-key (kbd "C-x C-k") 'kill-buffer) (global-set-key (kbd "C-x f") 'find-file) (let ((map (make-sparse-keymap))) (define-key map (kbd "t") 'string-insert-rectangle) (global-set-key (kbd "C-c r") map)) (defun ted-macro-dwim (arg) "DWIM keyboard macro recording and executing." (interactive "P") (if defining-kbd-macro (if arg (end-kbd-macro arg) (end-kbd-macro)) (if last-kbd-macro (call-last-kbd-macro arg) (start-kbd-macro arg)))) (defun ted-macro-clear () "Clear out the last keyboard macro." (interactive) (setq last-kbd-macro nil) (message "Last keyboard macro cleared.")) (global-set-key (kbd "") 'ted-macro-dwim) ;% (global-set-key (kbd "M-") 'ted-macro-clear) (define-key esc-map (kbd "") 'ted-macro-clear) (global-set-key (kbd "C-s-x") 'eval-defun) (global-set-key (kbd "s-%") 'query-replace) (global-set-key (kbd "s-/") 'dabbrev-expand) (global-set-key (kbd "s-:") 'eval-expression) (global-set-key (kbd "s-;") 'comment-dwim) (global-set-key (kbd "s-<") 'beginning-of-buffer) (global-set-key (kbd "s-") 'just-one-space) (global-set-key (kbd "s-") 'backward-kill-word) (global-set-key (kbd "s->") 'end-of-buffer) (global-set-key (kbd "s-\\") 'delete-horizontal-space) (global-set-key (kbd "s-b") 'backward-word) (global-set-key (kbd "s-d") 'kill-word) (global-set-key (kbd "s-f") 'forward-word) (global-set-key (kbd "s-l") 'downcase-word) (global-set-key (kbd "s-p") (kbd "M-p")) (global-set-key (kbd "s-q") 'fill-paragraph) (global-set-key (kbd "s-v") 'scroll-down) (global-set-key (kbd "s-w") 'kill-ring-save) (global-set-key (kbd "s-x") 'execute-extended-command) (global-set-key (kbd "s-~") 'not-modified) (setq smerge-command-prefix (kbd "C-c s")) ;;; I initialize my *scratch* buffer with a random Emacs haiku drawn ;;; from among these: (defvar ted-emacs-haiku '("Oort is so awesome deuglifies Outlook crap `W k' rocks" "Great clouds overhead Tiny black birds rise and fall Snow covers Emacs -- Alex Schroeder" "hacking on Smyrno `error in process filter' something is b0rken" "Swiftly typing. Oh! Where would we be without you, `self-insert-command'?" "treeless quiet field sudden bud: EmacsWiki now he{ar,re} the birds sing -- ttn" "an emacs user's fingers dance on the keyboard; a nerd pianist -- Erik Bourget" "The file was open. flying in a sparrow stole a parenthesis -- Oliver Scholz" "The day went away. The file still puts its weight on the tired mode-line. -- Oliver Scholz" "On a cloudy day you hear the cons cells whisper: 'We are lost and gone.' -- Oliver Scholz" "A message, a string remind me of my sweet love. Good bye, my buffers. -- Oliver Scholz" "Hot night in summer: Hush, you quibbling characters! Do not wake her up! -- Oliver Scholz" "A bright, busy day. The windows watch a thousand wild cursors dancing. -- Oliver Scholz" "Oh, why don't you are a lake, a stream, a meadow this morning, Emacs? -- Oliver Scholz" ;% "The friends chat gaily, I stand up to join their talk. My `save-excursion'. -- Oliver Scholz") "Haiku taken from the Emacs Wiki's EmacsHaiku page.") (defun ted-random-emacs-haiku (&optional prefix) "Select and format a random haiku from `ted-emacs-haiku'." (random t) (let* ((prefix (or prefix ";; ")) (n (random (length ted-emacs-haiku))) (haiku (nth n ted-emacs-haiku))) (with-temp-buffer (insert haiku) (goto-char (point-min)) (while (< (point) (point-max)) (goto-char (point-at-bol)) (delete-horizontal-space) (insert prefix) (when (looking-at "--") (insert " ")) (forward-line 1)) (concat (buffer-substring-no-properties (point-min) (point-max)) "\n\n")))) ;; (setq initial-scratch-message (ted-random-emacs-haiku)) ;;; Major Emacs-based applications, and Emacs interfaces to other major ;;; applications. (when (require 'selftest nil t) (define-selftest exercise "Did I get >=20min of exercise yesterday" :group 'health :when 'always) (define-selftest early-to-rise "Did I get up at or before 7:30 AM today" :group 'health :when 'weekday) (define-selftest desk "Is my desk area clean and clutter-free" :group 'house :when 'weekday) (define-selftest dishes "Did I do dishes yesterday" :group 'house :when 'always) (define-selftest trash "Did I take out the trash yesterday" :group 'house :when 'always) (define-selftest books "Did I read from my book yesterday" :group 'mind :when 'always) (define-selftest backups "Have I backed up my computers in the last 30 days" :group 'tech :when 'always) (defun ted-selftest-work-p () "Is today a day I should take my work-related tests?" (let ((day-of-week (nth 6 (decode-time (current-time))))) (member day-of-week ;; Tue Wed Thu Fri Sat '(2 3 4 5 6)))) (define-selftest tickets "Did I close a ticket yesterday" :group 'work :when 'ted-selftest-work-p) (define-selftest billing "Are my records of my billable hours more up-to-date" :group 'work :when 'weekday) (define-selftest pride "Am I excited to give my scrum report" :group 'work :when 'weekday) (define-selftest oss "Did I contribute to open source last week" :group 'tech :when 'monday) (define-selftest microformats "Did I make a contribution to Microformats last week" :group 'tech :when 'monday) (define-selftest html5 "Did I make a contribution to HTML 5 last week" :group 'tech :when 'monday) (define-selftest emacs "Did I make a contribution to Emacs last week" :group 'tech :when 'monday) (define-selftest sleep "Did I get a full night's sleep last night" :group 'health :when 'always) (defun ted-selftest-alcohol-p () "Is today a day I should take my alcohol test?" (let ((day-of-week (nth 6 (decode-time (current-time))))) (member day-of-week ;; Tue Wed Thu '(2 3 4)))) (define-selftest alcohol "Did I have at most one drink yesterday" :group 'health :when 'ted-selftest-alcohol-p) (define-selftest phone-home "Did I talk to my parents last week" :group 'family :when 'monday) (define-selftest love "Did I tell Erin I love her yesterday" :group 'family :when 'always) (define-selftest attention "Did I keep up with the firehose yesterday" :group 'mind :when 'always) (define-selftest blogging "Did I post to one of my blogs yesterday" :group 'mind :when 'always) (define-selftest meals "Did I have three square meals yesterday" :group 'health :when 'always) ;; At some point yesterday, was my email inbox smaller than the low ;; point from the day before? (define-selftest inbox "Did I shrink my inbox over the last 2 days" :group 'mind :when 'always) (define-selftest cell-phone "Did I charge my cell phone yesterday" :group 'misc :when 'always) (define-selftest teeth "Did I brush my teeth at least twice yesterday" :group 'health :when 'always) (define-selftest voicemail "Was my voicemail inbox empty yesterday" :group 'mind :when 'always) (define-selftest meta "Did I run my personal unit tests yesterday" :group 'misc :when 'always) (define-selftest old-friends "Did I contact an old friend last week" :group 'misc :when 'monday) (define-selftest breakfast-with-erin "Did I have breakfast with Erin this morning" :group 'family :when 'weekday) (define-selftest water "Did I have at least 4 glasses of water yesterday" :group 'health :when 'always) (define-selftest laundry "Did I do or help with >=1 load of laundry last week" :group 'house :when 'monday) (define-selftest cooking "Did I prepare or help prepare >=1 dinner last week" :group 'house :when 'monday) (define-selftest elevator "Did I take the elevator at work at most one time yesterday?" :group 'work :when 'ted-selftest-work-p) ;; (define-selftest NAME ;; "DOCSTRING" ;; :group 'GROUP ;; :when 'always) ) (when (locate-library "ledger") (autoload 'ledger-mode "ledger" nil t)) (when (require 'emms nil t) (global-set-key (kbd "s-n") 'emms-next) (global-set-key (kbd "s-p") 'emms-previous) (global-set-key (kbd "s-s") 'emms-shuffle) (global-set-key (kbd "s-") 'emms-play-directory-tree) (global-set-key (kbd "s-") 'emms-stop)) ;; Emacs games (add-hook 'tetris-mode-hook 'ted-hide-trailing-whitespace) (when (locate-library "chess-auto") (load-library "chess-auto")) (when (locate-library "malyon") (autoload 'malyon "malyon" nil t) (add-hook 'malyon-mode-hook 'ted-hide-trailing-whitespace)) ;; Viper, the VI-like editor in Emacs ;; Enable Viper ;; (setq viper-mode t) ;; (add-hook 'emacs-startup-hook 'viper-mode) (setq viper-toggle-key (kbd "M-a")) (eval-after-load "viper-init" '(progn (mapc (lambda (hook) (remove-hook hook 'viper-restore-cursor-type)) '(viper-vi-state-hook viper-replace-state-hook viper-emacs-state-hook)) (remove-hook 'viper-insert-state-hook 'viper-set-insert-cursor-type))) (when (and (boundp 'viper-mode) viper-mode (featurep 'aquamacs)) ;; Fixes some kind of Viper/Aquamacs interaction issue (raise-frame)) (when (fboundp 'rsh) (setq remote-shell-program "ssh") (defalias 'ssh 'rsh)) ;; Eshell, the Emacs Shell (when (locate-library "eshell") (when (not (fboundp 'eshell)) (autoload 'eshell "eshell" nil t)) (add-hook 'eshell-mode-hook (lambda () (local-set-key (kbd "C-a") 'eshell-bol))) (setq eshell-cd-on-directory nil) (setq eshell-save-history-on-exit t eshell-hist-ignoredups nil) (setq eshell-default-target-is-dot t eshell-pushd-tohome t) (setq eshell-cmpl-cycle-completions nil) (setq eshell-banner-message (ted-random-emacs-haiku "")) (if ted-sufficiently-bsd-like-flag (defun ted-eshell-C-t () "Request status of the running Eshell command. Only works on BSD." (interactive) ;; An anamorphic `when' would be nice here. (let ((proc (eshell-interactive-process))) (if proc (progn (process-send-string proc (string 20))) (call-interactively 'transpose-chars)))) (defun ted-eshell-C-t () (interactive) (ding))) (add-hook 'eshell-mode-hook (lambda () (local-set-key (kbd "C-t") 'ted-eshell-C-t))) (defun ted-eshell-prompt () (let ((user (or (getenv "USER") (user-login-name) "ted")) (host (car (split-string (or (getenv "HOST") (system-name) "unknown") "\\."))) (char (if (= (user-uid) 0) "#" ":"))) (format "\n%s@%s%s " user host char))) (setq eshell-prompt-function 'ted-eshell-prompt) (setq eshell-prompt-regexp "^[^#:\n]*[#:] ") (autoload 'ansi-color-filter-apply "ansi-color") (add-hook 'eshell-preoutput-filter-functions 'ansi-color-filter-apply) (add-hook 'eshell-mode-hook (lambda () (local-set-key (kbd "s-p") 'eshell-previous-matching-input-from-input))) (when (featurep 'xemacs) (eval-after-load "esh-cmd" '(defun eshell-find-alias-function (name) "Check whether a function called `eshell/NAME' exists." (let* ((sym (intern-soft (concat "eshell/" name))) (file (symbol-file sym))) ;; If the function exists, but is defined in an eshell module ;; that's not currently enabled, don't report it as found (if (and file (string-match "\\(em\\|esh\\)-\\(.*\\)\\(\\.el\\)?\\'" file)) (let ((module-sym (intern (file-name-sans-extension (file-name-nondirectory (concat "eshell-" (match-string 2 file))))))) (if (and (functionp sym) (or (null module-sym) (eshell-using-module module-sym) (memq module-sym (eshell-subgroups 'eshell)))) sym)) ;; Otherwise, if it's bound, return it. (if (functionp sym) sym)))))) (setq eshell-aliases-file "~/.alias") (defun eshell/less (file) "Pager view of FILE." (view-file file) 0) (defalias 'eshell/more 'eshell/less) (defun eshell/rmb () "Remove Emacs backup files in this directory." (mapconcat (lambda (filename) (delete-file filename) filename) (directory-files default-directory nil "~\\'" t) ", ")) (setq eshell-scroll-show-maximum-output nil) (defalias 'eshell/clear 'ted-clear) (defun eshell/info (subject) "Read the Info manual on SUBJECT." (let ((buf (current-buffer))) (Info-directory) (let ((node-exists (ignore-errors (Info-menu subject)))) (if node-exists 0 (switch-to-buffer buf) (eshell-print (format "There is no Info manual on %s.\n" subject)) 1)))) (defun eshell/emacs (&rest args) "Open a file in Emacs. Some habits die hard." (if (null args) (bury-buffer) (mapc 'find-file (mapcar 'expand-file-name (eshell-flatten-list args)))) 0) (defalias 'eshell/emacsclient 'eshell/emacs) (defun eshell/vi (file) "Open a file with Viper." (with-current-buffer (find-file file) (setq viper-mode t) (viper-mode)) 0) (defalias 'eshell/concat 'eshell/cat) (eval-after-load "em-ls" '(progn (defvar ted-eshell-ls-keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "RET") 'ted-eshell-ls-find-file-at-point) (define-key map (kbd "") 'ted-eshell-ls-find-file-at-point) ;% (define-key map (if (featurep 'xemacs) (kbd "") (kbd "")) 'pat-eshell-ls-find-file-at-mouse-click) map)) (defadvice eshell-ls-decorated-name (after ted-electrify-ls activate) "Eshell's `ls' now lets you click or RET on file names to open them." (add-text-properties 0 (length ad-return-value) (list 'help-echo "RET, middle-click: visit this file" 'mouse-face 'highlight 'keymap ted-eshell-ls-keymap) ad-return-value) ad-return-value) (defun ted-eshell-ls-find-file-at-point (point) "RET on Eshell's `ls' output to open files." (interactive "d") (find-file (buffer-substring-no-properties (previous-single-property-change point 'help-echo) (next-single-property-change point 'help-echo)))) ;; Not defined in Emacs. (unless (fboundp 'event-point) (defun event-point (event) "Return the character position of mouse EVENT." (posn-point (event-end event)))) (defun pat-eshell-ls-find-file-at-mouse-click (event) "Middle click on Eshell's `ls' output to open files. From Patrick Anderson via the EmacsWiki." (interactive "e") (ted-eshell-ls-find-file-at-point (event-point event)))))) ;; Emacs web browsing, web searching, and more! (define-key minibuffer-local-must-match-map (kbd "?") nil) (define-key minibuffer-local-completion-map (kbd "?") nil) (when (locate-library "w3m") (autoload 'w3m "w3m" nil t) (autoload 'w3m-goto-url "w3m" nil t) (autoload 'w3m-region "w3m") (setq w3m-home-page (if (file-readable-p "~/html/home.html") (concat "file://" (expand-file-name "~/html/home.html")) "http://edward.oconnor.cx/home")) (setq w3m-use-toolbar t w3m-use-tab nil w3m-key-binding 'info) (setq w3m-search-default-engine "google") (setq w3m-command-arguments '("-F" "-cookie") w3m-mailto-url-function 'compose-mail browse-url-browser-function 'w3m mm-text-html-renderer 'w3m) (add-hook 'w3m-mode-hook 'ted-hide-trailing-whitespace) (eval-after-load "w3m" '(define-key w3m-mode-map (kbd "z") 'bury-buffer)) (defalias 'eshell/w3m 'w3m) (setq w3m-use-cookies t) (setq w3m-cookie-accept-bad-cookies t) (defun ted-w3m-edit-emacswiki-page (url) (let ((node (substring (substring w3m-current-url (string-match "wiki[/?][^/&=]+\\'" w3m-current-url)) 5))) (w3m-goto-url (concat "http://www.emacswiki.org/cgi-bin/wiki" "?action=edit;id=" node)))) (defun ted-delicious-url () "Bookmark this page with del.icio.us." (interactive) (w3m-goto-url (concat "http://del.icio.us/hober?" "url=" (w3m-url-encode-string w3m-current-url) "&title=" (w3m-url-encode-string w3m-current-title)))) (eval-after-load "w3m" '(progn (add-to-list 'w3m-uri-replace-alist '("\\`lj:\\(.+\\)" w3m-pattern-uri-replace "http://www.livejournal.com/users/\\1/")) (add-to-list 'w3m-edit-function-alist '(".*emacswiki.org/cgi-bin/wiki.*" . ted-w3m-edit-emacswiki-page)) (define-key w3m-info-like-map "a" 'ted-delicious-url)))) (when (locate-library "backpack") (setq backpack-username "hober") (defvar ted-backpack-map (make-sparse-keymap)) (global-set-key (kbd "C-c b") ted-backpack-map) (mapc (lambda (cons) (let ((command (car cons))) (autoload command "backpack" nil t) (define-key ted-backpack-map (cdr cons) command))) '((backpack-remind . "r") (backpack-remind-from-region . "R")))) (cond ((locate-library "twitter") (autoload 'twitter "twitter" nil t) (global-set-key (kbd "C-c t") 'twitter)) ((locate-library "twit") (autoload 'twit-post "twit" nil t))) (when (locate-library "twittering-mode") (autoload 'twit "twittering-mode" nil t) ;; Don't forget to set `twittering-password' locally. (setq twittering-username "hober") ;; Work-around for a bug in `twittering-mode' in some Emacsen. (unless (fboundp 'clear-image-cache) (defun clear-image-cache (&rest ignore)))) (setq google-referer "http://edward.oconnor.cx/") (when (ignore-errors (require 'g)) (setq g-user-email "hober0@gmail.com")) (when (locate-library "ell") (setq ell-locate t) (setq ell-goto-addr t) (autoload 'ell-packages "ell" nil t)) (when (locate-library "wikiarea") (autoload 'wikiarea "wikiarea" nil t) (setq wikiarea-managed-directory (expand-file-name "emacs-wiki/" ted-elisp-dir))) (when (require 'oddmuse nil t) (setq oddmuse-directory "~/wikis") (oddmuse-mode-initialize)) (when (locate-library "wikipedia-mode") (autoload 'wikipedia-mode "wikipedia-mode" nil t) (add-to-list 'auto-mode-alist '("\\.wiki\\'" . wikipedia-mode))) (when (locate-library "mediawiki-mode") (autoload 'mediawiki-mode "mediawiki-mode" nil t) (add-to-list 'auto-mode-alist '("\\.mw$" . mediawiki-mode)) ; $ ;; do this in a hook because mediawiki-mode resets its keybindings on ;; evey mode change. (add-hook 'mediawiki-mode-hook (lambda () (define-key mediawiki-mode-map (kbd "C-x C-s") 'save-buffer)))) ;; Email. (defalias 'gnw 'gnus) (when (locate-library "sieve-mode") (autoload 'sieve-mode "sieve-mode" nil t) (add-to-list 'auto-mode-alist '("\\.si\\(eve\\|v\\)\\'" . sieve-mode))) (setq mail-user-agent 'gnus-user-agent read-mail-command 'gnus) (setq mail-signature t mail-yank-prefix "> " mail-from-style 'angles) (defun ted-determine-gnus-version () "Determine the version of Gnus." (setq ted-oort+-flag (> (gnus-continuum-version (gnus-version)) 5.09))) (add-hook 'gnus-before-startup-hook 'ted-determine-gnus-version) (add-to-list 'auto-mode-alist '("\\.SCORE\\'" . gnus-score-mode)) (when (locate-library "boxquote") (defvar ted-boxquote-map (make-sparse-keymap)) (global-set-key (kbd "C-c q") ted-boxquote-map) (mapc (lambda (cons) (let ((command (car cons)) (key (cdr cons))) (autoload command "boxquote" nil t) (define-key ted-boxquote-map key command))) '((boxquote-region . "r") (boxquote-buffer . "b") (boxquote-insert-file . "i") (boxquote-yank . "y") (boxquote-defun . "F") (boxquote-paragraph . "p") (boxquote-describe-function . "f") (boxquote-describe-variable . "v") (boxquote-describe-key . "k") (boxquote-kill . "K") (boxquote-unbox . "u")))) (when (require 'bbdb nil t) (setq bbdb-default-country nil bbdb-debug nil bbdb-file "~/.bbdb" bbdb-completion-display-record nil bbdb-quiet-about-name-mismatches 0) (when (ted-coding-system-p 'utf-8) (setq bbdb-file-coding-system 'utf-8)) (bbdb-initialize 'sendmail 'gnus 'message) (when (fboundp 'eshell) (defun eshell/bbdb (regex) (bbdb regex nil))) (add-hook 'message-setup-hook 'bbdb-define-all-aliases)) (defconst ted-bbdb-flag (featurep 'bbdb)) ;; Dired, the Emacs directory editor. (require 'dired-x nil t) (setq dired-dwim-target t) (setq dired-recursive-deletes 'top dired-recursive-copies 'top) (when (locate-library "wdired") (autoload 'wdired-change-to-wdired-mode "wdired" nil t) (add-hook 'dired-load-hook (lambda () (define-key dired-mode-map (kbd "r") 'wdired-change-to-wdired-mode)))) ;; ljupdate, an Emacs LiveJournal client ;; When I have a local copy of my website, use the ljupdate there. (let ((web-lib "~/web/html/ljupdate/")) (when (file-directory-p web-lib) (add-to-list 'load-path web-lib))) (when (require 'ljupdate nil t) (setq lj-cache-login-information t lj-default-username "hober" lj-fill-function 'ignore) (global-set-key (kbd "C-c j c") 'lj-compose) (global-set-key (kbd "C-c j l") 'lj-login) ;; handy for developing / testing in *ielm* (setq lj "www.livejournal.com" dj "www.deadjournal.com")) ;; My home-grown blogging software (let ((web-lib "~/web/lib/")) (when (file-directory-p web-lib) (add-to-list 'load-path web-lib) (require 'atomblog nil t))) ;; ERC, an Emacs IRC client (when (locate-library "erc") (autoload 'erc "erc" nil t) (autoload 'erc-select "erc" nil t) (autoload 'erc-select-read-args "erc" nil nil) ; needed for XEmacs (autoload 'erc-select-ssl "erc" nil t) (setq erc-server "irc.freenode.net" erc-port 6667 erc-user-full-name "Edward O'Connor" erc-email-userid "ted" erc-nick '("hober" "hober2" "janTeto") erc-nicklist-use-icons nil erc-password nil ; set this in local config erc-nickserv-passwords nil ; set this in local config erc-anonymous-login t erc-auto-query 'bury erc-join-buffer 'bury erc-max-buffer-size 30000 erc-prompt-for-password nil erc-command-indicator "CMD" erc-echo-notices-in-current-buffer t erc-send-whitespace-lines nil erc-hide-list '("JOIN" "PART" "QUIT") erc-ignore-list '("jibot")) (setq erc-quit-reason-various-alist '(("brb" "I'll be right back.") ("lunch" "Having lunch.") ("dinner" "Having dinner.") ("food" "Getting food.") ("sleep" "Sleeping.") ("work" "Getting work done.") (".*" (yow)))) (setq erc-part-reason-various-alist erc-quit-reason-various-alist erc-part-reason 'erc-part-reason-various erc-quit-reason 'erc-quit-reason-various) (defvar ted-erc-autojoin t "Whether or not ERC should autojoin on connect.") (defvar ted-erc-identify t "Whether or not ERC should identify with NickServ on connect.") (setq erc-server-alist '(("a11y" a11y "irc.a11y.org" 6667) ("apple" apple "irc.apple.com" 6667) ("freenode" freenode "irc.freenode.net" 8001) ("w3c" w3c "irc.w3.org" 6665)) erc-networks-alist '((a11y "a11y.org") (apple "apple.com") (freenode "freenode.net") (w3c "w3.org"))) (defun ted-irc (netspec) "Interactively select an IRC network to connect to. Loosely based on `erc-server-select'." (interactive (list (assoc (completing-read "IRC network? " erc-server-alist nil t) erc-server-alist))) (let* ((network (nth 1 netspec)) (nick (car erc-nick)) (args (list :server (nth 2 netspec) :port (nth 3 netspec) :nick nick)) (password (cdr (assoc nick (cadr (assoc network erc-nickserv-passwords)))))) (when password (setq args (append (list :password password) args))) (setq ted-erc-identify (not (eq network 'freenode))) (apply 'erc args)))) ;; rcirc (when (locate-library "rcirc") (setq rcirc-nick "hober") (add-hook 'rcirc-mode-hook 'ted-hide-trailing-whitespace)) (when (locate-library "lisppaste") (autoload 'lisppaste "lisppaste" nil t) (setq lisppaste-default-nick "hober")) (when (locate-library "csv") (autoload 'csv-parse-buffer "csv")) ;;; Programming and other forms of document preparation. ;; http://article.gmane.org/gmane.emacs.devel/64807 (setq parse-sexp-ignore-comments t) (ignore-errors (require 'paredit)) (setq diff-switches "-u") (autoload 'diff-context->unified "diff-mode" nil t) (autoload 'diff-unified->context "diff-mode" nil t) (setq vc-follow-symlinks t) (defun ted-next-warning () "Advance to the next buffer location in `font-lock-warning-face'." (interactive) (let ((here (point))) (condition-case nil (progn (goto-char (next-property-change (point))) (while (not (memq (get-text-property (point) 'face) '(font-lock-warning-face js2-error-face js2-warning-face))) (goto-char (next-property-change (point))))) (error (goto-char here) (error "There are no more warnings in the buffer!"))))) (global-set-key (kbd "C-c n") 'ted-next-warning) (setq skeleton-pair t) (global-set-key "[" 'skeleton-pair-insert-maybe) (global-set-key "{" 'skeleton-pair-insert-maybe) (global-set-key "\"" 'skeleton-pair-insert-maybe) (setq glasses-separator "-" glasses-uncapitalize-regexp ".*" glasses-uncapitalize-p t) (let ((bzr-mode (locate-library "bzr-mode.el"))) (when bzr-mode (load bzr-mode))) (when (locate-library "gitsum") (autoload 'gitsum "gitsum" nil t)) (when (locate-library "psvn") (autoload 'svn-status "psvn" nil t)) (when (and (featurep 'emacs) (locate-library "vc-svn")) (unless (memq 'SVN vc-handled-backends) (add-to-list 'vc-handled-backends 'SVN))) (when (locate-library "pcmpl-darcs") (autoload 'pcomplete/darcs "pcmpl-darcs" nil nil)) (when (locate-library "darcsum") (autoload 'darcsum-whatsnew "darcsum" nil t)) (when (locate-library "vc-darcs") (when (ignore-errors (require 'vc)) (require 'vc-darcs) (when (boundp 'vc-handled-backends) (add-to-list 'vc-handled-backends 'DARCS)))) (defun ted-darcs-readonly-current () "Ensure we open files in darcs' current directory read-only." (when (string-match ".*/_darcs/current/.*" (buffer-file-name)) (toggle-read-only 1))) (add-hook 'find-file-hook 'ted-darcs-readonly-current) (add-to-list 'auto-mode-alist '("\\.cs\\'" . java-mode)) (defun ted-c-sharp-fix-tab-width () (when (string-match "\\.cs\\'" (buffer-file-name)) (setq tab-width 2))) (add-hook 'java-mode-hook 'ted-c-sharp-fix-tab-width) (defun ted-c-kill-backwards-into-nomenclature () "Delete the CamelCase word before point." (interactive) (let ((end (point))) (c-backward-into-nomenclature 1) (kill-region (point) end))) (defun ted-c-kill-forwards-into-nomenclature () "Delete the CamelCase word after point." (interactive) (let ((beg (point))) (c-forward-into-nomenclature 1) (kill-region beg (point)))) (let ((hooks '(c-mode-common-hook python-mode-hook js2-mode-hook espresso-mode-hook js-mode-hook)) (enable-subword-bindings (cond ((fboundp 'subword-mode) (lambda () (subword-mode 1))) ((fboundp 'c-subword-mode) (lambda () (c-subword-mode 1))) (t (lambda () (local-set-key (kbd "M-DEL") 'ted-c-kill-backwards-into-nomenclature) (local-set-key (kbd "M-d") 'ted-c-kill-forwards-into-nomenclature)))))) (mapc (lambda (hook) (add-hook hook enable-subword-bindings)) hooks)) (when (boundp 'auto-coding-alist) (add-to-list 'auto-coding-alist '("\\.[jw]ar\\'" . no-conversion)) (add-to-list 'auto-coding-alist '("\\.[JW]AR\\'" . no-conversion))) (add-to-list 'auto-mode-alist '("\\.[jw]ar\\'" . archive-mode)) (add-to-list 'auto-mode-alist '("\\.[JW]AR\\'" . archive-mode)) (when (locate-library "haskell-mode") (add-to-list 'auto-mode-alist '("\\.\\([hg]s\\|hi\\)\\'" . haskell-mode)) (add-to-list 'auto-mode-alist '("\\.l[hg]s\\'" . literate-haskell-mode)) (autoload 'haskell-mode "haskell-mode" nil t) (autoload 'literate-haskell-mode "haskell-mode" nil t) (mapc (lambda (hook) (add-hook 'haskell-mode-hook hook)) '(turn-on-haskell-font-lock turn-on-haskell-decl-scan turn-on-haskell-doc-mode turn-on-haskell-indent turn-on-haskell-hugs))) ;; Moved load of generic-x up before we look for javascript.el: both put ;; entries in `auto-mode-alist' for "\\.js\\'", and I want the entry ;; from javascript.el. (when (ignore-errors (require 'generic-x)) (setq default-major-mode 'default-generic-mode)) (defun ted-unescape-html (start end) (interactive "r") (save-excursion (goto-char start) (while (re-search-forward "&\\(lt\\|gt\\|quot\\|amp\\);" end t) (let* ((entities '(("quot" . "\"") ("amp" . "&") ("lt" . "<") ("gt" . ">"))) (replacement (assoc (match-string 1) entities))) (when replacement (replace-match (cdr replacement))))))) (defvar ted-html4-intrinsic-events '("load" "unload" "click" "dblclick" "mousedown" "mouseup" "mouseover" "mousemove" "mouseout" "focus" "blur" "keypress" "keydown" "keyup" "submit" "reset" "select" "change") "HTML4 intrinsic events.") (defvar ted-html4-entity-map '(;; latin-1 ("nbsp" . 160) ("iexcl" . 161) ("cent" . 162) ("pound" . 163) ("curren" . 164) ("yen" . 165) ("brvbar" . 166) ("sect" . 167) ("uml" . 168) ("copy" . 169) ("ordf" . 170) ("laquo" . 171) ("not" . 172) ("shy" . 173) ("reg" . 174) ("macr" . 175) ("deg" . 176) ("plusmn" . 177) ("sup2" . 178) ("sup3" . 179) ("acute" . 180) ("micro" . 181) ("para" . 182) ("middot" . 183) ("cedil" . 184) ("sup1 #185") ("ordm" . 186) ("raquo" . 187) ("frac14" . 188) ("frac12" . 189) ("frac34" . 190) ("iquest" . 191) ("Agrave" . 192) ("Aacute" . 193) ("Acirc" . 194) ("Atilde" . 195) ("Auml" . 196) ("Aring" . 197) ("AElig" . 198) ("Ccedil" . 199) ("Egrave" . 200) ("Eacute" . 201) ("Ecirc" . 202) ("Euml" . 203) ("Igrave" . 204) ("Iacute" . 205) ("Icirc" . 206) ("Iuml" . 207) ("ETH" . 208) ("Ntilde" . 209) ("Ograve" . 210) ("Oacute" . 211) ("Ocirc" . 212) ("Otilde" . 213) ("Ouml" . 214) ("times" . 215) ("Oslash" . 216) ("Ugrave" . 217) ("Uacute" . 218) ("Ucirc" . 219) ("Uuml" . 220) ("Yacute" . 221) ("THORN" . 222) ("szlig" . 223) ("agrave" . 224) ("aacute" . 225) ("acirc" . 226) ("atilde" . 227) ("auml" . 228) ("aring" . 229) ("aelig" . 230) ("ccedil" . 231) ("egrave" . 232) ("eacute" . 233) ("ecirc" . 234) ("euml" . 235) ("igrave" . 236) ("iacute" . 237) ("icirc" . 238) ("iuml" . 239) ("eth" . 240) ("ntilde" . 241) ("ograve" . 242) ("oacute" . 243) ("ocirc" . 244) ("otilde" . 245) ("ouml" . 246) ("divide" . 247) ("oslash" . 248) ("ugrave" . 249) ("uacute" . 250) ("ucirc" . 251) ("uuml" . 252) ("yacute" . 253) ("thorn" . 254) ("yuml" . 255) ;; special ; ("quot" . 34) ("amp" . 38) ("lt" . 60) ("gt" . 62) ("OElig" . 338) ("oelig" . 339) ("Scaron" . 352) ("scaron" . 353) ("Yuml" . 376) ("circ" . 710) ("tilde" . 732) ("ensp" . 8194) ("emsp" . 8195) ("thinsp" . 8201) ("zwnj" . 8204) ("zwj" . 8205) ("lrm" . 8206) ("rlm" . 8207) ("ndash" . 8211) ("mdash" . 8212) ("lsquo" . 8216) ("rsquo" . 8217) ("sbquo" . 8218) ("ldquo" . 8220) ("rdquo" . 8221) ("bdquo" . 8222) ("dagger" . 8224) ("Dagger" . 8225) ("permil" . 8240) ("lsaquo" . 8249) ("rsaquo" . 8250) ("euro" . 8364) ;; symbol ("fnof" . 402) ("Alpha" . 913) ("Beta" . 914) ("Gamma" . 915) ("Delta" . 916) ("Epsilon" . 917) ("Zeta" . 918) ("Eta" . 919) ("Theta" . 920) ("Iota" . 921) ("Kappa" . 922) ("Lambda" . 923) ("Mu" . 924) ("Nu" . 925) ("Xi" . 926) ("Omicron" . 927) ("Pi" . 928) ("Rho" . 929) ("Sigma" . 931) ("Tau" . 932) ("Upsilon" . 933) ("Phi" . 934) ("Chi" . 935) ("Psi" . 936) ("Omega" . 937) ("alpha" . 945) ("beta" . 946) ("gamma" . 947) ("delta" . 948) ("epsilon" . 949) ("zeta" . 950) ("eta" . 951) ("theta" . 952) ("iota" . 953) ("kappa" . 954) ("lambda" . 955) ("mu" . 956) ("nu" . 957) ("xi" . 958) ("omicron" . 959) ("pi" . 960) ("rho" . 961) ("sigmaf" . 962) ("sigma" . 963) ("tau" . 964) ("upsilon" . 965) ("phi" . 966) ("chi" . 967) ("psi" . 968) ("omega" . 969) ("thetasym" . 977) ("upsih" . 978) ("piv" . 982) ("bull" . 8226) ("hellip" . 8230) ("prime" . 8242) ("Prime" . 8243) ("oline" . 8254) ("frasl" . 8260) ("weierp" . 8472) ("image" . 8465) ("real" . 8476) ("trade" . 8482) ("alefsym" . 8501) ("larr" . 8592) ("uarr" . 8593) ("rarr" . 8594) ("darr" . 8595) ("harr" . 8596) ("crarr" . 8629) ("lArr" . 8656) ("uArr" . 8657) ("rArr" . 8658) ("dArr" . 8659) ("hArr" . 8660) ("forall" . 8704) ("part" . 8706) ("exist" . 8707) ("empty" . 8709) ("nabla" . 8711) ("isin" . 8712) ("notin" . 8713) ("ni" . 8715) ("prod" . 8719) ("sum" . 8721) ("minus" . 8722) ("lowast" . 8727) ("radic" . 8730) ("prop" . 8733) ("infin" . 8734) ("ang" . 8736) ("and" . 8743) ("or" . 8744) ("cap" . 8745) ("cup" . 8746) ("int" . 8747) ("there4" . 8756) ("sim" . 8764) ("cong" . 8773) ("asymp" . 8776) ("ne" . 8800) ("equiv" . 8801) ("le" . 8804) ("ge" . 8805) ("sub" . 8834) ("sup" . 8835) ("nsub" . 8836) ("sube" . 8838) ("supe" . 8839) ("oplus" . 8853) ("otimes" . 8855) ("perp" . 8869) ("sdot" . 8901) ("lceil" . 8968) ("rceil" . 8969) ("lfloor" . 8970) ("rfloor" . 8971) ("lang" . 9001) ("rang" . 9002) ("loz" . 9674) ("spades" . 9824) ("clubs" . 9827) ("hearts" . 9829) ("diams" . 9830) ) "Alist mapping HTML 4.01 named character entity references to their numerical counterparts. Taken from the HTML 4.01 specification: http://www.w3.org/TR/html401/") (defun ted-numericalize-entity () "Replace the named character entity reference at point with its numerical equivalent, if known." (interactive) (let ((end (point)) (start (search-backward "&" (- (point) 7) t))) (when start (if (looking-at "&\\([a-z][a-z0-9]+\\)") (let* ((name (match-string 1)) (num (cdr (assoc name ted-html4-entity-map)))) (if num (progn (delete-region start end) (insert (format "&#%s;" num)) t) (goto-char end) nil)) (goto-char end) nil)))) ;;; editing relax-ng compact schema (when (locate-library "rnc-mode") (autoload 'rnc-mode "rnc-mode" nil t) (add-to-list 'auto-mode-alist '("\\.rnc\\'" . rnc-mode))) ;;; markdown (when (locate-library "markdown-mode") (autoload 'markdown-mode "markdown-mode" nil t) (add-to-list 'auto-mode-alist '("\\.\\(markdown\\|mdml\\|mkdn\\|md\\)\\'" . markdown-mode))) (defvar ted-xml-mode 'xml-mode "Which major-mode to use for editing XML.") (defvar ted-html-mode 'html-mode "Which major-mode to use for editing HTML.") (defun ted-linkify-region (start end) (interactive "r") (let ((str (buffer-substring-no-properties start end))) (delete-region start end) (insert "" str ""))) ;;; nxml (when (and (featurep 'emacs) (or (load "rng-auto" t) (locate-library "nxml-mode"))) (unless (fboundp 'nxml-mode) (autoload 'nxml-mode "nxml-mode" nil t)) (unless (fboundp 'rng-validate-mode) (autoload 'rng-validate-mode "rng-valid" nil t)) (setq ted-xml-mode 'nxml-mode) ;; (setq ted-html-mode 'nxml-mode) (setq nxml-sexp-element-flag t nxml-slash-auto-complete-flag t) ;; Hack `;' in nxml mode to automatically fix named character entity ;; references. (defun ted-nxml-semicolon-dwim (&rest ignore) "If we've just typed an HTML 4 named character entity reference, replace it with its numerical equivalent. Otherwise, just insert `;'." (interactive) (or (ted-numericalize-entity) (insert ";"))) (when (boundp 'nxml-mode-abbrev-table) (add-hook 'nxml-mode-hook (lambda () (setq local-abbrev-table nxml-mode-abbrev-table)))) (eval-after-load "nxml-mode" '(progn (define-key nxml-mode-map (kbd "") 'ted-linkify-region) (define-key nxml-mode-map (kbd "RET") 'newline-and-indent) ;; Install my `;' hack. (define-key nxml-mode-map (kbd ";") 'ted-nxml-semicolon-dwim)))) (add-to-list 'auto-mode-alist (cons "\\.\\(x?html\\|xht\\)\\'" ted-html-mode)) (add-to-list 'auto-mode-alist (cons "\\.\\(jsp\\|tpl\\|tag\\)\\'" ted-html-mode)) (add-to-list 'auto-mode-alist (cons "\\.\\(wsd[dl]\\|tld\\|xslt\\)\\'" ted-xml-mode)) (let ((html5-lib "~/code/html5-el/")) (when (file-directory-p html5-lib) (add-to-list 'load-path html5-lib) (eval-after-load "rng-loc" '(add-to-list 'rng-schema-locating-files "~/code/html5-el/schemas.xml")) (require 'whattf-dt nil t))) (defvar ted-html4-link-relations '("alternate" "stylesheet" "start" "next" "prev" "contents" "index" "glossary" "copyright" "chapter" "section" "subsection" "appendix" "help" "bookmark") "http://www.w3.org/TR/html4/types.html#type-links") (defvar ted-html5-link-relations '("alternate" "archives" "author" "bookmark" "contact" "external" "feed" "first" "help" "icon" "index" "last" "license" "next" "nofollow" "pingback" "prefetch" "prev" "search" "stylesheet" "sidebar" "tag" "up") "http://www.whatwg.org/specs/web-apps/current-work/#linkTypes") (defvar ted-atom-link-relations '(;; http://atompub.org/rfc4287.html#rel_attribute "alternate" "related" "self" "enclosure" "via" ;; http://www.iana.org/assignments/link-relations/ "current" "edit" "edit-media" "first" "last" "next" "next" "payment" "prev" "previous") "") (defvar ted-xfn-link-relations '("contact" "acquaintance" "friend" ; Friendship "met" ; Physical "co-worker" "colleague" ; Professional "co-resident" "neighbor" ; Geographical "child" "parent" "sibling" "spouse" "kin" ; Family "muse" "crush" "date" "sweetheart" ; Romantic "me") ; Identity "http://gmpg.org/xfn/11") (defvar ted-uf-link-relations '("license" ; http://microformats.org/wiki/rel-license "nofollow" ; http://microformats.org/wiki/rel-nofollow "tag" ; http://microformats.org/wiki/rel-tag ;; Drafts "directory" ; http://microformats.org/wiki/rel-directory "enclosure" ; http://microformats.org/wiki/rel-enclosure "home" ; http://microformats.org/wiki/rel-home "payment" ; http://microformats.org/wiki/rel-payment ;; Exploratory "cite" ; http://microformats.org/wiki/distributed-conversation-brainstorming "group" ; http://microformats.org/wiki/group-brainstorming "product" ; http://microformats.org/wiki/rel-product "profile") ; http://microformats.org/wiki/xmdp-brainstorming#linking_to_the_XMDP "") (defvar ted-custom-link-relations '("http://edward.oconnor.cx/link-relations/include" "http://edward.oconnor.cx/link-relations/legacy" "http://edward.oconnor.cx/link-relations/listening" "http://edward.oconnor.cx/link-relations/livejournal" "http://edward.oconnor.cx/link-relations/pingback" "http://edward.oconnor.cx/link-relations/reddit" "http://edward.oconnor.cx/link-relations/stylesheet") "http://edward.oconnor.cx/link-relations/") (defvar ted-link-relations (remove-duplicates (sort (append ted-html4-link-relations ted-html5-link-relations ted-atom-link-relations ted-xfn-link-relations ted-uf-link-relations ted-custom-link-relations) 'string<)) "List of Atom and HTML link relations.") (defun ted-read-link-relation () "Read a link relation from the user, with completion." (interactive) (completing-read "Link relation: " ted-link-relations nil t)) (defun ted-read-link-relations () "Read link relations from the user until they hit RET." (interactive) (let ((relations '()) (relation (ted-read-link-relation))) (if (equal relation "me") relation (while (not (equal relation "")) (push relation relations) (setq relation (ted-read-link-relation))) (mapconcat (lambda (x) x) (sort relations 'string<) " ")))) (define-skeleton ted-rel-expand "Expand @rel." nil "rel=\"" (ted-read-link-relations) "\"") (defun ted-nuke-nofollow () (interactive) (save-excursion (goto-char (point-min)) (while (re-search-forward "\\s-*rel=[\"']nofollow[\"']" nil t) (replace-match "")))) (defvar ted-javascript-mode 'javascript-generic-mode "What major mode should I be using for JavaScript.") (cond ((locate-library "js") (setq ted-javascript-mode 'js-mode) (setq js-indent-level 4)) ((locate-library "espresso") (setq ted-javascript-mode 'espresso-mode) (autoload 'espresso-mode "espresso" nil t) (setq espresso-indent-level 4)) ((locate-library "js2-mode") (setq ted-javascript-mode 'js2-mode) (autoload 'js2-mode "js2-mode" nil t) (setq js2-highlight-level 3 js2-cleanup-whitespace nil js2-bounce-indent-p nil js2-auto-indent-p nil js2-indent-on-enter-key t) (add-hook 'js2-mode-hook (lambda () (setq mode-name "JS2")))) ((locate-library "javascript") (setq ted-javascript-mode 'javascript-mode) (setq js-indent-level 4 javascript-indent-level 4 javascript-auto-indent-flag nil) (autoload 'javascript-mode "javascript" nil t) (when (boundp 'javascript-mode-abbrev-table) (add-hook 'javascript-mode-hook (lambda () (setq local-abbrev-table javascript-mode-abbrev-table)))))) (add-to-list 'auto-mode-alist (cons "\\.htc\\'" ted-javascript-mode)) (add-to-list 'auto-mode-alist (cons "\\.[ja]s\\'" ted-javascript-mode)) (add-to-list 'auto-mode-alist (cons "\\.json\\'" ted-javascript-mode)) (when (locate-library "css-mode") (autoload 'css-mode "css-mode" nil t) (add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode)) (eval-after-load "css-mode" '(cond ((boundp 'cssm-indent-function) ; larsga's css-mode.el (add-hook 'css-mode-hook (lambda () (setq cssm-mirror-mode nil cssm-newline-before-closing-bracket nil cssm-indent-function 'cssm-c-style-indenter)))) ((fboundp 'css-extract-keyword-list) ; monnier's css-mode.el (setq css-basic-offset 2 css-indent-offset 2)) (t nil)))) (add-to-list 'auto-mode-alist (cons "\\.\\(rdf\\|rss\\|atom\\)\\'" ted-xml-mode)) (defun ted-insert-char-entity-maybe (char entity) (if (equal (preceding-char) char) (progn (backward-delete-char 1) (insert entity)) (insert char))) (eval-after-load "sgml-mode" '(progn (setq sgml-specials nil) (mapc (lambda (char-entity-alist) (let ((cmd `(lambda () (interactive) (ted-insert-char-entity-maybe ,(car char-entity-alist) ,(cdr char-entity-alist))))) (define-key html-mode-map (string (car char-entity-alist)) cmd))) '((?< . "<") (?> . ">") (?& . "&") (?\" . """) (?\' . "'"))))) (setq html-tag-face-alist '(("b" . bold) ("big" . bold) ("blink" . highlight) ("h1" bold underline) ("h4" . underline) ("h5" . underline) ("h6" . underline) ("rev" . modeline) ("s" . underline) ("small" . default) ("strong" . bold) ("title" bold underline) ("tt" . default) ("u" . underline) ;; Were italic ("cite" . default) ("em" . bold) ("h2" bold underline) ("h3" underline) ("i" . italic) ("var" . default))) (when (locate-library "js-comint") (autoload 'run-js "js-comint" nil t) (dolist (candidate '("node")) (when (executable-find candidate) (setq inferior-js-program-command candidate)))) (add-to-list 'auto-mode-alist '("\\.arc\\'" . lisp-mode)) ;; completion in M-: (when (keymapp read-expression-map) (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)) (defun ted-comment-sexp () (interactive) (call-interactively 'mark-sexp) (call-interactively 'comment-region)) (defun ted-install-lispy-bindings (map bind-ret) "FIXME" (define-key map (kbd "M-k") 'kill-sexp) (define-key map (kbd "\"") (find-if 'commandp '(paredit-doublequote skeleton-pair-insert-maybe))) (define-key map (kbd "C-M-;") 'ted-comment-sexp) (when bind-ret (define-key map (kbd "RET") (find-if 'commandp '(paredit-newline newline-and-indent)))) (define-key map (kbd "(") (find-if 'commandp '(paredit-open-parenthesis paredit-open-list insert-parentheses))) (define-key map (kbd ")") (find-if 'commandp '(paredit-close-parenthesis-and-newline ;; paredit-close-list-and-newline move-past-close-and-reindent)))) (ted-install-lispy-bindings (cond ((boundp 'lisp-mode-shared-map) lisp-mode-shared-map) ((boundp 'shared-lisp-mode-map) shared-lisp-mode-map) (t emacs-lisp-mode-map)) t) (eval-after-load "ielm" '(ted-install-lispy-bindings ielm-map nil)) (define-key minibuffer-local-map (kbd "M-i") (lambda () (interactive) (insert ?i))) (add-to-list 'auto-mode-alist '("\\.elc\\'" . emacs-lisp-mode)) (defun ted-dedangle-parens-in-region (start end) "De-dangle close parens between START and END." (interactive "r") (goto-char start) (while (re-search-forward "[ \t\n]+)" end t) (replace-match ")"))) (defun ted-make-lisp-idiomatic-in-region (start end) "Make the Lisp code from START to END a bit more idiomatic. You might consider running `checkdoc' as well." (interactive "r\nP") (save-restriction (widen) (narrow-to-region start end) (setq start (point-min-marker) end (point-max-marker)) (ted-dedangle-parens-in-region start end) (indent-region start end))) (add-hook 'after-make-frame-functions (lambda (frame) (when (display-graphic-p (ted-frame-display frame)) (require 'parenface nil t)))) (dolist (candidate '("mzscheme")) (when (executable-find candidate) (setq scheme-program-name candidate))) (define-skeleton ted-elisp-when-locate-library-skeleton "Skeleton for (when (locate-library \"foo\") ... ) forms." ;; This `completing-read' form based on `find-library's `interactive' ;; spec, but generalized to work under different Emacsen. (completing-read "Library name: " (when (fboundp 'locate-file-completion) 'locate-file-completion) (cons (if (boundp 'find-function-source-path) find-function-source-path load-path) ;; (find-library-suffixes) '(".el" ".el.gz" ".gz"))) "when (locate-library \"" str "\")") (when (locate-library "eldoc") (mapc (lambda (mode-hook) (add-hook mode-hook 'turn-on-eldoc-mode)) '(emacs-lisp-mode-hook lisp-interaction-mode-hook ielm-mode-hook)) (setq eldoc-argument-case 'help-default-arg-highlight)) (defun ted-macroexpand-sexp-at-point () "Replace the s-expresion at point with its macroexpansion." (interactive) (let (pre start end) (save-excursion (up-list -1) (setq start (point)) (setq pre (sexp-at-point)) (forward-sexp 1) (setq end (point))) (goto-char start) (kill-region start end) (pp (macroexpand pre) (current-buffer)))) (defun ted-indent-containing-sexp () "Fix the indentation of the sexp containing point." (interactive) (save-excursion (up-list -1) (indent-sexp))) (global-set-key (kbd "C-c i") 'ted-indent-containing-sexp) (setq ielm-prompt "* ") (add-to-list 'auto-mode-alist '("\\.asd\\'" . lisp-mode)) (add-to-list 'auto-mode-alist '("\\.lisp-expr\\'" . lisp-mode)) (mapc (lambda (hook) (add-hook hook (lambda () (set (make-local-variable 'lisp-indent-function) 'common-lisp-indent-function)))) '(lisp-mode-hook inferior-lisp-mode-hook)) (setq inferior-lisp-program (or (executable-find "sbcl") (executable-find "lisp") (executable-find "openmcl") (executable-find "clisp"))) (when (locate-library "slime") (autoload 'slime-mode "slime" nil t) (add-hook 'lisp-mode-hook (lambda nil (slime-mode 1))) (autoload 'inferior-slime-mode "slime" nil t) (add-hook 'inferior-lisp-mode-hook (lambda nil (inferior-slime-mode 1))) (add-hook 'slime-repl-mode-hook 'ted-hide-trailing-whitespace)) (cond ((commandp 'find-library) (defalias 'ted-find-library 'find-library)) ((fboundp 'find-library) (defun ted-find-library (library) "Open LIBRARY." (interactive "sLibrary: ") (find-library library))) (t (defun ted-find-library (library) "Open LIBRARY." (interactive "sLibrary: ") (let ((filename (locate-library (concat library ".el")))) (if (stringp filename) (find-file filename) (message "Library %s not found." library)))))) (global-set-key (kbd "C-c L") 'ted-find-library) (when (locate-library "dns-mode") (add-hook 'dns-mode-hook (lambda () (add-hook 'before-save-hook 'dns-mode-soa-increment-serial nil t)))) (when (locate-library "rpm-spec-mode") (unless (fboundp 'user-mail-address) (defun user-mail-address () "Returns the value of the `user-mail-address' variable." user-mail-address)) (autoload 'rpm-spec-mode "rpm-spec-mode" nil t) ;; RPM specfiles are .spec (add-to-list 'auto-mode-alist '("\\.spec\\'" . rpm-spec-mode))) (when (locate-library "rfcview") (autoload 'rfcview-mode "rfcview" nil t) (add-to-list 'auto-mode-alist '("rfc[0-9]+\\.txt" . rfcview-mode))) (when (locate-library "cfengine") (autoload 'cfengine-mode "cfengine" nil t) (add-to-list 'auto-mode-alist '("cf\\(\\.\\|agent\\.conf\\)" . cfengine-mode)) (defalias 'cfengine-beginning-of-line 'beginning-of-line) (setq cfengine-indent 4)) (defvar ted-ports-tree-root (cond ((eq system-type 'darwin) (concat "/opt/local/var/db/dports/sources/" "rsync.rsync.opendarwin.org_dpupdate_dports")) ((eq system-type 'berkeley-unix) "/usr/ports") (t nil)) "Directory under which this system's ports tree lives.") (when (and (stringp ted-ports-tree-root) (file-directory-p ted-ports-tree-root)) (defun ted-list-ports-tree-categories () (let* ((default-directory ted-ports-tree-root) (subdirs (directory-files default-directory nil "[a-z].*")) (case-fold-search nil) retval) (mapc (lambda (file) (when (and (file-directory-p file) (string-match "^[a-z]" file)) (push file retval))) subdirs) (nreverse retval))) (defun ted-list-ports-in-category (category) (let* ((default-directory (expand-file-name category ted-ports-tree-root)) (listing (directory-files default-directory)) subdirs) (mapc (lambda (file) (when (and (file-directory-p file) (string-match "^[a-z]" file)) (push file subdirs))) listing) (nreverse subdirs))) (defun ted-read-port () (let* ((categories (ted-list-ports-tree-categories)) (category (completing-read "Port category: " (mapcar (lambda (entry) (cons entry entry)) categories) nil t)) (ports (ted-list-ports-in-category category)) (port (completing-read "Port: " (mapcar (lambda (entry) (cons entry entry)) ports) nil t))) (concat category "/" port)))) (when (locate-library "ruby-mode") ;; Autoloads (autoload 'ruby-mode "ruby-mode" nil t) ;; File associations, etc. (add-to-list 'auto-mode-alist '("\\.rb\\'" . ruby-mode)) (add-to-list 'auto-mode-alist '("Rakefile\\'" . ruby-mode)) ;; fixme: use two-mode-mode when possible (add-to-list 'auto-mode-alist '("\\.rhtml\\'" . html-mode)) (add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode)) ;; Key bindings (eval-after-load "ruby-mode" '(define-key ruby-mode-map (kbd "RET") 'ruby-reindent-then-newline-and-indent)) ;; Install key bindings for running an inferior Ruby in `ruby-mode'. (when (locate-library "inf-ruby") (autoload 'run-ruby "inf-ruby" nil t) (autoload 'inf-ruby-keys "inf-ruby" nil) (add-hook 'ruby-mode-hook 'inf-ruby-keys)) ;; Skeletons (define-skeleton ted-rails-migrate-create-table "Skeleton for creating a table in a rails migration." "Table name: " > "create_table \"" str "\" do |t|" \n _ \n -2 "end" \n) (define-skeleton ted-rails-migrate-drop-table "Skeleton for dropping a table in a rails migration." "Table name: " > "drop_table \"" str "\"" \n) (define-skeleton ted-rails-migrate-table-column "Skeleton for adding a column in a rails migration." "Column name: " > "t.column \"" str "\", :" (skeleton-read "Column type: " "string")) (define-skeleton ted-rails-migrate-add-column "Skeleton for adding a column in a rails migration." "Table name: " > "add_column \"" str "\", \"" (skeleton-read "Column name: ") "\", :" (skeleton-read "Column type: " "string")) (define-skeleton ted-rails-migrate-remove-column "Skeleton for adding a column in a rails migration." "Table name: " > "remove_column \"" str "\", \"" (skeleton-read "Column name: ") "\"")) (when (locate-library "php-mode") (eval-after-load "php-mode" '(define-key php-mode-map (kbd "C-c C-n") 'ted-next-warning)) (autoload 'php-mode "php-mode" "PHP editing mode" t) (add-to-list 'auto-mode-alist '("\\.php[34]?\\'" . php-mode)) (define-skeleton ted-php-new-file-skeleton "New PHP file skeleton." nil "") (when (fboundp 'auto-insert-mode) (add-to-list 'auto-insert-alist `(("\\.php\\'" . "PHP") . ted-php-new-file-skeleton))) (add-to-list 'auto-mode-alist '("wp-content/themes/.*/.*\\.php\\'" . html-mode))) (when (locate-library "cperl-mode") (autoload 'cperl-mode "cperl-mode" nil t) (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode)) (fset 'perl-mode 'cperl-mode) (add-hook 'cperl-mode-hook 'turn-off-auto-fill) (setq cperl-hairy t)) ;;; Python (when (locate-library "pymacs") (autoload 'pymacs-load "pymacs") (defun ted-load-ropemacs () "Load ropemacs iff pymacs is installed and ropemacs isn't loaded." (interactive) (when (fboundp 'pymacs-load) (unless (featurep 'ropemacs) (pymacs-load "ropemacs" "rope-" t) (ropemacs-mode 1)))) (add-hook 'python-mode-hook 'ted-load-ropemacs)) (unless (locate-library "python") (when (locate-library "python-mode") (autoload 'python-mode "python-mode" nil t) (add-to-list 'auto-mode-alist '("\\.\\(py\\|tac\\)\\'" . python-mode)) (add-to-list 'interpreter-mode-alist '("python" . python-mode)))) (add-to-list 'auto-mode-alist '("\\.view\\'" . sql-mode)) (add-to-list 'auto-mode-alist '("\\.psql\\'" . sql-mode)) (setq sql-sqlite-program "sqlite3") (when (locate-library "maxima") (autoload 'maxima "maxima" nil t) (add-to-list 'auto-mode-alist '("\\.max\\'" . maxima)) (autoload 'maxima-mode "maxima" nil t)) (when (locate-library "imaxima") (autoload 'imaxima "imaxima" nil t) (setq imaxima-pt-size 12 imaxima-fnt-size "Huge" imaxima-image-type 'ps imaxima-use-maxima-mode-flag (locate-library "maxima"))) (when (require 'tex-site nil t) (setq-default TeX-auto-untabify nil) (setq TeX-auto-untabify nil)) ;; AUC-TeX (setq font-latex-script-display nil) ;; TeX mode (eval-after-load "tex-mode" '(defun tex-font-lock-suscript (pos) '(face default))) (when (locate-library "table") (autoload 'table-insert "table" nil t) (global-set-key (kbd "C-c t") 'table-insert)) (when (and (not (fboundp 'org-mode)) (locate-library "org")) (autoload 'org-mode "org" nil t)) (when (fboundp 'org-mode) (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) (global-set-key (kbd "C-c o l") 'org-store-link) (global-set-key (kbd "C-c o a") 'org-agenda)) (when (locate-library "noweb-mode") (autoload 'noweb-mode "noweb-mode" nil t) (add-to-list 'auto-mode-alist '("\\.nw\\'" . noweb-mode)) (setq noweb-mode-prefix (kbd "")) ;% (defadvice noweb-update-chunk-vector (around ted-noweb-redisplay activate) (let ((inhibit-redisplay t) (ted-noweb-redisplay-message "Updating noweb's chunk vector")) (message "%s..." ted-noweb-redisplay-message) ad-do-it (message "%s...done" ted-noweb-redisplay-message))) (eval-after-load "noweb-mode" '(fset 'noweb-fill-paragraph-chunk 'fill-paragraph)) (when (fboundp 'font-lock-add-keywords) (add-hook 'emacs-lisp-mode-hook (lambda () (when (and (boundp 'noweb-mode) noweb-mode) (font-lock-add-keywords nil '(("\\([<][<][^>]*[>][>]\\)" ;% (1 font-lock-string-face)))))))) (setq-default noweb-default-code-mode 'emacs-lisp-mode noweb-code-mode 'emacs-lisp-mode) (when (featurep 'xemacs) (unless (fboundp 'ess-write-to-dribble-buffer) (defalias 'ess-write-to-dribble-buffer 'ignore)) (add-hook 'noweb-mode-hook (lambda () (require 'noweb-font-lock-mode) (noweb-font-lock-mode 1))))) ;;; Work. (defun ted-thingatpt-install-rdar-uri-scheme () (add-to-list 'thing-at-point-uri-schemes "rdar://") (setq thing-at-point-url-regexp (concat "\\<\\(" (mapconcat 'identity thing-at-point-uri-schemes "\\|") "\\)" thing-at-point-url-path-regexp))) (eval-after-load "thingatpt" '(ted-thingatpt-install-rdar-uri-scheme)) ;;; Customizations which are specific to using Emacs under the various ;;; windowing systems. (global-set-key (kbd "C-c a") 'browse-url) (cond ((eq system-type 'darwin) (setq browse-url-browser-function 'browse-url-default-macosx-browser)) (t (dolist (candidate '("chromium-browser" "google-chrome")) (when (executable-find candidate) (setq browse-url-browser-function 'browse-url-generic browse-url-generic-program candidate))))) (setq default-frame-alist '()) (defun ted-frob-xterm (frame) (when (and (ted-xterm-p) (require 'xterm-frobs nil t)) (mapc (lambda (pair) (let ((key (car pair)) (value (cdr pair))) (cond ((eq key 'foreground-color) (xterm-set-background-color value)) ((eq key 'background-color) (xterm-set-foreground-color value)) ((eq key 'mouse-color) (xterm-set-mouse-foreground-color value)) ((eq key 'cursor-color) (xterm-set-cursor-color value))))) default-frame-alist))) (add-hook 'after-make-frame-functions 'ted-frob-xterm) (setq ns-antialias-text t) (defvar ted-fonts '(;; Free-as-in-* Consolas replacement "Inconsolata" ;; Very nice console font from Microsoft "Consolas" ;; Free-as-in-* standby "DejaVu Sans Mono" ;; Decent defaults on the Mac "Menlo" "Andale Mono" "Monaco" ;; My old X11 standbys "Screen" "Lucida Console" ;; A fallback that's on every system ever. "Courier") "Fonts I like, in decreasing order of preference.") (defvar ted-typographic-scale '(6 7 8 9 10 11 12 14 16 18 21 24 36 48 60 72) "The typographic scale used for selecting a font size.") (defvar ted-screen-height-to-type-size-ratio 56.0 "Ratio of screen height (in pixels) to my preferred type size.") (defun ted-closest-traditional-type-size (size) "Return the entry in `ted-typographic-scale' closest to SIZE." (caar (sort (mapcar (lambda (candidate) (cons candidate (abs (- size candidate)))) ted-typographic-scale) (lambda (a b) (< (cdr a) (cdr b)))))) (defun ted-guess-font-size () "Guess an appropriate font size for this display." (ted-closest-traditional-type-size (/ (display-pixel-height) ted-screen-height-to-type-size-ratio))) (defvar ted-font-size (if window-system (ted-guess-font-size) nil) "My preferred font size. Can be overridden in `ted-local-elisp-config'.") (if (fboundp 'font-family-list) ;; New font backend (progn (defun ted-font-spec (font size) (format "%s-%d" font size)) (defun ted-find-font () "Return the first available font listed in `ted-fonts'." (let ((family-list (font-family-list))) (find-if (lambda (font) (member font family-list)) ted-fonts)))) ;; Old font backend (defun ted-font-spec (font size) (format "-*-%s-*-r-*-*-%d-*-*-*-*-*-*-*" (downcase font) size)) (defun ted-find-font () "Return the first available font listed in `ted-fonts'." (find-if (lambda (font) (x-list-fonts (ted-font-spec font ted-font-size))) ted-fonts)) (defun font-family-list () "Dummy `font-family-list'. So that `ted-set-font's `interactive' spec works in old Emacsen." ted-fonts)) (defvar ted-font (if window-system (ted-find-font) nil) "My preferred font. Can be overridden in `ted-local-elisp-config'.") (defun ted-set-font (&optional font size) "Figure out and install which font and size I use on this system. If called interactively, prompts the user for the font and size to use." (interactive (list (completing-read (format "Font (default %s): " ted-font) (font-family-list) nil t nil nil ted-font) (read-number "Size: " (ted-guess-font-size)))) (let* ((font (or font ted-font)) (size (or size ted-font-size)) (font-spec (ted-font-spec font size))) (setq ted-font-size size) (add-to-list 'default-frame-alist (cons 'font font-spec)) (set-frame-font font-spec))) (unless (ted-tty-p) (add-hook 'emacs-startup-hook 'ted-set-font)) (when (fboundp 'text-scale-increase) (global-set-key (kbd "M-=") 'text-scale-increase) (global-set-key (kbd "M--") 'text-scale-decrease)) (when (featurep 'emacs) (add-to-list 'default-frame-alist '(wait-for-wm . nil)) (add-to-list 'default-frame-alist (cons 'menu-bar-lines (ted-menu-bar-lines)))) (defvar ted-emacs-width nil "Iff non-null, the initial width that Emacs should use.") (defvar ted-emacs-height nil "Iff non-null, the initial height that Emacs should use.") (defvar ted-emacs-top nil "Iff non-null, the initial top that Emacs should use.") (defun ted-init-emacs-geometry () (when window-system (when ted-emacs-width (add-to-list 'default-frame-alist (cons 'width ted-emacs-width))) (when ted-emacs-height (add-to-list 'default-frame-alist (cons 'height ted-emacs-height))) (when ted-emacs-top (add-to-list 'default-frame-alist (cons 'height ted-emacs-top)))) ;; Finally, ensure both frame alists are the same. (setq initial-frame-alist default-frame-alist)) (add-hook 'emacs-startup-hook 'ted-init-emacs-geometry) (when (fboundp 'menu-bar-mode) (menu-bar-mode (ted-menu-bar-lines))) (when (featurep 'xemacs) (set-specifier menubar-visible-p nil) (defun menu-bar-mode () (interactive) (set-specifier menubar-visible-p (not (specifier-instance menubar-visible-p))))) (when (display-graphic-p) (setq frame-title-format (concat (if (string-equal (user-login-name) "root") "SU: " "") "%b (" ted-emacs-name "@" (or (getenv "HOST") (system-name) "unknown") ")")) (cond ((featurep 'xemacs) (setq scrollbars-visible-p nil) (defun scroll-bar-mode () (interactive) (set-specifier vertical-scrollbar-visible-p (not (specifier-instance vertical-scrollbar-visible-p)))) (set-specifier horizontal-scrollbar-visible-p nil) (set-specifier vertical-scrollbar-visible-p nil)) ((fboundp 'scroll-bar-mode) (scroll-bar-mode -1))) (add-hook 'after-make-frame-functions (lambda (frame) (when (ted-w32-window-system-p frame) (scroll-bar-mode -1)))) (cond ((featurep 'xemacs) (customize-set-variable 'toolbar-visible-p nil) (setq toolbar-visible-p nil) (defun tool-bar-mode () (interactive) (set-specifier default-toolbar-visible-p (not (specifier-instance default-toolbar-visible-p)))) (set-specifier default-toolbar-visible-p nil)) ((fboundp 'tool-bar-mode) (tool-bar-mode -1) (add-to-list 'default-frame-alist '(tool-bar-lines . 0)))) (when (featurep 'xemacs) (when (boundp 'default-gutter-visible-p) (set-specifier default-gutter-visible-p nil)) (setq progress-feedback-use-echo-area t)) (when (featurep 'tooltip) (setq tooltip-gud-tips-p t))) (when (display-graphic-p) (setq focus-follows-mouse (eq (ted-window-system) 'x) mouse-autoselect-window t) (setq-default mouse-yank-at-point t) (cond ((fboundp 'mouse-wheel-mode) (mouse-wheel-mode 1)) ((locate-library "mwheel") (unless (fboundp 'mwheel-install) (autoload 'mwheel-install "mwheel" nil nil)) (setq mwheel-follow-mouse t) (setq mwheel-scroll-amount '(4 . 1)) (mwheel-install)))) (setq ns-pop-up-frames nil) ; NSEmacs (Emacs.app, aqua, from NeXT Emacs) (when (fboundp 'one-buffer-one-frame-mode) (setq one-buffer-one-frame nil) ; Aquamacs is dumb. (one-buffer-one-frame-mode 0)) (when (featurep 'aquamacs) (setq aquamacs-buffer-specific-frame-themes nil aquamacs-mode-specific-default-themes nil aquamacs-auto-frame-parameters-flag nil special-display-buffer-names nil special-display-regexps nil) (setq kill-emacs-query-functions (delq 'aquamacs-ask-to-save-options kill-emacs-query-functions))) (when (fboundp 'smart-frame-positioning-mode) (smart-frame-positioning-mode 0)) ;;; Customizing Emacs' colors. (autoload 'xterm-register-default-colors "term/xterm") (when (and (not window-system) (string-match "256color" (getenv "TERM"))) (xterm-register-default-colors)) (when (locate-library "face-list") (autoload 'customize-face-at "face-list" nil t) (global-set-key (kbd "C-c f c") 'customize-face-at) (autoload 'describe-face-at "face-list" nil t) (global-set-key (kbd "C-c f d") 'describe-face-at)) (when (display-color-p) (when (locate-library "htmlize") (autoload 'htmlize-buffer "htmlize" nil t)) (defun ted-stringify-face-name (face) "Blah blah blah." (when (listp face) (setq face (car (last face)))) (let ((name (if (symbolp face) (symbol-name face) face))) (if (string-match "^\\(font-lock-\\)?\\(.+?\\)\\(-name\\)?\\(-face\\)?$" ; $ name) (match-string 2 name) name))) (defvar ted-htmlize-face-translation-map '(;; I don't want to highlight parens in lisp (paren-face . nil) ;; Parts of X{,HT}ML I don't want to highlight (nxml-tag-delimiter . nil) (nxml-tag-delimiter-face . nil) (nxml-tag-slash . nil) (nxml-tag-slash-face . nil) (nxml-text . nil) (nxml-text-face . nil) ;; CSS (css-property . font-lock-function-name-face) ;; Map nXML faces onto standard font-lock faces (nxml-attribute-value-delimiter . font-lock-string-face) (nxml-attribute-value-delimiter-face . font-lock-string-face) (nxml-attribute-value . font-lock-string-face) (nxml-attribute-value-face . font-lock-string-face) (nxml-attribute-local-name . font-lock-builtin-face) (nxml-attribute-local-name-face . font-lock-builtin-face) (nxml-element-local-name . font-lock-keyword-face) (nxml-element-local-name-face . font-lock-keyword-face) ;; Makefiles (makefile-targets . font-lock-function-name-face) (makefile-shell . nil) ;; MML tags should look like types (message-mml-face . font-lock-type-face) (message-mml . font-lock-type-face)) "Blah blah blah") (defun ted-htmlize-face-at-point (&optional pos) "Blah blah blah." (unless pos (setq pos (point))) (let* ((face (get-text-property pos 'face)) (translation (member* face ted-htmlize-face-translation-map :key 'car))) (if translation (cdar translation) face))) (defun ted-htmlize-region (start end) "Place an htmlized version of the region into the kill ring." (interactive "r") (let ((code (buffer-substring start end)) (language (substring (symbol-name major-mode) 0 -5)) current-face) (with-temp-buffer (fundamental-mode) (font-lock-mode -1) (insert code) (goto-char (point-min)) (setq current-face (ted-htmlize-face-at-point)) (insert (format "
" language))
        (when current-face
          (insert (format "" (ted-stringify-face-name current-face))))

        (let (n-p-c)
          (while (setq n-p-c (next-property-change (point)))
            (goto-char n-p-c)
            (cond
             ((and current-face (eq current-face (ted-htmlize-face-at-point))))
             ((and current-face (null (ted-htmlize-face-at-point)))
              (insert "")
              (setq current-face nil))
             ((and current-face (ted-htmlize-face-at-point))
              (insert "")
              (setq current-face (ted-htmlize-face-at-point))
              (when current-face
                (insert (format ""
                                (ted-stringify-face-name current-face)))))
             ((ted-htmlize-face-at-point)
              (setq current-face (ted-htmlize-face-at-point))
              (when current-face
                (insert (format ""
                                (ted-stringify-face-name current-face))))))))
        (goto-char (point-max))
        (insert "
") (setq code (buffer-substring-no-properties (point-min) (point-max)))) (kill-new code))) (cond ((and (fboundp 'load-theme) (locate-library "hober2-theme")) (if (custom-variable-p 'custom-theme-load-path) ;; Emacs 24.x (progn (add-to-list 'custom-theme-load-path ted-elisp-dir) (load "hober2-theme") (enable-theme 'hober2)) (load-theme 'hober2))) ((require 'color-theme nil t) ;; (setq color-theme-is-cumulative nil) (require 'color-theme-hober2 nil t) (let ((theme (find-if 'fboundp '(color-theme-hober2 color-theme-resolve color-theme-hober)))) (when theme (add-hook 'emacs-startup-hook theme)))) ) (setq ansi-term-color-vector [unspecified "black" "orange red" "DarkGreen" "sandy brown" "dark slate blue" "pale violet red" "cadet blue" "gray"]) ;% (setq font-lock-maximum-size most-positive-fixnum) (add-hook 'after-init-hook (cond ((featurep 'xemacs) (require 'font-lock) (setq font-lock-auto-fontify t) (setq font-lock-support-mode 'lazy-lock-mode)) ((fboundp 'global-font-lock-mode) (lambda () (global-font-lock-mode 1))) ((fboundp 'toggle-global-lazy-font-lock-mode) (lambda () (toggle-global-lazy-font-lock-mode))))) (when (featurep 'xemacs) (mapc (lambda (hook) (add-hook hook (lambda () (font-lock-mode 1)))) '(lisp-interaction-mode-hook ielm-mode-hook latex-mode-hook))) (autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t) (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)) ;;; OS version-specific customizations. (when ted-lion-flag ;; Disable the iOS-like accent typing which interferes with holding down ;; alphanumeric keys. (when (fboundp 'ns-get-resource) (let ((pne-enabled "ApplePressAndHoldEnabled")) (unless (string-equal "NO" (ns-get-resource nil pne-enabled)) (ns-set-resource nil pne-enabled "NO")))) ) (when ted-snow-leopard-flag ) ;;; Host-specific customizations. (load ted-local-elisp-config t) (setq custom-unlispify-tag-names nil custom-unlispify-menu-entries nil custom-unlispify-remove-prefixes nil) (setq custom-file (expand-file-name (concat ted-emacs-name "-custom.el") ted-elisp-dir)) (load custom-file t) ;;; .emacs ends here