462 lines
15 KiB
EmacsLisp
462 lines
15 KiB
EmacsLisp
;;; init.el --- -*- lexical-binding: t -*-
|
|
|
|
;;; Init file for emacs
|
|
|
|
;;; Commentary:
|
|
|
|
;; Init file, load everything necessary to have a full functional Emacs, this should
|
|
;; not be used with Emacs < 24.
|
|
|
|
;;; Code:
|
|
|
|
(add-to-list 'load-path "~/.emacs.d/one-file-mode/")
|
|
(add-to-list 'load-path "~/.emacs.d/site-lisp/")
|
|
|
|
;; Themes
|
|
(setq custom-theme-directory "~/.emacs.d/themes/")
|
|
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
|
|
|
|
;; Packages
|
|
(require 'package) ;; You might already have this line
|
|
(setq package-user-dir (expand-file-name "elpa" user-emacs-directory)
|
|
package-archives
|
|
'(("gnu" . "http://elpa.gnu.org/packages/")
|
|
("melpa" . "http://melpa.org/packages/")
|
|
("cselpa" . "http://elpa.thecybershadow.net/packages/")))
|
|
|
|
(unless (bound-and-true-p package--initialized)
|
|
(setq package-enable-at-startup nil) ; To prevent initializing twice
|
|
(package-initialize))
|
|
|
|
;; set use-package-verbose to t for interpreted .emacs,
|
|
;; and to nil for byte-compiled .emacs.elc.
|
|
(eval-and-compile
|
|
(setq use-package-verbose (not (bound-and-true-p byte-compile-current-file))))
|
|
|
|
;; Install use-package if not installed
|
|
(unless (package-installed-p 'use-package)
|
|
(package-refresh-contents)
|
|
(package-install 'use-package))
|
|
|
|
(eval-and-compile
|
|
(setq use-package-always-ensure t)
|
|
(setq use-package-expand-minimally t)
|
|
(setq use-package-compute-statistics t)
|
|
(setq use-package-enable-imenu-support t))
|
|
|
|
(eval-when-compile
|
|
(require 'use-package)
|
|
(require 'bind-key))
|
|
|
|
(use-package auto-package-update
|
|
:if (not (daemonp))
|
|
:custom
|
|
(auto-package-update-interval 7) ;; in days
|
|
(auto-package-update-prompt-before-update t)
|
|
(auto-package-update-delete-old-versions t)
|
|
(auto-package-update-hide-results t)
|
|
:config
|
|
(auto-package-update-maybe))
|
|
|
|
(use-package diminish)
|
|
|
|
(require 'iso-transl)
|
|
|
|
(global-display-line-numbers-mode)
|
|
|
|
;; No menu, scrollbar, displayline and column
|
|
(menu-bar-mode -1)
|
|
(tool-bar-mode -1)
|
|
(when (display-graphic-p)
|
|
(scroll-bar-mode -1))
|
|
(column-number-mode t)
|
|
(line-number-mode t)
|
|
(desktop-save-mode t)
|
|
|
|
;; Command rebinding
|
|
|
|
;; M-f (forward-word) : Déplacement d'un mot vers la droite du curseur.
|
|
;; M-b (backward-word) : Déplacement d'un mot vers la gauche du curseur.
|
|
;; C-a (beginning-of-line) : Déplacement au début de la ligne courante.
|
|
;; C-e (end-of-line) : Déplacement à la fin de la ligne courante.
|
|
;; M-{ (backward-paragraph) : Déplacement vers le paragraphe précédent.
|
|
(global-set-key (kbd "M-p") 'backward-paragraph)
|
|
;; M-} (forward-paragraph) : Déplacement vers le paragraphe suivant.
|
|
(global-set-key (kbd "M-n") 'forward-paragraph)
|
|
;; C-v (scroll-up) : Déplacement d'un écran vers le bas.
|
|
;; M-v (scroll-down) : Déplacement d'un écran vers le haut.
|
|
;; M-> (end-of-buffer) : Déplacement à la fin du buffer.
|
|
;; M-< (beginning-of-buffer) : Déplacement au début du buffer.
|
|
|
|
(use-package material-theme
|
|
:config
|
|
(load-theme 'material t))
|
|
|
|
;; No split screen at startup
|
|
(setq inhibit-startup-screen t)
|
|
;; Or if you use use-package
|
|
(setq dashboard-items '((recents . 5)
|
|
;; (bookmarks . 5)
|
|
(projects . 5)
|
|
(agenda . 5)
|
|
(registers . 5)))
|
|
(setq dashboard-set-heading-icons t)
|
|
(setq dashboard-set-file-icons t)
|
|
(setq dashboard-set-navigator t)
|
|
(use-package dashboard
|
|
:ensure t
|
|
:config
|
|
(dashboard-setup-startup-hook))
|
|
(add-hook 'dashboard-mode-hook (lambda () (display-line-numbers-mode -1)))
|
|
(setq initial-buffer-choice (lambda () (get-buffer "*dashboard*")))
|
|
|
|
(use-package doom-modeline
|
|
:ensure t
|
|
:hook (after-init . doom-modeline-mode))
|
|
|
|
(use-package ace-window
|
|
:bind ("C-x C-o" . ace-window))
|
|
|
|
;; Encoding
|
|
(set-language-environment "UTF-8")
|
|
|
|
;; Selection mode
|
|
(delete-selection-mode 1)
|
|
|
|
;; Indentation mode
|
|
(setq-default indent-tabs-mode nil)
|
|
(setq tab-width 4)
|
|
|
|
;; Compilation coloration
|
|
|
|
(ignore-errors
|
|
(require 'ansi-color)
|
|
(defun my-colorize-compilation-buffer ()
|
|
(when (eq major-mode 'compilation-mode)
|
|
(ansi-color-apply-on-region compilation-filter-start (point-max))))
|
|
(add-hook 'compilation-filter-hook 'my-colorize-compilation-buffer))
|
|
|
|
;; Retrieve PATH from fish shell
|
|
(when (memq window-system '(mac ns x))
|
|
(setq exec-path-from-shell-shell-name "/usr/local/bin/fish")
|
|
(exec-path-from-shell-initialize))
|
|
|
|
;; Auto complete + Yasnippet
|
|
(use-package projectile
|
|
:config
|
|
(projectile-mode 1)
|
|
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
|
|
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
|
|
(setq projectile-enable-caching t))
|
|
|
|
(use-package helm
|
|
:config
|
|
(global-set-key (kbd "M-x") 'helm-M-x)
|
|
(global-set-key (kbd "C-x r b") 'helm-filtered-bookmarks)
|
|
(global-set-key (kbd "C-x C-f") 'helm-find-files)
|
|
(global-set-key (kbd "C-x C-b") 'helm-buffers-list)
|
|
(helm-mode 1)
|
|
(add-to-list 'helm-boring-buffer-regexp-list "\\*.*"))
|
|
|
|
(use-package helm-projectile
|
|
:after (helm projectile)
|
|
:config
|
|
(setq projectile-completion-system 'helm)
|
|
(helm-projectile-on))
|
|
|
|
(use-package yasnippet
|
|
:config
|
|
(yas-global-mode 1))
|
|
|
|
(use-package flycheck
|
|
:config
|
|
(add-hook 'flycheck-after-syntax-check-hook 'flycheck-autolist-hook)
|
|
(global-flycheck-mode)
|
|
(setq flycheck-emacs-lisp-load-path "inherict")
|
|
(setq flycheck-clang-args '("-stdlib=libc++" "-W" "-Wall"))
|
|
(add-hook 'c++-mode-hook
|
|
(lambda ()
|
|
(setq-local flycheck-clang-language-standard "c++14"))))
|
|
|
|
(use-package flycheck-pos-tip
|
|
:after (flycheck)
|
|
:config
|
|
(add-hook 'flycheck-mode-hook 'flycheck-pos-tip-mode))
|
|
|
|
(use-package flycheck-color-mode-line
|
|
:after (flycheck)
|
|
:config
|
|
(add-hook 'flycheck-mode-hook 'flycheck-color-mode-line-mode))
|
|
|
|
(use-package company
|
|
:config
|
|
(add-hook 'after-init-hook 'global-company-mode)
|
|
(global-set-key (kbd "M-/") 'company-complete))
|
|
|
|
(use-package company-c-headers
|
|
:config
|
|
(add-to-list 'company-backends 'company-c-headers))
|
|
(use-package company-jedi
|
|
:config
|
|
(add-to-list 'company-backends 'company-jedi))
|
|
(use-package company-web
|
|
:config
|
|
(add-to-list 'company-backends 'company-web-html))
|
|
|
|
; C++
|
|
(use-package modern-cpp-font-lock
|
|
:ensure t)
|
|
(add-hook 'c++-mode-hook #'modern-c++-font-lock-mode)
|
|
|
|
;; Doc mode
|
|
(require 'doc-mode)
|
|
(add-hook 'c-mode-common-hook 'doc-mode)
|
|
(add-hook 'c++-mode-common-hook 'doc-mode)
|
|
|
|
;; Latex
|
|
(use-package auctex
|
|
:defer t
|
|
:config
|
|
(setq TeX-auto-save t)
|
|
(setq TeX-parse-self t)
|
|
(setq-default TeX-master nil)
|
|
(defun my-latex-mode-setup ()
|
|
"Redefines and updates variables for various customizations."
|
|
(setq LaTeX-paragraph-commands
|
|
'("If" "State" "Loop" "For" "ForAll"))
|
|
(setq LaTeX-begin-regexp
|
|
(concat LaTeX-begin-regexp "\\|If\\b" "\\|Loop\\b" "\\|For\\b" "\\|ForAll\\b"))
|
|
(setq LaTeX-end-regexp
|
|
(concat LaTeX-end-regexp "\\|EndIf\\b" "\\|EndLoop\\b"
|
|
"\\|EndFor\\b" "\\|Else\\b" "\\|ElsIf\\b"))
|
|
(setq LaTeX-paragraph-commands-regexp (LaTeX-paragraph-commands-regexp-make))
|
|
(defun LaTeX-indent-level-count ()
|
|
"Count indentation change caused by all \\left, \\right, \\begin, and
|
|
\\end commands in the current line."
|
|
(save-excursion
|
|
(save-restriction
|
|
(let ((count 0))
|
|
(narrow-to-region (point)
|
|
(save-excursion
|
|
(re-search-forward
|
|
(concat "[^" TeX-esc "]"
|
|
"\\(" LaTeX-indent-comment-start-regexp
|
|
"\\)\\|\n\\|\\'"))
|
|
(backward-char)
|
|
(point)))
|
|
(while (search-forward TeX-esc nil t)
|
|
(cond
|
|
((looking-at "left\\b")
|
|
(setq count (+ count LaTeX-left-right-indent-level)))
|
|
((looking-at "right\\b")
|
|
(setq count (- count LaTeX-left-right-indent-level)))
|
|
((looking-at LaTeX-begin-regexp)
|
|
(setq count (+ count LaTeX-indent-level)))
|
|
((looking-at "Else\\b"))
|
|
((looking-at "ElsIf\\b"))
|
|
((looking-at LaTeX-end-regexp)
|
|
(setq count (- count LaTeX-indent-level)))
|
|
((looking-at (regexp-quote TeX-esc))
|
|
(forward-char 1))))
|
|
count)))))
|
|
|
|
(add-to-list 'LaTeX-verbatim-environments "code")
|
|
(add-to-list 'LaTeX-indent-environment-list
|
|
'("code" current-indentation))
|
|
|
|
(add-hook 'LaTeX-mode-hook 'my-latex-mode-setup)
|
|
(add-hook 'LaTeX-mode-hook 'visual-line-mode)
|
|
(add-hook 'LaTeX-mode-hook 'flyspell-mode)
|
|
(add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
|
|
|
|
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
|
|
(setq reftex-plug-into-AUCTeX t)
|
|
(require 'tex)
|
|
(TeX-global-PDF-mode t)
|
|
)
|
|
(use-package company-auctex
|
|
:after (auctex company)
|
|
:config (company-auctex-init))
|
|
|
|
;; (add-to-list 'ispell-local-dictionary-alist '("francais-hunspell"
|
|
;; "[[:alpha:]]"
|
|
;; "[^[:alpha]]"
|
|
;; "[']"
|
|
;; t
|
|
;; ("-d" "fr_FR")
|
|
;; nil
|
|
;; iso-8859-1))
|
|
|
|
;; magit
|
|
(use-package magit
|
|
:config
|
|
(add-hook 'after-save-hook 'magit-after-save-refresh-status))
|
|
|
|
;; CSS style
|
|
(setq css-indent-offset 2)
|
|
|
|
;; Markdown mode
|
|
(use-package markdown-mode
|
|
:mode "\\.text\\'" "\\.markdown\\'" "\\.md\\'")
|
|
|
|
;; White space mode & Fill mode column
|
|
|
|
(defun my-visual-hook ()
|
|
(visual-line-mode t)
|
|
;; (visual-fill-column-mode t)
|
|
(define-key visual-line-mode-map [remap kill-line] nil)
|
|
(whitespace-mode t))
|
|
|
|
(setq-default fill-column 95)
|
|
(setq-default whitespace-line-column 95)
|
|
(add-hook 'python-mode-hook (lambda () (setq-local whitespace-line-column 100)))
|
|
(add-hook 'LaTeX-mode-hook (lambda () (setq-local whitespace-line-column -1)))
|
|
(add-hook 'markdown-mode-hook (lambda () (setq-local whitespace-line-column -1)))
|
|
(add-hook 'web-mode-hook (lambda () (setq-local whitespace-line-column -1)))
|
|
|
|
(add-hook 'text-mode-hook 'my-visual-hook)
|
|
(add-hook 'prog-mode-hook 'my-visual-hook)
|
|
|
|
(add-hook 'before-save-hook 'whitespace-cleanup)
|
|
|
|
;; Electric pair mode
|
|
(electric-pair-mode 1)
|
|
(show-paren-mode 1)
|
|
(setq show-paren-delay 0)
|
|
|
|
;; C mode
|
|
(setq c-default-style "k&r")
|
|
(setq c-basic-offset 4)
|
|
|
|
(defun ac-cc-mode-setup ()
|
|
"Initialization hook for CC-mode runs before any other hooks."
|
|
(hide-ifdef-mode)
|
|
(hs-minor-mode)
|
|
(setq hide-ifdef-shadow t))
|
|
|
|
(add-hook 'c-mode-common-hook 'ac-cc-mode-setup)
|
|
(add-hook 'c++-mode-common-hook 'ac-cc-mode-setup)
|
|
(add-hook 'auto-complete-mode-hook 'ac-common-setup)
|
|
|
|
(setq c-doc-comment-style
|
|
'((java-mode . javadoc)
|
|
(pike-mode . autodoc)
|
|
(c-mode . javadoc)
|
|
(c++-mode . javadoc)))
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.hpp\\'" . c++-mode))
|
|
|
|
;; Run C programs directly from within emacs
|
|
(setq execute-command nil)
|
|
(setq execute-buffer-name "*output*")
|
|
(setq execute-process-name "execute")
|
|
|
|
(defun set-execute-command ()
|
|
(interactive)
|
|
(setq sp (split-string (read-from-minibuffer "Execute command: ")))
|
|
(setq execute-command (combine-and-quote-strings (cons (file-truename (car sp)) (cdr sp)))))
|
|
|
|
(defun kill-execute-c-program ()
|
|
(interactive)
|
|
(if (get-process execute-process-name)
|
|
(delete-process (get-process execute-process-name))))
|
|
|
|
(defun execute-c-program ()
|
|
(interactive)
|
|
(if (not execute-command) (set-execute-command))
|
|
(kill-execute-c-program)
|
|
(setq old-buffer (current-buffer))
|
|
(setq output-buffer (get-buffer-create execute-buffer-name))
|
|
(switch-to-buffer-other-window output-buffer)
|
|
(end-of-buffer)
|
|
(insert (concat (propertize execute-command 'face 'bold) "\n"))
|
|
(switch-to-buffer-other-window old-buffer)
|
|
(start-process-shell-command execute-process-name execute-buffer-name execute-command))
|
|
|
|
(defun key-c-mode-setup ()
|
|
(local-set-key (kbd "C-c C-c") 'smart-compile)
|
|
(local-set-key (kbd "C-c C-r") 'execute-c-program)
|
|
(local-set-key [f3] 'kill-execute-c-program)
|
|
(local-set-key [f4] 'set-execute-command))
|
|
|
|
(add-hook 'c++-mode-common-hook 'key-c-mode-setup)
|
|
(add-hook 'c-mode-common-hook 'key-c-mode-setup)
|
|
|
|
;; Flyspell dictionarie
|
|
(defun fd-switch-dictionary ()
|
|
(interactive)
|
|
(let* ((dic ispell-current-dictionary)
|
|
(change (if (string= dic "francais") "english" "francais")))
|
|
(ispell-change-dictionary change)
|
|
(message "Dictionary switched from %s to %s" dic change)
|
|
))
|
|
|
|
(defun key-latex-mode-setup ()
|
|
(local-set-key [f8] 'fd-switch-dictionary))
|
|
|
|
(add-hook 'LaTeX-mode-hook 'key-latex-mode-setup)
|
|
|
|
;; python
|
|
(use-package flycheck-mypy)
|
|
(use-package elpy
|
|
:config
|
|
(when (load "flycheck" t t)
|
|
(flycheck-add-next-checker 'python-flake8 'python-mypy)
|
|
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
|
|
(add-hook 'elpy-mode-hook 'flycheck-mode))
|
|
(setq python-shell-interpreter "ipython"
|
|
python-shell-interpreter-args "-i --simple-prompt")
|
|
;; (setq python-shell-interpreter "jupyter"
|
|
;; python-shell-interpreter-args "console --simple-prompt"
|
|
;; python-shell-prompt-detect-failure-warning nil)
|
|
(add-to-list 'python-shell-completion-native-disabled-interpreters
|
|
"jupyter")
|
|
:init
|
|
(setq elpy-rpc-backend "jedi")
|
|
(setq elpy-rpc-python-command "I:\\Languages\\Python\\Python37\\python.exe")
|
|
(elpy-enable))
|
|
(add-hook 'python-mode-hook 'hs-minor-mode)
|
|
|
|
;; Web mode
|
|
(add-to-list 'auto-mode-alist '("\\.ctp\\'" . web-mode))
|
|
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
|
|
|
|
;;(use-package mmm-mode
|
|
;; :config
|
|
;; (require 'mmm-auto)
|
|
;; (setq mmm-global-mode 'maybe)
|
|
;; (mmm-add-mode-ext-class 'html-mode "\\.php\\'" 'html-php)
|
|
;; (mmm-add-mode-ext-class nil "\\.ctp\\'" 'html-php)
|
|
;; (add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil html-js))
|
|
;; (add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil embedded-css))
|
|
;; (add-to-list 'mmm-mode-ext-classes-alist '(html-mode nil fancy-html)))
|
|
|
|
;; Go
|
|
(require 'go-template-mode)
|
|
|
|
;; Dockers
|
|
(require 'dockerfile-mode)
|
|
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))
|
|
|
|
;; Lilypond
|
|
(autoload 'LilyPond-mode "lilypond-mode" "LilyPond Editing Mode" t)
|
|
(add-to-list 'auto-mode-alist '("\\.ly$" . LilyPond-mode))
|
|
(add-to-list 'auto-mode-alist '("\\.ily$" . LilyPond-mode))
|
|
(add-hook 'LilyPond-mode-hook (lambda () (turn-on-font-lock)))
|
|
|
|
;; Term
|
|
(setq explicit-shell-file-name "/bin/bash")
|
|
(defun my-term-hook ()
|
|
(visual-fill-column-mode nil)
|
|
(visual-line-mode nil))
|
|
(add-hook 'term-load-hook 'my-term-hook)
|
|
(eval-after-load "term"
|
|
'(define-key term-raw-map (kbd "C-c C-y") 'term-paste))
|
|
|
|
(setq custom-file "~/.emacs.d/custom.el")
|
|
(load custom-file)
|
|
(put 'narrow-to-region 'disabled nil)
|
|
|
|
(provide 'init)
|
|
;;; init.el ends here
|