Source

emacs / emacs.el

Full commit
;; Eugene Morozov's .emacs
;;

(eval-when-compile
  (require 'cl))

;; Variables describing environment Emacs is running in
(defvar running-on-windows (eq 'windows-nt system-type))
(defvar running-on-unix (not running-on-windows))
(defvar running-on-x (eq window-system 'x)
  "Whether emacs is running on X display.")
(defvar emacs-flavor
  (concat "gnuemacs-" (int-to-string emacs-major-version)))


;; Customization

;; Store customization information in file specific for emacs version
(setq custom-file (concat (expand-file-name "~/emacs/custom.") emacs-flavor ".el"))

;; Load customization information if it exists
(if (file-exists-p custom-file)
    (load custom-file))

;; load-path setup

;; Add to load-path directory "~/elisp" and all its subdirectories
(let* ((my-lisp-directory (expand-file-name "~/elisp"))
       (my-load-path (list my-lisp-directory)))
  (setq my-load-path
        (append (directory-files my-lisp-directory t nil t)
                my-load-path))
  (setq my-load-path (delete (concat my-lisp-directory "/.") my-load-path))
  (setq my-load-path (delete (concat my-lisp-directory "/..") my-load-path))
  (setq load-path (append my-load-path load-path)))

;; Add to load-path directory "~/emacs/packages" and all its subdirectories
(let* ((my-lisp-directory (expand-file-name "~/emacs/packages"))
       (my-load-path (list my-lisp-directory)))
  (setq my-load-path
        (append (directory-files my-lisp-directory t nil t)
                my-load-path))
  (setq my-load-path (delete (concat my-lisp-directory "/.") my-load-path))
  (setq my-load-path (delete (concat my-lisp-directory "/..") my-load-path))
  (setq load-path (append my-load-path load-path)))

(delete-if-not 'file-directory-p load-path)


;; Miscelanneous settings

(fset 'yes-or-no-p 'y-or-n-p)
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'rmail 'disabled t)

(setq inhibit-startup-screen t)

;; Make text mode default major mode
(setq default-major-mode 'text-mode)

(setq gc-cons-threshold 1000000)
(standard-display-8bit 128 255)

;; Scrolling settings
(setq scroll-conservatively 50)
(setq scroll-up-agressively 0)
(setq scroll-down-agressively 0)
(setq scroll-margin 5)

(transient-mark-mode 1)
(global-font-lock-mode t)

;; I hate that "emacs-snapshot-gtk" in the window title :)
(setq frame-title-format "(%m) %b")

;; Don't truncate lines in vertially split frames
(setq truncate-partial-width-windows nil)

;; Load packages required during initialization

(require 'cc-langs)
(require 'cc-mode)

(add-hook 'cperl-mode-hook (function (lambda () (imenu-add-menubar-index))))
(autoload 'cperl-mode "cperl-mode" "Alternate mode for editing Perl
       programs" t)
(setq interpreter-mode-alist
      (remove '("miniperl" . perl-mode)
              (remove '("perl" . perl-mode)
                      (remove '("perl5" . perl-mode) interpreter-mode-alist))))
(add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
(add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
(setq auto-mode-alist
      (remove '("\\.\\([pP]\\([Llm]\\|erl\\)\\|al\\)\\'" . perl-mode)
              auto-mode-alist))
(add-to-list 'auto-mode-alist
             '("\\.\\([pP]\\([Llm]\\|erl\\)\\|al\\)\\'" . cperl-mode))

;; Use nXML mode for XML files
(setq auto-mode-alist
      (remove '("\\.s?html?\\(\\.[a-zA-Z_]+\\)?\\'" . html-mode)
              (remove '("\\.x[ms]l\\'" . xml-mode)
                      (remove '("\\.s?html?\\'" . html-mode)
                              (remove '("\\.xml$" . xml-mode) auto-mode-alist)))))
(add-to-list 'auto-mode-alist
             '("\\.\\(pt\\|xul\\|xsl\\|zcml\\|x?html\\)\\'" . nxml-mode))

;; Load local packages

(autoload 'spamassassin-mode "spamassassin-mode" nil t)
(add-to-list 'auto-mode-alist
             '("\\.cf\\'" . spamassassin-mode))

;; PSVN subversion interface
(require 'psvn)

;; Mercurial support
(require 'ahg)

;; Dired extensions
(require 'dired+)
(require 'dired-sort-menu)
(require 'dired-sort-menu+)

;; Imenu extensions
(require 'imenu+)

;; Highlight column number in modeline when line is too long
(require 'modeline-posn)

;; Recent files menu
(recentf-mode)

;; LiveJournal client
(require 'ljupdate)

;; Easy browsing and editing of the kill-ring
;; URL: http://www.cis.ohio-state.edu/~walters/browse-kill-ring.el
(require 'browse-kill-ring)
(browse-kill-ring-default-keybindings)

;; Ledger mode
(autoload 'ledger-mode "ledger" "A mode for editing ledger data files." t)

;; Load support for dictionary lookups
;; URL: http://www.in-berlin.de/User/myrkr/dictionary.html
(autoload 'dictionary-search "dictionary"
  "Ask for a word and search it in all dictionaries" t)
(autoload 'dictionary-match-words "dictionary"
  "Ask for a word and search all matching words in the dictionaries" t)
(autoload 'dictionary-lookup-definition "dictionary"
  "Unconditionally lookup the word at point." t)
(autoload 'dictionary "dictionary"
  "Create a new dictionary buffer" t)
(autoload 'dictionary-mouse-popup-matching-words "dictionary"
  "Display entries matching the word at the cursor" t)
(autoload 'dictionary-popup-matching-words "dictionary"
  "Display entries matching the word at the point" t)
(autoload 'dictionary-tooltip-mode "dictionary"
  "Display tooltips for the current word" t)
(autoload 'global-dictionary-tooltip-mode "dictionary"
  "Enable/disable dictionary-tooltip-mode for all buffers" t)

(global-set-key [(control c) ?s] 'dictionary-search)
(global-set-key [(control c) ?m] 'dictionary-match-words)

;; auto-mode-alist setup

;; Open every file ending in .sql with sql mode
(setq auto-mode-alist (cons '("\\.sql$" . sql-mode) auto-mode-alist))

;; configure css-mode
(autoload 'css-mode "css-mode")
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-indent-level '2)
(setq cssm-mirror-mode nil)

;; c-mode setup

(defconst my-c-style
  '((c-basic-offset . 2)
    (c-comment-only-line-offset . (0 . 0))
    (c-offsets-alist . ((statement-block-intro . +)
                        (knr-argdecl-intro . 5)
                        (substatement-open . +)
                        (substatement-label . 0)
                        (label . 0)
                        (statement-case-open . +)
                        (statement-cont . +)
                        (arglist-intro . c-lineup-arglist-intro-after-paren)
                        (arglist-close . c-lineup-arglist)
                        (inline-open . 0)
                        (brace-list-open . +)
                        ))
    (c-special-indent-hook . c-gnu-impose-minimum)
    (c-block-comment-prefix . "")
    (c-hanging-braces-alist . ((substatement-open after)
                               (defun-open after))))
  "My C/C++ programming style")

(defun my-c-mode-common-hook ()
  (c-add-style "personal" my-c-style t)
  (imenu-add-menubar-index)
  (c-toggle-hungry-state 1))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


;; Fast file finder setup

;; Undefine C-c C-f binding -- fff needs it and I don't use it anyway
(define-key global-map [(control c) (control f)] nil)

;; Fast file finder
;; URL: ftp://ftp.splode.com/pub/users/friedman/emacs-lisp/fff.el
(require 'fff)
(fff-install-map)

;; Load modes for various config files
(require 'generic-x)

(autoload 'javascript-mode "javascript" nil t)

;; Remove dumb javascript-generic mode
(defun replace-alist-mode (alist oldmode newmode)
  (if (eq (cdr (car alist)) oldmode)
      (setcdr (car alist) newmode))
  (if (not (eq (cdr alist) nil))
      (replace-alist-mode (cdr alist) oldmode newmode)))

(replace-alist-mode auto-mode-alist 'javascript-generic-mode 'javascript-mode)


;; Cyrillic settings

;; Mime-edit setup
(setq-default mime-transfer-level 8)

;; MULE settings common to both emacsen
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)

(setq x-select-request-type 'UTF8_STRING)

(modify-coding-system-alist 'file "\\.txt\\'" 'utf-8)
(modify-coding-system-alist 'file "\\.html\\'" 'utf-8)
(modify-coding-system-alist 'network 6666 'koi8-r)

;; Load cyrillic keymap with unicode encoding under GNU Emacs
(load "~/emacs/unicode-im.el")
(setq default-input-method "cyrillic-jcuken-unicode")

;; Keys

;; Nice feature of XEmacs
(define-key global-map [(meta g)] 'goto-line)

(define-key global-map (kbd "C-c w") 'nuke-trailing-whitespace)

;; This code was taken from emacs wiki
(defun transpose-buffers (arg)
  "Transpose the buffers shown in two windows."
  (interactive "p")
  (let ((selector (if (>= arg 0) 'next-window 'previous-window)))
    (while (/= arg 0)
      (let ((this-win (window-buffer))
            (next-win (window-buffer (funcall selector))))
        (set-window-buffer (selected-window) next-win)
        (set-window-buffer (funcall selector) this-win)
        (select-window (funcall selector)))
      (setq arg (if (plusp arg) (1- arg) (1+ arg))))))

(define-key global-map "\C-x4t" 'transpose-buffers)

;;; Load additional settings
(load "~/emacs/rc/irc.el")
;; Abbrevs and completion
(load "~/emacs/rc/intellisense.el")
;; Python specific bindings and functions
(load "~/emacs/rc/python.el")
;; Javascript specific bindings and functions
(load "~/emacs/rc/javascript.el")
;; Slime specific settings
(load "~/emacs/rc/slime.el")
;; Org mode settings
(load "~/emacs/rc/org-mode.el")
;; Markup modes settings
(load "~/emacs/rc/markup.el")
;; Color themes
(cond (running-on-x
       (load "~/emacs/rc/color-theme.el")))

;; Keybindings for C-derived modes
(define-key c-mode-base-map "\C-cc" 'compile)
(define-key c-mode-base-map "\C-m" 'newline-and-indent)

;; Rebind C-x C-b for ibuffer
(define-key global-map [(control x) (control b)] 'ibuffer)

;; Gnus configuration
(setq gnus-select-method '(nntp "news.gmane.org"))

;; Never iconify
(define-key global-map [(control z)] nil)
(define-key global-map [(control x) (control z)] nil)

;; Hooks

(add-hook 'find-file-hook 'auto-insert)
(add-hook 'emacs-lisp-mode-hook 'imenu-add-menubar-index)
(add-hook 'javascript-mode-hook 'imenu-add-menubar-index)

(add-hook 'outline-mode-hook '(lambda ()
                                (font-lock-fontify-buffer)
                                (hide-body)))

;; Load settings for Emacs at work
(cond (running-on-windows
       (load "~/emacs/rc/work.el")))

(server-start)

(org-agenda-list)
(delete-other-windows)