emacs-init.el 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. ;; Load extensions and themes from these folder =====================================================
  2. (add-to-list 'load-path "~/.emacs.d/lisp/")
  3. (add-to-list 'load-path "~/.emacs.d/elpa/")
  4. (add-to-list 'load-path "~/.emacs.d/themes/")
  5. ;; Packages install =================================================================================
  6. (require 'package)
  7. ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341
  8. (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
  9. (add-to-list 'package-archives
  10. '("melpa" . "https://melpa.org/packages/")
  11. )
  12. (when (< emacs-major-version 24)
  13. ;; For important compatibility libraries like cl-lib
  14. (add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/")))
  15. ;; This might not be necessary anymore.
  16. (when (< emacs-major-version 27)
  17. (package-initialize)
  18. )
  19. ;; This is only needed once, near the top of the file
  20. (eval-when-compile
  21. ;; Following line is not needed if use-package.el is in ~/.emacs.d
  22. ;;(add-to-list 'load-path "<path where use-package is installed>")
  23. (require 'use-package))
  24. ;; Themes are safe…
  25. (setq custom-safe-themes t)
  26. ;; Use a separate custom variables file
  27. (setq custom-file "~/.emacs.d/custom.el")
  28. ;; And load it if exists
  29. (if (file-exists-p custom-file)
  30. (load custom-file))
  31. ;; Common packages ini =============================================================================
  32. ; list the packages you want
  33. (setq package-list
  34. '(deferred window-jump ample-theme ample-zen-theme kaesar kaesar-file
  35. preseed-generic-mode html-check-frag magit-gitflow
  36. flycheck flycheck-status-emoji flycheck-yamllint
  37. flymake-shell flymake-shellcheck
  38. goto-last-change
  39. ws-butler hl-todo
  40. move-text powerline git-gutter
  41. treemacs treemacs-magit treemacs-icons-dired
  42. auto-complete auto-complete-nxml
  43. clipmon xclip
  44. pass password-generator password-store password-store-otp
  45. diminish restart-emacs
  46. yaml-mode gitignore-mode ini-mode
  47. nginx-mode jinja2-mode haml-mode git-timemachine
  48. select-themes
  49. ansible ansible-doc
  50. jedi jedi-core
  51. alect-themes arc-dark-theme cloud-theme doom-themes kaolin-themes leuven-theme zerodark-theme
  52. immaterial-theme atom-one-dark-theme seoul256-theme subatomic256-theme
  53. multiple-cursors
  54. ))
  55. ; activate all the packages
  56. (package-initialize)
  57. ; fetch the list of packages available
  58. (unless package-archive-contents
  59. (package-refresh-contents))
  60. ; install the missing packages
  61. (dolist (package package-list)
  62. (unless (package-installed-p package)
  63. (package-install package)))
  64. ;; terminal eshell =================================================================================
  65. (defun eshell-clear-buffer ()
  66. "Clear terminal"
  67. (interactive)
  68. (let ((inhibit-read-only t))
  69. (erase-buffer)
  70. (eshell-send-input)))
  71. (add-hook 'eshell-mode-hook
  72. '(lambda()
  73. (local-set-key (kbd "C-l") 'eshell-clear-buffer)))
  74. ;; Jump between windows ============================================================================
  75. (require 'window-jump)
  76. (global-set-key (kbd "C-x <left>") 'window-jump-left)
  77. (global-set-key (kbd "C-x <right>") 'window-jump-right)
  78. (global-set-key (kbd "C-x <up>") 'window-jump-up)
  79. (global-set-key (kbd "C-x <down>") 'window-jump-down)
  80. ;; Startup ==========================================================================================
  81. (setq inhibit-startup-message t)
  82. (desktop-save-mode 1)
  83. ;; Themes loading ===================================================================================
  84. ;; If the bar character being changed, this is not necessary any more
  85. (defun init-theme()
  86. "Set csutom settings after a theme is applied"
  87. (interactive)
  88. (set-face-background 'vertical-border (face-foreground 'window-divider))
  89. (set-face-foreground 'vertical-border (face-background 'vertical-border))
  90. )
  91. ;; Remember the theme between the sessions
  92. ;; (remember-theme-load)
  93. ;; (add-hook 'kill-emacs-hook 'remember-theme-save)
  94. (use-package remember-last-theme
  95. :ensure t
  96. :config (remember-last-theme-with-file-enable "~/.emacs.d/last-theme"))
  97. ;; then in your init you can load all of the themes
  98. ;; without enabling theme (or just load one)
  99. (load-theme 'ample t t)
  100. (load-theme 'ample-flat t t)
  101. (load-theme 'ample-light t t)
  102. ;; treemacs init ====================================================================================
  103. (global-set-key [f12] 'treemacs)
  104. (with-eval-after-load "treemacs"
  105. (setq treemacs-icon-open-png (propertize "⊖ " 'face 'treemacs-directory-face)
  106. treemacs-icon-closed-png (propertize "⊕ " 'face 'treemacs-directory-face)))
  107. ;; Windows init =====================================================================================
  108. (defun init-window()
  109. "Initialise emacs in graphical environment"
  110. (interactive)
  111. ;; Don't display scroll bars
  112. (scroll-bar-mode -1)
  113. ;; Set font according to my resolution (laptop or desktop station)
  114. (if (> display-pixels-per-inch 72)
  115. ;; Use a nice font
  116. (set-face-attribute 'default nil :font "Fantasque Sans Mono-16" :weight 'normal)
  117. ;; Or a standard one
  118. (set-face-attribute 'default nil :font "DejaVu Sans Mono-14" :weight 'normal)
  119. )
  120. ;; Easier to read
  121. (set-default 'cursor-type 'bar)
  122. ;; Chabge cursor shape according to the mode
  123. (add-hook 'overwrite-mode-hook
  124. (lambda ()
  125. (if overwrite-mode (set-default 'cursor-type 'hbar)
  126. (set-default 'cursor-type 'bar))
  127. )
  128. )
  129. (add-hook 'read-only-mode-hook
  130. (lambda ()
  131. (if buffer-read-only (set-default 'cursor-type 'box)
  132. (set-default 'cursor-type 'bar))
  133. )
  134. )
  135. ;; term
  136. (defface term-color-black
  137. '((t (:foreground "#3f3f3f" :background "#272822")))
  138. "Unhelpful docstring.")
  139. (defface term-color-red
  140. '((t (:foreground "#cc9393" :background "#272822")))
  141. "Unhelpful docstring.")
  142. (defface term-color-green
  143. '((t (:foreground "#7f9f7f" :background "#272822")))
  144. "Unhelpful docstring.")
  145. (defface term-color-yellow
  146. '((t (:foreground "#f0dfaf" :background "#272822")))
  147. "Unhelpful docstring.")
  148. (defface term-color-blue
  149. '((t (:foreground "#6d85ba" :background "#272822")))
  150. "Unhelpful docstring.")
  151. (defface term-color-magenta
  152. '((t (:foreground "#dc8cc3" :background "#272822")))
  153. "Unhelpful docstring.")
  154. (defface term-color-cyan
  155. '((t (:foreground "#93e0e3" :background "#272822")))
  156. "Unhelpful docstring.")
  157. (defface term-color-white
  158. '((t (:foreground "#dcdccc" :background "#272822")))
  159. "Unhelpful docstring.")
  160. '(term-default-fg-color ((t (:inherit term-color-white))))
  161. '(term-default-bg-color ((t (:inherit term-color-black))))
  162. ;; ansi-term colors
  163. (setq ansi-term-color-vector
  164. [term term-color-black term-color-red term-color-green term-color-yellow
  165. term-color-blue term-color-magenta term-color-cyan term-color-white])
  166. ;; Scroll the buffer with arrow keys
  167. (global-set-key [C-up] 'scroll-down-line)
  168. (global-set-key [C-down] 'scroll-up-line)
  169. ;; use default Alt-Up, Alt-Down for moving line or region
  170. (require 'move-text)
  171. (move-text-default-bindings)
  172. )
  173. ;; Some useful macros ===============================================================================
  174. (defun init-general()
  175. "Global initialisation mode."
  176. (interactive)
  177. ;; Cleanup spaces when saving the file
  178. (add-hook 'before-save-hook
  179. (lambda() (untabify)))
  180. (add-hook 'before-save-hook
  181. (lambda() (delete-trailing-whitespace)))
  182. ;; Duplicate the current line
  183. (defun duplicate-line (arg)
  184. "Duplicate current line, leaving point in lower line."
  185. (interactive "*p")
  186. ;; save the point for undo
  187. (setq buffer-undo-list (cons (point) buffer-undo-list))
  188. ;; local variables for start and end of line
  189. (let ((bol (save-excursion (beginning-of-line) (point)))
  190. eol)
  191. (save-excursion
  192. ;; don't use forward-line for this, because you would have
  193. ;; to check whether you are at the end of the buffer
  194. (end-of-line)
  195. (setq eol (point))
  196. ;; store the line and disable the recording of undo information
  197. (let ((line (buffer-substring bol eol))
  198. (buffer-undo-list t)
  199. (count arg))
  200. ;; insert the line arg times
  201. (while (> count 0)
  202. (newline) ;; because there is no newline in 'line'
  203. (insert line)
  204. (setq count (1- count)))
  205. )
  206. ;; create the undo information
  207. (setq buffer-undo-list (cons (cons eol (point)) buffer-undo-list)))
  208. ) ; end-of-let
  209. ;; put the point in the lowest line and return
  210. (next-line arg))
  211. (global-set-key (kbd "M-d") 'duplicate-line)
  212. ;; Delete backwards
  213. (bind-key "C-<backspace>" 'nv-delete-back-all)
  214. (bind-key "M-<backspace>" 'nv-delete-back)
  215. ;; SavePlace: This puts the cursor in the last place you edited a particular
  216. ;; file. A very useful default vim feature.
  217. (setq-default save-place t)
  218. ;; Automatically close brackets / parenthesis, etc.
  219. (electric-pair-mode)
  220. ;; scroll & tool bars are not useful
  221. (tool-bar-mode -1)
  222. (menu-bar-mode -1)
  223. (defun menu-display()
  224. (interactive)
  225. (menu-bar-mode)
  226. (menu-bar-open)
  227. (menu-bar-mode -1)
  228. )
  229. (global-set-key [f10] 'menu-display)
  230. ;; Implementation of zap-up-to-char
  231. (autoload 'zap-up-to-char "misc"
  232. "Kill up to, but not including ARGth occurrence of CHAR.
  233. \(fn arg char)"
  234. 'interactive)
  235. (global-set-key "\M-z" 'zap-up-to-char)
  236. ;;
  237. (global-set-key "\M-#" 'goto-last-change)
  238. ;; Ignore case when trying to find a file
  239. (setq pcomplete-ignore-case 't)
  240. (setq read-file-name-completion-ignore-case 't)
  241. ;; Standards edition commands
  242. (cua-mode 1)
  243. ;; Do not confirm the buffer I close
  244. (global-set-key [(control x) (k)] 'kill-this-buffer)
  245. ;; use default Alt-Up, Alt-Down for moving line or region
  246. (require 'move-text)
  247. (move-text-default-bindings)
  248. ;; Buffers navigation
  249. (global-unset-key [C-next])
  250. (global-unset-key [C-prior])
  251. (global-set-key [C-next] 'switch-to-prev-buffer)
  252. (global-set-key [C-prior] 'switch-to-next-buffer)
  253. ;; This should be displayed when emacs starts
  254. (message "Initialised")
  255. )
  256. ;;; Create directory if the folder does not exists when opening a file
  257. (defadvice find-file (before make-directory-maybe (filename &optional wildcards) activate)
  258. "Create parent directory if not exists while visiting file."
  259. (unless (file-exists-p filename)
  260. (let ((dir (file-name-directory filename)))
  261. (unless (file-exists-p dir)
  262. (make-directory dir))))
  263. )
  264. ;; Save commands history =============================================================================
  265. (setq savehist-additional-variables
  266. '(search-ring regexp-search-ring)
  267. savehist-file "~/.emacs.d/savehist")
  268. (savehist-mode t)
  269. ;; Encryption =======================================================================================
  270. (require 'kaesar)
  271. (require 'kaesar-file)
  272. ;; Backup settings ==================================================================================
  273. (setq
  274. backup-by-copying t ; don't clobber symlinks
  275. backup-directory-alist
  276. '(("." . "~/.emacs.d/saves")) ; don't litter my fs tree
  277. delete-old-versions t
  278. kept-new-versions 6
  279. kept-old-versions 2
  280. version-control t) ; use versioned backups
  281. ;; Special characters ===============================================================================
  282. ;; See https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Tables.html
  283. (setq truncate-string-ellipsis "…")
  284. (global-set-key "\C-xt" 'toggle-truncate-lines)
  285. (set-display-table-slot standard-display-table 'wrap ?⏎) ; wrapped lines
  286. (set-display-table-slot standard-display-table 0 ?…) ; truncated lines
  287. (set-display-table-slot standard-display-table 4 "…") ; invisible lines
  288. (set-display-table-slot standard-display-table 5 ?│) ; vertitical border
  289. ;; Terminal specific settings =======================================================================
  290. (defun init-console()
  291. "Initialise Emacs in console mode."
  292. (interactive)
  293. (when (> emacs-major-version 26)
  294. (display-line-numbers-mode)
  295. )
  296. (add-hook 'git-gutter-mode-hook 'git-gutter-setup)
  297. ;; Share the clipboard with X
  298. (xclip-mode)
  299. ;; Change the cursor shape according to the mode, in VTE based terminals
  300. (add-hook 'overwrite-mode-hook
  301. (lambda ()
  302. (if overwrite-mode (send-string-to-terminal "\033[3 q")
  303. (send-string-to-terminal "\033[5 q"))
  304. ))
  305. (add-hook 'read-only-mode-hook
  306. (lambda ()
  307. (if buffer-read-only (send-string-to-terminal "\033[2 q")
  308. (send-string-to-terminal "\033[5 q"))
  309. ))
  310. (defun show-cursor()
  311. "Display the cursor"
  312. (interactive)
  313. (send-string-to-terminal "\033[1 q")
  314. (run-at-time 5 nil
  315. (lambda() (send-string-to-terminal "\033[5 q"))
  316. ))
  317. (global-set-key [f10] 'show-cursor)
  318. ;; Use the mouse in the terminal
  319. (xterm-mouse-mode)
  320. (progn
  321. ;; gnome-terminal / xfce
  322. (define-key input-decode-map "\e[1;5C" [(control right)])
  323. (define-key input-decode-map "\e[1;5D" [(control left)])
  324. (define-key input-decode-map "\e[1;5A" [(control up)])
  325. (define-key input-decode-map "\e[1;5B" [(control down)])
  326. (define-key input-decode-map "\e[1;5H" [(control home)])
  327. (define-key input-decode-map "\e[1;5F" [(control end)])
  328. (define-key input-decode-map "\e[3;5~" [(control deletechar)])
  329. ;;
  330. (define-key input-decode-map "\e[1;2C" [(shift right)])
  331. (define-key input-decode-map "\e[1;2D" [(shift left)])
  332. (define-key input-decode-map "\e[1;2A" [(shift up)])
  333. (define-key input-decode-map "\e[1;2B" [(shift down)])
  334. (define-key input-decode-map "\e[1;2F" [(shift end)])
  335. (define-key input-decode-map "\e[1;2H" [(shift home)])
  336. (define-key input-decode-map "\e[3;2~" [(shift deletechar)])
  337. ;;
  338. (define-key input-decode-map "\e[1;3C" [(meta right)])
  339. (define-key input-decode-map "\e[1;3D" [(meta left)])
  340. (define-key input-decode-map "\e[1;3A" [(meta up)])
  341. (define-key input-decode-map "\e[1;3B" [(meta down)])
  342. (define-key input-decode-map "\e[1;3H" [(meta home)])
  343. (define-key input-decode-map "\e[1;3F" [(meta end)])
  344. ;;
  345. (define-key input-decode-map "\e[1;6C" [(control shift right)])
  346. (define-key input-decode-map "\e[1;6D" [(control shift left)])
  347. (define-key input-decode-map "\e[1;6A" [(control shift up)])
  348. (define-key input-decode-map "\e[1;6B" [(control shift down)])
  349. (define-key input-decode-map "\e[1;6H" [(control shift home)])
  350. (define-key input-decode-map "\e[1;6F" [(control shift end)])
  351. (define-key input-decode-map "\e[3;5~" [(control shift delete)])
  352. ;;
  353. (define-key input-decode-map "\e[1;7C" [(control alt right)])
  354. (define-key input-decode-map "\e[1;7D" [(control alt left)])
  355. (define-key input-decode-map "\e[1;7A" [(control alt up)])
  356. (define-key input-decode-map "\e[1;7B" [(control alt down)])
  357. (define-key input-decode-map "\e[1;7H" [(control alt home)])
  358. (define-key input-decode-map "\e[1;7F" [(control alt end)])
  359. (define-key input-decode-map "\e[3;7~" [(control alt delete)])
  360. ;;
  361. (define-key input-decode-map "\e[5;2~" [(shift prior)])
  362. (define-key input-decode-map "\e[6;2~" [(shift next)])
  363. (define-key input-decode-map "\e[5;5~" [(control prior)])
  364. (define-key input-decode-map "\e[6;5~" [(control next)])
  365. (define-key input-decode-map "\e[5;3~" [(meta prior)])
  366. (define-key input-decode-map "\e[6;3~" [(meta next)])
  367. )
  368. ;; Other keys binding
  369. ;; cursor keys
  370. (define-key function-key-map "\eOH" [home])
  371. (define-key function-key-map "\eOF" [end])
  372. ;; default configuration for home & end key
  373. (global-set-key [home] 'beginning-of-line)
  374. (global-set-key [end] 'end-of-line)
  375. ;; fix select/ to home/end keys
  376. (global-set-key [find] 'beginning-of-line)
  377. (global-set-key [select] 'end-of-line)
  378. ;; Scroll the buffer with arrow keys
  379. (global-set-key [C-up] 'scroll-down-line)
  380. (global-set-key [C-down] 'scroll-up-line)
  381. ;; Same with the mouse
  382. (global-set-key [mouse-4] '(lambda() (interactive) (scroll-down-line 3)))
  383. (global-set-key [mouse-5] '(lambda() (interactive) (scroll-up-line 3)))
  384. (global-set-key [S-mouse-4] '(lambda () (interactive) (scroll-down 9)))
  385. (global-set-key [S-mouse-5] '(lambda () (interactive) (scroll-up 9)))
  386. )
  387. ;; Flyspell settings ================================================================================
  388. (defun init-environment-flyspell()
  389. "Initialise spelling check mode."
  390. (interactive)
  391. (setq ispell-program-name "aspell"
  392. ;; force the English dictionary, support Camel Case spelling check (tested with aspell 0.6)
  393. ispell-extra-args '(
  394. "--sug-mode=ultra"
  395. "--lang=en_GB"
  396. "--run-together"
  397. "--run-together-limit=5"
  398. "--run-together-min=2")
  399. )
  400. (set-face-foreground 'flyspell-incorrect "red")
  401. (set-face-background 'flyspell-incorrect nil)
  402. (set-face-attribute 'flyspell-incorrect nil :weight 'normal)
  403. (set-face-attribute 'flyspell-incorrect nil :slant 'italic)
  404. (set-face-underline 'flyspell-incorrect "red")
  405. (set-face-foreground 'flyspell-duplicate nil)
  406. (set-face-background 'flyspell-duplicate nil)
  407. (set-face-attribute 'flyspell-duplicate nil :weight 'normal)
  408. (set-face-attribute 'flyspell-duplicate nil :slant 'italic)
  409. (set-face-underline 'flyspell-duplicate nil)
  410. )
  411. ;; Generic programming mode =========================================================================
  412. (defun init-environment-coding()
  413. "Initialise coding environment settings."
  414. (interactive)
  415. ;; Line numbers mode (Emacs >= 26)
  416. (display-line-numbers-mode)
  417. ;; always display line numbers
  418. (column-number-mode 1)
  419. (line-number-mode 1)
  420. ;; Display parenthesis
  421. (show-paren-mode 1)
  422. (setq show-paren-delay 0)
  423. (set-face-foreground 'show-paren-match nil)
  424. (set-face-inverse-video 'show-paren-match nil)
  425. (set-face-underline 'show-paren-match nil)
  426. (set-face-background 'show-paren-match nil)
  427. (set-face-attribute 'show-paren-match nil :weight 'bold)
  428. ;; FlyCheck mode
  429. (require 'flycheck)
  430. (flycheck-mode)
  431. (if (display-graphic-p)
  432. (require 'flycheck-status-emoji)
  433. (flycheck-status-emoji-mode))
  434. (require 'paren)
  435. (require 'ws-butler)
  436. (require 'hl-todo)
  437. (setq auto-indent-blank-lines-on-move nil)
  438. (standard-display-ascii ?\t " →")
  439. (hl-todo-mode)
  440. ;; Hide/Show blocks
  441. (require 'hideshow)
  442. (global-set-key [M-left] 'hs-hide-block)
  443. (global-set-key [M-right] 'hs-show-block)
  444. ;; Incrementaly select blocks
  445. (global-set-key (kbd "C-@") 'er/expand-region)
  446. )
  447. ;; Jabber / Google talk =============================================================================
  448. (defun init-jabber()
  449. (interactive)
  450. (require 'jabber)
  451. (require 'jabber-otr)
  452. (setq jabber-account-list
  453. '(("andre@rodier.me"
  454. ;;(:password . "*******")
  455. (:network-server . "xmpp.rodier.me")
  456. (:port . 5222)
  457. (:connection-type . tls)
  458. )
  459. )
  460. )
  461. )
  462. ;; CSS ==============================================================================================
  463. (add-hook 'css-mode-hook 'css-mode-init)
  464. (defun css-mode-init ()
  465. "Initialise CSS edition mode."
  466. (define-key css-mode-map "\M-\C-x" 'slime-js-refresh-css)
  467. (define-key css-mode-map "\C-c\C-r" 'slime-js-embed-css)
  468. )
  469. ;; Debian preseed files =============================================================================
  470. (require 'preseed-generic-mode)
  471. (add-to-list
  472. 'auto-mode-alist
  473. '("\\.preseed\\'" . preseed-generic-mode)
  474. )
  475. ;; Debian preseed files =============================================================================
  476. (add-hook 'preseed-generic-mode-hook 'preseed-mode-init)
  477. (defun preseed-mode-init ()
  478. (display-line-numbers-mode)
  479. )
  480. ;; Puppet mode ======================================================================================
  481. (remove-hook 'puppet-mode-hook nil)
  482. (add-hook 'puppet-mode-hook 'puppet-mode-init)
  483. (defun puppet-mode-init ()
  484. (display-line-numbers-mode)
  485. (flymake-mode)
  486. (flymake-puppet-load)
  487. )
  488. ;; Sieve filter files =============================================================================
  489. (defun sieve-mode-init ()
  490. "Initialise sieve mode"
  491. (interactive)
  492. (display-line-numbers-mode)
  493. )
  494. (add-hook 'sieve-generic-mode-hook 'sieve-mode-init)
  495. ;; Markdown files =================================================================================
  496. (setq markdown-mode-hook nil)
  497. (defun markdown-mode-init ()
  498. "Initialise markdown mode"
  499. (interactive)
  500. (message "Markdown mode initialised")
  501. (auto-fill-mode 't)
  502. (setq fill-column 120)
  503. (display-line-numbers-mode)
  504. (display-fill-column-indicator-mode 't)
  505. (flyspell-mode 't)
  506. (init-general)
  507. )
  508. (add-hook 'markdown-mode-hook 'markdown-mode-init)
  509. ;; HTML =============================================================================================
  510. (defun html-mode-init ()
  511. "Initialise HTML mode."
  512. (interactive)
  513. ;; Ensure 4 spaces for HTML mode
  514. (setq c-basic-offset 4)
  515. (use-package html-check-frag)
  516. (html-check-frag-mode)
  517. (require 'tagedit)
  518. (tagedit-add-experimental-features)
  519. (tagedit-mode)
  520. ;; Ensure 4 spaces for HTML mode
  521. (setq sgml-basic-offset 4)
  522. (setq-local sgml-basic-offset 4)
  523. ;; Require ac-haml since we are setup haml auto completion
  524. (require 'ac-haml)
  525. ;; Require default data provider if you want to use
  526. (require 'ac-html-default-data-provider)
  527. ;; Enable data providers,
  528. ;; currently only default data provider available
  529. (ac-html-enable-data-provider 'ac-html-default-data-provider)
  530. ;; Let ac-haml do some setup
  531. (ac-haml-setup)
  532. ;; Set your ac-source
  533. (setq ac-sources '(ac-source-html-tag
  534. ac-source-html-attr
  535. ac-source-html-attrv))
  536. ;; Enable auto complete mode
  537. (auto-complete-mode)
  538. (ac-config-default)
  539. (setq ac-auto-start t)
  540. (setq ac-delay 0.1)
  541. (setq ac-auto-show-menu t)
  542. (setq ac-show-menu-immediately-on-auto-complete t)
  543. (setq ac-trigger-key "TAB")
  544. ;; Try again to force the timer
  545. (run-at-time "1 sec" nil (lambda ()
  546. (message "HTML Mode initialised")
  547. (setq sgml-basic-offset 4)
  548. (setq-local sgml-basic-offset 4)
  549. )
  550. )
  551. (ac-html-angular+)
  552. )
  553. (add-hook 'html-mode-hook 'html-mode-init)
  554. ;; Diminish (hide minor modes) ======================================================================
  555. (defun diminish-modes()
  556. "Minimise the minor modes area."
  557. (interactive)
  558. (use-package diminish)
  559. (diminish 'auto-complete-mode (propertize "→ " 'face 'mode-line-emphasis))
  560. (diminish 'hs-minor-mode (propertize "± " 'face 'mode-line-emphasis))
  561. (diminish 'flycheck-mode (propertize "✓ " 'face 'mode-line-emphasis))
  562. (diminish 'flyspell-mode (propertize "ß " 'face 'mode-line-emphasis))
  563. (diminish 'yas-minor-mode (propertize "" 'face 'mode-line-emphasis))
  564. (diminish 'encourage-mode (propertize "☺ " 'face 'mode-line-emphasis))
  565. (diminish 'auto-indent-mode (propertize "⇆ " 'face 'mode-line-emphasis))
  566. (diminish 'overwrite-mode (propertize "⊠ " 'face 'mode-line-emphasis))
  567. (diminish 'eldoc-mode (propertize "⛳ " 'face 'mode-line-emphasis))
  568. (diminish 'git-gutter-mode (propertize "⌥ " 'face 'mode-line-emphasis))
  569. (diminish 'auto-fill-mode (propertize "⏎ " 'face 'mode-line-emphasis))
  570. (diminish 'auto-revert-mode (propertize "↺ " 'face 'mode-line-emphasis))
  571. ;; javascript
  572. (diminish 'js2-refactor-mode (propertize "" 'face 'mode-line-emphasis))
  573. (diminish 'tern-mode (propertize "" 'face 'mode-line-emphasis))
  574. )
  575. ;; Slack functions ==================================================================================
  576. (defun init-slack()
  577. "Initiailse slack functions, sample values, unused."
  578. (interactive)
  579. (require 'log4e)
  580. (require 'slack)
  581. (require 'emojify)
  582. (require 'alert)
  583. (require 'websocket)
  584. (require 'request)
  585. (require 'oauth2)
  586. (require 'circe)
  587. (use-package slack
  588. :commands (slack-start)
  589. :init
  590. (setq slack-buffer-emojify t) ;; if you want to enable emoji, default nil
  591. (setq slack-prefer-current-team t)
  592. :config
  593. (slack-register-team
  594. :name "emacs-slack"
  595. :default t
  596. :client-id "102803899024.104339549506"
  597. :client-secret "7d716b50ad70bffef1b827929ca877bc"
  598. :token "xoxp-102803899024-102835239505-104416141204-3944fa01e34e84e8ab1a198660b5f746"
  599. ;; :subscribed-channels '()
  600. )
  601. )
  602. )
  603. ;; Markdown ==========================================================================================
  604. (require 'html-check-frag)
  605. (add-to-list
  606. 'auto-mode-alist
  607. '("\\.md\\'" . markdown-mode)
  608. )
  609. ;; SSH config ========================================================================================
  610. (defun init-environment-admin()
  611. "Used for administration."
  612. (interactive)
  613. (autoload 'ssh-config-mode "ssh-config-mode" t)
  614. (add-to-list 'auto-mode-alist '(".ssh/config\\'" . ssh-config-mode))
  615. (add-to-list 'auto-mode-alist '("sshd?_config\\'" . ssh-config-mode))
  616. (add-to-list 'auto-mode-alist '("known_hosts\\'" . ssh-known-hosts-mode))
  617. (add-to-list 'auto-mode-alist '("authorized_keys2?\\'" . ssh-authorized-keys-mode))
  618. (add-hook 'ssh-config-mode-hook 'turn-on-font-lock)
  619. )
  620. ;; Lisp related =====================================================================================
  621. (defun init-environment-lisp()
  622. "Initialise Lisp functions."
  623. (interactive)
  624. (defun lisp-mode-init ()
  625. (setq lisp-indent-offset 2)
  626. (global-set-key "\C-_" 'eval-region)
  627. (auto-complete-mode)
  628. (display-line-numbers-mode)
  629. )
  630. (init-environment-coding)
  631. (add-hook 'lisp-mode-hook 'lisp-mode-init)
  632. (add-hook 'el-mode-hook 'lisp-mode-init)
  633. (add-hook 'emacs-lisp-mode-hook 'lisp-mode-init)
  634. (display-line-numbers-mode 't)
  635. (auto-complete-mode 't)
  636. )
  637. ;; SQL Modes ========================================================================================
  638. (add-hook 'sql-mode-hook 'sql-mode-init)
  639. (defun sql-mode-init ()
  640. "Initialise SQL mode."
  641. (display-line-numbers-mode)
  642. )
  643. ;; LDIF Modes ========================================================================================
  644. (add-hook 'ldif-mode-hook 'ldif-mode-init)
  645. (defun ldif-mode-init ()
  646. "Initialise LDIF mode."
  647. (display-line-numbers-mode)
  648. )
  649. ;; JavaScript related ===============================================================================
  650. (defun init-environment-js()
  651. "Initialise Javascript mode."
  652. (interactive)
  653. (init-environment-coding)
  654. ;; required librairies
  655. (require 'js2-refactor)
  656. (require 'js-comint)
  657. ;; Autocomplete
  658. (require 'tern)
  659. (eval-after-load 'tern
  660. '(progn
  661. (require 'tern-auto-complete)
  662. (tern-ac-setup))
  663. )
  664. ;; JS doc files
  665. (setq js-doc-mail-address "andre@rodier.me"
  666. js-doc-author (format "André Rodier <%s>" js-doc-mail-address)
  667. js-doc-url "http://github.com/arodier"
  668. js-doc-license "GPLv3")
  669. (defun js2-mode-init ()
  670. (setq js2-basic-offset 4)
  671. (flyspell-prog-mode)
  672. (auto-complete-mode t)
  673. (tern-mode t)
  674. (js2-refactor-mode)
  675. (js2r-add-keybindings-with-prefix "C-c C-m")
  676. (setq js2-indent-switch-body t)
  677. (js2-minor-mode)
  678. (setq js2-include-jslint-globals t)
  679. (setq js2-include-node-externs t)
  680. ;; Show trailing spaces & tabs
  681. (show-ws-toggle-show-trailing-whitespace)
  682. (show-ws-toggle-show-tabs)
  683. ;; Run mocha tests
  684. (setq mocha-command "/usr/bin/mocha")
  685. (setq mocha-options "--no-timeouts --no-colors --reporter min")
  686. (define-key js2-mode-map "\C-d" 'js-doc-insert-function-doc)
  687. (define-key js2-mode-map "@" 'js-doc-insert-tag)
  688. (global-set-key [f5] 'slime-js-reload)
  689. ;;(slime-js-minor-mode 1)
  690. (setq js2-include-jslint-globals t)
  691. (setq js2-include-node-externs t)
  692. ;;
  693. (idle-highlight-mode)
  694. (setq-local helm-dash-docsets '("NodeJS"))
  695. (add-node-modules-path)
  696. ;; Snippets
  697. (yas-reload-all)
  698. (local-set-key "\C-x\C-e" 'js-send-last-sexp)
  699. (local-set-key "\C-\M-x" 'js-send-last-sexp-and-go)
  700. (local-set-key "\C-cb" 'js-send-buffer)
  701. (local-set-key "\C-c\C-b" 'js-send-buffer-and-go)
  702. (local-set-key "\C-cl" 'js-load-file-and-go)
  703. (tern-ac-setup)
  704. (setq inferior-js-program-command "node-debug index.js <args>")
  705. (setq inferior-js-mode-hook
  706. (lambda ()
  707. ;; We like nice colors
  708. (ansi-color-for-comint-mode-on)
  709. ;; Deal with some prompt nonsense
  710. (add-to-list
  711. 'comint-preoutput-filter-functions
  712. (lambda (output)
  713. (replace-regexp-in-string "\033\\[[0-9]+[GK]" "" output)))))
  714. )
  715. (add-hook 'js2-mode-hook 'js2-mode-init)
  716. (add-to-list
  717. 'auto-mode-alist
  718. '("\\.js\\'" . js2-mode)
  719. )
  720. )
  721. ;; TypeScript related ===============================================================================
  722. (defun init-environment-typescript()
  723. "Used for typescript."
  724. (interactive)
  725. (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode-init))
  726. (defun typescript-mode-init ()
  727. (typescript-mode)
  728. (setq tab-width 4)
  729. (standard-display-ascii ?\t " ")
  730. (tss-setup-current-buffer)
  731. (setq-local helm-dash-docsets '("Typescript"))
  732. )
  733. )
  734. ;; Python Related ======================================================================================
  735. (defun init-environment-python()
  736. "Python environment initialisation."
  737. (interactive)
  738. (add-to-list
  739. 'auto-mode-alist
  740. '("\\.py\\'" . python-mode-init)
  741. )
  742. (defun python-mode-init ()
  743. ;; Common to programming
  744. (init-environment-coding)
  745. ;; Language related
  746. (require 'company-quickhelp)
  747. (require 'pymacs)
  748. (require 'jedi)
  749. (display-line-numbers-mode t)
  750. ;;(auto-complete-mode nil)
  751. (company-mode t)
  752. (company-quickhelp-mode t)
  753. (setq auto-indent-blank-lines-on-move nil)
  754. (yas-global-mode 0)
  755. (setq python-indent 4)
  756. (setq python-offset 4)
  757. (setq-default python-indent-offset 4)
  758. (setq-default python-offset 4)
  759. (setq-default python-indent-offset 4)
  760. (setq jedi:complete-on-dot t)
  761. )
  762. (add-hook 'python-mode-hook 'python-mode-init)
  763. (add-hook 'python-mode-hook 'jedi:setup)
  764. )
  765. ;; Go language ======================================================================================
  766. (defun init-environment-go()
  767. "Go programming environment initialisation."
  768. (interactive)
  769. (defun go-mode-init ()
  770. (interactive)
  771. (init-environment-coding)
  772. (require 'auto-complete-config)
  773. (require 'go-autocomplete)
  774. (require 'company)
  775. (require 'company-quickhelp)
  776. (require 'golint)
  777. (company-mode t)
  778. (company-quickhelp-mode t)
  779. (ac-config-default)
  780. (setq c-basic-offset 4)
  781. (setq tab-width 4)
  782. (standard-display-ascii ?\t " »")
  783. (setq-default indent-tabs-mode nil)
  784. (setq auto-indent-blank-lines-on-move nil)
  785. ;;(auto-complete-mode 1)
  786. ;;(add-to-list 'ac-sources 'ac-source-go)
  787. ;;(call-process "gocode" nil nil nil "-s")
  788. ;;(add-to-list 'load-path (concat (getenv "GOPATH") "/src/github.com/golang/lint/misc/emacs"))
  789. (setq-local helm-dash-docsets '("Go"))
  790. )
  791. (add-hook 'go-mode-hook 'go-mode-init)
  792. )
  793. ;; Makefiles ========================================================================================
  794. (add-hook 'makefile-mode-hook 'makefile-mode-init)
  795. (defun makefile-mode-init ()
  796. "Initialise makefile mode."
  797. (setq tab-width 4)
  798. (standard-display-ascii ?\t " →")
  799. (display-line-numbers-mode)
  800. )
  801. ;; JSON Modes =======================================================================================
  802. (add-to-list 'auto-mode-alist '("\\.json\\'" . json-mode))
  803. ;; YAML Modes =======================================================================================
  804. (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
  805. (remove-hook 'yaml-mode-hook nil)
  806. (defun yaml-mode-init ()
  807. "Yaml mode edition environment."
  808. (interactive)
  809. (init-environment-coding)
  810. (outline-minor-mode)
  811. ;; (define-key yaml-mode-map (kbd "TAB") 'outline-toggle-children)
  812. ;; (setq outline-regexp "^- [A-Za-z0-9_-]*: .*")
  813. )
  814. (add-hook 'yaml-mode-hook 'yaml-mode-init)
  815. ;; Configuration files ==============================================================================
  816. (defun conf-mode-init ()
  817. "Configuration file edition environment."
  818. (interactive)
  819. (init-environment-coding)
  820. )
  821. (add-hook 'conf-mode-hook 'conf-mode-init)
  822. (add-to-list
  823. 'auto-mode-alist
  824. '("\\.inc\\'" . conf-mode)
  825. )
  826. ;; systemd config files =============================================================================
  827. ;; systemd-mode is not working locally (systemd-analyze errors)
  828. (add-to-list
  829. 'auto-mode-alist
  830. '("\\.systemd\\'" . ini-mode)
  831. )
  832. ;; PHP Related ======================================================================================
  833. (defun init-environment-php()
  834. "Initialise PHP coding mode."
  835. (interactive)
  836. (add-to-list
  837. 'auto-mode-alist
  838. '("\\.php\\'" . php-mode)
  839. )
  840. (defun php-mode-init ()
  841. (display-line-numbers-mode)
  842. (auto-complete-mode t)
  843. (setq auto-indent-blank-lines-on-move nil)
  844. (require 'geben)
  845. (setq ac-sources '(ac-source-php) )
  846. (yas-global-mode 0)
  847. ;;(define-key php-mode-map (kbd "C-]") 'ac-php-find-symbol-at-point) ;goto define
  848. ;;(define-key php-mode-map (kbd "C-t") 'ac-php-location-stack-back ) ;go back
  849. ;; Debug a simple PHP script.
  850. ;; Change the session key my-php-54 to any session key text you like
  851. (setq c-basic-offset 4) ; Ensure 4 spaces for Javascript mode
  852. (setq php-mode-indent-level 4) ; Ensure 4 spaces for Javascript mode
  853. (defun my-php-debug ()
  854. "Run current PHP script for debugging with geben"
  855. (interactive)
  856. (call-interactively 'geben)
  857. (shell-command
  858. (concat "XDEBUG_CONFIG='idekey=my-php-54' /usr/bin/php "
  859. (buffer-file-name) " &"))
  860. )
  861. (global-set-key [f5] 'my-php-debug)
  862. (defun ywb-php-lineup-arglist-intro (langelem)
  863. (save-excursion
  864. (goto-char (cdr langelem))
  865. (vector (+ (current-column) c-basic-offset))))
  866. (defun ywb-php-lineup-arglist-close (langelem)
  867. (save-excursion
  868. (goto-char (cdr langelem))
  869. (vector (current-column))))
  870. (c-set-offset 'arglist-intro 'ywb-php-lineup-arglist-intro)
  871. (c-set-offset 'arglist-close 'ywb-php-lineup-arglist-close)
  872. (setq c-default-style "bsd"
  873. c-basic-offset 4)
  874. )
  875. (add-hook 'php-mode-hook 'php-mode-init)
  876. )
  877. ;; Epub docs read ===================================================================================
  878. (setq auto-mode-alist
  879. (append
  880. (list
  881. '("\\.epub$" . archive-mode))
  882. auto-mode-alist))
  883. (setq auto-coding-alist
  884. (append
  885. (list
  886. '("\\.epub$" . no-conversion))
  887. auto-coding-alist))
  888. ;; Configure magit modules ==========================================================================
  889. (require 'magit-gitflow)
  890. (add-hook 'magit-mode-hook 'turn-on-magit-gitflow)
  891. ;; Git gutter mode ==================================================================================
  892. (use-package git-gutter)
  893. (defun git-blame-line ()
  894. "Runs `git blame` on the current line and adds the commit id to the kill ring."
  895. (interactive)
  896. (let* ((line-number (save-excursion
  897. (goto-char (point-at-bol))
  898. (+ 1 (count-lines 1 (point)))))
  899. (line-arg (format "%d,%d" line-number line-number))
  900. (commit-buf (generate-new-buffer "*git-blame-line-commit*")))
  901. (call-process "git" nil commit-buf nil
  902. "blame" (buffer-file-name) "-L" line-arg)
  903. (let* ((commit-id (with-current-buffer commit-buf
  904. (buffer-substring 1 9)))
  905. (log-buf (generate-new-buffer "*git-blame-line-log*")))
  906. (kill-new commit-id)
  907. (call-process "git" nil log-buf nil
  908. "log" "-1" "--pretty=%h %an %s" commit-id)
  909. (with-current-buffer log-buf
  910. (message "Line %d: %s" line-number (buffer-string)))
  911. (kill-buffer log-buf))
  912. (kill-buffer commit-buf)))
  913. (global-set-key (kbd "C-x C-g") 'git-gutter-mode)
  914. (global-set-key (kbd "C-x v =") 'git-gutter:popup-hunk)
  915. ;; Jump to next/previous hunk
  916. (global-set-key (kbd "C-x p") 'git-gutter:previous-hunk)
  917. (global-set-key (kbd "C-x n") 'git-gutter:next-hunk)
  918. ;; Stage current hunk
  919. (global-set-key (kbd "C-x v s") 'git-gutter:stage-hunk)
  920. ;; Revert current hunk
  921. (global-set-key (kbd "C-x v r") 'git-gutter:revert-hunk)
  922. (defun git-gutter-setup()
  923. "Better git-gutter macros."
  924. (interactive)
  925. ;; If you enable global minor mode
  926. ;;(global-git-gutter-mode t)
  927. (setq git-gutter:always-show-separator t)
  928. (setq git-gutter:always-show-gutter t)
  929. (setq git-gutter:hide-no-change nil)
  930. (setq git-gutter:hide-gutter nil)
  931. (setq git-gutter:linum-enabled nil)
  932. (setq git-gutter:diff-option " -w ")
  933. ;;
  934. (setq git-gutter:modified-sign "⊛")
  935. (set-face-foreground 'git-gutter:modified "orange")
  936. (set-face-background 'git-gutter:modified nil)
  937. (set-face-inverse-video 'git-gutter:modified nil)
  938. (set-face-attribute 'git-gutter:modified nil :weight 'normal)
  939. (set-face-underline 'git-gutter:modified nil)
  940. ;;
  941. (setq git-gutter:added-sign "⊕")
  942. (set-face-foreground 'git-gutter:added "green")
  943. (set-face-background 'git-gutter:added nil)
  944. (set-face-inverse-video 'git-gutter:added nil)
  945. (set-face-attribute 'git-gutter:added nil :weight 'normal)
  946. (set-face-underline 'git-gutter:added nil)
  947. ;;
  948. (setq git-gutter:deleted-sign "⊝")
  949. (set-face-foreground 'git-gutter:deleted "red")
  950. (set-face-background 'git-gutter:deleted nil)
  951. (set-face-inverse-video 'git-gutter:deleted nil)
  952. (set-face-attribute 'git-gutter:deleted nil :weight 'normal)
  953. (set-face-underline 'git-gutter:deleted nil)
  954. ;;
  955. (set-face-background 'git-gutter:separator nil)
  956. (set-face-foreground 'git-gutter:separator nil)
  957. ;;
  958. (setq git-gutter:window-width 1)
  959. ;;
  960. (setq git-gutter:unchanged-sign nil)
  961. ;;
  962. (set-face-foreground 'git-gutter:unchanged nil)
  963. (set-face-background 'git-gutter:unchanged nil)
  964. (set-face-attribute 'git-gutter:unchanged nil :underline nil :bold nil)
  965. (set-face-underline 'git-gutter:unchanged nil)
  966. )
  967. (defun git-gutter-setup-window()
  968. "Initialise git gutter mode in graphical environment."
  969. (interactive)
  970. (global-git-gutter-mode t)
  971. (setq git-gutter:always-show-separator t)
  972. (setq git-gutter:always-show-gutter t)
  973. (setq git-gutter:hide-no-change nil)
  974. (setq git-gutter:hide-gutter nil)
  975. (setq git-gutter:diff-option " -w ")
  976. ;;
  977. (set-face-foreground 'git-gutter:modified "inherit")
  978. (set-face-background 'git-gutter:modified "inherit")
  979. (set-face-inverse-video 'git-gutter:modified nil)
  980. (set-face-attribute 'git-gutter:modified nil :weight 'bold)
  981. (set-face-underline 'git-gutter:modified nil)
  982. ;;
  983. (set-face-foreground 'git-gutter:added "inherit")
  984. (set-face-background 'git-gutter:added "inherit")
  985. (set-face-inverse-video 'git-gutter:added nil)
  986. (set-face-attribute 'git-gutter:added nil :weight 'bold)
  987. (set-face-underline 'git-gutter:added nil)
  988. ;;
  989. (set-face-foreground 'git-gutter:deleted "inherit")
  990. (set-face-background 'git-gutter:deleted "inherit")
  991. (set-face-inverse-video 'git-gutter:deleted nil)
  992. (set-face-attribute 'git-gutter:deleted nil :weight 'bold)
  993. (set-face-underline 'git-gutter:deleted nil)
  994. ;;
  995. (setq git-gutter:window-width 3)
  996. ;;
  997. (setq git-gutter:modified-sign "~")
  998. (setq git-gutter:added-sign "+")
  999. (setq git-gutter:deleted-sign "-")
  1000. (setq git-gutter:unchanged-sign " ")
  1001. (set-face-foreground 'git-gutter:unchanged "inherit")
  1002. (set-face-background 'git-gutter:unchanged "inherit")
  1003. (set-face-attribute 'git-gutter:unchanged nil :underline nil :bold nil)
  1004. (set-face-underline 'git-gutter:unchanged nil)
  1005. ;; (git-gutter:hide-gutter nil)
  1006. )
  1007. ;; C# related =======================================================================================
  1008. (defun init-environment-dotnet()
  1009. "Initialise .net / C# programming mode."
  1010. (interactive)
  1011. (autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
  1012. (setq auto-mode-alist
  1013. (append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
  1014. ;; Optionally, define and register a mode-hook function. To do so, use
  1015. ;; something like this in your .emacs file:
  1016. (defun my-csharp-mode-fn ()
  1017. "function that runs when csharp-mode is initialized for a buffer."
  1018. (require 'omnisharp-utils)
  1019. (require 'omnisharp-server-actions)
  1020. (require 'omnisharp-auto-complete-actions)
  1021. (require 'omnisharp-settings)
  1022. (turn-on-auto-revert-mode)
  1023. (setq indent-tabs-mode nil)
  1024. )
  1025. (add-hook 'csharp-mode-hook 'my-csharp-mode-fn t)
  1026. (add-to-list 'load-path
  1027. (expand-file-name
  1028. (concat (file-name-directory (or load-file-name buffer-file-name)) "/src/actions")
  1029. )
  1030. )
  1031. (add-to-list 'load-path
  1032. (expand-file-name
  1033. (concat (file-name-directory (or load-file-name buffer-file-name)) "/src/")
  1034. ))
  1035. )
  1036. ;; Shell scripts ====================================================================================
  1037. (require 'flymake)
  1038. (require 'flymake-shell)
  1039. (require 'flymake-shellcheck)
  1040. (require 'flymake-easy)
  1041. (remove-hook 'sh-mode-hook nil)
  1042. (defun shell-mode-init ()
  1043. "Shell script mode initialisation."
  1044. (interactive)
  1045. (display-line-numbers-mode)
  1046. (auto-complete-mode)
  1047. (hl-todo-mode)
  1048. (flymake-mode)
  1049. (flymake-shell-load)
  1050. (flyspell-prog-mode)
  1051. )
  1052. (add-hook 'sh-mode-hook 'shell-mode-init)
  1053. (add-hook 'sh-mode-hook 'flymake-shellcheck-load)
  1054. ;; Docker files =====================================================================================
  1055. (add-to-list
  1056. 'auto-mode-alist
  1057. '("\\.runit\\'" . dockerfile-mode)
  1058. )
  1059. (defun docker-mode-init ()
  1060. "Intitialise docer files edition mode."
  1061. (display-line-numbers-mode)
  1062. )
  1063. (add-hook 'dockerfile-mode-hook 'docker-mode-init)
  1064. ;; Text mode initialisation
  1065. (unless (display-graphic-p)
  1066. (progn
  1067. (init-general)
  1068. (init-console)
  1069. ;; Not use full width to display minor modes
  1070. (diminish-modes)
  1071. (set-face-background 'vertical-border (face-foreground 'window-divider))
  1072. (set-face-foreground 'vertical-border (face-background 'vertical-border))
  1073. (powerline-default-theme)
  1074. ))
  1075. ;; Graphic mode initialisation
  1076. (if (display-graphic-p)
  1077. (progn
  1078. (init-general)
  1079. (init-window)
  1080. ))