mirror of https://github.com/Chizi123/.emacs.d.git

Chizi123
2019-06-10 0864ffaba6e44e8fc49f9871adb1200cc0885f9e
commit | author | age
990949 1 #+TITLE: My Emacs configuration
20e001 2 #  LocalWords:  poppler mingw emacs eq nt gnuplot setenv mapconcat el cond minibuffer pdf color Smartparens smartparens yas aindent whitespace eldoc ielm ibuffer hippie pscp pos Spaceline spaceline powerline spacemacs seperator dir Yasnippet yasnippet flycheck magit fullscreen CEDET askifnotset semanticdb EDE ede gdb srefactor analyzer eval cdb autosetup ghostscript math unicode reftex bibtex TeXcount texcount str latin rkt PlantUML plantuml autoload alist matlab verilog ds vh src fontify natively fortran dvipng plist xcolor EXWM Zenburn setq zenburn defun dolist init config DejaVu ispell aspell flyspell kbd recentf sexp ov bg listp defadvice progn prog keyfreq autosave dabbrev hl gc linum linux utf RET ARG arg configs backends contribs AucTex tex auctex LaTeX url
8a38cc 3
990949 4 * Windows dependencies
C 5 Dependencies needed for Aspell, poppler PDF-tools, compilers and ghost-script provided by mingw64
6 #+BEGIN_SRC emacs-lisp
7   (when (eq system-type 'windows-nt)
8     (add-to-list 'exec-path "C:/msys64/usr/bin")
9     (add-to-list 'exec-path "C:/msys64/mingw64/bin")
10     (add-to-list 'exec-path "c:/Program Files/gnuplot")
11     (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
12 #+END_SRC
13
14 * Aesthetic changes
0fcc09 15 ** Emacs theme
C 16 Zenburn theme is the default
990949 17 #+BEGIN_SRC emacs-lisp
0fcc09 18   (setq emacs-theme 'zenburn)
C 19
412080 20   (defun disable-all-themes ()
C 21     (dolist (i custom-enabled-themes)
22       (disable-theme i)))
23
0fcc09 24   (cond ((eq emacs-theme 'zenburn)
C 25          (use-package zenburn-theme
26            :ensure t
412080 27            :init
C 28            (disable-all-themes)
0fcc09 29            :config
C 30            (load-theme 'zenburn t)))
31         ((eq emacs-theme 'doom-one)
32          (use-package doom-themes
33            :ensure t
412080 34            :init
C 35            (disable-all-themes)
0fcc09 36            :config
C 37            (setq doom-themes-enable-bolt t
38                  doom-themes-enable-italic t)
39            (load-theme 'doom-one t)
40            (doom-themes-visual-bell-config)
412080 41            (doom-themes-org-config)))
C 42         ((eq emacs-theme 'none)
43          (disable-all-themes)))
990949 44 #+END_SRC
8a38cc 45
990949 46 ** Default font
20e001 47 #+BEGIN_SRC emacs-lisp 
C 48   ;;(set-frame-font "DejaVu Sans Mono" nil t)
49   (set-frame-font "Dank Mono-11" nil t)
50   (set-face-italic 'font-lock-comment-face t)
51   (set-face-italic 'font-lock-keyword-face t)
990949 52 #+END_SRC
8a38cc 53
990949 54 ** Remove menu bar, toolbar, but keep scroll bar
C 55 #+BEGIN_SRC emacs-lisp
56   (menu-bar-mode 0)
57   (tool-bar-mode 0)
58   (scroll-bar-mode 1)
59 #+END_SRC
60
61 * Writing requirements
62 ** Spellchecking
63 #+BEGIN_SRC emacs-lisp
64   (require 'ispell)
65   (setq-default ispell-program-name "aspell")
66   (setq-default ispell-local-dictionary "en_AU")
67   (add-hook 'latex-mode-hook 'flyspell-mode)
68   (add-hook 'latex-mode-hook 'flyspell-buffer)
69   (add-hook 'org-mode-hook 'flyspell-mode)
70   (add-hook 'org-mode-hook 'flyspell-buffer)
71 #+END_SRC
72
73 ** Switch-window
74 Helps to change windows easily when many are open at once
75 #+BEGIN_SRC emacs-lisp
76 (use-package switch-window
77   :ensure t
78   :config
79     (setq switch-window-input-style 'minibuffer)
80     (setq switch-window-increase 4)
81     (setq switch-window-threshold 2)
82     (setq switch-window-shortcut-style 'qwerty)
83     (setq switch-window-qwerty-shortcuts
84         '("a" "s" "d" "f" "j" "k" "l" "i" "o"))
85   :bind
86     ([remap other-window] . switch-window))
87 #+END_SRC
8a38cc 88
990949 89 ** Go to new window when opened
C 90 #+BEGIN_SRC emacs-lisp
91   (defun split-and-follow-horizontally ()
92     (interactive)
93     (split-window-below)
94     (balance-windows)
95     (other-window 1))
96   (global-set-key (kbd "C-x 2") 'split-and-follow-horizontally)
97
98   (defun split-and-follow-vertically ()
99     (interactive)
100     (split-window-right)
101     (balance-windows)
102     (other-window 1))
103   (global-set-key (kbd "C-x 3") 'split-and-follow-vertically)
104 #+END_SRC
8a38cc 105
990949 106 ** PDF-tools
C 107 #+BEGIN_SRC emacs-lisp
108 (use-package pdf-tools
109   :ensure t
110   :config
111   (pdf-tools-install))
112 #+END_SRC
8a38cc 113
990949 114 * Helm and Projectile
C 115 ** Helm core
116 #+BEGIN_SRC emacs-lisp
117   (use-package helm-config
118     :ensure helm
119     :bind (("M-x" . helm-M-x)
120            ("C-x C-f" . helm-find-files)
121            ("M-y" . helm-show-kill-ring)
122            ("C-x b" . helm-mini)
123            ("C-c h o" . helm-occur))
124     :config
125     (setq helm-M-x-fuzzy-match t)
126     (setq helm-buffers-fuzzy-matching t
127           helm-recentf-fuzzy-match    t)
128     (setq helm-split-window-in-side-p           t ; open helm buffer inside current window, not occupy whole other window
129           helm-move-to-line-cycle-in-source     t ; move to end or beginning of source when reaching top or bottom of source.
130           helm-ff-search-library-in-sexp        t ; search for library in `require' and `declare-function' sexp.
131           helm-scroll-amount                    8 ; scroll 8 lines other window using M-<next>/M-<prior>
132           helm-ff-file-name-history-use-recentf t
133           helm-echo-input-in-header-line t)
134     (defun spacemacs//helm-hide-minibuffer-maybe ()
135       "Hide minibuffer in Helm session if we use the header line as input field."
136       (when (with-helm-buffer helm-echo-input-in-header-line)
137         (let ((ov (make-overlay (point-min) (point-max) nil nil t)))
138           (overlay-put ov 'window (selected-window))
139           (overlay-put ov 'face
140                        (let ((bg-color (face-background 'default nil)))
141                          `(:background ,bg-color :foreground ,bg-color)))
142           (setq-local cursor-type nil))))
143     (add-hook 'helm-minibuffer-set-up-hook
144               'spacemacs//helm-hide-minibuffer-maybe)
145     (helm-mode 1))
146 #+END_SRC
8a38cc 147
990949 148 ** Projectile
C 149 *** Enable it
150  #+BEGIN_SRC emacs-lisp
151    (use-package projectile
152      :ensure t
153      :bind ("C-c p" . projectile-command-map)
154      :diminish projectile-mode
155      :config
156      (projectile-global-mode)
157      (setq projectile-completion-system 'helm)
158      (when (eq system-type 'windows-nt)
159        (setq projectile-indexing-method 'alien)))
160  #+END_SRC
8a38cc 161
990949 162 *** Let it compile things
C 163  #+BEGIN_SRC emacs-lisp
164    (global-set-key (kbd "<f5>") 'projectile-compile-project)
165  #+END_SRC
8a38cc 166
990949 167 *** Enable communication with helm
C 168 #+BEGIN_SRC emacs-lisp
baf326 169   (use-package helm-projectile
C 170     :ensure t
171     :config
172     (helm-projectile-on))
990949 173 #+END_SRC
8a38cc 174
990949 175 * Small tweaks
C 176 ** Remove startup screen
177 #+BEGIN_SRC emacs-lisp
178 (setq inhibit-startup-message t)
179 #+END_SRC
8a38cc 180
990949 181 ** Disable bell
C 182 Bloody bell dings every time you hit a key too much
183 #+BEGIN_SRC emacs-lisp
184 (setq ring-bell-function 'ignore)
185 #+END_SRC
8a38cc 186
990949 187 ** Pretty symbols
C 188 Why not? They make it look nice
189 #+BEGIN_SRC emacs-lisp
190   (when window-system
191     (use-package pretty-mode
192       :ensure t
193       :diminish t
194       :config
195       (global-pretty-mode)))
196 #+END_SRC
8a38cc 197
990949 198 ** find file other window
C 199 Lets it accept more than one file. Works recursively.
200 #+BEGIN_SRC emacs-lisp
201 (defadvice find-file-other-window (around find-files activate)
202   (if (listp filename)
203       (loop for f in filename do (find-file-other-window f wildcards))
204     ad-do-it))
205 #+END_SRC
8a38cc 206
990949 207 ** Which key
C 208 Helps to explain keybindings if you get lost
209 #+BEGIN_SRC emacs-lisp
210   (use-package which-key
211     :ensure t
212     :diminish which-key-mode
213     :config
214     (which-key-mode))
215 #+END_SRC
8a38cc 216
990949 217 ** Go to this file
C 218 #+BEGIN_SRC emacs-lisp
219 (defun config-visit ()
220   (interactive)
221   (find-file "~/.emacs.d/config.org"))
222 (global-set-key (kbd "C-c e d") 'config-visit)
223 #+END_SRC
8a38cc 224
990949 225 ** Go to init.el
C 226 #+BEGIN_SRC emacs-lisp
227   (defun init-visit ()
228     (interactive)
229     (find-file "~/.emacs.d/init.el"))
230   (global-set-key (kbd "C-c e i") 'init-visit)
231 #+END_SRC
8a38cc 232
990949 233 ** Reload configuration
C 234 #+BEGIN_SRC emacs-lisp
235 (defun config-reload ()
236   "Reloads ~/.emacs.d/config.org at run time"
237   (interactive)
238   (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))
239 (global-set-key (kbd "C-c e r") 'config-reload)
240 #+END_SRC
8a38cc 241
990949 242 ** Smartparens
C 243 Matches brackets automatically
244 #+BEGIN_SRC emacs-lisp
245 (use-package smartparens
246   :ensure t
247   :diminish smartparens-mode
248   :config
249   (progn
250     (require 'smartparens-config)
251     (smartparens-global-mode 1)))
252 #+END_SRC
8a38cc 253
990949 254 ** Rainbow
C 255 Its a little gimmicky but its still cool
256 #+BEGIN_SRC emacs-lisp
257   (use-package rainbow-mode
258     :ensure t
259     :diminish rainbow-mode
260     :init
261     (add-hook 'prog-mode-hook 'rainbow-mode))
262 #+END_SRC
8a38cc 263
990949 264 ** Rainbow delimiters
C 265 A bit more useful than above.
266 Colours the brackets so that they stand out more.
267 #+BEGIN_SRC emacs-lisp
268   (use-package rainbow-delimiters
269     :ensure t
270     :init
271       (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
272 #+END_SRC
8a38cc 273
990949 274 ** clean-aindent-mode
C 275 Removes unnecessary white space
276 #+BEGIN_SRC emacs-lisp
277 (use-package clean-aindent-mode
278   :ensure t
279   :hook prog-mode)
280 #+END_SRC
281 Shows trailing white space
282 #+BEGIN_SRC emacs-lisp
283 (add-hook 'prog-mode-hook (lambda () (interactive) (setq show-trailing-whitespace 1)))
284 #+END_SRC
8a38cc 285
990949 286 ** whitespace mode
C 287 Reveals whitespace characters
288 #+BEGIN_SRC emacs-lisp
289 (global-set-key (kbd "C-c w") 'whitespace-mode)
290 (add-hook 'diff-mode-hook (lambda ()
291                             (setq-local whitespace-style
292                                         '(face
293                                           tabs
294                                           tab-mark
295                                           spaces
296                                           space-mark
297                                           trailing
298                                           indentation::space
299                                           indentation::tab
300                                           newline
301                                           newline-mark))
302                             (whitespace-mode 1)))
303
304 #+END_SRC
8a38cc 305
990949 306 ** eldoc
C 307 #+BEGIN_SRC emacs-lisp
308   (add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
309   (add-hook 'lisp-interaction-mode-hook 'eldoc-mode)
310   (add-hook 'ielm-mode-hook 'eldoc-mode)
311 #+END_SRC
8a38cc 312
990949 313 ** key-freq
C 314 collects interesting statistics
315 #+BEGIN_SRC emacs-lisp
316 (use-package keyfreq
317   :ensure t
318   :config
319   (keyfreq-mode 1)
320   (keyfreq-autosave-mode 1))
321 #+END_SRC
8a38cc 322
990949 323 ** undo-tree
C 324 A more advanced undo mechanism
325 #+BEGIN_SRC emacs-lisp
326 (use-package undo-tree
327   :ensure t
328   :diminish undo-tree-mode
329   :config
330   (global-undo-tree-mode))
331 #+END_SRC
8a38cc 332
990949 333 ** volatile highlights
C 334 Colour the material just copied
335 #+BEGIN_SRC emacs-lisp
336 (use-package volatile-highlights
337   :ensure t
338   :diminish volatile-highlights-mode
339   :config
340   (volatile-highlights-mode t))
341 #+END_SRC
8a38cc 342
990949 343 ** ibuffer
C 344 #+BEGIN_SRC emacs-lisp
345 (global-set-key (kbd "C-x C-b") 'ibuffer)
346 (setq ibuffer-use-other-window t)
347 #+END_SRC
8a38cc 348
990949 349 ** hippie expand
C 350 #+BEGIN_SRC emacs-lisp
351 (global-set-key (kbd "M-/") 'hippie-expand) ;; replace dabbrev-expand
352 (setq
353  hippie-expand-try-functions-list
354  '(try-expand-dabbrev ;; Try to expand word "dynamically", searching the current buffer.
355    try-expand-dabbrev-all-buffers ;; Try to expand word "dynamically", searching all other buffers.
356    try-expand-dabbrev-from-kill ;; Try to expand word "dynamically", searching the kill ring.
357    try-complete-file-name-partially ;; Try to complete text as a file name, as many characters as unique.
358    try-complete-file-name ;; Try to complete text as a file name.
359    try-expand-all-abbrevs ;; Try to expand word before point according to all abbrev tables.
360    try-expand-list ;; Try to complete the current line to an entire line in the buffer.
361    try-expand-line ;; Try to complete the current line to an entire line in the buffer.
362    try-complete-lisp-symbol-partially ;; Try to complete as an Emacs Lisp symbol, as many characters as unique.
363    try-complete-lisp-symbol) ;; Try to complete word as an Emacs Lisp symbol.
364  )
365 #+END_SRC
8a38cc 366
990949 367 ** Highlight line
C 368 #+BEGIN_SRC emacs-lisp
369 (global-hl-line-mode)
370 #+END_SRC
8a38cc 371
990949 372 ** Line numbers
C 373 #+BEGIN_SRC emacs-lisp
374 (add-hook 'prog-mode-hook 'linum-mode)
375 #+END_SRC
376
377 ** Garbage collection
378 starts garbage collection every 100MB
379 #+BEGIN_SRC emacs-lisp
380 (setq gc-cons-threshold 100000000)
381 #+END_SRC
382
383 ** Kill ring
384 Changes the kill ring size to 5000.
385 #+BEGIN_SRC emacs-lisp
386   (setq global-mark-ring-max 5000
387     mark-ring-max 5000
388     mode-require-final-newline t
389     kill-ring-max 5000
390     kill-whole-line t)
391 #+END_SRC
8a38cc 392
990949 393 ** Coding style
C 394 #+BEGIN_SRC emacs-lisp
395 (setq c-default-style "linux")
396 #+END_SRC
397
398 ** Coding system
399 #+BEGIN_SRC emacs-lisp
400 (set-terminal-coding-system 'utf-8)
401 (set-keyboard-coding-system 'utf-8)
402 (set-language-environment "UTF-8")
403 (prefer-coding-system 'utf-8)
404 (setq-default indent-tabs-mode t)
405 (delete-selection-mode)
406 (global-set-key (kbd "RET") 'newline-and-indent)
407 #+END_SRC
8a38cc 408
990949 409 ** Move to beginning of line ignoring whitespace
C 410 Move point back to indentation of beginning of line.
411
412 Move point to the first non-whitespace character on this line.
413 If point is already there, move to the beginning of the line.
414 Effectively toggle between the first non-whitespace character and
415 the beginning of the line.
416
417 If ARG is not nil or 1, move forward ARG - 1 lines first. If
418 point reaches the beginning or end of the buffer, stop there.
419 #+BEGIN_SRC emacs-lisp
420 (defun prelude-move-beginning-of-line (arg)
421   (interactive "^p")
422   (setq arg (or arg 1))
423
424   ;; Move lines first
425   (when (/= arg 1)
426     (let ((line-move-visual nil))
427       (forward-line (1- arg))))
428
429   (let ((orig-point (point)))
430     (back-to-indentation)
431     (when (= orig-point (point))
432       (move-beginning-of-line 1))))
433
434 (global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)
435 #+END_SRC
8a38cc 436
990949 437 ** Indent region or buffer
C 438 #+BEGIN_SRC emacs-lisp
439 (defun indent-region-or-buffer ()
440   "Indent a region if selected, otherwise the whole buffer."
441   (interactive)
442   (unless (member major-mode prelude-indent-sensitive-modes)
443     (save-excursion
444       (if (region-active-p)
445           (progn
446             (indent-region (region-beginning) (region-end))
447             (message "Indented selected region."))
448         (progn
449           (indent-buffer)
450           (message "Indented buffer.")))
451       (whitespace-cleanup))))
452
453 (global-set-key (kbd "C-c i") 'indent-region-or-buffer)
454 #+END_SRC
8a38cc 455
990949 456 ** Tramp
C 457 #+BEGIN_SRC emacs-lisp
458   (when (eq system-type 'windows-nt)
459     (setq tramp-default-method "pscp"))
460   (setq password-cache-expiry nil)
461 #+END_SRC
462
463 * Mode line tweaks
464 Diminish is used but is included in init.el such that it can be used throughout this document
465 ** Spaceline
466 A little easier to read than the default emacs mode line
467 #+BEGIN_SRC emacs-lisp
412080 468     (use-package spaceline
C 469       :ensure t
470       :config
471       (require 'spaceline-config)
472       (setq spaceline-buffer-encoding-abbrev-p t)
473       (setq spaceline-line-column-p t)
474       (setq spaceline-line-p t)
475       (setq powerline-default-separator (quote arrow))
476       (spaceline-spacemacs-theme)
477       (spaceline-helm-mode))
990949 478 #+END_SRC
8a38cc 479
990949 480 ** No separator
C 481 #+BEGIN_SRC emacs-lisp
482 (setq powerline-default-seperator nil)
483 #+END_SRC
8a38cc 484
990949 485 * Programming tweaks
C 486 ** Yasnippet
487 #+BEGIN_SRC emacs-lisp
488     (use-package yasnippet
489       :ensure t
490       :diminish yas-minor-mode
491       :config
492       (use-package yasnippet-snippets
493     :ensure t)
494       (yas-reload-all)
495       (yas-global-mode 1))
496 #+END_SRC
8a38cc 497
990949 498 ** flycheck
C 499 #+BEGIN_SRC emacs-lisp
8a38cc 500   (use-package flycheck
C 501     :ensure t
502     :diminish flycheck-mode
503     :config
504     (global-flycheck-mode))
990949 505 #+END_SRC
C 506 *** flycheck-pos-tip
507 #+BEGIN_SRC emacs-lisp
508 (use-package flycheck-pos-tip
509   :ensure t
510   :after flycheck
511   :config
512   (flycheck-pos-tip-mode))
513 #+END_SRC
8a38cc 514
990949 515 ** Company
8a38cc 516 Company is auto-complete for Emacs
990949 517 #+BEGIN_SRC emacs-lisp
C 518   (use-package company
519     :ensure t
520     :diminish company-mode
521     :config
522     (global-company-mode)
523     (setq company-idle-delay 0)
524     (setq company-minimum-prefix-length 3))
525 #+END_SRC
8a38cc 526
990949 527 ** Magit
C 528 #+BEGIN_SRC emacs-lisp
529   (use-package magit
530     :ensure t
531     :commands magit-get-top-dir
532     :bind ("C-x g" . magit-status)
533     :init
534     (progn
535       ;; make magit status go full-screen but remember previous window
536       ;; settings
537       ;; from: http://whattheemacsd.com/setup-magit.el-01.html
538       (defadvice magit-status (around magit-fullscreen activate)
539         (window-configuration-to-register :magit-fullscreen)
540         ad-do-it
541         (delete-other-windows))
542
543       ;; Close popup when committing - this stops the commit window
544       ;; hanging around
545       ;; From: http://git.io/rPBE0Q
546       (defadvice git-commit-commit (after delete-window activate)
547         (delete-window))
548
549       (defadvice git-commit-abort (after delete-window activate)
550         (delete-window))
551
552       :config
553       (progn
554         ;; restore previously hidden windows
555         (defadvice magit-quit-window (around magit-restore-screen activate)
556           (let ((current-mode major-mode))
557             ad-do-it
558             ;; we only want to jump to register when the last seen buffer
559             ;; was a magit-status buffer.
560             (when (eq 'magit-status-mode current-mode)
561               (jump-to-register :magit-fullscreen)))))
562
563       ;; magit settings
564       (setq
565        ;; don't put "origin-" in front of new branch names by default
566        magit-default-tracking-name-function 'magit-default-tracking-name-branch-only
567        ;; open magit status in same window as current buffer
568        magit-status-buffer-switch-function 'switch-to-buffer
569        ;; highlight word/letter changes in hunk diffs
570        magit-diff-refine-hunk t
571        ;; ask me if I want to include a revision when rewriting
572        magit-rewrite-inclusive 'ask
573        ;; ask me to save buffers
574        magit-save-some-buffers t
575        ;; pop the process buffer if we're taking a while to complete
576        magit-process-popup-time 10
577        ;; ask me if I want a tracking upstream
578        magit-set-upstream-on-push 'askifnotset
579        )))
580 #+END_SRC
8a38cc 581
990949 582 ** CEDET
C 583 *** semantic
584 #+BEGIN_SRC emacs-lisp
585   (use-package semantic
586     :config
587     (global-semanticdb-minor-mode 1)
588     (global-semantic-idle-scheduler-mode 1)
589     (global-semantic-idle-summary-mode 1)
590     (semantic-mode 1))
591 #+END_SRC
8a38cc 592
990949 593 *** EDE
C 594 #+BEGIN_SRC emacs-lisp
595 (use-package ede
596   :config
597   (global-ede-mode t))
598 #+END_SRC
8a38cc 599
990949 600 *** gdb-many-windows
C 601 #+BEGIN_SRC emacs-lisp
602 (setq
603  ;; use gdb-many-windows by default
604  gdb-many-windows t
605
606  ;; Non-nil means display source file containing the main routine at startup
607  gdb-show-main t)
608 #+END_SRC
8a38cc 609
990949 610 *** Semantic refactor
C 611 #+BEGIN_SRC emacs-lisp
612 (use-package srefactor
613   :ensure t
614   :bind (("M-RET o" . 'srefactor-lisp-one-line)
615      ("M-RET m" . 'srefactor-lisp-format-sexp)
616      ("M-RET d" . 'srefactor-lisp-format-defun)
617      ("M-RET b" . 'srefactor-lisp-format-buffer)
618      :map c-mode-base-map
619           ("M-RET" . 'srefactor-refactor-at-point)
620           :map c++-mode-map
621           ("M-RET" . 'srefactor-refactor-at-point)))
622 #+END_SRC
8a38cc 623
990949 624 ** Language specific configs
C 625 *** C/C++
626 **** yasnippet
627 #+BEGIN_SRC emacs-lisp
628 (add-hook 'c++-mode-hook 'yas-minor-mode)
629 (add-hook 'c-mode-hook 'yas-minor-mode)
630 #+END_SRC
8a38cc 631
990949 632 **** flycheck clang
C 633 #+BEGIN_SRC emacs-lisp
634 (use-package flycheck-clang-analyzer
635   :ensure t
636   :config
637   (with-eval-after-load 'flycheck
638     (require 'flycheck-clang-analyzer)
639      (flycheck-clang-analyzer-setup)))
640 #+END_SRC
8a38cc 641
990949 642 **** company
C 643 #+BEGIN_SRC emacs-lisp
644   (use-package company-c-headers
645       :ensure t
646       :after company
647       :config
648       (add-hook 'c++-mode-hook 'company-mode)
649       (add-hook 'c-mode-hook 'company-mode))
650
651   (use-package company-irony
652     :ensure t
653     :config
654     (add-to-list 'company-backends '(company-c-headers
655                                      company-dabbrev-code
656                                      company-irony)))
657
658   (use-package irony
659     :ensure t
660     :init
661     (setq w32-pipe-read-delay 0)
662     (setq irony-server-w32-pipe-buffer-size (* 64 1024))
663     (add-hook 'c++-mode-hook 'irony-mode)
664     (add-hook 'c-mode-hook 'irony-mode)
665     (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
666     (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))
667 #+END_SRC
8a38cc 668
990949 669 *** emacs-lisp
C 670 **** eldoc
671 #+BEGIN_SRC emacs-lisp
672 (add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
673 #+END_SRC
8a38cc 674
990949 675 **** yasnippet
C 676 #+BEGIN_SRC emacs-lisp
677 (add-hook 'emacs-lisp-mode-hook 'yas-minor-mode)
678 #+END_SRC
8a38cc 679
990949 680 **** company
C 681 #+BEGIN_SRC emacs-lisp
682 (add-hook 'emacs-lisp-mode-hook 'company-mode)
683
684 (use-package slime
685   :ensure t
686   :config
687   (setq inferior-lisp-program "/usr/bin/sbcl")
688   (setq slime-contribs '(slime-fancy)))
689
690 (use-package slime-company
691   :ensure t
692   :init
693     (require 'company)
694     (slime-setup '(slime-fancy slime-company)))
695 #+END_SRC
8a38cc 696
990949 697 *** x86
C 698 **** x86-lookup
699 #+BEGIN_SRC emacs-lisp
700 (use-package x86-lookup
701   :ensure t
702   :init
703   (setq x86-lookup-pdf "D:/Coding/x86-instructions.pdf")
704   :bind ("C-h x" . x86-lookup))
705 #+END_SRC
8a38cc 706
990949 707 *** Latex
C 708 **** AucTex
709 #+BEGIN_SRC emacs-lisp
20e001 710   (use-package tex
C 711     :ensure auctex
712     :config
713     (setq TeX-auto-save t)
714     (setq TeX-parse-self t)
715     (setq TeX-view-program-selection '((output-pdf "PDF Tools"))
716           TeX-source-correlate-start-server t)
717     (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer))
990949 718 #+END_SRC
8a38cc 719
990949 720 **** Company
C 721 #+BEGIN_SRC emacs-lisp
722   (use-package company-math
723     :ensure t
724     :after company
725     :config
726     (add-to-list 'company-backends 'company-math-symbols-unicode))
727
728   (use-package company-reftex
729     :ensure t
730     :after company
731     :config
732     (add-to-list 'company-backends 'company-reftex))
733
734   (use-package company-auctex
735     :ensure t
736     :after company
737     :config
738     (company-auctex-init))
739
740   (use-package company-bibtex
741     :ensure t
742     :after company
743     (add-to-list 'company-backends 'company-bibtex))
744 #+END_SRC
8a38cc 745
20e001 746 **** COMMENT TeXcount
990949 747      Word counts in latex
C 748      #+BEGIN_SRC emacs-lisp
20e001 749        (defun get-texcount-latest()
C 750          (url-copy-file "https://app.uio.no/ifi/texcount/download.php?file=texcount_3_1_1.zip" "~/.texcount/texcount.zip" 1)
751          (shell-command "unzip -o ~/.texcount/texcount.zip -d ~/.texcount")
752          (add-to-list 'exec-path "~/.texcount/texcount.pl"))
753
754        (get-texcount-latest)
990949 755
C 756        (defun texcount ()
757          (interactive)
758          (let*
759              ( (this-file (buffer-file-name))
760                (enc-str (symbol-name buffer-file-coding-system))
761                (enc-opt
762                 (cond
763                  ((string-match "utf-8" enc-str) "-utf8")
764                  ((string-match "latin" enc-str) "-latin1")
765                  ("-encoding=guess")
766                  ) )
767                (word-count
768                 (with-output-to-string
769                   (with-current-buffer standard-output
770                     (call-process "texcount" nil t nil "-0" enc-opt this-file)
771                     ) ) ) )
772            (message word-count)
773            ) )
774        (add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-c c") 'texcount)))
775        (add-hook 'latex-mode-hook (lambda () (define-key latex-mode-map (kbd "C-c c") 'texcount)))
776      #+END_SRC
777
778 *** PlantUML
779 #+BEGIN_SRC emacs-lisp
780 (use-package plantuml-mode
781   :ensure t
782   :init
783   (setq plantuml-jar-path "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar"))
784 #+END_SRC
785
786 *** Racket
787 **** Major mode
788 #+BEGIN_SRC emacs-lisp
789   (when (eq system-type 'windows-nt)
790     (add-to-list 'exec-path "c:/Program Files/Racket")
791     (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
792
793   (use-package racket-mode
794       :ensure t
795       :config
796       (autoload 'racket-mode "Racket" "Racket Editing Mode" t)
797       (add-to-list
798        'auto-mode-alist
8a38cc 799        '("\\.rkt$" . racket-mode))
990949 800       (setq matlab-indent-function t))
C 801 #+END_SRC
802
803 *** Verilog
baf326 804 **** Get latest version
C 805 Pull the latest version from the web
806 #+BEGIN_SRC emacs-lisp
807   (defun get-verilog-latest()
0864ff 808     (if (not(file-directory-p "~/.emacs.d/elpa/verilog-mode"))
C 809         (make-directory "~/.emacs.d/elpa/verilog-mode"))
810     (if (file-exists-p "~/.emacs.d/elpa/verilog-mode/verilog-mode.el")
811         (delete-file "~/.emacs.d/elpa/verilog-mode/verilog-mode.el"))
dc8eb0 812     (url-copy-file "https://www.veripool.org/ftp/verilog-mode.el" "~/.emacs.d/elpa/verilog-mode/verilog-mode.el" 1))
baf326 813 #+END_SRC
C 814
815 **** Integrate into emacs
990949 816 Add updated version and integrate it with Emacs.
C 817 #+BEGIN_SRC emacs-lisp
0864ff 818     (defun verilog-read-file-as-string (file)
C 819       "Read FILE contents."
820       (when (file-exists-p file)
821         (with-temp-buffer
822           (insert-file-contents file)
823           (buffer-string))))
824
825     (defun verilog-write-string-to-file (file string)
826       "Substitute FILE contents with STRING."
827       (with-temp-buffer
828         (insert string)
829         (when (file-writable-p file)
830           (write-region (point-min)
831                         (point-max)
832                         file))))
833
834     (defun verilog-today-day ()
835       (time-to-days (current-time)))
836
837     (defun should-update-verilog-p ()
838       "Return non-nil when an update is due."
839       (and
840        (or
841         (not (file-exists-p "~/.emacs.d/.last-verilog-update-day"))
842         (if (>= (/ (- (verilog-today-day) (verilog-read-last-update-day)) 7) 1)
843             t
844           nil))))
845
846     (defun verilog-read-last-update-day ()
847       "Read last update day."
848       (string-to-number
849        (verilog-read-file-as-string "~/.emacs.d/.last-verilog-update-day")))
850
851     (defun verilog-write-current-day ()
852       "Store current day."
853       (verilog-write-string-to-file
854        "~/.emacs.d/.last-verilog-update-day"
855        (int-to-string (verilog-today-day))))
856
857     (use-package verilog-mode
858       :init
859       (when (should-update-verilog-p)
860           (get-verilog-latest)
861           (verilog-write-current-day))
862       (add-to-list 'load-path "~/.emacs.d/elpa/verilog-mode/verilog-mode.el")
863       :config
864       (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
865       (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode)))
990949 866 #+END_SRC
8a38cc 867
990949 868 * Org mode
C 869 ** Up to date org
870 #+BEGIN_SRC emacs-lisp
871     (use-package org
872       :ensure t
873       :pin org)
874 #+END_SRC
8a38cc 875
990949 876 ** Small tweaks
C 877 #+BEGIN_SRC emacs-lisp
878 (setq org-src-fontify-natively t)
879 (setq org-src-tab-acts-natively t)
880 (setq org-confirm-babel-evaluate nil)
881 (setq org-export-with-smart-quotes t)
882 (setq org-src-window-setup 'current-window)
883 (add-hook 'org-mode-hook 'org-indent-mode)
884 (diminish 'org-indent-mode)
885 (diminish 'visual-line-mode)
886 #+END_SRC
8a38cc 887
990949 888 ** Line wrapping
C 889 #+BEGIN_SRC emacs-lisp
890   (add-hook 'org-mode-hook
891           '(lambda ()
892          (visual-line-mode 1)))
893 #+END_SRC
8a38cc 894
990949 895 ** org-bullets
C 896 #+BEGIN_SRC emacs-lisp
897 (use-package org-bullets
898   :ensure t
899   :config
900     (add-hook 'org-mode-hook (lambda () (org-bullets-mode))))
901 #+END_SRC
8a38cc 902
990949 903 ** Org Babel
C 904 *** Languages
905 Add C to org babel supported languages
906 #+BEGIN_SRC emacs-lisp
baf326 907     (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t)
C 908                                                              (C . t)
909                                                              (python . t)
910                                                              (latex . t)
911                                                              (scheme . t)
912                                                              (gnuplot . t)
913                                                              (matlab . t)
914                                                              (plantuml . t)
915                                                              (fortran . t)
916                                                              (java . t)
917                                                              (plantuml . t)))
918 #+END_SRC
919
920 **** Plantuml path
921 #+BEGIN_SRC emacs-lisp
922   (setq org-plantuml-jar-path plantuml-jar-path)
990949 923 #+END_SRC
8a38cc 924
990949 925 ** Latex preview fragments match colour
C 926 Make the previews match theme colour of Emacs.
927 #+BEGIN_SRC emacs-lisp
928   (let ((dvipng--plist (alist-get 'dvipng org-preview-latex-process-alist)))
929     (plist-put dvipng--plist :use-xcolor t)
930     (plist-put dvipng--plist :image-converter '("dvipng -D %D -T tight -o %O %f")))
931 #+END_SRC