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

Joel Grunbaum
2021-12-22 3cfd40ae21dc2f2b7950d0e902002f900501962f
commit | author | age
990949 1 #+TITLE: My Emacs configuration
5a75e4 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 htmlize linter backend writegood ggtags gtags dired eshell asm cd dwim VHDL defvar ctags vhdl concat sp html awk defalias cedet mips IPython ein contrib pandoc dokuwiki EMMS MPD emms toc favicon href css stylesheet async dataLayer gtag js UA sitelinks br Github postamble isso center disqus onclick Disqus javascript dsq createElement getElementsByTagName xml urlset xmlns curr loc RSS elfeed
8a38cc 3
6252df 4 * OS dependencies
JG 5 Windows and Mac have some interesting paths when starting emacs which needs to be fixed.
6 Using mingw64 in windows and general path in mac.
990949 7 #+BEGIN_SRC emacs-lisp
6252df 8   (cond ((eq system-type 'windows-nt)
JG 9          (add-to-list 'exec-path "C:/msys64/usr/bin")
10          (add-to-list 'exec-path "C:/msys64/mingw64/bin")
1cfa19 11          (add-to-list 'exec-path "C:/Program Files/gnuplot")
6252df 12          (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
JG 13         ((eq system-type 'darwin)
14          (use-package exec-path-from-shell
15            :ensure t
16            :config
8264c0 17            (exec-path-from-shell-initialize))
JG 18          (setq default-directory "~/")))
990949 19 #+END_SRC
C 20
21 * Aesthetic changes
0fcc09 22 ** Emacs theme
80d515 23 Theme switcher, using a cond allows loading of many preconfigured themes which can be switched between easily.
JG 24 Zenburn theme is my default.
990949 25 #+BEGIN_SRC emacs-lisp
0fcc09 26   (setq emacs-theme 'zenburn)
80d515 27
JG 28   (defun disable-all-themes ()
29       (dolist (i custom-enabled-themes)
30            (disable-theme i)))
412080 31
0fcc09 32   (cond ((eq emacs-theme 'zenburn)
C 33          (use-package zenburn-theme
34            :ensure t
412080 35            :init
C 36            (disable-all-themes)
0fcc09 37            :config
C 38            (load-theme 'zenburn t)))
39         ((eq emacs-theme 'doom-one)
40          (use-package doom-themes
41            :ensure t
412080 42            :init
C 43            (disable-all-themes)
0fcc09 44            :config
C 45            (setq doom-themes-enable-bolt t
46                  doom-themes-enable-italic t)
47            (load-theme 'doom-one t)
48            (doom-themes-visual-bell-config)
412080 49            (doom-themes-org-config)))
a428a2 50         ((eq emacs-theme 'nord)
JG 51          (use-package nord-theme
52            :ensure t
53            :init
54            (disable-all-themes)
55            :config
56            (load-theme 'nord t)))
b0ee5f 57         ((eq emacs-theme 'solarized)
JG 58          (use-package solarized-theme
59            :ensure t
60            :init
61            (disable-all-themes)
62            :config
63            (load-theme 'solarized-dark t)))
995f2c 64         ((eq emacs-theme 'jetbrains-darcula)
JG 65          (use-package jetbrains-darcula-theme
66            :ensure t
67            :init
68            (disable-all-themes)
69            :config
70            (load-theme 'jetbrains-darcula t)))
412080 71         ((eq emacs-theme 'none)
80d515 72          (disable-all-themes)))
990949 73 #+END_SRC
8a38cc 74
990949 75 ** Default font
80d515 76 Set default font and faces.
20e001 77 #+BEGIN_SRC emacs-lisp 
350884 78   (cond ((member "Dank Mono" (font-family-list))
JG 79          (set-frame-font "Dank Mono-11" nil t))
80         ((member "DejaVu Sans Mono" (font-family-list))
81          (set-frame-font "DejaVu Sans Mono" nil t))
82         ((member "Source Code Pro" (font-family-list))
83          (set-frame-font "Source Code Pro-10" nil t)))
84
20e001 85   (set-face-italic 'font-lock-comment-face t)
C 86   (set-face-italic 'font-lock-keyword-face t)
990949 87 #+END_SRC
8a38cc 88
e0a5d8 89 ** Remove menu bar, toolbar, and scroll bar
80d515 90 Make the emacs interface slightly nicer.
990949 91 #+BEGIN_SRC emacs-lisp
C 92   (menu-bar-mode 0)
93   (tool-bar-mode 0)
e0a5d8 94   (scroll-bar-mode 0)
990949 95 #+END_SRC
350884 96 * COMMENT EXWM
JG 97 Emacs window manager.
98 Tiling window manager that runs in emacs.
5a75e4 99 Open external applications with =s-&=
350884 100 #+BEGIN_SRC emacs-lisp
JG 101   (use-package exwm
102     :ensure t
0b5a77 103     :defer t
350884 104     :config
JG 105     (require 'exwm-config)
106     (exwm-config-default))
107 #+END_SRC
990949 108
C 109 * Writing requirements
110 ** Spellchecking
80d515 111 Use aspell for spellchecking. 
JG 112 Auto-enable in latex and org as they're the main writing modes.
990949 113 #+BEGIN_SRC emacs-lisp
C 114   (require 'ispell)
115   (setq-default ispell-program-name "aspell")
116   (setq-default ispell-local-dictionary "en_AU")
f0bf38 117   (add-hook 'tex-mode-hook 'flyspell-mode)
990949 118   (add-hook 'latex-mode-hook 'flyspell-mode)
f0bf38 119   (add-hook 'TeX-mode-hook 'flyspell-mode)
JG 120   (add-hook 'LaTeX-mode-hook 'flyspell-mode)
0ba1ff 121   ;; (add-hook 'latex-mode-hook 'flyspell-buffer)
990949 122   (add-hook 'org-mode-hook 'flyspell-mode)
0ba1ff 123   ;; (add-hook 'org-mode-hook 'flyspell-buffer)
f1b53f 124   (diminish 'flyspell-mode)
a428a2 125
990949 126 #+END_SRC
af0806 127 ** Language Tool
JG 128 Language tool is an open source grammar checker.
129 #+BEGIN_SRC emacs-lisp
130   (use-package langtool
131     :ensure t
132     :init
133     (setq langtool-java-classpath "/usr/share/languagetool:/usr/share/java/languagetool/*"))
134 #+END_SRC
990949 135 ** Switch-window
80d515 136 Helps to change windows easily when many are open at once.
990949 137 #+BEGIN_SRC emacs-lisp
C 138 (use-package switch-window
139   :ensure t
140   :config
141     (setq switch-window-input-style 'minibuffer)
142     (setq switch-window-increase 4)
143     (setq switch-window-threshold 2)
144     (setq switch-window-shortcut-style 'qwerty)
145     (setq switch-window-qwerty-shortcuts
146         '("a" "s" "d" "f" "j" "k" "l" "i" "o"))
147   :bind
148     ([remap other-window] . switch-window))
149 #+END_SRC
8a38cc 150
990949 151 ** Go to new window when opened
80d515 152 Go to new window when its opened instead of staying with current one.
990949 153 #+BEGIN_SRC emacs-lisp
C 154   (defun split-and-follow-horizontally ()
155     (interactive)
156     (split-window-below)
157     (balance-windows)
158     (other-window 1))
159   (global-set-key (kbd "C-x 2") 'split-and-follow-horizontally)
160
161   (defun split-and-follow-vertically ()
162     (interactive)
163     (split-window-right)
164     (balance-windows)
165     (other-window 1))
166   (global-set-key (kbd "C-x 3") 'split-and-follow-vertically)
167 #+END_SRC
8a38cc 168
990949 169 ** PDF-tools
80d515 170 Helpful pdf viewer.
990949 171 #+BEGIN_SRC emacs-lisp
bf794a 172   (use-package pdf-tools
0b5a77 173     :ensure t
JG 174     :config
175     (pdf-tools-install 1))
990949 176 #+END_SRC
8a38cc 177
be9cff 178 ** COMMENT Writegood-mode
80d515 179 Supposedly should provide insight to writing quality.
49aa9f 180 #+BEGIN_SRC emacs-lisp
JG 181   (use-package writegood-mode
182     :ensure t
183     :hook (text-mode . writegood-mode))
184 #+END_SRC
185
990949 186 * Helm and Projectile
C 187 ** Helm core
80d515 188 Helm aids the user interface for emacs. Adds visual and auto-complete feedback for emacs commands.
990949 189 #+BEGIN_SRC emacs-lisp
C 190   (use-package helm-config
191     :ensure helm
192     :bind (("M-x" . helm-M-x)
193            ("C-x C-f" . helm-find-files)
194            ("M-y" . helm-show-kill-ring)
195            ("C-x b" . helm-mini)
196            ("C-c h o" . helm-occur))
197     :config
198     (setq helm-M-x-fuzzy-match t)
199     (setq helm-buffers-fuzzy-matching t
200           helm-recentf-fuzzy-match    t)
201     (setq helm-split-window-in-side-p           t ; open helm buffer inside current window, not occupy whole other window
202           helm-move-to-line-cycle-in-source     t ; move to end or beginning of source when reaching top or bottom of source.
203           helm-ff-search-library-in-sexp        t ; search for library in `require' and `declare-function' sexp.
204           helm-scroll-amount                    8 ; scroll 8 lines other window using M-<next>/M-<prior>
205           helm-ff-file-name-history-use-recentf t
206           helm-echo-input-in-header-line t)
207     (defun spacemacs//helm-hide-minibuffer-maybe ()
208       "Hide minibuffer in Helm session if we use the header line as input field."
209       (when (with-helm-buffer helm-echo-input-in-header-line)
210         (let ((ov (make-overlay (point-min) (point-max) nil nil t)))
211           (overlay-put ov 'window (selected-window))
212           (overlay-put ov 'face
213                        (let ((bg-color (face-background 'default nil)))
214                          `(:background ,bg-color :foreground ,bg-color)))
215           (setq-local cursor-type nil))))
216     (add-hook 'helm-minibuffer-set-up-hook
217               'spacemacs//helm-hide-minibuffer-maybe)
218     (helm-mode 1))
219 #+END_SRC
8a38cc 220
990949 221 ** Projectile
80d515 222 Projectile is project management framework for emacs.
JG 223 Helps in navigation and management of projects.
224 Identifies project layout from git.
990949 225 *** Enable it
C 226  #+BEGIN_SRC emacs-lisp
227    (use-package projectile
228      :ensure t
229      :bind ("C-c p" . projectile-command-map)
230      :diminish projectile-mode
231      :config
232      (projectile-global-mode)
233      (setq projectile-completion-system 'helm)
234      (when (eq system-type 'windows-nt)
235        (setq projectile-indexing-method 'alien)))
236  #+END_SRC
8a38cc 237
990949 238 *** Let it compile things
80d515 239 Shortcut for compilation.
990949 240  #+BEGIN_SRC emacs-lisp
C 241    (global-set-key (kbd "<f5>") 'projectile-compile-project)
242  #+END_SRC
8a38cc 243
990949 244 *** Enable communication with helm
80d515 245 Use helm to manage project.
990949 246 #+BEGIN_SRC emacs-lisp
baf326 247   (use-package helm-projectile
C 248     :ensure t
249     :config
250     (helm-projectile-on))
990949 251 #+END_SRC
8a38cc 252
be9cff 253 ** COMMENT ggtags
0ba1ff 254 Use GNU Global Tags. Can be useful for large projects.
bf794a 255 #+BEGIN_SRC emacs-lisp
JG 256     (use-package ggtags
257       :ensure t
258       :bind (("C-c g s" . ggtags-find-other-symbol)
259            ("C-c g h" . ggtags-view-tag-history)
260            ("C-c g r" . ggtags-find-reference)
261            ("C-c g f" . ggtags-find-file)
262            ("C-c g c" . ggtags-create-tags)
263            ("C-c g u" . ggtags-update-tags))
264       :config
265       (add-hook 'c-mode-common-hook
266               (lambda ()
267                 (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
268                   (ggtags-mode 1))))
269       )
270
271     (setq
272      helm-gtags-ignore-case t
273      helm-gtags-auto-update t
274      helm-gtags-use-input-at-cursor t
275      helm-gtags-pulse-at-cursor t
276      helm-gtags-prefix-key "\C-c g"
277      helm-gtags-suggested-key-mapping t
278      )
279
280     (use-package helm-gtags
281       :ensure t
282       :config
283       (add-hook 'dired-mode-hook 'helm-gtags-mode)
284       (add-hook 'eshell-mode-hook 'helm-gtags-mode)
285       (add-hook 'c-mode-hook 'helm-gtags-mode)
286       (add-hook 'c++-mode-hook 'helm-gtags-mode)
287       (add-hook 'asm-mode-hook 'helm-gtags-mode)
288     
289       (define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
290       (define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
291       (define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
292       (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
293       (define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
294       (define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))
295 #+END_SRC
296
be9cff 297 ** COMMENT Ctags
0ba1ff 298 Ctags is an older tagging program that supports more languages.
JG 299 Currently setup for VHDL as I had to work with a large existing VHDL code-base.
bf794a 300 #+BEGIN_SRC emacs-lisp
JG 301   (defvar ctags-command "ctags -e -R --languages=vhdl")
302
303   (defun ctags ()
304     (call-process-shell-command ctags-command nil "*Ctags*"))
305
306
307   (defun ctags-find-tags-file ()
308     "Recursively searches each parent directory for a file named
309                 TAGS and returns the path to that file or nil if a tags file is
310                 not found or if the buffer is not visiting a file."
311     (progn
312       (defun find-tags-file-r (path)
313         "Find the tags file from current to the parent directories."
314         (let* ((parent-directory (file-name-directory (directory-file-name path)))
315                (tags-file-name (concat (file-name-as-directory path) "TAGS")))
316           (cond
317            ((file-exists-p tags-file-name) (throw 'found tags-file-name))
318            ((string= "/TAGS" tags-file-name) nil)
319            (t (find-tags-file-r parent-directory)))))
320
321       (if (buffer-file-name)
322           (catch 'found
323             (find-tags-file-r (file-name-directory buffer-file-name)))
324         nil)))
325
326   (defun ctags-set-tags-file ()
327     "Uses `ctags-find-tags-file' to find a TAGS file. If found,
328                 set 'tags-file-name' with its path or set as nil."
329     (setq-default tags-file-name (ctags-find-tags-file)))
330
331   (defun ctags-create-tags-table ()
332     (interactive)
333     (let* ((current-directory default-directory)
334            (top-directory (read-directory-name
335                            "Top of source tree: " default-directory))
336            (file-name (concat (file-name-as-directory top-directory) "TAGS")))
337       (cd top-directory)
338       (if (not (= 0 (ctags)))
339           (message "Error creating %s!" file-name)
340         (setq-default tags-file-name file-name)
341         (message "Table %s created and configured." tags-file-name))
342       (cd current-directory)))
343
344   (defun ctags-update-tags-table ()
345     (interactive)
346     (let ((current-directory default-directory))
347       (if (not tags-file-name)
348           (message "Tags table not configured.")
349         (cd (file-name-directory tags-file-name))
350         (if (not (= 0 (ctags)))
351             (message "Error updating %s!" tags-file-name)
352           (message "Table %s updated." tags-file-name))
353         (cd current-directory))))
354
355   (defun ctags-create-or-update-tags-table ()
356     "Create or update a tags table with `ctags-command'."
357     (interactive)
358     (if (not (ctags-set-tags-file))
359         (ctags-create-tags-table)
360       (ctags-update-tags-table)))
361
362
363   (defun ctags-search ()
364     "A wrapper for `tags-search' that provide a default input."
365     (interactive)
366     (let* ((symbol-at-point (symbol-at-point))
367            (default (symbol-name symbol-at-point))
368            (input (read-from-minibuffer
369                    (if (symbol-at-point)
370                        (concat "Tags search (default " default "): ")
371                      "Tags search (regexp): "))))
372       (if (and (symbol-at-point) (string= input ""))
373           (tags-search default)
374         (if (string= input "")
375             (message "You must provide a regexp.")
376           (tags-search input)))))
377 #+END_SRC
378
990949 379 * Small tweaks
C 380 ** Remove startup screen
0ba1ff 381 Start on scratch buffer instead.
990949 382 #+BEGIN_SRC emacs-lisp
C 383 (setq inhibit-startup-message t)
384 #+END_SRC
8a38cc 385
990949 386 ** Disable bell
0ba1ff 387 Bloody bell dings every time you hit a key too much.
990949 388 #+BEGIN_SRC emacs-lisp
C 389 (setq ring-bell-function 'ignore)
390 #+END_SRC
8a38cc 391
990949 392 ** Pretty symbols
0ba1ff 393 Why not? They make it look nice.
990949 394 #+BEGIN_SRC emacs-lisp
0b5a77 395   (use-package pretty-mode
JG 396     :ensure t
397     :diminish t
398     :if window-system
399     :config
400     (global-pretty-mode))
990949 401 #+END_SRC
8a38cc 402
0ba1ff 403 ** COMMENT Find file other window
990949 404 Lets it accept more than one file. Works recursively.
C 405 #+BEGIN_SRC emacs-lisp
406 (defadvice find-file-other-window (around find-files activate)
407   (if (listp filename)
408       (loop for f in filename do (find-file-other-window f wildcards))
409     ad-do-it))
410 #+END_SRC
8a38cc 411
990949 412 ** Which key
0ba1ff 413 Helps to explain keybindings if you get lost.
990949 414 #+BEGIN_SRC emacs-lisp
C 415   (use-package which-key
416     :ensure t
417     :diminish which-key-mode
418     :config
419     (which-key-mode))
420 #+END_SRC
8a38cc 421
bf794a 422 ** Config shortcuts
JG 423 *** Go to this file
990949 424 #+BEGIN_SRC emacs-lisp
C 425 (defun config-visit ()
426   (interactive)
427   (find-file "~/.emacs.d/config.org"))
428 (global-set-key (kbd "C-c e d") 'config-visit)
429 #+END_SRC
8a38cc 430
bf794a 431 *** Go to init.el
990949 432 #+BEGIN_SRC emacs-lisp
C 433   (defun init-visit ()
434     (interactive)
435     (find-file "~/.emacs.d/init.el"))
436   (global-set-key (kbd "C-c e i") 'init-visit)
437 #+END_SRC
8a38cc 438
bf794a 439 *** Reload configuration
990949 440 #+BEGIN_SRC emacs-lisp
C 441 (defun config-reload ()
442   "Reloads ~/.emacs.d/config.org at run time"
443   (interactive)
444   (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))
445 (global-set-key (kbd "C-c e r") 'config-reload)
446 #+END_SRC
8a38cc 447
990949 448 ** Smartparens
0ba1ff 449 Matches brackets automatically. Added "$" for latex in org mode.
990949 450 #+BEGIN_SRC emacs-lisp
0ba1ff 451   (use-package smartparens
JG 452     :ensure t
453     :diminish smartparens-mode
454     :config
455     (progn
456       (require 'smartparens-config)
457       (smartparens-global-mode 1))
458     (sp-with-modes 'org-mode
459       (sp-local-pair "$" "$")))
990949 460 #+END_SRC
8a38cc 461
0ba1ff 462 ** COMMENT Rainbow
JG 463 Its a little gimmicky but its still cool.
464 Colours according to code after a "#", works with 3 and 6 character hex codes.
990949 465 #+BEGIN_SRC emacs-lisp
C 466   (use-package rainbow-mode
467     :ensure t
468     :diminish rainbow-mode
469     :init
470     (add-hook 'prog-mode-hook 'rainbow-mode))
471 #+END_SRC
8a38cc 472
990949 473 ** Rainbow delimiters
C 474 A bit more useful than above.
475 Colours the brackets so that they stand out more.
476 #+BEGIN_SRC emacs-lisp
477   (use-package rainbow-delimiters
478     :ensure t
0b5a77 479     :hook (prog-mode . rainbow-delimiters-mode))
990949 480 #+END_SRC
8a38cc 481
0ba1ff 482 ** Following whitespace
990949 483 Removes unnecessary white space
C 484 #+BEGIN_SRC emacs-lisp
0ba1ff 485   (use-package clean-aindent-mode
JG 486     :ensure t
487     :hook prog-mode)
990949 488 #+END_SRC
C 489 Shows trailing white space
490 #+BEGIN_SRC emacs-lisp
491 (add-hook 'prog-mode-hook (lambda () (interactive) (setq show-trailing-whitespace 1)))
492 #+END_SRC
8a38cc 493
0ba1ff 494 ** Whitespace mode
990949 495 Reveals whitespace characters
C 496 #+BEGIN_SRC emacs-lisp
497 (global-set-key (kbd "C-c w") 'whitespace-mode)
498 (add-hook 'diff-mode-hook (lambda ()
499                             (setq-local whitespace-style
500                                         '(face
501                                           tabs
502                                           tab-mark
503                                           spaces
504                                           space-mark
505                                           trailing
506                                           indentation::space
507                                           indentation::tab
508                                           newline
509                                           newline-mark))
510                             (whitespace-mode 1)))
511
512 #+END_SRC
8a38cc 513
990949 514 ** eldoc
0ba1ff 515 Shows function arguments in echo area below mode line.
990949 516 #+BEGIN_SRC emacs-lisp
f1b53f 517   (diminish 'eldoc-mode)
990949 518   (add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
C 519   (add-hook 'lisp-interaction-mode-hook 'eldoc-mode)
520   (add-hook 'ielm-mode-hook 'eldoc-mode)
521 #+END_SRC
8a38cc 522
0ba1ff 523 ** Key frequency statistics
JG 524 Collects interesting statistics about key presses.
525 Use M-x keyfreq-show to show in emacs or M-x keyfreq-html to output
990949 526 #+BEGIN_SRC emacs-lisp
C 527 (use-package keyfreq
528   :ensure t
529   :config
530   (keyfreq-mode 1)
531   (keyfreq-autosave-mode 1))
532 #+END_SRC
8a38cc 533
0ba1ff 534 ** Undo tree
JG 535 A more advanced undo mechanism.
536 Supports branched undo history (thus the tree).
537 Pretty neat, if seldom used.
990949 538 #+BEGIN_SRC emacs-lisp
C 539 (use-package undo-tree
540   :ensure t
541   :diminish undo-tree-mode
542   :config
543   (global-undo-tree-mode))
544 #+END_SRC
8a38cc 545
0ba1ff 546 ** Volatile highlights
990949 547 Colour the material just copied
C 548 #+BEGIN_SRC emacs-lisp
549 (use-package volatile-highlights
550   :ensure t
551   :diminish volatile-highlights-mode
552   :config
553   (volatile-highlights-mode t))
554 #+END_SRC
8a38cc 555
990949 556 ** ibuffer
0ba1ff 557 View all open buffers in their own buffer rather in the temporary mini buffer.
990949 558 #+BEGIN_SRC emacs-lisp
C 559 (global-set-key (kbd "C-x C-b") 'ibuffer)
560 (setq ibuffer-use-other-window t)
561 #+END_SRC
8a38cc 562
0ba1ff 563 ** Hippie expand
JG 564 Seems cool, but I don't think I ever use this.
565 Meant to suggest completions to beginning of a word.
990949 566 #+BEGIN_SRC emacs-lisp
C 567 (global-set-key (kbd "M-/") 'hippie-expand) ;; replace dabbrev-expand
568 (setq
569  hippie-expand-try-functions-list
570  '(try-expand-dabbrev ;; Try to expand word "dynamically", searching the current buffer.
571    try-expand-dabbrev-all-buffers ;; Try to expand word "dynamically", searching all other buffers.
572    try-expand-dabbrev-from-kill ;; Try to expand word "dynamically", searching the kill ring.
573    try-complete-file-name-partially ;; Try to complete text as a file name, as many characters as unique.
574    try-complete-file-name ;; Try to complete text as a file name.
575    try-expand-all-abbrevs ;; Try to expand word before point according to all abbrev tables.
576    try-expand-list ;; Try to complete the current line to an entire line in the buffer.
577    try-expand-line ;; Try to complete the current line to an entire line in the buffer.
578    try-complete-lisp-symbol-partially ;; Try to complete as an Emacs Lisp symbol, as many characters as unique.
579    try-complete-lisp-symbol) ;; Try to complete word as an Emacs Lisp symbol.
580  )
581 #+END_SRC
8a38cc 582
990949 583 ** Highlight line
0ba1ff 584 Very useful for finding where you are.
990949 585 #+BEGIN_SRC emacs-lisp
C 586 (global-hl-line-mode)
587 #+END_SRC
8a38cc 588
990949 589 ** Line numbers
0ba1ff 590 Everyone needs line numbers when programming.
990949 591 #+BEGIN_SRC emacs-lisp
C 592 (add-hook 'prog-mode-hook 'linum-mode)
593 #+END_SRC
594
595 ** Garbage collection
0ba1ff 596 Starts garbage collection every 100MB.
990949 597 #+BEGIN_SRC emacs-lisp
C 598 (setq gc-cons-threshold 100000000)
599 #+END_SRC
600
601 ** Kill ring
602 Changes the kill ring size to 5000.
603 #+BEGIN_SRC emacs-lisp
604   (setq global-mark-ring-max 5000
605     mark-ring-max 5000
606     mode-require-final-newline t
607     kill-ring-max 5000
608     kill-whole-line t)
609 #+END_SRC
8a38cc 610
990949 611 ** Coding style
0ba1ff 612 Use java for java, awk for awk and K&R for everything else.
JG 613 K&R uses 4 space tabs.
990949 614 #+BEGIN_SRC emacs-lisp
bf794a 615   (setq c-default-style '((java-mode . "java")
JG 616                          (awk-mode . "awk")
30d015 617                          (other . "k&r")))
990949 618 #+END_SRC
C 619
620 ** Coding system
0b5a77 621 Cause we all love UTF8.
990949 622 #+BEGIN_SRC emacs-lisp
bf794a 623   (set-terminal-coding-system 'utf-8)
JG 624   (set-keyboard-coding-system 'utf-8)
625   (set-language-environment "UTF-8")
626   (prefer-coding-system 'utf-8)
30d015 627   (setq-default indent-tabs-mode nil
JG 628                 tab-width 4
16980b 629                 c-basic-offset tab-width
JG 630                 cperl-indent-level tab-width)
30d015 631   (c-set-offset 'inline-open '0)
bf794a 632   (delete-selection-mode)
JG 633   (global-set-key (kbd "RET") 'newline-and-indent)
990949 634 #+END_SRC
30d015 635 *** Smart tabs
JG 636 Tabs for indentation, spaces for alignment
637 #+BEGIN_SRC emacs-lisp
638     (use-package smart-tabs-mode
639       :ensure t
640       :config
641       (smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python 'ruby
642                             'nxml))
643 #+END_SRC
8a38cc 644
990949 645 ** Move to beginning of line ignoring whitespace
C 646 Move point back to indentation of beginning of line.
0ba1ff 647 Pretty good for getting to the start of what you actually wanted.
990949 648
C 649 Move point to the first non-whitespace character on this line.
650 If point is already there, move to the beginning of the line.
651 Effectively toggle between the first non-whitespace character and
652 the beginning of the line.
653
654 If ARG is not nil or 1, move forward ARG - 1 lines first. If
655 point reaches the beginning or end of the buffer, stop there.
656 #+BEGIN_SRC emacs-lisp
657 (defun prelude-move-beginning-of-line (arg)
658   (interactive "^p")
659   (setq arg (or arg 1))
660
661   ;; Move lines first
662   (when (/= arg 1)
663     (let ((line-move-visual nil))
664       (forward-line (1- arg))))
665
666   (let ((orig-point (point)))
667     (back-to-indentation)
668     (when (= orig-point (point))
669       (move-beginning-of-line 1))))
670
671 (global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)
672 #+END_SRC
8a38cc 673
990949 674 ** Indent region or buffer
0ba1ff 675 Indent, slightly different to standard tab or C-M-\.
990949 676 #+BEGIN_SRC emacs-lisp
C 677 (defun indent-region-or-buffer ()
678   "Indent a region if selected, otherwise the whole buffer."
679   (interactive)
680   (unless (member major-mode prelude-indent-sensitive-modes)
681     (save-excursion
682       (if (region-active-p)
683           (progn
684             (indent-region (region-beginning) (region-end))
685             (message "Indented selected region."))
686         (progn
687           (indent-buffer)
688           (message "Indented buffer.")))
689       (whitespace-cleanup))))
690
691 (global-set-key (kbd "C-c i") 'indent-region-or-buffer)
692 #+END_SRC
8a38cc 693
990949 694 ** Tramp
0ba1ff 695 Remote editing mode.
JG 696 Hate having to re-input passwords.
990949 697 #+BEGIN_SRC emacs-lisp
8b0d06 698   (use-package tramp
JG 699     :ensure t
700     :pin gnu
701     :config
702     ;; (setq tramp-default-method "ssh")
703     (when (eq system-type 'windows-nt)
704       (setq tramp-default-method "pscp"))
ccdb5b 705     (setq password-cache-expiry nil)
JG 706     (add-to-list 'tramp-remote-path 'tramp-own-remote-path))
990949 707 #+END_SRC
C 708
0ba1ff 709 ** COMMENT Y or N instead of yes or no
JG 710 Need not type out whole word.
711 #+BEGIN_SRC emacs-lisp
712   (defalias 'yes-or-no-p 'y-or-n-p)
713 #+END_SRC
714
06a72e 715 ** COMMENT Sublime-like minimap
JG 716 Get a minimap preview of the file on the side like sublime text.
717 Want to make work but need to find a good way of doing so.
718 #+BEGIN_SRC emacs-lisp
719   (use-package sublimity
720     :ensure t
721     :config
722     (require 'sublimity-scroll)
723     (setq sublimity-scroll-weight 4
724           sublimity-scroll-drift-length 3)
725     (require 'sublimity-map)
726     (setq sublimity-map-size 20
727           sublimity-map-scale 0.3)
728     (sublimity-map-set-delay nil)
729     (sublimity-mode 1))
730
731   (use-package minimap
732     :ensure t
733     :config
734     (minimap-mode))
735 #+END_SRC
736
1cfa19 737 ** Highlight indentation
JG 738 Vertical demarcations for indent levels
739 #+BEGIN_SRC emacs-lisp
740   (use-package highlight-indentation
741     :ensure t
742     :hook (prog-mode . highlight-indentation-mode))
743 #+END_SRC
990949 744 * Mode line tweaks
C 745 Diminish is used but is included in init.el such that it can be used throughout this document
746 ** Spaceline
0ba1ff 747 A little easier to read than the default emacs mode line.
990949 748 #+BEGIN_SRC emacs-lisp
412080 749     (use-package spaceline
C 750       :ensure t
751       :config
752       (require 'spaceline-config)
753       (setq spaceline-buffer-encoding-abbrev-p t)
754       (setq spaceline-line-column-p t)
755       (setq spaceline-line-p t)
756       (setq powerline-default-separator (quote arrow))
757       (spaceline-spacemacs-theme)
758       (spaceline-helm-mode))
990949 759 #+END_SRC
8a38cc 760
1005e3 761 *** Separator
JG 762 Slightly nicer separator.
763 #+BEGIN_SRC emacs-lisp
764 (setq powerline-default-separator nil)
765 #+END_SRC
766
0c962c 767 ** Nyan mode
JG 768 Use nyan cat as a reference for buffer progression.
769 #+BEGIN_SRC emacs-lisp
770   (use-package nyan-mode
771     :ensure t
772     :config
773     (nyan-mode 1))
774 #+END_SRC
775
990949 776 * Programming tweaks
C 777 ** Yasnippet
0ba1ff 778 Add snippets, pretty useful.
JG 779 Manually added snippets are in ~/.emacs.d/snippets/{mode}.
990949 780 #+BEGIN_SRC emacs-lisp
bf794a 781   (use-package yasnippet
JG 782     :ensure t
783     :diminish yas-minor-mode
784     :config
785     (yas-global-mode 1))
0b5a77 786
JG 787   (use-package yasnippet-snippets
788     :ensure t
789     :after yasnippet)
990949 790 #+END_SRC
8a38cc 791
0ba1ff 792 ** Flycheck
JG 793 Basic linter. Works pretty well.
990949 794 #+BEGIN_SRC emacs-lisp
8a38cc 795   (use-package flycheck
C 796     :ensure t
797     :diminish flycheck-mode
798     :config
799     (global-flycheck-mode))
990949 800 #+END_SRC
0ba1ff 801 *** flycheck-pos-tip
JG 802 Add suggestions at the cursor.
990949 803 #+BEGIN_SRC emacs-lisp
C 804 (use-package flycheck-pos-tip
805   :ensure t
806   :after flycheck
807   :config
808   (flycheck-pos-tip-mode))
809 #+END_SRC
810 ** Company
0ba1ff 811 Company is auto-complete for Emacs.
JG 812 Uses various backends, more of which are added later.
990949 813 #+BEGIN_SRC emacs-lisp
C 814   (use-package company
815     :ensure t
816     :diminish company-mode
817     :config
818     (global-company-mode)
819     (setq company-idle-delay 0)
e0a5d8 820     (setq company-minimum-prefix-length 1))
990949 821 #+END_SRC
8a38cc 822
e92017 823 ** LSP Mode
3f2799 824 Use LSP for completion suggestions.
JG 825 Causes too much memory usage, need to debug.
0d8394 826 Need to generate ~compile_flags~ for c/c++, can use ~bear~ but may need other tools.
c8124c 827 #+BEGIN_SRC emacs-lisp
JG 828   (use-package lsp-mode
829     :ensure t
0b5a77 830     :hook (((c-mode
0d8394 831              c++-mode
0b5a77 832              tex-mode
JG 833              latex-mode
834              TeX-mode
835              LaTeX-mode
836              rust-mode
837              sh-mode
3cfd40 838              ;; verilog-mode
43cf1d 839              go-mode) . lsp))
c8124c 840     :init
JG 841     (setq lsp-keymap-prefix "C-c l")
842     :commands lsp
843     :config
4b91a3 844     (add-hook 'lsp-mode-hook 'lsp-enable-which-key-integration)
c8124c 845     (setq read-process-output-max (* 1024 1024))
f0bf38 846     (setq lsp-completion-provider :capf)
83addc 847     (setq lsp-keep-workspace-alive 'nil)
f0bf38 848     (add-to-list 'exec-path "~/.cargo/bin"))
e56895 849
c8124c 850   (use-package lsp-ui
JG 851     :ensure t
852     :commands lsp-ui-mode)
e56895 853
c8124c 854   (use-package helm-lsp
JG 855     :ensure t
856     :commands helm-lsp-workspace-symbol)
857 #+END_SRC
0b5a77 858
da7a13 859 ** Version control
JG 860 Settings for emacs' own version control system.
861 *** Enable version control on the mode line
862 #+BEGIN_SRC emacs-lisp
863   (vc-mode)
864 #+END_SRC
0b5a77 865
990949 866 ** Magit
0ba1ff 867 Emacs git client.
JG 868 Pretty good and offers fairly decent features.
990949 869 #+BEGIN_SRC emacs-lisp
C 870   (use-package magit
871     :ensure t
872     :commands magit-get-top-dir
873     :bind ("C-x g" . magit-status)
874     :init
875     (progn
876       ;; make magit status go full-screen but remember previous window
877       ;; settings
878       ;; from: http://whattheemacsd.com/setup-magit.el-01.html
879       (defadvice magit-status (around magit-fullscreen activate)
880         (window-configuration-to-register :magit-fullscreen)
881         ad-do-it
882         (delete-other-windows))
883
884       ;; Close popup when committing - this stops the commit window
885       ;; hanging around
886       ;; From: http://git.io/rPBE0Q
887       (defadvice git-commit-commit (after delete-window activate)
888         (delete-window))
889
890       (defadvice git-commit-abort (after delete-window activate)
891         (delete-window))
892
893       :config
894       (progn
895         ;; restore previously hidden windows
896         (defadvice magit-quit-window (around magit-restore-screen activate)
897           (let ((current-mode major-mode))
898             ad-do-it
899             ;; we only want to jump to register when the last seen buffer
900             ;; was a magit-status buffer.
901             (when (eq 'magit-status-mode current-mode)
902               (jump-to-register :magit-fullscreen)))))
903
904       ;; magit settings
905       (setq
906        ;; don't put "origin-" in front of new branch names by default
907        magit-default-tracking-name-function 'magit-default-tracking-name-branch-only
908        ;; open magit status in same window as current buffer
909        magit-status-buffer-switch-function 'switch-to-buffer
910        ;; highlight word/letter changes in hunk diffs
911        magit-diff-refine-hunk t
912        ;; ask me if I want to include a revision when rewriting
913        magit-rewrite-inclusive 'ask
914        ;; ask me to save buffers
915        magit-save-some-buffers t
916        ;; pop the process buffer if we're taking a while to complete
917        magit-process-popup-time 10
918        ;; ask me if I want a tracking upstream
919        magit-set-upstream-on-push 'askifnotset
920        )))
921 #+END_SRC
8a38cc 922
990949 923 ** CEDET
0ba1ff 924 *** Semantic
JG 925 Parser library for code, supports many other packages.
0b5a77 926 Allows emacs to be more aware of what is being written.
990949 927 #+BEGIN_SRC emacs-lisp
C 928   (use-package semantic
0b5a77 929     :hook (prog-mode . semantic-mode)
990949 930     :config
C 931     (global-semanticdb-minor-mode 1)
932     (global-semantic-idle-scheduler-mode 1)
933     (global-semantic-idle-summary-mode 1)
934     (semantic-mode 1))
935 #+END_SRC
8a38cc 936
a428a2 937 *** COMMENT EDE
0ba1ff 938 Emacs Development Environment.
JG 939 Can be used to manage and create build files for a project.
990949 940 #+BEGIN_SRC emacs-lisp
C 941 (use-package ede
942   :config
943   (global-ede-mode t))
944 #+END_SRC
8a38cc 945
990949 946 *** gdb-many-windows
0ba1ff 947 Enhances the use of GDB in emacs.
JG 948 Shows register contents, variable contents and others in addition to GDB shell.
949 Also shows source code while debugging.
990949 950 #+BEGIN_SRC emacs-lisp
C 951 (setq
952  gdb-many-windows t
953  gdb-show-main t)
954 #+END_SRC
8a38cc 955
0ba1ff 956 *** COMMENT Semantic refactor
JG 957 Trying to get this to work.
958 Should help to refactor file.
990949 959 #+BEGIN_SRC emacs-lisp
0ba1ff 960   (use-package srefactor
JG 961     :ensure t
962     :bind (("M-RET o" . 'srefactor-lisp-one-line)
963        ("M-RET m" . 'srefactor-lisp-format-sexp)
964        ("M-RET d" . 'srefactor-lisp-format-defun)
965        ("M-RET b" . 'srefactor-lisp-format-buffer)
966        :map c-mode-base-map
967             ("M-RET" . 'srefactor-refactor-at-point)
968             :map c++-mode-map
969             ("M-RET" . 'srefactor-refactor-at-point)))
990949 970 #+END_SRC
8a38cc 971
990949 972 ** Language specific configs
C 973 *** C/C++
8dba69 974 **** Flycheck
JG 975 ***** Flycheck clang
0ba1ff 976 Add the clang backend for linting.
990949 977 #+BEGIN_SRC emacs-lisp
0b5a77 978   (use-package flycheck-clang-analyzer
JG 979     :ensure t
980     :after flycheck
981     :config
982     (with-eval-after-load 'flycheck
983       (require 'flycheck-clang-analyzer)
984        (flycheck-clang-analyzer-setup)))
990949 985 #+END_SRC
8dba69 986 ***** Flycheck project root
JG 987 Flycheck tends to fail finding the project root, giving errors about missing files.
988 This should remove them.
989 #+BEGIN_SRC emacs-lisp
990   (defun setup-flycheck-project-path ()
991     (let ((root (ignore-errors (projectile-project-root))))
992       (when root
993         (add-to-list
994          (make-variable-buffer-local 'flycheck-clang-include-path)
995          root)
996         (add-to-list
997          (make-variable-buffer-local 'flycheck-gcc-include-path)
998          root))))
999
1000   (add-hook 'c-mode-hook 'setup-flycheck-project-path)
1001   (add-hook 'c++-mode-hook 'setup-flycheck-project-path)
1002 #+END_SRC
8a38cc 1003
cf3d41 1004 **** COMMENT Company
0ba1ff 1005 Add header completion as well as Irony, which uses clang for suggestions.
990949 1006 #+BEGIN_SRC emacs-lisp
C 1007   (use-package company-c-headers
1008       :ensure t
1009       :after company
1010       :config
1011       (add-hook 'c++-mode-hook 'company-mode)
1012       (add-hook 'c-mode-hook 'company-mode))
1013
9397d2 1014   ;; (use-package irony
JG 1015   ;;   :ensure t
1016   ;;   :init
1017   ;;   (setq w32-pipe-read-delay 0)
1018   ;;   (setq irony-server-w32-pipe-buffer-size (* 64 1024))
1019   ;;   (add-hook 'c++-mode-hook 'irony-mode)
1020   ;;   (add-hook 'c-mode-hook 'irony-mode)
1021   ;;   (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
1022   ;;   (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))
0ba1ff 1023
9397d2 1024   ;; (use-package company-irony
JG 1025   ;;   :ensure t
1026   ;;   :after irony
1027   ;;   :config
1028   ;;   (add-to-list 'company-backends '(company-c-headers
1029   ;;                                    company-dabbrev-code
1030   ;;                                    company-irony)))
990949 1031 #+END_SRC
545e6d 1032 **** Clang-format
27d33b 1033 Automatically format buffer on save.
JG 1034 #+BEGIN_SRC emacs-lisp
1035   (when (file-exists-p "/usr/share/clang/clang-format.el")
1036     (load "/usr/share/clang/clang-format.el")
1037     (setq clang-format-linux-style (concat "{BasedOnStyle: LLVM,"
1038                                            "IndentWidth: 8,"
1039                                            "UseTab: Always,"
1040                                            "BreakBeforeBraces: Linux,"
1041                                            "AllowShortIfStatementsOnASingleLine: false,"
1042                                            "IndentCaseLabels: false}"))
1043     (setq-default clang-format-style clang-format-linux-style)
1044     (defun clang-format-on-save ()
545e6d 1045       (add-hook 'before-save-hook 'clang-format-buffer nil t))
JG 1046     (add-hook 'c-mode-hook 'clang-format-on-save nil t)
1047     (add-hook 'c++-mode-hook 'clang-format-on-save nil t))
27d33b 1048 #+END_SRC
990949 1049 *** emacs-lisp
545e6d 1050 **** COMMENT Company
0ba1ff 1051 Add slime backend.
990949 1052 #+BEGIN_SRC emacs-lisp
C 1053 (add-hook 'emacs-lisp-mode-hook 'company-mode)
1054
1055 (use-package slime
1056   :ensure t
1057   :config
1058   (setq inferior-lisp-program "/usr/bin/sbcl")
1059   (setq slime-contribs '(slime-fancy)))
1060
1061 (use-package slime-company
1062   :ensure t
1063   :init
1064     (require 'company)
1065     (slime-setup '(slime-fancy slime-company)))
1066 #+END_SRC
8a38cc 1067
bf794a 1068 *** COMMENT x86
990949 1069 **** x86-lookup
0ba1ff 1070 Look up reference PDF. Use Intel manual.
990949 1071 #+BEGIN_SRC emacs-lisp
C 1072 (use-package x86-lookup
1073   :ensure t
1074   :init
1075   (setq x86-lookup-pdf "D:/Coding/x86-instructions.pdf")
1076   :bind ("C-h x" . x86-lookup))
1077 #+END_SRC
8a38cc 1078
990949 1079 *** Latex
C 1080 **** AucTex
0ba1ff 1081 AucTex contains many additions to make tex editing good.
990949 1082 #+BEGIN_SRC emacs-lisp
20e001 1083   (use-package tex
C 1084     :ensure auctex
1085     :config
0b5a77 1086     (setq TeX-auto-save t
JG 1087           TeX-parse-self t
1088           TeX-view-program-selection '((output-pdf "PDF Tools"))
20e001 1089           TeX-source-correlate-start-server t)
C 1090     (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer))
990949 1091 #+END_SRC
8a38cc 1092
990949 1093 **** Company
0ba1ff 1094 Help company complete tex math and references.
990949 1095 #+BEGIN_SRC emacs-lisp
C 1096   (use-package company-math
1097     :ensure t
1098     :after company
1099     :config
1005e3 1100     (add-to-list 'company-backends '(company-math-symbols-unicode company-math-symbols-latex
0a6cd2 1101                                      company-latex-commands))
1005e3 1102     (setq company-math-allow-latex-symbols-in-faces t))
990949 1103
C 1104   (use-package company-reftex
1105     :ensure t
1106     :after company
1107     :config
1005e3 1108     (add-to-list 'company-backends 'company-reftex-citations))
990949 1109
C 1110   (use-package company-auctex
1111     :ensure t
1112     :after company
1113     :config
1114     (company-auctex-init))
1115
1116   (use-package company-bibtex
1117     :ensure t
1118     :after company
1119     (add-to-list 'company-backends 'company-bibtex))
1120 #+END_SRC
8a38cc 1121
bf794a 1122 **** TeXcount
0ba1ff 1123 Word counts in latex.
JG 1124 Uses a Perl script.
1125 #+BEGIN_SRC emacs-lisp
1126   (defun get-texcount-latest()
1127     (if (not(file-directory-p "~/.texcount"))
1128         (make-directory "~/.texcount"))
fb9b1b 1129     (url-copy-file "https://app.uio.no/ifi/texcount/download.php?file=texcount_3_2_0_41.zip" "~/.texcount/texcount.zip" 1)
0ba1ff 1130     (shell-command "unzip -o ~/.texcount/texcount.zip -d ~/.texcount")
JG 1131     (add-to-list 'exec-path "~/.texcount/texcount.pl"))
20e001 1132
df1744 1133   (if (not(or (file-exists-p "~/.texcount/texcount.pl") (file-exists-p "/usr/bin/texcount")))
0ba1ff 1134       (get-texcount-latest))
990949 1135
0ba1ff 1136   (defun texcount ()
JG 1137     (interactive)
1138     (let*
1139         ( (this-file (buffer-file-name))
1140           (enc-str (symbol-name buffer-file-coding-system))
1141           (enc-opt
1142            (cond
1143             ((string-match "utf-8" enc-str) "-utf8")
1144             ((string-match "latin" enc-str) "-latin1")
1145             ("-encoding=guess")
1146             ) )
1147           (word-count
1148            (with-output-to-string
1149              (with-current-buffer standard-output
1150                (call-process "texcount" nil t nil "-0" enc-opt this-file)
1151                ) ) ) )
1152       (message word-count)
1153       ) )
1154   (add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-c c") 'texcount)))
1155   (add-hook 'latex-mode-hook (lambda () (define-key latex-mode-map (kbd "C-c c") 'texcount)))
1156 #+END_SRC
990949 1157
C 1158 *** PlantUML
0ba1ff 1159 Sets the PlantUML path for the mode to generate models.
990949 1160 #+BEGIN_SRC emacs-lisp
bf794a 1161   (use-package plantuml-mode
JG 1162     :ensure t
1163     :init
1164     (cond ((eq system-type 'windows-nt)
1730fa 1165            (when (file-exists-p "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar")
JG 1166              (setq plantuml-jar-path "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar")
1167              (setq planuml-default-exec-mode 'jar)))
bf794a 1168           ((eq system-type 'gnu/linux)
1730fa 1169            (when (file-exists-p "/usr/share/java/plantuml/plantuml.jar")
JG 1170              (setq plantuml-jar-path "/usr/share/java/plantuml/plantuml.jar")
1171              (setq planuml-default-exec-mode 'jar)))))
990949 1172 #+END_SRC
C 1173
bf794a 1174 *** COMMENT Racket
990949 1175 **** Major mode
0ba1ff 1176 Set racket path in windows and enable racket mode.
990949 1177 #+BEGIN_SRC emacs-lisp
C 1178   (when (eq system-type 'windows-nt)
1179     (add-to-list 'exec-path "c:/Program Files/Racket")
1180     (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
1181
1182   (use-package racket-mode
1183       :ensure t
1184       :config
1185       (autoload 'racket-mode "Racket" "Racket Editing Mode" t)
1186       (add-to-list
1187        'auto-mode-alist
e0a5d8 1188        '("\\.rkt$" . racket-mode)))
990949 1189 #+END_SRC
C 1190
08c6c1 1191 *** Verilog
baf326 1192 **** Get latest version
387766 1193 Use latest version from repositories.
baf326 1194 #+BEGIN_SRC emacs-lisp
c8124c 1195   (use-package verilog-mode
387766 1196     :ensure t
JG 1197     :pin gnu
c8124c 1198     :config
JG 1199     (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
3cfd40 1200     (add-to-list 'auto-mode-alist '("\\.[ds]?va?h?\\'" . verilog-mode))
JG 1201     (setq-default verilog-align-ifelse t
1202                   verilog-auto-delete-trailing-whitespace t
1203                   verilog-auto-inst-param-value t
1204                   verilog-auto-lineup 'all
1205                   verilog-auto-newline nil
1206                   verilog-auto-save-policy nil
1207                   verilog-auto-template-warn-unused t
1208                   verilog-auto-endcomments nil
1209                   verilog-highlight-grouping-keywords t
1210                   verilog-highlight-modules t
1211                   verilog-tab-to-comment t
1212                   verilog-indent-begin-after-if nil
1213                   verilog-indent-lists nil
1214                   verilog-case-indent 4
1215                   verilog-cexp-indent 0
1216                   verilog-indent-level 4
1217                   verilog-indent-level-behavioral 4
1218                   verilog-indent-level-declaration 4
1219                   verilog-indent-level-directive 4
1220                   verilog-indent-level-module 4))
990949 1221 #+END_SRC
3cfd40 1222 #+END_SRC
0ba1ff 1223 *** COMMENT MATLAB
49aa9f 1224 Mode for editing MATLAB m-files.
JG 1225 #+BEGIN_SRC emacs-lisp
0ba1ff 1226   (use-package matlab
JG 1227     :ensure matlab-mode
1228     :config
1229     (autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
1230     (add-to-list
1231      'auto-mode-alist
1232      '("\\.m$" . matlab-mode))
1233     (setq matlab-indent-function t)
1234     (setq matlab-shell-command "matlab")
1235     (matlab-cedet-setup))
49aa9f 1236 #+END_SRC
JG 1237
0ba1ff 1238 *** COMMENT MIPS
JG 1239 For editing MIPS assembly.
49aa9f 1240 #+BEGIN_SRC emacs-lisp
JG 1241   (use-package mips-mode
1242     :ensure t
1243     :mode "\\.mips$")
1244 #+END_SRC
1245
0ba1ff 1246 *** COMMENT IPython notebooks
60454d 1247 Allow emacs to view and use IPython notebooks
JG 1248 #+BEGIN_SRC emacs-lisp
1249   (use-package ein
1250     :ensure t)
1251 #+END_SRC
1252
22b4cd 1253 *** Rust
JG 1254 **** Major mode
1255 Get the major mode for rust files.
1256 #+BEGIN_SRC emacs-lisp
1257   (use-package rust-mode
1258     :ensure t
1259     :config
1260     ;; style guide suggests spaces not tabs
1261     (add-hook 'rust-mode-hook (lambda () (setq indent-tabs-mode nil)))
1262     (setq rust-format-on-save t))
1263
1264   (use-package toml-mode
1265     :ensure t)
1266 #+END_SRC
1267 **** Cargo integration
1268 Integrate Cargo, rust's package manager.
1269 #+BEGIN_SRC emacs-lisp
1270   (use-package cargo
1271     :ensure t
1272     :hook
1273     (rust-mode . cargo-minor-mode))
1274 #+END_SRC
1275 **** Flycheck
1276 Linting with flycheck.
1277 #+BEGIN_SRC emacs-lisp
1278   (use-package flycheck-rust
1279     :ensure t
1280     :config
0d8394 1281     (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))
22b4cd 1282 #+END_SRC
43cf1d 1283 *** Go
JG 1284 **** Major mode
22b4cd 1285 #+BEGIN_SRC emacs-lisp
43cf1d 1286   (use-package go-mode
22b4cd 1287     :ensure t
43cf1d 1288     :config
JG 1289     (add-hook 'before-save-hook #'gofmt-before-save))
1290 #+END_SRC
1291
1292 #+RESULTS:
1293 : t
1294
1295 **** Flycheck
1296 #+BEGIN_SRC emacs-lisp
1297   (use-package flycheck-golangci-lint
1298     :ensure t
1299     :config
1300     (add-hook 'flycheck-mode-hook #'flycheck-golangci-lint-setup))
1301 #+END_SRC
1302 **** Company
1303 #+BEGIN_SRC emacs-lisp
1304   (use-package company-go
1305     :ensure t)
c8124c 1306 #+END_SRC
990949 1307 * Org mode
C 1308 ** Up to date org
0ba1ff 1309 Pull the latest org mode from the repository, rather than the org which comes with emacs.
990949 1310 #+BEGIN_SRC emacs-lisp
d2a873 1311         (use-package org
JG 1312           :ensure org-contrib)
990949 1313 #+END_SRC
8a38cc 1314
990949 1315 ** Small tweaks
0ba1ff 1316 Small quality of life changes to org-mode.
990949 1317 #+BEGIN_SRC emacs-lisp
C 1318 (setq org-src-fontify-natively t)
1319 (setq org-src-tab-acts-natively t)
1320 (setq org-confirm-babel-evaluate nil)
1321 (setq org-export-with-smart-quotes t)
1322 (setq org-src-window-setup 'current-window)
1323 (add-hook 'org-mode-hook 'org-indent-mode)
1324 (diminish 'org-indent-mode)
1325 (diminish 'visual-line-mode)
1326 #+END_SRC
a428a2 1327 *** Spell checking for code and latex
JG 1328 #+BEGIN_SRC emacs-lisp
1329   (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
1330   (add-to-list 'ispell-skip-region-alist '("\\$" . "\\$"))
1331   (add-to-list 'ispell-skip-region-alist '("\\$\\$" . "\\$\\$"))
1332 #+END_SRC
8a38cc 1333
990949 1334 ** Line wrapping
0ba1ff 1335 Enable line wrapping for long lines.
990949 1336 #+BEGIN_SRC emacs-lisp
C 1337   (add-hook 'org-mode-hook
bf794a 1338             '(lambda ()
JG 1339                (visual-line-mode 1)))
990949 1340 #+END_SRC
8a38cc 1341
d2a873 1342 ** Fancy org points
0ba1ff 1343 Use bullets of different colours and styles instead of the "\*\*\*" to denote indentation levels.
990949 1344 #+BEGIN_SRC emacs-lisp
d2a873 1345   (use-package org-superstar
bf794a 1346     :ensure t
JG 1347     :config
d2a873 1348     (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1))))
990949 1349 #+END_SRC
8a38cc 1350
990949 1351 ** Org Babel
0ba1ff 1352 Allows the execution of code from within an org buffer.
JG 1353 Code output can also be input to the buffer.
990949 1354 *** Languages
0ba1ff 1355 Add a bunch of languages to org babel supported languages
990949 1356 #+BEGIN_SRC emacs-lisp
baf326 1357     (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t)
C 1358                                                              (C . t)
1359                                                              (python . t)
1360                                                              (latex . t)
1361                                                              (scheme . t)
1362                                                              (gnuplot . t)
1363                                                              (matlab . t)
1364                                                              (fortran . t)
1365                                                              (java . t)
1366                                                              (plantuml . t)))
1367 #+END_SRC
1368
0ba1ff 1369 **** PlantUML path
JG 1370 Org uses its own path for some reason.
baf326 1371 #+BEGIN_SRC emacs-lisp
C 1372   (setq org-plantuml-jar-path plantuml-jar-path)
990949 1373 #+END_SRC
8a38cc 1374
5a75e4 1375 *** Async export
JG 1376 Allow the editing of files while execution of blocks is occurring.
1377 Needs :async tag in src header.
1378 #+BEGIN_SRC emacs-lisp
1379   (use-package ob-async
1380     :ensure t)
1381 #+END_SRC
1382
990949 1383 ** Latex preview fragments match colour
C 1384 Make the previews match theme colour of Emacs.
0ba1ff 1385 Gets very annoying very quickly without it.
990949 1386 #+BEGIN_SRC emacs-lisp
C 1387   (let ((dvipng--plist (alist-get 'dvipng org-preview-latex-process-alist)))
1388     (plist-put dvipng--plist :use-xcolor t)
1389     (plist-put dvipng--plist :image-converter '("dvipng -D %D -T tight -o %O %f")))
1390 #+END_SRC
bf794a 1391
0ba1ff 1392 ** Org export additions
f552a0 1393 *** Pandoc
0ba1ff 1394 Call pandoc on org buffer from org export.
f552a0 1395 Need to add ~#+OPTIONS: H:99~ to enable large level header exports.
0ba1ff 1396 #+BEGIN_SRC emacs-lisp
JG 1397   (use-package ox-pandoc
1398     :ensure t)
1399 #+END_SRC
1400
1401 *** COMMENT Dokuwiki Wiki
1402 Allow export to dokuwiki markup from org.
1403 #+BEGIN_SRC emacs-lisp
1404   (use-package ox-wk
1405     :ensure t)
1406 #+END_SRC
1407
1408 * COMMENT EMMS
be9cff 1409 Emacs media manager.
0ba1ff 1410 I come back to it every now and again as an MPD front-end, but haven't quite gotten the hang of it.
be9cff 1411 #+BEGIN_SRC emacs-lisp
JG 1412   (use-package emms-setup
1413     :ensure emms
1414     :init
1415     (add-to-list 'load-path "~/elisp/emms/")
1416     :config
1417     (emms-all)
1418     (emms-default-players)
1419     (setq emms-source-file-directory "~/Music/"))
1420 #+END_SRC
1421
a428a2 1422 * COMMENT Org Blog
0ba1ff 1423 I use org to write my blog and use org-static-blog to generate the HTML.
be9cff 1424 ** Org static blog config
0ba1ff 1425 Basic configuration for site.
JG 1426 Copied and modified from the example configuration.
be9cff 1427 #+BEGIN_SRC emacs-lisp
1005e3 1428   (use-package org-static-blog
JG 1429     :ensure t
1430     :config
1431     (setq org-static-blog-publish-title "Joel's Site")
1432     (setq org-static-blog-publish-url "https://blog.joelg.cf/")
1433     (setq org-static-blog-publish-directory "/backup/home/joel/Downloads/Chizi123.github.io/")
1434     (setq org-static-blog-posts-directory "/backup/home/joel/Downloads/Chizi123.github.io/posts/")
1435     (setq org-static-blog-drafts-directory "/backup/home/joel/Downloads/Chizi123.github.io/drafts/")
1436     (setq org-static-blog-enable-tags t)
1437     (setq org-export-with-toc nil)
1438     (setq org-export-with-section-numbers nil)
be9cff 1439
1005e3 1440     ;; This header is inserted into the <head> section of every page:
JG 1441     ;;   (you will need to create the style sheet at
1442     ;;    ~/projects/blog/static/style.css
1443     ;;    and the favicon at
1444     ;;    ~/projects/blog/static/favicon.ico)
1445     (setq org-static-blog-page-header
1446           "<meta name=\"author\" content=\"Joel Grunbaum\">
0ba1ff 1447       <meta name=\"referrer\" content=\"no-referrer\">
JG 1448       <link href= \"static/style.css\" rel=\"stylesheet\" type=\"text/css\" />
1449       <link rel=\"icon\" href=\"static/favicon.png\">
1450       <script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-147303155-2\"></script>
1451       <script>
1452         window.dataLayer = window.dataLayer || [];
1453         function gtag(){dataLayer.push(arguments);}
1454         gtag('js', new Date());
1455         gtag('config', 'UA-147303155-2');
1456       </script>
1457       ")
be9cff 1458
1005e3 1459     ;; This preamble is inserted at the beginning of the <body> of every page:
JG 1460     ;;   This particular HTML creates a <div> with a simple linked headline
1461     (setq org-static-blog-page-preamble
1462           "<div class=\"header\">
0ba1ff 1463         <a href=\"https://blog.joelg.cf\">Joel's Site - Personal site and constant work in progress</a>
JG 1464         <div class=\"sitelinks\">
1465           <a href=\"https://blog.joelg.cf/about-me.html\">About Me</a> |
1466           <a href=\"https://github.com/Chizi123\">Github</a> |
1467           <a href=\"https://facebook.com/joel.grun.5\">Facebook</a>
1468         </div>
1469       </div>")
1470
1005e3 1471     ;; This postamble is inserted at the end of the <body> of every page:
JG 1472     ;;   This particular HTML creates a <div> with a link to the archive page
1473     ;;   and a licensing stub.
1474     (setq org-static-blog-page-postamble
1475           "<div id=\"archive\">
0ba1ff 1476         <a href=\"https://blog.joelg.cf/archive.html\">Other posts</a>
be9cff 1477       </div>
0ba1ff 1478       <br>
1005e3 1479       <center><button id=\"disqus_button\" onclick=\"load_disqus()\">Load Disqus Comments</button></center>
JG 1480     <div id=\"disqus_thread\"></div>
1481     <script type=\"text/javascript\">
1482       function load_disqus() {
1483           var dsq = document.createElement('script');
1484           dsq.type = 'text/javascript';
1485           dsq.async = true;
1486           dsq.src = 'https://joelg-cf.disqus.com/embed.js';
1487           (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
1488           document.getElementById('disqus_button').style.visibility = 'hidden';
1489       };
1490     </script>"))
be9cff 1491 #+END_SRC
JG 1492
0ba1ff 1493 ** Sitemap addition
JG 1494 Creates a sitemap.xml for the blog based on the generated HTML files output in the final directory.
1495 #+BEGIN_SRC emacs-lisp
1496   (defun blog-publish()
1497     (interactive)
1498     (org-static-blog-publish)
1499     (setq n 0)
1500     (setq site "https://blog.joelg.cf/")
1501     (setq posts (directory-files org-static-blog-publish-directory))
1502     (generate-new-buffer "sitemap.xml.gen")
1503     (with-current-buffer "sitemap.xml.gen" (insert "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"))
1504     (while (< n (length (directory-files org-static-blog-publish-directory)))
1505       (setq curr (nth n posts))
1506       (if (string-match "\\(html\\)" curr)
1507           (if (string-match "index.html" curr)
1508               (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site "</loc>\n\t</url>\n")))
1509             (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site curr "</loc>\n\t</url>\n")))))
1510       (setq n (1+ n)))
1511     (with-current-buffer "sitemap.xml.gen" (insert "</urlset>"))
1512     (with-current-buffer "sitemap.xml.gen" (write-region (point-min) (point-max) (concat org-static-blog-publish-directory "sitemap.xml")) t)
1513     (kill-buffer "sitemap.xml.gen"))
1514 #+END_SRC
1515
be9cff 1516 ** Emacs-htmlize
0ba1ff 1517 Allow org features to be exported to HTML for site.
be9cff 1518 #+BEGIN_SRC emacs-lisp
JG 1519   (use-package htmlize
0b5a77 1520     :ensure t
JG 1521     :defer t)
be9cff 1522 #+END_SRC
0ba1ff 1523
a428a2 1524 * Journaling
JG 1525 ** Noteworthy entries
1526 I write weekly journal entries recapping my week.
1527 These files are in org mode.
1528 This is inspired by org-static-blog.
1529 #+BEGIN_SRC emacs-lisp
1530   (defun journal-create-new-post ()
1531       "Create a new entry, prompt for title and insert header"
1532     (interactive)
1533     (let ((title (read-string "Title: ")))
1534       (find-file (concat "~/Documents/Journal/entry/"
1535                          (read-string "Filename: "
1536                                       (concat (format-time-string "%Y-%m-%d-" (current-time))
1537                                               (replace-regexp-in-string "\s" "-" (downcase title))
1538                                               ".org"))))
1539       (insert "#+title: " title "\n"
1540               "#+date: " (format-time-string "<%Y-%m-%d %H:%M>") "\n"
1541               "#+filetags: ")))
1542 #+END_SRC
1543 *** Publish entries
1544 Use org-publish to collate entries into a single unit.
1545 #+BEGIN_SRC emacs-lisp
1546   (setq org-publish-project-alist
1547                '(("Journal"
1548                  :base-directory "~/Documents/Journal/entry/"
1549                  :publishing-directory "~/Documents/Journal/out/"
1550                  :publishing-function org-html-publish-to-html
0a6cd2 1551                  ;;:htmlized-source t
a428a2 1552                  :section-numbers nil
JG 1553                  :html-preamble t
0a6cd2 1554                  :html-validation-link nil
JG 1555
a428a2 1556                  :auto-sitemap t
0a6cd2 1557                  :sitemap-sort-files anti-chronologically
JG 1558                  :sitemap-file-entry-format "%d - %t"
1559                  :sitemap-title "Home"
1560                  :sitemap-filename "index.html"
1561                  :sitemap-function org-publish-sitemap)))
5a75e4 1562 #+END_SRC