;; YC, 2018 10, added cpp, tpp to C++-mode
;; YC, 2017 01 15, pour accent circomflexe qui ne fonctionne pas
;; -> dead-circumflex undefined

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)

(load-library "iso-transl")

;; Use cscope
;;(require 'xcscope)

;; 5. If you intend to use xcscope.el often you can optionally edit your
;;    ~/.emacs file to add keybindings that reduce the number of keystrokes
;;    required.  For example, the following will add "C-f#" keybindings, which
;;    are easier to type than the usual "C-c s" prefixed keybindings. Note
;;    that specifying "global-map" instead of "cscope:map" makes the
;;    keybindings available in all buffers:
;;
;;      (define-key global-map [(control f3)] 'cscope-set-initial-directory)
;;      (define-key global-map [(control f4)] 'cscope-unset-initial-directory)
;;      (define-key global-map [(control f5)]  'cscope-find-this-symbol)
;;      (define-key global-map [(control f6)] 'cscope-find-global-definition)
;;      (define-key global-map [(control f7)]
;;        'cscope-find-global-definition-no-prompting)
;;      (define-key global-map [(control f8)]  'cscope-pop-mark)
;;      (define-key global-map [(control f9)]  'cscope-next-symbol)
;;      (define-key global-map [(control f10)] 'cscope-next-file)
;;      (define-key global-map [(control f11)] 'cscope-prev-symbol)
;;      (define-key global-map [(control f12)] 'cscope-prev-file)
;;      (define-key global-map [(meta f9)]  'cscope-display-buffer)
;;      (define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)

;; Retire splash-screen
;;'(current-language-environment "UTF-8")
;;'(default-input-method "UTF-8-prefix")
;; '(current-language-environment "Latin-9")
;; '(default-input-method "latin-9-prefix")
(setq inhibit-splash-screen t)
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(auto-compression-mode t nil (jka-compr))
 '(c-font-lock-extra-types
   (quote
    ("DIR" "FILE" "gchar" "gint" "guint" "guint8" "guint32" "gboolean" "gpointer" "GList" "GSList" "xmlDocPtr" "xmlNsPtr" "xmlNodePtr" "xmlChar" "PGconn" "PGresult" "pthread_t" "\\<\\(Gdk[-.a-zA-Z0-9_]*;?\\)\\>" "\\<\\(Gtk[-.a-zA-Z0-9_]*;?\\)\\>" "\\<\\(Gnome[-.a-zA-Z0-9_]*;?\\)\\>" "\\<\\(Td_[-.a-zA-Z0-9_]*;?\\)\\>" "\\<\\(Hopla_[-.a-zA-Z0-9_]*;?\\)\\>")))
 '(case-fold-search t)
 '(current-language-environment "UTF-8")
 '(default-input-method "UTF-8-prefix")
 '(font-lock-global-modes t)
 '(global-font-lock-mode t nil (font-lock))
 '(ispell-program-name "/usr/bin/aspell")
 '(save-place t nil (saveplace))
 '(show-paren-mode t nil (paren))
 '(show-paren-style (quote parenthesis))
 '(speedbar-supported-extension-expressions
   (quote
    ("\\.vhdl?\\'" ".emacs" ".cvsignore" ".p" ".am" ".in" ".spec" ".fsfdb" "README" "AUTHORS" "NEWS" "TODO" "HACKING" "ChangeLog" ".po" ".dat" ".sgml" ".xml" ".xsl" ".dtd" ".html" ".css" ".tex" ".cls" ".c" ".h" ".cc" ".hh" ".xpm" ".png" ".jpeg" ".gif" ".toutdoux" ".hopla" ".gnumeric" ".log" ".txt" ".sh")))
 '(tool-bar-mode nil))
 '(speedbar-supported-extension-expressions (quote ("\\.vhdl?\\'" ".emacs" ".cvsignore" ".p" ".am" ".in" ".spec" ".fsfdb" "README" "AUTHORS" "NEWS" "TODO" "HACKING" "ChangeLog" ".po" ".dat" ".sgml" ".xml" ".xsl" ".dtd" ".html" ".css" ".tex" ".cls" ".c" ".cc" ".h" ".hh" ".xpm" ".png" ".jpeg" ".gif" ".toutdoux" ".hopla" ".gnumeric" ".log" ".txt" ".sh")))
 '(pc-selection-mode t nil (pc-select))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:foreground "Wheat" :background "DarkSlateGray"))))
 '(bold ((t (:foreground "LightSalmon"))))
 '(custom-saved-face ((t (:underline t :background "DarkSlateGray"))) t)
 '(custom-variable-tag-face ((t (:underline t :foreground "lightblue"))) t)
 '(font-lock-builtin-face ((t (:foreground "Pink"))))
 '(font-lock-constant-face ((t (:foreground "LightGoldenrod"))))
 '(font-lock-variable-name-face ((t (:foreground "Aquamarine"))))
 '(mode-line ((t (:inverse-video t :foreground "Tan" :background "DarkSlateGray"))))
 '(region ((t (:foreground "#102829" :background "#6a997b"))))
 '(show-paren-match ((t (:background "IndianRed"))))
 '(speedbar-button-face ((t (:foreground "Wheat"))))
 '(speedbar-directory-face ((t (:foreground "PaleGreen"))))
 '(speedbar-file-face ((t (:foreground "LightSalmon"))))
 '(speedbar-highlight-face ((t (:foreground "Wheat" :background "DarkOliveGreen"))))
 '(speedbar-selected-face ((t (:underline t :foreground "OrangeRed"))))
 '(speedbar-tag-face ((t (:foreground "LightGoldenrod"))))
 '(underline ((t (:underline t))))
 '(vc-default-back-end (quote RCS)))


(require 'paren)
 (show-paren-mode) 

;; Clavier
;(global-set-key "\C-k" 'kill-this-buffer)
(global-set-key "\C-b" 'switch-to-buffer)
(global-set-key "\M-q" 'other-window)
;;;(global-set-key "\C-0" 'delete-window)
;;;(global-set-key "\C-1" 'delete-other-windows)
;; Pour justifier a gauche (utile sous latex)
(global-set-key "\C-q" 'set-justification-left)
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m)

(global-set-key "\M-g=" 'goto-line)
;(global-set-key "\C-g" 'grep)
;(global-set-key "\C-e" 'save-buffer)
;(global-set-key "\C-g=" 'goto-line)
;(global-set-key "\C-r" 'grep)
;(global-set-key "\C-s" 'save-buffer)


;; Francais
(set-input-mode nil nil 1)
(setq ispell-dictionary "francais")

;; Mode : Tex
(global-set-key "\C-t" 'tex-buffer)
;;'(tex-dvi-view-command "xdvi" t)

;; Mode : Sgml
(require 'sgml-mode)
;;(setq sgml-indent-data t)
;;(setq sgml-set-face t)
;;(setq sgml-validate-command "nsgmls -s")
;;(setq sgml-name-8bit-mode nil)

;; Mode : C
(global-set-key "\C-z" 'compile)
(global-set-key "\C-d" 'gdb)

;; Fichier : Definition des modes
(setq auto-mode-alist
      '( 
        ("\\.java$" . java-mode)
        ("\\.txt$" . text-mode)
        ("\\.log$" . text-mode)
        ("\\.fsfdb$" . text-mode)
        ("\\README$" . text-mode)
        ("\\AUTHORS$" . text-mode)
        ("\\NEWS$" . text-mode)
        ("\\TODO$" . text-mode)
        ("\\ChangeLog$" . change-log-mode)
        ("\\.am$" . makefile-mode)
        ("\\.c$"  . c-mode) 
        ("\\.h$"  . c-mode)
        ("\\.C$"  . c++-mode) 
        ("\\.cc$" . c++-mode) 
        ("\\.cxx$" . c++-mode)
	("\\.cpp$" . c++-mode)
	("\\.tpp$" . c++-mode) 
        ("\\.hh$"  . c++-mode)
        ("\\.sgml$" . sgml-mode)
        ("\\.xml$" . sgml-mode)
        ("\\.xsl$" . sgml-mode)
        ("\\.dtd$" . sgml-mode)
        ("\\.toutdoux$" . sgml-mode)
        ("\\.hopla$" . sgml-mode)
        ("\\.tex$" . latex-mode )
        ("\\.bib$" . latex-mode )
        ("\\.cls$" . latex-mode )
        ("\\.html$" . html-mode)
        ("\\.shtml$" . html-mode)
        ("\\.php3$" . html-mode)
        ("\\.phtml$" . html-mode)
	("\\.sh$" . sh-mode )
        ("\\.scm$" . scheme-mode) 
        ("\\.l$" . lisp-mode) 
        ("\\.lisp$" . lisp-mode) 
        ("\\.f$" . fortran-mode) 
        ("\\.awk$" . awk-mode )
        ("\\.pl$" . perl-mode )
        ("\\.el$" . emacs-lisp-mode) 
        ("\\.emacs$" . emacs-lisp-mode) 
        ("\\.gnus$" . emacs-lisp-mode)
        ("\\.py$" . python-mode))
)

;; Fichier : Speedbar



;; Ecran
;(custom-set-variables
; '(visible-bell t)
; '(fill-column 100)
; (hscroll-global-mode t))
;(setq line-number-mode t)
;(setq column-number-mode t)

;; Colorisation : Generalite

(setq font-lock-maximum-decoration t)


;; Colorisation : Dans ta face PaleGreen


;; Colorisation : C : Grands classiks
(font-lock-add-keywords 'c-mode
			'(
			  ("\\<\\(printf\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(getc\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(strtok\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(strcmp\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(strlen\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(atoi\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(fgets\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(fprintf\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(remove\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(rename\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(stat\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(open\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(opendir\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(closedir\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(fstat\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(fopen\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(freopen\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(fclose\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(fflush\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(fpurge\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(feof\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(dlopen\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(dlsym\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(dlerror()\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(sleep;?\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(setenv;?\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(pthread_[-.a-z0-9_]*;?\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(sem_[-.a-z0-9_]*;?\\)\\>" . font-lock-keyword-face)
			  ))

;; Colorisation : C : Commentaires
(font-lock-add-keywords 'c-mode
			'(
			  ("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
			  ))

;; Colorisation : C : Xml PostgreSQL
(font-lock-add-keywords 'c-mode
			'(
			  ("\\<\\(xmlNewDoc\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlNewDocNode\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlSetDocCompressMode\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlFreeDoc\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlSaveFile\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlParseFile\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlNewGlobalNs\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlSearchNsByHref\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlNewChild\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlGetProp\\)\\>" . font-lock-constant-face)
			  ("\\<\\(xmlSetProp\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQsetdbLogin\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQfinish\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQexec\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQresultStatus\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQnfields\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQfname\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQntuples\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQgetvalue\\)\\>" . font-lock-constant-face)
			  ("\\<\\(PQstatus\\)\\>" . font-lock-constant-face)
			  ))

;; Colorisation : Glib Gdk Gtk+ GNOME
(font-lock-add-keywords 'c-mode
			'(
			  ("\\<\\(g_[-.a-z0-9_]*;?\\)\\>" . font-lock-keyword-face)
			  ("\\<\\(gdk_[-.a-z0-9_]*;?\\)\\>" . font-lock-constant-face)
			  ("\\<\\(gtk_[-.a-z0-9_]*;?\\)\\>" . font-lock-constant-face)
			  ("\\<\\(gnome_[-.a-z0-9_]*;?\\)\\>" . font-lock-constant-face)
			  ("\\<\\(poptGetArgs\\)\\>" . font-lock-constant-face)
			  ))

;; Colorisation : ToutDoux hOpla
(font-lock-add-keywords 'c-mode
			'(
			  ("\\<\\(td_[-.a-z0-9_]*;?\\)\\>" . font-lock-builtin-face)
			  ("\\<\\(hopla_[-.a-z0-9_]*;?\\)\\>" . font-lock-builtin-face)
			  ))


;; Colorisation : Types


;; Divers
(fset 'yes-or-no-p 'y-or-n-p)
(add-to-list 'default-frame-alist '(background-color . "DarkSlateGray"))
(add-to-list 'default-frame-alist '(foreground-color . "Wheat"))
;(add-to-list 'default-frame-alist '(default ((t (:foreground "Wheat" :background "DarkSlateGray"))) t))
;;lyon (add-to-list 'default-frame-alist '(background-color . "LightGrey"))

;;(setq default-frame-alist (foreground-color . "lightcyan") (background-color . "black"))
;;; fonction de mode plan pour latex par 
;;;        Jacques L'helgoualc'h <lhh@free.fr>

(defun LaTeX-raise-hierarchy ()
  "Change: \\subsection--> \\section, etc. in region."
  (interactive)
  (save-excursion
    (save-match-data
      (let ((case-fold-search nil)
            (beg (region-beginning))
            (end (region-end)))
        ;; ... chapter --> part ?
        (goto-char beg)
        (while (re-search-forward "\\\\section\\>" end t)
          (replace-match "\\chapter" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\subsection\\>" end t)
          (replace-match "\\section" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\subsubsection\\>" end t)
          (replace-match "\\subsection" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\paragraph\\>" end t)
          (replace-match "\\subsubsection" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\subparagraph\\>" end t)
          (replace-match "\\paragraph" t t))))))

(defun LaTeX-lower-hierarchy ()
  "Change: \\section--> \\subsection, etc. in region."
  (interactive)
  (save-excursion
    (save-match-data
      (let ((case-fold-search nil)
            (beg (region-beginning))
            (end (region-end)))
        (goto-char beg)
        (while (re-search-forward "\\\\paragraph\\>" end t)
          (replace-match "\\subparagraph" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\subsubsection\\>" end t)
          (replace-match "\\paragraph" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\subsection\\>" end t)
          (replace-match "\\subsubsection" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\section\\>" end t)
          (replace-match "\\subsection" t t))
        (goto-char beg)
        (while (re-search-forward "\\\\chapter\\>" end t)
          (replace-match "\\section" t t))))))

(global-set-key [f9] 'LaTeX-raise-hierarchy )
(global-set-key [f10] 'LaTeX-lower-hierarchy)

;; Pour une indentation des progs bash
(setq sh-indent-for-then 0)
(setq sh-indent-for-do 0)
(setq sh-indent-after-do '+)
(setq sh-indent-for-case-label '*)
(setq sh-indent-for-case-alt '+)
(setq sh-indent-comment t)
;; autocompletion for bash shell in emacs
;; (autoload 'bash-completion-dynamic-complete 
;;   "bash-completion"
;;   "BASH completion hook")
;; (add-hook 'shell-dynamic-complete-functions
;;   'bash-completion-dynamic-complete)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Completion for languages can be done with company
;;;;;;;;;;; Gestion des TAGS avec global tags-add-tables
;; Si C mode, alors gtags mode automatiquement
(setq c-mode-hook
      '(lambda ()
	 (gtags-mode 1)
	 ))
;; And to use company-mode in all buffers
;; (add-hook 'after-init-hook 'global-company-mode)
(defun complete-or-indent ()
  (interactive)
  (if (company-manual-begin)
      (company-complete-common)
    (indent-according-to-mode)))
(global-set-key "\M-." 'find-tag)
(global-set-key "\M-*" 'pop-tag-mark)
;;;;;;;;;;;;;;;;;;;;;;;;;;;; C and C++ dev in EMACS
;; See http://tuhdo.github.io/c-ide.html

(global-set-key "\C-q" 'set-justification-left)
;;(global-set-key "\M-q" 'goto-line)
;;%%%%end file


;; pour les copier coller depuis une fenetre xterm sans aberations dues
;; au codage des fontes
;; 2010/01/10 marche plus : (require 'ucs-tables)
;(unify-8859-on-encoding-mode 1)
;(unify-8859-on-decoding-mode -1)
;(setq selection-coding-system 'compound-text-with-extensions)

;; pas de toolbar
(tool-bar-mode -1)

;; key delete
(global-set-key [delete] 'delete-char)

;; Un petit morceau de code qui permet de supprimer les espaces
;; qui restent en fin de ligne.
;; Origine :  lutzeb@cs.tu-berlin.de (Dirk Lutzebaeck) (1992)
;; la nouvelle fonction est associée au raccourci C-x espace
(defun delete-trailing-space ()
  "Deletes trailing space from all lines in buffer."
  (interactive)
  (or buffer-read-only
      (save-excursion
	(message "Deleting trailing spaces ... ")
	(goto-char (point-min))
	(while (< (point) (point-max))
	  (end-of-line nil)
	  (delete-horizontal-space)
	  (forward-line 1))
	(message "Deleting trailing spaces ... done.")))
  nil) ; indicates buffer-not-saved for write-file-hook
(define-key ctl-x-map " " 'delete-trailing-space)

;; en C, on va automatiquement a la ligne quand on tape un ; ou une accolade
;(setq c-auto-newline t)

;; from auctex
; completion
          (setq-default TeX-master nil)
          (setq TeX-parse-self t)
          (setq TeX-auto-save t)

;; load auctex
;;(set-language-environment "UTF-8")
;(require '/usr/share/emacs/site-lisp/auctex/tex-site.el.in)
; ---- language-env DON'T MODIFY THIS LINE!
;; (if (>= emacs-major-version 21)
;;     (progn
;; ;      (set-language-environment "Latin-9")
;;       (set-language-environment "UTF-8")
;;       (setq selection-coding-system 'compound-text-with-extensions)
;;     )
;;     (if (>= emacs-major-version 20)
;;         (set-language-environment "Latin-9")
;;         (require 'iso-syntax)))
;; ;; Names for calendar command.
;; ;; These should be derived from nl_langinfo() by emacs
;; ;;
;; (defvar calendar-day-name-array
;;   ["dim" "lun" "mar" "mer" "jeu" "ven" "sam"])
;; (defvar calendar-month-name-array
;;   ["janvier" "février" "mars" "avril" "mai" "juin" 
;;    "juillet" "août" "septembre" "octobre" "novembre" "décembre"])
; ---- language-env end DON'T MODIFY THIS LINE!
