emacs.d

My emacs configuration, done in a literate programming fashion using org-mode

git clone git://git.shimmy1996.com/emacs.d.git

README.org (52332B)

    1 #+TITLE: My Emacs Config
    2 #+AUTHOR: Shimmy Xu
    3 #+TODO: DISABLED(t) | ENABLED(d)
    4 #+PROPERTY: header-args :results none
    5 
    6 This is my humble collection of Emacs config, modeled after
    7 [[https://github.com/admiralakber/simplemacs][simplemacs]], documented
    8 in an hopefully understandable manner. I went from using multiple
    9 =.org= files back to a single one because =org-mode= is fantastic and
   10 my config is not too complicated for a single file to handle (yet).
   11 
   12 | Module        | Function                     |
   13 |---------------+------------------------------|
   14 | [[Packages]]      | Package management.          |
   15 | [[Aesthetics]]    | UI and theme.                |
   16 | [[Plugins]]       | Larger scale packages.       |
   17 | [[Mode Specific]] | Settings specific to a mode. |
   18 | [[Enhancements]]  | Plug-and-play enhancements.  |
   19 
   20 * Packages
   21 Manage my package settings.
   22 
   23 ** Package Repositories
   24 Initialize Emacs Package Manager and add repositories.
   25 #+BEGIN_SRC emacs-lisp
   26   (package-initialize)
   27   (require 'package)
   28   (let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
   29                       (not (gnutls-available-p))))
   30          (url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
   31         (add-to-list 'package-archives (cons "melpa" url) t))
   32   (when (< emacs-major-version 24)
   33     ;; For important compatibility libraries like cl-lib
   34     (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
   35 #+END_SRC
   36 
   37 ** Setup =use-package=
   38 Bootstrap =use-package= so that package requirements can be handled in separate
   39 sections.
   40 #+BEGIN_SRC emacs-lisp
   41   (unless (package-installed-p 'use-package)
   42     (package-refresh-contents)
   43     (package-install 'use-package))
   44 #+END_SRC
   45 
   46 * Aesthetics
   47 Mostly aesthetics and quality of life changes.
   48 
   49 ** 80 Character Limit
   50 Set =fill-column= to 80 characters.
   51 #+BEGIN_SRC emacs-lisp
   52   (setq-default fill-column 80)
   53 #+END_SRC
   54 
   55 Highlight portions of line over 80 characters in =prog-mode=.
   56 #+BEGIN_SRC emacs-lisp
   57   (require 'whitespace)
   58   (setq whitespace-line-column 80)
   59   (setq whitespace-style '(face empty tabs lines-tail trailing))
   60   (add-hook 'prog-mode-hook 'whitespace-mode)
   61 #+END_SRC
   62 
   63 ** Auto Detect File Changes
   64 Enable auto revert mode to auto-refresh when files have changed on disk.
   65 #+BEGIN_SRC emacs-lisp
   66   (global-auto-revert-mode t)
   67 #+END_SRC
   68 
   69 ** Color Themes
   70 Install =base16-theme= and enable gruvbox dark pale.
   71 #+BEGIN_SRC emacs-lisp
   72     (use-package base16-theme
   73       :ensure t
   74       :config
   75       (load-theme 'base16-gruvbox-dark-pale t))
   76 #+END_SRC
   77 
   78 ** Customize Settings in Separate File
   79 Save customized settings in a separate file than =init.el=. Create the customization file if none found.
   80 #+BEGIN_SRC emacs-lisp
   81   (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
   82   (unless (file-exists-p custom-file)
   83     (write-region "" "" custom-file))
   84   (load custom-file)
   85 #+END_SRC
   86 
   87 ** Fcitx
   88 Install fcitx support.
   89 #+BEGIN_SRC emacs-lisp
   90   (use-package fcitx
   91     :ensure t
   92     :init
   93     (fcitx-aggressive-setup)
   94     (setq fcitx-use-dbus t))
   95 #+END_SRC
   96 
   97 *** Daemon Support
   98 If using Emacs daemon with =systemd=, remember to add to the
   99 =.service= file:
  100 
  101 #+BEGIN_SRC sh
  102   Environment="LC_CTYPE=zh_CN.UTF-8" "XMODIFIERS=@im=fcitx"
  103 #+END_SRC
  104 
  105 It would also help to change the default command for =emacs= into:
  106 #+BEGIN_SRC sh
  107   emacsclient -c -a emacs
  108 #+END_SRC
  109 
  110 ** Font Settings
  111 *** Default Fonts
  112 Specify font settings.
  113 #+BEGIN_SRC emacs-lisp
  114   (defvar user/cjk-font "Noto Sans CJK SC"
  115     "Default font for CJK characters.")
  116 
  117   (defvar user/latin-font "Iosevka Term SS09"
  118     "Default font for Latin characters.")
  119 
  120   (defvar user/unicode-font "Symbola"
  121     "Default font for Unicode characters, including emojis.")
  122 
  123   (defvar user/font-size 17
  124     "Default font size in px.")
  125 
  126   (defvar user/standard-fontset
  127     (create-fontset-from-fontset-spec standard-fontset-spec)
  128     "Standard fontset for user.")
  129 
  130   ;; Ensure user/standard-fontset gets used for new frames.
  131   (add-to-list 'default-frame-alist (cons 'font user/standard-fontset))
  132   (add-to-list 'initial-frame-alist (cons 'font user/standard-fontset))
  133 #+END_SRC
  134 
  135 *** CJK Font Scaling
  136 Ensure CJK fonts scales correctly to twice the width of mono-space half-width
  137 characters. I tried to add something similar for Unicode fonts, but found that
  138 they don't have uniform width anyways (not to mention that not all of them are
  139 full-width), rendering this method useless.
  140 
  141 I think CJK fonts have less granular sizing controls, i.e. the actual glyph size
  142 of size 16 and size 17 are in fact the same and only starts actually increasing
  143 after we hit size 18.
  144 
  145 #+BEGIN_SRC emacs-lisp
  146   (defvar user/cjk-font-scale
  147     '((16 . 1.0)
  148       (17 . 1.1)
  149       (18 . 1.0))
  150     "Scaling factor to use for cjk font of given size.")
  151 
  152   ;; Specify scaling factor for CJK font.
  153   (setq face-font-rescale-alist
  154         (list (cons user/cjk-font
  155                     (cdr (assoc user/font-size user/cjk-font-scale)))))
  156 #+END_SRC
  157 
  158 *** Fontset with CJK and Unicode Fallback
  159 To ensure fontset gets correctly configured, I simply created one from
  160 scratch. This is because =emacsclient= seems to have a different dynamic when
  161 creating =startup-fontset= and no other method guarantees consistent behavior
  162 between =emacs= and =emacsclient=.
  163 
  164 Use ~C-u C-x =~ to examine the font used for a specific character and use
  165 =describe-fontset= to check if our changes went through.
  166 
  167 #+BEGIN_SRC emacs-lisp
  168   ;; Enable font customization for charset 'symbols, which contains puncuation
  169   ;; marks, emoji, etc.
  170   (setq use-default-font-for-symbols nil)
  171 
  172   (defun user/set-font ()
  173     "Set Unicode, Latin and CJK font for user/standard-fontset."
  174     ;; Unicode font.
  175     (set-fontset-font user/standard-fontset 'unicode
  176                       (font-spec :family user/unicode-font)
  177                       nil 'prepend)
  178     ;; Latin font.
  179     ;; Only specify size here to allow text-scale-adjust work on other fonts.
  180     (set-fontset-font user/standard-fontset 'latin
  181                       (font-spec :family user/latin-font :size user/font-size)
  182                       nil 'prepend)
  183     ;; CJK font.
  184     (dolist (charset '(kana han cjk-misc hangul kanbun bopomofo))
  185       (set-fontset-font user/standard-fontset charset
  186                         (font-spec :family user/cjk-font)
  187                         nil 'prepend))
  188     ;; Special settings for certain CJK puncuation marks.
  189     ;; These are full-width characters but by default uses half-width glyphs.
  190     (dolist (charset '((#x2018 . #x2019)    ;; Curly single quotes "‘’"
  191                        (#x201c . #x201d)))  ;; Curly double quotes "“”"
  192       (set-fontset-font user/standard-fontset charset
  193                         (font-spec :family user/cjk-font)
  194                         nil 'prepend)))
  195 
  196   ;; Apply changes.
  197   (user/set-font)
  198   ;; For emacsclient.
  199   (add-hook 'before-make-frame-hook #'user/set-font)
  200 #+END_SRC
  201 
  202 ** Line Highlighting
  203 Enable line highlighting.
  204 #+BEGIN_SRC emacs-lisp
  205   (global-hl-line-mode t)
  206 #+END_SRC
  207 
  208 ** Line Numbering
  209 Use =display-line-numbers= instead of =linum=.
  210 Enable relative line numbering, and set minimum width to 3.
  211 #+BEGIN_SRC emacs-lisp
  212   (setq-default display-line-numbers-type (quote relative))
  213   (setq-default display-line-numbers-width 3)
  214   (global-display-line-numbers-mode)
  215 #+END_SRC
  216 
  217 ** Line Wrapping
  218 Enable line wrapping by default.
  219 #+BEGIN_SRC emacs-lisp
  220   (global-visual-line-mode t)
  221 #+end_SRC
  222 
  223 ** No Tabs
  224 Use spaces for indenting.
  225 #+BEGIN_SRC emacs-lisp
  226   (setq-default indent-tabs-mode nil)
  227 #+END_SRC
  228 
  229 For those that uses tab, set width to 4.
  230 #+BEGIN_SRC emacs-lisp
  231   (setq-default tab-width 4)
  232 #+END_SRC
  233 
  234 ** Parenthesis Highlighting
  235 Highlight matching parenthesis.
  236 #+BEGIN_SRC emacs-lisp
  237   (show-paren-mode t)
  238 #+END_SRC
  239 
  240 ** Rainbow Delimiters
  241 =rainbow-delimiters= is a "rainbow parentheses"-like mode which highlights delimiters such as parentheses, brackets or braces according to their depth.
  242 
  243 Install =rainbow-delimiters= and enable it for =prog-mode=.
  244 #+BEGIN_SRC emacs-lisp
  245   (use-package rainbow-delimiters
  246     :ensure t
  247     :init (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
  248 #+END_SRC
  249 
  250 ** Remove Trailing Whitespace
  251 Remove trailing whitespace upon saving.
  252 #+BEGIN_SRC emacs-lisp
  253   (add-hook 'before-save-hook 'delete-trailing-whitespace)
  254 #+END_SRC
  255 
  256 ** Save Backups Elsewhere
  257 Save =*~= backups in =$(pwd)/.bak=.
  258 #+BEGIN_SRC emacs-lisp
  259   (setq backup-directory-alist
  260         '(("." . ".bak"))
  261         )
  262 #+END_SRC
  263 
  264 ** Show Column Number
  265 #+BEGIN_SRC emacs-lisp
  266   (setq column-number-mode t)
  267 #+END_SRC
  268 
  269 ** DISABLED Smooth Scrolling
  270 *** DISABLED Sublimity
  271 #+BEGIN_SRC emacs-lisp
  272   (use-package sublimity
  273     :ensure t
  274     :config
  275     (require 'sublimity-scroll)
  276     (require 'sublimity-map)
  277     (sublimity-global-mode))
  278 #+END_SRC
  279 
  280 *** Smooth
  281 #+BEGIN_SRC emacs-lisp
  282   (use-package smooth-scrolling
  283     :ensure t
  284     :config (smooth-scrolling-mode 1))
  285 #+END_SRC
  286 
  287 ** UI Settings
  288 *** *bars
  289 Hide menu, scrollbar and toolbars.
  290 #+BEGIN_SRC emacs-lisp
  291   (menu-bar-mode -1)
  292   (scroll-bar-mode -1)
  293   (tool-bar-mode -1)
  294 #+END_SRC
  295 
  296 **** New Frame Scrollbar
  297 Remove scrollbar for any new frames as well, useful for =emacsclient=.
  298 #+BEGIN_SRC emacs-lisp
  299   (defun user/disable-scroll-bars (frame)
  300     (modify-frame-parameters frame
  301                              '((vertical-scroll-bars . nil)
  302                                (horizontal-scroll-bars . nil))))
  303   (add-hook 'after-make-frame-functions 'user/disable-scroll-bars)
  304 #+END_SRC
  305 
  306 *** Half screen fix
  307 Fills up gap in the border when tiling Emacs to half-screen.
  308 #+BEGIN_SRC emacs-lisp
  309   (setq frame-resize-pixelwise t)
  310 #+END_SRC
  311 
  312 ** Zoom In
  313 Use mouse wheel to adjust zoom level.
  314 #+BEGIN_SRC emacs-lisp
  315   (global-set-key [C-mouse-4] 'text-scale-increase)
  316   (global-set-key [C-mouse-5] 'text-scale-decrease)
  317 #+END_SRC
  318 
  319 * Plugins
  320 Larger scale packages that either requires more configuration, or
  321 fundamentally changes how Emacs behave. Because these package
  322 configurations is a lot more complex and may be spread out, any
  323 subtree that depends on packages in this section will have a tag to
  324 mark the dependency.
  325 
  326 ** Ivy
  327 Flexible, simple tools for minibuffer completion in Emacs.
  328 
  329 Ivy, a generic completion mechanism for Emacs.
  330 Counsel, a collection of Ivy-enhanced versions of common Emacs commands.
  331 Swiper, an Ivy-enhanced alternative to isearch.
  332 
  333 *** Installation
  334 #+BEGIN_SRC emacs-lisp
  335   (use-package ivy
  336     :ensure t
  337     :init
  338     (setq enable-recursive-minibuffers t)
  339     (ivy-mode 1)
  340     :config
  341     ;; Show recents and bookmarks in find-file.
  342     (setq ivy-use-virtual-buffers t)
  343     ;; Use Enter to navigate into the directory, not open it with dired.
  344     (define-key ivy-minibuffer-map (kbd "C-m") 'ivy-alt-done)
  345     ;; Use C-l to go back one level.
  346     (define-key ivy-minibuffer-map (kbd "C-l") 'ivy-backward-delete-char)
  347     :bind
  348     (("C-c C-r" . ivy-resume)))
  349   (use-package counsel
  350     :ensure t
  351     :bind
  352     (("M-x"     . counsel-M-x)
  353      ("M-y"     . counsel-yank-pop)
  354      ("C-c c f" . counsel-git)
  355      ("C-c c s" . counsel-git-grep)
  356      ("C-x C-f" . counsel-find-file)
  357      ("C-x r b" . counsel-bookmark)
  358      ("C-h a"   . counsel-apropos)
  359      ("C-h f"   . counsel-describe-function)
  360      ("C-h v"   . counsel-describe-variable)
  361      ("C-h l"   . counsel-find-library)
  362      ("C-h b"   . counsel-descbinds)
  363      ("C-h i"   . counsel-info-lookup-symbol)
  364      ("<f2> u"  . counsel-unicode-char)))
  365   (use-package swiper
  366     :ensure t
  367     :bind
  368     (("C-s"     . swiper)))
  369 #+END_SRC
  370 
  371 *** Integration
  372 Integration with =magit= and =projectile=.
  373 #+BEGIN_SRC emacs-lisp
  374   (setq magit-completing-read-function 'ivy-completing-read)
  375   (setq projectile-completion-system 'ivy)
  376 #+END_SRC
  377 
  378 ** DISABLED Helm
  379 Stolen from Admiral Akber's config.
  380 
  381 *** Install
  382 Helm is incredible, it really supercharges emacs. It's a framework for
  383 incremental searching / completion / narrowing down options. Sounds
  384 simple, and it is in application, and it's so worth it.
  385 
  386 Web: [[https://emacs-helm.github.io/helm/]]
  387 Git: [[https://github.com/emacs-helm/helm]]
  388 #+BEGIN_SRC emacs-lisp
  389   (use-package helm
  390     :ensure t
  391     :init (helm-mode t))
  392   (require 'helm-config)
  393 #+END_SRC
  394 
  395 *** Visual customization
  396 I want helm to automatically resize and appear in the current buffer
  397 only.
  398 #+BEGIN_SRC emacs-lisp
  399   (setq helm-autoresize-mode 1)
  400   (setq helm-split-window-in-side-p t)
  401 #+END_SRC
  402 
  403 *** Fuzzy matching
  404 Fuzzy matching works most of the time, it does seem to have the issue
  405 of only matching forward i.e. "machine snow" will not match with "snow
  406 machine".
  407 
  408 It does make it a lot easier to search through Emacs functions though
  409 as you only need to remember one part of the function name.
  410 #+BEGIN_SRC emacs-lisp
  411   ;; Enable Fuzzy Matching
  412   (setq helm-recentf-fuzzy-match       t
  413         helm-buffers-fuzzy-matching    t
  414         helm-recentf-fuzzy-match       t
  415         helm-buffers-fuzzy-matching    t
  416         helm-locate-fuzzy-match        t
  417         helm-apropos-fuzzy-match       t
  418         helm-lisp-fuzzy-completion     t
  419         helm-candidate-number-limit    250)
  420 #+END_SRC
  421 
  422 *** Keybindings
  423 Above defaults overides such as =M-x= these are custom bindings.
  424 
  425 **** Self help
  426 The Emacs culture is to have great documentation with your functions,
  427 all searchable via =apropos=. Helm provides a nice interface to this,
  428 use it often.
  429 #+BEGIN_SRC emacs-lisp
  430   (global-set-key (kbd "C-h a") 'helm-apropos)
  431   (global-set-key (kbd "C-h i") 'helm-info-emacs)
  432 #+END_SRC
  433 
  434 **** Buffers and files
  435 Buffers and files are an obvious case where helm is very useful.
  436 #+BEGIN_SRC emacs-lisp
  437   (global-set-key (kbd "C-x b")   'helm-mini)
  438   (global-set-key (kbd "C-x C-b") 'helm-buffers-list)
  439   (global-set-key (kbd "M-x")     'helm-M-x)
  440   (global-set-key (kbd "C-x C-f") 'helm-find-files)
  441   (global-set-key (kbd "C-x C-r") 'helm-recentf)
  442   (global-set-key (kbd "C-x r l") 'helm-filtered-bookmarks)
  443 #+END_SRC
  444 
  445 **** Advanced editing
  446 Kill ring memory, grepping, etc, all gorgeous with helm.
  447 #+BEGIN_SRC emacs-lisp
  448   (global-set-key (kbd "M-y")     'helm-show-kill-ring)
  449   (global-set-key (kbd "C-x c g") 'helm-do-grep)
  450   (global-set-key (kbd "C-x c o") 'helm-occur)
  451 #+END_SRC
  452 
  453 **** The overloaded tab key
  454 The good ol' =TAB= key is used for a lot, in this case I want to make
  455 sure that when used in helm that it completes in helm, not attempting
  456 to insert a snippet or something.
  457 #+BEGIN_SRC emacs-lisp
  458   (define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)
  459 #+END_SRC
  460 
  461 Also, the following makes sure that tab works when running in terminal
  462 mode:
  463 #+BEGIN_SRC emacs-lisp
  464   (define-key helm-map (kbd "C-i") 'helm-execute-persistent-action)
  465 #+END_SRC
  466 
  467 This requires fixing the select other actions which IIRC is set to
  468 ~C-i~ by default.
  469 #+BEGIN_SRC emacs-lisp
  470   (define-key helm-map (kbd "C-z") 'helm-select-action)
  471 #+END_SRC
  472 
  473 ** Company
  474 Auto completion of everything with nice backends.
  475 
  476 *** Installation
  477 Install =company= and enable it globally.
  478 #+BEGIN_SRC emacs-lisp
  479   (use-package company
  480     :ensure t
  481     :init (global-company-mode))
  482 #+END_SRC
  483 
  484 *** Tweaks
  485 **** Adjust Delay
  486 Set delay for auto-completion. 0 would be too extreme and wastes CPU clocks apparently.
  487 #+BEGIN_SRC emacs-lisp
  488   (setq company-idle-delay 0.01)
  489   (setq company-minimum-prefix-length 2)
  490 #+END_SRC
  491 
  492 **** Align Annotation
  493 Flush annotation on candidates to the right.
  494 #+BEGIN_SRC emacs-lisp
  495   (setq company-tooltip-align-annotations t)
  496 #+END_SRC
  497 
  498 *** Tooltip Documentation
  499 Install dependency =pos-tip=.
  500 #+BEGIN_SRC emacs-lisp
  501   (use-package pos-tip
  502     :ensure t)
  503   (require 'pos-tip)
  504 #+END_SRC
  505 
  506 Install =company-quickhelp= and set delay, FG/BG colors, max lines.
  507 #+BEGIN_SRC emacs-lisp
  508   (use-package company-quickhelp
  509     :ensure t
  510     :init
  511     (company-quickhelp-mode t)
  512     (setq company-quickhelp-delay 0.01)
  513     (setq company-quickhelp-color-background "#262626")
  514     (setq company-quickhelp-color-foreground "#ebdbb2")
  515     (setq company-quickhelp-max-lines 20)
  516     (setq company-quickhelp-use-propertized-text t))
  517 #+END_SRC
  518 
  519 *** Backend Configurations
  520 **** =company-auctex=
  521 Install =company-auctex= and add it to =company-backends=. This is for =acutex= macro completion.
  522 Adding backends is handled by =company-auctex-init=.
  523 #+BEGIN_SRC emacs-lisp
  524   (use-package company-auctex
  525     :ensure t
  526     :init
  527     (company-auctex-init))
  528 #+END_SRC
  529 
  530 ***** DISABLED Workaround To Enable Completion in Org Mode
  531 #+BEGIN_SRC emacs-lisp
  532     :config
  533     (defun company-auctex-prefix (regexp)
  534       "Returns the prefix for matching given REGEXP in org-mode and latex-mode."
  535       (and (or (derived-mode-p 'latex-mode) (derived-mode-p 'org-mode))
  536            (when (looking-back regexp)
  537              (match-string-no-properties 1)))))
  538 #+END_SRC
  539 
  540 **** DISABLED =company-math=
  541 Install =company-math= and add it to =company-backends=.
  542 ***** Unicode Symbols
  543 Enable unicode symbol backend globally.
  544 #+BEGIN_SRC emacs-lisp
  545   (use-package company-math
  546     :ensure t)
  547   ;;  :init (add-to-list 'company-backends
  548   ;;                     '(company-math-symbols-unicode)))
  549 #+END_SRC
  550 
  551 ***** Math Symbols
  552 Enable math symbol backend only in =TeX-mode= and =org-mode=.
  553 #+BEGIN_SRC emacs-lisp
  554   (defun user/company-math-init()
  555     (setq-local company-backends
  556                 (append '((company-math-symbols-latex
  557                            ;;company-math-symbols-unicode
  558                            company-auctex-macros
  559                            company-auctex-symbols
  560                            company-auctex-environments))
  561                         company-backends)))
  562 
  563   (add-hook 'TeX-mode-hook 'user/company-math-init)
  564   (add-hook 'org-mode-hook 'user/company-math-init)
  565 #+END_SRC
  566 **** =company-anaconda=
  567 Install =company-anaconda= and add it to =company-backends=.
  568 #+BEGIN_SRC emacs-lisp
  569   (use-package company-anaconda
  570     :ensure t
  571     :init (add-to-list 'company-backends
  572                        'company-anaconda))
  573 #+END_SRC
  574 
  575 **** =company-go=
  576 Auto complete for =go=. This relies on =gocode= to be installed using =go get=. Either install from [[https://github.com/mdempsky/gocode][github.com/mdempsky/gocode]] or [[https://github.com/stamblerre/gocode][github.com/stamblerre/gocode]] (supports go-modules).
  577 
  578 #+BEGIN_SRC emacs-lisp
  579   (use-package company-go
  580     :ensure t
  581     :init (add-to-list 'company-backends
  582                        'company-go))
  583 #+END_SRC
  584 
  585 **** =company-lsp=
  586 Company completion via =company-lsp=. =lsp-mode= will add the appropriate backend.
  587 #+BEGIN_SRC emacs-lisp
  588   (use-package company-lsp
  589     :ensure t)
  590 #+END_SRC
  591 
  592 **** =company-yasnippet=
  593 Add =company-yasnippet= backend for =yasnippet= key completion.
  594 #+BEGIN_SRC emacs-lisp
  595   (defun user/enable-yas-for-backend (backend)
  596     "Add yasnippet support for specified BACKEND."
  597     (if (and (listp backend) (member 'company-yasnippet backend))
  598         backend
  599       (append (if (consp backend) backend (list backend))
  600               '(:with company-yasnippet))))
  601 
  602   ;; Enable for all company backends. Add to hook to prevent missed backends.
  603   (add-hook 'yas-minor-mode-hook
  604             (lambda()
  605               (setq company-backends
  606                     (mapcar #'user/enable-yas-for-backend company-backends))))
  607 #+END_SRC
  608 
  609 *** =yasnippet= Conflict
  610 Pressing tab with company mode conflicts with =yasnippets=, this is the only fix
  611 that I found that makes everything work as expected. Make sure this is placed after backend settings.
  612 #+BEGIN_SRC emacs-lisp
  613   (defun user/check-expansion()
  614     (save-excursion
  615       (if (looking-at "\\_>") t
  616         (backward-char 1)
  617         (if (looking-at "\\.") t
  618           (backward-char 1)
  619           (if (looking-at "->") t nil)))))
  620 
  621   (defun user/do-yas-expand()
  622     (let ((yas-fallback-behavior 'return-nil))
  623       (yas-expand)))
  624 
  625   (defun user/tab-indent-or-complete()
  626     (interactive)
  627     (if (minibufferp)
  628         (minibuffer-complete)
  629       (if (or (not yas-minor-mode)
  630               (null (user/do-yas-expand)))
  631           (if (user/check-expansion)
  632               (company-complete-common)
  633             (indent-for-tab-command)))))
  634 
  635   (global-set-key (kbd "TAB") 'user/tab-indent-or-complete)
  636 #+END_SRC
  637 
  638 ** Flycheck
  639 Flycheck is a modern on-the-fly syntax checking extension for GNU
  640 Emacs, intended as replacement for the older Flymake extension which
  641 is part of GNU Emacs.
  642 
  643 *** Installation
  644 Install =flycheck=.
  645 #+BEGIN_SRC emacs-lisp
  646   (use-package flycheck
  647     :ensure t
  648     :init (global-flycheck-mode))
  649 #+END_SRC
  650 
  651 *** Set C++ Standard
  652 Use =c++17= as the C++ standard. =cppcheck= only support C++ 14 so far however.
  653 #+BEGIN_SRC emacs-lisp
  654   (add-hook 'c++-mode-hook
  655             (lambda () (progn
  656                          (setq flycheck-cppcheck-standards '("c++14"))
  657                          (setq flycheck-clang-language-standard "c++17")
  658                          (setq flycheck-gcc-language-standard "c++17"))))
  659 #+END_SRC
  660 
  661 *** Set Google C++ Syntax Checker
  662 **** Install =flycheck-google-cpplint=
  663 Add Google C++ Style checker for =flycheck= (Now deprecated, using local copy).
  664 On Arch Linux, if using AUR package =cpplint=, need to modify command
  665 in =flycheck-google-cpplint.el= to use =cpplint= instead of
  666 =cppling.py=.
  667 #+BEGIN_SRC emacs-lisp
  668   (use-package flycheck-google-cpplint
  669     :load-path "local/flycheck-google-cpplint/"
  670     :config
  671     (eval-after-load 'flycheck
  672       '(progn
  673          (require 'flycheck-google-cpplint)
  674          ;; Add Google C++ Style checker.
  675          ;; In default, syntax checked by Clang and Cppcheck.
  676          ;; Use Google Checker after errors are cleared
  677          (flycheck-add-next-checker 'c/c++-cppcheck
  678                                     '(error . c/c++-googlelint)))))
  679 #+END_SRC
  680 
  681 **** Set Checker Parameters
  682 Set various parameters for the checker.
  683 #+BEGIN_SRC emacs-lisp
  684   (custom-set-variables
  685    '(flycheck-googlelint-verbose "5")
  686    '(flycheck-googlelint-filter "-legal/copyright,-whitespace/braces")
  687    '(flycheck-googlelint-linelength "80"))
  688 #+END_SRC
  689 
  690 *** Set Clang Analyzer
  691 **** Install =flycheck-clang-analyzer=
  692 #+BEGIN_SRC emacs-lisp
  693   (use-package flycheck-clang-analyzer
  694     :ensure t
  695     :init
  696     (with-eval-after-load 'flycheck
  697       (require 'flycheck-clang-analyzer)
  698       (flycheck-clang-analyzer-setup)))
  699 #+END_SRC
  700 
  701 *** Proselint
  702 A linter for prose, checks grammar and style errors. Setting from [[https://unconj.ca/blog/linting-prose-in-emacs.html][here]].
  703 
  704 #+BEGIN_SRC emacs-lisp
  705   (flycheck-define-checker proselint
  706     "A linter for prose."
  707     :command ("proselint" source-inplace)
  708     :error-patterns
  709     ((warning line-start (file-name) ":" line ":" column ": "
  710               (id (one-or-more (not (any " "))))
  711               (message) line-end))
  712     :modes (text-mode markdown-mode gfm-mode org-mode))
  713 
  714   (add-to-list 'flycheck-checkers 'proselint)
  715 #+END_SRC
  716 
  717 ** Yasnippet
  718 YASnippet is a template system for Emacs. It allows you to type an
  719 abbreviation and automatically expand it into function templates.
  720 
  721 *** Installation
  722 Install =yasnippet=. Load =yasnippet= when =yas-minor-mode= is called
  723 and add the hook for =yas-minor-mode= for programming modes. Reload
  724 the snippets on start up.
  725 #+BEGIN_SRC emacs-lisp
  726   (require 'cl)
  727   (use-package yasnippet
  728     :ensure t
  729     :commands (yas-minor-mode)
  730     :init (yas-global-mode)
  731     :config (yas-reload-all))
  732 #+END_SRC
  733 
  734 *** Install =yasnippet-snippets=
  735 =yasnippet-snippets= is a collection of snippets for many langulages.
  736 #+BEGIN_SRC emacs-lisp
  737   (use-package yasnippet-snippets
  738     :ensure t)
  739 #+END_SRC
  740 
  741 * Mode Specific
  742 Settings specific to a mode or defines a new mode that often
  743 specializes Emacs for a certain programming language.
  744 
  745 ** Auctex
  746 =auctex= is an extensible package for writing and formatting TEX files
  747 in GNU Emacs.
  748 
  749 *** Installation
  750 Need to use =defer= as =auctex.el= does not actually provide =auctex= feature.
  751 #+BEGIN_SRC emacs-lisp
  752   (use-package auctex
  753     :defer t
  754     :ensure t)
  755 #+END_SRC
  756 
  757 *** Automatic Parsing
  758 Enable =auctex= to automatically parse buffer information.
  759 #+BEGIN_SRC emacs-lisp
  760   (setq TeX-parse-self t)
  761   (setq TeX-auto-save t)
  762   (setq TeX-save-query nil)
  763 #+END_SRC
  764 
  765 *** Master File Detection
  766 Let =auctex= figure out the master file for TeX document spread over many files.
  767 #+BEGIN_SRC emacs-lisp
  768   (setq-default TeX-master nil)
  769 #+END_SRC
  770 
  771 *** Spell Checking
  772 Spell checking with =flyspell=.
  773 #+BEGIN_SRC emacs-lisp
  774   (add-hook 'LaTeX-mode-hook 'flyspell-mode)
  775 #+END_SRC
  776 
  777 *** Enable =reftex=
  778 Turn on RefTeX Mode for all LaTeX files. This enables you to jump via table of contents.
  779 The key to invoke this is ~C-c =~.
  780 #+BEGIN_SRC emacs-lisp
  781   (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
  782 #+END_SRC
  783 
  784 *** Enable =LaTeX-math-mode=
  785 Enable LaTeX Math mode. This allows macro insertion following ~`~.
  786 Not exactly useful since we already have =company=.
  787 #+BEGIN_SRC emacs-lisp
  788   (add-hook 'LaTeX-mode-hook 'LaTeX-math-mode)
  789 #+END_SRC
  790 
  791 **** Auto-complete Sub/Superscripts
  792 Insert braces after ~_~ or ~^~.
  793 #+BEGIN_SRC emacs-lisp
  794   (setq TeX-electric-sub-and-superscript t)
  795 #+END_SRC
  796 
  797 ** C/C++-mode
  798 *** DISABLED Default Indention
  799 Set default indention level to 4 and style to "linux"(do not indent braces).
  800 #+BEGIN_SRC emacs-lisp
  801   (setq-default c-default-style "linux"
  802                 c-basic-offset 4)
  803 #+END_SRC
  804 
  805 *** Google Style
  806 Google's C/C++ style for c-mode.
  807 **** Installation
  808 #+BEGIN_SRC emacs-lisp
  809   (use-package google-c-style
  810     :ensure t
  811     :init
  812     (add-hook 'c-mode-common-hook 'google-set-c-style)
  813     (add-hook 'c-mode-common-hook 'google-make-newline-indent))
  814 #+END_SRC
  815 
  816 *** Treat =.h= as C++
  817 Identify =.h= files as C++ files instead of C. To enable =c++-mode=
  818 manually, type =M-x c\+\+-mode=.
  819 #+BEGIN_SRC emacs-lisp
  820   (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
  821 #+END_SRC
  822 
  823 *** Clang-format
  824 **** Installation
  825 Install and set hot keys for formatting.
  826 #+BEGIN_SRC emacs-lisp
  827   (use-package clang-format
  828     :ensure t
  829     :init
  830     (global-set-key (kbd "C-c i") 'clang-format-region)
  831     (global-set-key (kbd "C-c u") 'clang-format-buffer))
  832 #+END_SRC
  833 
  834 **** Set code style
  835 Use Google's C++ style.
  836 #+BEGIN_SRC emacs-lisp
  837   (custom-set-variables '(clang-format-style "file"))
  838 #+END_SRC
  839 
  840 *** Doxygen Highlighting
  841 Add highlighting for doxygen blocks.
  842 #+BEGIN_SRC emacs-lisp
  843   (use-package highlight-doxygen
  844     :ensure t
  845     :init
  846     (add-hook 'c-mode-common-hook 'highlight-doxygen-mode))
  847 #+END_SRC
  848 
  849 ** CMake-mode
  850 Syntax highlighting and indention for =CMakeLists.txt=.
  851 #+BEGIN_SRC emacs-lisp
  852   (use-package cmake-mode
  853     :ensure t)
  854 #+END_SRC
  855 
  856 *** Eldoc Support
  857 Eldoc for CMake.
  858 #+BEGIN_SRC emacs-lisp
  859   (use-package eldoc-cmake
  860     :ensure t
  861     :hook (cmake-mode . eldoc-cmake-enable))
  862 #+END_SRC
  863 
  864 *** Extended syntax highlighting
  865 Additional syntax highlighting for CMake. For some reason manual activation is still required.
  866 #+BEGIN_SRC emacs-lisp
  867   (use-package cmake-font-lock
  868     :ensure t
  869     :init (autoload 'cmake-font-lock-activate "cmake-font-lock" nil t)
  870     :hook (cmake-mode . cmake-font-lock-activate))
  871 #+END_SRC
  872 
  873 ** ESS
  874 Use ESS (Emacs Speaks Statistics) for R and Julia support.
  875 #+BEGIN_SRC emacs-lisp
  876   (use-package ess
  877     :ensure t
  878     :config
  879     ;; Add latex symbol completion in julia buffer mode as well.
  880     (add-hook 'ess-julia-mode-hook
  881           (lambda()
  882             (add-hook 'completion-at-point-functions
  883                       'ess-julia-latexsub-completion nil 'local)))
  884     (setq tab-always-indent 'complete))
  885 #+END_SRC
  886 
  887 *** Auto Format R Code
  888 Use the =styler= R package to format buffer or region. Modeled after =yapfify=.
  889 #+BEGIN_SRC emacs-lisp
  890   (defun user/r-format-call-bin (input-buffer output-buffer beginning end)
  891     "Format specified region in INPUT-BUFFER saving the output to OUTPUT-BUFFER.
  892 
  893   BEGINNING and END specify region to format."
  894     (with-current-buffer input-buffer
  895       (write-region beginning end "r-format-temp.R"))
  896     (call-process "R" nil nil nil "-e"
  897                   "library(styler);style_file(\"r-format-temp.R\")")
  898     (with-current-buffer output-buffer
  899       (insert-file-contents "r-format-temp.R" nil nil nil t))
  900     (with-current-buffer input-buffer
  901       (delete-region beginning end)
  902       (insert-buffer-substring output-buffer))
  903     (delete-file "r-format-temp.R"))
  904 
  905   (defun user/r-format-region (beginning end)
  906     "Try to r-format the current region.
  907 
  908   Output from R is stored in *r-format*."
  909     (interactive "r")
  910     (let* ((original-buffer (current-buffer))
  911            (original-point (point))  ; Because we are replacing text, save-excursion does not always work.
  912            (buffer-windows (get-buffer-window-list original-buffer nil t))
  913            (original-window-pos (mapcar 'window-start buffer-windows))
  914            (tmpbuf (generate-new-buffer "*r-format*"))
  915            (r-output (user/r-format-call-bin original-buffer tmpbuf beginning end)))
  916       (deactivate-mark)
  917       ;; Clean up tmpbuf
  918       (kill-buffer tmpbuf)
  919       ;; restore window to similar state
  920       (goto-char original-point)
  921       (mapcar* 'set-window-start buffer-windows original-window-pos)))
  922 
  923   (defun user/r-format-buffer ()
  924     "Format whole buffer."
  925     (interactive)
  926     (user/r-format-region (point-min) (point-max)))
  927 #+END_SRC
  928 
  929 Auto format bindings for =ess-r-mode=. Need a keybinding as auto formatting doesn't seem to work for org-mode =src= blocks.
  930 #+BEGIN_SRC emacs-lisp
  931   (defun user/r-format-before-save ()
  932     "Runs r-format on current buffer if in ess-r-mode."
  933     (interactive)
  934     (when (eq major-mode 'ess-r-mode) (user/r-format-buffer)))
  935 
  936   (add-hook 'ess-r-mode-hook
  937             (lambda () (local-set-key (kbd "C-c u") 'user/r-format-buffer)))
  938 
  939   (add-hook 'before-save-hook 'user/r-format-before-save)
  940 #+END_SRC
  941 
  942 ** DISABLED Lsp-mode
  943 Use Language Server Protocol (LSP) for code completion, jump to definition, etc. Check [[https://github.com/emacs-lsp/lsp-mode#supported-languages][list of language servers]] and install needed ones. Note that the Python language server also requires =autopepe8= and =pydocstyle=.
  944 
  945 *** Installation
  946 #+BEGIN_SRC emacs-lisp
  947   (use-package lsp-mode
  948     :ensure t
  949     :init
  950     (add-hook 'prog-mode-hook #'lsp)
  951     (setq lsp-prefer-flymake nil))
  952 #+END_SRC
  953 
  954 *** Flycheck Integration
  955 Flycheck integration via =lsp-ui=.
  956 #+BEGIN_SRC emacs-lisp
  957   (use-package lsp-ui
  958     :ensure t
  959     :init
  960     (add-hook 'lsp-mode-hook 'lsp-ui-mode)
  961     (setq lsp-ui-flycheck-enable t))
  962 #+END_SRC
  963 
  964 ** Go-mode
  965 Remember to set =$GOPATH= environment variable and add =$GOPATH/bin= to =$PATH=.
  966 
  967 *** Go-mode
  968 #+BEGIN_SRC emacs-lisp
  969   (use-package go-mode
  970     :ensure t
  971     :init
  972     (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  973     (add-hook 'before-save-hook 'gofmt-before-save))
  974 #+END_SRC
  975 
  976 *** go-guru
  977 Helpful code analysis tool, requires [[https://godoc.org/golang.org/x/tools/cmd/guru][golang.org/x/tools/cmd/guru]].
  978 
  979 #+BEGIN_SRC emacs-lisp
  980   (use-package go-guru
  981     :ensure t)
  982 #+END_SRC
  983 
  984 ** Julia-mode
  985 *** Julia-mode
  986 Official major mode for =julia=. This is required as a dependency for =ess-julia-mode=.
  987 #+BEGIN_SRC emacs-lisp
  988   (use-package julia-mode
  989     :ensure t)
  990 #+END_SRC
  991 
  992 *** Flycheck Support
  993 Flycheck support via =flycheck-julia=. This relies on [[https://github.com/tonyhffong/Lint.jl][Lint.jl]], which doesn't have a release yet for Julia 1.0. A work around is to give the repository URL to =Pkg= instead of the package name and fix 1.0 incompatibilities as they show up.
  994 #+BEGIN_SRC emacs-lisp
  995   (use-package flycheck-julia
  996     :ensure t
  997     :init
  998     (add-hook 'ess-julia-mode-hook #'flycheck-julia-setup))
  999 #+END_SRC
 1000 
 1001 *** Better REPL
 1002 This is a minor mode for interacting with a Julia REPL running inside Emacs.
 1003 #+BEGIN_SRC emacs-lisp
 1004   (use-package julia-repl
 1005     :ensure t
 1006     :init
 1007     (with-eval-after-load 'julia-mode
 1008       (add-hook 'flycheck-mode-hook #'flycheck-julia-setup)))
 1009 #+END_SRC
 1010 
 1011 ** Org-mode
 1012 =org-mode= specific settings.
 1013 
 1014 *** Allow Alphabetical Ordering
 1015 Allows the use of "a." or "b)" in ordered lists.
 1016 #+BEGIN_SRC emacs-lisp
 1017   (setq org-list-allow-alphabetical t)
 1018 #+END_SRC
 1019 
 1020 *** Global Keybindings
 1021 Set up keybindings for global access.
 1022 #+BEGIN_SRC emacs-lisp
 1023   (global-set-key "\C-cl" 'org-store-link)
 1024   (global-set-key "\C-ca" 'org-agenda)
 1025   (global-set-key "\C-cc" 'org-capture)
 1026   (global-set-key "\C-cb" 'org-switchb)
 1027 #+END_SRC
 1028 
 1029 *** Formatting
 1030 **** Emphasis Boundary Regex
 1031 Allow non-ASCII characters (CJK characters for instance) to be boundaries for
 1032 Org emphasis markers. This need to happen before =org-mode= is loaded.
 1033 #+BEGIN_SRC emacs-lisp
 1034   (use-package org
 1035     :init
 1036     (setq org-emphasis-regexp-components
 1037           (list (concat " \t('\"{"            "[:nonascii:]")  ;; prematch
 1038                 (concat "- \t.,:!?;'\")}\\["  "[:nonascii:]")  ;; postmatch
 1039                 " \t\r\n,\"'"                                  ;; border
 1040                 "."                                            ;; body-regexp
 1041                 1)))                                           ;; newline
 1042 #+END_SRC
 1043 
 1044 **** DISABLED Set Link Format
 1045 Do not collapse the links.
 1046 #+BEGIN_SRC emacs-lisp
 1047   (org-toggle-link-display)
 1048 #+END_SRC
 1049 
 1050 **** Subtree Indention
 1051 Do not change text indention when promoting/demoting subtrees.
 1052 #+BEGIN_SRC emacs-lisp
 1053   (setq org-adapt-indentation nil)
 1054 #+END_SRC
 1055 
 1056 **** Truncate Lines by Default
 1057 Automatically enable truncated lines when starting =org-mode=.
 1058 #+BEGIN_SRC emacs-lisp
 1059   (setq-default org-startup-truncated t)
 1060 #+END_SRC
 1061 
 1062 **** DISABLED Turn Off =auto-fill=
 1063 Disable =auto-fill-mode= when in =org-mode=.
 1064 #+BEGIN_SRC emacs-lisp
 1065   (add-hook 'org-mode-hook 'turn-off-auto-fill)
 1066 #+END_SRC
 1067 
 1068 **** Display Inline Images
 1069 Display inline images for =org-babel= execution results.
 1070 #+BEGIN_SRC emacs-lisp
 1071 (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
 1072 (add-hook 'org-mode-hook 'org-display-inline-images)
 1073 #+END_SRC
 1074 
 1075 **** Protect Folded Regions
 1076 Don't allow editing of folded regions
 1077 #+BEGIN_SRC emacs-lisp
 1078   (setq org-catch-invisible-edits 'error)
 1079 #+END_SRC
 1080 
 1081 **** DISABLED Enforce TODO Dependencies
 1082 Parent tasks should not be marked DONE until all subtasks are marked as DONE.
 1083 #+BEGIN_SRC emacs-lisp
 1084   (setq org-enforce-todo-dependencies t)
 1085 #+END_SRC
 1086 
 1087 **** Highlight LaTeX Related Syntax
 1088 Non-nil means highlight LaTeX related syntax in the buffer. When non nil, the value should be a list containing any of the following symbols:
 1089 - `latex' Highlight LaTeX snippets and environments.
 1090 - `script' Highlight subscript and superscript.
 1091 - `entities' Highlight entities.
 1092 
 1093 #+BEGIN_SRC emacs-lisp
 1094   (eval-after-load 'org
 1095     '(setf org-highlight-latex-and-related '(latex)))
 1096 #+END_SRC
 1097 
 1098 **** Default Image Size
 1099 In LaTeX export, the default image size is =width=.9\linewidth=, which is way too large. Setting this to empty allows images to retain it's original size.
 1100 #+BEGIN_SRC emacs-lisp
 1101   (setq org-latex-image-default-width ".6\\linewidth")
 1102 #+END_SRC
 1103 
 1104 *** Enable spell checking
 1105 Spell checking with =flyspell-mode=. Would need to install dictionary lib like =aspell= in base system.
 1106 #+BEGIN_SRC emacs-lisp
 1107   (add-hook 'org-mode-hook 'flyspell-mode)
 1108 #+END_SRC
 1109 
 1110 *** Enable Code Evaluation
 1111 Enable evaluation of various languages in org-mode.
 1112 #+BEGIN_SRC emacs-lisp
 1113   (defvar user/org-babel-enabled-languages
 1114     '(emacs-lisp
 1115       python
 1116       R
 1117       org)
 1118     "Extra languages user can execute in org-babel code blocks.")
 1119 
 1120   (org-babel-do-load-languages
 1121    'org-babel-load-languages
 1122    (mapcar
 1123     (lambda (arg) (cons arg t))
 1124     user/org-babel-enabled-languages))
 1125 #+END_SRC
 1126 
 1127 There is no need to confirm execution for these languages.
 1128 #+BEGIN_SRC emacs-lisp
 1129   (defvar user/org-babel-no-confirm-languages
 1130     '(emacs-lisp
 1131       python
 1132       R
 1133       latex-macros
 1134       org)
 1135     "Languages that do not user confirmation to execute")
 1136 
 1137   (setq org-confirm-babel-evaluate
 1138         (lambda (lang body)
 1139           (not (member lang
 1140                        (mapcar (lambda (arg) (symbol-name arg))
 1141                                user/org-babel-no-confirm-languages)))))
 1142 #+END_SRC
 1143 
 1144 *** Exporter Backends
 1145 **** HTML
 1146 Do not export validation link.
 1147 #+BEGIN_SRC emacs-lisp
 1148   (setq org-html-validation-link nil)
 1149 #+END_SRC
 1150 
 1151 **** Markdown (Blackfriday)
 1152 An Org exporter backend that exports Org to Hugo-compatible Markdown
 1153 (Blackfriday) and generates the front-matter (in TOML or YAML format).
 1154 
 1155 ***** Installation
 1156 Enable =ox-hugo= as an option for exporting.
 1157 #+BEGIN_SRC emacs-lisp
 1158   (use-package ox-hugo
 1159     :ensure t
 1160     :init (with-eval-after-load 'ox (require 'ox-hugo)))
 1161 #+END_SRC
 1162 
 1163 ***** Export Key Bindings
 1164 Wrap key bindings in =<kbd>=.
 1165 #+BEGIN_SRC emacs-lisp
 1166   (setq org-hugo-use-code-for-kbd t)
 1167 #+END_SRC
 1168 
 1169 **** Pandoc
 1170 This is another exporter for org-mode that translates Org-mode file to various
 1171 other formats via Pandoc.
 1172 
 1173 ***** Installation
 1174 #+BEGIN_SRC emacs-lisp
 1175   (use-package ox-pandoc
 1176     :ensure t)
 1177 #+END_SRC
 1178 
 1179 **** Jupyter Notebook
 1180 Export backend for =.ipynb=. Package is not in MELPA yet, so using local copy. Repository is located [[https://github.com/jkitchin/ox-ipynb][here]].
 1181 
 1182 #+BEGIN_SRC emacs-lisp
 1183   (use-package ox-ipynb
 1184     :load-path "local/ox-ipynb/")
 1185 #+END_SRC
 1186 
 1187 Quick and easy hack to get python source blocks to work.
 1188 #+BEGIN_SRC emacs-lisp
 1189   (setq ox-ipynb-kernelspecs
 1190         '((ipython . (kernelspec . ((display_name . "Python 3")
 1191                                     (language . "python")
 1192                                     (name . "python3"))))
 1193           (python . (kernelspec . ((display_name . "Python 3")
 1194                                    (language . "python")
 1195                                    (name . "python3"))))
 1196           (R . (kernelspec . ((display_name . "R")
 1197                               (language . "R")
 1198                               (name . "ir"))))
 1199           (julia . (kernelspec . ((display_name . "Julia 0.6.0")
 1200                                   (language . "julia")
 1201                                   (name . "julia-0.6"))))))
 1202 
 1203   (setq ox-ipynb-language-infos
 1204         '((ipython . (language_info . ((codemirror_mode . ((name . ipython)
 1205                                                            (version . 3)))
 1206                                        (file_extension . ".py")
 1207                                        (mimetype . "text/x-python")
 1208                                        (name . "python")
 1209                                        (nbconvert_exporter . "python")
 1210                                        (pygments_lexer . "ipython3")
 1211                                        (version . "3.5.2"))))
 1212           (python . (language_info . ((codemirror_mode . ((name . ipython)
 1213                                                           (version . 3)))
 1214                                       (file_extension . ".py")
 1215                                       (mimetype . "text/x-python")
 1216                                       (name . "python")
 1217                                       (nbconvert_exporter . "python")
 1218                                       (pygments_lexer . "ipython3")
 1219                                       (version . "3.5.2"))))
 1220           (R . (language_info . ((codemirror_mode . "r")
 1221                                  (file_extension . ".r")
 1222                                  (mimetype . "text/x-r-source")
 1223                                  (name . "R")
 1224                                  (pygments_lexer . "r")
 1225                                  (version . "3.3.2"))))
 1226           (julia . (language_info . ((codemirror_mode . "julia")
 1227                                      (file_extension . ".jl")
 1228                                      (mimetype . "text/x-julia")
 1229                                      (name . "julia")
 1230                                      (pygments_lexer . "julia")
 1231                                      (version . "0.6.0"))))))
 1232 #+END_SRC
 1233 
 1234 **** LaTeX
 1235 ***** LaTeX Macros
 1236 Support LaTeX macros in both LaTeX and HTML/MathJax export. We do this by adding
 1237 a dummy language to Babel. Idea comes form [[https://www.reddit.com/r/orgmode/comments/7u2n0h/tip_for_defining_latex_macros_for_use_in_both/][here]].
 1238 #+BEGIN_SRC emacs-lisp
 1239   (add-to-list 'org-src-lang-modes '("latex-macros" . latex))
 1240 
 1241   (defvar org-babel-default-header-args:latex-macros
 1242     '((:results . "raw")
 1243       (:exports . "results")))
 1244 
 1245   (defun user/prefix-all-lines (pre body)
 1246     (with-temp-buffer
 1247       (insert body)
 1248       (string-insert-rectangle (point-min) (point-max) pre)
 1249       (buffer-string)))
 1250 
 1251   (defun org-babel-execute:latex-macros (body _params)
 1252     (concat
 1253      (user/prefix-all-lines "#+LATEX_HEADER: " body)
 1254      "\n#+HTML_HEAD_EXTRA: <div style=\"display: none\"> \\(\n"
 1255      (user/prefix-all-lines "#+HTML_HEAD_EXTRA: " body)
 1256      "\n#+HTML_HEAD_EXTRA: \\)</div>\n"))
 1257 #+END_SRC
 1258 
 1259 ***** LaTeX Preview Scaling
 1260 Default size is a bit small. Also note that the =fullpage= package can cause preview images to become really tall. Use =dvisvgm= backend for clearer image.
 1261 
 1262 #+BEGIN_SRC emacs-lisp
 1263   (plist-put org-format-latex-options :scale 1.75)
 1264   (setq org-latex-create-formula-image-program 'dvisvgm)
 1265 #+END_SRC
 1266 
 1267 ***** Code Listing
 1268 Use =minted= for code listings. Relies on =pygments= for syntax highlighting.
 1269 #+BEGIN_SRC emacs-lisp
 1270   (setq org-latex-listings 'minted)
 1271   (setq org-latex-minted-options
 1272         '(("frame" "single")
 1273           ("fontsize" "\\scriptsize")))
 1274   (add-to-list 'org-latex-packages-alist '("" "minted" nil))
 1275 #+END_SRC
 1276 
 1277 ***** SVG Support
 1278 Use =svg= for supporting SVGs. Requires =inkscape= to be installed.
 1279 #+BEGIN_SRC emacs-lisp
 1280   (add-to-list 'org-latex-packages-alist '("" "svg" nil))
 1281 #+END_SRC
 1282 
 1283 ***** Shell Escape
 1284 This is required for =minted= and =svg= to work.
 1285 #+begin_src emacs-lisp
 1286   (setq org-latex-pdf-process
 1287         '("%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
 1288           "%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
 1289           "%latex -shell-escape -interaction nonstopmode -output-directory %o %f"))
 1290 #+end_src
 1291 
 1292 ** Python-mode
 1293 Enhancements to =python-mode=.
 1294 
 1295 *** Anaconda Mode
 1296 Code navigation, documentation lookup and completion for Python.
 1297 #+BEGIN_SRC emacs-lisp
 1298   (use-package anaconda-mode
 1299     :ensure t
 1300     :init
 1301     (add-hook 'python-mode-hook 'anaconda-mode)
 1302     (add-hook 'python-mode-hook 'anaconda-eldoc-mode))
 1303 #+END_SRC
 1304 
 1305 *** Auto Format
 1306 **** black
 1307 Use =black= to auto format python buffers on save.
 1308 #+BEGIN_SRC emacs-lisp
 1309   (use-package blacken
 1310     :ensure t
 1311     :init
 1312     (add-hook 'python-mode-hook 'blacken-mode))
 1313 #+END_SRC
 1314 
 1315 **** isort
 1316 Use =isort= to sort imports.
 1317 #+BEGIN_SRC emacs-lisp
 1318   (use-package isortify
 1319     :ensure t
 1320     :init
 1321     (add-hook 'python-mode-hook 'isortify-mode)
 1322     (setq isortify-multi-line-output 3)
 1323     (setq isortify-trailing-comma t)
 1324     (setq isortify-line-width 88))
 1325 #+END_SRC
 1326 
 1327 Use =black=-compatible settings as recommended [[https://github.com/python/black#how-black-wraps-lines][here]]. Add missing variables to conform with =black=.
 1328 #+BEGIN_SRC emacs-lisp
 1329   (defcustom isortify-force-grid-wrap nil
 1330     "Force from imports to be grid wrapped regardless of line length, where the value given is the number of imports allowed before wrapping occurs.")
 1331 
 1332   (defcustom isortify-use-parentheses nil
 1333     "Tells isort to use parenthesis for line continuation instead of \ for lines over the allotted line length limit.")
 1334 
 1335   (setq isortify-force-grid-wrap 0)
 1336   (setq isortify-use-parentheses t)
 1337 
 1338   (defun isortify-call-args ()
 1339     "Collect CLI arguments for isort process."
 1340     (let (args)
 1341       (when (string= "ipython" python-shell-interpreter)
 1342         (push "--" args))
 1343       (when isortify-multi-line-output
 1344         (push "--multi-line" args)
 1345         (push (number-to-string isortify-multi-line-output) args))
 1346       (when isortify-trailing-comma
 1347         (push "--trailing-comma" args))
 1348       (when isortify-known-first-party
 1349         (dolist (project isortify-known-first-party)
 1350           (push "--project" args)
 1351           (push project args)))
 1352       (when isortify-known-third-party
 1353         (dolist (thirdparty isortify-known-third-party)
 1354           (push "--thirdparty" args)
 1355           (push thirdparty args)))
 1356       (when isortify-lines-after-imports
 1357         (push "--lines-after-imports" args)
 1358         (push (number-to-string isortify-lines-after-imports) args))
 1359       (when isortify-line-width
 1360         (push "--line-width" args)
 1361         (push (number-to-string isortify-line-width) args))
 1362       (when isortify-force-grid-wrap
 1363         (push "--force-grid-wrap" args)
 1364         (push (number-to-string isortify-force-grid-wrap) args))
 1365       (when isortify-use-parentheses
 1366         (push "--use-parentheses" args))
 1367       (push "-" args)
 1368       (reverse args)))
 1369 #+END_SRC
 1370 
 1371 
 1372 **** DISABLED yapf
 1373 Use =yapf= to auto format python buffers on save.
 1374 #+BEGIN_SRC emacs-lisp
 1375   (use-package yapfify
 1376     :ensure t
 1377     :init
 1378     (add-hook 'python-mode-hook 'yapf-mode))
 1379 #+END_SRC
 1380 
 1381 **** DISABLED pep8
 1382 Use =py-autopep8= to auto format python buffers on save.
 1383 #+BEGIN_SRC emacs-lisp
 1384   (use-package py-autopep8
 1385     :ensure t
 1386     :init
 1387     (add-hook 'python-mode-hook 'py-autopep8-enable-on-save))
 1388 #+END_SRC
 1389 
 1390 *** Syntax Checking
 1391 **** Flycheck
 1392 By default =flycheck= only runs one available python checker.
 1393 #+BEGIN_SRC emacs-lisp
 1394   (flycheck-add-next-checker 'python-flake8 'python-pylint)
 1395 #+END_SRC
 1396 
 1397 **** DISABLED pycheckers
 1398 By default =flycheck= only runs one available python checker. Use
 1399 =flycheck-pycheckers=.
 1400 #+BEGIN_SRC emacs-lisp
 1401   (use-package flycheck-pycheckers
 1402     :ensure t
 1403     :init
 1404     (setq flycheck-pycheckers-checkers '(pylint flake8))
 1405     (add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup))
 1406 #+END_SRC
 1407 
 1408 *** Python Interpretor
 1409 Use =ipython= as default interpreter and disable feature warning.
 1410 
 1411 #+BEGIN_SRC emacs-lisp
 1412   (setq python-shell-interpreter "ipython"
 1413         python-shell-interpreter-args "-i --simple-prompt"
 1414         python-shell-prompt-detect-failure-warning nil)
 1415   (add-to-list 'python-shell-completion-native-disabled-interpreters
 1416                "ipython")
 1417 #+END_SRC
 1418 
 1419 ** Rust-mode
 1420 A compilation of settings for programming in rust. The recommended way to
 1421 install rust is via =rustup=. Remember to use =rustup add component= to install
 1422 =rust-fmt=, =rust-src=, and =rls=.
 1423 
 1424 *** Rust-mode
 1425 Install =rust-mode=, use =rust-fmt= to format the code upon saving,
 1426 and automatically enable =rust-mode= for =*.rs= files.
 1427 #+BEGIN_SRC emacs-lisp
 1428   (use-package rust-mode
 1429     :ensure t
 1430     :init
 1431     (setq rust-format-on-save t)
 1432     (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)))
 1433 #+END_SRC
 1434 
 1435 *** Cargo Integration
 1436 A minor mode for =cargo=, the package manager for rust.
 1437 #+BEGIN_SRC emacs-lisp
 1438   (use-package cargo
 1439     :ensure t
 1440     :init
 1441     (add-hook 'rust-mode-hook 'cargo-minor-mode))
 1442 #+END_SRC
 1443 
 1444 *** Flycheck Support
 1445 Better flycheck support via =flycheck-rust=.
 1446 #+BEGIN_SRC emacs-lisp
 1447   (use-package flycheck-rust
 1448     :ensure t
 1449     :init
 1450     (with-eval-after-load 'rust-mode
 1451       (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)))
 1452 #+END_SRC
 1453 
 1454 *** Racer
 1455 Code completion utility for rust. Provides =company= integration.
 1456 #+BEGIN_SRC emacs-lisp
 1457   (use-package racer
 1458     :ensure t
 1459     :init
 1460     (add-hook 'rust-mode-hook #'racer-mode)
 1461     (add-hook 'rust-mode-hook #'eldoc-mode))
 1462 #+END_SRC
 1463 
 1464 ** Zig-mode
 1465 #+BEGIN_SRC emacs-lisp
 1466   (use-package zig-mode
 1467     :ensure t)
 1468 #+END_SRC
 1469 
 1470 * Enhancements
 1471 Packages providing enhancements to Emacs interface. Mostly simple plug-and-play
 1472 packages. Load enhancements in the end to prevent their dependencies getting
 1473 loaded prior to their own customization.
 1474 
 1475 ** Avy
 1476 Jump to visible text using a char-based decision tree, similar to =ace-jump=.
 1477 #+BEGIN_SRC emacs-lisp
 1478   (use-package avy
 1479     :ensure t
 1480     :init
 1481     (define-prefix-command 'user/avy-prefix)
 1482     (global-set-key (kbd "C-:") 'user/avy-prefix)
 1483     (define-key 'user/avy-prefix (kbd "c") 'avy-goto-char)
 1484     (define-key 'user/avy-prefix (kbd "C") 'avy-goto-char-2)
 1485     (define-key 'user/avy-prefix (kbd "t") 'avy-goto-char-timer)
 1486     (define-key 'user/avy-prefix (kbd "s") 'avy-goto-char-in-line)
 1487     (define-key 'user/avy-prefix (kbd "l") 'avy-goto-line)
 1488     (define-key 'user/avy-prefix (kbd "w") 'avy-goto-word-0)
 1489     (define-key 'user/avy-prefix (kbd "W") 'avy-goto-word-1)
 1490     (define-key 'user/avy-prefix (kbd "o") 'avy-org-goto-heading-timer)
 1491     (define-key 'user/avy-prefix (kbd "O") 'avy-org-refile-as-child))
 1492 #+END_SRC
 1493 
 1494 ** Dashboard
 1495 An extensible Emacs startup screen showing you what's most important.
 1496 
 1497 *** Installation
 1498 Change default startup screen with =dashboard=.
 1499 Customize =initial-buffer-choice= to affect new frames created by =emacsclient=.
 1500 Also refresh dashboard to ensure customizations take effect.
 1501 #+BEGIN_SRC emacs-lisp
 1502   (use-package dashboard
 1503     :ensure t
 1504     :config
 1505     (dashboard-setup-startup-hook)
 1506     (setq initial-buffer-choice (lambda()
 1507                                   (dashboard-refresh-buffer)
 1508                                   (get-buffer "*dashboard*"))))
 1509 #+END_SRC
 1510 
 1511 *** Customize Banner and Logo
 1512 Customize banner and logo.
 1513 #+BEGIN_SRC emacs-lisp
 1514   (defvar user/dashboard-banner-logo-titles
 1515     '("42"
 1516       "9 MORE SEASONS UNTIL I GET THAT DIPPING SZECHUAN SAUCE!"
 1517       "Avocado + Maple Syrup = Dragon Fruit"
 1518       "Eight-Megabytes-And-Constantly-Swapping"
 1519       "Enter-Meta-Alt-Control-Shift"
 1520       "Execute order 66."
 1521       "Greetings from Emacs!"
 1522       "POLYBIUS"
 1523       "Project-iM@CS"
 1524       "Supervillain Repair & Restoration"
 1525       "This is fine."
 1526       "Weak emperors mean strong viceroys."
 1527       "Wissen ist Nacht!"
 1528       "Wubba Lubba Dub-Dub!"))
 1529   (setq dashboard-banner-logo-title
 1530         (elt user/dashboard-banner-logo-titles
 1531              (random (length user/dashboard-banner-logo-titles))))
 1532   (setq dashboard-startup-banner
 1533         (expand-file-name "static/sxs.png" user-emacs-directory))
 1534 #+END_SRC
 1535 
 1536 *** Customize Widgets
 1537 **** =dashboard-insert-configs=
 1538 Create widget to display important config files. Use ~c~ to jump to this section.
 1539 #+BEGIN_SRC emacs-lisp
 1540   (defvar user/config-file-list
 1541     (mapcar (lambda (arg) (expand-file-name arg user-emacs-directory))
 1542             '("README.org"
 1543               "init.el"
 1544               "static/math_macros.sty")))
 1545 
 1546   (defun user/dashboard-insert-configs (list-size)
 1547     "Add a list of config files."
 1548     (dashboard-insert-section
 1549      "Config Files:"
 1550      user/config-file-list
 1551      list-size
 1552      "c"
 1553      `(lambda (&rest ignore) (find-file-existing ,el))
 1554      (abbreviate-file-name el)))
 1555 
 1556   (add-to-list 'dashboard-item-generators '(configs . user/dashboard-insert-configs))
 1557 #+END_SRC
 1558 
 1559 **** =dashboard-insert-init-time=
 1560 Display initialization time.
 1561 #+BEGIN_SRC emacs-lisp
 1562   (defun user/dashboard-insert-init-time (list-size)
 1563      "Displays Emacs init time."
 1564      (insert (format "[Started Emacs in %s.]" (emacs-init-time))))
 1565 
 1566   (add-to-list 'dashboard-item-generators '(init-time . user/dashboard-insert-init-time))
 1567 #+END_SRC
 1568 
 1569 **** Apply All Widgets
 1570 Set items to display:
 1571 #+BEGIN_SRC emacs-lisp
 1572   (setq dashboard-items '((recents  . 10)
 1573                           (bookmarks . 5)
 1574                           (projects . 8)
 1575                           (agenda . 5)
 1576   ;                        (registers . 5)
 1577                           (configs)
 1578                           (init-time)))
 1579 #+END_SRC
 1580 
 1581 ** HTML Export
 1582 Convert buffer text and decorations to HTML by =htmlize-buffer= so
 1583 that people can see what I see.
 1584 #+BEGIN_SRC emacs-lisp
 1585   (use-package htmlize
 1586     :ensure t)
 1587 #+END_SRC
 1588 
 1589 ** Keybindings
 1590 *** IBuffer
 1591 Use =ibuffer= instead of =list-buffer=.
 1592 #+BEGIN_SRC emacs-lisp
 1593   (global-set-key (kbd "C-x C-b") 'ibuffer)
 1594   (autoload 'ibuffer "ibuffer" "List buffers." t)
 1595 #+END_SRC
 1596 
 1597 ** Keyfreq
 1598 Records command frequency. I am planning on adjusting my keyboard
 1599 layout with this information.
 1600 #+BEGIN_SRC emacs-lisp
 1601     (use-package keyfreq
 1602       :ensure t
 1603       :init
 1604       (keyfreq-mode 1)
 1605       (keyfreq-autosave-mode 1))
 1606 #+END_SRC
 1607 
 1608 ** Magit
 1609 Install =magit= and bind =magit-status= to ~C-c g~.
 1610 #+BEGIN_SRC emacs-lisp
 1611   (use-package magit
 1612     :ensure t
 1613     :init
 1614     (global-set-key (kbd "C-c g") 'magit-status))
 1615 #+END_SRC
 1616 
 1617 *** Magit annex
 1618 Magit support for =git-annex=.
 1619 #+BEGIN_SRC emacs-lisp
 1620   (use-package magit-annex
 1621     :ensure t)
 1622 #+END_SRC
 1623 
 1624 ** Projectile
 1625 Projectile is a project interaction library for Emacs. Its goal is to
 1626 provide a nice set of features operating on a project level without
 1627 introducing external dependencies(when feasible).
 1628 
 1629 *** Installation
 1630 Install =projectile=.
 1631 #+BEGIN_SRC emacs-lisp
 1632   (use-package projectile
 1633     :ensure t
 1634     :init
 1635     (projectile-mode +1))
 1636 #+END_SRC
 1637 
 1638 *** DISABLED Enable =helm= support
 1639 Since I use =helm=, I need to install additional support.
 1640 #+BEGIN_SRC emacs-lisp
 1641   (use-package helm-projectile
 1642     :ensure t
 1643     :init
 1644     (setq projectile-completion-system 'helm)
 1645     (helm-projectile-on))
 1646 #+END_SRC