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

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