;;; John Dierdorf (dierdorf@io.com) customization for Emacs
(setq gc-cons-threshold 50000000)
(custom-set-variables)
(custom-set-faces)
(column-number-mode 1)
(mouse-wheel-mode 1)
(menu-bar-enable-clipboard)
(setq scroll-step 1) ;;single-step scrolling
(fset 'yes-or-no-p 'y-or-n-p) ;; simple y or n to answer questions
;;; load cperl mode for perl files
(fset 'perl-mode 'cperl-mode)
(setq-default indent-tabs-mode nil) ;;tabs converted to spaces
(setq-default tab-width 4)
(setq apropos-do-all t)
(setq lazy-lock-defer-on-scrolling t)
;;; (setq-default flyspell-mode t)
(setq dired-listing-switches "-l")
;;;;;;;;;; jd -- kb macros ;;;;;;;;;;
;;; find a line starting with blk or tab, insert a blank line
(fset 'blankbreak
[(menu-bar) search re-search-forward ?^ ?[ ? tab ?] return left return right])
;;; find next tab, delete it
(fset 'notab
[?\C-s ?\C-i ?\C-m backspace])
;;; end the most recent html
(fset 'ehtml
[?\C-r ?< ?\C- ?\C-s ?> ?\M-w end ?\C-y ?\C-r ?< right ?/ delete end])
;;; edit the file at the start of the line (eg, from grep)
;;;(fset 'show
;;; [?\C-a ?\C-s ?: left ?\M-w ?\C-x ?\C-f ?\C-y return])
;;; (replaced by lookat-file function)
;;; fill paragraph, move point to end of paragraph
(fset 'para
[?\M-x ?f ?i ?l ?l ?- ?p tab return C-down])
;;; find next line starting with capital letter or quote, insert line
(fset 'capbreak
[(menu-bar) search re-search-forward ?^ ?[ ?A ?- ?Z ?" ?] return left return right])
;;; another try at show-file at beginning of line (from grep)
;;;(fset 'show
;;; [home ?\C- ?\C-s ?: left (menu-bar) edit copy ?\C-x ?\C-f (menu-bar) edit paste return])
(fset 'equaldelete
[?\C-s ?= left delete delete])
;;; timestamp
(fset 'tims
[?\C-s ?L ?a ?s ?t ? ?m ?o ?d ?i ?v ?i ?e ?d ?\C-? ?\C-? ?\C-? ?\C-? ?f ?i ?e ?d ? ?\C-m ?\C-k ?\M-x ?t ?s return ?.])
;;; double-space next line
(fset 'ds
[(menu-bar) search re-search-forward ?^ ?[ ?A ?- ?Z ?a ?- ?z ?" ?' ?\\ ?( ?] return left return right])
(fset 'bb
[(menu-bar) search re-search-forward ?^ ?[ ? tab ?] return left return right (menu-bar) search re-search-forward ?^ ?[ ? tab ?] return left])
(fset 'spacelast
[?\C-\M-s ?[ ?. ?? ?! ?\" ?] ?$ ?\C-m return])
(fset 'nocm [?\M-r ?\C-q ?\C-m return return ?!] )
;;; one-key save-and-kill
(fset 'save-and-kill-buffer
[?\C-x ?\C-s ?\C-x ?k return])
;;;;;;;;;; jd -- interactive functions ;;;;;;;;;;
;;; translate unreadable characters
(defun qq ()
"translate unreadable characters in text file"
(interactive)
(let ((ll '(
"—" "--"
"“" "\""
"‹" "-"
"\214" "'"
"”" "\""
"’" "'"
"‘" "'"
"…" "..."
"–" "--"
"©" "(c)"
"
" ""
"---" "-"
"\\*\\*\\*" "*"
"===" "="
)))
(replace-loop ll)))
;;; convert html into text, more or less
(defun unhtml ()
"convert html into text, more or less"
(interactive)
(let ((ll '(
"*p>" ""
"*title>" ""
"
" ""
"*b>" ""
"*i>" ""
"*sup>" ""
"" ""
"" ""
"" " "
"" ""
"<\![if \!supportEmptyParas]> <\![endif]>" ""
"*h[0-6]>" ""
"*html>" ""
"*head>" ""
"
" ""
"*body>" ""
"" "")))
(replace-loop ll)))
;;; non-interactive -- used by unhtml, qq
;;; the arg is a list of from-to pairs of strings to be globally replaced
;;; "from" can be regexp
(defun replace-loop (ll)
(beginning-of-buffer)
(while ll
(replace-regexp (pop ll) (pop ll))
(beginning-of-buffer)))
;;; used by allnob, allnow
(defun fillrest ()
"Fill from point to end of buffer"
(interactive)
(set-mark (point))
(end-of-buffer)
(fill-region (mark) (point))
(end-of-buffer)
)
(defun eehtml ()
"end the most recent html code"
(interactive)
(save-excursion
(search-backward "<")
(set-mark (point))
(search-forward ">")
(copy-region-as-kill (mark) (point)))
(yank)
(save-excursion
(search-backward "<")
(forward-char 1)
(insert "/")))
(defun ec ()
(interactive)
(end-of-buffer)
(open-line 1)
(beginning-of-buffer)
(alldspace)
(beginning-of-buffer)
(allnow))
(defun allnob ()
"Remove leading whitespace, fill from point to end of buffer, add spaces between paragraphs."
(interactive)
(save-excursion
(qq))
(save-excursion
(noblankspace)
(fillrest)))
(defun rallnob ()
"Remove leading whitespace, fill marked region, add spaces between paragraphs."
(interactive)
(narrow-to-region (point) (mark))
(beginning-of-buffer)
(qq)
(save-excursion
(noblankspace)
(fillrest))
(end-of-buffer)
(widen))
(defun allnow ()
"Remove leading whitespace and reformat (fill) from point to end of buffer."
(interactive)
(save-excursion
(qq))
(save-excursion
(nowhitespace)
(fillrest)))
(defun rallnow ()
"Remove leading whitespace and reformat (fill) in marked region."
(interactive)
(narrow-to-region (point) (mark))
(beginning-of-buffer)
(qq)
(save-excursion
(nowhitespace)
(fillrest))
(end-of-buffer)
(widen))
(defun alldspace ()
"Double space from point to end of buffer"
(interactive)
(save-excursion
(beginning-of-line)
(while (not (eobp))
(open-line 1)
(next-line 2)))
)
(defun nowhitespace ()
"Remove lead ing whitespace from point to end of document."
(interactive)
(save-excursion
(while (replace-regexp "^[ ]+" ""))))
(defun noblankspace ()
"Remove leading whitespace and insert LFs from point to end of document."
(interactive)
(save-excursion
(while (replace-regexp "^[ ]+" "\n"))))
(defun alllast ()
"Add blanks based on ending of previous line."
(interactive)
(while (search-forward-regexp "[.!?\"\)] *$" nil t)
(open-line 1)
(next-line 2))
(beginning-of-buffer)
(fillrest)
)
(defun ralllast ()
"Add blanks based on ending of previous lin in marked region."
(interactive)
(narrow-to-region (point) (mark))
(beginning-of-buffer)
(alllast)
(beginning-of-buffer)
(save-excursion
(nowhitespace)
(fillrest))
(end-of-buffer)
(widen))
(defun lookat-file ()
"Edit colon-delimited (e.g., from grep) file name at beginning of current line."
(interactive)
(save-excursion
(save-match-data
(beginning-of-line)
(search-forward-regexp "^\\([^:]*\\)")
(find-file (match-string 1)))))
(defun kfile ()
"Delete colon-delimited (e.g., from grep) file name at beginning of current line."
(interactive)
(save-excursion
(save-match-data
(beginning-of-line)
(search-forward-regexp "^\\([^:]*\\)")
(delete-file (match-string 1))
(message "%s deleted." (match-string 1)))))
(defun tstamp ()
"Search for timestamp phrase, insert new date and time"
(interactive)
(search-forward "Last modified ")
(kill-line)
(insert (current-time-string) "."))
(defun tsstamp ()
"Insert html green date stamp, at least with current CSS"
(interactive)
(insert "[")
(shell-command "date +%d%b%y" 1)
(exchange-point-and-mark)
(backward-delete-char 1)
(insert "] ")
)
(defun oed-cite ()
"Insert cited OED at point"
(interactive)
(insert "oed ")
)
(defun ie-abbr ()
"Insert small-caps IE at point"
(interactive)
(insert "ie ")
)
(defun span ()
"Insert ... at point."
(interactive)
(insert "")
(backward-char 7)
)
(defun nonodiv()
(interactive)
(insert "\n\n\n\n\n
\n")
)
;;; for nono.html
(defun leadspan ()
"Insert ... at point."
(interactive)
(insert "")
(backward-char 7)
)
(defun nop ()
"Apply only to paragraph"
(interactive)
(mark-paragraph)
(narrow-to-region (point) (mark))
(beginning-of-buffer)
(allnow)
(widen)
(forward-paragraph)
(next-line 1)
)
(defun emdash ()
(interactive)
(insert " — "))
;;;;;;;;;; jd -- key redefinitions ;;;;;;;;;;
;;; map save-and-kill to CTL-V and F4, kill to F3
;;; (define-key global-map "" 'save-and-kill-buffer)
(define-key global-map [f4] 'save-and-kill-buffer)
(define-key global-map [f3] 'kill-this-buffer)
(define-key global-map [f5] 'equaldelete)
(define-key global-map [f6] 'bb)
(define-key global-map [f8] 'clipboard-yank)
(define-key global-map [f2] 'save-buffer)
(define-key global-map [f12] 'save-buffers-kill-emacs)
;;; map para to ESC-Q, replacing default
(define-key global-map "\eq" 'para)
;;; map query-replace to ESC-r
(define-key global-map "\er" 'query-replace)
;;; redefine home and end keys so they work right
(define-key global-map [end] 'end-of-line)
(define-key global-map [home] 'beginning-of-line)
(define-key global-map [C-end] 'end-of-buffer)
(define-key global-map [C-home] 'beginning-of-buffer)
(define-key global-map "\em" 'emdash)
(define-key global-map "\e," 'eehtml)
(define-key global-map "\es" 'flyspell-region)
;;;;;;;;;; jd -- set session defaults ;;;;;;;;;;
(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;;; turn on flyspell for text and html
;;; (add-hook 'html-helper-mode-hook 'flyspell-mode)
;;; (add-hook 'text-mode-hook 'flyspell-mode)
(setq-default transient-mark-mode t)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t) ;;all possible colors
;;;;;;;;;; jd - set up html helper mode
(setq load-path (cons "/usr/share/emacs21/site-lisp/html-helper-mode" load-path))
(autoload 'hilit19 "hilit19" "Yay HTML" t)
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
(setq auto-mode-alist (cons '("\.html?$" . html-helper-mode) auto-mode-alist))
(setq html-helper-never-indent t)
(setq tempo-interactive t)
(setq html-helper-do-write-file-hooks t)
(setq html-helper-build-new-buffer t)
;;;;;;;;;; jd - set up major mode IX
(setq load-path (cons "/home/dierdorf/bin" load-path))
(autoload 'ix-mode "ix-mode" "IX" t)
(setq auto-mode-alist (cons '("\.0ix?$" . ix-mode) auto-mode-alist))
;;; map lookat-file to CTL-F
(defvar ix-mode-map nil
"local keymap for ix mode buffers")
(if ix-mode-map
nil
(setq ix-mode-map (make-sparse-keymap))
(define-key ix-mode-map "" 'lookat-file)
(define-key ix-mode-map "^M" 'lookat-file)
(define-key ix-mode-map "\ek" 'kfile))
;;;;;;;;;; set up major mode css
;;; (autoload 'css-mode "css-mode")
;;; (setq auto-mode-alist (cons '("\\.css\\'" . css-mode) auto-mode-alist))
;;; (setq cssm-indent-function #'cssm-c-style-indenter)
;;;;;;;;;; misc. customizations
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(setq initial-frame-alist '((top . 1) (left . 1) (width . 100) (height . 42)))
(put 'narrow-to-region 'disabled nil)
;;begin buffer-switching methods, which I bind to F11 and Shift-F11
;; ----------------------------------------------------------------------
;; Original yic-buffer.el
;; From: choo@cs.yale.edu (young-il choo)
;; Date: 7 Aug 90 23:39:19 GMT
;;
;; Modified
;; ----------------------------------------------------------------------
(defun yic-ignore (str)
(or
;;buffers I don't want to switch to
(string-match "\\*Buffer List\\*" str)
(string-match "^TAGS" str)
(string-match "^\\*Messages\\*$" str)
(string-match "^\\*Completions\\*$" str)
(string-match "^ " str)
;;Test to see if the window is visible on an existing visible frame.
;;Because I can always ALT-TAB to that visible frame, I never want to
;;Ctrl-TAB to that buffer in the current frame. That would cause
;;a duplicate top-level buffer inside two frames.
(memq str
(mapcar
(lambda (x)
(buffer-name
(window-buffer
(frame-selected-window x))))
(visible-frame-list)))
))
(defun yic-next (ls)
"Switch to next buffer in ls skipping unwanted ones."
(let* ((ptr ls)
bf bn go
)
(while (and ptr (null go))
(setq bf (car ptr) bn (buffer-name bf))
(if (null (yic-ignore bn)) ;skip over
(setq go bf)
(setq ptr (cdr ptr))
)
)
(if go
(switch-to-buffer go))))
(defun yic-prev-buffer ()
"Switch to previous buffer in current window."
(interactive)
(yic-next (reverse (buffer-list))))
(defun yic-next-buffer ()
"Switch to the other buffer (2nd in list-buffer) in current window."
(interactive)
(bury-buffer (current-buffer))
(yic-next (buffer-list)))
;;end of yic buffer-switching methods
;; switch buffers with ctl-tab and ctl-shift-tab
(global-set-key [f11] 'yic-next-buffer) ;forward reference
(global-set-key [\S-f11] 'yic-prev-buffer) ;forward reference