;; -*- Mode: Emacs-Lisp -*-
;; Time-stamp: <1999-09-17 16:34:03 hindy>
;; Fichier .emacs que j'utilise avec emacs 20.4 sur un kernel 2.2.10
;; avec une redhat 5.2. J'espere que les commentaires vous aideront et
;; a apprecier emacs.
;; une version html est aussi dispo a l'url http://netweb.org/hindy/

(if (file-exists-p "/bin/bash")
        (setq explicit-shell-file-name "/bin/bash"))

;; maintenant on ne veut plus la bar de menu
(menu-bar-mode nil)
;; pour la faire revenir M-x menu-bar-mode :)

;;bon la on a pas mal galerer mais bon c'est tellement
;;pratique. L'auto insert permet d'inserer selon l'extension d'un
;;fichier un contenu de fichier statique.
(add-hook 'find-file-hooks 'auto-insert)
(setq auto-insert-directory (expand-file-name "~/.autoinsert/"))
(auto-insert-mode 1)
(define-auto-insert "\\.tex\\'" "autoinsert.tex")

;; on en a marre d'ecrire yes, ou no en entier. Un y ou un n suffit
;; now.
(fset 'yes-or-no-p 'y-or-n-p)

(setq-default shell-cd-regexp nil)
(setq-default shell-pushd-regexp nil)
(setq-default shell-popd-regexp nil)

