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

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