.emacs-my
author Oleksandr Gavenko <gavenkoa@gmail.com>
Wed, 23 Dec 2009 13:04:05 +0200
changeset 237 39054eb39d27
parent 215 404b444d990b
child 238 9bbf7d3d45b3
permissions -rw-r--r--
Added workaround to allow find-dired worked in Windows when interacrive shell set to bash..

;; -*- mode: lisp; coding: cp1251 -*-
;;
;; Copyright (C) 2008 by Oleksandr Gavenko <gavenkoa@gmail.com>
;;
;; This file formed from parts and ideas from many sites/docs and
;; placed in public domain.
;;
;; .emacs file for GNU Emacs.
;;
;; ~/.emacs load this file after ~/.emacs-pre, but before ~/.emacs-post.

;; ======================================================================
;; Debugging.

;; Shut off message buffer by setting nil.
(setq message-log-max 100)

;;(add-hook 'after-init-hook
;;    '(lambda () (setq debug-on-error t)))
;;(debug-on-entry 'command-line-1)

;; Set the debug option to enable a backtrace when a problem occurs.
(setq debug-on-error nil)               ; t/nil

;; ======================================================================
;; Настройка внешнего вида редактора.
;; View.

(menu-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
(scroll-bar-mode 1)

(if window-system
    ;; Для X-window и Win
    (progn
      ;;установка цветов экрана
      (set-background-color "white")
      (set-foreground-color "black")
      ;;установка режимов работы курсора
      (set-cursor-color "brown")
      ;;(setq blink-matching-delay 0.01)
      ;; курсор не мигает!
      ;; (blink-cursor-mode nil)
      ;; (set-face-font 'default "7x14")
      (fringe-mode 'default)
      )
  ;; Для tty
  (progn
    )
)

;; ----------------------------------------------------------------------
;; Silent runing.

;; (setq inhibit-splash-screen t) ; nonexist on 21.4.1
(setq inhibit-startup-message t)

;; ======================================================================
;; GNU Serv.

;; (load "~/emacs/bin/gnuserv/gnuserv.el")
;; (require 'gnuserv)
;; (setq gnuserv-frame (selected-frame))

(require 'server)
(when (and (= emacs-major-version 23) (equal window-system 'w32))
  (defun server-ensure-safe-dir (dir) "Noop" t)) ; Suppress error directory ~/.emacs.d/server is unsafe on windows.

(server-start)

;; (desktop-load-default)
;; (desktop-read)

;; ======================================================================
;; standart/general settings

(setq kill-whole-line t)

;; show column & line numbers in status bar
(setq column-number-mode t)
(setq line-number-mode t)

(setq view-read-only t)

(setq frame-title-format "Emacs - %b")

;; Control if end of file end with newline.
;; See also 'mode-require-final-newline'.
(add-hook 'text-mode-hook (lambda () (setq require-final-newline nil)))

(setq read-quoted-char-radix 16)

;; ----------------------------------------------------------------------
;; Switching, creating, selecting buffers.
(iswitchb-mode 1)
(setq iswitchb-buffer-ignore nil)
(mapc (lambda (arg) (add-to-list 'iswitchb-buffer-ignore arg))
        '("^ "
          "^\*Buffer"
          "^\*Completions\*"
          "^\*tramp"
          "^\*Dired log\*"
          "^\*Help\*"
          "^\*Quail Completions\*"
          "^\*Disabled Command\*"
          "^\*vc\*"
          ))

(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward)

(global-set-key "\C-x\C-b" 'buffer-menu)

;; ----------------------------------------------------------------------
;; Scrolling

(setq-default
 ;; The number of lines to try scrolling a window by when point moves out.
 scroll-step 1
 scroll-conservatively 100
 ;; при перемещении точка останавливается на расстоянии i строк к границе фрейма,
 scroll-margin 2
 scroll-preserve-screen-position t
 )

;; ----------------------------------------------------------------------
;; *Text*
(setq default-major-mode 'text-mode)

;; ----------------------------------------------------------------------
;; syntax highlighting
(setq font-lock-maximum-decoration t)
(global-font-lock-mode 1 t)

;; ----------------------------------------------------------------------
;; highlight selected text

;; 1/-1, when the mark is active, the region is highlighted.
(transient-mark-mode 1)
(delete-selection-mode 1)               ; 1/-1

;; Order of next item is important.
(require 'pc-select)
;; To avoid some key bindings as F6, etc. Must set before 'pc-selection-mode' invoke.
(setq pc-select-selection-keys-only t)
(pc-selection-mode 1)

(when (eq window-system 'x)
  (setq x-select-enable-clipboard t)    ; from Emacs 21.2.1 and newer
  )

;; ----------------------------------------------------------------------
;; line
(if window-system
    (progn
      (global-hl-line-mode t)
      (custom-set-faces '(hl-line ((t (:inherit highlight :background "light yellow")))))
      )
  )

;; ----------------------------------------------------------------------
;; paren, brace

(show-paren-mode 1) ; Parenthesis matching via highlighting.
;; (setq show-paren-style 'expression) ; выделять все выражение в скобках
(setq show-paren-style (quote parenthesis))

;; ======================================================================
;; Keyboard, mouse.

;; cyrillic-jcuken  for 567 is :,.
;; russian-computer for 567 is %^&
(setq default-input-method 'cyrillic-jcuken)

;; (pc-bindings-mode) ; Myself define keybinding, see

;; ----------------------------------------------------------------------
;; Completition
(partial-completion-mode t) ; For example, M-x p-c-m expands to M-x partial-completion-mode

;; ----------------------------------------------------------------------
;; Mouse

;; Scroll Bar gets dragged by mouse butn 1
(global-set-key [vertical-scroll-bar down-mouse-1] 'scroll-bar-drag)
;; Paste at point NOT at cursor
(setq mouse-yank-at-point t)
(mouse-wheel-mode 1)

;; ----------------------------------------------------------------------
;; Key Binding (Short-keys).

(global-set-key [home]    'beginning-of-line)
(global-set-key [end]     'end-of-line)
(global-set-key [C-home] 'beginning-of-buffer)
(global-set-key [C-end]  'end-of-buffer)
(global-set-key [C-delete]  'kill-word)
(global-set-key [delete]     'delete-char)
;; (global-set-key [backspace]  'backward-delete-char-untabify) ; not work properly in *info* mode

;; setting some f[1-12] keys
(global-set-key [f1]    'help)
(global-set-key [f2]    'save-buffer)
;; (global-set-key [xxx]    'ediff-buffers)
(global-set-key [f4]    'ispell-buffer)
(global-set-key [S-f6]  'rename-buffer)
(global-set-key [f8]    'kill-this-buffer)
(global-set-key [M-f4]  'save-buffers-kill-emacs)
(global-set-key [f6]    'toggle-truncate-lines)

;; *Occur*
(global-set-key [f7] 'occur)            ; Key binding as in mc

;; frames, windows manipulation, switch buffers
(global-set-key [?\C-x right] 'next-buffer)
(global-set-key [?\C-x left]  'previous-buffer)

;; I usually mistype "C-x C-f" to "C-x d" or "C-x C-d", so always use find-file,
;; because when file if directory find-file load dired, if regular file open it.
(global-set-key (kbd "C-x C-f") 'find-file)
(global-set-key (kbd "C-x C-d") 'find-file)
(global-set-key (kbd "C-x d") 'find-file)

(global-set-key (kbd "\e\eg") 'goto-line)
(global-set-key (kbd "\e\er") 'query-replace-regexp)

;; Disable C-z, it ugly.
(if window-system (global-set-key (kbd "C-z") 'nil))

;; (global-set-key [language-change] 'ignore)

;; ======================================================================
;; Coding system, charset, locale, lang.

;; Emacs 23.1 no longer need codepage-setup.
(when (<= emacs-major-version 22)
  (codepage-setup 866)
  (codepage-setup 1251)
  )

;; Comment because prefer-coding-system will be ignored.
;; (setq-default coding-system-for-read  'cp1251-dos)
;; (setq-default coding-system-for-write 'cp1251-dos)

;; (setq locale-coding-system  'cp1251-dos)
;; (set-terminal-coding-system 'cp1251)
;; (set-keyboard-coding-system 'cp1251)

(prefer-coding-system 'koi8-r-dos)
(prefer-coding-system 'utf-16-le)
(prefer-coding-system 'cp866-dos)

(modify-coding-system-alist 'file "\\.el" 'iso-2022-7bit)
(cond
 ((equal window-system 'w32)          ; also (string-equal system-type "windows-nt")
  (progn
    (set-selection-coding-system 'utf-16le-dos)
    (prefer-coding-system 'utf-8-unix)
    (prefer-coding-system 'cp1251-dos)
    ))
 ((equal window-system 'x)
  (progn
    (prefer-coding-system 'cp1251-dos)
    (prefer-coding-system 'utf-8-unix)
    (setq selection-coding-system 'ctext-with-extensions)
    (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
    (modify-coding-system-alist 'process ".*" 'utf-8-unix)
    ))
 (t
  (progn
    ;; (set-selection-coding-system   'utf-8-unix)
    (prefer-coding-system 'cp1251-dos)
    (prefer-coding-system 'utf-8-unix)
    (modify-coding-system-alist 'process ".*" 'utf-8-unix)
    ))
  )

;; XXXXXXXXXXXXXXXXXXXXXXXX

;; To open from command line file, which names has extended opcode
;; (set-file-name-coding-system 'cp1251)

;; (set-language-environment "Russian") ; XXX not used as set default coding system to koi8-r.

;; ======================================================================
;;
;; NON-STANDARD VARIABLES

;; ======================================================================
;;
;; STANDARD VARIABLES

(if (boundp 'confirm-kill-emacs)
    (setq confirm-kill-emacs 'yes-or-no-p))

;; Try to speed things up, especially in VM.
(setq gc-cons-threshold 2000000)

;; Don't beep in my headphones!
(setq ring-bell-function '(lambda () "Empty ring-bell-function." nil))
(setq visible-bell t) ; With default ring-bell-function in text terminal
                      ; revert screen if press [end] or [home]

;; Prompt before evaluating local bits of lisp.  This stops people
;; putting things at the end of files which delete all your files!
(setq enable-local-variables t
      enable-local-eval      1)

;; ======================================================================
;;
;; STANDARD LIBRARIES

(require 'jka-compr) ; Automatic decompression, hooks for tar-mode.
(if (fboundp 'auto-compression-mode)
    (auto-compression-mode 1))

;; ----------------------------------------------------------------------
;; *Recentf*

(require 'recentf)
;; Prevent TRAMP to login on remote host when loading.
;; Its take time and ask passwords!
(setq recentf-auto-cleanup 'never)
(recentf-mode t)
(setq recentf-max-saved-items 200)
(global-set-key (kbd "\e\eq")  'recentf-open-files)

;; ----------------------------------------------------------------------
;; revert
(global-set-key [f5]    'revert-buffer)
(setq revert-without-query (quote (".*")))
(setq auto-revert-interval 2)

;; ======================================================================
;; Convenient

;; ----------------------------------------------------------------------
;; Completion

(require 'icomplete) ; Interactive completion in minibuffer.
(icomplete-mode 1)

(setq completion-ignored-extensions
      '("CVS/" ".hg/" ".svn/" ".git/" ".bzr/"
        ".o" "~" ".bin" ".bak" ".obj" ".map" ".a" ".ln" ".blg" ".bbl" ".elc"
        ".lof" ".glo" ".idx" ".lot" ".fmt" ".tfm" ".class" ".fas" ".lib" ".x86f" ".sparcf"
        ".lo" ".la" ".toc" ".log" ".aux" ".cp" ".fn" ".ky" ".pg" ".tp" ".vr" ".cps"
        ".fns" ".kys" ".pgs" ".tps" ".vrs"))

;; ----------------------------------------------------------------------
;; *grep*
(setq grep-command "find . -name '*' -exec grep -nH '' {} ;"
      grep-find-command "find . '(' -name .svn -o -name CVS -o -name .hg -o -name _darcs ')' -prune -o -type f -name '*' -print0 | xargs -0 -e grep -nH "
      grep-highlight-matches nil ; do not set t because some grep do not has --color options
      grep-tree-command "find <D> <X> -type f <F> -print0 | xargs -0 -e grep <C> -nH  <R>"
      grep-use-null-device t)
(setq blink-matching-paren-on-screen t)

;; ----------------------------------------------------------------------
;; Music
(setq gnus-audio-au-player "winamp.exe"
      gnus-audio-directory "D:\\music"
      gnus-audio-wav-player "winamp.exe")

;; ----------------------------------------------------------------------
;; archive

(modify-coding-system-alist 'file "\\.\\(war\\|ear\\|sar\\|egg\\)\\'" 'no-conversion)

(add-to-list 'auto-mode-alist '("\\.\\(war\\|ear\\|sar\\|egg\\)\\'" . archive-mode))

;; ----------------------------------------------------------------------
;; browser

(cond
 ((equal window-system 'w32)
  (setq browse-url-browser-function 'browse-url-default-windows-browser))
 (t
  (setq browse-url-browser-function 'browse-url-mozilla)))

;; ======================================================================
;; TIME SETTING

;; ----------------------------------------------------------------------
;; Time

;; Also useful such format:
;; (setq display-time-format " %H:%M %d-%m-%y ")
(setq display-time-24hr-format t)
(setq display-time-default-load-average nil)
(display-time)

;; ----------------------------------------------------------------------
;; Calendar
;; (setq mark-holidays-in-calendar t)
;; (setq all-christian-calendar-holidays t)
;; (setq calendar-date-display-form (quote ((format "%04s-%02d-%02d" year (string-to-int month) (string-to-int day)))))
;; (setq calendar-time-display-form (quote (24-hours ":" minutes (if time-zone " (") time-zone (if time-zone ")"))))
(setq calendar-week-start-day 1)
(setq european-calendar-style t)

;; ======================================================================
;;
;; STANDARD HOOKS

(add-hook 'write-file-hooks 'time-stamp)

;; ======================================================================
;; *auto-fill*

(setq-default fill-column 78)

;; By default used American convention - sentence and with two spaces. Change
;; it to one space. Has affect on filling and M-a, M-e commands.
(setq sentence-end-double-space nil)

;; Turn on auto-fill mode
(add-hook 'html-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook 'turn-on-auto-fill)

;; ----------------------------------------------------------------------
;; unknown

;; (require 'desire)
;; (add-to-list 'desire-load-path
;;       (expand-file-name "~/share/emacs/desire"))
;; (add-to-list 'auto-mode-alist
;;       (cons (concat (regexp-quote desire-extension) "\\'")
;;         'emacs-lisp-mode))

;; (desire 'browse-url)
;; (desire 'mailcrypt)
;; (desire 'gnus)
;; (desire 'message)
;; (desire 'sendmail)
;; (desire 'bbdb "bbdb")
;; (desire 'pilot)
;; (desire 'bibtex)
;; (desire 'eiffel-mode)
;; (desire 'emacs-w3m)
;; (desire 'eudc)
;; (desire 'filladapt)
;;;; (desire 'hugs-mode)
;; (desire 'mpg123)
;; (desire 'php-mode)
;; (desire 'ps-print)
;; (require 'chord-mode)  ; edit guitar music.
;; (require 'discography) ; variant of BibTeX mode for discographies.

;; ======================================================================
;; unNOVICEd commands...
;;
;; The following commands are usually disabled by default. Enable them...

(put 'eval-expression  'disabled nil)
(put 'downcase-region  'disabled nil)
(put 'upcase-region    'disabled nil)
(put 'narrow-to-page   'disabled nil)
(put 'narrow-to-region 'disabled nil)

;; ======================================================================
;; TEX
(setq tex-run-command "initex")


;; ======================================================================
;; AUC TeX

;(add-hook 'LaTeX-mode-hook 'LaTeX-install-toolbar)
;; (setq TeX-parse-self t)             ; Enable parse on load.
;; (setq TeX-auto-save t)              ; Enable parse on save.
;; (setq-default TeX-master nil)       ; Query for master file. Finally, if you often use \include or \input, you should make AUCTEX aware of the multi-file document structure

;(setq TeX-PDF-mode t)
;(setq TeX-interactive-mode t)
;(setq TeX-source-specials-mode 1)

;;модифицируем меню
;;; some more menu entries in the command list:
;;; see tex-mik.el from package auctex: %v is defined in tex-mik.el
;;; other variables are defined in tex.el from auctex
;;; the meaning of some auctex-varibles:
        ;symbols defined in tex.el and tex-mik.el:
        ;%b name slave tex-file  %t name master tex-file
        ;%d dvi-file  %f ps-file
        ;%l "latex --src-specials"
        ;%n line number  %p printcommand  %q "lpq"
        ;%r (TeX-style-check TeX-print-style)
        ;%s master-file-name without extention
        ;%v yap command view line
;(eval-after-load "tex"
;  '(progn
;     (add-to-list 'TeX-command-list
;         (list "->PS landscape for pdf"
;           "dvips %d -N0 -Ppdf -G0 -T 297mm,210mm -o %f "
;           'TeX-run-command nil t))
;     (add-to-list 'TeX-command-list
;         (list "All Texify run-viewer"
;           "texify --tex-opt=--src --run-viewer --clean %s.tex"
;           'TeX-run-command nil t))))


;; ======================================================================
;;
;; Reftex activation (Reftex is included with Emacs 21.1)

;; (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
;; (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
;; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
;; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
;; (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
;; (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode

;; ======================================================================
;;
;;Настройки PreviewLatex

;(load "preview-latex.el" nil t t)

;(add-hook 'LaTeX-mode-hook #'LaTeX-preview-setup)
;(autoload 'LaTeX-preview-setup "preview")


;; ======================================================================
;;
;; Info

(require 'info)
(if (equal window-system 'w32)
    (progn
      ;; TODO Write which func to find runemacs.exe dir.
      ;; (setq Info-directory-list (list (expand-file-name "~/../bin/emacs/info")))
      ;; (add-to-list 'Info-directory-list (expand-file-name "~/../bin/MinGW/info") t) ; t - append to the end
      ))

;; ======================================================================
;; man, woman
(require 'woman)
(setq woman-use-own-frame nil)
(setq woman-fill-frame t)

;; ======================================================================
;; shell, sh, bash

;; Setup Emacs to run bash as its primary shell.
;; (setq binary-process-input t)
;; (setq shell-file-name "bash")
;; (setq shell-command-switch "-c")
;; (setenv "SHELL" shell-file-name)

(when (eq window-system 'w32)           ; may require Cygwin or MSYS
  (setq explicit-shell-file-name "bash")
  (setq explicit-bash-args '("-i"))
  (setq explicit-sh-args '("-i"))
  ;; Here is workaround: when explicit-shell-file-name is "bash" and shell-file-name is "cmdproxy.exe"
  ;; find-dired incorrect quote args (in shell-quote-argument (w32-shell-name) return "bash", but
  ;; shell-command used shell-file-name which value "cmdproxy.exe"). So I put additional space in pattern to
  ;; prevent quoting.
  (setq find-ls-option '("-exec ls -ld {}  ;" . "-ld"))
  )

;; ======================================================================
;; spell, ispall, aspell

(setq ispell-program-name "ispell")
;(setq ispell-dictionary "russianw"); default dictionary
;(setq ispell-local-dictionary "russianw"); default dictionary
;(add-hook 'text-mode-hook 'flyspell-mode)
;(setq flyspell-default-dictionary "russianw")
;(setq flyspell-delay '1)
;; (setq ispell-local-dictionary-alist
;;   '((nil             ; default (english.aff)
;;      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B") nil iso-8859-1)
;;     ("UK-xlg"                ; english large version
;;      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "UK-xlg") nil iso-8859-1)
;;     ("US-xlg"                ; american large version
;;      "[A-Za-z]" "[^A-Za-z]" "[']" nil ("-B" "-d" "US-xlg") nil iso-8859-1)
;;    )
;; )

;; ======================================================================
;; GTD, PIM, organize, todo mode.

;; ----------------------------------------------------------------------
;; org-mode

(if (>= emacs-major-version 22)
(progn
  (require 'org)
  ))

;; XXX org-todo-keywords '((sequence "TODO" "START" "|" "DONE")) для org-version 4.67c
;; XXX (setq org-todo-keywords '("TODO" "START" "DONE")) для org-version 6.05b
(if (or (featurep 'org) (featurep 'org-install))
    (progn
      (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
      (setq org-directory (expand-file-name "~/.gtd"))
      (setq org-default-notes-file (expand-file-name "~/.gtd/notes"))
      (setq org-agenda-ndays 14
            org-deadline-warning-days 7
            org-agenda-show-all-dates t
            org-agenda-skip-deadline-if-done t
            org-agenda-skip-scheduled-if-done t
            org-agenda-start-on-weekday nil
            org-reverse-note-order t
            org-hide-leading-stars t
            org-tags-column 64
            )
      (define-key global-map "\C-ca" 'org-agenda)
      (setq org-agenda-files '("~/.gtd/todo.org")) ))

;; ----------------------------------------------------------------------
;; remember-mode
(if (featurep 'remember)
    (progn
      (setq remember-annotation-functions '(org-remember-annotation))
      (setq remember-handler-functions '(org-remember-handler))
      (add-hook 'remember-mode-hook 'org-remember-apply-template)
      (define-key global-map "\C-cr" 'org-remember)
      (setq org-remember-templates
            ;; With one item emacs do not prompt choose template.
            '((?t "* TODO %?" "~/.gtd/todo.org")
              ;; (?j "* %^{topic}\n  %T\n" "~/.gtd/journal.org")
              ))
      (setq
       org-remember-store-without-prompt t
       ) ))

;; ----------------------------------------------------------------------
;; TODO, XXX, FIXME highlight.
;; Show blanks and FIXME
;; http://www.emacswiki.org/cgi-bin/wiki/EightyColumnRule

(defface my-tab-face
  '((t :background "gray"))
  "Face for showing TABs."
  :group 'basic-faces)

(defface my-todo-face
  '((t :foreground "red" :weight bold))
  "Font for showing TODO words."
  :group 'basic-faces)

(defface my-conflict-face
  '((t :background "pink" :foreground "red" :weight bold))
  "Font for showing conflicts."
  :group 'basic-faces)

(defvar my-devel-mode-list
  '(sh-mode script-mode java-mode c-mode outline-mode text-mode
            lisp-mode makefile-mode makefile-gmake-mode python-mode)
  "List of development modes." )

(add-hook 'font-lock-mode-hook (function (lambda ()
  (when (or
         (member major-mode my-devel-mode-list)
         )
    (font-lock-add-keywords nil
     '(
       ("\t+" 0 'my-tab-face t)
       ("\\<\\(FIXME:?\\|XXX:?\\|TODO:?\\)\\>" 1 'my-todo-face t)
       ("\\(=\\{7,\\}\\|<\\{7,\\}\\|>\\{7,\\}\\)" 1 'my-conflict-face t)
       ))))))

;; ======================================================================
;; communication

;; ----------------------------------------------------------------------
;; jabber
(when (featurep 'jabber)
  (setq
   jabber-history-enabled t
   jabber-use-global-history nil
   jabber-backlog-number 15
   jabber-backlog-days 30
   jabber-alert-presence-message-function (lambda (who oldstatus newstatus statustext) nil)
   )
  )

(setq my-chat-prompt "[%t] %n>\n")
(when (featurep 'jabber)
  (setq
   jabber-chat-foreign-prompt-format my-chat-prompt
   jabber-chat-local-prompt-format my-chat-prompt
   jabber-groupchat-prompt-format my-chat-prompt
   jabber-muc-private-foreign-prompt-format "[%t] %g/%n>\n"
   )
  )

;; fsm used in emacs jabber
(when (featurep 'fsm)
  (setq fsm-debug nil)                  ; Disable *fsm-debug* buffer.
  )

;; ----------------------------------------------------------------------
;; rcirc

;; Turn on logging everything to a special buffer, for debugging.
;; (setq rcirc-debug-flag t)

(add-hook 'rcirc-mode-hook (lambda () (rcirc-track-minor-mode 1)))
(setq rcirc-time-format "%H:%M ")
(defun rcirc-handler-301 (process cmd sender args)
  "/away message handler.")

;; ======================================================================
;; VCS, version control, cvs, svn.

(if (equal window-system 'w32)
    (progn
      (modify-coding-system-alist 'process "cvs" '(cp1251-dos . cp1251-dos))
      (modify-coding-system-alist 'process "svn" '(cp866-dos . cp1251-dos))
      ))

;; (setq-default vc-svn-register-switches "--encoding cp1251")
(setq-default vc-svn-register-switches nil)

(if window-system
    (progn
     (custom-set-variables
      '(vc-annotate-very-old-color "#0b5b20")
      '(vc-annotate-background "white")
      '(vc-annotate-color-map
        (quote (
                (20 .  "#EE0000")
                (40 .  "#E0800D")
                (60 .  "#D3001A")
                (80 .  "#C68027")
                (100 . "#B90034")
                (120 . "#AB8042")
                (140 . "#9E004F")
                (160 . "#91805C")
                (180 . "#840069")
                (200 . "#778077")
                (220 . "#690084")
                (240 . "#5C8091")
                (260 . "#4F009E")
                (280 . "#4280AB")
                (300 . "#3400B9")
                (320 . "#2780C6")
                (340 . "#1A00D3")
                (360 . "#0D80E0"))))
      )
     )
  )

;; ----------------------------------------------------------------------
;; psvn
(setq svn-status-verbose t)
(setq svn-status-hide-unmodified t)

;; ----------------------------------------------------------------------
;; DVC

(when (featurep 'dvc-emacs)
  (setq dvc-tips-enabled nil)
  )

;; ======================================================================
;; devel, prog, programming

(add-to-list 'auto-mode-alist '("\\.cu$" . c-mode))

(setq-default comment-style (quote indent))
(setq-default comment-column 44)
(setq-default comment-fill-column 100)

(mapc (lambda (mode)
        (add-hook mode
                  (lambda ()
                    (setq fill-column 110) )
                  ))
      '(c-mode-hook lisp-mode-hook))

(setq-default show-trailing-whitespace t)

;; ----------------------------------------------------------------------
;; Diff, patch
(setq diff-switches "-u")

;; ----------------------------------------------------------------------
;; Indent

(setq standard-indent 4)
(setq c-basic-offset 4)
(setq sh-basic-offset 2)
(setq sgml-basic-offset 4)

;; TAB (tab settings)
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)     ; t - будут вставляться \t
(setq tab-always-indent t)
(setq c-tab-always-indent t)
(let ( (line-width 400) i )
  (setq i (* (ceiling line-width 4) 4))
  (setq tab-stop-list nil)
  (while (>= i 0)
    (setq tab-stop-list (cons i tab-stop-list))
    (setq i (- i 4))))

;; ----------------------------------------------------------------------
;; Diff.
(setq ediff-diff-options "")

;; ----------------------------------------------------------------------
;; *Compile*
(setq compile-auto-highlight t
      compile-command "make ")
;; compilation window shall scroll down if not 0
(setq compilation-scroll-output 1)

;; My funny error messages.
;; XXX нужно реализовать через hook.
(require 'compile)
(add-to-list 'compilation-error-regexp-alist '("^\\( +\\[csc\\] \\|\\)\\(.*\\)(\\([0-9]*\\),\\([0-9]*\\)):" 2 3 4))
(add-to-list 'compilation-error-regexp-alist '("^ *\\(.*\\)(\\([0-9]*\\)) +:" 1 2))
(add-to-list 'compilation-error-regexp-alist '("^\"?\\([^\"]*\\)\"?,\\([0-9]*\\) .*\\[.*\\]: " 1 2)) ; KEIL compiler
;; (add-to-list 'compilation-mode-font-lock-keywords '("\\(/[Oo][Uu][Tt]:[^ 	]+\\)" . 1))
;; (add-to-list 'compilation-mode-font-lock-keywords '("[ 	]\\(/F[oe][^ 	]+\\)" . 1))

;; ----------------------------------------------------------------------
;; makefile, make

(add-to-list 'auto-mode-alist '("\\(Makefile\\|Makefile\\..+\\)\\'" . makefile-gmake-mode))

;; ----------------------------------------------------------------------
;; asm
;; (setq-default asm-comment-char 59)
(add-hook 'asm-mode-hook '(lambda () (setq comment-start "/*") (setq comment-end "*/")) t)

(add-to-list 'auto-mode-alist '("\\.\\([sS]79\\|[sS]\\)\\'" . asm-mode))

;; (add-hook 'asm-mode-hook '(lambda () (local-unset-key ":")))
;; (add-hook 'asm-mode-hook '(lambda () (local-set-key ":" ":")))

;; ----------------------------------------------------------------------
;; lisp
(setq list-command-history-max 256)

;; ----------------------------------------------------------------------
;; C, c-mode, C++, c++-mode

(setq c-echo-syntactic-information-p t)
(add-hook 'c-mode-common-hook
 (lambda ()
   ;; Automatically inserte newlines after special characters such as brace, comma, semi-colon, and colon.
   (c-toggle-auto-newline -1)
   ;; Delete all preceding whitespace by DEL.
   (c-toggle-hungry-state -1)
   ))

(defconst my-c-style
  '((c-tab-always-indent . t)
    (c-comment-only-line-offset . 4)
    (c-hanging-braces-alist
     . (
        (brace-list-open)
        (substatement-open after)
        ))
    (c-hanging-colons-alist
     . (
        (access-label after)
        (case-label after)
        (inher-intro)
        (label after)
        (member-init-intro before)
        ))
    (c-cleanup-list
     . (
        defun-close-semi
        empty-defun-braces
        scope-operator
        ))
    (c-offsets-alist
     . (
        (arglist-close . c-lineup-arglist)
        (arglist-cont-nonempty . ++)
        (arglist-intro . ++)
        (block-open . 0)
        (case-label . 0)
        (comment-intro . 0)
        (func-decl-cont . ++)
        (inexpr-class . 0)
        (inline-open . 0)
        (knr-argdecl-intro . -)
        (label . 0)
        (statement-block-intro . +)
        (statement-cont . ++)
        (substatement-open . 0)
        ))
    (c-echo-syntactic-information-p . t))
  "My C Programming Style")

(add-hook 'c-mode-common-hook
          (lambda () (c-add-style "my" my-c-style t)))
(setq c-default-style '((java-mode . "my") (c-mode . "my") (csharp-mode . "my") (c++-mode . "my") (objc-mode . "my") (other . "my")))

;; ----------------------------------------------------------------------
;; bat file, batch

(when (provide 'bat-mode)
  (progn
    (add-to-list 'auto-mode-alist '("\\.[bB][aA][tT]\\'" . bat-mode))
    (add-to-list 'auto-mode-alist '("\\.[cC][mM][dD]\\'" . bat-mode))
    ))

;; ----------------------------------------------------------------------
;; *csharp*, c-sharp

(autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
(add-to-list 'auto-mode-alist '("\\.cs$" . csharp-mode))

;; ----------------------------------------------------------------------
;; *Java*
;; Update the Emacs load-path to include the path to
;; the JDE and its require packages. This code assumes
;; that you have installed the packages in the emacs/site
;; subdirectory of your home directory.
;; (add-to-list 'load-path (expand-file-name "~/emacs/site/semantic"))
;; (add-to-list 'load-path (expand-file-name "~/emacs/site/speedbar"))
;; (add-to-list 'load-path (expand-file-name "~/emacs/site/elib-1.0"))
;; (add-to-list 'load-path (expand-file-name "~/emacs/site/eieio"))
;; (add-to-list 'load-path (expand-file-name "~/emacs/site/jde-2.3.5.1/lisp"))

;; Load CEDET
;; (load-file "~/emacs/site/common/cedet.el")
;; Enabling SEMANTIC minor modes.  See semantic/INSTALL for more ideas.
;; (semantic-load-enable-code-helpers)

;; If you want Emacs to defer loading the JDE until you open a
;; Java file, edit the following line
;; (setq defer-loading-jde nil)
;; to read:
;;
;;  (setq defer-loading-jde t)
;;

;; (if defer-loading-jde
;;     (progn
;;       (autoload 'jde-mode "jde" "JDE mode." t)
;;       (add-to-list 'auto-mode-alist '("\\.java\\'" . jde-mode))
;;       (require 'jde)))


;; Sets the basic indentation for Java source files
;; to two spaces.
;; (defun my-jde-mode-hook ()
;;   (setq c-basic-offset 2))

;; (add-hook 'jde-mode-hook 'my-jde-mode-hook)

;; (require 'jde)

;; ********************
;; ECB
;; *******************

(setq ecb-tip-of-the-day nil)
;; (add-to-list 'load-path  "~/emacs/site/ecb-2.32")
;; (require 'ecb)

;; (global-set-key (kbd "\e\eE") 'ecb-activate)

;; ----------------------------------------------------------------------
;; html

;; ----------------------------------------------------------------------
;; xml

;; ----------------------------------------------------------------------
;; psgml
(setq sgml-set-face t)			; for highlighting in sgml

;; ======================================================================
;; Printing

;; Use Notepad to print plain text files to the default Windows printer
;(setq lpr-command "notepad")
;(setq lpr-headers-switches '("/p"))    ; \ mis-use these
;(setq lpr-switches nil)                ; / two variables
;(setq printer-name nil)        ; notepad takes the default
;(setq lpr-printer-switch "/P") ;; run notepad as batch printer
;;
;;Печать в файл
;(setq printer-name "~/myprint.txt")
;(setq ps-printer-name nil)
;(setq ps-print-header nil)
;;модифицируем меню
;;; some more menu entries in the command list:
;;; see tex-mik.el from package auctex: %v is defined in tex-mik.el
;;; other variables are defined in tex.el from auctex
;;; the meaning of some auctex-varibles:
        ;symbols defined in tex.el and tex-mik.el:
        ;%b name slave tex-file  %t name master tex-file
        ;%d dvi-file  %f ps-file
        ;%l "latex --src-specials"
        ;%n line number  %p printcommand  %q "lpq"
        ;%r (TeX-style-check TeX-print-style)
        ;%s master-file-name without extention
        ;%v yap command view line
;(eval-after-load "tex"
;  '(progn
;     (add-to-list 'TeX-command-list
;         (list "->PS landscape for pdf"
;           "dvips %d -N0 -Ppdf -G0 -T 297mm,210mm -o %f "
;           'TeX-run-command nil t))
;     (add-to-list 'TeX-command-list
;         (list "All Texify run-viewer"
;           "texify --tex-opt=--src --run-viewer --clean %s.tex"
;           'TeX-run-command nil t))))

;; ----------------------------------------------------------------
;; SQL

;; (desire 'sql-mode)
(setq sql-password "")

;; ======================================================================
;;
;; Установка режима CUA - все как в Windows
;; поддержка Ctr-c,v,x,d как в windows через пакет CUA

;; версия 21.3

;(require 'cua)
;(CUA-mode t)
;;установка режимов работы курсора через CUA
;(setq CUA-mode-normal-cursor-color "black")
;(setq CUA-mode-overwrite-cursor-color "red")
;(setq CUA-mode-read-only-cursor-color "green")
;(CUA-keypad-mode 'numeric t); доп.клавиатура - цифры
;(CUA-keypad-mode 'prefix t); доп.клавиатура - префиксы регистров (М-2)

;; версия 21.3.50 и старше

;(require 'cua-base)
;(cua-mode t)
;;установка режимов работы курсора через CUA
;(setq cua-normal-cursor-color "black")
;(setq cua-overwrite-cursor-color "red")
;(setq cua-read-only-cursor-color "green")

;; ======================================================================
;; Backup

(setq
 backup-by-copying t                           ; don't clobber symlinks
 backup-directory-alist '(("." . "~/.backup")) ; don't litter my fs tree
 delete-old-versions t                         ; delete excess backup versions silently
 kept-old-versions 1                           ; store first original version
 kept-new-versions 3                           ; store last 3 version
 version-control t)                            ; use versioned backups

;; ======================================================================
;; auto save

(setq auto-save-default t)
;; If nil autosave to different than original to buffer file.
(setq auto-save-visited-file-name nil)
;; Note: if you kill unsaved file auto save file not deleted.
(setq delete-auto-save-files t)

;; ======================================================================
;; Setup user info.

(cd "~/")
(setq user-full-name "Oleksandr Gavenko")
(setq user-mail-address "gavenkoa@gmail.com")
(setenv "ORGANIZATION" (concat user-full-name " <" user-mail-address  ">"))

(message ".emacs loaded OK.")

;;
;; End loading...