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

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