Created
December 5, 2010 04:00
-
-
Save bradclawsie/728758 to your computer and use it in GitHub Desktop.
public .emacs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ------------------------------------------------------------- | |
(defun run-at-home () | |
(interactive) | |
(string-match "192" (shell-command-to-string | |
"/sbin/ifconfig -a|awk '/inet /'"))) | |
(defun run-on-inside () | |
(interactive) | |
(string-match "REDACTED" (shell-command-to-string | |
"/sbin/ifconfig -a|awk '/inet /'"))) | |
;; ------------------------------------------------------------- | |
;; global setup | |
(setq-default indent-tabs-mode nil) | |
(setq-default make-backup-files nil) | |
(setq-default column-number-mode t) | |
(setq-default ecb-options-version "2.32") | |
(setq-default ecb-wget-setup (quote cons)) | |
(setq-default tramp-default-user "REDACTED") | |
(setq-default tramp-default-host "localhost") | |
(setq-default mumamo-chunk-coloring (quote no-chunks-colored)) | |
(setq-default nxhtml-skip-welcome t) | |
(setq-default pgg-default-user-id "REDACTED") | |
(setq-default pgg-query-keyserver nil) | |
(setq confirm-nonexistent-file-or-buffer nil) | |
(setq inhibit-splash-screen t) | |
(setq display-time-24hr-format t) | |
(setq debug-on-error t) | |
(setq next-line-add-newlines nil) | |
(setq scroll-step 1) | |
(set-input-mode nil nil t) | |
(global-set-key "\C-l" `goto-line) | |
(global-set-key "\C-h" `delete-backward-char) | |
(global-set-key (kbd "C-x a") 'beginning-of-line) | |
(global-set-key (kbd "<f4>") 'eshell) | |
(global-set-key (kbd "<f5>") 'rename-buffer) | |
(global-set-key (kbd "<f6>") 'bzr-status) | |
(global-set-key [mouse-2] 'yank) | |
(global-font-lock-mode 1) | |
(mouse-wheel-mode t) | |
(fset 'yes-or-no-p 'y-or-n-p) | |
(display-time) | |
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)) | |
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1)) | |
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1)) | |
(if (fboundp 'blink-cursor-mode) (blink-cursor-mode 0)) | |
(setq-default transient-mark-mode t) | |
(standard-display-ascii ?\221 [?\']) | |
(standard-display-ascii ?\223 [?\"]) | |
(standard-display-ascii ?\224 [?\"]) | |
(standard-display-ascii ?\225 [?+]) | |
(standard-display-ascii ?\227 [?-]) | |
(standard-display-ascii ?\222 [?']) | |
(standard-display-ascii ?\205 [?.?.?.]) | |
;; ------------------------------------------------------------- | |
;; http://www.emacswiki.org/emacs/SlickCopy | |
(defadvice kill-ring-save (before slick-copy activate compile) | |
"When called interactively with no active region, copy a single line instead." | |
(interactive | |
(if mark-active (list (region-beginning) (region-end)) | |
(message "Copied line") | |
(list (line-beginning-position) | |
(line-beginning-position 2))))) | |
(defadvice kill-region (before slick-cut activate compile) | |
"When called interactively with no active region, kill a single line instead." | |
(interactive | |
(if mark-active (list (region-beginning) (region-end)) | |
(list (line-beginning-position) | |
(line-beginning-position 2))))) | |
;; ------------------------------------------------------------- | |
;; various external modes | |
;; magit | |
(load "~/.el/vcs/magit.elc") | |
(require 'ibuffer) | |
(global-set-key (kbd "C-x C-b") 'ibuffer-other-window) | |
(setq ibuffer-default-sorting-mode 'major-mode) | |
;; dvc / bzr | |
(add-to-list 'load-path "~/.el/vcs/dvc/lisp") | |
(load "~/.el/vcs/dvc/lisp/dvc-autoloads.elc") | |
(setq dvc-tips-enabled nil) | |
;; ido | |
(require 'ido) | |
(ido-mode t) | |
;; browse-kill-ring | |
(load "~/.el/util/browse-kill-ring.el") | |
(browse-kill-ring-default-keybindings) | |
(global-set-key (kbd "M-y") 'browse-kill-ring) | |
;; w3m | |
(add-to-list 'load-path "~/.el/net/w3m") | |
(require 'w3m-load) | |
;; recursive find | |
(load "~/.el/util/find-recursive.el") | |
;; anything! | |
(add-to-list 'load-path "~/.el/util") | |
(require 'anything) | |
(require 'anything-config) | |
;; better unfo | |
(require 'undo-tree) | |
(global-undo-tree-mode) | |
;; info | |
(require 'info) | |
(setq Info-default-directory-list | |
(append Info-default-directory-list '("~/info"))) | |
;; winner | |
(require 'winner) | |
(setq winner-dont-bind-my-keys t) | |
(winner-mode t) | |
(global-set-key (kbd "M-O d") 'windmove-left) | |
(global-set-key (kbd "M-O c") 'windmove-right) | |
(global-set-key (kbd "M-O a") 'windmove-up) | |
(global-set-key (kbd "M-O b") 'windmove-down) | |
(global-set-key (kbd "C-<left>") 'windmove-left) | |
(global-set-key (kbd "C-<right>") 'windmove-right) | |
(global-set-key (kbd "C-<up>") 'windmove-up) | |
(global-set-key (kbd "C-<down>") 'windmove-down) | |
(global-set-key (kbd "ESC <up>") 'other-window) | |
(global-set-key (kbd "ESC <down>") 'other-window) | |
;; midnight - clear old buffers | |
(require 'midnight) | |
(defvar clean-buffer-list-kill-never-buffer-names-init | |
clean-buffer-list-kill-never-buffer-names | |
"Init value for clean-buffer-list-kill-never-buffer-names") | |
(setq clean-buffer-list-kill-never-buffer-names | |
(append | |
'("*Kill Ring*" "*eshell*" "0" "1" "2" "3" "4" "5" | |
"*scratch*") | |
clean-buffer-list-kill-never-buffer-names-init)) | |
;; ------------------------------------------------------------- | |
;; for an editing mode, cleanup the buffer wrt to indenting and tabification | |
(defun clean-up-buffer-or-region () | |
"Untabifies, indents and deletes trailing whitespace from buffer or region." | |
(interactive) | |
(save-excursion | |
(unless (region-active-p) | |
(mark-whole-buffer)) | |
(untabify (region-beginning) (region-end)) | |
(indent-region (region-beginning) (region-end)) | |
(save-restriction | |
(narrow-to-region (region-beginning) (region-end)) | |
(delete-trailing-whitespace)))) | |
(global-set-key (kbd "C-c n") 'clean-up-buffer-or-region) | |
;; ------------------------------------------------------------- | |
;; modes for special tasks | |
;; wrap mode for text files | |
(autoload 'wrap-mode "~/.el/text/wrap-mode.el" "Toggle wrapping." t) | |
(setq auto-mode-alist (append '(("\\.txt$" . wrap-mode)) auto-mode-alist)) | |
(global-set-key (kbd "C-x C-j") `wrap-mode) | |
;; ------------------------------------------------------------- | |
;; date/time funcs | |
(defun say-date () | |
(interactive) | |
(message (format-time-string "%Y-%m-%d %R"))) | |
(global-set-key (kbd "<f9>") 'say-date) | |
(defun insert-time () | |
(interactive) | |
(insert (format-time-string "%Y-%m-%d-%R"))) | |
(defun insert-date () | |
(interactive) | |
(insert (format-time-string "%Y-%m-%d"))) | |
;; change email addresses from work to home | |
(defun cfm () | |
(interactive) | |
(goto-char (point-min)) | |
(while (search-forward "REDACTED" nil t) | |
(replace-match "REDACTED"))) | |
;; change email addresses from home to work | |
(defun bsc () | |
(interactive) | |
(goto-char (point-min)) | |
(while (search-forward "REDACTED" nil t) | |
(replace-match "REDACTED"))) | |
;; dos2unix | |
(defun dos2unix () | |
(interactive) | |
(goto-char (point-min)) | |
(while (search-forward "\r" nil t) | |
(replace-match ""))) | |
;; dictionary lookup | |
(defun lookup () | |
(interactive) | |
(setq lookup-term (read-string "term: ")) | |
(shell-command (concat "dict -h dict.org \"" lookup-term "\""))) | |
;; ------------------------------------------------------------- | |
;; http://github.com/rejeep/emacs/blob/master/rejeep-defuns.el | |
(defun nuke-all-buffers () | |
"Kill all buffers, leaving *scratch* only." | |
(interactive) | |
(mapcar (lambda (x) (kill-buffer x)) (buffer-list)) (delete-other-windows)) | |
(defun untabify-buffer () | |
"Replaces all tabs in the buffer with spaces." | |
(interactive) | |
(untabify (point-min) (point-max))) | |
(defun untabify-buffer-or-region () | |
"Replaces all tabs in the buffer with spaces." | |
(interactive) | |
(if mark-active | |
(untabify-buffer) | |
(untabify (point-min) (point-max)))) | |
(defun indent-buffer () | |
"Indents whole buffer." | |
(interactive) | |
(indent-region (point-min) (point-max))) | |
(defun indent-buffer-or-region () | |
"Indents region if any. Otherwise whole buffer." | |
(interactive) | |
(if mark-active | |
(call-interactively 'indent-region) | |
(indent-buffer))) | |
(defun open-line-below () | |
"Open a line below the line the point is at. | |
Then move to that line and indent accordning to mode" | |
(interactive) | |
(move-end-of-line 1) | |
(newline) | |
(indent-according-to-mode)) | |
(defun open-line-above () | |
"Open a line above the line the point is at. | |
Then move to that line and indent accordning to mode" | |
(interactive) | |
(move-beginning-of-line 1) | |
(newline) | |
(previous-line) | |
(indent-according-to-mode)) | |
(defun back-to-indentation-or-beginning-of-line () | |
"Moves point back to indentation if there is any | |
non blank characters to the left of the cursor. | |
Otherwise point moves to beginning of line." | |
(interactive) | |
(if (= (point) (save-excursion (back-to-indentation) (point))) | |
(beginning-of-line) | |
(back-to-indentation))) | |
(defun copy-region-to-scratch-buffer () | |
"Copies region to *scratch* buffer." | |
(interactive) | |
(append-to-buffer "*scratch*" (region-beginning) (region-end))) | |
(defun mark-current-line () | |
"Marks the current line. Mark is lower than point." | |
(interactive) | |
(set-mark (line-end-position)) | |
(back-to-indentation)) | |
(defun mark-whole-lines-region () | |
"Marks whole lines in the selected region." | |
(if (< (point) (mark)) | |
(beginning-of-line) | |
(end-of-line)) | |
(exchange-point-and-mark) | |
(if (< (point) (mark)) | |
(beginning-of-line) | |
(end-of-line)) | |
(exchange-point-and-mark)) | |
(defun comment-or-uncomment-whole-lines-or-region () | |
"Comments or uncomments whole lines in region. If no region is selected, | |
current line is commented or uncommented." | |
(interactive) | |
(save-excursion | |
(if mark-active | |
(mark-whole-lines-region) | |
(mark-current-line)) | |
(comment-or-uncomment-region (region-beginning) (region-end)))) | |
(defun match-paren (arg) | |
"Go to the matching paren if on a paren; otherwise insert %." | |
(interactive "p") | |
(cond ((looking-at "\\s\(") (forward-list 1)) | |
((looking-back "\\s\)") (backward-list 1)) | |
(t (self-insert-command arg)))) | |
(defun duplicate-current-line-or-region (arg) | |
"Duplicates the current line or region ARG times. | |
If there's no region, the current line will be duplicated. However, if | |
there's a region, all lines that region covers will be duplicated." | |
(interactive "p") | |
(let (beg end (origin (point))) | |
(if (and mark-active (> (point) (mark))) | |
(exchange-point-and-mark)) | |
(setq beg (line-beginning-position)) | |
(if mark-active | |
(exchange-point-and-mark)) | |
(setq end (line-end-position)) | |
(let ((region (buffer-substring-no-properties beg end))) | |
(dotimes (i arg) | |
(goto-char end) | |
(newline) | |
(insert region) | |
(setq end (point))) | |
(goto-char (+ origin (* (length region) arg) arg))))) | |
;; ------------------------------------------------------------- | |
;; macros | |
(fset 'switchbuffers | |
[?\C-x ?b]) | |
(global-set-key (kbd "C-c b") 'switchbuffers) | |
(fset 'checkin-vcs | |
[?\C-x ?v ?v]) | |
(global-set-key (kbd "C-c v") 'checkin-vcs) | |
;; ------------------------------------------------------------- | |
;; eshell funcs | |
(load "~/.el/util/esh-proc.el") | |
(setq eshell-prompt-function | |
(lambda () | |
(if (= (user-uid) 0) " # " " $ "))) | |
(eval-after-load "em-term" | |
'(add-to-list 'eshell-visual-commands "git-log")) | |
(eval-after-load "em-term" | |
'(add-to-list 'eshell-visual-commands "tig")) | |
(eval-after-load "em-term" | |
'(add-to-list 'eshell-visual-commands "perldoc")) | |
;; ------------------------------------------------------------- | |
;; ansi-term stuff | |
;; http://jfm3-repl.blogspot.com/2008/11/how-i-use-emacs-ansi-term.html | |
(setq centos-zsh "/bin/zsh") | |
(setq linux-zsh "/usr/bin/zsh") | |
(setq freebsd-zsh "/usr/local/bin/zsh") | |
(setq my-sh-program (cond ((file-exists-p centos-zsh) centos-zsh) | |
((file-exists-p linux-zsh) linux-zsh) | |
((file-exists-p freebsd-zsh) freebsd-zsh) | |
(t "/bin/sh"))) | |
(require 'term) | |
(defun visit-ansi-term () | |
"If the current buffer is: | |
1) a running ansi-term named *ansi-term*, rename it. | |
2) a stopped ansi-term, kill it and create a new one. | |
3) a non ansi-term, go to an already running ansi-term | |
or start a new one while killing a defunt one" | |
(interactive) | |
(let ((is-term (string= "term-mode" major-mode)) | |
(is-running (term-check-proc (buffer-name))) | |
(term-cmd my-sh-program) | |
(anon-term (get-buffer "*ansi-term*"))) | |
(if is-term | |
(if is-running | |
(if (string= "*ansi-term*" (buffer-name)) | |
(call-interactively 'rename-buffer) | |
(if anon-term | |
(switch-to-buffer "*ansi-term*") | |
(ansi-term term-cmd))) | |
(kill-buffer (buffer-name)) | |
(ansi-term term-cmd)) | |
(if anon-term | |
(if (term-check-proc "*ansi-term*") | |
(switch-to-buffer "*ansi-term*") | |
(kill-buffer "*ansi-term*") | |
(ansi-term term-cmd)) | |
(ansi-term term-cmd))))) | |
(global-set-key (kbd "<f2>") 'visit-ansi-term) | |
;; ------------------------------------------------------------- | |
;; erc | |
(defun yim () | |
(interactive) | |
(erc :server "REDACTED" :port "6667" :nick "REDACTED")) | |
(defun fn () | |
(interactive) | |
(erc :server "REDACTED" :port "6667" :nick "REDACTED")) | |
;; | |
(defun smuggersirc () | |
(interactive) | |
(erc :server "REDACTED" :port "6667" :nick "REDACTED")) | |
(add-hook 'erc-after-connect | |
'(lambda (SERVER NICK) | |
(cond | |
((string-match "freenode\\.net" SERVER) | |
(erc-message "PRIVMSG" "NickServ identify REDACTED")) | |
((string-match "irc\\.net" SERVER) | |
(erc-message "PRIVMSG" "NickServ identify REDACTED"))))) | |
;; ------------------------------------------------------------- | |
;; jabber | |
(add-to-list 'load-path "~/.el/net/jabber/share/emacs/site-lisp") | |
(load "~/.el/net/jabber/share/emacs/site-lisp/jabber-autoloads.el") | |
(setq jabber-account-list '( | |
("REDACTED" | |
;; (:password . nil) or (:password . "your-pass") | |
(:network-server . "talk.google.com") | |
(:port . 443) | |
(:connection-type . ssl)) | |
)) | |
;; ------------------------------------------------------------- | |
;; programming language modes | |
;; lisp slime | |
(setq inferior-lisp-program "/usr/bin/sbcl") | |
(if (run-on-inside) | |
(add-to-list 'load-path "/home/smugbin/local/share/emacs/site-lisp/slime") | |
(add-to-list 'load-path "/usr/share/emacs/site-lisp/-slime")) | |
(require 'slime) | |
(slime-setup) | |
;; haskell editing | |
(load "~/.el/lang/haskell-mode/haskell-site-file.el") | |
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) | |
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation) | |
;; quack (scheme) | |
(load "~/.el/lang/quack.el") | |
(require 'quack) | |
;; perl | |
(defalias 'perl-mode 'cperl-mode) | |
(autoload 'perl-mode "cperl-mode" "alternate mode for editing Perl programs" t) | |
(defun my-perl-setup () | |
(setq tab-width 4) | |
(setq c-basic-offset 4) | |
(setq indent-tabs-mode nil) | |
t) | |
(add-hook 'perl-mode-hook 'my-perl-setup) | |
;; c | |
(defun my-c-mode-hook () | |
(setq tab-width 4) | |
(setq c-basic-offset 4) | |
t) | |
(add-hook 'c-mode-common-hook 'my-c-mode-hook) | |
;; php | |
(load "~/.el/lang/php-mode.el") | |
(defun my-php-mode-hook () | |
(c-set-offset 'substatement-open 0) | |
(c-set-offset 'statement-case-open 0) | |
(c-set-offset 'case-label '+) | |
(setq tab-width 4) | |
(setq c-basic-offset 4) | |
(setq c-auto-newline nil) | |
(setq indent-tabs-mode nil) | |
(add-hook 'write-file-functions 'delete-trailing-whitespace) | |
t) | |
(add-hook 'php-mode-hook 'my-php-mode-hook) | |
;; if this is 23.2 or greater, do not use js2 mode, it has been replaced | |
(if (and (>= emacs-major-version 23) (>= emacs-minor-version 2)) | |
(progn | |
;; js-comint | |
(load "~/.el/lang/js-comint.el") | |
(setq inferior-js-program-command | |
"java -jar /home/brad/local/share/java/js.jar") | |
(add-hook 'js-mode-hook '(lambda () | |
(local-set-key "\C-x\C-e" | |
'js-send-last-sexp) | |
(local-set-key "\C-\M-x" | |
'js-send-last-sexp-and-go) | |
(local-set-key "\C-cb" | |
'js-send-buffer) | |
(local-set-key "\C-c\C-b" | |
'js-send-buffer-and-go) | |
(local-set-key "\C-cl" | |
'js-load-file-and-go) | |
)) | |
) | |
(progn | |
;; js2 mode for older emacs | |
(load "~/.el/lang/js2.elc") | |
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)) | |
;; js-comint | |
(load "~/.el/lang/js-comint.el") | |
(setq inferior-js-program-command | |
"java -jar /home/brad/local/share/java/js.jar") | |
(add-hook 'js2-mode-hook '(lambda () | |
(local-set-key "\C-x\C-e" | |
'js-send-last-sexp) | |
(local-set-key "\C-\M-x" | |
'js-send-last-sexp-and-go) | |
(local-set-key "\C-cb" | |
'js-send-buffer) | |
(local-set-key "\C-c\C-b" | |
'js-send-buffer-and-go) | |
(local-set-key "\C-cl" | |
'js-load-file-and-go) | |
)) | |
) | |
) | |
;; java | |
(defun my-java-mode-hook () | |
"Hook for running Java file..." | |
;;don't indent braces | |
(c-set-offset 'substatement-open 0) | |
(c-set-offset 'statement-case-open 0) | |
(c-set-offset 'case-label '+) | |
(setq tab-width 4) | |
(setq c-basic-offset 4) | |
(setq c-auto-newline nil) | |
(setq indent-tabs-mode nil) | |
t) | |
(add-hook 'java-mode-hook 'my-java-mode-hook) | |
;; smugmug extensions | |
(setq auto-mode-alist (append '(("/*.\.php\\w?" . php-mode) | |
("/*.\js.mgi$" . js2-mode) | |
("/*.\css.mgi$" . css-mode) | |
("/*.\.mg$" . php-mode) | |
("/*.\.mgi$" . php-mode)) | |
auto-mode-alist)) | |
;; ------------------------------------------------------------- | |
;; coloring | |
;; hard setting of fg and bg | |
(set-foreground-color "white") | |
(set-background-color "black") | |
;; ------------------------------------------------------------- | |
;; if at work, set up the vars for quick database connectivity | |
(if (string-match "inside" system-name) | |
(progn | |
(setq sql-connection-alist | |
'( | |
(db-sm | |
(sql-product 'mysql) | |
(sql-server "localhost") | |
(sql-user "REDACTED") | |
(sql-password "REDACTED") | |
(sql-database "REDACTED") | |
) | |
(db-st | |
(sql-product 'mysql) | |
(sql-server "REDACTED") | |
(sql-user "REDACTED") | |
(sql-password "REDACTED") | |
(sql-database "REDACTED") | |
) | |
(db-test | |
(sql-product 'mysql) | |
(sql-server "REDACTED") | |
(sql-user "REDACTED") | |
(sql-password "REDACTED") | |
(sql-database "REDACTED") | |
) | |
(db-statsslave | |
(sql-product 'mysql) | |
(sql-server "REDACTED") | |
(sql-user "REDACTED") | |
(sql-password "REDACTED") | |
(sql-database "REDACTED") | |
) | |
(db-globalslave | |
(sql-product 'mysql) | |
(sql-server "REDACTED") | |
(sql-user "REDACTED") | |
(sql-password "REDACTED") | |
(sql-database "REDACTED") | |
) | |
) | |
) | |
(defun sql-connect-preset (name) | |
"Connect to a predefined SQL connection listed in `sql-connection-alist'" | |
(eval `(let ,(cdr (assoc name sql-connection-alist)) | |
(flet ((sql-get-login (&rest what))) | |
(sql-product-interactive sql-product)))) | |
(sql-rename-buffer) | |
(toggle-truncate-lines) | |
) | |
(defun sql-db-test () | |
(interactive) | |
(sql-connect-preset 'db-test)) | |
(defun sql-db-st () | |
(interactive) | |
(sql-connect-preset 'db-st)) | |
(defun sql-db-sm () | |
(interactive) | |
(sql-connect-preset 'db-sm)) | |
(defun sql-db-statsslave () | |
(interactive) | |
(sql-connect-preset 'db-statsslave)) | |
(defun sql-db-globalslave () | |
(interactive) | |
(sql-connect-preset 'db-globalslave)) | |
)) | |
;; ------------------------------------------------------------- | |
;; server | |
(server-start) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment