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

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