;; j'utilise rcs qui me permet de faire des versions sur certains
;; documents. 
(setq vc-default-back-end 'RCS)

(add-to-list 'load-path "/home/hindy/.elisp/") ;; autre endroit pour
                                               ;; chercher des
                                               ;; fichiers.  pensez a
                                               ;; le renommer ou a
                                               ;; l'enlever

(display-time)                     ;; Pour avoir l'heure dans la barre d'etat
(setq display-time-24hr-format t)  ;; Format 24 heures
(custom-set-faces)

;; La barre de titre selon le model fichier @ host
;;(setq frame-title-format "%b")
;;(multiple-frames "%b" ("" invocation-name "@" system-name))

;; pour ouvrir les fichiers compressés
(auto-compression-mode 1)

;; pour ne pas affichier les passwd, ne semble pas obligatoire avec
;; emacs 20.3 et au dessus
(add-hook `comint-output-filter-functions
	  `comint-watch-for-password-prompt)

;; mon email etc
(setq user-full-name "Soliman Hindy")
(setq mail-host-address "wanadoo.fr")
(setq mail-archive-file-name "~/News/outbox")
(custom-set-variables
 '(mark-holidays-in-calendar t)
 '(ps-paper-type (quote a4) t)
 '(all-christian-calendar-holidays t)
 '(query-user-mail-address nil)
 '(user-mail-address "soliman.hindy@wanadoo.fr")
 '(message-default-headers hindy::message-default-headers))

;; Les en-tetes par defaut pour les messages sortants:
(setq hindy::message-default-headers "Mail-Copies-To: never\nOrganization: Linux Home")
(custom-set-variables
 '(message-default-headers hindy::message-default-headers))

;; 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-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")
(setq gnus-startup-hook 'bbdb-insinuate-gnus)
(setq bbdb-send-mail-style 'message)

;; La suite de la configurations nous vient de Nat, c'est une
;; configuration parmis tant d'autres, mais un tres bon exemple.

(global-set-key (read-kbd-macro "C-<f5>") 'bbdb-create)
(global-set-key (read-kbd-macro "S-<f5>") 'bbdb)

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

;;les beeps enervants d'emacs sont desactives le "t" signifiant "true"
(setq visible-bell t)

;; pour utiliser le format européen pour la calendrier.
(setq european-calendar-style 't)
;; on va dire que les semaines commencent le lundi, et non le
;; dimanche.
(setq calendar--week--start--day 1)

;; Accents...
(standard-display-european t)
(iso-accents-mode t)
(require 'iso-insert)
(set-language-environment 'latin-1)
(set-input-mode (car (current-input-mode)) (nth 1 (current-input-mode)) 0)

(setq line-number-mode t)
(setq column-number-mode t)

;; un peu de couleur :)
(set-face-foreground 'highlight    "yellow")
(set-face-background 'modeline     "lightblue")       ; Ligne en bas du tampon

;; font-lock pour tous les modes majeurs
(global-font-lock-mode 1)

;; highlight a region under X.
(transient-mark-mode t)

;; pour emacs 20.3 il semblerait qu'on utilise celui la pour virer
;; tout lors d'une selection par C-SPC.
(delete-selection-mode t)

;; Automatically turn on auto-fill-mode when editing text files
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;; Auto-fill in all major modes
(setq-default auto-fill-function 'do-auto-fill)
;; on se met en mode Text pour une grande partie des fichiers.
(setq default-major-mode 'text-mode)

;; config html-helper-mode:
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
(setq html-helper-do-write-file-hooks t
      html-helper-build-new-buffer t)
(add-hook 'html-helper-load-hook '(lambda () (require 'html-font)))
(add-hook 'html-helper-mode-hook '(lambda () (font-lock-mode 1)))
;; end cfg html-helper-mode

;; datation automatique lors de l'enregistrement d'un fichier HTML
(setq html-helper-do-write-file-hooks t)
(setq html-helper-build-new-buffer t)
(setq tempo-interactive t)
(setq html-helper-never-indent 't)

;; association des fichiers html au mode html
(setcdr (assoc "\\.s?html?\\'" auto-mode-alist) 'html-helper-mode)

;; de la couleur en mode html !
(require 'font-lock)
(font-lock-mode 1)
      (setq font-lock-maximum-decoration 't
         font-lock-background-mode 'light)  ;; ou "dark", selon couleur de fond
      (setq font-lock-face-attributes
         '((font-lock-comment-face "Red4")
         (font-lock-string-face "Green4")
         (font-lock-keyword-face "Orange4")
         (font-lock-function-name-face "Blue4")
         (font-lock-variable-name-face "Blue2")
         (font-lock-type-face "Wheat")
         (font-lock-reference-face "VioletRed4")
         (message-cited-text-face "Blue1")
         (message-header-name-face "Green3")))

;; et on poursuit, vive le lisp
(global-set-key (read-kbd-macro "<f12>") 'font-lock-mode)
(global-set-key (read-kbd-macro "S-<f12>") 'show_face_on_point_name)
;; explication, si on appuie sur F12 ca fontify le buffer ou
;; l'inverse, agit comme une bascule.

;;on utilise fetchmail a partir d'emacs sans lancer un shell. C'est
;;tres pratique comme commande.
(defun check-mail ()
  "Check new mail, popup exit message."
  (interactive)
  (set-process-sentinel 
   (start-process "fetchmail" nil "fetchmail")
   (lambda (process change)
     (message (concat "fetchmail " change))
     (sit-for 1))))

;; qd vous recevez un fichier .txt d'une machine dos/windows il est
;; tres enevervant de voir les ^M a chaque fin de ligne, utiliser M-x
;; dos2unix pour vous en debarrasser.
;; dos2unix
(defun dos-unix ()
  (interactive)
    (goto-char (point-min))
      (while (search-forward "\r" nil t) (replace-match "")))

;; c l'inverse du precedent.
;; unix2dos
(defun unix-dos ()
  (interactive)
    (goto-char (point-min))
      (while (search-forward "\n" nil t) (replace-match "\r\n")))

;; Caractères 8 bit en sgml sous emacs...
       (setq sgml-mode-hook
       '(lambda () "Defauts pour le mode SGML."
       (load-library "iso-sgml")))


;; Mode sgml.
(setq auto-mode-alist
      (append '(("\.sgml$"  . sgml-mode))
                auto-mode-alist))

;; essai supplémentaire.
(setq auto-mode-alist
      (cons '("\\.sgml$" . sgml-mode)  auto-mode-alist))

;; Mode psgml.
(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/psgml")
(autoload 'sgml-mode "psgml" "Mode majeur SGML." t)
(setq sgml-validate-command "nsgmls -s %s %s"
          sgml-trace-entity-lookup t
          sgml-set-face t
          sgml-live-element-indicator t
          sgml-indent-data t
          sgml-indent-step 1)

;; 80 carac par lignes...
(setq sgml-mode-hook
       '(lambda () "Defauts pour le mode SGML."
       (auto-fill-mode)
       (setq fill-column 80)))


;; Le Mode SGML...
;; grande premiere
(defun insert-sgml-header ()
  "Insere l'entete d'un document LinuxDoc"
  (interactive)
  (let (titre auteur email home traducteur email-traducteur home-traducteur date
              point-debut)
    (setq titre (read-from-minibuffer "Titre : "))
    (if (> (length titre) 0)
        (progn
          (setq date (read-from-minibuffer "Date : ")
                auteur (read-from-minibuffer "Auteur : ")
                email (read-from-minibuffer "Email auteur : ")
                home (read-from-minibuffer "Home page auteur : http://")
                traducteur (read-from-minibuffer "Traducteur : "))
          (insert "<!doctype linuxdoc system>\n<article>\n<title>")
          (insert titre)
          (insert "</title>\n<author>\nAuteur : ") (insert auteur) (insert "<newline>\n")
          (if (> (length email) 0)
              (progn
                (insert "<htmlurl url=\"mailto:")
                (insert email) (insert "\" name=\"") (insert email)
                (insert "\"><newline>\n")))
          (if (> (length home) 0)
              (progn
                (insert "<htmlurl url=\"http://")
                (insert home) (insert "\" name=\"") (insert home)
                (insert "\">\n<newline>")))
          (if (> (length traducteur) 0)
              (progn
                (setq email-traducteur (read-from-minibuffer "Email traducteur : ")
                      home-traducteur (read-from-minibuffer "Home page traducteur : http://"))
                (insert "Traducteur : ")
                (insert traducteur)
                (insert "<newline>\n")
                (if (> (length email-traducteur) 0)
                    (progn
                      (insert "<htmlurl url=\"mailto:")
                      (insert email-traducteur) (insert "\" name=\"")
                      (insert email-traducteur)
                      (insert "\"><newline>\n")))
                (if (> (length home-traducteur) 0)
                    (progn
                      (insert "<htmlurl url=\"http://")
                      (insert home-traducteur) (insert "\" name=\"")
                      (insert home-traducteur)
                      (insert "\"><newline>\n")))))
          (insert "</author>\n<date>\n")
          (insert date)
          (insert "</date>\n\n<abstract>\n")
          (setq point-debut (point))
          (insert "</abstract>\n<toc>\n\n<sect>\n<p>\n\n\n</sect>\n\n</article>\n")
          (goto-char point-debut)
          ))))

(setq minibuffer-max-depth nil)

;; de la couleur en mode psgml
(setq sgml-set-face t)
(make-face 'sgml-comment-face)
(make-face 'sgml-doctype-face)
(make-face 'sgml-end-tag-face)
(make-face 'sgml-entity-face)
(make-face 'sgml-ignored-face)
(make-face 'sgml-ms-end-face)
(make-face 'sgml-ms-start-face)
(make-face 'sgml-pi-face)
(make-face 'sgml-sgml-face)
(make-face 'sgml-short-ref-face)
(make-face 'sgml-start-tag-face)

(set-face-foreground 'sgml-comment-face "dark green")
(set-face-foreground 'sgml-doctype-face "maroon")
(set-face-foreground 'sgml-end-tag-face "blue2")
(set-face-foreground 'sgml-entity-face "red2")
(set-face-foreground 'sgml-ignored-face "maroon")
(set-face-background 'sgml-ignored-face "gray90")
(set-face-foreground 'sgml-ms-end-face "maroon")
(set-face-foreground 'sgml-ms-start-face "maroon")
(set-face-foreground 'sgml-pi-face "maroon")
(set-face-foreground 'sgml-sgml-face "maroon")
(set-face-foreground 'sgml-short-ref-face "goldenrod")
(set-face-foreground 'sgml-start-tag-face "blue2")

(setq-default sgml-markup-faces
   '((comment . sgml-comment-face)
     (doctype . sgml-doctype-face)
     (end-tag . sgml-end-tag-face)
     (entity . sgml-entity-face)
     (ignored . sgml-ignored-face)
     (ms-end . sgml-ms-end-face)
     (ms-start . sgml-ms-start-face)
     (pi . sgml-pi-face)
     (sgml . sgml-sgml-face)
     (short-ref . sgml-short-ref-face)
     (start-tag . sgml-start-tag-face)))

;; ispell
(autoload 'ispell-word "ispell" "Check the spelling of word in buffer." 't)
(autoload 'ispell-region "ispell" "Check the spelling of region." 't)
(autoload 'ispell-buffer "ispell" "Check the spelling of buffer." t)
(global-set-key (read-kbd-macro "M-$") 'ispell-word)
(setq ispell-dictionary "francais"
     ispell-skip-sgml t)
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checking" t)
(setq flyspell-default-dictionary "francais")

;; Mailcrypt je sais pas si ca va fonctionner
;; fait pour utiliser gnupg.
(load-library "mailcrypt")
(mc-setversion "gpg")
(autoload 'mc-install-write-mode "mailcrypt" nil t)
(autoload 'mc-install-read-mode "mailcrypt" nil t)
(add-hook 'mail-mode-hook 'mc-install-write-mode)
(add-hook 'gnus-summary-mode-hook 'mc-install-read-mode)
(add-hook 'message-mode-hook 'mc-install-write-mode)
(add-hook 'news-reply-mode-hook 'mc-install-write-mode)
;; note si ca marche c cool...

;; TeX & LaTeX...
(setq auto-mode-alist (cons '("\\.tex$" . latex-mode) auto-mode-alist))
(setq tex-dvi-view-command "xdvi")
(setq tex-show-queue-command "lpstat -O")
(setq tex-dvi-print-command "dvips")
(setq tex-alt-dvi-print-command 
      '(format "dvips * -o %s" (read-string "Name of postscript file:")))

;; Time-stamp quelle galere a faire fonctionner mais que c cool.
;; explication dans un fichier pour garder la derniere date de
;; modification on dispose bien entendu de la commande ls -l du shell
;; unix. Dans votre fichier mettez ceci Time-stamp <> et entre les
;; crochets lors de votre enregistrement des informations seront mise
;; entre les crochets.
(defun insert-date ()
"Insert date at point."
(interactive)
(insert (format-time-string "%a %b %e, %Y %l:%M %p")))
(global-set-key [f3] 'insert-date)
(add-hook 'write-file-hooks 'time-stamp)
(setq time-stamp-active t)

;; a la fin de chaque fichier une ligne blanche est ajoutee.
;;(setq require-final-newline t)
;; peut etre pas si bien que cela, on le met de cote pour le moment.

;; dans mes test j'ai vu speedbar c genial ;)

;; recentf, pour ouvrir les files recents simplement.
;; on le trouve ici http://perso.wanadoo.fr/david.ponce/more-elisp.html
(require 'recentf)
(setq recentf-max-menu-items 21)
;; tres sympa

;;test pour htmlize...
;; on peut le trouver ici http://jagor.srce.hr/~hniksic/htmlize.el
(require 'htmlize)

;;; 1999-07-12 Noah Friedman <friedman@splode.com>
;;; pour mettre un chmod +x si on trouve #! qqch :))
(defun make-buffer-file-executable-if-script-p ()
  "Make file executable according to umask if not already executable.
If file already has any execute bits set at all, do not change existing
file modes."
  (and (save-excursion
         (save-restriction
           (widen)
           (goto-char (point-min))
           (save-match-data
             (looking-at "^#!"))))
       (let* ((current-mode (file-modes (buffer-file-name)))
              (add-mode (logand ?\111 (default-file-modes))))
         (or (/= (logand ?\111 current-mode) 0)
             (zerop add-mode)
             (set-file-modes (buffer-file-name)
                             (logior current-mode add-mode))))))

(add-hook 'after-save-hook 'make-buffer-file-executable-if-script-p)

;;emacs-name trop fort :)
(require 'emacs-name)

;;mode ssh a partir d'emacs
(require 'ssh)

(autoload 'rpm "rpm"
     "Shell for the rpm package management utility." t)
(autoload 'rpm-dired-install "rpm"
     "Install all marked (or next ARG) rpm-files." t)
(add-hook 'dired-load-hook
 '(lambda () (define-key dired-mode-map "I"
	'rpm-dired-install)))

;; on definit mes raccourcis claviers.
(global-set-key "\C-xp" 'ps-print-buffer)

;;de la couleur pour le mode info
;; (from Andy.Ling@quantel.com)
(defvar info-font-lock-keywords
  (list
   '("^\\* [^:]+:+" . font-lock-function-name-face)
   '("\\*[Nn]ote\\b[^:]+:+" . font-lock-reference-face)
   '("  \\(Next\\|Prev\\|Up\\):" . font-lock-reference-face))
  "Additional expressions to highlight in Info mode")

(add-hook 'Info-mode-hook
          (lambda ()
            (make-local-variable 'font-lock-defaults)
            (setq font-lock-defaults '(info-font-lock-keywords nil t))))

;; jouer des mp3 avec emacs, oui c'est possible.
;; note mpg123 est requis.
(defun mp3-feel ()
  "Dired mp3 feel directory."
  (interactive)
  (dired "~/mp3"))

; (defmacro mp3 (filename)
;   "mpg123 mp3 FILENAME."
;   `(lambda () (interactive)
;      (shell-command (format "mpg123 %s &" ,filename))))

(defun mp3 ()
  "mpg123 mp3 FILENAME."
     (shell-command (format "mpg123 %s &")))




