(setq load-path (cons "~/emacs" load-path))
(require 'cl)
(require 'tex-site)
(require 'ctypes)
(setq inhibit-startup-message t)
(setq message-log-max 512)
(setq modifier-keys-are-sticky t)
(setq require-final-newline t)
(setq display-time-day-and-date t)
(display-time)
(require 'paren)
(show-paren-mode t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq next-line-add-newlines nil)
(setq kill-whole-line t)
(setq c-hungry-delete-key t)
(setq-default indent-tabs-mode nil)
(setq c-auto-newline 1)
(setq-default truncate-lines t)
(setq-default truncate-partial-width-windows nil)
(require 'auto-show)
(auto-show-mode 1)
(setq-default auto-show-mode t)
(auto-show-make-point-visible)
(transient-mark-mode t)
(setq query-replace-highlight t)
(setq search-highlight t)
(setq comint-buffer-maximum-size 10240)
(add-hook 'comint-output-filter-functions
'comint-truncate-buffer)
(add-hook 'comint-output-filter-functions
'comint-watch-for-password-prompt)
(add-hook 'comint-output-filter-functions
'comint-strip-ctrl-m)
(setq default-major-mode 'text-mode)
(global-font-lock-mode t t)
(setq font-lock-maximum-decoration t)
(setq auto-mode-alist (cons '("\\.tex$" . latex-mode) auto-mode-alist))
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(modify-syntax-entry ?- "w") ))
(add-hook 'c-mode-common-hook
(lambda ()
(turn-on-auto-fill)
(setq fill-column 80)
(setq comment-column 60)
(modify-syntax-entry ?_ "w") (c-set-style "whitesmith") (local-set-key [(control tab)] 'tempo-forward-mark)
(local-set-key "\M-u" '(lambda () (interactive) (backward-word 1) (upcase-word 1)))
))
(add-hook 'text-mode-hook
'(lambda ()
(turn-on-auto-fill)
(auto-fill-mode 1)
))
(add-hook 'shell-mode-hook
'(lambda ()
(local-set-key [home] 'comint-bol)
(local-set-key [up] '(lambda () (interactive)
(if (comint-after-pmark-p)
(comint-previous-input 1)
(previous-line 1))))
(local-set-key [down] '(lambda () (interactive)
(if (comint-after-pmark-p)
(comint-next-input 1)
(forward-line 1))))
))
(add-hook 'gud-mode-hook
'(lambda ()
(local-set-key [home] 'comint-bol)
(local-set-key [up] '(lambda () (interactive)
(if (comint-after-pmark-p)
(comint-previous-input 1)
(previous-line 1))))
(local-set-key [down] '(lambda () (interactive)
(if (comint-after-pmark-p)
(comint-next-input 1)
(forward-line 1))))
))
(setq tex-mode-hook
'(lambda ()
(auto-fill-mode 1)
))
(setq latex-mode-hook
'(lambda ()
(auto-fill-mode 1)
))
(setq my-key-pairs
'((?! ?1) (?@ ?2) (?# ?3) (?$ ?4) (?% ?5)
(?^ ?6) (?& ?7) (?* ?8) (?( ?9) (?) ?0)
(?- ?_) (?\" ?') (?{ ?[) (?} ?]) ))
(defun my-key-swap (key-pairs)
(if (eq key-pairs nil)
(message "Keyboard Zapped!!")
(progn
(keyboard-translate (caar key-pairs) (cadar key-pairs))
(keyboard-translate (cadar key-pairs) (caar key-pairs))
(my-key-swap (cdr key-pairs))
)
))
(defun my-key-restore (key-pairs)
(if (eq key-pairs nil)
(message "Keyboard Restored!!")
(progn
(keyboard-translate (caar key-pairs) (caar key-pairs))
(keyboard-translate (cadar key-pairs) (cadar key-pairs))
(my-key-restore (cdr key-pairs))
)
))
(global-set-key [C-delete] 'kill-word)
(global-set-key [C-backspace] 'backward-kill-word)
(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 [f1] 'find-file)
(global-set-key [f3] 'manual-entry)
(global-set-key [f4] 'shell)
(global-set-key [f5] '(lambda () (interactive) (kill-buffer (current-buffer))))
(global-set-key [S-f7] 'compile)
(global-set-key [f7] 'next-error)
(global-set-key [C-f7] 'kill-compilation)
(global-set-key [f8] 'other-window)
(global-set-key [f9] 'save-buffer)
(global-set-key [f10] '(lambda () (interactive) (my-key-swap my-key-pairs)))
(global-set-key [S-f10] '(lambda () (interactive) (my-key-restore my-key-pairs)))
(global-set-key [C-f12] 'save-buffers-kill-emacs)
(global-set-key "\C-x\C-b" 'electric-buffer-list)
(global-set-key "\C-m" 'newline-and-indent)
(defun my-editing-function (first last len)
(interactive)
(if (and (boundp 'major-mode)
(member major-mode (list 'c-mode 'c++-mode 'gud-mode 'fundamental-mode))
(= len 0)
(> (point) 4)
(= first (- (point) 1)))
(cond
((and (string-equal (buffer-substring (point) (- (point) 2)) "__")
(not (string-equal (buffer-substring (point) (- (point) 3)) "___")))
(progn (delete-backward-char 2) (insert-char ?- 1) (insert-char ?> 1)))
((string-equal (buffer-substring (point) (- (point) 3)) "->_")
(progn (delete-backward-char 3) (insert-char ?_ 3)))
((and (string-equal (buffer-substring (point) (- (point) 2)) "..")
(not (string-equal (buffer-substring (point) (- (point) 3)) "...")))
(progn (delete-backward-char 2) (insert-char ?[ 1) (insert-char ?] 1) (backward-char 1)))
((and (> (point-max) (point))
(string-equal (buffer-substring (+ (point) 1) (- (point) 2)) "[.]"))
(progn (forward-char 1) (delete-backward-char 3) (insert-char ?. 1) (insert-char ?. 1) ))
)
nil))
(add-hook 'after-change-functions 'my-editing-function)
(defvar c-tempo-tags nil
"Tempo tags for C mode")
(defvar c++-tempo-tags nil
"Tempo tags for C++ mode")
(require 'tempo)
(setq tempo-interactive t)
(add-hook 'c-mode-hook '(lambda ()
(local-set-key [f11] 'tempo-complete-tag)))
(add-hook 'c-mode-hook '(lambda ()
(tempo-use-tag-list 'c-tempo-tags)
))
(add-hook 'c++-mode-hook '(lambda ()
(tempo-use-tag-list 'c-tempo-tags)
(tempo-use-tag-list 'c++-tempo-tags)
))
(tempo-define-template "c-include"
'("include <" r ".h>" > n
)
"include"
"Insert a #include <> statement"
'c-tempo-tags)
(tempo-define-template "c-ifdef"
'("ifdef " (p "ifdef-clause: " clause) > n> p n
"#else /* !(" (s clause) ") */" n> p n
"#endif /* " (s clause)" */" n>
)
"ifdef"
"Insert a #ifdef #else #endif statement"
'c-tempo-tags)
(tempo-define-template "c-ifndef"
'("ifndef " (p "ifndef-clause: " clause) > n
"#define " (s clause) n> p n
"#endif /* " (s clause)" */" n>
)
"ifndef"
"Insert a #ifndef #define #endif statement"
'c-tempo-tags)
(tempo-define-template "c-if"
'(> "if (" (p "if-clause: " clause) ")" n>
"{" > n>
> r n
"}" > n>
)
"if"
"Insert a C if statement"
'c-tempo-tags)
(tempo-define-template "c-else"
'(> "else" n>
"{" > n>
> r n
"}" > n>
)
"else"
"Insert a C else statement"
'c-tempo-tags)
(tempo-define-template "c-if-else"
'(> "if (" (p "if-clause: " clause) ")" n>
"{" > n
> r n
"}" > n
"else" > n
"{" > n>
> r n
"}" > n>
)
"ifelse"
"Insert a C if else statement"
'c-tempo-tags)
(tempo-define-template "c-while"
'(> "while (" (p "while-clause: " clause) ")" > n>
"{" > n
> r n
"}" > n>
)
"while"
"Insert a C while statement"
'c-tempo-tags)
(tempo-define-template "c-for"
'(> "for (" (p "for-clause: " clause) ")" > n>
"{" > n
> r n
"}" > n>
)
"for"
"Insert a C for statement"
'c-tempo-tags)
(tempo-define-template "c-for-i"
'(> "for (" (p "variable: " var) " = 0; " (s var)
" < "(p "upper bound: " ub)"; " (s var) "++)" > n>
"{" > n
> r n
"}" > n>
)
"fori"
"Insert a C for loop: for(x = 0; x < ..; x++)"
'c-tempo-tags)
(tempo-define-template "c-main"
'(> "int main(int argc, char *argv[])" > n>
"{" > n>
> r n
> "return 0 ;" n>
> "}" > n>
)
"main"
"Insert a C main statement"
'c-tempo-tags)
(tempo-define-template "c-if-malloc"
'(> (p "variable: " var) " = ("
(p "type: " type) " *) malloc (sizeof(" (s type)
") * " (p "nitems: " nitems) ") ;" n>
> "if (" (s var) " == NULL)" n>
> "error_exit (\"" (buffer-name) ": " r ": Failed to malloc() " (s var) " \") ;" n>
)
"ifmalloc"
"Insert a C if (malloc...) statement"
'c-tempo-tags)
(tempo-define-template "c-if-calloc"
'(> (p "variable: " var) " = ("
(p "type: " type) " *) calloc (sizeof(" (s type)
"), " (p "nitems: " nitems) ") ;" n>
> "if (" (s var) " == NULL)" n>
> "error_exit (\"" (buffer-name) ": " r ": Failed to calloc() " (s var) " \") ;" n>
)
"ifcalloc"
"Insert a C if (calloc...) statement"
'c-tempo-tags)
(tempo-define-template "c-switch"
'(> "switch (" (p "switch-condition: " clause) ")" n>
"{" > n>
"case " (p "first value: ") ":" > n> p n
"break;" > n> p n
"default:" > n> p n
"break;" > n
"}" > n>
)
"switch"
"Insert a C switch statement"
'c-tempo-tags)
(tempo-define-template "c-case"
'(n "case " (p "value: ") ":" > n> p n
"break;" > n> p
)
"case"
"Insert a C case statement"
'c-tempo-tags)
(autoload 'vm "~/emacs/vm" "Start VM on your primary inbox." t)
(autoload 'vm-visit-folder "~/emacs/vm" "Start VM on an arbitrary folder." t)
(autoload 'vm-mail "~/emacs/vm" "Send a mail message using VM." t)
(autoload 'vm-submit-bug-report "~/emacs/vm" "Send a bug report about VM." t)
(autoload 'reftex-mode "reftex" "RefTeX Minor Mode" t)
(autoload 'turn-on-reftex "reftex" "RefTeX Minor Mode" t)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-enable-partial-scans t)
(setq reftex-save-parse-info t)
(setq reftex-use-multiple-selection-buffers t)
(setq reftex-plug-into-AUCTeX t)
(type-break-mode)
(setq enable-recursive-minibuffers t)
(resize-minibuffer-mode 1)
(follow-mode t)
(split-window-horizontally)
(other-window 1)
(shell)
(other-window 1)