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

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