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

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