;; -*- emacs-lisp -*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; $Id: emacs_keys.el,v 1.7 2006-11-06 21:02:42 rscholz Exp $
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Einstellungen der Tastaturkürzel
;;
;; Die offizielle Quelle dieser Datei ist
;;   <http://www.zonix.de/projects/emacs/config>
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; F-Tasten (Applikationen)

(define-key global-map [(f7)] 'calendar)
(define-key global-map [(f8)] 'iso-accents-mode)
(define-key global-map [(f9)] 'ispell)
(define-key global-map [(f11)] 'compile)
(define-key global-map [(f12)] 'next-error)

; Tastenkombinationen für die Navigation zwischen verschiedenen Buffern

(define-key global-map [?\C-o] 'other-window)

(define-key global-map [(f1)] "\C-x1") 
(define-key global-map [(f2)] "\C-x2") 
(define-key global-map [(f3)] "\C-xo") 

; Editierfunktionen
(define-key function-key-map [C-return] [?\r])
(define-key function-key-map [S-return] [?\r])
(global-set-key [C-left] 'backward-word)
(global-set-key [C-right] 'forward-word)
(global-set-key [S-left] 'backward-word)
(global-set-key [S-right] 'forward-word)
(global-set-key [delete] 'delete-char)

; TAGS Navigation
(global-set-key [?\M-,] [?\C-u?\M-.])               ; nächstes Auftreten
(global-set-key [?\C-x?\M-.] 'tags-generate-c-file) ; TAGS für c/c++ generieren
(global-set-key [?\C-x?\M-,] 'visit-tags-table)     ; TAGS Datei wählen

;; diverses
(if window-system
    (define-key global-map [?\C-z] 'undo))          ; Undo, im Terminal suspend
(define-key global-map [?\C-6] 'goto-line)

(define-key global-map "\C-x\C-j" 'dired-jump)

(define-key global-map "\C-cr" 'comment-region)

(global-set-key "\C-xve" 'ediff-revision)

(define-key global-map [(control tab)] 'dabbrev-expand)

(global-set-key [(control backspace)] 'backward-kill-word)

(global-unset-key [(control delete)])
(define-key function-key-map [(control delete)] [?\177])

(global-unset-key [(shift delete)]) 
(define-key function-key-map [(shift delete)] [?\177])

(define-key function-key-map (kbd "<kp-enter>") (kbd "RET"))


(global-set-key [?\C-\S-l] 'goto-line)              ; Zeilenansprung
(global-set-key "\C-c\C-c" 'comment-region)

(global-unset-key [?\C-0]) (define-key global-map [?\C-0] [?\C-x ?\C-b])
(global-unset-key [?\C-2]) (define-key function-key-map [?\C-2] [?\C-@])
(global-unset-key [?\C-3]) (define-key function-key-map [?\C-3] [?\e])
(global-unset-key [?\C-4]) (define-key function-key-map [?\C-4] [?\C-q])
(global-unset-key [?\C-7]) (define-key function-key-map [?\C-7] [?\C-_])
(global-unset-key [?\C-8]) (define-key function-key-map [?\C-8] [?\C-x ?8])
(global-unset-key [?\C-9]) (define-key function-key-map [?\C-9] [?\C-x ?8 ?\"])

; Die folgenden Zeilen belegen die Pos1 und End Taste so, dass der Cursor 
; an den Zeilenanfang bzw. Ende springen. Bei gedrueckter Ctrl-Taste springt 
; er zum Anfang bzw. Ende des Buffers.

; (global-set-key [end] 'end-of-line) 
; (global-set-key [C-end] 'end-of-buffer)
; (global-set-key [home] 'beginning-of-line)
; (global-set-key [C-home] 'beginning-of-buffer)
; (global-set-key [S-delete] 'kill-region)
; (global-set-key [S-insert] 'yank)
; (global-set-key [C-insert] 'kill-ring-save)))

; Einige Einstellungen für engl. Tastaturen. Wenn man die Windows-Tasten als 
; Super_L und Super_R definiert, kann man mit ihnen die dt. Umlaute bekommen
(global-set-key [?\s-a] [?\344]) (global-set-key [?\s-A] [?\304])
(global-set-key [?\s-o] [?\366]) (global-set-key [?\s-O] [?\326])
(global-set-key [?\s-u] [?\374]) (global-set-key [?\s-U] [?\334])
(global-set-key [?\s-s] [?\337])

; Korrekturen von original Tastenkombinationen durch verbesserte Funktionen 
; und einige Dinge die sonst noch so fehlen
(define-key global-map "\C-h\C-n" 'site-lisp-news)  ; Lokale Neuheiten
(global-set-key "\C-xve" 'ediff-revision)
(global-set-key "\C-xf" 'ff-find-other-file)
(define-key esc-map "!" 'cabo:shell-command)
(define-key esc-map "|" 'cabo:shell-command-on-region)

; kleine Erweiterung, gleich mit Prefix. Output wird direkt in den Buffer
; eingestzt, bei shell-command-on-region-replace die markierte Region ersetzt
(global-set-key [?\C-!] 'dischi:shell-command-insert) 
(global-set-key [?\C-|] 'dischi:shell-command-on-region-replace) 

; Minibuffer keys (definitions later in this file)
(define-key minibuffer-local-completion-map "\C-v" 'scroll-completions-up)
(define-key minibuffer-local-completion-map "\M-v" 'scroll-completions-down)
(define-key minibuffer-local-must-match-map "\C-v" 'scroll-completions-up)
(define-key minibuffer-local-must-match-map "\M-v" 'scroll-completions-down)
(define-key minibuffer-local-map "\C-c\C-f" 'ins-buffer-file-name)
(define-key minibuffer-local-ns-map "\C-c\C-f" 'ins-buffer-file-name)
(define-key minibuffer-local-must-match-map "\C-c\C-f" 'ins-buffer-file-name)
(define-key minibuffer-local-completion-map "\C-c\C-f" 'ins-buffer-file-name)

; Einstellungen fuer Sun Tastaturen
(define-key function-key-map [f14] [?\C-/])
(define-key function-key-map [f16] [?\M-w])
(define-key function-key-map [f18] [?\C-y])
(define-key function-key-map [f20] [?\C-w])
(define-key function-key-map [f29] [prior])
(define-key function-key-map [f35] [next])

; Emacs 21
(when (>= emacs-major-version 21) 
  (global-set-key (kbd "<end>") 'end-of-buffer) 
  (global-set-key (kbd "<home>") 'beginning-of-buffer))