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

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