 (setq load-path (append load-path (list "/home/moi/emacs"
"/home/moi/emacs" )))
;;; -*-emacs-lisp-*-
;;(setq debug-on-error t) ; au cas-zou

(setq message-log-max 150)

(if (> emacs-major-version 20)
    (add-to-list 'load-path (expand-file-name "~/.elisp21"))
  (add-to-list 'load-path (expand-file-name "~/.elisp")))

;;(setq custom-file "~/.custom")
;;(if (> emacs-major-version 20)
;;      (load custom-file))

;;(load-library "emacs")

:;;; config personnelle
;;(when (equal user-real-login-name "lhh")
;;	 (load "post")
;;	 (load "courrier")
;;	 (load "mutt-alias"))

;; pour Â« C-x n n Â» et Â« C-x n w Â» (je me demande ce que Ã§a fout lÃ ) :
(put 'narrow-to-region 'disabled nil)
 


;;1/ mais il appelle ~/.elisp21/emacs.el (compilÃ© en *.elc)

 
;;; fichier de conf. emacs21
(fset 'yes-or-no-p 'y-or-n-p)
(tool-bar-mode -1)
;(menu-bar-mode -1)
(column-number-mode t)
(recentf-mode t)
(global-font-lock-mode t)

(setq-default
 inhibit-startup-message t
 frame-background-mode 'dark
 default-major-mode 'text-mode		; mode standard
 visible-bell t
 display-time-24hr-format t
 display-time-format "%R %a %e/%m/%Y")

(display-time)				; montre l'heure dans la barre d'Ã©tat

(require 'uniquify)			; changements de buffer C-x b amÃ©liorÃ©s
(setq-default uniquify-buffer-name-style 'post-forward-angle-brackets)
(setq uniquify-after-kill-buffer-p t)
(uniquify-rationalize-file-buffer-names)
(iswitchb-default-keybindings)


;;; Apropos
(global-set-key [f3]
		(lambda ()
		  (interactive)
		  (apropos (current-word))))
;;; Manuel
(autoload 'manual-entry "man" "appelle une page de manuel")
(autoload 'Man-default-man-entry "man" "choisit une page de manuel")
(global-set-key (kbd "<f4> <f4>")
		(lambda ()
		  (interactive)
		  (manual-entry (Man-default-man-entry))))

;;; Perl
(defun perl-func (func)
  "Look up FUNC in the perlfunc man page."
  (interactive "sFunction: ")
  (if (not (get-buffer "*Man perlfunc*"))
      (Man-getpage-in-background "perlfunc")
    (pop-to-buffer (get-buffer "*Man perlfunc*"))
    (goto-char (point-min))
    (re-search-forward (concat "^[ 	]+" func " "))))
(global-set-key (kbd "<f4> p")
		(lambda ()
		  (interactive)
		  (perl-func (current-word))))
(defalias 'perl-mode 'cperl-mode)
(setq cperl-hairy t)


;;;
;;; X-window|console ?
;;;
(if window-system
    (progn
      ;; options d'emacs sous X-window
      (setq-default
       wheel-scroll-interval 6		; nombre de lignes dÃ©placÃ©es par la roulette
       hauteur-normale 32		; petite hauteur du frame emacs
       largeur-normale 88
      ;; gestions des fenÃªtres -- fonte 9x15, X 1024*768
       largeur-ecran 103
       hauteur-ecran 49
       )

;;; fonctions d'emacs sous X-window
      ;; mulot Ã  roulette
      (defun wheel-scroll-down-some-lines ()
	(interactive)
	(scroll-down wheel-scroll-interval))
      (defun wheel-scroll-up-some-lines ()
	(interactive)
	(scroll-up wheel-scroll-interval))

      (defun wheel-scroll-down-page ()
	(interactive)
	(scroll-down))
      (defun wheel-scroll-up-page ()
	(interactive)
	(scroll-up))

      (defun wheel-scroll-down-other-page ()
	(interactive)
	(scroll-other-window-down wheel-scroll-interval))
      (defun wheel-scroll-up-other-page ()
	(interactive)
	(scroll-other-window wheel-scroll-interval))

      (global-set-key [mouse-5] 'wheel-scroll-up-some-lines)
      (global-set-key [mouse-4] 'wheel-scroll-down-some-lines)

      (global-set-key [S-mouse-5] 'wheel-scroll-up-page)
      (global-set-key [S-mouse-4] 'wheel-scroll-down-page)

      (global-set-key [C-mouse-5] 'wheel-scroll-up-other-page)
      (global-set-key [C-mouse-4] 'wheel-scroll-down-other-page)
      ;; end mulot

      (defun lhh-grande-fenetre ()
	"place et dimensionne la fenÃªtre active"
	(interactive)
	(set-frame-size (selected-frame) largeur-ecran hauteur-ecran)
	(set-frame-position (selected-frame) 0 0))

      (defun lhh-large-fenetre ()
	"redimensionne la fenÃªtre active"
	(interactive)
	(set-frame-size (selected-frame) largeur-ecran hauteur-normale))

      (defun lhh-petite-fenetre ()
	"redimensionne la fenÃªtre active"
	(interactive)
	(set-frame-size (selected-frame) largeur-normale hauteur-normale))

      (defun lhh-haute-fenetre ()
	"redimensionne la fenÃªtre active"
	(interactive)
	(set-frame-size (selected-frame) largeur-normale hauteur-ecran))

      (defun lhh-fenetre-utile ()
	"la fenÃªtre active prend la largeur utile"
	(interactive)
	(set-frame-width (selected-frame) (+ fill-column 1)))

      (defun lhh-bascule ()
	"bascule la taille de la fenÃªtre"
	(interactive)
	(cond
	 ((= taille-fenetre 0)
	  (progn (lhh-large-fenetre)
		 (setq taille-fenetre 1)))
	 ((= taille-fenetre 1)
	  (progn (lhh-petite-fenetre)
		 (setq taille-fenetre 2)))
	 ((= taille-fenetre 2)
	  (progn (lhh-haute-fenetre)
		 (setq taille-fenetre 3)))
	 (t
	  (progn (lhh-grande-fenetre)
		 (setq taille-fenetre 0)))))

      (defvar taille-fenetre 0)

      (defun intelligent-kill ()
	"ferme la fenÃªtre active"
	(interactive)
	(if multiple-frames
	    (delete-frame)
	  (save-buffers-kill-emacs)))
      (global-set-key "\C-x\C-c" 'intelligent-kill)

      ;; www
      (setq-default
       ;; browse-url-browser-function 'browse-url-lynx-xterm
       browse-url-xterm-program "lxterm"
       browse-url-browser-function 'browse-url-generic
       browse-url-generic-program "lxterm"
       browse-url-generic-args '("-e" "w3m")
       ;;browse-url-browser-function 'w3m-browse-url
       w3-default-homepage "http://localhost"
       url-keep-history "~/.emacs-w3-history"
       url-global-history-file "~/.mosaic-global-history"
       )

      (setq
       default-mode-line-format
       '("" mode-line-mule-info
	 mode-line-modified
	 (line-number-mode " L%l") (column-number-mode " C%c") " %p"
	  mode-line-frame-identification "%b"
	 " %[(" mode-name mode-line-process minor-mode-alist "%n" ")%] "
	 global-mode-string
	 (which-func-mode ("" which-func-format " ")))

       frame-title-format
       '((multiple-frames "%F " "Emacs ")
	 user-real-login-name "@" system-name " " display-time-string " " default-directory
	 " %[(" mode-name mode-line-process minor-mode-alist "%n" ")%] "
	 "%b")

       icon-title-format
       '((multiple-frames "emacs " "Emacs ")
	 user-real-login-name " %b")

       default-frame-alist
       '((foreground-color . "beige")(background-color . "grey14")
	 (scroll-bar-width . 9)
	 (font . "-misc-fixed-medium-r-normal-*-15-140-75-75-c-90-iso8859-1")
	 (top . 0)(left . 0)
	 (width . 88)
	 (height . 49))

       initial-frame-alist
       '((foreground-color . "ivory")(background-color . "black")
	 (width . 103)
	 )

       Man-notify-method 'newframe
       Man-frame-parameters
       '((background-color . "grey15")
	 (cursor-color . "deepskyblue2")
	 (mouse-color . "gold")
	 (width . 80)
	 (tool-bar-lines . 0)))

      (defun lhh-quitte-gnus ()
	"quitte les niouzes et ferme le frame"
	(interactive)
	(gnus-group-exit)
	(delete-frame))

      (defun lhh-suspend-gnus ()
	"suspend les niouzes et ferme le frame"
	(interactive)
	(gnus-group-suspend)
	(delete-frame))

      (defun niouzes ()
	"les niouzes"
	(interactive)
	(if (equal (buffer-name) "*Group*")
		   (progn
		     (make-frame-command)
		     (switch-to-buffer "*Group*"))
		   (gnus-other-frame))
	(modify-frame-parameters
	 nil '(;;(font . "-etl-fixed-medium-r-normal--14-135-75-75-c-0-iso8859-1")
	       (foreground-color . "wheat")
	       (height . 49)
	       (width . 100)))
	(gnus-topic-mode t t)
	(tool-bar-mode -1)
	(define-key gnus-group-mode-map "q" 'lhh-quitte-gnus)
	(define-key gnus-group-mode-map "z" 'lhh-suspend-gnus))

      ;; touches X
      (global-set-key [f12] 'lhh-bascule)
      (global-set-key "\C-x5+" 'lhh-grande-fenetre)
      (global-set-key "\C-x5-" 'lhh-petite-fenetre)

      (global-set-key [menu] 'tmm-menubar)
      (global-set-key [C-tab] 'other-window)

      ;; curseur variable selon insert/overwrite/read-only
      (defvar cursor-color nil "Last cursor color used (string)")
      (defun ins-cursor-set () "set cursor color according to ins mode"
	(let ((sv-crs-str cursor-color))
	  (cond (overwrite-mode
		 (modify-frame-parameters (selected-frame) '((cursor-type . box)))
		 (setq cursor-color "orchid")) ;overwrite cursor color
		(buffer-read-only
		 (modify-frame-parameters (selected-frame) '((cursor-type . box)))
		 (setq cursor-color "limegreen")) ;insertbuffer read only
		(t
		 (modify-frame-parameters (selected-frame) '((cursor-type . (bar . 4))))
		 (setq cursor-color "orangered"))) ;insert mode
	  (or (string= sv-crs-str cursor-color)
	      (set-cursor-color cursor-color)))) ;X terminal cursor color
      (add-hook 'post-command-hook 'ins-cursor-set))
  ;; fin du cas X

  ;; emacs-console : initialisation d'emacs en mode texte
  (progn
    (menu-bar-mode -1)			; pas de menus
    )
  ;; c'est tout pour l'instant
  )
;;; fin de (X | console)

;;; blancs & tabs
;;; whitespace
(autoload 'nuke-trailing-white-space "white-space" nil t)
(global-set-key [f16] 'nuke-trailing-white-space)

;;; blank-mode
(autoload 'blank-mode           "blank-mode"
  "Toggle blank visualization."    t)
(autoload 'blank-mode-customize "blank-mode"
  "Customize blank visualization." t)
(global-set-key [f6] 'blank-mode)

(add-hook 'text-mode-hook
	  (lambda ()
	    (setq show-trailing-whitespace t)))

;;; Scroll

;;(require 'scroll-in-place)

;; hll - B. rutt
;;(require 'hll)
(autoload 'hll-toggle-line "hll" "Highline lines and jumps" t)
(global-set-key (kbd "C-c h h") 'hll-toggle-line)
(global-set-key (kbd "C-c h p") 'hll-prev-highlight)
(global-set-key (kbd "C-c h n") 'hll-next-highlight)
(global-set-key (kbd "C-c h u") 'hll-unhighlight-buffer)

;;; ibuffer
(require 'ibuffer)
(setq ibuffer-line-format
      "%o%m%r %(%-16,999n%) %s \t%-13,999M %{%p%} %f")
(global-set-key [f10] 'ibuffer)
(setq ibuffer-formats '((mark modified read-only " " (name 20 20) " "
			      (size 8 -1 :right) " " (mode 20 20)
			      " " (process 8 -1) " " filename)
			(mark " " (name 25 -1) " " filename))
      ibuffer-elide-long-columns t)

;;;
;;; Hooks
;;;

(setq skeleton-pair t)
(defun my-skeleton-keys ()
	    (local-set-key "{" 'skeleton-pair-insert-maybe)
	    (local-set-key "(" 'skeleton-pair-insert-maybe)
	    (local-set-key "[" 'skeleton-pair-insert-maybe))

(add-hook 'text-mode-hook 'my-skeleton-keys)
(add-hook 'emacs-lisp-mode-hook 'my-skeleton-keys)

(add-hook 'Info-mode-hook
	  (lambda ()
	      ;; mode Info Ã  la Lynx
	      (local-set-key [home]  'Info-up)
	      (local-set-key [right] 'Info-follow-nearest-node)
	      (local-set-key [left]  'Info-last)
	      (local-set-key [up]    'Info-prev-reference)
	      (local-set-key [down]  'Info-next-reference)))

;; Pari
(defvar hilit-mode-enable-list nil)
(add-to-list 'hilit-mode-enable-list 'gp-mode)
(add-to-list 'hilit-mode-enable-list 'gp-script-mode)
(setq pari-colors "~/.gpdir/pari-colors.el")

(autoload 'gp-mode "pari" nil t)
(autoload 'gp-script-mode "pari" nil t)
(autoload 'gp "pari" nil t)
(autoload 'gpman "pari" nil t)
(add-to-list 'auto-mode-alist '("\\.gp$" . gp-script-mode))

(setq-default gp-window-height 15)
(defvar gp-process nil)
(defun gp-sub-window ()
  "ouvre/masque une fenÃªtre *PARI*"
  (interactive)
  (if (equal (buffer-name) "*PARI*")
      (delete-windows-on "*PARI*" t)
    (progn
      (split-window nil (max (- (window-height) gp-window-height) gp-window-height))
      (if gp-process
	  (progn
	    (other-window 1)
	    (switch-to-buffer "*PARI*"))
	(gp)
	(shrink-window (max 0 (- (window-height) gp-window-height)))))))
(global-set-key (kbd "<f5>") 'gp-sub-window)
;; fin de pari

;;;
;;; fonctions globales
;;;
(defun insert-date ()
  (interactive)
  (insert (format-time-string "%d/%m/%Y")))

(defun insert-long-date ()
  (interactive)
  (insert (format-time-string "date '+%A %e %B %Y, Ã  %H:%M'")))

(defun recenter-arg-zero ()
  "ramÃ¨ne la ligne courante en haut de l'Ã©cran"
  (interactive)
  (recenter 0))

(defun dos-unix ()
  "efface les retours-chariot"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (search-forward "\r\n" nil t) (replace-match "\n"))))

(defun unix-dos ()
  "crÃ©e les retours-chariot"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (search-forward "\n" nil t) (replace-match "\r\n"))))

(defun reformat-line ()
  "Indente la ligne, supprime les espaces finaux et passe Ã  la ligne."
  (interactive)
  (indent-according-to-mode)
  (end-of-line)
  (delete-region (point) (progn (skip-chars-backward " \t") (point)))
  (next-line 1))

(defun my-text-wash ()
  "nettoie dÃ©but et fin de lignes des espaces inutiles"
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while
	(search-forward-regexp "\\(^[ \t]+\\|[ \t]+$\\)" nil t)
      (replace-match ""))))

;;; home/end
(defun my-home ()
  "Le premier Home envoie en dÃ©but de ligne,
le deuxiÃ¨me en dÃ©but de page,
et le troisiÃ¨me au dÃ©but du tampon."
  (interactive nil)
  (cond
   ((and (eq last-command 'my-home)
	 (eq my-last-last-command 'my-home))
    (goto-char (point-min)))
   ((eq last-command 'my-home)
    (move-to-window-line 0))
   (t
    (beginning-of-line)))
  (setq my-last-last-command last-command))

(defun my-end ()
  "Le premier End envoie en fin de ligne,
le deuxiÃ¨me en fin de page,
et le troisiÃ¨me Ã  la fin du tampon."
  (interactive nil)
  (cond
   ((and (eq last-command 'my-end)
	 (eq my-last-last-command 'my-end))
    (goto-char (point-max)))
   ((eq last-command 'my-end)
    (move-to-window-line -1)
    (end-of-line))
   (t
    (end-of-line)))
  (setq my-last-last-command last-command))

;; Dired
(defun dired-first-file ()
  "remonte au premier fichier"
  (interactive)
  (beginning-of-buffer)
  (dired-next-line 2))

(defun dired-last-file ()
  "descend au dernier fichier"
  (interactive)
  (end-of-buffer)
  (dired-previous-line 1))

(setq-default dired-trivial-filenames "^\\.\\.?$\\|^#") ; fichiers cachÃ©s

(add-hook 'dired-load-hook
	  (lambda ()
	    (load "dired-x")
	    (setq dired-recursive-deletes 'top
		  dired-x-hands-off-my-keys nil
		  ;; cache les fichiers .*
		  dired-omit-files
		  (concat dired-omit-files "\\|^\\..+$\\|\\.bak$\\|\\.index\\|\\.old$"))
	    ;; touches dired
	    (define-key dired-mode-map [left] 'dired-up-directory)
	    (define-key dired-mode-map [right] 'dired-view-file)
	    (define-key dired-mode-map [home] 'dired-first-file)
	    (define-key dired-mode-map [end] 'dired-last-file)))

(add-hook 'dired-mode-hook
	  (function (lambda ()
		      (setq dired-omit-files-p t)
		      )))

(defun backward-char-or-view-quit ()
  "recule ou quitte"
  (interactive)
  (if (equal (point) 1)
      (View-quit)
    (backward-char)))

(eval-after-load "view"
  '(define-key view-mode-map [left] 'backward-char-or-view-quit))


;;; shell
(require 'shell-command)

;;; ssh
(autoload 'ssh "ssh" "Ssh shell" t)

;;; options de clavier emacs
;; Remaps universels
(global-set-key (kbd "\C-c <delete>") 'delete-region)
(global-set-key "\C-cg" 'goto-line)
(global-set-key "\C-cG" 'goto-char)
(global-set-key "\e*"   'ispell-complete-word)
(global-set-key [insertchar] 'overwrite-mode)

;; mise en boÃ®te des citations
(require 'boxquote)
(global-set-key "\C-cbB" 'boxquote-boxquote)
(global-set-key "\C-cbR" 'boxquote-unbox-region)
(global-set-key "\C-cbb" 'boxquote-buffer)
(global-set-key "\C-cbf" 'boxquote-defun)
(global-set-key "\C-cbi" 'boxquote-insert-file)
(global-set-key "\C-cbk" 'boxquote-kill)
(global-set-key "\C-cbK" 'boxquote-describe-key)
(global-set-key "\C-cbn" 'boxquote-narrow-to-boxquote)
(global-set-key "\C-cbp" 'boxquote-paragraph)
(global-set-key "\C-cbr" 'boxquote-region)
(global-set-key "\C-cbt" 'boxquote-title)
(global-set-key "\C-cbu" 'boxquote-unbox)
(global-set-key "\C-cbv" 'boxquote-describe-variable)
(global-set-key "\C-cby" 'boxquote-yank)
;; fin de boxquote

;; mouvements du curseur
(global-set-key [home] 'my-home)
(global-set-key [end]  'my-end)

;;;;; filladapt-mode ;;;;;
;; (filladapt.el) Augment the standard fill-mode
;; with more smarts - handles multiply quoted mail text, for example.
(require 'filladapt)
(setq-default default-justification 'full)
;; always use filladapt in several modes
(add-hook 'text-mode-hook 'turn-on-filladapt-mode)
;;(add-hook 'emacs-lisp-mode 'turn-on-filladapt-mode)

(global-set-key [f9] 'auto-fill-mode)


;;; ido
;; (require 'ido)
;; (ido-mode t)

;;; ffap
(ffap-bindings)

(require 'ff-paths)
;;
;;  You may alter the value of the variables:
;;
;;   ff-paths-list
;;   ff-paths-use-locate
;;   ff-paths-locate-max-matches
;;   ff-paths-using-ms-windows
;;   ff-paths-display-non-existent-filename
;;   ff-paths-prompt-for-only-one-match
;;   ff-paths-require-match
;;   ff-paths-gzipped



;;; local
(defvar french-holidays
  '((holiday-fixed 1 1 "Nouvel an")
    (holiday-float 4 1 1 "Lundi de PÃ¢ques")
    (holiday-fixed 5 1 "FÃªte du travail")
    (holiday-fixed 5 8 "Victoire 1945")
    (holiday-float 5 4 3 "Ascension")
    (holiday-float 5 1 -1 "Lundi de PentecÃ´te")
    ;; (holiday-float 6 0 1 "FÃªte des mÃ¨res") ; merde Ã  pÃ©tain
    ;; (holiday-float 6 0 3 "FÃªte des pÃ¨res")
    (holiday-fixed 7 14 "FÃªte Nationale")
    (holiday-fixed 8 15 "Assomption")
    (holiday-fixed 11 1 "Toussaint")
    (holiday-fixed 11 11 "Armistice 1918")
    (holiday-fixed 12 25 "NoÃ«l"))
  "French holidays")

(setq-default
 calendar-holidays french-holidays
 calendar-latitude 47.3			; Hey, emacs, I'm here !
 calendar-location-name "Nantes, fr"
 calendar-longitude -1.5
 calendar-week-start-day 1		; dÃ©marre la semaine le lundi
 diary-file "~/.memento"
 european-calendar-style t		; date normale jour/mois/annÃ©e
 mark-diary-entries-in-calendar	t
 mark-holidays-in-calendar t
 view-calendar-holidays-initially t
 view-diary-entries-initially	t
 calendar-day-name-array
 ["Dimanche" "Lundi" "Mardi" "Mercredi" "Jeudi" "Vendredi" "Samedi"]
 calendar-month-name-array
  ["Janvier" "FÃ©vrier" "Mars" "Avril" "Mai" "Juin" "Juillet"
   "AoÃ»t"   "Septembre" "Octobre" "Novembre" "DÃ©cembre"])

;;; Flyspell
(ispell-change-dictionary "francais" t) ; mon dico...
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checking" t)
(setq
 flyspell-global-modes
 '(LaTeX-mode TeX-mode latex-mode tex-mode gnus-article-edit-mode message-mode post-mode)
 flyspell-default-dictionary "francais")

;;; Devine la langue pour flyspell
;;; Langue(s)
;;(require 'guess-lang)
;(;;defun my-lang ()
 ;; "Le premier appel devine la langue,
;;le second bascule sur une langue usuelle"
 ;; (interactive nil)
  ;;(cond
  ;; ((eq last-command 'my-lang)
   ;; (lang-toggle))
   ;;(t
   ;; (guess-dictionary))))

(setq
 ispell-dictionary "francais"
 ispell-other-dictionary "british"
 flyspell-default-dictionary ispell-dictionary)
;;; devine le dictionnaire/bascule entre franÃ§ais et anglais
(global-set-key (kbd "<f7>") 'my-lang)
;;; (dÃ©s)active flyspell
(global-set-key (kbd "C-<f7>") 'flyspell-mode)

;;; Ocaml
(add-to-list 'auto-mode-alist '("\\.ml[iylp]?$" . caml-mode))
(autoload 'caml-mode "caml" "Major mode for editing Caml code." t)
(autoload 'run-caml "inf-caml" "Run an inferior Caml process." t)

;;; Scilab
;;(add-to-list 'auto-mode-alist '("\\(\\.sci$\\|\\.sce$\\)" . scilab-mode))
;;(autoload 'scilab-mode "scilab" "Major mode for editing Scilab code" t)

;;; Mutt
;;(defun my-post-settings ()
;;  (setq fill-column 72)
 ;; (turn-on-auto-fill)
  ;;(flyspell-mode 1))

;;(add-hook 'post-mode-hook 'my-post-settings)
;;(add-to-list 'auto-mode-alist '("^/tmp/mutt-" . post-mode))

;; TeX & LaTeX & AucTeX
;;(require 'tex-site)
(load "auctex.el" nil t t)
(setq-default
 tex-dvi-view-command "/usr/bin/evince"
 tex-dvi-print-command "lpr"
 TeX-auto-save t
 TeX-parse-self t
 TeX-master nil
 ;; Postscript
 ps-paper-type 'a4
 ;; LaTeX
 LaTeX-command-style '(;;("^french$" "frlatex") ; ligne Ã  ajouter
		       ("." "latex")))

 ;; Auctex - math-abbrev-prefix = Â² (kbd "Â²")
 ;; (setq LaTex-math-abbrev-prefix [2226])
 ;;LaTeX-math-abbrev-prefix [?\262])

(defun my-LaTeX-setup ()
  "Configuration LaTeX"
  (interactive)
  (auto-fill-mode t)
  (setq fill-column 100			; <-texte->
	ispell-parser 'tex
	TeX-insert-braces nil)
  (LaTeX-math-mode t)
  (when window-system
    (flyspell-mode 1)))

(add-hook 'LaTeX-mode-hook 'my-LaTeX-setup)

(defun my-french-guill ()
  "InsÃ¨re une paire de guillemets"
  (interactive)
  (insert "«  »")
  (backward-char 2))

(defun my-displaymaths ()
  "Ouvre un Â« displaymath Â»"
  (interactive)
  (newline-and-indent)
  (indent-for-tab-command)
  (insert "\\begin{displaymath}")
  (newline-and-indent)
  (newline-and-indent)
  (insert "\\end{displaymath}")
  (indent-for-tab-command)
  (previous-line 1)
  (indent-for-tab-command))

(defun my-display-maths ()
  "Ouvre un Â« displaymaths Â»"
  (interactive)
  (newline-and-indent)
  (indent-for-tab-command)
  (insert "\\[")
  (newline-and-indent)
  (newline-and-indent)
  (insert "\\]")
  (indent-for-tab-command)
  (previous-line 1)
  (indent-for-tab-command))

(defun my-footnote ()
  "Ouvre une footnote"
  (interactive)
  (search-backward-regexp "[])>Â».,[:alnum:]]")
  (forward-char)
  (insert "\\footnote{%\n  .}")
  (newline-and-indent)
  (beginning-of-line)
  (backward-char 4))

(defun my-fraction ()
  "InsÃ¨re une fraction"
  (interactive)
  (insert "\\frac{}{}")
  (backward-char 3))

(defun my-display-fraction ()
  "InsÃ¨re une grande fraction"
  (interactive)
  (insert "\\dfrac{}{}")
  (backward-char 3))

(defun my-frac-or-foot ()
  "InsÃ¨re une fraction ou une footnote selon le contexte"
  (interactive)
  (if (texmathp)
	  (my-fraction)
	(my-footnote)))

(defun my-nombre ()
  "InsÃ¨re \"\\nombre{}\""
  (interactive)
  (insert "\\nombre{}")
  (backward-char 1))

(defun index-current-word ()
  "Indexe le mot sous ou prÃ©cÃ©dant le curseur"
  (interactive)
  (forward-char)
  (backward-word 1)
  (forward-word 1)
  (insert (concat "\\index{" (current-word) "}")))

(defun my-label ()
  "Ouvre un label"
  (interactive)
  (forward-char)
  (backward-word 1)
  (insert "\\label{}")
  (backward-char 1))

(defun my-latex-keys ()
  "Touches LaTeX"
  (interactive)
  (setq skeleton-pair t)
  (define-key LaTeX-mode-map "$" 'skeleton-pair-insert-maybe)
  (define-key LaTeX-mode-map "{" 'skeleton-pair-insert-maybe)
  (define-key LaTeX-mode-map "(" 'skeleton-pair-insert-maybe)
  (define-key LaTeX-mode-map "[" 'skeleton-pair-insert-maybe)
  (define-key LaTeX-mode-map (kbd "C-c f") 'my-frac-or-foot)
  (define-key LaTeX-mode-map (kbd "C-c F") 'my-display-fraction)
  (define-key LaTeX-mode-map (kbd "C-c n") 'my-nombre)
  (define-key LaTeX-mode-map [S-f12] 'wysiwyg-latex-tabular)
  (define-key LaTeX-mode-map (kbd "C-c !") 'TeX-next-error)
  (define-key LaTeX-mode-map (kbd "C-c i") 'index-current-word)
  (define-key LaTeX-mode-map (kbd "C-c l") 'my-label)
  (define-key LaTeX-mode-map [?\253] 'my-french-guill)
  (define-key LaTeX-mode-map "\"" 'my-french-guill)
  (define-key LaTeX-mode-map (kbd "C-c m") 'my-display-maths)
  (setq LaTex-math-abbrev-prefix (kbd "<pause>")))

(add-hook 'LaTeX-mode-hook 'my-latex-keys)
(require 'font-latex)

;; reftex -- D. Kastrup
(require 'reftex)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)

;;; ... et c'est en couleurs !
(set-face-foreground 'font-lock-comment-face "gold")
(set-face-background 'font-lock-comment-face "grey32")
(set-face-background 'fringe "gray25")

(defun my-message-colors ()
  (interactive)
  (set-face-foreground 'message-cited-text-face "gold")
  (set-face-background 'message-cited-text-face "grey32"))
(eval-after-load "message-mode" 'my-message-colors)

;;; w3m
(setq w3m-icon-directory "/usr/src/ftp/cvs/emacs-w3m/icons")
(autoload 'w3m "w3m" "Interface for w3m on Emacs." t)

;;; mail
(add-hook 'mail-setup-hook 'mail-abbrevs-setup)

(setq gnus-auto-select-next 'quietly)

;;; essai d'unification...
(set-language-environment "Latin-1")

(setq gnus-group-posting-charset-alist
      '((message-this-is-mail iso-8859-1 (iso-8859-1))
	(message-this-is-news iso-8859-1 (iso-8859-1))))

;;; aussi dans ~/.gnus
(setq mm-body-charset-encoding-alist
      '((iso-8859-1 . 8bit)
	(iso-8859-15 . 8bit)))

(require 'ucs-tables)
(unify-8859-on-encoding-mode 1)
(unify-8859-on-decoding-mode 1)
(standard-display-8bit 128 255)


;;;
(defun adieu ()
  (unless (y-or-n-p "Fermer cette instance d'Emacs ?")
    (keyboard-quit)))

(add-hook 'kill-emacs-hook
	  'adieu)

(if (equal user-real-login-name "lhh")
    (require 'trucs))
;;; The End ;;;
 


;2/ Le fichier ~/.elisp21/trucs.el contient des trucs Ã  l'essai

 
;;; trucs et bidules Ã  l'essai
(message "les trucs...")

;;; Linus
(defun linux-c-mode ()
  "C mode with adjusted defaults for use with the Linux kernel."
  (interactive)
  (c-mode)
  (c-set-style "K&R")
  (setq c-basic-offset 8))

;;; Jay Belanger
(defvar zoomconf nil)

(defun zoom-in ()
  "Maximize the current window, saving the current window configuration"
  (interactive)
  (setq zoomconf (current-window-configuration))
  (delete-other-windows))

(defun zoom-out ()
  "Restore the window configuration"
  (interactive)
  (set-window-configuration zoomconf))

;;; euro
(setq euro-rate 6.55957)
(defun cvef (&optional arg)
"Converts ARG euros to francs. If ARG is nil,
returns the exchange rate contained in euro-rate variable."
(interactive "p")
(if arg
    (/ (float (floor (+ 0.5 (* 100 (* euro-rate
				      (if (numberp arg) arg
					(prefix-numeric-value arg))))))) 100)
  euro-rate))

(defun cvfe (&optional arg)
"Converts ARG francs to euros. If ARG is nil,
returns the exchange rate contained in euro-rate variable."
(interactive "p")
(if arg
    (/ (float (floor (+ 0.5 (* 100 (/ (if (numberp arg) arg
					(prefix-numeric-value arg))  euro-rate))))) 100)
  (/ 1 euro-rate)))

(defun conv-euro (&optional arg)
"Converts ARG euros to locale currency.
If ARG is nil, converts the number before point."
(interactive)
(if arg
    (cvef arg)
  (let ((pos (point))
	(value nil))
    (save-excursion
      (if (re-search-backward "^\\|[ \t\n]" 0 t 1)
	  (if (re-search-forward "[0-9]*\\(.?[0-9]+\\)"
				 pos t 1)
	      (setq value (cvef (float
				 (string-to-number
				  (match-string 0)))))
	    (setq value (cvef))))
      (if value
	  (message "%s" value))))))

;;; calendrier
(global-set-key [f11] (lambda ()
			(interactive)
			(require 'calendar)
			(insert (calendar-french-date-string (calendar-current-date)))))


(global-set-key (kbd "C-c <deletechar>") 'delete-region)
(global-set-key (kbd "M-\"") 'my-french-guill)

;;; no-word
(autoload 'no-word "no-word" "word to txt")
(add-to-list 'auto-mode-alist '("\\.doc\\'" . no-word))

;;; ePiX
(setq auto-mode-alist (cons '("\\.xp" . epix-mode) auto-mode-alist))
(autoload 'epix-mode "epix" "ePiX editing mode" t)
(setq epix-mark-files-as-epix t)
(setq epix-insert-template-in-empty-buffer t)

(autoload 'flix-mode "epix" "ePiX editing mode" t)
(setq auto-mode-alist (cons '("\\.flx" . flix-mode) auto-mode-alist))

;;; Post
;;(require 'post)

;;; parenthÃ¨ses
;;(global-set-key "%" 'goto-match-paren)
;; (defun goto-match-paren (arg)
;;   "Go to the matching parenthesis if on parenthesis, otherwise insert %."
;;   (interactive "p")
;;   (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
;;         ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
;;         (t (self-insert-command (or arg 1)))))

;; This will match the corresponding ( even when the cursor
;; is on or following the ) char

;; (defun goto-match-paren (arg)
;;   "Move to the parenthesis matching the one under or before the
;; cursor, otherwise insert %"
;;   (interactive "p")
;;   (cond ((looking-at "\\s\(") (forward-list 1) t)
;; 	((eq (char-syntax (preceding-char)) ?\)) (backward-list 1) t)
;; 	((looking-at "\\s\)") (forward-char 1) (backward-list 1) t)
;;         (t (self-insert-command (or arg 1)))))

;;; indentation auto
(global-set-key (kbd "RET") 'newline-and-indent)
(define-key text-mode-map (kbd "RET") 'newline)

;;; voir les images
(auto-image-file-mode t)

;;; jit-lock
(setq-default
 jit-lock-stealth-time 16
 jit-lock-stealth-nice 0.5
 jit-lock-defer-contextually t
 font-lock-multiline t)

;; B. Rutt
(setq gc-cons-threshold 4000000)


;(define-key global-map [menu-bar]
;  (remove '(buffer) (lookup-key global-map [menu-bar])))
;(define-key global-map [menu-bar buffer]
;  (cons "Buffers" (make-sparse-keymap "Buffers")))

;;(menu-bar-mode -1) ; pas de menu apparent par dÃ©faut

;(require 'wysiwyg-latex-tabular)


;;(define-key LaTeX-mode-map (kbd "C-<f6>") 'nuke-trailing-white-space)
(global-set-key (kbd "C-<f6>") 'nuke-trailing-white-space)

(set-face-font 'modeline "8x13")

;;; Aspell
(setq-default ispell-program-name "aspell")

;;; Fin ;;;
(provide 'trucs)
(message "OK pour les trucs")

;;; 1 Germinal an 213 de la RÃ©volution
 

 
;;; This code determines the buffer language by counting several small and
;;; often used words characteristic each language and ranks them.  The
;;; original version was posted by Jean-Philippe Theberge.
;;;    From: Jean-Philippe Theberge <mailto:jphil@godzilla.act.oda.fr> 
;;;    Subject: Re: Guessing a language.
;;;    Newsgroups: gnu.emacs.help
;;;    Date: 03 Mar 2000 16:46:41 +0100"
;;; Adapted by Alex Schroeder <alex@gnu.org>

;;; modified by Jacques L'helgoualc'h <lhh@free.fr> 17:28:49, dimanche 20 mai 2001

;;; Installation: put this file somewhere in your load-path,
;;;
;;;             (require 'guess-lang)
;;;
;;; in your ~/.emacs, set initial values like:
;;;
;;;  (setq
;;;   flyspell-default-dictionary "francais"
;;;   ispell-other-dictionary "british")
;;;
;;; and set keys as you want:
;;;
;;;(global-set-key (kbd "<f7>") 'guess-dictionary)

(require 'cl)

(defvar guess-language-rules
  '(("en" . "\\<\\(of\\|the\\|and\\|or\\|how\\)\\>")
    ("de" . "\\<\\(und\\|oder\\|der\\|die\\|das\\|wie\\)\\>") 
    ("fr" . "\\<\\(et\\|ou\\|[ld]es\\|que\\)\\>"))
  "Alist of rules to determine the language of some text.
    Each rule has the form (CODE . REGEXP) where CODE is a string to
    identify the language (probably according to ISO 639), and REGEXP is a
    regexp that matches some very common words particular to that language.
    The default language should be listed first.  That will be the language
    returned when no REGEXP matches, as would happen for an empty
    document.")

(defvar lang-dictionary-alist
  '(("en" . "british")
    ("de" . "deutsch")
    ("fr" . "francais"))
  "Alist of rules (LANG . ISPELL-DICTIONARY)")

(defun guess-buffer-language ()
  "Guess language in the current buffer"
  (save-excursion 
    (goto-char (point-min))
    (let ((count (map 'list (lambda (x)
			      (cons (string-to-number
				     (count-matches (cdr x))) (car x)))
		      guess-language-rules)))
      (cdr (assoc (car (sort (map 'list 'car count) '>)) 
		  count)))))

(defun guess-lang ()
  "Guess language in the current buffer."
  (interactive)
  (message (guess-buffer-language)))

(defun guess-dictionary ()
  "Set ispell-local-dictionary according to guessed language"
  (interactive)
  (ispell-change-dictionary 
   (setq ispell-local-dictionary (cdr (assoc (setq lang (guess-buffer-language)) lang-dictionary-alist))))
  (set-face-inverse-video-p 'modeline (not (equal ispell-local-dictionary flyspell-default-dictionary)))
  (message (concat "Ispell will use dictionary: " ispell-local-dictionary)))

;;; 
(defun lang-toggle ()
  "Toggles between two languages - Alterne entre deux langues"
  (interactive)
  (ispell-change-dictionary
   (setq ispell-local-dictionary
	 (if (set-face-inverse-video-p
	      'modeline
	      (equal ispell-local-dictionary flyspell-default-dictionary))
	     ispell-other-dictionary
	   flyspell-default-dictionary))))

(provide 'guess-lang)
 

 
;;; wysiwyg-latex-tabular.el - Adjust spacing in LaTeX tabular constructs
;;;
;;; Copyright Â© 1992-2003 Dag Asheim, Linpro AS
;;;
;;; Author: Dag Asheim <dash@linpro.no>
;;;
;;; $Id: wysiwyg-latex-tabular.el,v 1.41 2003/01/16 20:27:25 dash Exp $

;;; This file is not (yet) part of GNU Emacs.
;;;
;;; This is free software; you can redistribute it and/or modify it
;,; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2, or (at your option)
;,; any later version.

;;; LaTeX and WYSIWYG (What You See Is What You Get) are two very
;;; different concepts, each with their own pros and cons. The ideas
;;; behind LaTeX and structured mark-up are excellent, but even the
;;; most avid LaTeX proponent can have a hard time justifying (pun
;;; intended) layout of complex \multicolumn-ridden LaTeX tables.
;;;
;;; This code attempts to aid in that process by bringing just a touch
;;; of WYSIWYG to the table.  Wouldn't it be nice if there was some
;;; Emacs Lisp function that could transform the following LaTeX code:
;;;
;;; \begin{tabular}{lcr}\hline
;;; left justified&centred&right justified\\
;;; l&c&r\\
;;; \& and \%&\multicolumn{2}{|c|}{centred over 2 columns}\\
;;; \multicolumn{2}{|l|}{left justified over 2 columns}&r\\
;;; \end{tabular}
;;;
;;; ... to something more readable?  Let's say, something like this:
;;;
;;; \begin{tabular}{lcr}\hline
;;; left justified &              centred               & right justified \\
;;; l              &                 c                  &               r \\
;;; \& and \%      &     \multicolumn{2}{|c|}{centred over 2 columns}     \\
;;; \multicolumn{2}{|l|}{left justified over 2 columns} &               r \\
;;; \end{tabular}
;;;
;;; If you agree, then this code might be for you.  Features:
;;;
;;;  o Supports most of LaTeX's table making environments (check out
;;;    the ones you don't have from www.ctan.org):
;;;
;;;    Environment		       Description
;;;    \begin{tabular}{FMT}	       Standard table, format FMT
;;;    \begin{tabular*}{W}{FMT}	       Table of width W and format FMT
;;;    \begin{array}{FMT}	       Typeset table in math mode
;;;    \begin{supertabular}{FMT}Â¹      Table can span more than 1 page
;;;    \begin{supertabular*}{W}{FMT}Â¹  Width = W, more than 1 page
;;;    \begin{longtable}{FMT}Â²	       Table can span more than 1 page
;;;    \begin{tabularx}{W}{FMT}Â²       Width = W, supports format X
;;;    \begin{ltxtable}{W}{FMT}Â²       Combines longtable and tabularx
;;;    \begin{array}DELIM{FMT}DELIMÂ³   As array, but with delimiters
;;;
;;;    Â¹ \usepackage{supertab} is needed to provide these to LaTeX.
;;;
;;;    Â² These environments must be imported to LaTeX with
;;;      \usepackage{name-of-environment} before use.
;;;
;;;    Â³ After an \usepackage{delarray} declaration, it it possible to
;;;      include delimiters around the format string of an array
;;;      environment to get huge delimiters around the table in the
;;;      output.  The delimiters can be: \{, \}, (, ), |, or . (for no
;;;      delimiter).
;;;
;;;    (Btw, all this has nothing to do with the environment named
;;;    'table', which (confusingly) is inessential for making tables.)
;;;
;;;  o Supports the following column format codes:
;;;
;;;    Format code	 Effect on LaTeX tables
;;;    l		 Left justify
;;;    c		 Center
;;;    r		 Right justify
;;;    p{WIDTH}		 Paragraph, can be multiline (aligned as 'l')
;;;    @{CODE}		 Suppress spacing and insert CODE at each row
;;;    |		 Vertical line - does not create a column
;;;    *{COUNT}{FORMAT}  COUNT repetitions of FORMAT
;;;    XÂ¹		 As p, but width is calculated automatically
;;;    m{WIDTH}Â²	 As p, but vertically aligned in the middle
;;;    b{WIDTH}Â²	 As p, but vertically aligned to the bottom
;;;    >{CODE}Â²		 Insert CODE before next column
;;;    <{CODE}Â²		 Insert CODE after previous column
;;;    !{CODE}Â²		 Insert CODE at each row (but keep spacing)
;;;    P{SPEC}Â³		 Format numbers (supported as an 'r'-column)
;;;    D{TEX}{DVI}{NR}Â³	 Format numbers (supported as an 'r'-column)
;;;
;;;    Â¹ \usepackage{tabularx} or \usepackage{ltxtable} is needed to
;;;      provide the format code X to LaTeX, and it is then only
;;;      recognised within the respective environments.
;;;
;;;    Â² \usepackage{array} is needed to provide these 5 format codes
;;;      to LaTeX, but then they are available to the regular tabular
;;;      environments.
;;;
;;;    Â³ These environments align numbers on decimal point:
;;;      \usepackage{warpcol} is needed for P (e.g P{3.1}) and
;;;      \usepackage{dcolumn} is needed for D (e.g D{.}{\cdot}{2}).
;;;
;;;  o Supports \multicolumn, and (for brevity) the abbreviation \mc
;;;    (for \mc to work in LaTeX, an declaration such as the following
;;;    is needed: \def\mc{\multicolumn})
;;;
;;;  o Points out some common mistakes in the table formating:
;;;
;;;    These are marked as errors (no processing is done):
;;;
;;;    - Not in LaTeX tabular(*{})/array/supertabular(*{})/-
;;;	 longtable/tabularx/ltxtable{} format
;;;    - Empty format string - no use of l, c, r, X, p{}, m{}, b{},
;;;      @{}, !{}, <{}, >{}, or *{}{}
;;;    - Error in format string, unrecognised character: '...'
;;;    - Format string requires ... columns, but more are
;;;	 present in row ...
;;;    - Format string requires ... columns, but only ... are
;;;	 present in row ...
;;;    - Mismatched environment: \begin{E1} ... \end{E2}
;;;
;;;    This is just a warning (i.e. the processing is done):
;;;
;;;    - Warning: Format code 'X' used in ... environment, not
;;;      tabularx or ltxtable
;;;
;;; Basic assumptions:
;;;
;;; This code is meant for tables where each row in the table are on a
;;; single line in the input.  This may lead to very long lines on
;;; some tables.  LaTeX does not require \\ at the end of the last
;;; row, but this code does.  Text after \\ is ignored for formating
;;; purposes, so don't put &-signs there.

(defun wysiwyg-latex-tabular ()
  "Align columns in LaTeX tabular constructs, giving a quasi-WYSIWYG effect.
The alignment is based on the format string (e.g. {lcr}) to make the
spacing in the mark-up similar to the printed output.

Before:

\\begin{tabular}{lcr}\\hline
left justified&centred&right justified\\\\
l&c&r\\\\
\\& and \\%&\\multicolumn{2}{|c|}{centred over 2 columns}\\\\
\\multicolumn{2}{|l|}{left justified over 2 columns}&r\\\\
\\end{tabular}

After:

\\begin{tabular}{lcr}\\hline
left justified &              centred               & right justified \\\\
l              &                 c                  &               r \\\\
\\& and \\%      &     \\multicolumn{2}{|c|}{centred over 2 columns}     \\\\
\\multicolumn{2}{|l|}{left justified over 2 columns} &               r \\\\
\\end{tabular}"
  (interactive "*")

  (defun unique-string-in-buffer (&optional init start end limit)
    "Return a string which don't (yet) exist in current buffer."

    (defun a+ (str limit)
      "Increase value of string STR destructivly, as a base LIMIT number."
      (cond ((string= str "")
	     (string 0))
	    ((< (aref str (1- (length str))) (1- limit))
	     (progn (aset str (1- (length str))
			  (1+ (aref str (1- (length str)))))
		    str))
	    ((concat (a+ (substring str 0 -1) limit) (string 0)))))

    (let* ((limit (if (null limit) 32 limit))
	   (str (cond ((stringp init) (a+ (copy-sequence init) limit))
		      ((integerp init) (make-string init 0))
		      (make-string 0)))
	   (start (if (null start) (point-min) start)))
      (save-excursion
	(goto-char start)
	(while (re-search-forward str end t)
	  (goto-char start)
	  (setq str (a+ str limit))))
      str))


  (defun width-from-to (c1 c2)
    "Calculate the width from column C1 to C2, based on the widths array."
    (let ((sum 0))
      (while (< c1 c2)
	(setq sum (+ sum (aref widths c1) 3) ; 3 == (length " & ")
	      c1 (1+ c1)))
      (+ sum (aref widths c1))))


  (defun re-paren (&optional n)
    "Return the string matched by the last search in the current buffer.
Argument N is number of the parenthesis which matched, 1 by default."
    (if (null n)
	(setq n 1))
    (buffer-substring (match-beginning n) (match-end n)))


  (defun match-int (n)
    "Return the integer matched by the last search in the current buffer.
Argument N is number of the parenthesis which matched."
    (string-to-int (re-paren n)))


  (defun insert-3 (c2 c1 w ll)
    "Insert '(C2 C1 W) into the list LL.
LL has the form ((ac2 ac1 aw) (bc2 bc1 bw) ...), with ac2 < bc2."
    (if (or (null ll) (< c2 (car (car ll))))
	(cons (list c2 c1 w) ll)
      (cons (car ll) (insert-3 c2 c1 w (cdr ll)))))


  (defun parse-format ()
    "Parse the format string from a LaTeX array/tabular construct.
The function does not take any arguments, but it communicates with
the caller by reading (match-end 0)"

    (defun parse-format-internal (pt fmt rep)
      "The internal parsing function for tabular format strings.
Start at position PT.  Append result to FMT.  Do REP repetitions.  Return FMT."
      (while (<= 0 (setq rep (1- rep)))
	(goto-char pt)
	(while (looking-at re-fmt)
	  (goto-char (match-end 0))
	  (cond ((memq (char-after (match-beginning 0))
		       '(?l ?c ?r ?p ?m ?b ?X ?P ?D))
		 (setq fmt (cons (char-after (match-beginning 0)) fmt)))
		((eq (char-after (match-beginning 0)) ?*)
		 (setq fmt
		       (parse-format-internal (point) fmt (match-int 1)))))))
      (if (eq (char-after) ?\})
	  (forward-char)
	(error "Error in format string, unrecognised character: '%c'"
	       (char-after)))
      fmt)

    (or (nreverse (parse-format-internal (match-end 0) '() 1))
	(error "Empty format string - no use of l, c, r, X, p{}, m{}, b{}, @{}, !{}, <{}, >{}, *{}{}, P{}, or D{}{}{}")))


  (let ((fmt	'())			; List of format codes for each column
	(widths	'())			; Used as a vector (aset/aref)
	(multi	'())			; \multicolumn data: '((C2 C1 W) ...)
	(colnum	0)			; Number of current column
	(maxcol	0)			; Max number of columns/length of fmt
	(maxw	0)			; Max width in characters
	(w	0)			; Width of current cell
	(tmp	0)
	(unique1 "")
	(unique2 "")
	(unique3 "")
	(newtable "")
	(marker '())
	(origpos (point))
	(delta  0)
	(type	0)			; Format type
	(envir '())			; Environment (following \begin)
	(re-beg	"\\\\begin{\\(\\(tabular\\*\\|supertabular\\*\\|tabularx\\|ltxtable\\)}{[^}]*\\|tabular\\|supertabular\\|array\\|longtable\\)}\\(\\[[tb]\\]\\)?\\(%[^\n]*\n\\)*\\(\\\\[{}]\\|[(|).]\\)?{")
	(re-end	"\\\\end{\\(\\(super\\)?tabular\\*?\\|array\\|longtable\\|tabularx\\|ltxtable\\)}")
	(re-fs "%\\|\n\\|&\\|\\\\\\\\")	; Field (+ line) separator
	(re-fmt	"[lcrX|]\\|[pmb@!><P]{[^}]*}\\|D{[^}]*}{[^}]*}{[^}]*}\\|\\*{\\([0-9]+\\)}{")
	(re-mc	"[ \t]*\\\\\\(multicolumn\\|mc\\){\\([1-9][0-9]*\\)}{"))
    (save-excursion
      (end-of-line)
      (condition-case err (re-search-backward re-beg)
	(search-failed (error "Not in LaTeX tabular(*{})/array/supertabular(*{})/longtable/tabularx/ltxtable{} format")))

      (setq envir (buffer-substring (match-beginning 1) (match-end 1))
	    fmt (parse-format))

      (if (string-match "}{.*" envir)	; Search for and ...
	  (setq envir (replace-match "" t t envir))) ; ... remove '}{width'

      (if (and (memq ?X fmt) (not (member envir '("tabularx" "ltxtable"))))
	  (message "%s%s%s"
		   "Warning: Format code 'X' used in "
		   envir
		   " environment, not tabularx or ltxtable"))

      (setq maxcol (length fmt)		; Init maxcol
	    widths (make-vector maxcol 0)) ; Set all widths to 0

      (forward-line)

      (setq delta (- origpos (point)))

      (setq buf (current-buffer)
	    start (point)
	    end
	    (save-excursion
	      (re-search-forward re-end nil 'move)
	      (if (not (string= envir (re-paren)))
		  (error "Mismatched environment: \\begin{%s} ... \\end{%s}"
			 envir
			 (re-paren)))
	      (1- (match-beginning 0))))

      (setq
       newtable
       (with-temp-buffer		; Copy table to scratch buffer
	 (insert-buffer-substring buf start end)

	 (setq marker (make-marker))
	 (set-marker marker delta)

	 (setq unique1 (unique-string-in-buffer 2))

	 (goto-char (point-min))
	 (while (re-search-forward "\\\\&" nil t)
	   (replace-match unique1 t t)) ; Hide \&

	 (setq unique2 (unique-string-in-buffer unique1))

	 (goto-char (point-min))
	 (while (re-search-forward "\\\\%" nil t)
	   (replace-match unique2 t t)) ; Hide \%

	 (setq unique3 (unique-string-in-buffer unique2))

	 (goto-char (point-min))
	 (while (re-search-forward "%[^\n&]*\\(&\\)" nil t)
	   (replace-match unique3 t t nil 1) ; Hide & after %
	   (goto-char (point-min)))

	 (goto-char (point-min))
	 (while (re-search-forward "[ \t]*&[ \t]*" nil t) ; Kill whitespace
	   (replace-match "&" t t))

	 (goto-char (point-min))
	 (while (re-search-forward "^[ \t]+\\|[ \t]+$" nil t)
	   (replace-match "" t t))

	 (goto-char (point-min))
	 (while (re-search-forward "[ \t]+\\\\\\\\" nil t)
	   (replace-match "\\\\" t t))

	 (goto-char (point-min))

	 (while (not (eobp))		; Find the width of the rows
	   (setq w (- (save-excursion (re-search-forward re-fs nil t)
				      (match-beginning 0))
		      (point)))		; w == width of current cell
	   (cond ((looking-at re-mc)
		  (setq multi (insert-3 (+ colnum (match-int 2) -1)
					colnum w multi)
			colnum (+ colnum (match-int 2) -1)))
		 ((< (aref widths colnum) w)
		  (aset widths colnum w))) ; width = max width
	   (forward-char w)
	   (cond ((looking-at "\\\\\\\\")
		  (if (< (1+ colnum) maxcol)
		      (error "Format string requires %d columns, but only %d are present in row %d"
			     maxcol
			     (1+ colnum)
			     (count-lines (point-min) (point))))
		  (setq colnum 0)
		  (forward-line))
		 ((looking-at "\n")
		  (forward-line))
		 ((looking-at "%")
		  (forward-line))
		 ((looking-at "&")
		  (setq colnum (1+ colnum))
		  (forward-char)))
	   (if (<= maxcol colnum)
	       (error "Format string requires %d columns, but more are present in row %d"
		      maxcol
		      (count-lines (point-min) (point)))))
	 (goto-char (point-min))

	 ;; (aref widths N) == max width of row N, excluding \multicolumn

	 (while multi		; Adjust field widths for \multicolumn
	   (let* ((c2 (car (car multi))) ; Ending column
		  (w (car (cdr (cdr (car multi))))) ; Width from \multicolumn
		  (cw (width-from-to (car (cdr (car multi))) c2)))
	     (if (< cw w)
		 (aset widths c2 (+ (aref widths c2) (- w cw))))
	     (setq multi (cdr multi))))

	 ;; (aref widths N) == max width of row N, including \multicolumn

	 (while (not (eobp))		; Insert correct spacing
	   (setq colnum 0)
	   (while (< colnum maxcol)
	     (if (looking-at re-mc)
		 (setq type (let ((data (match-data)))
			      (prog1 (save-excursion
				       (car (parse-format)))
				(store-match-data data)))
		       maxw (width-from-to colnum
					   (+ colnum -1 (match-int 2)))
		       colnum (+ colnum (match-int 2)))
	       (setq type (nth colnum fmt)
		     maxw  (aref widths colnum)
		     colnum (1+ colnum)))
	     (setq w (- (save-excursion (re-search-forward re-fs nil t)
					(match-beginning 0))
			(point))
		   tmp (- maxw w))
	     (cond ((memq type '(?l ?p ?m ?b ?X))
		    (forward-char w)	; Align left,
		    (insert-char 32 tmp)) ; spaces after
		   ((memq type '(?c))	; Align centre,
		    (insert-char 32 (/ tmp 2)) ; space before...
		    (forward-char w)
		    (insert-char 32 (/ (1+ tmp) 2))) ; ... and after
		   ((memq type '(?r ?P ?D)) ; Align right,
		    (insert-char 32 tmp) ; space before
		    (forward-char w)))
	     (if (looking-at "\n\\|%")
		 (progn
		   (setq colnum (1- colnum))
		   (forward-line)
		   (if (< 0 colnum)
		       (insert-char 32 (+ 3 (width-from-to 0 (1- colnum)))))
		   (backward-char)))
	     (forward-char))
	   (forward-line))

	 (goto-char (point-min))	; Insert space around &
	 (while (re-search-forward "&" nil t)
	   (replace-match " & " t t))

	 (goto-char (point-min))	; Insert space before \\
	 (while (re-search-forward "\\\\\\\\" nil t)
	   (replace-match " \\\\" t t))

	 (goto-char (point-min))	; Restore & after %
	 (while (re-search-forward unique3 nil t)
	   (replace-match "&" t t))

	 (goto-char (point-min))	; Restore \%
	 (while (re-search-forward unique2 nil t)
	   (replace-match "\\%" t t))

	 (goto-char (point-min))	; Restore \&
	 (while (re-search-forward unique1 nil t)
	   (replace-match "\\&" t t))

	 (goto-char (point-min))	; Remove indention on comments
	 (while (re-search-forward "\n *%" nil t)
	   (replace-match "\n%" t t))

	 (list (marker-position marker) (buffer-string))))

      (setq delta (car newtable))
      (if (or (<= origpos start) (< end origpos))
	  (setq delta 0))
      (delete-region start end)
      (insert (car (cdr newtable))))
    (forward-char delta)))

;;;
(provide 'wysiwyg-latex-tabular)









;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;; LATEX PERSO

(defvar guillaume-compile-command "rubber -pd %s")

(defun guillaume-compile () (interactive)
   (save-buffer)
   (shell-command (format guillaume-compile-command buffer-file-name))
   )
(add-hook 'LaTeX-mode-hook
	  '(lambda nil
	     (define-key LaTeX-mode-map "\M-c\M-t" 'guillaume-compile)))

(defvar guillaume-view-command "evince %s.ps & " "&")

(defun guillaume-view () (interactive)
   (save-buffer)
   (shell-command (format guillaume-view-command
(file-name-sans-extension(buffer-file-name))))
   )
(add-hook 'LaTeX-mode-hook
          '(lambda nil
             (define-key LaTeX-mode-map "\M-c\M-v" 'guillaume-view)))


(defvar guillaume-rubber-command "rubber --clean %s")

(defun guillaume-rubber () (interactive)
   (save-buffer)
   (shell-command (format guillaume-rubber-command
buffer-file-name))
   )
(add-hook 'LaTeX-mode-hook
          '(lambda nil
             (define-key LaTeX-mode-map "\M-c\M-r" 'guillaume-rubber)))



(defvar guillaume-pdf-command "kpdf %s.pdf & ")

(defun guillaume-pdf () (interactive)
   (save-buffer)
   (shell-command (format guillaume-pdf-command
(file-name-sans-extension(buffer-file-name))))
   )
(add-hook 'LaTeX-mode-hook
          '(lambda nil
             (define-key LaTeX-mode-map "\M-c\M-d" 'guillaume-pdf)))


(add-hook 'LaTeX-mode-hook
'(lambda ()
(load "~/emacs/latex-tempo")))






;;;;;;;;;;; ;;;;Metapost; ;;;;;;;;; ;;;;;;;;
(autoload 'metafont-mode "meta-mode" "Metafont editing mode." t)
(autoload 'metapost-mode "meta-mode" "MetaPost editing mode." t)

(setq auto-mode-alist
(append '(("\\.mf\\' " . metafont-mode)
("\\.mp\\'" . metapost-mode) ) auto-mode-alist) )

(add-hook 'metapost-mode-hook
'(lambda ()
(load "meta")))

;; (defvar guillaume-mpost-command "mpost  %s")

;; (defun guillaume-mpost () (interactive)
;;    (save-buffer)
;;    (shell-command (format guillaume-mpost-command buffer-file-name))
;;    )
;; (add-hook 'meta-mode-hook
;; 	  '(lambda nil
;; 	     (define-key meta-mode-map "\M-c\M-m" 'guillaume-mpost)))

;;;;;;;;;;;;;  TEMPO de Philippe ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;(setq-default abbrev-mode t) ;; enable abbreviations
;; save abbreviations upon exiting emacs whithout confirmation

;(global-set-key (kbd "M-SPC") 'expand-abbrev)


 (add-hook 'LaTeX-mode-hook
   (function
    (lambda ()
     (define-key LaTeX-mode-map [C-M-right] 'tempo-forward-mark)
     (define-key LaTeX-mode-map [C-M-left]  'tempo-backward-mark)
     (define-key LaTeX-mode-map [f3] 'tempo-complete-tag))))




;; (setq save-abbrevs 'silently)
;; (setq abbrev-file-name (expand-file-name "pi-tempo-abbrev"))
;; (if (file-readable-p abbrev-file-name) ;; read the abbreviations every
;;     (read-abbrev-file abbrev-file-name)) ;; time emacs is started
;; ;; Combine tempo et abbrev
;; (require 'pi-tempo-abbrev)
;; ;; Ajouter/modifier des tag dans les fichiers pi-tempo-abbrev-UN_NOM.el
;; ;; Voir le manuel de tempo: http://www.lysator.liu.se/~davidk/elisp/tempo.texi
;; ;; La valeur par défaut de `tempo-insert-region' pose des pb chez moi
;; (setq-default tempo-insert-region nil)
;; (load "pi-tempo-abbrev-latex");; Essayer dans un buffer LaTeX-mode enu<SPACE>.
;; (load "pi-tempo-abbrev-meta");; en metapost-mode, pre<space>
;; ;(load "pi-tempo-abbrev-lisp");; defun <space>...
;; ;(load "pi-tempo-abbrev-asy") 


(setq load-path (append load-path (list "~/emacs")))
(autoload 'metafont-mode "meta-mode" "Metafont editing mode." t)
(autoload 'metapost-mode "meta-mode" "MetaPost editing mode." t)
(setq auto-mode-alist
      (append '(("\\.mf\\'" . metafont-mode)
                ("\\.mp\\'" . metapost-mode)) auto-mode-alist))
(require 'tex-site)

(setq-default abbrev-mode t)
(require 'pi-tempo-abbrev)
(setq tempo-interactive t)
(setq-default tempo-insert-region nil)
;; (load "pi-tempo-abbrev-latex")
(load "pi-tempo-abbrev-meta")
(global-set-key (kbd "<f3>") 'tempo-complete-tag)