;; .emacs initialization file  ; -*- mode: emacs-lisp -*-
;;
;; Time-stamp: <2011-04-11 11:31:40 cmic>
;; <2020-05-03 11:56:29 cmic> ajout doc set-goal-column
;;
(setq inhibit-splash-screen t)
;; Set up the keyboard so the delete key on both the regular keyboard
;; and the keypad delete the character under the cursor and to the right
;; under X, instead of the default, backspace behavior.
;;(global-set-key [delete] 'delete-char)
;;(global-set-key [kp-delete] 'delete-char)
(define-key global-map "\C-h" 'backward-delete-char )
;; turn on font-lock mode
(global-font-lock-mode t)
;; enable visual feedback on selections
(setq-default transient-mark-mode t)
      
;; always end a file with a newline
(setq require-final-newline t)

;; stop at the end of the file, not just add lines
(setq next-line-add-newlines nil)

(when window-system
  ;; enable wheelmouse support by default
  (mwheel-install)
  ;; use extended compound-text coding for X clipboard
  (set-selection-coding-system 'compound-text-with-extensions))
;;
;; (standard-display-european t)
;; Caracteres francais accentues
;; (set-language-environment 'latin-1)
;; ci-dessous fonctionne bien
(set-input-mode (car (current-input-mode))
	(nth 1 (current-input-mode)) 0 )

(setq-default iso-accents-mode t)
;;
;; Abbrev-mode configuration from cmic's home
;;
(setq abbrev-file-name       ;; where to read abbrevs
 "~cmic/.abbrev_defs")
(quietly-read-abbrev-file)  ;; read on startup
(setq save-abbrevs t)        ;; auto-save on quit
(setq abbrev-mode t)         ;; abbrev mode on 
;;
;; Copy line 
;;
(defun copy-line (n)
  "Copy N lines at point to the kill-ring."
  (interactive "p")
  (kill-ring-save (line-beginning-position) (line-beginning-position (1+ n))))

(global-set-key "\C-ck" 'copy-line) 
(global-set-key "\C-cg" 'goto-line) 
;;
;; preserve hard linked files
(setq backup-by-copying-when-linked t) 
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Perl utiities
;; Syntaxe en sortant de Emacs
;;
(defvar perl-syntax-bin "/usr/local/bin/perl"
  "the Perl binary used to check syntax.")
(defun perl-syntax-check-only () 
  "Returns either nil or t depending on whether \ 
    the current buffer passes perl syntax check."
  (interactive)
  (let ((buf (get-buffer-create "*Perl syntax check*")))
    (let ((syntax-ok ( = 0 (save-excursion
			    (widen)
			    (call-process-region
			     (point-min) (point-max) perl-syntax-bin nil buf nil "-c"))) ))
      (if syntax-ok (kill-buffer buf)
	(display-buffer buf))
      syntax-ok )))
;;
(defvar perl-syntax-mode nil
  "Check perl syntax before saving." )
(make-variable-buffer-local 'perl-syntax-mode)
;;
(defun perl-syntax-write-hook ()
  "Check perl syntax during write-file-hooks for 'perl-syntax-mode'"
  (if perl-syntax-mode
      (save-excursion
	(widen)
	(mark-whole-buffer)
	(not (perl-syntax-check-only)))
    nil))
;;
;; fixing obsolete make-local-hook
;;
(add-hook 'emacs-lisp-mode-hook
	  '(lambda ()
	     (add-hook 'write-content-hooks 'untab-all nil t) ))

(defun untab-all ()
  (unless (and (stringp mode-name)
               (string= mode-name "GNUmakefile") )
    (untabify (point-min) (point-max)) )
  nil) ; did not write buffer to disk
;;
;; ENDOF fixing obsolete make-local-hook
;;
(defun perl-syntax-mode (&optional arg)
  "Perl syntax check minor mode."
  (interactive "P")
  (setq perl-syntax-mode
	(if (null arg)
	    (not perl-syntax-mode)
	  (> (prefix-numeric-value arg) 0 )))
;;  (make-local-hook 'write-file-hooks)
  (add_hook 'write-file-hooks)
  (if perl-syntax-mode
      (add-hook 'write-file-hooks 'perl-syntax-write-hook)
    (remove-hook 'write-file-hooks 'perl-syntax-write-hook)))
;;
  (if (not (assq 'perl-syntax-mode minor-mode-alist))
      (setq minor-mode-alist
	    (cons '(perl-syntax-mode " Perl syntax")
		  minor-mode-alist)))
  (eval-after-load "cperl-mode"
    '(add-hook 'cperl-mode-hook 'perl-syntax-mode))
;;
;;(global-set-key "\C-xp" 'perl-syntax-mode) 
(global-set-key "\C-xp" 'perl-syntax-check-only) 
;; ENDOF perl utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Detect endianness of UTF-16 containing a Byte Order Mark U+FEFF 
;; kludge to read utf-16-Le files
;;
(add-to-list 'auto-coding-regexp-alist '("^\xFF\xFE" . utf-16-le) t) 
(add-to-list 'auto-coding-regexp-alist '("^\xFE\xFF" . utf-16-be) t)
;;
;; adds a BOM U+FEFF at the beginig of the file before saving
;;
(defun utf-16-le-pre-write-conversion 
  (start end) nil) 
(defun utf-16-be-pre-write-conversion 
  (start end) nil)
;;
;; en test pour utilisation du mail....
;;
(defun my-insert-reply-to ()
  (interactive)
  (beginning-of-buffer)
  (insert-string "Reply-To: michel.marcon@developpement-durable.gouv.fr\n") ) 
;;
;;First set the column number N with C-x C-n and type your tyext if any
;;then move downward (arrow or C-n), you are positionned at the column
;;number N you've chosen !!
;;And C-p/C-n moves you upward/diwnward to column N.  
;;To disable this goal column number N, type C-u C-x C-n
;;(require 'linum) not usefull on post 23 version
;;
(put 'set-goal-column 'disabled nil)
;;
;; desktop save line number for each file
;;
(setq desktop-enable t)
(desktop-load-default)
(desktop-read)
;;
;; Insert date string (ala time-stamp)
;;
(defun insert-date-string ()
  (interactive)
  (insert "<" (format-time-string "%Y-%m-%d %H:%M:%S" ) " "user-login-name ">" 
	  )
  )
(global-set-key "\C-cd" 'insert-date-string)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; rust-mode <2017-01-10 20:41:42 cmic>
;; Tell emacs where is your personal elisp lib dir
;; load the packaged named rust-mode.
(add-to-list 'load-path "~cmic/.emacs.d/lisp/")
(autoload 'rust-mode "rust-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
;;
;;;; cargo.el minor mode (to get C-c C- b to build, C-c C-c r to run, etc.
;;;;
;;(add-to-list 'load-path "~cmic/.emacs.d/lisp/")
;;(load "cargo-progress" )
;;(load "cargo" )
;;(add-hook 'rust-mode-hook 'cargo-minor-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MELPA thing for SLIME <2019-03-01 18:45:31 cmic>
;;
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl
    (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
    ;; For important compatibility libraries like cl-lib
    (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))
(package-initialize)
;;
;; Note : to install another package from MELPA, under emacs,
;; execute M-x packege-list-packages, the mouse-slect packages,
;; C-x o to go in the other pane, then install.
;; Done for SLIME (slim-mode for Lisp) <2019-03-01 18:53:04 cmic>
;;
(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.
 '(package-selected-packages (quote (slime slim-mode))))
(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.
 )
;;;; Set your lisp system and, optionally, some contribs
(setq inferior-lisp-program "/usr/local/bin/sbcl")
(setq slime-contribs '(slime-fancy))
;;
;;FIN
