| 
eval-when-compile(require 'cl)
(defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
(defvar running-on-windows (eq 'windows-nt system-type))
(defvar running-on-unix (not running-on-windows))
(defvar mule-present (featurep 'mule))
(defvar running-on-x (cond (running-xemacs 
                            (eq (console-type) 'x))
                           (t
                            (eq window-system 'x)))
  "Whether emacs is running on X display.")
(defvar emacs-flavor 
  (concat (if running-xemacs "xemacs" "gnuemacs") "."
          (if mule-present "mule" "nomule") "-"
          (int-to-string emacs-major-version) "."
          (int-to-string emacs-minor-version)))
(defvar default-mail-user-agent 'mutt
  "Default MUA to use. Can be mutt or vm.")
(defun read-mail-with-mutt ()
  "Run mutt in gnome-terminal."
  (interactive)
  (call-process "gnome-terminal" nil 0 nil "-e" "mutt"))
(setq custom-file (concat (expand-file-name "~/emacs/custom.") emacs-flavor ".el"))
(if (eq default-mail-user-agent 'vm)
    (setq vm-init-file "~/emacs/vm.el"))
(if (file-exists-p custom-file)
    (load custom-file))
(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))
  (delete-if-not 'file-directory-p my-load-path)
  (setq load-path (append my-load-path load-path)))
(require 'cc-langs)
(require 'cc-mode)
(require 'vc-hooks)
(require 'gnus)
(require 'message)
(cond ((featurep 'xemacs)
       (require 'auto-save)
       (require 'big-menubar)
       (require 'filladapt)
                     (require 'font-lock)))
(require 'psgml)
(require 'greedy-delete)
(require 'wiki)
(require 'table)
(if (and (eq default-mail-user-agent 'vm) (file-exists-p "~/elisp/vm-pcrisis.el"))
    (load "vm-pcrisis"))
(setq auto-mode-alist (cons '("\\.sql$" . sql-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.s?html$" . sgml-mode) auto-mode-alist))
(modify-syntax-entry ?_ "w" c-mode-syntax-table)
(defun my-c-mode-common-hook ()
  (turn-on-auto-fill)
  (imenu-add-menubar-index)
  )
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(cond ((not running-xemacs)
       (transient-mark-mode 1)
              (global-font-lock-mode t)
       ))
(define-key global-map [(control c) (control f)] nil)
(require 'fff)
(fff-install-map)
(load "folding" 'nomessage 'noerror)
(folding-mode-add-find-file-hook)
(folding-add-to-marks-list 'python-mode "# {{{ " "# }}}" nil t)
(cond ((featurep 'x)
       (autoload 'mwheel-install "mwheel" "Enable mouse wheel support.")
       (mwheel-install)))
(cond ((not running-on-windows)
       (load-library "mailcrypt")
       (mc-setversion "gpg")
       (setq mc-passwd-timeout 600
             mc-gpg-user-id "Eugene Morozov")
       (autoload 'mc-install-write-mode "mailcrypt" nil t)
       (autoload 'mc-install-read-mode "mailcrypt" nil t)
       (add-hook 'mail-mode-hook 'mc-install-write-mode)))
(require 'browse-kill-ring)
(define-key global-map [(control c) k] 'browse-kill-ring)
(if running-xemacs
    (setq resize-minibuffer-file "rsz-minibuf")
  (setq resize-minibuffer-file "rsz-mini"))
(autoload 'resize-minibuffer-mode resize-minibuffer-file nil t)
(resize-minibuffer-mode)
(cond (running-xemacs
                     (custom-set-variables 
        '(savehist-file (concat "~/.emacs-history." emacs-flavor)))
       (require 'savehist)
       (savehist-load)))
       
(cond ((and running-xemacs (not mule-present) (eq (console-type) 'x))
       (global-set-key [(iso-next-group)] [])
       (global-set-key [Cyrillic_a] [Á])
       (global-set-key [Cyrillic_A] [á])
       (global-set-key [Cyrillic_be] [Â])
       (global-set-key [Cyrillic_BE] [â])
       (global-set-key [Cyrillic_che] [Þ])
       (global-set-key [Cyrillic_CHE] [þ])
       (global-set-key [Cyrillic_de] [Ä])
       (global-set-key [Cyrillic_DE] [ä])
       (global-set-key [Cyrillic_dzhe] [Ö])
       (global-set-key [Cyrillic_DZHE] [ö])
       (global-set-key [Cyrillic_e] [Ü])
       (global-set-key [Cyrillic_E] [ü])
       (global-set-key [Cyrillic_ef] [Æ])
       (global-set-key [Cyrillic_EF] [æ])
       (global-set-key [Cyrillic_el] [Ì])
       (global-set-key [Cyrillic_EL] [ì])
       (global-set-key [Cyrillic_em] [Í])
       (global-set-key [Cyrillic_EM] [í])
       (global-set-key [Cyrillic_en] [Î])
       (global-set-key [Cyrillic_EN] [H])
       (global-set-key [Cyrillic_er] [Ò])
       (global-set-key [Cyrillic_ER] [ò])
       (global-set-key [Cyrillic_es] [Ó])
       (global-set-key [Cyrillic_ES] [ó])
       (global-set-key [Cyrillic_ghe] [Ç])
       (global-set-key [Cyrillic_GHE] [ç])
       (global-set-key [Cyrillic_ha] [È])
       (global-set-key [Cyrillic_HA] [è])
       (global-set-key [Cyrillic_hardsign] [ß])
       (global-set-key [Cyrillic_HARDSIGN] [ÿ])
       (global-set-key [Cyrillic_i] [É])
       (global-set-key [Cyrillic_I] [é])
       (global-set-key [Cyrillic_ie] [Å])
       (global-set-key [Cyrillic_IE] [å])
       (global-set-key [Cyrillic_io] [£])
       (global-set-key [Cyrillic_IO] [³])
       (global-set-key [Cyrillic_ka] [Ë])
       (global-set-key [Cyrillic_KA] [ë])
       (global-set-key [Cyrillic_o] [Ï])
       (global-set-key [Cyrillic_O] [ï])
       (global-set-key [Cyrillic_pe] [Ð])
       (global-set-key [Cyrillic_PE] [ð])
       (global-set-key [Cyrillic_sha] [Û])
       (global-set-key [Cyrillic_SHA] [û])
       (global-set-key [Cyrillic_shcha] [Ý])
       (global-set-key [Cyrillic_SHCHA] [ý])
       (global-set-key [Cyrillic_shorti] [Ê])
       (global-set-key [Cyrillic_SHORTI] [ê])
       (global-set-key [Cyrillic_softsign] [Ø])
       (global-set-key [Cyrillic_SOFTSIGN] [ø])
       (global-set-key [Cyrillic_te] [Ô])
       (global-set-key [Cyrillic_TE] [ô])
       (global-set-key [Cyrillic_tse] [Ã])
       (global-set-key [Cyrillic_TSE] [ã])
       (global-set-key [Cyrillic_u] [Õ])
       (global-set-key [Cyrillic_U] [õ])
       (global-set-key [Cyrillic_ve] [×])
       (global-set-key [Cyrillic_VE] [÷])
       (global-set-key [Cyrillic_ya] [Ñ])
       (global-set-key [Cyrillic_YA] [ñ])
       (global-set-key [Cyrillic_yeru] [Ù])
       (global-set-key [Cyrillic_YERU] [ù])
       (global-set-key [Cyrillic_yu] [À])
       (global-set-key [Cyrillic_YU] [à])
       (global-set-key [Cyrillic_ze] [Ú])
       (global-set-key [Cyrillic_ZE] [ú])
       (global-set-key [Cyrillic_zhe] [Ö])
       (global-set-key [Cyrillic_ZHE] [ö])
                     (modify-syntax-entry ?\× "w" (standard-syntax-table))
       (modify-syntax-entry ?\÷ "w" (standard-syntax-table))
       (modify-syntax-entry ?\£ "w" (standard-syntax-table))
       (modify-syntax-entry ?\³ "w" (standard-syntax-table))))
(setq ispell-dictionary-alist
      (append ispell-dictionary-alist
              (list
               (list
                "russian"
                "[áâ÷çäåöúéêëìíîïðòóôõæèãþûýÿùøüàñÁÂ×ÇÄÅÖÚÉÊËÌÍÎÏÐÒÓÔÕÆÈÃÞÛÝßÙØ
ÜÀÑ]"
                "[^áâ÷çäåöúéêëìíîïðòóôõæèãþûýÿùøüàñÁÂ×ÇÄÅÖÚÉÊËÌÍÎÏÐÒÓÔÕÆÈÃÞÛÝßÙ
ØÜÀÑ]"
                "[\0]"
                nil
                nil
                nil)))
      ispell-dictionary "russian")
(cond ((and running-xemacs mule-present)
       (require 'mail-utils)
       (fset 'mail-check-safe-charset '(lambda () nil))))
(cond (mule-present
              (put-charset-property 'cyrillic-iso8859-5 
                             'preferred-coding-system 'koi8-r)
              (modify-coding-system-alist 'network 6666 'koi8-r)
              (modify-coding-system-alist 'network 2628 'koi8-r)
       ))
(cond (running-xemacs
       (defun isearch-foo-command ()
         (interactive)
         (isearch-update))
       (put 'isearch-foo-command 'isearch-command t)
       (define-key isearch-mode-map [(iso-next-group)] 'isearch-foo-command)
       (define-key isearch-mode-map [(iso-prev-group)] 'isearch-foo-command)))
(cond ((and running-on-unix mule-present)
       (set-language-environment "Cyrillic-KOI8")
       (prefer-coding-system 'koi8-r)
       (if running-on-x
           (set-face-font
            'default
            '("-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-1"
              "-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-2"
              "-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-3"
              "-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-4"
              "-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-5"
              "-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-7"
              "-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-8"
              "-monotype-courier new-medium-r-*-*-17-*-*-*-*-*-iso8859-9")
            'global '(mule-fonts) 'prepend))))
(if (and running-xemacs (>= emacs-major-version 21) (>= emacs-minor-version 4))
    (let ((uc "áâ÷çäå³öúéêëìíîïðòóôõæèãþûýøùÿüàñ")
          (dc "ÁÂ×ÇÄÅ£ÖÚÉÊËÌÍÎÏÐÒÓÔÕÆÈÃÞÛÝØÙßÜÀÑ")
          (ct (standard-case-table)))
      (mapc (lambda (x y)
              (put-case-table-pair x y ct))
            uc dc)
      (set-standard-case-table ct)))
(cond (running-on-windows       
       (codepage-setup 1251)       
       (prefer-coding-system 'cp1251-dos)       
       (set-w32-system-coding-system 'cp1251-dos)       
       (set-clipboard-coding-system 'cp1251-dos)       
       (set-default-coding-systems 'cp1251-dos)       
       (setq w32-standard-fontset-spec	     
             "-*-Courier New-normal-r-*-*-*-120-*-*-c-*-fontset-courier,   
              ascii:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-1,   
              latin-iso8859-1:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-1,   
              latin-iso8859-2:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-2,   
              latin-iso8859-3:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-3,   
              latin-iso8859-4:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-4,   
              latin-iso8859-9:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-9,   
              cyrillic-iso8859-5:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-5,   
              greek-iso8859-7:-*-Courier New-normal-r-*-*-*-120-*-*-c-*-iso8859-7")       
       (setq w32-enable-italics t)       
       (create-fontset-from-fontset-spec w32-standard-fontset-spec t)       
       (setq default-frame-alist '((font . "fontset-courier")))))
(autoload 'remember "remember" nil t)
(autoload 'remember-region "remember" nil t)
(define-key global-map [(control c) (meta r)] 'remember)
(define-key global-map [(control c) (control r)] 'remember-region)
(cond ((not running-on-windows)
       (require 'bbdb)
       (bbdb-initialize 'gnus 'message 'vm 'w3)
       (add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
       (add-hook 'mail-setup-hook 'bbdb-insinuate-sendmail)
       (bbdb-insinuate-message)
       (bbdb-insinuate-w3)
       (add-hook 'message-setup-hook 'bbdb-define-all-aliases)))
(put 'narrow-to-region 'disabled nil)
(setq gd-indicator-string " G")
(setq-default filladapt-mode t)
(setq mail-sources nil)
(setq nnmail-spool-file nil)
(setq default-major-mode 'text-mode)
(setq shell-prompt-pattern "^[^#$%>\n]*[#$%>\)] *")
(standard-display-8bit 128 255)
(define-key c-mode-base-map "\C-cc" 'compile)
(define-key c-mode-base-map "\C-m" 'newline-and-indent)
(if (eq default-mail-user-agent 'vm)
    (define-key global-map [(control x) m] 'vm-mail))
(define-key global-map [(f1)] 'manual-entry)
(define-key global-map [(f2)] 'gnus)
(if (eq default-mail-user-agent 'vm)
    (define-key global-map [(f3)] 'vm))
(if (eq default-mail-user-agent 'mutt)
    (define-key global-map [(f3)] 'read-mail-with-mutt))
(define-key global-map [(f4)] 'zenirc)
(define-key global-map [(control c) v] 'view-file)
(define-key global-map [(control c) (control b)] 'buffer-menu)
(define-key global-map [(control z)] nil)
(define-key global-map [(control x) (control z)] nil)
(define-key global-map [(control x) (control c)]
  '(lambda () (interactive)
     (cond ((y-or-n-p "Quit editor? ")
            (save-buffers-kill-emacs)))))
(defun my-text-modes-common-hook ()
  (turn-on-auto-fill))
(defun small-fill-column-hook ()
  (setq fill-column 70))
(add-hook 'sgml-mode-common-hook 'my-text-modes-common-hook)
(add-hook 'text-mode-hook 'my-text-modes-common-hook)
(add-hook 'shell-mode-hook 'my-text-modes-common-hook)
(add-hook 'mail-mode-hook 'my-text-modes-common-hook)
(add-hook 'py-mode-hook 'my-text-modes-common-hook)
(add-hook 'mail-mode-hook 'small-fill-column-hook)
(add-hook 'mail-mode-hook 'font-lock-mode)
(add-hook 'shell-mode-hook 'install-shell-fonts)
(add-hook 'find-file-hook 'auto-insert)
(add-hook 'emacs-lisp-mode-hook 'imenu-add-menubar-index)
(setq zenirc-server-alist 
      '(
        ("irc.ru" 6666 nil "sad" "Eugene")
        ("irc.funet.fi" 6666 nil "sad" "Eugene")
        ))
(setq zenirc-user-full-name-default "Eugene Morozov"
      zenirc-userinfo "Oink."
      zenirc-beep-on-signal 'always)
(setq zenirc-signal-list '("^\\([^ ]\\)* PRIVMSG [^#&+]\\([^ ]\\)* :"))
(setq zenirc-send-confirmation 'message
      zenirc-timestamp t
      zenirc-timestamp-prefix "["
      zenirc-timestamp-suffix "]"
      zenirc-delete-preceding-whitespaces t)
(setq zenirc-always-show-channelname t)
(setq zenirc-whowas-on-401 t)
(setq zenirc-send-ctcp-errmsg-on-unknown t)
(setq zenirc-send-ctcp-errmsg-on-unbalanced t)
(setq zenirc-verbose-ctcp t)
(setq zenirc-fingerdata "Why do you want to know that")
(load-library "zenirc-complete")
(load-library "zenirc-history")
(load-library "zenirc-netsplit")
nick(load-library "zenirc-format")
(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 "dictionary"
  "Create a new dictionary buffer" t)
(global-set-key [(control c) ?s] 'dictionary-search)
(global-set-key [(control c) ?m] 'dictionary-match-words)
(cond (running-xemacs
       (gnuserv-start)))
 |