;;; General settings (custom-set-faces '(button ((t nil))) '(cursor ((t (:background "#000000")))) '(custom-button ((((type x w32 mac) (class color)) (:background "#f0f0f0" :foreground "#303030" :box (:line-width 1 :color "#d5d5d5" :style released-button))))) '(erc-timestamp-face ((t (:foreground "#6090ff" :weight bold)))) '(flashcard-answer-face ((t (:foreground "green4")))) '(flashcard-input-face ((t (:foreground "black")))) '(flashcard-question-face ((t (:foreground "red")))) '(highlight ((((class color) (min-colors 88) (background light)) (:background "#fffea6")))) '(mode-line ((t (:background "#f0f0f0" :foreground "#333333" :box (:line-width 1 :color "#d5d5d5"))))) '(mode-line-highlight ((((class color) (min-colors 88)) (:underline "#303030")))) '(mode-line-inactive ((t (:background "#f0f0f0" :foreground "#606060" :box (:line-width 1 :color "#d5d5d5"))))) '(org-done ((t (:foreground "ForestGreen" :underline t)))) '(org-level-2 ((((class color) (background light)) (:foreground "#900000")))) '(org-level-3 ((((class color) (background light)) (:foreground "#d7720f")))) '(org-link ((((class color) (background light)) (:background "#eeeeee" :foreground "#303030")))) '(org-warning ((t (:foreground "Red" :underline t)))) '(region ((((class color) (min-colors 88) (background light)) (:background "#b8d8ff")))) '(show-paren-match ((((class color) (background light)) (:background "#7edcff")))) '(tooltip ((((class color)) (:inherit variable-pitch :background "#dddddd" :foreground "#303030")))) '(widget-field ((t (:background "#f0f0f0" :foreground "#333333"))))) (add-to-list 'load-path "/home/sztywny/.elisp") (add-to-list 'load-path "/home/sztywny/.elisp/rails") (add-to-list 'load-path "/usr/share/emacs/site-lisp/elscreen") (add-to-list 'load-path "/usr/share/emacs/site-lisp/emacs-w3m") (add-to-list 'load-path "/usr/share/emacs/site-lisp/ruby-mode") (add-to-list 'load-path "/usr/share/emacs/site-lisp/subversion") (add-to-list 'load-path "/usr/share/emacs/site-lisp/quack") (require 'anchored-transpose) (require 'browse-kill-ring) (require 'cl) (require 'compile) (require 'dired+) (require 'elscreen) (require 'filecache) (require 'flashcard) (require 'hide-lines) (require 'htmlize) (require 'quack) (require 'minibuffer-complete-cycle) (require 'nxml-mode) (require 'rng-valid) (require 'css-mode) (require 'paren) (require 'psvn) (require 'rails) (require 'slime) (require 'yaml-mode) (require 'w3m) (require 'msf-abbrev) (setq Info-directory-list (cons "/usr/share/info/emacs-22.0.90" Info-default-directory-list) auto-save-default nil calendar-week-start-day 1 common-lisp-hyperspec-root "file:/usr/share/doc/hyperspec-7.0/HyperSpec/" compilation-ask-about-save nil compilation-window-height 5 compilation-scroll-output t compilation-read-command nil compile-auto-highlight t default-left-fringe-width 0 default-right-fringe-width 0 desktop-save t elscreen-display-screen-number t elscreen-display-tab nil european-calendar-style t erc-encoding-coding-alist '(("#polska" . iso-8859-2)) erc-insert-away-timestamp-function (quote erc-insert-timestamp-left) erc-insert-timestamp-function (quote erc-insert-timestamp-left) erc-stamp-mode t erc-timestamp-right-column 0 fill-mode 1 font-lock-maximum-decoration t frame-title-format '("Emacs: %f") grep-find-ignored-directories '("CVS" ".svn" ".hg" "{arch}") grep-template "grep -n -e \"\" " history-length 250 icicle-prompt-suffix "" ido-everywhere t inhibit-default-init t inhibit-startup-message t ispell-library-directory "english" ispell-program-name "/usr/bin/aspell" kill-whole-line t make-backup-files nil mouse-yank-at-point t minibuffer-complete-cycle t msf-abbrev-root "/home/sztywny/.elisp/mode-abbrevs" next-line-add-newlines nil next-screen-context-lines 0 nxml-slash-auto-complete-flag t quack-pretty-lambda-p t quack-remap-find-file-bindings-p nil quack-run-scheme-always-prompts-p nil require-final-newline t ruby-electric-expand-delimiters-list nil save-abbrevs nil scroll-conservatively 1 sentence-end "[.?!][]\"')]*\\($\\|\t\\| \\)[ \t\n]*" sentence-end-double-space nil set-mark-command-repeat-pop t slime-startup-animation nil speedbar-show-unknown-files t svn-status-preserve-window-configuration t svn-status-verbose nil svn-status-window-alist '((diff nil) (log nil) (info nil) (blame nil) (proplist nil) (update invisible)) tramp-default-method "ftp" tramp-verbose 0 w3m-default-display-inline-images t w3m-form-input-textarea-buffer-lines 20 w3m-use-tab t w3m-use-cookies t) (setq-default abbrev-mode t truncate-lines t truncate-partial-width-windows nil left-margin-width 2 right-margin-width 2 save-place t scroll-up-aggressively 0 scroll-down-aggressively 0) (prefer-coding-system 'utf-8) (show-paren-mode t) (ido-mode t) (cua-mode) (auto-compression-mode t) (global-font-lock-mode t) (transient-mark-mode t) (delete-selection-mode t) (fset 'yes-or-no-p 'y-or-n-p) (set-scroll-bar-mode (quote right)) (partial-completion-mode +1) (server-start) (msf-abbrev-load) (toggle-dired-find-file-reuse-dir 1) ;;; Auto-compile ~/.emacs (defun byte-compile-init-file () (when (equal user-init-file buffer-file-name) (when (file-exists-p (concat user-init-file ".elc")) (delete-file (concat user-init-file ".elc"))) (byte-compile-file user-init-file)) (message "Compiling .emacs...")) (add-hook 'emacs-lisp-mode-hook (lambda () (add-hook 'after-save-hook 'byte-compile-init-file t t))) ;;; Macros (fset 'unfill (lambda (&optional arg) "Keyboard macro." (interactive "p") (kmacro-exec-ring-item (quote ([67108896 C-down up end 134217765 17 10 return 32 return 33 home down down] 0 "%d")) arg))) ;;; Various Elisp functions (defmacro defuni (name &rest body) `(defun ,name() (interactive) (progn ,@body))) (defuni todo () (find-file "~/txt/todo.txt")) (defuni notes () (find-file "~/txt/notes.txt")) (defuni insert-date () (insert (concat " [" (format-time-string "%d.%m.%y") "]"))) (defuni mycompile () (setq compile-command (concat "ruby " (buffer-file-name) " | sed -e 's/ //g' -e 's/\\\[/ /g' -e 's/ //g' -e 's/^\\\(.*\\\)test_helper\\\(.*\\\)$//g'")) (let ((compilation-window (get-buffer-window "*compilation*"))) (if (windowp compilation-window) (select-window compilation-window) (progn (split-window-vertically) (windmove-down) (enlarge-window -12) (switch-to-buffer "*compilation*")))) (call-interactively 'compile) (windmove-up)) (defuni linkify () (replace-regexp "http://[0-9A-Za-z-.&\/_$%@~\*']*" "\\&")) (defuni markdown () (mark-whole-buffer) (shell-command-on-region (point-min) (point-max) "bluecloth -f" t)) (defuni reindent () (point-to-register 'r) (indent-region (point-min) (point-max)) (register-to-point 'r)) (defuni swap-windows () (cond ((not (= (count-windows) 2)) (message "You need exactly 2 windows to do this.")) (t (let* ((w1 (first (window-list))) (w2 (second (window-list))) (b1 (window-buffer w1)) (b2 (window-buffer w2)) (s1 (window-start w1)) (s2 (window-start w2))) (set-window-buffer w1 b2) (set-window-buffer w2 b1) (set-window-start w1 s2) (set-window-start w2 s1))))) (defuni clear-buffer () (delete-matching-lines "^" (point-min) (point-max))) ;;; Project handling (defun recursive-directory-list (directory match-files-re match-dirs-not-re) (let (el-files-list (current-directory-list (directory-files-and-attributes directory t nil t))) (while current-directory-list (cond ((not (eq nil (string-match match-files-re (car (car current-directory-list))))) (setq el-files-list (cons (extract-not-project-dir (car (car current-directory-list))) el-files-list))) ((eq t (car (cdr (car current-directory-list)))) (if (or (equal "." (substring (car (car current-directory-list)) -1)) (not (eq nil (string-match match-dirs-not-re (car (car current-directory-list))) )) ) () (setq el-files-list (append (recursive-directory-list (car (car current-directory-list)) match-files-re match-dirs-not-re) el-files-list))))) (setq current-directory-list (cdr current-directory-list))) el-files-list)) (defun extract-project-dir (path) (string-match "/home/sztywny/projects/\\(.*?\\)/" path) (match-string 1 path)) (defun extract-project-dir-or-file (path) (string-match "/home/sztywny/projects/\\(.*?\\)$" path) (match-string 1 path)) (defun extract-not-project-dir (path) (string-match "/home/sztywny/projects/\\(.*?\\)/\\(.*\\)$" path) (match-string 2 path)) (defuni projects-list () (mapcar 'extract-project-dir-or-file (cddr (remove-if-not 'file-directory-p (directory-files "/home/sztywny/projects" t))))) (defuni current-project-dir () (if (or (eq nil (buffer-file-name)) (eq nil (extract-project-dir (buffer-file-name)))) (progn (let ((ido-make-buffer-list-hook (lambda () (setq ido-temp-list (projects-list))))) (ido-read-buffer "Choose project: "))) (extract-project-dir (buffer-file-name)))) (defuni my-svn () (svn-status (concat "/home/sztywny/projects/" (current-project-dir)))) (defuni my-switch-in-project () (defun my-ido-in-project (project-dir) (let ((ido-make-buffer-list-hook (lambda () (setq ido-temp-list (sort (recursive-directory-list project-dir "\\(.rb\\|.rhtml\\|.yml\\|.rjs\\|.css\\|.js\\)" ".svn.*") 'string<) )))) (ido-read-buffer "Switch to: "))) (let ((project-dir (concat "/home/sztywny/projects/" (current-project-dir)))) (find-file (concat project-dir "/" (my-ido-in-project project-dir))))) (defuni my-grep-in-rails-project () (let ((project-dir (current-project-dir)) (pattern (read-string "Enter pattern: " nil 'pattern))) (lgrep pattern (concat "/home/sztywny/projects/" project-dir "/**/*.(css|rb|rhtml|yml|rjs|js)")))) ;;; Key bindings (defmacro bind-key (key function) `(progn (global-set-key (read-kbd-macro ,key) ,function))) (defun bind-keys (bindings) (if (eq (cdr bindings) nil) t (progn (let ((key (car bindings)) (function (cadr bindings))) (bind-key key function) (bind-keys (cddr bindings)))))) (bind-keys '("" save-buffer "" dired-jump ;;; "" mmm-parse-buffer "" save-buffers-kill-emacs "s-a" mark-whole-buffer "s-b" ido-switch-buffer "s-c" mycompile "s-d" insert-date "s-D" svn-status-show-svn-diff "s-e" eval-buffer "s-f" my-switch-in-project "s-g" my-grep-in-rails-project "s-h" arorem-switch-view "s-i" reindent "s-j" recursive-edit "s-k" browse-kill-ring "s-m" markdown "s-n" notes "s-p" clear-buffer "s-r" swap-windows "s-s" sort-lines "s-t" todo "s-u" unfill "s-v" my-svn "s-w" w3m "M-o" find-file "C-M-s" save-buffer "C--" split-window-vertically "C-\\" split-window-horizontally "C->" indent-region "C-#" comment-or-uncomment-region "" dabbrev-expand "" find-file-at-point "" nil "C-M-+" split-window-vertically "C-M-|" split-window-horizontally "M-s" hs-show-block "M-h" hs-hide-block "M-S" hs-show-all "M-H" hs-hide-all "" windmove-down "" windmove-up "" windmove-left "" windmove-right "C-x b" ido-switch-buffer "C-x r a" string-insert-rectangle "C-x k" kill-this-buffer "C-x t" anchored-transpose "" end-of-line "" beginning-of-line "C-s" isearch-forward-regexp "C-r" isearch-backward-regexp "M-%" query-replace-regexp)) ;;; Text mode settings (setq default-major-mode 'text-mode) (defun my-text-mode-hook () (if (not (eq nil (buffer-file-name))) (if (string-match ".txt$" (buffer-file-name)) (auto-fill-mode))) (abbrev-mode)) (add-hook 'text-mode-hook 'my-text-mode-hook) ;;; Ruby settings (autoload 'ruby-mode "ruby-mode" "Major mode to edit ruby files." t) (setq auto-mode-alist (append '(("\\.rb$" . ruby-mode) ("\\.rjs$" . ruby-mode)) auto-mode-alist)) (setq interpreter-mode-alist (append '(("ruby" . ruby-mode)) interpreter-mode-alist)) (autoload 'run-ruby "inf-ruby" "Run an inferior Ruby process") (autoload 'inf-ruby-keys "inf-ruby" "Set local key defs for inf-ruby in ruby-mode") (defuni my-ruby-newline () (indent-according-to-mode) (newline-and-indent)) (add-hook 'ruby-mode-hook '(lambda () (require 'ruby-electric) (ruby-electric-mode) (define-key ruby-mode-map "\r" 'my-ruby-newline) (add-to-list 'compilation-error-regexp-alist '("\\(.*?\\)\\([0-9A-Za-z_./\:-]+\\.rb\\):\\([0-9]+\\)" 2 3)) (inf-ruby-keys) (add-to-list 'hs-special-modes-alist '(ruby-mode "\\(def\\|do\\)" "end" "#" (lambda (arg) (ruby-end-of-block)) nil)) (hs-minor-mode t))) ;;; Xmpfilter love (defadvice comment-dwim (around xmp-hack activate) "" (if (and (eq last-command 'comment-dwim) ;; TODO =>check ) (insert "=>") ad-do-it)) (defuni xmp () (let ((old-point (point))) (shell-command-on-region 1 (point-max) (xmp-command) t t) (goto-char old-point))) (defun xmp-command () (cond ((save-excursion (goto-char 1) (search-forward "< Test::Unit::TestCase" nil t)) "ruby -S xmpfilter.rb --unittest") ((save-excursion (goto-char 1) (re-search-forward "^context.+do$" nil t)) "ruby -S xmpfilter.rb --spec") (t "ruby -S xmpfilter.rb"))) ;;; RHTML settings (add-to-list 'auto-mode-alist '("\\.rhtml$" . nxml-mode)) ;;; YAML settings (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode)) (defun my-yaml-mode-hook () (define-key yaml-mode-map "\r" 'newline-and-indent)) (add-hook 'yaml-mode-hook 'my-yaml-mode-hook) ;;; SQL settings (setq sql-interactive-mode-hook (lambda () (define-key sql-interactive-mode-map "\t" nil))) (add-to-list 'same-window-buffer-names "*SQL*") ;;; C/C++ settings (defun my-c-mode-hook () (define-key c-mode-map "\r" 'newline-and-indent)) (add-hook 'c-mode-hook 'my-c-mode-hook) (defun my-c++-mode-hook () (define-key c++-mode-map "\r" 'newline-and-indent)) (add-hook 'c++-mode-hook 'my-c++-mode-hook) ;;; XHTML & CSS settings (add-hook 'html-mode-hook (lambda () (nxml-mode) (rng-auto-set-schema) (rng-validate-mode) (message "My html-mode customizations loaded"))) (add-hook 'nxml-mode-hook (lambda () (define-key nxml-mode-map "\r" 'newline-and-indent) (setq indent-tabs-mode nil) (setq local-abbrev-table nxml-mode-abbrev-table) (message "My nxml-mode customizations loaded"))) (autoload 'css-mode "css-mode") (setq auto-mode-alist (cons '("\\.css\\'" . css-mode) auto-mode-alist)) ;;; Scheme config (defuni my-run-scheme () (split-window-vertically) (run-scheme "mzscheme") (enlarge-window -15) (windmove-up)) (defuni my-surround-sexp() (insert "(") (forward-sexp) (insert ")") (backward-sexp) (forward-char)) (defuni scheme-load-current-file() (scheme-load-file buffer-file-name)) (add-hook 'scheme-mode-hook (lambda () (define-key scheme-mode-map [(return)] 'quack-newline) (define-key scheme-mode-map [(?\s-l)] 'my-run-scheme) (define-key scheme-mode-map [(?\s-c)] 'scheme-load-current-file) (define-key scheme-mode-map [(?\s-p)] 'my-surround-sexp))) (add-hook 'inferior-scheme-mode-hook (lambda () (define-key inferior-scheme-mode-map [(return)] 'quack-newline) (define-key inferior-scheme-mode-map [(shift return)] 'comint-send-input))) ;;; Lisp config (setq inferior-lisp-program "sbcl") (defuni my-run-lisp () (split-window-vertically) (windmove-down) (slime) (enlarge-window -15) (windmove-up)) (add-hook 'lisp-mode-hook (lambda () (slime-mode t) (define-key lisp-mode-map [(control j)] 'newline) (define-key lisp-mode-map [(control m)] 'newline-and-indent) (define-key lisp-mode-map [(?\s-l)] 'my-run-lisp) (define-key lisp-mode-map [(?\s-c)] 'slime-compile-and-load-file) (define-key lisp-mode-map [(control tab )] 'slime-complete-symbol) (set (make-local-variable lisp-indent-function) 'common-lisp-indent-function))) (add-hook 'emacs-lisp-mode-hook (lambda () (define-key emacs-lisp-mode-map "\r" 'newline-and-indent))) ;;; Various other stuff (add-to-list 'auto-mode-alist '("\\.deck\\'" . flashcard-mode)) ;;; Post initialization toys :> (if (not (boundp 'loaded)) (progn (find-file "~/txt/todo.txt") (switch-to-buffer "todo.txt"))) (setq loaded 1)