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

Joel Grunbaum
2021-01-27 af0806f06cc98353b09254da5c023e9b321f3997
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")
11          (add-to-list 'exec-path "c:/Program Files/gnuplot")
12          (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
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
990949 89 ** Remove menu bar, toolbar, but keep 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)
94   (scroll-bar-mode 1)
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")
27d33b 617                          (other . "linux")))
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)
627   (setq-default indent-tabs-mode t
27d33b 628                 tab-width 8
16980b 629                 c-basic-offset tab-width
JG 630                 cperl-indent-level tab-width)
bf794a 631   (delete-selection-mode)
JG 632   (global-set-key (kbd "RET") 'newline-and-indent)
990949 633 #+END_SRC
8a38cc 634
990949 635 ** Move to beginning of line ignoring whitespace
C 636 Move point back to indentation of beginning of line.
0ba1ff 637 Pretty good for getting to the start of what you actually wanted.
990949 638
C 639 Move point to the first non-whitespace character on this line.
640 If point is already there, move to the beginning of the line.
641 Effectively toggle between the first non-whitespace character and
642 the beginning of the line.
643
644 If ARG is not nil or 1, move forward ARG - 1 lines first. If
645 point reaches the beginning or end of the buffer, stop there.
646 #+BEGIN_SRC emacs-lisp
647 (defun prelude-move-beginning-of-line (arg)
648   (interactive "^p")
649   (setq arg (or arg 1))
650
651   ;; Move lines first
652   (when (/= arg 1)
653     (let ((line-move-visual nil))
654       (forward-line (1- arg))))
655
656   (let ((orig-point (point)))
657     (back-to-indentation)
658     (when (= orig-point (point))
659       (move-beginning-of-line 1))))
660
661 (global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)
662 #+END_SRC
8a38cc 663
990949 664 ** Indent region or buffer
0ba1ff 665 Indent, slightly different to standard tab or C-M-\.
990949 666 #+BEGIN_SRC emacs-lisp
C 667 (defun indent-region-or-buffer ()
668   "Indent a region if selected, otherwise the whole buffer."
669   (interactive)
670   (unless (member major-mode prelude-indent-sensitive-modes)
671     (save-excursion
672       (if (region-active-p)
673           (progn
674             (indent-region (region-beginning) (region-end))
675             (message "Indented selected region."))
676         (progn
677           (indent-buffer)
678           (message "Indented buffer.")))
679       (whitespace-cleanup))))
680
681 (global-set-key (kbd "C-c i") 'indent-region-or-buffer)
682 #+END_SRC
8a38cc 683
990949 684 ** Tramp
0ba1ff 685 Remote editing mode.
JG 686 Hate having to re-input passwords.
990949 687 #+BEGIN_SRC emacs-lisp
C 688   (when (eq system-type 'windows-nt)
689     (setq tramp-default-method "pscp"))
690   (setq password-cache-expiry nil)
691 #+END_SRC
692
0ba1ff 693 ** COMMENT Y or N instead of yes or no
JG 694 Need not type out whole word.
695 #+BEGIN_SRC emacs-lisp
696   (defalias 'yes-or-no-p 'y-or-n-p)
697 #+END_SRC
698
06a72e 699 ** COMMENT Sublime-like minimap
JG 700 Get a minimap preview of the file on the side like sublime text.
701 Want to make work but need to find a good way of doing so.
702 #+BEGIN_SRC emacs-lisp
703   (use-package sublimity
704     :ensure t
705     :config
706     (require 'sublimity-scroll)
707     (setq sublimity-scroll-weight 4
708           sublimity-scroll-drift-length 3)
709     (require 'sublimity-map)
710     (setq sublimity-map-size 20
711           sublimity-map-scale 0.3)
712     (sublimity-map-set-delay nil)
713     (sublimity-mode 1))
714
715   (use-package minimap
716     :ensure t
717     :config
718     (minimap-mode))
719 #+END_SRC
720
990949 721 * Mode line tweaks
C 722 Diminish is used but is included in init.el such that it can be used throughout this document
723 ** Spaceline
0ba1ff 724 A little easier to read than the default emacs mode line.
990949 725 #+BEGIN_SRC emacs-lisp
412080 726     (use-package spaceline
C 727       :ensure t
728       :config
729       (require 'spaceline-config)
730       (setq spaceline-buffer-encoding-abbrev-p t)
731       (setq spaceline-line-column-p t)
732       (setq spaceline-line-p t)
733       (setq powerline-default-separator (quote arrow))
734       (spaceline-spacemacs-theme)
735       (spaceline-helm-mode))
990949 736 #+END_SRC
8a38cc 737
1005e3 738 *** Separator
JG 739 Slightly nicer separator.
740 #+BEGIN_SRC emacs-lisp
741 (setq powerline-default-separator nil)
742 #+END_SRC
743
0c962c 744 ** Nyan mode
JG 745 Use nyan cat as a reference for buffer progression.
746 #+BEGIN_SRC emacs-lisp
747   (use-package nyan-mode
748     :ensure t
749     :config
750     (nyan-mode 1))
751 #+END_SRC
752
990949 753 * Programming tweaks
C 754 ** Yasnippet
0ba1ff 755 Add snippets, pretty useful.
JG 756 Manually added snippets are in ~/.emacs.d/snippets/{mode}.
990949 757 #+BEGIN_SRC emacs-lisp
bf794a 758   (use-package yasnippet
JG 759     :ensure t
760     :diminish yas-minor-mode
761     :config
762     (yas-global-mode 1))
0b5a77 763
JG 764   (use-package yasnippet-snippets
765     :ensure t
766     :after yasnippet)
990949 767 #+END_SRC
8a38cc 768
0ba1ff 769 ** Flycheck
JG 770 Basic linter. Works pretty well.
990949 771 #+BEGIN_SRC emacs-lisp
8a38cc 772   (use-package flycheck
C 773     :ensure t
774     :diminish flycheck-mode
0b5a77 775     :hook (prog-mode . flycheck-mode)
8a38cc 776     :config
C 777     (global-flycheck-mode))
990949 778 #+END_SRC
0ba1ff 779 *** flycheck-pos-tip
JG 780 Add suggestions at the cursor.
990949 781 #+BEGIN_SRC emacs-lisp
C 782 (use-package flycheck-pos-tip
783   :ensure t
784   :after flycheck
785   :config
786   (flycheck-pos-tip-mode))
787 #+END_SRC
8a38cc 788
990949 789 ** Company
0ba1ff 790 Company is auto-complete for Emacs.
JG 791 Uses various backends, more of which are added later.
990949 792 #+BEGIN_SRC emacs-lisp
C 793   (use-package company
794     :ensure t
795     :diminish company-mode
796     :config
797     (global-company-mode)
798     (setq company-idle-delay 0)
799     (setq company-minimum-prefix-length 3))
800 #+END_SRC
8a38cc 801
3f2799 802 ** COMMENT LSP Mode
JG 803 Use LSP for completion suggestions.
804 Causes too much memory usage, need to debug.
c8124c 805 #+BEGIN_SRC emacs-lisp
JG 806   (use-package lsp-mode
807     :ensure t
0b5a77 808     :hook (((c-mode
JG 809              cpp-mode
810              tex-mode
811              latex-mode
812              TeX-mode
813              LaTeX-mode
814              rust-mode
815              sh-mode
816              verilog-mode) . lsp))
c8124c 817     :init
JG 818     (setq lsp-keymap-prefix "C-c l")
819     :commands lsp
820     :config
0b5a77 821     (add-hook lsp-mode-hook lsp-enable-which-key-integration)
c8124c 822     (setq read-process-output-max (* 1024 1024))
f0bf38 823     (setq lsp-completion-provider :capf)
JG 824     (add-to-list 'exec-path "~/.cargo/bin"))
c8124c 825
JG 826   (use-package lsp-ui
827     :ensure t
828     :commands lsp-ui-mode)
829
830   (use-package helm-lsp
831     :ensure t
832     :commands helm-lsp-workspace-symbol)
833 #+END_SRC
0b5a77 834
da7a13 835 ** Version control
JG 836 Settings for emacs' own version control system.
837 *** Enable version control on the mode line
838 #+BEGIN_SRC emacs-lisp
839   (vc-mode)
840 #+END_SRC
0b5a77 841
990949 842 ** Magit
0ba1ff 843 Emacs git client.
JG 844 Pretty good and offers fairly decent features.
990949 845 #+BEGIN_SRC emacs-lisp
C 846   (use-package magit
847     :ensure t
848     :commands magit-get-top-dir
849     :bind ("C-x g" . magit-status)
850     :init
851     (progn
852       ;; make magit status go full-screen but remember previous window
853       ;; settings
854       ;; from: http://whattheemacsd.com/setup-magit.el-01.html
855       (defadvice magit-status (around magit-fullscreen activate)
856         (window-configuration-to-register :magit-fullscreen)
857         ad-do-it
858         (delete-other-windows))
859
860       ;; Close popup when committing - this stops the commit window
861       ;; hanging around
862       ;; From: http://git.io/rPBE0Q
863       (defadvice git-commit-commit (after delete-window activate)
864         (delete-window))
865
866       (defadvice git-commit-abort (after delete-window activate)
867         (delete-window))
868
869       :config
870       (progn
871         ;; restore previously hidden windows
872         (defadvice magit-quit-window (around magit-restore-screen activate)
873           (let ((current-mode major-mode))
874             ad-do-it
875             ;; we only want to jump to register when the last seen buffer
876             ;; was a magit-status buffer.
877             (when (eq 'magit-status-mode current-mode)
878               (jump-to-register :magit-fullscreen)))))
879
880       ;; magit settings
881       (setq
882        ;; don't put "origin-" in front of new branch names by default
883        magit-default-tracking-name-function 'magit-default-tracking-name-branch-only
884        ;; open magit status in same window as current buffer
885        magit-status-buffer-switch-function 'switch-to-buffer
886        ;; highlight word/letter changes in hunk diffs
887        magit-diff-refine-hunk t
888        ;; ask me if I want to include a revision when rewriting
889        magit-rewrite-inclusive 'ask
890        ;; ask me to save buffers
891        magit-save-some-buffers t
892        ;; pop the process buffer if we're taking a while to complete
893        magit-process-popup-time 10
894        ;; ask me if I want a tracking upstream
895        magit-set-upstream-on-push 'askifnotset
896        )))
897 #+END_SRC
8a38cc 898
990949 899 ** CEDET
0ba1ff 900 *** Semantic
JG 901 Parser library for code, supports many other packages.
0b5a77 902 Allows emacs to be more aware of what is being written.
990949 903 #+BEGIN_SRC emacs-lisp
C 904   (use-package semantic
0b5a77 905     :hook (prog-mode . semantic-mode)
990949 906     :config
C 907     (global-semanticdb-minor-mode 1)
908     (global-semantic-idle-scheduler-mode 1)
909     (global-semantic-idle-summary-mode 1)
910     (semantic-mode 1))
911 #+END_SRC
8a38cc 912
a428a2 913 *** COMMENT EDE
0ba1ff 914 Emacs Development Environment.
JG 915 Can be used to manage and create build files for a project.
990949 916 #+BEGIN_SRC emacs-lisp
C 917 (use-package ede
918   :config
919   (global-ede-mode t))
920 #+END_SRC
8a38cc 921
990949 922 *** gdb-many-windows
0ba1ff 923 Enhances the use of GDB in emacs.
JG 924 Shows register contents, variable contents and others in addition to GDB shell.
925 Also shows source code while debugging.
990949 926 #+BEGIN_SRC emacs-lisp
C 927 (setq
928  gdb-many-windows t
929  gdb-show-main t)
930 #+END_SRC
8a38cc 931
0ba1ff 932 *** COMMENT Semantic refactor
JG 933 Trying to get this to work.
934 Should help to refactor file.
990949 935 #+BEGIN_SRC emacs-lisp
0ba1ff 936   (use-package srefactor
JG 937     :ensure t
938     :bind (("M-RET o" . 'srefactor-lisp-one-line)
939        ("M-RET m" . 'srefactor-lisp-format-sexp)
940        ("M-RET d" . 'srefactor-lisp-format-defun)
941        ("M-RET b" . 'srefactor-lisp-format-buffer)
942        :map c-mode-base-map
943             ("M-RET" . 'srefactor-refactor-at-point)
944             :map c++-mode-map
945             ("M-RET" . 'srefactor-refactor-at-point)))
990949 946 #+END_SRC
8a38cc 947
990949 948 ** Language specific configs
C 949 *** C/C++
0ba1ff 950 **** Flycheck clang
JG 951 Add the clang backend for linting.
990949 952 #+BEGIN_SRC emacs-lisp
0b5a77 953   (use-package flycheck-clang-analyzer
JG 954     :ensure t
955     :after flycheck
956     :config
957     (with-eval-after-load 'flycheck
958       (require 'flycheck-clang-analyzer)
959        (flycheck-clang-analyzer-setup)))
990949 960 #+END_SRC
8a38cc 961
0ba1ff 962 **** Company
JG 963 Add header completion as well as Irony, which uses clang for suggestions.
990949 964 #+BEGIN_SRC emacs-lisp
C 965   (use-package company-c-headers
966       :ensure t
967       :after company
968       :config
969       (add-hook 'c++-mode-hook 'company-mode)
970       (add-hook 'c-mode-hook 'company-mode))
971
972   (use-package irony
973     :ensure t
974     :init
975     (setq w32-pipe-read-delay 0)
976     (setq irony-server-w32-pipe-buffer-size (* 64 1024))
977     (add-hook 'c++-mode-hook 'irony-mode)
978     (add-hook 'c-mode-hook 'irony-mode)
979     (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
980     (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))
0ba1ff 981
JG 982   (use-package company-irony
983     :ensure t
0b5a77 984     :after irony
0ba1ff 985     :config
JG 986     (add-to-list 'company-backends '(company-c-headers
987                                      company-dabbrev-code
988                                      company-irony)))
990949 989 #+END_SRC
27d33b 990 **** Clang-format
JG 991 Automatically format buffer on save.
992 #+BEGIN_SRC emacs-lisp
993   (when (file-exists-p "/usr/share/clang/clang-format.el")
994     (load "/usr/share/clang/clang-format.el")
995     (setq clang-format-linux-style (concat "{BasedOnStyle: LLVM,"
996                                            "IndentWidth: 8,"
997                                            "UseTab: Always,"
998                                            "BreakBeforeBraces: Linux,"
999                                            "AllowShortIfStatementsOnASingleLine: false,"
1000                                            "IndentCaseLabels: false}"))
1001     (setq-default clang-format-style clang-format-linux-style)
1002     (defun clang-format-on-save ()
1003       (add-hook 'before-save-hook 'clang-format-buffer))
1004     (add-hook 'c-mode-hook 'clang-format-on-save)
1005     (add-hook 'c++-mode-hook 'clang-format-on-save))
1006 #+END_SRC
990949 1007 *** emacs-lisp
0ba1ff 1008 **** COMMENT company
JG 1009 Add slime backend.
990949 1010 #+BEGIN_SRC emacs-lisp
C 1011 (add-hook 'emacs-lisp-mode-hook 'company-mode)
1012
1013 (use-package slime
1014   :ensure t
1015   :config
1016   (setq inferior-lisp-program "/usr/bin/sbcl")
1017   (setq slime-contribs '(slime-fancy)))
1018
1019 (use-package slime-company
1020   :ensure t
1021   :init
1022     (require 'company)
1023     (slime-setup '(slime-fancy slime-company)))
1024 #+END_SRC
8a38cc 1025
bf794a 1026 *** COMMENT x86
990949 1027 **** x86-lookup
0ba1ff 1028 Look up reference PDF. Use Intel manual.
990949 1029 #+BEGIN_SRC emacs-lisp
C 1030 (use-package x86-lookup
1031   :ensure t
1032   :init
1033   (setq x86-lookup-pdf "D:/Coding/x86-instructions.pdf")
1034   :bind ("C-h x" . x86-lookup))
1035 #+END_SRC
8a38cc 1036
990949 1037 *** Latex
C 1038 **** AucTex
0ba1ff 1039 AucTex contains many additions to make tex editing good.
990949 1040 #+BEGIN_SRC emacs-lisp
20e001 1041   (use-package tex
C 1042     :ensure auctex
1043     :config
0b5a77 1044     (setq TeX-auto-save t
JG 1045           TeX-parse-self t
1046           TeX-view-program-selection '((output-pdf "PDF Tools"))
20e001 1047           TeX-source-correlate-start-server t)
C 1048     (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer))
990949 1049 #+END_SRC
8a38cc 1050
990949 1051 **** Company
0ba1ff 1052 Help company complete tex math and references.
990949 1053 #+BEGIN_SRC emacs-lisp
C 1054   (use-package company-math
1055     :ensure t
1056     :after company
1057     :config
1005e3 1058     (add-to-list 'company-backends '(company-math-symbols-unicode company-math-symbols-latex
0a6cd2 1059                                      company-latex-commands))
1005e3 1060     (setq company-math-allow-latex-symbols-in-faces t))
990949 1061
C 1062   (use-package company-reftex
1063     :ensure t
1064     :after company
1065     :config
1005e3 1066     (add-to-list 'company-backends 'company-reftex-citations))
990949 1067
C 1068   (use-package company-auctex
1069     :ensure t
1070     :after company
1071     :config
1072     (company-auctex-init))
1073
1074   (use-package company-bibtex
1075     :ensure t
1076     :after company
1077     (add-to-list 'company-backends 'company-bibtex))
1078 #+END_SRC
8a38cc 1079
bf794a 1080 **** TeXcount
0ba1ff 1081 Word counts in latex.
JG 1082 Uses a Perl script.
1083 #+BEGIN_SRC emacs-lisp
1084   (defun get-texcount-latest()
1085     (if (not(file-directory-p "~/.texcount"))
1086         (make-directory "~/.texcount"))
1087     (url-copy-file "https://app.uio.no/ifi/texcount/download.php?file=texcount_3_1_1.zip" "~/.texcount/texcount.zip" 1)
1088     (shell-command "unzip -o ~/.texcount/texcount.zip -d ~/.texcount")
1089     (add-to-list 'exec-path "~/.texcount/texcount.pl"))
20e001 1090
df1744 1091   (if (not(or (file-exists-p "~/.texcount/texcount.pl") (file-exists-p "/usr/bin/texcount")))
0ba1ff 1092       (get-texcount-latest))
990949 1093
0ba1ff 1094   (defun texcount ()
JG 1095     (interactive)
1096     (let*
1097         ( (this-file (buffer-file-name))
1098           (enc-str (symbol-name buffer-file-coding-system))
1099           (enc-opt
1100            (cond
1101             ((string-match "utf-8" enc-str) "-utf8")
1102             ((string-match "latin" enc-str) "-latin1")
1103             ("-encoding=guess")
1104             ) )
1105           (word-count
1106            (with-output-to-string
1107              (with-current-buffer standard-output
1108                (call-process "texcount" nil t nil "-0" enc-opt this-file)
1109                ) ) ) )
1110       (message word-count)
1111       ) )
1112   (add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-c c") 'texcount)))
1113   (add-hook 'latex-mode-hook (lambda () (define-key latex-mode-map (kbd "C-c c") 'texcount)))
1114 #+END_SRC
990949 1115
C 1116 *** PlantUML
0ba1ff 1117 Sets the PlantUML path for the mode to generate models.
990949 1118 #+BEGIN_SRC emacs-lisp
bf794a 1119   (use-package plantuml-mode
JG 1120     :ensure t
1121     :init
1122     (cond ((eq system-type 'windows-nt)
1123            (setq plantuml-jar-path "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar"))
1124           ((eq system-type 'gnu/linux)
4659c3 1125            (setq plantuml-jar-path "/usr/share/java/plantuml/plantuml.jar")))
JG 1126     (setq planuml-default-exec-mode 'jar))
990949 1127 #+END_SRC
C 1128
bf794a 1129 *** COMMENT Racket
990949 1130 **** Major mode
0ba1ff 1131 Set racket path in windows and enable racket mode.
990949 1132 #+BEGIN_SRC emacs-lisp
C 1133   (when (eq system-type 'windows-nt)
1134     (add-to-list 'exec-path "c:/Program Files/Racket")
1135     (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
1136
1137   (use-package racket-mode
1138       :ensure t
1139       :config
1140       (autoload 'racket-mode "Racket" "Racket Editing Mode" t)
1141       (add-to-list
1142        'auto-mode-alist
8a38cc 1143        '("\\.rkt$" . racket-mode))
990949 1144       (setq matlab-indent-function t))
C 1145 #+END_SRC
1146
0ba1ff 1147 *** COMMENT Verilog
baf326 1148 **** Get latest version
0ba1ff 1149 Pull the latest version from the web.
baf326 1150 #+BEGIN_SRC emacs-lisp
C 1151   (defun get-verilog-latest()
0864ff 1152     (if (not(file-directory-p "~/.emacs.d/elpa/verilog-mode"))
C 1153         (make-directory "~/.emacs.d/elpa/verilog-mode"))
1154     (if (file-exists-p "~/.emacs.d/elpa/verilog-mode/verilog-mode.el")
1155         (delete-file "~/.emacs.d/elpa/verilog-mode/verilog-mode.el"))
dc8eb0 1156     (url-copy-file "https://www.veripool.org/ftp/verilog-mode.el" "~/.emacs.d/elpa/verilog-mode/verilog-mode.el" 1))
baf326 1157 #+END_SRC
C 1158
1159 **** Integrate into emacs
0ba1ff 1160 Add updated version (based off auto-package-update) and integrate it with Emacs.
990949 1161 #+BEGIN_SRC emacs-lisp
c8124c 1162   (defun verilog-read-file-as-string (file)
JG 1163     "Read FILE contents."
1164     (when (file-exists-p file)
0864ff 1165       (with-temp-buffer
c8124c 1166         (insert-file-contents file)
JG 1167         (buffer-string))))
0864ff 1168
c8124c 1169   (defun verilog-write-string-to-file (file string)
JG 1170     "Substitute FILE contents with STRING."
1171     (with-temp-buffer
1172       (insert string)
1173       (when (file-writable-p file)
1174         (write-region (point-min)
1175                       (point-max)
1176                       file))))
0864ff 1177
c8124c 1178   (defun verilog-today-day ()
JG 1179     (time-to-days (current-time)))
0864ff 1180
c8124c 1181   (defun should-update-verilog-p ()
JG 1182     "Return non-nil when an update is due."
1183     (and
1184      (or
1185       (not (file-exists-p "~/.emacs.d/.last-verilog-update-day"))
1186       (if (>= (/ (- (verilog-today-day) (verilog-read-last-update-day)) 7) 1)
1187           t
1188         nil))))
0864ff 1189
c8124c 1190   (defun verilog-read-last-update-day ()
JG 1191     "Read last update day."
1192     (string-to-number
1193      (verilog-read-file-as-string "~/.emacs.d/.last-verilog-update-day")))
0864ff 1194
c8124c 1195   (defun verilog-write-current-day ()
JG 1196     "Store current day."
1197     (verilog-write-string-to-file
1198      "~/.emacs.d/.last-verilog-update-day"
1199      (int-to-string (verilog-today-day))))
1200
1201   (use-package verilog-mode
1202     :init
1203     (when (should-update-verilog-p)
1204         (get-verilog-latest)
1205         (verilog-write-current-day))
1206     (add-to-list 'load-path "~/.emacs.d/elpa/verilog-mode/verilog-mode.el")
1207     :config
1208     (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
1209     (add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode)))
990949 1210 #+END_SRC
8a38cc 1211
0ba1ff 1212 *** COMMENT MATLAB
49aa9f 1213 Mode for editing MATLAB m-files.
JG 1214 #+BEGIN_SRC emacs-lisp
0ba1ff 1215   (use-package matlab
JG 1216     :ensure matlab-mode
1217     :config
1218     (autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
1219     (add-to-list
1220      'auto-mode-alist
1221      '("\\.m$" . matlab-mode))
1222     (setq matlab-indent-function t)
1223     (setq matlab-shell-command "matlab")
1224     (matlab-cedet-setup))
49aa9f 1225 #+END_SRC
JG 1226
0ba1ff 1227 *** COMMENT MIPS
JG 1228 For editing MIPS assembly.
49aa9f 1229 #+BEGIN_SRC emacs-lisp
JG 1230   (use-package mips-mode
1231     :ensure t
1232     :mode "\\.mips$")
1233 #+END_SRC
1234
0ba1ff 1235 *** COMMENT IPython notebooks
60454d 1236 Allow emacs to view and use IPython notebooks
JG 1237 #+BEGIN_SRC emacs-lisp
1238   (use-package ein
1239     :ensure t)
1240 #+END_SRC
1241
22b4cd 1242 *** Rust
JG 1243 **** Major mode
1244 Get the major mode for rust files.
1245 #+BEGIN_SRC emacs-lisp
1246   (use-package rust-mode
1247     :ensure t
1248     :config
1249     ;; style guide suggests spaces not tabs
1250     (add-hook 'rust-mode-hook (lambda () (setq indent-tabs-mode nil)))
1251     (setq rust-format-on-save t))
1252
1253   (use-package toml-mode
1254     :ensure t)
1255 #+END_SRC
1256 **** Cargo integration
1257 Integrate Cargo, rust's package manager.
1258 #+BEGIN_SRC emacs-lisp
1259   (use-package cargo
1260     :ensure t
1261     :hook
1262     (rust-mode . cargo-minor-mode))
1263 #+END_SRC
1264 **** Flycheck
1265 Linting with flycheck.
1266 #+BEGIN_SRC emacs-lisp
1267   (use-package flycheck-rust
1268     :ensure t
1269     :config
1270     (add-hook 'flyckeck-mode-hook #'flycheck-rust-setup))
1271 #+END_SRC
1272
1273 **** COMMENT Completion
1274 Code completion with racer.
1275 #+BEGIN_SRC emacs-lisp
1276   (use-package racer
1277     :ensure t
1278     :hook ((rust-mode . racer-mode)
1279            (racer-mode . (eldoc-mode company-mode)))
1280     :init
1281     (setq racer-command "~/.cargo/bin/racer"))
c8124c 1282 #+END_SRC
990949 1283 * Org mode
C 1284 ** Up to date org
0ba1ff 1285 Pull the latest org mode from the repository, rather than the org which comes with emacs.
990949 1286 #+BEGIN_SRC emacs-lisp
C 1287     (use-package org
0ba1ff 1288       :ensure org-plus-contrib
990949 1289       :pin org)
C 1290 #+END_SRC
8a38cc 1291
990949 1292 ** Small tweaks
0ba1ff 1293 Small quality of life changes to org-mode.
990949 1294 #+BEGIN_SRC emacs-lisp
C 1295 (setq org-src-fontify-natively t)
1296 (setq org-src-tab-acts-natively t)
1297 (setq org-confirm-babel-evaluate nil)
1298 (setq org-export-with-smart-quotes t)
1299 (setq org-src-window-setup 'current-window)
1300 (add-hook 'org-mode-hook 'org-indent-mode)
1301 (diminish 'org-indent-mode)
1302 (diminish 'visual-line-mode)
1303 #+END_SRC
a428a2 1304 *** Spell checking for code and latex
JG 1305 #+BEGIN_SRC emacs-lisp
1306   (add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
1307   (add-to-list 'ispell-skip-region-alist '("\\$" . "\\$"))
1308   (add-to-list 'ispell-skip-region-alist '("\\$\\$" . "\\$\\$"))
1309 #+END_SRC
8a38cc 1310
990949 1311 ** Line wrapping
0ba1ff 1312 Enable line wrapping for long lines.
990949 1313 #+BEGIN_SRC emacs-lisp
C 1314   (add-hook 'org-mode-hook
bf794a 1315             '(lambda ()
JG 1316                (visual-line-mode 1)))
990949 1317 #+END_SRC
8a38cc 1318
990949 1319 ** org-bullets
0ba1ff 1320 Use bullets of different colours and styles instead of the "\*\*\*" to denote indentation levels.
990949 1321 #+BEGIN_SRC emacs-lisp
bf794a 1322   (use-package org-bullets
JG 1323     :ensure t
1324     :config
990949 1325     (add-hook 'org-mode-hook (lambda () (org-bullets-mode))))
C 1326 #+END_SRC
8a38cc 1327
990949 1328 ** Org Babel
0ba1ff 1329 Allows the execution of code from within an org buffer.
JG 1330 Code output can also be input to the buffer.
990949 1331 *** Languages
0ba1ff 1332 Add a bunch of languages to org babel supported languages
990949 1333 #+BEGIN_SRC emacs-lisp
baf326 1334     (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t)
C 1335                                                              (C . t)
1336                                                              (python . t)
1337                                                              (latex . t)
1338                                                              (scheme . t)
1339                                                              (gnuplot . t)
1340                                                              (matlab . t)
1341                                                              (plantuml . t)
1342                                                              (fortran . t)
1343                                                              (java . t)
1344                                                              (plantuml . t)))
1345 #+END_SRC
1346
0ba1ff 1347 **** PlantUML path
JG 1348 Org uses its own path for some reason.
baf326 1349 #+BEGIN_SRC emacs-lisp
C 1350   (setq org-plantuml-jar-path plantuml-jar-path)
990949 1351 #+END_SRC
8a38cc 1352
5a75e4 1353 *** Async export
JG 1354 Allow the editing of files while execution of blocks is occurring.
1355 Needs :async tag in src header.
1356 #+BEGIN_SRC emacs-lisp
1357   (use-package ob-async
1358     :ensure t)
1359 #+END_SRC
1360
990949 1361 ** Latex preview fragments match colour
C 1362 Make the previews match theme colour of Emacs.
0ba1ff 1363 Gets very annoying very quickly without it.
990949 1364 #+BEGIN_SRC emacs-lisp
C 1365   (let ((dvipng--plist (alist-get 'dvipng org-preview-latex-process-alist)))
1366     (plist-put dvipng--plist :use-xcolor t)
1367     (plist-put dvipng--plist :image-converter '("dvipng -D %D -T tight -o %O %f")))
1368 #+END_SRC
bf794a 1369
0ba1ff 1370 ** Org export additions
0b5a77 1371 *** COMMENT Pandoc
0ba1ff 1372 Call pandoc on org buffer from org export.
JG 1373 #+BEGIN_SRC emacs-lisp
1374   (use-package ox-pandoc
1375     :ensure t)
1376 #+END_SRC
1377
1378 *** COMMENT Dokuwiki Wiki
1379 Allow export to dokuwiki markup from org.
1380 #+BEGIN_SRC emacs-lisp
1381   (use-package ox-wk
1382     :ensure t)
1383 #+END_SRC
1384
1385 * COMMENT EMMS
be9cff 1386 Emacs media manager.
0ba1ff 1387 I come back to it every now and again as an MPD front-end, but haven't quite gotten the hang of it.
be9cff 1388 #+BEGIN_SRC emacs-lisp
JG 1389   (use-package emms-setup
1390     :ensure emms
1391     :init
1392     (add-to-list 'load-path "~/elisp/emms/")
1393     :config
1394     (emms-all)
1395     (emms-default-players)
1396     (setq emms-source-file-directory "~/Music/"))
1397 #+END_SRC
1398
a428a2 1399 * COMMENT Org Blog
0ba1ff 1400 I use org to write my blog and use org-static-blog to generate the HTML.
be9cff 1401 ** Org static blog config
0ba1ff 1402 Basic configuration for site.
JG 1403 Copied and modified from the example configuration.
be9cff 1404 #+BEGIN_SRC emacs-lisp
1005e3 1405   (use-package org-static-blog
JG 1406     :ensure t
1407     :config
1408     (setq org-static-blog-publish-title "Joel's Site")
1409     (setq org-static-blog-publish-url "https://blog.joelg.cf/")
1410     (setq org-static-blog-publish-directory "/backup/home/joel/Downloads/Chizi123.github.io/")
1411     (setq org-static-blog-posts-directory "/backup/home/joel/Downloads/Chizi123.github.io/posts/")
1412     (setq org-static-blog-drafts-directory "/backup/home/joel/Downloads/Chizi123.github.io/drafts/")
1413     (setq org-static-blog-enable-tags t)
1414     (setq org-export-with-toc nil)
1415     (setq org-export-with-section-numbers nil)
be9cff 1416
1005e3 1417     ;; This header is inserted into the <head> section of every page:
JG 1418     ;;   (you will need to create the style sheet at
1419     ;;    ~/projects/blog/static/style.css
1420     ;;    and the favicon at
1421     ;;    ~/projects/blog/static/favicon.ico)
1422     (setq org-static-blog-page-header
1423           "<meta name=\"author\" content=\"Joel Grunbaum\">
0ba1ff 1424       <meta name=\"referrer\" content=\"no-referrer\">
JG 1425       <link href= \"static/style.css\" rel=\"stylesheet\" type=\"text/css\" />
1426       <link rel=\"icon\" href=\"static/favicon.png\">
1427       <script async src=\"https://www.googletagmanager.com/gtag/js?id=UA-147303155-2\"></script>
1428       <script>
1429         window.dataLayer = window.dataLayer || [];
1430         function gtag(){dataLayer.push(arguments);}
1431         gtag('js', new Date());
1432         gtag('config', 'UA-147303155-2');
1433       </script>
1434       ")
be9cff 1435
1005e3 1436     ;; This preamble is inserted at the beginning of the <body> of every page:
JG 1437     ;;   This particular HTML creates a <div> with a simple linked headline
1438     (setq org-static-blog-page-preamble
1439           "<div class=\"header\">
0ba1ff 1440         <a href=\"https://blog.joelg.cf\">Joel's Site - Personal site and constant work in progress</a>
JG 1441         <div class=\"sitelinks\">
1442           <a href=\"https://blog.joelg.cf/about-me.html\">About Me</a> |
1443           <a href=\"https://github.com/Chizi123\">Github</a> |
1444           <a href=\"https://facebook.com/joel.grun.5\">Facebook</a>
1445         </div>
1446       </div>")
1447
1005e3 1448     ;; This postamble is inserted at the end of the <body> of every page:
JG 1449     ;;   This particular HTML creates a <div> with a link to the archive page
1450     ;;   and a licensing stub.
1451     (setq org-static-blog-page-postamble
1452           "<div id=\"archive\">
0ba1ff 1453         <a href=\"https://blog.joelg.cf/archive.html\">Other posts</a>
be9cff 1454       </div>
0ba1ff 1455       <br>
1005e3 1456       <center><button id=\"disqus_button\" onclick=\"load_disqus()\">Load Disqus Comments</button></center>
JG 1457     <div id=\"disqus_thread\"></div>
1458     <script type=\"text/javascript\">
1459       function load_disqus() {
1460           var dsq = document.createElement('script');
1461           dsq.type = 'text/javascript';
1462           dsq.async = true;
1463           dsq.src = 'https://joelg-cf.disqus.com/embed.js';
1464           (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
1465           document.getElementById('disqus_button').style.visibility = 'hidden';
1466       };
1467     </script>"))
be9cff 1468 #+END_SRC
JG 1469
0ba1ff 1470 ** Sitemap addition
JG 1471 Creates a sitemap.xml for the blog based on the generated HTML files output in the final directory.
1472 #+BEGIN_SRC emacs-lisp
1473   (defun blog-publish()
1474     (interactive)
1475     (org-static-blog-publish)
1476     (setq n 0)
1477     (setq site "https://blog.joelg.cf/")
1478     (setq posts (directory-files org-static-blog-publish-directory))
1479     (generate-new-buffer "sitemap.xml.gen")
1480     (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"))
1481     (while (< n (length (directory-files org-static-blog-publish-directory)))
1482       (setq curr (nth n posts))
1483       (if (string-match "\\(html\\)" curr)
1484           (if (string-match "index.html" curr)
1485               (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site "</loc>\n\t</url>\n")))
1486             (with-current-buffer "sitemap.xml.gen" (insert (concat "\t<url>\n\t\t<loc>" site curr "</loc>\n\t</url>\n")))))
1487       (setq n (1+ n)))
1488     (with-current-buffer "sitemap.xml.gen" (insert "</urlset>"))
1489     (with-current-buffer "sitemap.xml.gen" (write-region (point-min) (point-max) (concat org-static-blog-publish-directory "sitemap.xml")) t)
1490     (kill-buffer "sitemap.xml.gen"))
1491 #+END_SRC
1492
be9cff 1493 ** Emacs-htmlize
0ba1ff 1494 Allow org features to be exported to HTML for site.
be9cff 1495 #+BEGIN_SRC emacs-lisp
JG 1496   (use-package htmlize
0b5a77 1497     :ensure t
JG 1498     :defer t)
be9cff 1499 #+END_SRC
0ba1ff 1500
a428a2 1501 * Journaling
JG 1502 ** Noteworthy entries
1503 I write weekly journal entries recapping my week.
1504 These files are in org mode.
1505 This is inspired by org-static-blog.
1506 #+BEGIN_SRC emacs-lisp
1507   (defun journal-create-new-post ()
1508       "Create a new entry, prompt for title and insert header"
1509     (interactive)
1510     (let ((title (read-string "Title: ")))
1511       (find-file (concat "~/Documents/Journal/entry/"
1512                          (read-string "Filename: "
1513                                       (concat (format-time-string "%Y-%m-%d-" (current-time))
1514                                               (replace-regexp-in-string "\s" "-" (downcase title))
1515                                               ".org"))))
1516       (insert "#+title: " title "\n"
1517               "#+date: " (format-time-string "<%Y-%m-%d %H:%M>") "\n"
1518               "#+filetags: ")))
1519 #+END_SRC
1520 *** Publish entries
1521 Use org-publish to collate entries into a single unit.
1522 #+BEGIN_SRC emacs-lisp
1523   (setq org-publish-project-alist
1524                '(("Journal"
1525                  :base-directory "~/Documents/Journal/entry/"
1526                  :publishing-directory "~/Documents/Journal/out/"
1527                  :publishing-function org-html-publish-to-html
0a6cd2 1528                  ;;:htmlized-source t
a428a2 1529                  :section-numbers nil
JG 1530                  :html-preamble t
0a6cd2 1531                  :html-validation-link nil
JG 1532
a428a2 1533                  :auto-sitemap t
0a6cd2 1534                  :sitemap-sort-files anti-chronologically
JG 1535                  :sitemap-file-entry-format "%d - %t"
1536                  :sitemap-title "Home"
1537                  :sitemap-filename "index.html"
1538                  :sitemap-function org-publish-sitemap)))
5a75e4 1539 #+END_SRC