~ coder_ /.emacs

;; .emacs
;; Colin Drake

;; --Created by Emacs--
(desktop-load-default)
(desktop-read)
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(case-fold-search t)
 '(column-number-mode t)
 '(current-language-environment "UTF-8")
 '(debug-on-quit t)
 '(default-input-method "rfc1345")
 '(global-font-lock-mode t nil (font-lock))
 '(save-place t nil (saveplace))
 '(scroll-bar-mode (quote right))
 '(show-paren-mode t)
 '(tab-width 4)
 '(transient-mark-mode t)
 '(truncate-lines t)
 '(uniquify-buffer-name-style (quote forward) nil (uniquify))
 '(visible-bell t))
;; -- End Created by Emacs --

;; {{{ Includes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(load "~/.emacs.d/railsenv.el")
(load "~/.emacs.d/misc.el")
;; }}}

;; {{{ Color Scheme ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'color-theme)
(setq color-theme-is-global t)
(color-theme-charcoal-black)
;; }}}

;; {{{ Key bindings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-set-key "\C-z" 'goto-line)

;;; Interactive Regexp Replace
;;; 1 Escape + C-r/s = search, 1 Escapes is replace
(global-set-key "\e\e\C-r" 'iquery-backward-replace-regexp)
(global-set-key "\e\e\C-s" 'iquery-forward-replace-regexp)
;; }}}

;; {{{ Custom Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; An interactive version of the query-replace-regexp function  that lets you
;; see your regexp search before executing it (Safety first!)
(defun iquery-forward-replace-regexp ()
  "Interactive Regexp Replace Forwards"
  (interactive)
  (setq lineno (line-number-at-pos (point)))
  (isearch-forward-regexp)
  (goto-line lineno)
  (setq replace (read-from-minibuffer (concat "Replace regexp " (first regexp-search-ring) " with: ")))
  (while (re-search-forward (first regexp-search-ring) nil t)
        (replace-match replace)))

;; Same as above, but for backwards
(defun iquery-backward-replace-regexp ()
  "Interactive Regexp Replace Backwards"
  (interactive)
  (setq lineno (line-number-at-pos (point)))
  (isearch-backward-regexp)
  (goto-line lineno)
  (setq replace (read-from-minibuffer (concat "Replace regexp " (first regexp-search-ring) " with: ")))
  (while (re-search-backward (first regexp-search-ring) nil t)
        (replace-match replace)))
;; }}}