~ forcotton /.emacs

for emacs 22/23
(setq inhibit-startup-screen t)
(if window-system
    (progn
      (set-default-font "DejaVu Sans Mono-13")
      (add-to-list 'default-frame-alist '(font . "DejaVu Sans Mono-13"))
      (set-fontset-font (frame-parameter nil 'font) 'han 
			'("Microsoft YaHei" . "unicode-bmp"))))

;(setq semantic-idle-scheduler-idle-time 432000) ;workaround for ecb
(setq default-indicate-empty-lines 't)
(setq visible-bell 't)
(menu-bar-mode -1)
(tool-bar-mode -1)
(mouse-wheel-mode 1)
(blink-cursor-mode 1)
(transient-mark-mode nil)
(set-scroll-bar-mode nil)
(setq require-final-newline 't)
(global-font-lock-mode 1 't)
(setq font-lock-maximum-decoration 't)
(show-paren-mode 't)
(ansi-color-for-comint-mode-on)
(setq compilation-window-height 16)
(temp-buffer-resize-mode 1) ; make window smaller for temporary buffers
(setq temp-buffer-max-height 
      (lambda (buffer) 
	(min 20 (/ (- (frame-height) 2) 2))))
(fset 'yes-or-no-p 'y-or-n-p) ; make y or n suffice for a yes or no question

(ido-mode 1)
(setq ido-ignore-buffers
      '("\\` " "^\\*ESS\\*" "^\\*Messages\\*" "^\\*Help\\*" "^\\*Buffer"
	      "^\\*.*Completions\\*$" "^\\*Ediff" "^\\*tramp" "^\\*cvs-"
	      "_region_" " output\\*$" "^TAGS$" "^\*Ido")
      ido-ignore-directories
      '("\\`auto/" "\\.prv/" "\\`CVS/" "\\`\\.\\./" "\\`\\./")
      ido-ignore-files
      '("\\`auto/" "\\.prv/" "_region_" "\\`CVS/" "\\`#" "\\`.#" "\\`\\.\\./" "\\`\\./"))
(define-key ido-file-dir-completion-map
  [remap set-mark-command]  'ido-restrict-to-matches)

(if (fboundp 'ibuffer)
    (global-set-key (kbd "C-x C-b") 'ibuffer))

;; show more info in taskbar/icon than just "Emacs"
;;(setq-default frame-title-format (list "%F %b"))
(setq-default frame-title-format (list "Emacs"))

(setq tramp-default-method "ssh")
(setq-default ispell-program-name "aspell")

(defun toggle-variable (var)
  "toggles boolean variable"
  (interactive "vToggle variable: ")
  (set var (not (symbol-value var)))
  (message "%s set to %s" var (symbol-value var))
  )

(global-set-key (kbd "C-`") 'set-mark-command)
(global-set-key (kbd "C-;") 'set-mark-command)
(global-set-key [f1] 'ispell-word)
(global-set-key [(shift f1)] 'ispell-region)
(global-set-key [(ctrl f1)] 'ispell)
(global-set-key [f2] 'menu-bar-mode)
(global-set-key [(shift f2)] 'speedbar)
(global-set-key [(ctrl f2)] 'tool-bar-mode)
(global-set-key [(shift ctrl f2)] 'scroll-bar-mode)
;; F3 and F4 for macros
(global-set-key [f5] 'grep)
(global-set-key [(shift f5)] 'rgrep)
(global-set-key [(ctrl f5)] 'occur)
(global-set-key [(shift ctrl f5)] 'multi-occur-in-matching-buffers)
(global-set-key [f6] 'gud-up)
(global-set-key [(shift f6)] 'gud-down)
(global-set-key [f7] 'gud-step)
(global-set-key [(shift f7)] 'gud-stepi)
(global-set-key [f8] 'gud-next)
(global-set-key [(shift f8)] 'gud-finish)
(global-set-key [(ctrl f8)] 'gud-until)
(global-set-key [f9] 'humble-recompile)
(global-set-key [(shift f9)] 'compile)
(global-set-key [f10] 'humble-gud)

(global-set-key (kbd "C-=") 'abbrev-mode)
(global-set-key (kbd "C-x t a") 'abbrev-mode)
(global-set-key (kbd "C-x t c") 'highlight-changes-mode)
(global-set-key (kbd "C-x t v") 'view-mode)
(global-set-key (kbd "C-x t f") 'auto-fill-mode)
(global-set-key (kbd "C-x t h") 'hs-minor-mode)

(defun toggle-show-trailing-whitespace ()
   "Toggle show-trailing-whitespace"
   (interactive)
   (toggle-variable 'show-trailing-whitespace))
(global-set-key (kbd "C-x t s") 'toggle-show-trailing-whitespace)
(global-set-key (kbd "C-x t l") 'flyspell-mode)
(global-set-key (kbd "C-x t k") 'flyspell-prog-mode)
(global-set-key (kbd "C-x t o") 'outline-minor-mode)

(define-key isearch-mode-map (kbd "C-o")
  (lambda ()
    (interactive)
    (let ((case-fold-search isearch-case-fold-search))
      (occur (if isearch-regexp isearch-string
               (regexp-quote isearch-string))))))
(when (fboundp 'windmove-default-keybindings)
  (windmove-default-keybindings))  ; shift+Arrow moves to other window

(setq load-path (append load-path (list "~/.emacs.d")))
(setq abbrev-file-name "~/.emacs.d/abbrev-def.el")
(load "tempo-def" t)

(setq auto-mode-alist
      (append 
       '(("\\.octave$" . octave-mode)	;octave script
	 ("\\.m$" . matlab-mode)	;matlab file
;;	 ("\\.java$" . java-mode)
	 )
       auto-mode-alist))

;; Set up matlab-mode to load on .m files
(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)
(setq matlab-indent-function t)	; if you want function bodies indented
(setq matlab-verify-on-save-flag nil)	; turn off auto-verify on save
(setq matlab-shell-command-switches '("-nojvm"))

(defun humble-recompile () 
  "recompile if possible"
  (interactive) 
  (if (fboundp 'recompile)
      (recompile)
    (call-interactively 'compile)))

(setq preferred-debugger-alist 
      '((c-mode . gdb) 
	(c++-mode . gdb)
	(cperl-mode . perldb)
	(jde-mode . jdb)
	))
(defun humble-gud ()
  "gdb if not already running, otherwise bring to front"
  (interactive)
  (require 'gud)
  (if (and (boundp 'gud-comint-buffer)	;find running gdb process
	   gud-comint-buffer
	   (buffer-name gud-comint-buffer)
	   (get-buffer-process gud-comint-buffer))
      (if (fboundp 'gdb-restore-windows)
	   (gdb-restore-windows)
	(pop-to-buffer gud-comint-buffer))
    (call-interactively 
     (or (cdr (assq major-mode preferred-debugger-alist))
	 'gdb))))

(add-hook 'calendar-mode-hook  
	  (lambda ()
	    (define-key calendar-mode-map "," ;for research RCV1
	      (lambda () "goto base date" (interactive)
		(calendar-goto-date '(08 19 1996))))
	  ))

(defun my-c-mode-common-hook ()
  (define-key c-mode-base-map "\C-m" 'newline-and-indent)
  (define-key c-mode-base-map (kbd "C-x t d") 'doxymacs-mode)
  (define-key c-mode-base-map (kbd "C-x t w") 'cwarn-mode)
  (setq c-electric-pound-behavior '(alignleft)) ;make a #define left-aligned 
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(add-hook 'text-mode-hook 'auto-fill-mode)


;; cperl-mode is preferred to perl-mode                                        
(defalias 'perl-mode 'cperl-mode)
(add-hook 'cperl-mode-hook
	  (lambda ()
	    (define-key cperl-mode-map (kbd "C-h f") 'cperl-perldoc)
	    (define-key cperl-mode-map "\C-m" 'newline-and-indent)
	    (setq cperl-invalid-face nil)
	    (setq cperl-electric-parens nil)
	    (setq cperl-electric-keywords nil)
	    (setq cperl-indent-level 4)
	    (define-key cperl-mode-map (kbd "C-(") 
	      (lambda () "toggle electric parens"
		(interactive)
		(toggle-variable 'cperl-electric-parens)))
	    (define-key cperl-mode-map (kbd "C-)") 
	      (lambda () "toggle electric keywords"
		(interactive)
		(toggle-variable 'cperl-electric-keywords)))
	    ))

(add-hook 'gdb-mode-hook 
	  (lambda ()
	    (setq gdb-many-windows 't)
	    (define-key gud-mode-map [f9] 'gdb-many-windows)
	    ;;(setq gdb-use-separate-io-buffer 't)
	    ;;(tool-bar-mode 't)
	    ))

(add-hook 'LaTeX-mode-hook
	  (lambda ()
	    (define-key LaTeX-mode-map [f9] 'TeX-command-master)
	    (define-key LaTeX-mode-map (kbd "C-x `") 'next-error)
	    (define-key LaTeX-mode-map [(ctrl f1)] 'TeX-ispell-document)
	    (turn-on-reftex)
	    (setq reftex-plug-into-AUCTeX t)
	    (setq TeX-auto-save t)
	    (setq TeX-parse-self t)))

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(bold ((t (:bold t :foreground "SteelBlue1"))))
 '(bold-italic ((t (:bold t :italic t :foreground "DarkKhaki"))))
 '(cperl-array-face ((((class color) (background dark)) (:foreground "#CCCC30" :weight bold))))
 '(cperl-hash-face ((((class color) (background dark)) (:foreground "#CC2020" :weight bold))))
 '(ebrowse-root-class ((((min-colors 88)) (:foreground "lightblue3" :weight bold))))
 '(fringe ((((class color) (background dark)) (:foreground "steelblue1"))))
 '(header-line ((((class color grayscale) (background dark)) (:inherit mode-line :background "navy" :foreground "grey90" :box nil))))
 '(info-node ((t (:italic t :foreground "salmon"))))
 '(info-xref ((t (:foreground "DarkSalmon"))))
 '(italic ((t (:italic t :foreground "orange1"))))
 '(variable-pitch ((t (:family "Sans")))))