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 (52613B)

    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     (add-hook 'ess-mode-hook
  885               (lambda () (ess-set-style 'RStudio)))
  886     (setq tab-always-indent 'complete))
  887 #+END_SRC
  888 
  889 *** DISABLED Auto Format R Code
  890 Use the =styler= R package to format buffer or region. Modeled after =yapfify=.
  891 #+BEGIN_SRC emacs-lisp
  892   (defun user/r-format-call-bin (input-buffer output-buffer beginning end)
  893     "Format specified region in INPUT-BUFFER saving the output to OUTPUT-BUFFER.
  894 
  895   BEGINNING and END specify region to format."
  896     (with-current-buffer input-buffer
  897       (write-region beginning end "r-format-temp.R"))
  898     (call-process "R" nil nil nil "-e"
  899                   "library(styler);style_file(\"r-format-temp.R\")")
  900     (with-current-buffer output-buffer
  901       (insert-file-contents "r-format-temp.R" nil nil nil t))
  902     (with-current-buffer input-buffer
  903       (delete-region beginning end)
  904       (insert-buffer-substring output-buffer))
  905     (delete-file "r-format-temp.R"))
  906 
  907   (defun user/r-format-region (beginning end)
  908     "Try to r-format the current region.
  909 
  910   Output from R is stored in *r-format*."
  911     (interactive "r")
  912     (let* ((original-buffer (current-buffer))
  913            (original-point (point))  ; Because we are replacing text, save-excursion does not always work.
  914            (buffer-windows (get-buffer-window-list original-buffer nil t))
  915            (original-window-pos (mapcar 'window-start buffer-windows))
  916            (tmpbuf (generate-new-buffer "*r-format*"))
  917            (r-output (user/r-format-call-bin original-buffer tmpbuf beginning end)))
  918       (deactivate-mark)
  919       ;; Clean up tmpbuf
  920       (kill-buffer tmpbuf)
  921       ;; restore window to similar state
  922       (goto-char original-point)
  923       (mapcar* 'set-window-start buffer-windows original-window-pos)))
  924 
  925   (defun user/r-format-buffer ()
  926     "Format whole buffer."
  927     (interactive)
  928     (user/r-format-region (point-min) (point-max)))
  929 #+END_SRC
  930 
  931 Auto format bindings for =ess-r-mode=. Need a keybinding as auto formatting doesn't seem to work for org-mode =src= blocks.
  932 #+BEGIN_SRC emacs-lisp
  933   (defun user/r-format-before-save ()
  934     "Runs r-format on current buffer if in ess-r-mode."
  935     (interactive)
  936     (when (eq major-mode 'ess-r-mode) (user/r-format-buffer)))
  937 
  938   (add-hook 'ess-r-mode-hook
  939             (lambda () (local-set-key (kbd "C-c u") 'user/r-format-buffer)))
  940 
  941   (add-hook 'before-save-hook 'user/r-format-before-save)
  942 #+END_SRC
  943 
  944 ** Lsp-mode
  945 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=.
  946 
  947 *** Installation
  948 #+BEGIN_SRC emacs-lisp
  949   (use-package lsp-mode
  950     :ensure t
  951     :init
  952     ;; (add-hook 'prog-mode-hook #'lsp)
  953     (setq lsp-prefer-flymake nil)
  954     :config
  955     (setq lsp-keymap-prefix "C-c p")
  956     (add-to-list 'lsp--formatting-indent-alist
  957                  '(ess-r-mode . ess-indent-offset))
  958     :bind-keymap
  959     ("C-c p" . lsp-command-map))
  960 #+END_SRC
  961 
  962 *** Flycheck Integration
  963 Flycheck integration via =lsp-ui=.
  964 #+BEGIN_SRC emacs-lisp
  965   (use-package lsp-ui
  966     :ensure t
  967     :init
  968     (add-hook 'lsp-mode-hook 'lsp-ui-mode)
  969     (setq lsp-ui-flycheck-enable t))
  970 #+END_SRC
  971 
  972 ** Go-mode
  973 Remember to set =$GOPATH= environment variable and add =$GOPATH/bin= to =$PATH=.
  974 
  975 *** Go-mode
  976 #+BEGIN_SRC emacs-lisp
  977   (use-package go-mode
  978     :ensure t
  979     :init
  980     (add-to-list 'auto-mode-alist '("\\.go\\'" . go-mode))
  981     (add-hook 'before-save-hook 'gofmt-before-save))
  982 #+END_SRC
  983 
  984 *** go-guru
  985 Helpful code analysis tool, requires [[https://godoc.org/golang.org/x/tools/cmd/guru][golang.org/x/tools/cmd/guru]].
  986 
  987 #+BEGIN_SRC emacs-lisp
  988   (use-package go-guru
  989     :ensure t)
  990 #+END_SRC
  991 
  992 ** Julia-mode
  993 *** Julia-mode
  994 Official major mode for =julia=. This is required as a dependency for =ess-julia-mode=.
  995 #+BEGIN_SRC emacs-lisp
  996   (use-package julia-mode
  997     :ensure t)
  998 #+END_SRC
  999 
 1000 *** Flycheck Support
 1001 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.
 1002 #+BEGIN_SRC emacs-lisp
 1003   (use-package flycheck-julia
 1004     :ensure t
 1005     :init
 1006     (add-hook 'ess-julia-mode-hook #'flycheck-julia-setup))
 1007 #+END_SRC
 1008 
 1009 *** Better REPL
 1010 This is a minor mode for interacting with a Julia REPL running inside Emacs.
 1011 #+BEGIN_SRC emacs-lisp
 1012   (use-package julia-repl
 1013     :ensure t
 1014     :init
 1015     (with-eval-after-load 'julia-mode
 1016       (add-hook 'flycheck-mode-hook #'flycheck-julia-setup)))
 1017 #+END_SRC
 1018 
 1019 ** Org-mode
 1020 =org-mode= specific settings.
 1021 
 1022 *** Allow Alphabetical Ordering
 1023 Allows the use of "a." or "b)" in ordered lists.
 1024 #+BEGIN_SRC emacs-lisp
 1025   (setq org-list-allow-alphabetical t)
 1026 #+END_SRC
 1027 
 1028 *** Global Keybindings
 1029 Set up keybindings for global access.
 1030 #+BEGIN_SRC emacs-lisp
 1031   (global-set-key "\C-cl" 'org-store-link)
 1032   (global-set-key "\C-ca" 'org-agenda)
 1033   (global-set-key "\C-cc" 'org-capture)
 1034   (global-set-key "\C-cb" 'org-switchb)
 1035 #+END_SRC
 1036 
 1037 *** Formatting
 1038 **** Emphasis Boundary Regex
 1039 Allow non-ASCII characters (CJK characters for instance) to be boundaries for
 1040 Org emphasis markers. This need to happen before =org-mode= is loaded.
 1041 #+BEGIN_SRC emacs-lisp
 1042   (use-package org
 1043     :init
 1044     (setq org-emphasis-regexp-components
 1045           (list (concat " \t('\"{"            "[:nonascii:]")  ;; prematch
 1046                 (concat "- \t.,:!?;'\")}\\["  "[:nonascii:]")  ;; postmatch
 1047                 " \t\r\n,\"'"                                  ;; border
 1048                 "."                                            ;; body-regexp
 1049                 1)))                                           ;; newline
 1050 #+END_SRC
 1051 
 1052 **** DISABLED Set Link Format
 1053 Do not collapse the links.
 1054 #+BEGIN_SRC emacs-lisp
 1055   (org-toggle-link-display)
 1056 #+END_SRC
 1057 
 1058 **** Subtree Indention
 1059 Do not change text indention when promoting/demoting subtrees.
 1060 #+BEGIN_SRC emacs-lisp
 1061   (setq org-adapt-indentation nil)
 1062 #+END_SRC
 1063 
 1064 **** Truncate Lines by Default
 1065 Automatically enable truncated lines when starting =org-mode=.
 1066 #+BEGIN_SRC emacs-lisp
 1067   (setq-default org-startup-truncated t)
 1068 #+END_SRC
 1069 
 1070 **** DISABLED Turn Off =auto-fill=
 1071 Disable =auto-fill-mode= when in =org-mode=.
 1072 #+BEGIN_SRC emacs-lisp
 1073   (add-hook 'org-mode-hook 'turn-off-auto-fill)
 1074 #+END_SRC
 1075 
 1076 **** Display Inline Images
 1077 Display inline images for =org-babel= execution results.
 1078 #+BEGIN_SRC emacs-lisp
 1079 (add-hook 'org-babel-after-execute-hook 'org-display-inline-images)
 1080 (add-hook 'org-mode-hook 'org-display-inline-images)
 1081 #+END_SRC
 1082 
 1083 **** Protect Folded Regions
 1084 Don't allow editing of folded regions
 1085 #+BEGIN_SRC emacs-lisp
 1086   (setq org-catch-invisible-edits 'error)
 1087 #+END_SRC
 1088 
 1089 **** DISABLED Enforce TODO Dependencies
 1090 Parent tasks should not be marked DONE until all subtasks are marked as DONE.
 1091 #+BEGIN_SRC emacs-lisp
 1092   (setq org-enforce-todo-dependencies t)
 1093 #+END_SRC
 1094 
 1095 **** Highlight LaTeX Related Syntax
 1096 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:
 1097 - `latex' Highlight LaTeX snippets and environments.
 1098 - `script' Highlight subscript and superscript.
 1099 - `entities' Highlight entities.
 1100 
 1101 #+BEGIN_SRC emacs-lisp
 1102   (eval-after-load 'org
 1103     '(setf org-highlight-latex-and-related '(latex)))
 1104 #+END_SRC
 1105 
 1106 **** Default Image Size
 1107 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.
 1108 #+BEGIN_SRC emacs-lisp
 1109   (setq org-latex-image-default-width ".6\\linewidth")
 1110 #+END_SRC
 1111 
 1112 *** Enable spell checking
 1113 Spell checking with =flyspell-mode=. Would need to install dictionary lib like =aspell= in base system.
 1114 #+BEGIN_SRC emacs-lisp
 1115   (add-hook 'org-mode-hook 'flyspell-mode)
 1116 #+END_SRC
 1117 
 1118 *** Enable Code Evaluation
 1119 Enable evaluation of various languages in org-mode.
 1120 #+BEGIN_SRC emacs-lisp
 1121   (defvar user/org-babel-enabled-languages
 1122     '(emacs-lisp
 1123       python
 1124       R
 1125       org)
 1126     "Extra languages user can execute in org-babel code blocks.")
 1127 
 1128   (org-babel-do-load-languages
 1129    'org-babel-load-languages
 1130    (mapcar
 1131     (lambda (arg) (cons arg t))
 1132     user/org-babel-enabled-languages))
 1133 #+END_SRC
 1134 
 1135 There is no need to confirm execution for these languages.
 1136 #+BEGIN_SRC emacs-lisp
 1137   (defvar user/org-babel-no-confirm-languages
 1138     '(emacs-lisp
 1139       python
 1140       R
 1141       latex-macros
 1142       org)
 1143     "Languages that do not user confirmation to execute")
 1144 
 1145   (setq org-confirm-babel-evaluate
 1146         (lambda (lang body)
 1147           (not (member lang
 1148                        (mapcar (lambda (arg) (symbol-name arg))
 1149                                user/org-babel-no-confirm-languages)))))
 1150 #+END_SRC
 1151 
 1152 *** Exporter Backends
 1153 **** HTML
 1154 Do not export validation link.
 1155 #+BEGIN_SRC emacs-lisp
 1156   (setq org-html-validation-link nil)
 1157 #+END_SRC
 1158 
 1159 **** Markdown (Blackfriday)
 1160 An Org exporter backend that exports Org to Hugo-compatible Markdown
 1161 (Blackfriday) and generates the front-matter (in TOML or YAML format).
 1162 
 1163 ***** Installation
 1164 Enable =ox-hugo= as an option for exporting.
 1165 #+BEGIN_SRC emacs-lisp
 1166   (use-package ox-hugo
 1167     :ensure t
 1168     :init (with-eval-after-load 'ox (require 'ox-hugo)))
 1169 #+END_SRC
 1170 
 1171 ***** Export Key Bindings
 1172 Wrap key bindings in =<kbd>=.
 1173 #+BEGIN_SRC emacs-lisp
 1174   (setq org-hugo-use-code-for-kbd t)
 1175 #+END_SRC
 1176 
 1177 **** Pandoc
 1178 This is another exporter for org-mode that translates Org-mode file to various
 1179 other formats via Pandoc.
 1180 
 1181 ***** Installation
 1182 #+BEGIN_SRC emacs-lisp
 1183   (use-package ox-pandoc
 1184     :ensure t)
 1185 #+END_SRC
 1186 
 1187 **** Jupyter Notebook
 1188 Export backend for =.ipynb=. Package is not in MELPA yet, so using local copy. Repository is located [[https://github.com/jkitchin/ox-ipynb][here]].
 1189 
 1190 #+BEGIN_SRC emacs-lisp
 1191   (use-package ox-ipynb
 1192     :load-path "local/ox-ipynb/")
 1193 #+END_SRC
 1194 
 1195 Quick and easy hack to get python source blocks to work.
 1196 #+BEGIN_SRC emacs-lisp
 1197   (setq ox-ipynb-kernelspecs
 1198         '((ipython . (kernelspec . ((display_name . "Python 3")
 1199                                     (language . "python")
 1200                                     (name . "python3"))))
 1201           (python . (kernelspec . ((display_name . "Python 3")
 1202                                    (language . "python")
 1203                                    (name . "python3"))))
 1204           (R . (kernelspec . ((display_name . "R")
 1205                               (language . "R")
 1206                               (name . "ir"))))
 1207           (julia . (kernelspec . ((display_name . "Julia 0.6.0")
 1208                                   (language . "julia")
 1209                                   (name . "julia-0.6"))))))
 1210 
 1211   (setq ox-ipynb-language-infos
 1212         '((ipython . (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           (python . (language_info . ((codemirror_mode . ((name . ipython)
 1221                                                           (version . 3)))
 1222                                       (file_extension . ".py")
 1223                                       (mimetype . "text/x-python")
 1224                                       (name . "python")
 1225                                       (nbconvert_exporter . "python")
 1226                                       (pygments_lexer . "ipython3")
 1227                                       (version . "3.5.2"))))
 1228           (R . (language_info . ((codemirror_mode . "r")
 1229                                  (file_extension . ".r")
 1230                                  (mimetype . "text/x-r-source")
 1231                                  (name . "R")
 1232                                  (pygments_lexer . "r")
 1233                                  (version . "3.3.2"))))
 1234           (julia . (language_info . ((codemirror_mode . "julia")
 1235                                      (file_extension . ".jl")
 1236                                      (mimetype . "text/x-julia")
 1237                                      (name . "julia")
 1238                                      (pygments_lexer . "julia")
 1239                                      (version . "0.6.0"))))))
 1240 #+END_SRC
 1241 
 1242 **** LaTeX
 1243 ***** LaTeX Macros
 1244 Support LaTeX macros in both LaTeX and HTML/MathJax export. We do this by adding
 1245 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]].
 1246 #+BEGIN_SRC emacs-lisp
 1247   (add-to-list 'org-src-lang-modes '("latex-macros" . latex))
 1248 
 1249   (defvar org-babel-default-header-args:latex-macros
 1250     '((:results . "raw")
 1251       (:exports . "results")))
 1252 
 1253   (defun user/prefix-all-lines (pre body)
 1254     (with-temp-buffer
 1255       (insert body)
 1256       (string-insert-rectangle (point-min) (point-max) pre)
 1257       (buffer-string)))
 1258 
 1259   (defun org-babel-execute:latex-macros (body _params)
 1260     (concat
 1261      (user/prefix-all-lines "#+LATEX_HEADER: " body)
 1262      "\n#+HTML_HEAD_EXTRA: <div style=\"display: none\"> \\(\n"
 1263      (user/prefix-all-lines "#+HTML_HEAD_EXTRA: " body)
 1264      "\n#+HTML_HEAD_EXTRA: \\)</div>\n"))
 1265 #+END_SRC
 1266 
 1267 ***** LaTeX Preview Scaling
 1268 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.
 1269 
 1270 #+BEGIN_SRC emacs-lisp
 1271   (plist-put org-format-latex-options :scale 1.75)
 1272   (setq org-latex-create-formula-image-program 'dvisvgm)
 1273 #+END_SRC
 1274 
 1275 ***** Code Listing
 1276 Use =minted= for code listings. Relies on =pygments= for syntax highlighting.
 1277 #+BEGIN_SRC emacs-lisp
 1278   (setq org-latex-listings 'minted)
 1279   (setq org-latex-minted-options
 1280         '(("frame" "single")
 1281           ("fontsize" "\\scriptsize")))
 1282   (add-to-list 'org-latex-packages-alist '("" "minted" nil))
 1283 #+END_SRC
 1284 
 1285 ***** SVG Support
 1286 Use =svg= for supporting SVGs. Requires =inkscape= to be installed.
 1287 #+BEGIN_SRC emacs-lisp
 1288   (add-to-list 'org-latex-packages-alist '("" "svg" nil))
 1289 #+END_SRC
 1290 
 1291 ***** Shell Escape
 1292 This is required for =minted= and =svg= to work.
 1293 #+begin_src emacs-lisp
 1294   (setq org-latex-pdf-process
 1295         '("%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
 1296           "%latex -shell-escape -interaction nonstopmode -output-directory %o %f"
 1297           "%latex -shell-escape -interaction nonstopmode -output-directory %o %f"))
 1298 #+end_src
 1299 
 1300 ** Python-mode
 1301 Enhancements to =python-mode=.
 1302 
 1303 *** Anaconda Mode
 1304 Code navigation, documentation lookup and completion for Python.
 1305 #+BEGIN_SRC emacs-lisp
 1306   (use-package anaconda-mode
 1307     :ensure t
 1308     :init
 1309     (add-hook 'python-mode-hook 'anaconda-mode)
 1310     (add-hook 'python-mode-hook 'anaconda-eldoc-mode))
 1311 #+END_SRC
 1312 
 1313 *** Auto Format
 1314 **** black
 1315 Use =black= to auto format python buffers on save.
 1316 #+BEGIN_SRC emacs-lisp
 1317   (use-package blacken
 1318     :ensure t
 1319     :init
 1320     (add-hook 'python-mode-hook 'blacken-mode))
 1321 #+END_SRC
 1322 
 1323 **** isort
 1324 Use =isort= to sort imports.
 1325 #+BEGIN_SRC emacs-lisp
 1326   (use-package isortify
 1327     :ensure t
 1328     :init
 1329     (add-hook 'python-mode-hook 'isortify-mode)
 1330     (setq isortify-multi-line-output 3)
 1331     (setq isortify-trailing-comma t)
 1332     (setq isortify-line-width 88))
 1333 #+END_SRC
 1334 
 1335 Use =black=-compatible settings as recommended [[https://github.com/python/black#how-black-wraps-lines][here]]. Add missing variables to conform with =black=.
 1336 #+BEGIN_SRC emacs-lisp
 1337   (defcustom isortify-force-grid-wrap nil
 1338     "Force from imports to be grid wrapped regardless of line length, where the value given is the number of imports allowed before wrapping occurs.")
 1339 
 1340   (defcustom isortify-use-parentheses nil
 1341     "Tells isort to use parenthesis for line continuation instead of \ for lines over the allotted line length limit.")
 1342 
 1343   (setq isortify-force-grid-wrap 0)
 1344   (setq isortify-use-parentheses t)
 1345 
 1346   (defun isortify-call-args ()
 1347     "Collect CLI arguments for isort process."
 1348     (let (args)
 1349       (when (string= "ipython" python-shell-interpreter)
 1350         (push "--" args))
 1351       (when isortify-multi-line-output
 1352         (push "--multi-line" args)
 1353         (push (number-to-string isortify-multi-line-output) args))
 1354       (when isortify-trailing-comma
 1355         (push "--trailing-comma" args))
 1356       (when isortify-known-first-party
 1357         (dolist (project isortify-known-first-party)
 1358           (push "--project" args)
 1359           (push project args)))
 1360       (when isortify-known-third-party
 1361         (dolist (thirdparty isortify-known-third-party)
 1362           (push "--thirdparty" args)
 1363           (push thirdparty args)))
 1364       (when isortify-lines-after-imports
 1365         (push "--lines-after-imports" args)
 1366         (push (number-to-string isortify-lines-after-imports) args))
 1367       (when isortify-line-width
 1368         (push "--line-width" args)
 1369         (push (number-to-string isortify-line-width) args))
 1370       (when isortify-force-grid-wrap
 1371         (push "--force-grid-wrap" args)
 1372         (push (number-to-string isortify-force-grid-wrap) args))
 1373       (when isortify-use-parentheses
 1374         (push "--use-parentheses" args))
 1375       (push "-" args)
 1376       (reverse args)))
 1377 #+END_SRC
 1378 
 1379 
 1380 **** DISABLED yapf
 1381 Use =yapf= to auto format python buffers on save.
 1382 #+BEGIN_SRC emacs-lisp
 1383   (use-package yapfify
 1384     :ensure t
 1385     :init
 1386     (add-hook 'python-mode-hook 'yapf-mode))
 1387 #+END_SRC
 1388 
 1389 **** DISABLED pep8
 1390 Use =py-autopep8= to auto format python buffers on save.
 1391 #+BEGIN_SRC emacs-lisp
 1392   (use-package py-autopep8
 1393     :ensure t
 1394     :init
 1395     (add-hook 'python-mode-hook 'py-autopep8-enable-on-save))
 1396 #+END_SRC
 1397 
 1398 *** Syntax Checking
 1399 **** Flycheck
 1400 By default =flycheck= only runs one available python checker.
 1401 #+BEGIN_SRC emacs-lisp
 1402   (flycheck-add-next-checker 'python-flake8 'python-pylint)
 1403 #+END_SRC
 1404 
 1405 **** DISABLED pycheckers
 1406 By default =flycheck= only runs one available python checker. Use
 1407 =flycheck-pycheckers=.
 1408 #+BEGIN_SRC emacs-lisp
 1409   (use-package flycheck-pycheckers
 1410     :ensure t
 1411     :init
 1412     (setq flycheck-pycheckers-checkers '(pylint flake8))
 1413     (add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup))
 1414 #+END_SRC
 1415 
 1416 *** Python Interpretor
 1417 Use =ipython= as default interpreter and disable feature warning.
 1418 
 1419 #+BEGIN_SRC emacs-lisp
 1420   (setq python-shell-interpreter "ipython"
 1421         python-shell-interpreter-args "-i --simple-prompt"
 1422         python-shell-prompt-detect-failure-warning nil)
 1423   (add-to-list 'python-shell-completion-native-disabled-interpreters
 1424                "ipython")
 1425 #+END_SRC
 1426 
 1427 ** Rust-mode
 1428 A compilation of settings for programming in rust. The recommended way to
 1429 install rust is via =rustup=. Remember to use =rustup add component= to install
 1430 =rust-fmt=, =rust-src=, and =rls=.
 1431 
 1432 *** Rust-mode
 1433 Install =rust-mode=, use =rust-fmt= to format the code upon saving,
 1434 and automatically enable =rust-mode= for =*.rs= files.
 1435 #+BEGIN_SRC emacs-lisp
 1436   (use-package rust-mode
 1437     :ensure t
 1438     :init
 1439     (setq rust-format-on-save t)
 1440     (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode)))
 1441 #+END_SRC
 1442 
 1443 *** Cargo Integration
 1444 A minor mode for =cargo=, the package manager for rust.
 1445 #+BEGIN_SRC emacs-lisp
 1446   (use-package cargo
 1447     :ensure t
 1448     :init
 1449     (add-hook 'rust-mode-hook 'cargo-minor-mode))
 1450 #+END_SRC
 1451 
 1452 *** Flycheck Support
 1453 Better flycheck support via =flycheck-rust=.
 1454 #+BEGIN_SRC emacs-lisp
 1455   (use-package flycheck-rust
 1456     :ensure t
 1457     :init
 1458     (with-eval-after-load 'rust-mode
 1459       (add-hook 'flycheck-mode-hook #'flycheck-rust-setup)))
 1460 #+END_SRC
 1461 
 1462 *** Racer
 1463 Code completion utility for rust. Provides =company= integration.
 1464 #+BEGIN_SRC emacs-lisp
 1465   (use-package racer
 1466     :ensure t
 1467     :init
 1468     (add-hook 'rust-mode-hook #'racer-mode)
 1469     (add-hook 'rust-mode-hook #'eldoc-mode))
 1470 #+END_SRC
 1471 
 1472 ** Zig-mode
 1473 #+BEGIN_SRC emacs-lisp
 1474   (use-package zig-mode
 1475     :ensure t)
 1476 #+END_SRC
 1477 
 1478 * Enhancements
 1479 Packages providing enhancements to Emacs interface. Mostly simple plug-and-play
 1480 packages. Load enhancements in the end to prevent their dependencies getting
 1481 loaded prior to their own customization.
 1482 
 1483 ** Avy
 1484 Jump to visible text using a char-based decision tree, similar to =ace-jump=.
 1485 #+BEGIN_SRC emacs-lisp
 1486   (use-package avy
 1487     :ensure t
 1488     :init
 1489     (define-prefix-command 'user/avy-prefix)
 1490     (global-set-key (kbd "C-:") 'user/avy-prefix)
 1491     (define-key 'user/avy-prefix (kbd "c") 'avy-goto-char)
 1492     (define-key 'user/avy-prefix (kbd "C") 'avy-goto-char-2)
 1493     (define-key 'user/avy-prefix (kbd "t") 'avy-goto-char-timer)
 1494     (define-key 'user/avy-prefix (kbd "s") 'avy-goto-char-in-line)
 1495     (define-key 'user/avy-prefix (kbd "l") 'avy-goto-line)
 1496     (define-key 'user/avy-prefix (kbd "w") 'avy-goto-word-0)
 1497     (define-key 'user/avy-prefix (kbd "W") 'avy-goto-word-1)
 1498     (define-key 'user/avy-prefix (kbd "o") 'avy-org-goto-heading-timer)
 1499     (define-key 'user/avy-prefix (kbd "O") 'avy-org-refile-as-child))
 1500 #+END_SRC
 1501 
 1502 ** Dashboard
 1503 An extensible Emacs startup screen showing you what's most important.
 1504 
 1505 *** Installation
 1506 Change default startup screen with =dashboard=.
 1507 Customize =initial-buffer-choice= to affect new frames created by =emacsclient=.
 1508 Also refresh dashboard to ensure customizations take effect.
 1509 #+BEGIN_SRC emacs-lisp
 1510   (use-package dashboard
 1511     :ensure t
 1512     :config
 1513     (dashboard-setup-startup-hook)
 1514     (setq initial-buffer-choice (lambda()
 1515                                   (dashboard-refresh-buffer)
 1516                                   (get-buffer "*dashboard*"))))
 1517 #+END_SRC
 1518 
 1519 *** Customize Banner and Logo
 1520 Customize banner and logo.
 1521 #+BEGIN_SRC emacs-lisp
 1522   (defvar user/dashboard-banner-logo-titles
 1523     '("42"
 1524       "9 MORE SEASONS UNTIL I GET THAT DIPPING SZECHUAN SAUCE!"
 1525       "Avocado + Maple Syrup = Dragon Fruit"
 1526       "Eight-Megabytes-And-Constantly-Swapping"
 1527       "Enter-Meta-Alt-Control-Shift"
 1528       "Execute order 66."
 1529       "Greetings from Emacs!"
 1530       "POLYBIUS"
 1531       "Project-iM@CS"
 1532       "Supervillain Repair & Restoration"
 1533       "This is fine."
 1534       "Weak emperors mean strong viceroys."
 1535       "Wissen ist Nacht!"
 1536       "Wubba Lubba Dub-Dub!"))
 1537   (setq dashboard-banner-logo-title
 1538         (elt user/dashboard-banner-logo-titles
 1539              (random (length user/dashboard-banner-logo-titles))))
 1540   (setq dashboard-startup-banner
 1541         (expand-file-name "static/sxs.png" user-emacs-directory))
 1542 #+END_SRC
 1543 
 1544 *** Customize Widgets
 1545 **** =dashboard-insert-configs=
 1546 Create widget to display important config files. Use ~c~ to jump to this section.
 1547 #+BEGIN_SRC emacs-lisp
 1548   (defvar user/config-file-list
 1549     (mapcar (lambda (arg) (expand-file-name arg user-emacs-directory))
 1550             '("README.org"
 1551               "init.el"
 1552               "static/math_macros.sty")))
 1553 
 1554   (defun user/dashboard-insert-configs (list-size)
 1555     "Add a list of config files."
 1556     (dashboard-insert-section
 1557      "Config Files:"
 1558      user/config-file-list
 1559      list-size
 1560      "c"
 1561      `(lambda (&rest ignore) (find-file-existing ,el))
 1562      (abbreviate-file-name el)))
 1563 
 1564   (add-to-list 'dashboard-item-generators '(configs . user/dashboard-insert-configs))
 1565 #+END_SRC
 1566 
 1567 **** =dashboard-insert-init-time=
 1568 Display initialization time.
 1569 #+BEGIN_SRC emacs-lisp
 1570   (defun user/dashboard-insert-init-time (list-size)
 1571      "Displays Emacs init time."
 1572      (insert (format "[Started Emacs in %s.]" (emacs-init-time))))
 1573 
 1574   (add-to-list 'dashboard-item-generators '(init-time . user/dashboard-insert-init-time))
 1575 #+END_SRC
 1576 
 1577 **** Apply All Widgets
 1578 Set items to display:
 1579 #+BEGIN_SRC emacs-lisp
 1580   (setq dashboard-items '((recents  . 10)
 1581                           (bookmarks . 5)
 1582                           (projects . 8)
 1583                           (agenda . 5)
 1584   ;                        (registers . 5)
 1585                           (configs)
 1586                           (init-time)))
 1587 #+END_SRC
 1588 
 1589 ** HTML Export
 1590 Convert buffer text and decorations to HTML by =htmlize-buffer= so
 1591 that people can see what I see.
 1592 #+BEGIN_SRC emacs-lisp
 1593   (use-package htmlize
 1594     :ensure t)
 1595 #+END_SRC
 1596 
 1597 ** Keybindings
 1598 *** IBuffer
 1599 Use =ibuffer= instead of =list-buffer=.
 1600 #+BEGIN_SRC emacs-lisp
 1601   (global-set-key (kbd "C-x C-b") 'ibuffer)
 1602   (autoload 'ibuffer "ibuffer" "List buffers." t)
 1603 #+END_SRC
 1604 
 1605 ** Keyfreq
 1606 Records command frequency. I am planning on adjusting my keyboard
 1607 layout with this information.
 1608 #+BEGIN_SRC emacs-lisp
 1609     (use-package keyfreq
 1610       :ensure t
 1611       :init
 1612       (keyfreq-mode 1)
 1613       (keyfreq-autosave-mode 1))
 1614 #+END_SRC
 1615 
 1616 ** Magit
 1617 Install =magit= and bind =magit-status= to ~C-c g~.
 1618 #+BEGIN_SRC emacs-lisp
 1619   (use-package magit
 1620     :ensure t
 1621     :init
 1622     (global-set-key (kbd "C-c g") 'magit-status))
 1623 #+END_SRC
 1624 
 1625 *** Magit annex
 1626 Magit support for =git-annex=.
 1627 #+BEGIN_SRC emacs-lisp
 1628   (use-package magit-annex
 1629     :ensure t)
 1630 #+END_SRC
 1631 
 1632 ** Projectile
 1633 Projectile is a project interaction library for Emacs. Its goal is to
 1634 provide a nice set of features operating on a project level without
 1635 introducing external dependencies(when feasible).
 1636 
 1637 *** Installation
 1638 Install =projectile=.
 1639 #+BEGIN_SRC emacs-lisp
 1640   (use-package projectile
 1641     :ensure t
 1642     :init
 1643     (projectile-mode +1))
 1644 #+END_SRC
 1645 
 1646 *** DISABLED Enable =helm= support
 1647 Since I use =helm=, I need to install additional support.
 1648 #+BEGIN_SRC emacs-lisp
 1649   (use-package helm-projectile
 1650     :ensure t
 1651     :init
 1652     (setq projectile-completion-system 'helm)
 1653     (helm-projectile-on))
 1654 #+END_SRC