; -*- Lisp -*-


;; Set path for searching
;;(add-to-list 'load-path "/usr/local/share/emacs/site-lisp")
;;(add-to-list 'load-path "/usr/local/share/emacs/site-lisp")
;;(add-to-list 'load-path "/home/phil/.emacs-lisp")
;;(add-to-list 'load-path "/home/phil/.emacs-lisp/povray")
;;(add-to-list 'load-path "/usr/install/auctex-11.14/")
;;(add-to-list 'load-path "/home/phil/.emacs-lisp/erc")
;;(add-to-list 'load-path "/home/phil/.emacs-lisp/chess-2.0b3")


;;(require 'color-theme)
;;(color-theme-deep-blue)
;;(color-theme-arjen)
;;(color-theme-dark-laptop)

;;(require 'python-mode)



;;;;;; This is only to prevent Alt-gr warning
;;;(defun nothing ()
;;;  (interactive)
;;;  nil)
;;;(global-set-key (read-kbd-macro "<key-3>") 'nothing)


;; replace yes or no with y or n
(fset 'yes-or-no-p 'y-or-n-p) 

(tool-bar-mode -1)
(menu-bar-mode -1)
(mouse-wheel-mode)

;;(defsetf frame-parameter (frame parameter) (new-value)
;;  `(progn
;;     (modify-frame-parameters ,frame 
;;			      (list (cons ,parameter ,new-value)))
;;     ,new-value))
;;
;;(setf (frame-parameter nil 'scroll-bar-width) 10)


(column-number-mode 't)
(show-paren-mode 't)
(auto-compression-mode 1)

; time in mode line
(setq display-time-format "%a %d %b %H:%M")
(display-time-mode 1)


;; disable local variables
;(setq enable-local-variables nil)



;; highlighting

(require 'font-lock)

(global-font-lock-mode 't)
(setq font-lock-maximum-decoration 't)

(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(browse-url-browser-function (quote browse-url-netscape))
 '(browse-url-netscape-program "links2")
 '(browse-url-netscape-startup-arguments (quote ("-g" "-mode" "800x600")))
 '(bubblet-high-score 422 t)
 '(bubblet-high-stats (quote (66 178)) t)
 '(bubblet-num-games 2 t)
 '(bubblet-total-score 552 t)
 '(bubblet-total-stats (quote (84 231)) t)
 '(canlock-password "f4e68ddbd0e59efe52c041525f3c7297e329f367")
 '(case-fold-search t)
 '(compilation-read-command nil)
 '(current-language-environment "Latin-1")
 '(default-input-method "latin-1-prefix")
 '(dired-listing-switches "-la -I.[a-z,A-Z,0-9]*" t)
 '(erc-notice-highlight-type (quote all))
 '(erc-server "irc.freenode.net")
 '(global-font-lock-mode t nil (font-lock))
 '(inhibit-local-menu-bar-menus nil)
 '(ispell-program-name "aspell")
 '(mail-default-headers "From: 
Bcc: hocwp@free.fr
")
 '(mail-host-address "free.fr")
 '(save-place t)
 '(scroll-bar-mode (quote right))
 '(show-paren-mode t nil (paren))
 '(speedbar-mode-specific-contents-flag t)
 '(spell-command "ispell")
 '(uniquify-buffer-name-style (quote post-forward) nil (uniquify))
 '(user-login-name "hocwp" t)
 '(visible-bell t))


(setq user-mail-address "hocwp@free.fr")

;; Pour les accents
(set-terminal-coding-system 'latin-1)
(set-keyboard-coding-system 'latin-1)
(set-language-environment 'latin-1)
(standard-display-european 1)
(set-input-mode nil nil 1)



;; C-x C-b : buffer list in same window
(global-set-key (read-kbd-macro "C-x C-b") 'electric-buffer-list)

(global-set-key (read-kbd-macro "C-x C-M-b") 'buffer-menu)

(global-set-key (read-kbd-macro "C-x C-k") 'kill-buffer)

(global-set-key (read-kbd-macro "C-x C-<up>") 'enlarge-window)
(global-set-key (read-kbd-macro "C-x C-<down>") 'shrink-window)

(global-set-key (read-kbd-macro "C-x C-<right>") 'forward-sexp)
(global-set-key (read-kbd-macro "C-x C-<left>") 'backward-sexp)


(defun my-open-todo ()
  "Open the TODO file"
  (interactive)
  (find-file "~phil/.TODO"))
(global-set-key (read-kbd-macro "<f12>") 'my-open-todo)

;; C-x b : complete buffer list in same window
;;(global-set-key (read-kbd-macro "C-x b") 'bs-show)


;; F2 : Recent files
(global-set-key (read-kbd-macro "<f2>") 'recentf-open-files)


;; F5 : toggle Shell
(defun my-shell ()
  "Start a shell in the directory of current buffer"
  (interactive)
  (let ((my-file-dir (expand-file-name
		      (if (eq buffer-file-name nil)
			  default-directory
			(file-name-directory buffer-file-name)))))
    (switch-to-buffer my-file-dir)
    (shell my-file-dir)
    (ansi-color-for-comint-mode-on)))

(defun my-update-shell ()
  "Update shell name with current directory"
  (interactive)
  (if (string= mode-name "Shell")
      (rename-buffer (expand-file-name
		      (if (eq buffer-file-name nil)
			  default-directory
			(file-name-directory buffer-file-name))) t)
    (message "Sorry, buffer is not in Shell mode.")))

(defun my-open-shell ()
  "Open a shell in a given directory"
  (interactive)
  (let ((my-dir (expand-file-name (read-file-name "Open shell in: "
				  nil default-directory nil))))
    (switch-to-buffer my-dir)
    (cd my-dir)
    (shell my-dir)
    (ansi-color-for-comint-mode-on)))
  


(defun my-send-invisible ()
  "Send invisible text to Shell"
  (interactive)
  (if (string= mode-name "Shell")
      (send-invisible nil)
    (message "Sorry, buffer is not in Shell mode.")))


(global-set-key (read-kbd-macro "<f5>") 'my-shell)
(global-set-key (read-kbd-macro "<f7>") 'my-send-invisible)
(global-set-key (read-kbd-macro "C-<f7>") 'my-open-shell)
(global-set-key (read-kbd-macro "C-<f5>") 'my-update-shell)


;;;(defun my-term-change-mode ()
;;;  "Change term mode : char-mode <-> line-mode"
;;;  (interactive)
;;;  (if (string= mode-name "Term")
;;;    (if (term-in-char-mode)
;;;	(term-line-mode)
;;;      (term-char-mode))
;;;    (message "Sorry, buffer is not in Term mode.")))
;;;
;;;
;;;(defun my-term ()
;;;  "Start a shell in the directory of current buffer"
;;;  (interactive)
;;;  (let ((my-file-dir (expand-file-name
;;;		      (if (eq buffer-file-name nil)
;;;			  default-directory
;;;			(file-name-directory buffer-file-name))))
;;;	(buffer-exist nil))
;;;    (dolist (b (buffer-list))
;;;      (when (string= my-file-dir (buffer-name b))
;;;	(setq buffer-exist t)))
;;;    (cond (buffer-exist
;;;	   (if (string= (buffer-name (current-buffer)) my-file-dir)
;;;	       (my-term-change-mode)
;;;	     (switch-to-buffer my-file-dir)))
;;;	  (t (ansi-term "/bin/bash")
;;;	     (term-line-mode)
;;;	     (rename-buffer my-file-dir t)))))
;;;
;;;(defun my-update-shell ()
;;;  "Update shell name with current directory"
;;;  (interactive)
;;;  (if (string= mode-name "Term")
;;;      (rename-buffer (expand-file-name
;;;		      (if (eq buffer-file-name nil)
;;;			  default-directory
;;;			(file-name-directory buffer-file-name))) t)
;;;    (message "Sorry, buffer is not in Term mode.")))
;;;
;;;
;;;(global-set-key (read-kbd-macro "<f5>") 'my-term)
;;;(global-set-key (read-kbd-macro "<f7>") 'my-term-change-mode)
;;;(global-set-key (read-kbd-macro "C-<f5>") 'my-update-shell)



;; C-M-F5 : Xterm
(defun my-xterm ()
  "Start an Xterm"
  (interactive)
  (shell-command "xterm"))

(global-set-key (read-kbd-macro "C-M-<f5>") 'my-xterm)


;; F8 : Execute ./run
(defun my-exec-run ()
  "Execute the program ./run"
  (interactive)
  (shell-command "./run"))

(global-set-key (read-kbd-macro "<f8>") 'my-exec-run)

(global-set-key (read-kbd-macro "<C-tab>") 'other-window)
(global-set-key (read-kbd-macro "C-&") 'other-frame)

(global-set-key (read-kbd-macro "C-x &") 'delete-other-windows)
(global-set-key (read-kbd-macro "C-x \é") 'split-window-vertically)
(global-set-key (read-kbd-macro "C-x \"") 'split-window-horizontally)
(global-set-key (read-kbd-macro "C-x \à") 'delete-window)



(global-set-key (read-kbd-macro "<f4>") 'gnus)
;;(global-set-key (read-kbd-macro "<f3>") 'bbdb-complete-name)

(global-set-key (read-kbd-macro "C-<f6>") 'erc-select)

(global-set-key (read-kbd-macro "<f6>") 'ispell-region)
(global-set-key (read-kbd-macro "M-<f6>") 'ispell-buffer)
(global-set-key (read-kbd-macro "C-M-<f6>") 'ispell-change-dictionary)

(global-set-key (read-kbd-macro "C-M-g") 'goto-line)


;; C-x t : delete horizontal space
(global-set-key (read-kbd-macro "C-x t") 'delete-horizontal-space)

;; C-x C-! : next error in compilation
(global-set-key (read-kbd-macro "C-x C-!") 'next-error)

;; C-h u : find entry in manual pages
(global-set-key (read-kbd-macro "C-h u") 'manual-entry)

;; C-c C-v : indent comment (in c mode)
(global-set-key (read-kbd-macro "C-c C-v") 'comment-indent)

;; C-M-right : next parent
(global-set-key (read-kbd-macro "C-M-<right>") 'forward-sexp)
;; C-M-left : previous parent
(global-set-key (read-kbd-macro "C-M-<left>") 'backward-sexp)

;;;; BBDB Bookmark pour gnus
;;(require 'bbdb)
;;(bbdb-initialize 'gnus)
;;(add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)


;; W3 : web broswer
;;(require 'w3)

;; AucTex for Latex in emacs
;;(require 'tex-site)

;;(global-set-key (read-kbd-macro "C-c c") 'LaTeX-close-environment)

;; ERC => IRC client
;;(require 'erc)

;;(setq erc-server "irc.freenode.net" 
;;      erc-port 6667 
;;      erc-nick "hocwp"
;;      erc-user-name "Unknown"
;;      erc-user-full-name "hocwp"
;;      erc-email-userid "hocwp"
;;      erc-highlight-strings (quote ("hocwp")))

;;(setq dismal-directory "/home/test/dismal-1.4")
;;(load "dismal")


;; load SES : Simple Emacs Spreadsheet
;;(autoload 'ses-mode "ses.el" "Spreadsheet mode" t)
;;(add-to-list 'auto-mode-alist '("\\.ses$" . ses-mode))


;; Add a function to create TAGS on .c and .h files
(defun my-create-tags ()
  "create TAGS on .c and .h files"
  (interactive)
  (shell-command "etags *.c *.h *.lisp"))



(defun my-call-occur ()
  (interactive)
  (occur (current-word)))

(global-set-key (read-kbd-macro "<f1>") 'my-call-occur)

;; client server for emacs
;;(require 'gnuserv-compat)
;;(require 'gnuserv)

;(gnuserv-start)


(blink-cursor-mode -1)

(recentf-mode 1)

(setq recentf-arrange-by-rules-min-items 0
      recentf-arrange-by-rule-others nil
      recentf-arrange-rules 
      '(("Elisp files (%d)" ".\\.el$"
	 "^\\.?emacs-") 
	("Java files (%d)" ".\\.java$")
	("C/C++ files (%d)" ".\\.c\\(pp\\)?$")
	("C/C++ include files (%d)" ".\\.h$")
	("Configuration files (%d)" "rc$\\|/\\.")
	("Ada files (%d)" ".\\.ad[sb]$")
	("TeX/LaTeX files (%d)" ".\\.\\(tex\\|bib\\)$")
	("Scripts (%d)" ".\\.\\(sh\\|pl\\)$")
	("Documentation (%d)" "/doc/")
	)
      recentf-max-saved-items 50
      recentf-max-menu-items  30
      recentf-menu-path nil
      recentf-exclude '(".emacs-customize$"
			".newsrc"
			".etags$"
			".emacs.bmk$"
			".bbdb$"
			".log$"
			"^/tmp/")
      recentf-menu-filter 'recentf-arrange-by-rule
      recentf-menu-title "Recentf"
      )


;;(require 'chess)
;;(require 'chess-puzzle)

;;(put 'erase-buffer 'disabled nil)



(defun my-show-html ()
  "Render the Gnus Article through lynx"
  (interactive)
  (gnus-summary-pipe-message "lynx -stdin -dump"))

(add-hook 'gnus-summary-mode-hook
          (function
           (lambda ()
             (local-set-key "v" 'my-show-html))))


; ZenIRC
;;(setq load-path (cons 
;;		 (expand-file-name "/usr/install/zenirc-2.112/lib/emacs/site-lisp") 
;;		 load-path))
;;(autoload 'zenirc "/home/phil/.zenirc-conf.el" "Major mode to waste time" t)
;;(put 'narrow-to-region 'disabled nil)


(defun line-upscreen (line)
  "Move the line in witch is the point to the top of screen
With ARG set the point to line ARG"
  (interactive "P")
  (recenter (if (null line)
                0
                (prefix-numeric-value line))))

(defun line-downscreen (line)
  "Move the line in witch is the point to the bottom of screen"
  (interactive "P")
  (recenter (if (null line)
                -1
                (prefix-numeric-value (- line)))))


(global-set-key (read-kbd-macro "C-x C-l") 'line-upscreen)
(global-set-key (read-kbd-macro "C-x M-l") 'line-downscreen)


;;(load-file "/usr/install/ilisp-5.12.0/ilisp.emacs")

;;(add-to-list 'load-path "/home/test/slime-1.0")
;;(require 'slime)
;;(slime-setup)

;;(add-to-list 'load-path "/usr/install/slime-1.0")
(add-to-list 'load-path "C:\\Program Files\\slime")
(require 'slime)
(add-hook 'lisp-mode-hook (lambda () (slime-mode t)))
(add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t)))
;; Optionally, specify the lisp program you are using. Default is "lisp"
;;(setq inferior-lisp-program "clisp")
(setq inferior-lisp-program "C:/Progra~1/clisp/clisp.bat")
;;(setq inferior-lisp-program "cmucl")
;;(setq inferior-lisp-program "sbcl")
(define-key lisp-mode-map "\C-m"   'reindent-then-newline-and-indent)
(define-key slime-repl-mode-map (read-kbd-macro "<C-up>") 'slime-repl-previous-input)
(define-key slime-repl-mode-map (read-kbd-macro "<C-down>") 'slime-repl-next-input)




(custom-set-faces
  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 )


(setq auto-mode-alist
      (append '(("\\.cl$" . lisp-mode)
		) auto-mode-alist))

;;(require 'scheme)
;;(define-key scheme-mode-map "\C-m" 'reindent-then-newline-and-indent)
;;
;;(autoload 'pov-mode "pov-mode.el" "PoVray scene file mode" t)
;;(setq auto-mode-alist
;;      (append '(("\\.pov$" . pov-mode) 
;;		("\\.inc$" . pov-mode))
;;	      auto-mode-alist))
