Emacs

From HackDownWiki
Jump to navigation Jump to search

[EN] Emacs is a family of text editors which handle well code and provides lots of functionality for programmers.

[FR] Emacs est une famille d'éditeurs de texte qui gèrent bien le code et offrent beaucoup de fonctionnalités pour les programmeurs.

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

; See https://emacs.stackexchange.com/questions/5828/why-do-i-have-to-add-each-package-to-load-path-or-problem-with-require-packag

; Manually load package instead of waiting until after init.el is loaded

(package-initialize)

; Disable loading package again after init.el

(setq package-enable-at-startup nil)

; Enable "package", for installing packages
; Add some common package repositories

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("elpy" . "https://jorgenschaefer.github.io/packages/"))

; Use "package" to install "use-package", a better package management and config system

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

; Hide hidden files using Dired

(require 'dired-x)
(setq-default dired-omit-files-p t) ; Buffer-local variable
(setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))

(eval-when-compile
  (require 'use-package))

; Make OS shell path available in emacs exec path

(use-package exec-path-from-shell
  :ensure t
  :config (exec-path-from-shell-copy-env "PATH"))

;Hide hidden, backup, autosave files

(add-hook 'dired-load-hook '(lambda () (require 'dired-x))) ; Load Dired X when Dired is loaded.
(setq dired-omit-mode t) ; Turn on Omit mode.

; Hide Welcome Screen

(setq inhibit-startup-screen t)

; Theme dracula

(load-theme 'dracula t)

; ruler mode
; create a 72-character line marker============================================


; with a work-around so that fill-column-indicator works with company mode
; https://emacs.stackexchange.comllllll/questions/147/how-can-i-get-a-ruler-at-column-80

(use-package fill-column-indicator
  :ensure t
  :config
  (setq fci-rule-column 72)
  (add-hook 'prog-mode-hook 'fci-mode))

; Column numbers

(setq column-number-mode 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.
 '(package-selected-packages
   (quote
    (markdown-mode pandoc-mode company-jedi helm-projectile projectile elpy fill-column-indicator exec-path-from-shell use-package zenburn-theme paganini-theme gruber-darker-theme dracula-theme))))
(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.
 )

 ;; 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 up elpy for Python in Emacs

(use-package elpy
  :ensure t
  :pin elpy
  :config
  (elpy-enable)
  ;; Enable elpy in a Python mode
  (add-hook 'python-mode-hook 'elpy-mode)
  (setq elpy-rpc-backend "jedi")
  ;; Open the Python shell in a buffer after sending code to it
  (add-hook 'inferior-python-mode-hook 'python-shell-switch-to-shell)
  ;; Use IPython as the default shell, with a workaround to accommodate IPython 5
  ;; https://emacs.stackexchange.com/questions/24453/weird-shell-output-when-using-ipython-5  (setq python-shell-interpreter "ipython")
  (setq python-shell-interpreter "/usr/bin/python3")
  (setq python-shell-interpreter-args "-i")
  ;; Enable pyvenv, which manages Python virtual environments
  (pyvenv-mode 1)
  ;; Tell Python debugger (pdb) to use the current virtual environment
  ;; https://emacs.stackexchange.com/questions/17808/enable-python-pdb-on-emacs-with-virtualenv
  (setq gud-pdb-command-name "python -m pdb "))


; Set up company, i.e. code autocomplete

(use-package company
  :ensure t
  :config
  ;; Enable company mode everywhere
  (add-hook 'after-init-hook 'global-company-mode)
  ;; Set up TAB to manually trigger autocomplete menu
  (define-key company-mode-map (kbd "TAB") 'company-complete)
  (define-key company-active-map (kbd "TAB") 'company-complete-common)
  ;; Set up M-h to see the documentation for items on the autocomplete menu
  (define-key company-active-map (kbd "M-h") 'company-show-doc-buffer))

 ; Set up company-jedi, i.e. tell elpy to use company autocomplete backend

(use-package company-jedi
  :ensure t
  :config
  (defun my/python-mode-hook ()
    (add-to-list 'company-backends 'company-jedi))
  (add-hook 'python-mode-hook 'my/python-mode-hook))

; Set up markdown in Emacs
; Tutorial: http://jblevins.org/projects/markdown-mode/

(use-package pandoc-mode
  :ensure t
  :config
  (add-hook 'markdown-mode-hook 'pandoc-mode))

(add-hook 'text-mode-hook (lambda() (flyspell-mode 1)))

(use-package markdown-mode
  :ensure t
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "pandoc"))

; C-n add new lines at the end of buffer

(setq next-line-add-newlines t)
; open emacs full screen

(add-to-list 'default-frame-alist '(fullscreen . maximized))

; Make Emacs highlight paired parentheses

(show-paren-mode 1)


;; Insérer la date sur la page
(defun insert-date ()
    "Insert the current date and time at point."
    (interactive)
    (insert "============================================")
    (newline 1)
    (insert (current-time-string))
    (newline 1)
    (insert "--------------------------------------------")
    (newline 1))
(global-set-key "\C-ct" 'insert-date)

;; Affiche l'heure au format 24h dans le modeline
(display-time-mode 1)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)

;; ***************************************************************
;; Show line and column number
;; ***************************************************************

(require 'linum)
(line-number-mode 1)
(set-face-foreground 'linum "green")
(column-number-mode 1) ;; Line numbers on left most column
(global-linum-mode 1)

;; Make emacs' window title show path of current file:
(setq-default frame-title-format
              '(:eval
                (format "%s@%s: %s %s"
                        (or (file-remote-p default-directory 'user)
                            user-real-login-name)
                        (or (file-remote-p default-directory 'host)
                            system-name)
                        (buffer-name)
                        (cond
                         (buffer-file-truename
                          (concat "(" buffer-file-truename ")"))
                         (dired-directory
                          (concat "{" dired-directory "}"))
                         (t
                          "[no file]")))))
;; cursor stops blinking

(blink-cursor-mode 0)


;; ***************************************************************
;; highlight the current line; set a custom face, so we can
;; recognize from the normal marking (selection)
;; ***************************************************************
(defface hl-line '((t (:background "DarkSlateGrey")))
"Face to use for `hl-line-face'." :group 'hl-line)
(setq hl-line-face 'hl-line)
(global-hl-line-mode t) ; turn it on for all modes by default



;; 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)
;3R    (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")))

https://www.gnu.org/software/emacs/manual/html_node/emacs/Init-File.html