;; .emacs pro EMACS 21.3 POD WINDOWS 2000 a Emacs pod Ccygwin
;; ************************************************************ spoleèné nastavení

;; Make the sequence "C-x l" execute the `goto-line' command (before C-x l did count lines in the text mode)
(global-set-key "\C-xl" 'goto-line)
(global-font-lock-mode)    ; mám rád syntax heighlighting
(transient-mark-mode t)        ;zapni podsvícení vybraného "regionu"
(setq display-time-format "%H:%M %d/%m")
(display-time-mode t)
(show-paren-mode 1)     ;zvýrazni odpovídající si závorky
(recentf-mode t)        ; zapni pamatování poslednì otevø. souborù
(require 'iswitchb)     ; faster switching of buffers
(iswitchb-mode)         
(icomplete-mode t)      ;incremental minibufer completion (like iswitchb)

;; Make (left) shift-tab to insert tab (useful in C mode, equals to C-q tab)

(add-hook 'c-mode-common-hook ; Common across all languages. 
'(lambda () 
   (progn 
     (global-set-key [S-iso-lefttab] [?\C-q tab]) ; Shift-Tab inserts TAB
     (c-set-offset 'substatement-open 0) ; no indentation for '{' after if/for/...
   )))

;; If makefile doesn't exist compile with g++ -Wall -o <current file name> <current file name>
(add-hook 'c++-mode-hook
          (lambda ()
            (unless (or (file-exists-p "makefile")
                        (file-exists-p "Makefile"))
              (set (make-local-variable 'compile-command)
                   (concat "g++ -Wall -o "
                           (file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
                           " "
                           (file-name-nondirectory (buffer-file-name)))))))

;Likvidace bufferu otevreneho v 2. okne i s oknem (misto C-x o, C-x k RET, C-x 0)
(defun kill-other-buffer-and-window ()
  "Kill the other buffer and delete its window.
   Based on (kill-buffer-and-window)(C-x 4 0)."
  (interactive)  
  (progn 
    (other-window '1) ;jump to other window
    (if (and (not (one-window-p t))
         (y-or-n-p (format "Kill buffer `%s'? " (buffer-name))))
        (let ((buffer (current-buffer)))
          (delete-window (selected-window))
          (kill-buffer buffer))
        (error "Aborted || One window only"))))
(define-key ctl-x-4-map "1" 'kill-other-buffer-and-window); prirad zkratku C-x 4 1

;; SPEEDBAR - make 'a' to run 'speedbar-toggle-show-all-files'
;; Type "C-h v  speedbar-key-map" to see the key map.
(add-hook 'speedbar-mode-hook
'(lambda () (define-key speedbar-key-map "a" 'speedbar-toggle-show-all-files)))

;; Enable some commands
(put 'narrow-to-region 'disabled nil)
(put 'upcase-region 'disabled nil)      ; C-x C-u     
(put 'downcase-region 'disabled nil)    ; C-x C-l 

;;**************************************************************************
;; ROZDEL NA
;; 1.WINDOWS EMACS (if; nastaveno dle hodnot var. mého win emacsu)
;; 2.CYGWIN EMACS (else)
(if (and (string-match "21.3.1" emacs-version)
(string-match "i386-msvc-nt5.0.2195" system-configuration))
(progn ;WINDOWS EMACS INIT ------------------------------------------- Windows
    ;; Set copy and paste keys for win emacs
    (global-set-key [f5] [copy])
    (global-set-key [f6] [paste])
    (global-set-key [f12] 'view-mode)   ; read-only
    (global-set-key [\M-delete] 'backward-kill-word); normally M-DEL (!= M-delete)
    (put 'narrow-to-region 'disabled nil)    
    (global-set-key [deletechar] 'backward-delete-char-untabify)    ; norm. backspace
    ;; Èestina pro Emacs 21.3 .................................... CZ ....
    (codepage-setup '1250)                  ; nezbytné k zpøístupnìní cp1250
    (set-keyboard-coding-system 'cp1250)    ; !!! bez tohoto Emacs nepøeète klávesy š,ž
    (set-selection-coding-system 'cp1250)   ; pro kopírování do jiných aplikací
    (setq-default default-input-method "Czech-qwerty")
    ;; Mùj Emacs si sám nastavuje na èeštinu, takže toto nepotøebuji:
    ; (set-language-environment "Czech")        
    ;(set-input-method "czech-qwerty")
    ; (set-default-font "-*-Courier-normal-r-*-*-13-97-96-96-c-*-iso8859-2")
    ; (prefer-coding-system 'cp1250)
    ; (define-coding-system-alias 'windows-1250 'cp1250)
    (setq custom-file "C:\\moje\\_unix\\.emacs-win-mine")
    (load custom-file)
    (if (string= (frame-parameter nil 'background-mode)  'light) ;if not 'dark
        (set-background-color "AntiqueWhite1")  ;if true
      nil                                       ;else
      )
    ; Use the gnuserv (jen 1 kopie Emacsu najednou)
    (load-file "C:\\Program Files\\gnuserv\\gnuserv.el")
    (require 'gnuserv)
    (setq exec-path (cons "C:/Program Files//emacs/my_gnuserv" exec-path))
    (setenv "PATH" (concat "C:\\Program Files\\emacs\\my_gnuserv;" (getenv "PATH")))
    (gnuserv-start)     ;gnuserv.exe musí být ve windows var PATH
    (setq gnuserv-frame (selected-frame)) ;neotvírej v novém oknì); list of inic. 4 windows
(progn ;CYGWIN EMACS INIT ------------------------------------------- Cygwin
    (tool-bar-mode nil)     ; nechci tool-bar
    (setq custom-file "/cygdrive/c/moje/_unix/.emacs-cygwin-mine")
    (load custom-file)
    'nedelej-nic-dalsiho    ;nicnedìlající formule
); list of inic. 4 cygwin
);if-else win/cygwin 
;;**************************************************************************