(setq load-path (append load-path (list "~/emacs" "~/mupacs-3.2.3"
 )))
;;; -*-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))


;;asymptote

(autoload 'asy-mode "/usr/local/share/asymptote/asy-mode.el" "Asymptote major mode." t)
(autoload 'lasy-mode "/usr/local/share/asymptote/asy-mode.el" "hybrid Asymptote/Latex major mode." t)
(autoload 'asy-insinuate-latex "/usr/local/share/asymptote/asy-mode.el" "Asymptote insinuate LaTeX." t)
(add-to-list 'auto-mode-alist '("\\.asy$" . asy-mode))
;;(setq ps-view-command "evince")

;;encodage








;; Encodage en utf-8
; (prefer-coding-system 'iso-8859-1)
; (set-terminal-coding-system 'iso-8859-1)  ; pour l'affichage
;; (set-keyboard-coding-system 'utf-8)  ; pour la saisie (eventuelement)> 



(set-terminal-coding-system 'latin-9)
(set-keyboard-coding-system 'latin-9)
(set-language-environment 'latin-9)
;; Pour que les copier/coller vers Emacs fonctionnent bien, même avec
;; des accents en latin9
(setq selection-coding-system 'compound-text-with-extensions)

;;(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)
 

;; pour naviguer sur les buffers

(iswitchb-mode t)



;;Inhiber l'affichage du message d'accueil
(setq inhibit-startup-message t       ;Emacs
          gnus-inhibit-startup-message t) ;Gnus

;; beep visuel
(setq visible-bell t)

;; curseur en barre et non clignotant
;;(setq cursor-type 'bar) -> default-frame-alist
;(blink-cursor-mode 0)
;;(set-cursor-color "black")

;; Ne pas utiliser de boîte de dialogue mais le minibuffer pour poser une question
;; (les dialogues marchent mal sous OSX pour choisir un fichier inexistant)
(setq use-dialog-box nil
      use-file-dialog nil)


;; Laisser le curseur en place lors d'un défilement par pages.
;; Par défaut, Emacs place le curseur en début ou fin d'écran
;; selon le sens du défilement.
(setq scroll-preserve-screen-position t)

;; Faire apparaître la position du curseur dans la ligne modale
(setq column-number-mode t)
(setq line-number-mode t)


;;Changement de fenetre moins fatigant que Ctrl-x o (EmacsFR)
(global-set-key [(control tab)] `other-window)
;(global-set-key [C-S-iso-lefttab] '(lambda () (interactive) (other-window -1)))

;; Changement de frame avec C-S-Tab en plus de C-x 5 o
(global-set-key [(control meta tab)] `other-frame)
;(global-set-key [C-M-S-iso-lefttab] '(lambda () (interactive) (other-frame -1)))

;; Changement de buffer C-x b amélioré
;(iswitchb-mode)
(when (require 'ido nil t)
  (ido-mode t))


;; Colorisation syntaxique maximale dans tous les modes
;; Avec emacs 21, la colorisation est disponible en mode texte. Cool !
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)

;; Montrer la correspondance des parenthèses
;; (systématiquement et non seulement après la frappe)
(when (require 'paren)
  (show-paren-mode t)
  (setq blink-matching-paren t)
  (setq blink-matching-paren-on-screen t)
  (setq show-paren-style 'parenthesis)
  ;;(setq show-paren-style 'expression)
  (setq blink-matching-paren-dont-ignore-comments t))

;; (dé)compression automatique des fichiers lus et écrits
(auto-compression-mode t); nil (jka-compr))









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



(global-font-lock-mode t) ;pour avoir les couleurs sans avoir a taper font-lock-mode

   (setq font-lock-maximum-decoration t) ;maximum de couleurs

   (setq font-lock-maximum-size nil)

   (transient-mark-mode t) ;pour que la region selectionnee soit mise en surbrillance

   (setq compilation-window-height 5) ;pour que la fenetre de compilation ne soit pas trop grande

   (standard-display-european 1)   ;pour avoir les accents

   (setq ispell-dictionary "francais") ;dictionnaire francais par defaut

;; ***************************************************************
;; Misc useful functions
;; ***************************************************************

(defun jdz-to-first-non-space ()
  "Move point to first non-blank character on the current line. Sort of like 'w' does in vi."
  (interactive)
  (beginning-of-line 1)
  (skip-chars-forward " \t"))

(global-set-key "\C-cw" 'jdz-to-first-non-space)
;;(global-set-key "\C-A" 'jdz-to-first-non-space)

(defun jdz-buffer-switch ()
  "Switches buffers."
  (interactive)
  (switch-to-buffer (other-buffer)))

(global-set-key "\C-q" 'jdz-buffer-switch)

(defun jdz-frame-switch ()
  "Switches buffers."
  (interactive)
  (other-frame 1))

(global-set-key "\C-Q" 'jdz-frame-switch)




 
;;; 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-frame-alist
      '((foreground-color."yellow"))
      )


(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)


;;;php
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)

(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.php$" . html-helper-mode) auto-mode-alist))



;;;
;;; 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 62               ; petite hauteur du frame emacs
       largeur-normale 118
      ;; gestions des fenêtres -- fonte 9x15, X 1024*768
       largeur-ecran 183
       hauteur-ecran 83
       )

;;; 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

      ; Utilisation de w3m-emacs
      ; il faut que le programme w3m soit installé
      (autoload 'w3m "w3m" "Interface for w3m on Emacs." t)

    (add-to-list 'load-path "/usr/share/emacs21/site-lisp/w3")
    (require 'w3-auto "w3-auto")

    (autoload 'w3-preview-this-buffer "w3" "WWW Previewer" 't)
    (autoload 'w3 "w3" "WWW Browser" 't)
    (autoload 'w3-open-local "w3" "Open local file for WWW browsing" 't)
    (autoload 'w3-fetch "w3" "Open remote file for WWW browsing" 't)
    (autoload 'w3-use-hotlist "w3" "Use shortcuts to view WWW docs" 't)
   ; (autoload 'w3-
    (setq-default w3-do-incremental-display t
                  url-be-asynchronous t)
;; (setq w3-use-netscape-configuration-file t
;; w3-netscape-configuration-file
;; "/where/the/file/is/.netscape-preferences")
    (setq url-using-proxy t
;          w3-hotlist-file (expand-file-name "~/.netscape/bookmarks.html")
         ; browse-url-browser-function 'browse-url-netscape
         ; url-proxy-services
          ;'(("ftp" . "localhost:8080")
           ; ("http" . "localhost:8080")
            ;("gopher" . "localhost:8080")
           ; ("no_proxy" . "localhost"))
          url-confirmation-func 'y-or-n-p
          w3-default-homepage "http://gconnan.free.fr/"
          ;w3-default-homepage "une-URL"                       MODIFIER CECI
          ;url-pgp/pem-entity "mon-adresse@mon-domaine"        MODIFIER CECI
          url-personal-mail-address "gconnan@free.fr" ;MODIFIER CECI
          url-xterm-command "nxterm -title %s -ut -e %s %s %s"
          w3-delimit-links t
          url-confirmation-func 'y-or-n-p
          w3-show-status t
;         w3-debug-html t
          url-show-status t
          url-keep-history t
          )
(global-set-key [(super w)] 'w3-follow-url-at-point)

      ;(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 . "orange")
               (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)))

;;; Tools

(defvar scissors "8<------"
  "string to insert in \\[scissors]")

(defun scissors ()
  "Insert a line of SCISSORS in the buffer"
  (interactive)
  (or (bolp) (beginning-of-line 2))
  (while (<= (current-column) (- (or fill-column 70) (length scissors)))
    (insert scissors))
  (newline))


 (global-set-key [C-c C-z] 'scissors)


(require 'scrmable)
 

;;(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)))




;;mupacs



(autoload 'mupad-run      "mupad-run.el" "To start a MuPAD session" t)
;;y(add-hook 'mupad-run-mode-hook 'mupad-bus-adapt-textwidth)

;; 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 ""))))

;; 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 [(super c) (super l)] '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 [(super c) (super 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 [(super c) (super 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 [(super c) (super d)] 'guillaume-pdf)))


(defvar guillaume-livreta5-command
  "psbook %s.ps | psnup -2 | pstops -p a4 2:0,1U\\(1w,1h\\) > %s_livret_a5.ps | ps2pdf %s_livret_a5.ps")

(defun guillaume-livreta5 ()
  (interactive)
  (save-buffer)
  (let ((fnse (file-name-sans-extension (buffer-file-name))))
    (shell-command (format
                    guillaume-livreta5-command
                    fnse fnse fnse))))
(add-hook 'LaTeX-mode-hook
          '(lambda nil
             (define-key LaTeX-mode-map [(super c) (super s)] 'guillaume-livreta5)))




(defvar guillaume-livreta4-command "psbook %s.ps | psnup -p a3 -P a4 -2 pstops -p a4 2:0,1U\\(1w,1h\\) >  %s_livret_a4.ps")

(defun guillaume-livreta4 () (interactive)
   (save-buffer)
 (let ((fnse (file-name-sans-extension (buffer-file-name))))
    (shell-command (format
                    guillaume-livreta4-command
                    fnse fnse))))
(add-hook 'LaTeX-mode-hook
          '(lambda nil
             (define-key LaTeX-mode-map [(super c) (super S)] 'guillaume-livreta4)))






(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)
(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.
 '(LaTeX-verbatim-environments (quote ("verbatim" "verbatim*" "lstlisting" "boxedverbatim")))
 '(auto-compression-mode t nil (jka-compr))
 '(backup-by-copying t)
 '(canlock-password "133aadb960dace95c22833969aae1d7433b437f2")
 '(case-fold-search t)
 '(current-language-environment "latin-9")
 '(default-input-method "latin-9-prefix")
 '(delete-old-versions nil)
 '(display-time-24hr-format t)
 '(face-font-family-alternatives (quote (("helvetica" "fixed") ("helv" "helvetica" "arial" "fixed"))))
 '(global-font-lock-mode t nil (font-lock))
 '(kept-new-versions 1)
 '(mail-yank-prefix "> ")
 '(message-directory "~/.Mail/")
 '(mm-discouraged-alternatives (quote ("(\"text/html\" \"text/richtext\")")))
 '(pdf-view-command "evince")
 '(ps-view-command "evince")
 '(read-mail-command (quote gnus))
 '(show-paren-mode t nil (paren))
 '(speedbar-frame-parameters (quote ((minibuffer) (width . 20) (border-width . 0) (menu-bar-lines . 0) (tool-bar-lines . 0) (unsplittable . t) (set-background-color "black"))))
 '(transient-mark-mode t)
 '(uniquify-buffer-name-style (quote post-forward-angle-brackets) nil (uniquify)))







;; pour selectionner copier coller

(load-library "pc-mode")
(pc-selection-mode)


(define-key global-map [(meta w)] 'kill-ring-save)
(define-key global-map [(control w)] 'kill-region)
(define-key global-map [(control y)] 'yank)


;;; 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))








;;; GNUS

;; Definit Gnus comme lecteur courriel
 
 ;; Definit Gnus comme lecteur courriel
 
 ;; Definit Galeon comme brouteur web, pour suivre les liens
 (setq browse-url-browser-function 'browse-url-generic
       browse-url-generic-program "firefox")



(setq
 mail-header-separator "=== le texte du message suit cette ligne ==="
 mail-self-blind t
 mail-signature t
 mail-yank-prefix "> ")



(setq gnus-posting-styles
              '((".*"
                 (signature-file "~/.signature")
                 (name "Guillaume Connan")
                 ("X-Home-Page" (getenv "WWW_HOME")))))
;;;              (organization "People's Front Against MWM"))
;;;             ("^rec.humor"
;;;              (signature my-funny-signature-randomizer))
;;;             ((equal (system-name) "gnarly")
;;;              (signature my-quote-randomizer))
;;;             ((message-news-p)
;;;              (signature my-news-signature))
;;;             (header "From\\|To" "larsi.*org"
;;;                     (Organization "Somewhere, Inc."))
;;;             ((posting-from-work-p)
;;;              (signature-file "~/.work-signature")
;;;              (address "user@bar.foo")
;;;              (body "You are fired.\n\nSincerely, your boss.")
;;;              (organization "Important Work, Inc"))
;;;             ("nnml:.*"
;;;              (From (save-excursion
;;;                      (set-buffer gnus-article-buffer)
;;;                      (message-fetch-field "to"))))
;;;             ("^nn.+:"
;;;              (signature-file "~/.mail-signature"))))


;; bbdb
(require 'bbdb)
(bbdb-initialize)
(autoload 'bbdb/gnus-lines-and-from "bbdb-gnus")
(setq gnus-optional-headers 'bbdb/gnus-lines-and-from)
(autoload 'bbdb         "bbdb-com" "Insidious Big Brother Database" t)
(autoload 'bbdb-name    "bbdb-com" "Insidious Big Brother Database" t)
(autoload 'bbdb-company "bbdb-com" "Insidious Big Brother Database" t)
(autoload 'bbdb-net     "bbdb-com" "Insidious Big Brother Database" t)
(autoload 'bbdb-notes   "bbdb-com" "Insidious Big Brother Database" t)
(autoload 'bbdb-insinuate-vm       "bbdb-vm"    "Hook BBDB into VM")
(autoload 'bbdb-insinuate-rmail    "bbdb-rmail" "Hook BBDB into RMAIL")
(autoload 'bbdb-insinuate-mh       "bbdb-mhe"   "Hook BBDB into MH-E")
(autoload 'bbdb-insinuate-gnus     "bbdb-gnus"  "Hook BBDB into GNUS")
(autoload 'bbdb-insinuate-sendmail "bbdb"       "Hook BBDB into sendmail")
(add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
(setq bbdb-send-mail-style 'message)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Configuration du Big Brother Insidious   ;;
;;         Database (base d'adresse)          ;;
;; (pour utiliser bbdb il faut le recuperer    ;;
;; sur internet car il n'y est pas                ;; 
;;          par defaut                                 ;;
;; une bonne partie de la config permet    ;;
;; d'utiliser bbdb comme mail-alias          ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;(add-hook 'mail-setup-hook 'mail-abbrevs-setup)
;;(add-hook 'mail-setup-hook 'bbdb-insinuate-sendmail)
;;(add-hook 'mail-setup-hook 'bbdb-define-all-aliases)
;;(add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)

(defun bbdb-insinuate-message ()
  (define-key message-mode-map "\S-n" 'bbdb-complete-name))
(add-hook 'message-mode-hook 'bbdb-insinuate-message)
(setq bbdb-north-american-phone-numbers-p 'nil)
   (autoload 'bbdb-define-all-aliases
       "bbdb-com" "Hook mail alias feature of BBDB into message-mode." t)
     (add-hook 'message-setup-hook 'bbdb-define-all-aliases)
     (add-hook 'message-mode-hook 'ls6-message-mode-hook-mail-aliases)
     (defun ls6-message-mode-hook-mail-aliases ()
      (define-key message-mode-map (kbd "C-c C-a")
       'mail-interactive-insert-alias))


;; ca c'est pour que bbdb remplisse tout seul ma base d'adresse.
(setq bbdb/news-auto-create-p t)









;; La suite de la configurations nous vient de Nat, c'est une
;; configuration parmis tant d'autres, mais un tres bon exemple.
;; par defaut bbdb est configure pour accepter les numeros de
;; telephone au format americain ici on desactive cette option
(setq bbdb-north-american-phone-numbers-p nil)
;; permet d'eviter d'avoir une fenetre bbdb qui montre en permanence
;; les mises a jour dans bbdb lorsque l'on utilise VM, MH, RMAIL ou
;; GNUS
(setq bbdb-use-pop-up nil)
;; pas de code de localisation par defaut pour les numeros de
;; telephone 
(setq bbdb-default-area-code nil)
;; permet d'empecher a bbdb de creer une nouvelle entree a chaque fois
;; qu'un mail d'une nouvelle personne est lu avec GNUS, RMAIL, VM ou
;; MH. 
(setq bbdb/mail-auto-create-p t)
;; nombre de lignes desire dans la fenetre popup de bbdb lorsque l'on
;; utilise VM/MH/RMAIL ou GNUS.
(setq bbdb-pop-up-target-lines 7)
(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.
 '(default ((t (:stipple nil :background "black" :foreground "wheat" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 165 :width normal :family "terminal"))))
 '(background "blue")
 '(fixed-pitch ((t (:family "terminal"))))
 '(font-latex-math-face ((((class color) (background dark)) (:foreground "orange"))))
 '(font-latex-verbatim-face ((((class color) (background dark)) (:inherit fixed-pitch :foreground "red" :inverse-video unspecified))))
 '(font-lock-builtin-face ((((class color) (background dark)) (:foreground "Turquoise"))))
;; '(font-lock-comment-face ((t (:foreground "MediumAquamarine"))))
 '(font-lock-constant-face ((((class color) (background dark)) (:bold t :foreground "DarkOrchid"))))
 '(font-lock-doc-string-face ((t (:foreground "green2"))))
 '(font-lock-function-name-face ((t (:foreground "SkyBlue"))))
 '(font-lock-keyword-face ((t (:bold t :foreground "CornflowerBlue"))))
 '(font-lock-preprocessor-face ((t (:italic nil :foreground "CornFlowerBlue"))))
 '(font-lock-reference-face ((t (:foreground "DodgerBlue"))))
 '(font-lock-string-face ((t (:foreground "LimeGreen"))))
 '(font-lock-type-face ((t (:foreground "#9290ff"))))
 '(font-lock-variable-name-face ((t (:foreground "PaleGreen"))))
 '(font-lock-warning-face ((((class color) (background dark)) (:foreground "yellow" :background "red"))))
 '(header-line ((((class color grayscale) (background dark)) (:inherit mode-line :background "grey20" :foreground "grey90" :box nil :family "terminal"))))
 '(highlight ((t (:background "orangered"))))
 '(list-mode-item-selected ((t (:background "gold"))))
 '(makefile-space-face ((t (:background "wheat"))))
 '(mode-line ((t (:background "Brown" :foreground "gray" :box (:line-width -1 :style released-button)))))
 '(modeline ((t (:background "Brown"))))
 '(mouse ((t (:background "grey35"))))
 '(paren-match ((t (:background "darkseagreen4"))))
 '(pi-big-font pi-small-font)
 '(pi-toggle-font pi-toggle-font)
 '(region ((t (:background "DarkSlateBlue"))))
 '(scissors scrmable)
 '(scroll-bar ((t (:background "grey45" :foreground "#00ffbf"))))
 '(show-paren-match-face ((t (:foreground "black" :background "wheat"))))
 '(show-paren-mismatch-face ((((class color)) (:foreground "white" :background "red"))))
 '(speedbar-button-face ((((class color) (background dark)) (:foreground "green4"))))
 '(speedbar-directory-face ((((class color) (background dark)) (:foreground "khaki"))))
 '(speedbar-file-face ((((class color) (background dark)) (:foreground "cyan"))))
 '(speedbar-tag-face ((((class color) (background dark)) (:foreground "Springgreen"))))
 '(textomail-region textomail-region)
 '(vhdl-speedbar-architecture-selected-face ((((class color) (background dark)) (:underline t :foreground "Blue"))))
 '(vhdl-speedbar-entity-face ((((class color) (background dark)) (:foreground "darkGreen"))))
 '(vhdl-speedbar-entity-selected-face ((((class color) (background dark)) (:underline t :foreground "darkGreen"))))
 '(vhdl-speedbar-package-face ((((class color) (background dark)) (:foreground "black"))))
 '(vhdl-speedbar-package-selected-face ((((class color) (background dark)) (:underline t :foreground "black"))))
 '(widget-field-face ((((class grayscale color) (background light)) (:background "DarkBlue")))))