Skip to content

Latest commit

 

History

History
1578 lines (1445 loc) · 53.7 KB

config.org

File metadata and controls

1578 lines (1445 loc) · 53.7 KB

My Emacs configuration

OS dependencies

Windows and Mac have some interesting paths when starting emacs which needs to be fixed. Using mingw64 in windows and general path in mac.

(cond ((eq system-type 'windows-nt)
       (add-to-list 'exec-path "C:/msys64/usr/bin")
       (add-to-list 'exec-path "C:/msys64/mingw64/bin")
       (add-to-list 'exec-path "C:/Program Files/gnuplot")
       (setenv "PATH" (mapconcat #'identity exec-path path-separator)))
      ((eq system-type 'darwin)
       (use-package exec-path-from-shell
         :config
         (exec-path-from-shell-initialize))
       (setq default-directory "~/")))

Aesthetic changes

Emacs theme

Theme switcher, using a cond allows loading of many preconfigured themes which can be switched between easily. Zenburn theme is my default.

(defun disable-all-themes ()
  (dolist (i custom-enabled-themes)
    (disable-theme i)))

(defun set-theme (theme)
  "Set the theme with theme downloading"
  (interactive "SWhat theme to load? ")
  (cond ((eq theme 'zenburn)
         (use-package zenburn-theme))
        ((string-match-p "^doom" "doom-one")
         (use-package doom-themes
           :config
           (setq doom-themes-enable-bolt t
                 doom-themes-enable-italic t)
           (doom-themes-visual-bell-config)
           (doom-themes-org-config)))
        ((eq theme 'nord)
         (use-package nord-theme))
        ((eq theme 'solarized)
         (use-package solarized-theme))
        ((eq theme 'jetbrains-darcula)
         (use-package jetbrains-darcula-theme))
        ((eq theme 'none)
         (disable-all-themes)))
  (setq emacs-theme theme)
  (when (not (eq theme 'none))
    (load-theme theme t))
  (message (format "Theme set to: %s" theme)))

(set-theme 'zenburn)

Default font

Set default font and faces.

(cond ((member "Dank Mono" (font-family-list))
       (set-frame-font "Dank Mono-11" nil t))
      ((member "DejaVu Sans Mono" (font-family-list))
       (set-frame-font "DejaVu Sans Mono" nil t))
      ((member "Source Code Pro" (font-family-list))
       (set-frame-font "Source Code Pro-10" nil t)))

(set-face-italic 'font-lock-comment-face t)
(set-face-italic 'font-lock-keyword-face t)

Remove menu bar, toolbar, and scroll bar

Make the emacs interface slightly nicer.

(menu-bar-mode 0)
(tool-bar-mode 0)
(scroll-bar-mode 0)

Writing requirements

Spellchecking

Use aspell for spellchecking. Auto-enable in latex and org as they’re the main writing modes.

(use-package flyspell
  :hook ((tex-mode latex-mode TeX-mode LaTeX-mode org-mode text-mode) . flyspell-mode)
  :diminish flyspell-mode
  :init
  (require 'ispell)
  :config
  (setq-default ispell-program-name "aspell")
  (setq-default ispell-local-dictionary "en_AU"))

Language Tool

Language tool is an open source grammar checker.

(use-package langtool
  :init
  (setq langtool-java-classpath "/usr/share/languagetool:/usr/share/java/languagetool/*"))

Switch-window

Helps to change windows easily when many are open at once.

(use-package switch-window
  :config
  ;; (setq switch-window-input-style 'minibuffer)
  (setq switch-window-threshold 2)
  (setq switch-window-shortcut-style 'qwerty)
  :bind
  ([remap other-window] . switch-window))

Go to new window when opened

Go to new window when its opened instead of staying with current one.

(defun split-and-follow-horizontally ()
  (interactive)
  (split-window-below)
  (balance-windows)
  (other-window 1))
(global-set-key (kbd "C-x 2") 'split-and-follow-horizontally)

(defun split-and-follow-vertically ()
  (interactive)
  (split-window-right)
  (balance-windows)
  (other-window 1))
(global-set-key (kbd "C-x 3") 'split-and-follow-vertically)

PDF-tools

Helpful pdf viewer.

(use-package pdf-tools
  :config
  (pdf-tools-install 1))

Helm and Projectile

Helm core

Helm aids the user interface for emacs. Adds visual and auto-complete feedback for emacs commands.

(use-package helm
  :bind (("M-x" . helm-M-x)
         ("C-x C-f" . helm-find-files)
         ("M-y" . helm-show-kill-ring)
         ("C-x b" . helm-mini)
         ("C-c h o" . helm-occur))
  :diminish helm-mode
  :config
  (setq helm-mode-fuzzy-match                 t
        helm-completion-in-regionfuzzy-match  t
        helm-split-window-inside-p            t ; open helm buffer inside current window, not occupy whole other window
        helm-move-to-line-cycle-in-source     t ; move to end or beginning of source when reaching top or bottom of source.
        helm-ff-search-library-in-sexp        t ; search for library in `require' and `declare-function' sexp.
        helm-scroll-amount                    8 ; scroll 8 lines other window using M-<next>/M-<prior>
        helm-ff-file-name-history-use-recentf t
        helm-echo-input-in-header-line        t
        completion-styles                     '(flex))
  (defun spacemacs//helm-hide-minibuffer-maybe ()
    "Hide minibuffer in Helm session if we use the header line as input field."
    (when (with-helm-buffer helm-echo-input-in-header-line)
      (let ((ov (make-overlay (point-min) (point-max) nil nil t)))
        (overlay-put ov 'window (selected-window))
        (overlay-put ov 'face
                     (let ((bg-color (face-background 'default nil)))
                       `(:background ,bg-color :foreground ,bg-color)))
        (setq-local cursor-type nil))))
  (add-hook 'helm-minibuffer-set-up-hook
            'spacemacs//helm-hide-minibuffer-maybe)
  (helm-mode 1))

Helm git

Give helm git awareness.

(use-package helm-ls-git
  :bind (("C-x C-d" . helm-browse-project)))

Projectile

Projectile is project management framework for emacs. Helps in navigation and management of projects. Identifies project layout from git.

Enable it

(use-package projectile
  :bind ("C-c p" . projectile-command-map)
  :diminish projectile-mode
  :config
  (projectile-global-mode)
  (setq projectile-completion-system 'helm)
  (when (eq system-type 'windows-nt)
    (setq projectile-indexing-method 'alien)))

Let it compile things

Shortcut for compilation.

(global-set-key (kbd "<f5>") 'projectile-compile-project)

Enable communication with helm

Use helm to manage project.

(use-package helm-projectile
  :config
  (helm-projectile-on))

Small tweaks

Remove startup screen

Start on scratch buffer instead.

(setq inhibit-startup-message t)

Disable bell

Bloody bell dings every time you hit a key too much.

(setq ring-bell-function 'ignore)

Pretty symbols

Why not? They make it look nice.

(use-package pretty-mode
  :diminish t
  :if window-system
  :config
  (global-pretty-mode))

Which key

Helps to explain keybindings if you get lost.

(use-package which-key
  :diminish which-key-mode
  :config
  (which-key-mode))

Config shortcuts

Go to this file

(defun config-visit ()
  (interactive)
  (find-file "~/.emacs.d/config.org"))
(global-set-key (kbd "C-c e d") 'config-visit)

Go to init.el

(defun init-visit ()
  (interactive)
  (find-file "~/.emacs.d/init.el"))
(global-set-key (kbd "C-c e i") 'init-visit)

Go to early-init.el

(defun early-init-visit ()
  (interactive)
  (find-file "~/.emacs.d/early-init.el"))
(global-set-key (kbd "C-c e e") 'early-init-visit)

Reload configuration

(defun config-reload ()
  "Reloads ~/.emacs.d/config.org at run time"
  (interactive)
  (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))
(global-set-key (kbd "C-c e r") 'config-reload)

Smartparens

Matches brackets automatically. Added “$” for latex in org mode.

(use-package smartparens
  :diminish smartparens-mode
  :config
  (progn
    (require 'smartparens-config)
    (smartparens-global-mode 1))
  (sp-with-modes 'org-mode
    (sp-local-pair "$" "$")))

Rainbow delimiters

A bit more useful than above. Colours the brackets so that they stand out more.

(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode))

Following whitespace

Removes unnecessary white space

(use-package clean-aindent-mode
  :hook prog-mode)

Shows trailing white space

(add-hook 'prog-mode-hook (lambda () (interactive) (setq show-trailing-whitespace 1)))

Whitespace mode

Reveals whitespace characters

(global-set-key (kbd "C-c w") 'whitespace-mode)
(add-hook 'diff-mode-hook (lambda ()
                            (setq-local whitespace-style
                                        '(face
                                          tabs
                                          tab-mark
                                          spaces
                                          space-mark
                                          trailing
                                          indentation::space
                                          indentation::tab
                                          newline
                                          newline-mark))
                            (whitespace-mode 1)))

eldoc

Shows function arguments in echo area below mode line.

(diminish 'eldoc-mode)
(add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
(add-hook 'lisp-interaction-mode-hook 'eldoc-mode)
(add-hook 'ielm-mode-hook 'eldoc-mode)

Key frequency statistics

Collects interesting statistics about key presses. Use M-x keyfreq-show to show in emacs or M-x keyfreq-html to output

(use-package keyfreq
  :config
  (keyfreq-mode 1)
  (keyfreq-autosave-mode 1))

Undo tree

A more advanced undo mechanism. Supports branched undo history (thus the tree). Pretty neat, if seldom used.

(use-package undo-tree
  :diminish undo-tree-mode
  :config
  (setq-default undo-tree-auto-save-history t)
  (add-to-list 'undo-tree-incompatible-major-modes 'archive-mode)
  (global-undo-tree-mode))

Volatile highlights

Colour the material just copied

(use-package volatile-highlights
  :diminish volatile-highlights-mode
  :config
  (volatile-highlights-mode t))

ibuffer

View all open buffers in their own buffer rather in the temporary mini buffer.

(global-set-key (kbd "C-x C-b") 'ibuffer)
(setq ibuffer-use-other-window t)

Hippie expand

Seems cool, but I don’t think I ever use this. Meant to suggest completions to beginning of a word.

(global-set-key (kbd "M-/") 'hippie-expand) ;; replace dabbrev-expand
(setq
 hippie-expand-try-functions-list
 '(try-expand-dabbrev ;; Try to expand word "dynamically", searching the current buffer.
   try-expand-dabbrev-all-buffers ;; Try to expand word "dynamically", searching all other buffers.
   try-expand-dabbrev-from-kill ;; Try to expand word "dynamically", searching the kill ring.
   try-complete-file-name-partially ;; Try to complete text as a file name, as many characters as unique.
   try-complete-file-name ;; Try to complete text as a file name.
   try-expand-all-abbrevs ;; Try to expand word before point according to all abbrev tables.
   try-expand-list ;; Try to complete the current line to an entire line in the buffer.
   try-expand-line ;; Try to complete the current line to an entire line in the buffer.
   try-complete-lisp-symbol-partially ;; Try to complete as an Emacs Lisp symbol, as many characters as unique.
   try-complete-lisp-symbol) ;; Try to complete word as an Emacs Lisp symbol.
 )

Highlight line

Very useful for finding where you are.

(global-hl-line-mode)

Line numbers

Everyone needs line numbers when programming.

(if (version<= "26.0.50" emacs-version)
    (add-hook 'prog-mode-hook 'display-line-numbers-mode)
  (add-hook 'prog-mode-hook 'linum-mode))

Garbage collection

Starts garbage collection every 100MB.

(setq gc-cons-threshold (* 1024 1024 100))

Kill ring

Changes the kill ring size to 5000.

(setq global-mark-ring-max 5000
      mark-ring-max 5000
      mode-require-final-newline t
      kill-ring-max 5000
      kill-whole-line t)

Coding style

Use java for java, awk for awk and K&R for everything else. K&R uses 4 space tabs.

(setq c-default-style '((java-mode . "java")
                        (awk-mode . "awk")
                        (other . "k&r")))

Coding system

Cause we all love UTF8.

(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)
(setq-default indent-tabs-mode nil
              tab-width 4
              c-basic-offset tab-width
              cperl-indent-level tab-width)
(c-set-offset 'inline-open '0)
(delete-selection-mode)
(global-set-key (kbd "RET") 'newline-and-indent)

Smart tabs

Tabs for indentation, spaces for alignment

(use-package smart-tabs-mode
  :config
  (smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python 'ruby
                        'nxml))

Move to beginning of line ignoring whitespace

Move point back to indentation of beginning of line. Pretty good for getting to the start of what you actually wanted.

Move point to the first non-whitespace character on this line. If point is already there, move to the beginning of the line. Effectively toggle between the first non-whitespace character and the beginning of the line.

If ARG is not nil or 1, move forward ARG - 1 lines first. If point reaches the beginning or end of the buffer, stop there.

(defun prelude-move-beginning-of-line (arg)
  (interactive "^p")
  (setq arg (or arg 1))

  ;; Move lines first
  (when (/= arg 1)
    (let ((line-move-visual nil))
      (forward-line (1- arg))))

  (let ((orig-point (point)))
    (back-to-indentation)
    (when (= orig-point (point))
      (move-beginning-of-line 1))))

(global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)

Indent region or buffer

Indent, slightly different to standard tab or C-M-.

(defun indent-region-or-buffer ()
  "Indent a region if selected, otherwise the whole buffer."
  (interactive)
  (unless (member major-mode prelude-indent-sensitive-modes)
    (save-excursion
      (if (region-active-p)
          (progn
            (indent-region (region-beginning) (region-end))
            (message "Indented selected region."))
        (progn
          (indent-buffer)
          (message "Indented buffer.")))
      (whitespace-cleanup))))

(global-set-key (kbd "C-c i") 'indent-region-or-buffer)

Tramp

Remote editing mode. Hate having to re-input passwords.

(use-package tramp
  :pin gnu
  :config
  ;; (setq tramp-default-method "ssh")
  (when (eq system-type 'windows-nt)
    (setq tramp-default-method "pscp"))
  (setq password-cache-expiry nil)
  (add-to-list 'tramp-remote-path 'tramp-own-remote-path))

Highlight indentation

Vertical demarcations for indent levels

(use-package highlight-indentation
  :hook (prog-mode . highlight-indentation-mode))

Auto revert mode

Update unchanged buffers if underlying file changes.

(global-auto-revert-mode)

Mode line tweaks

Diminish is used but is included in init.el such that it can be used throughout this document

Spaceline

A little easier to read than the default emacs mode line.

(use-package spaceline
  :config
  (require 'spaceline-config)
  (setq spaceline-buffer-encoding-abbrev-p t)
  (setq spaceline-line-column-p t)
  (setq powerline-default-separator (quote arrow))
  (spaceline-spacemacs-theme)
  (spaceline-helm-mode))

Separator

Slightly nicer separator.

(setq powerline-default-separator nil)

Nyan mode

Use nyan cat as a reference for buffer progression.

(use-package nyan-mode
  :config
  (nyan-mode 1))

Programming tweaks

Yasnippet

Add snippets, pretty useful. Manually added snippets are in ~/.emacs.d/snippets/{mode}.

(use-package yasnippet
  :diminish yas-minor-mode
  :config
  (yas-global-mode 1))

(use-package yasnippet-snippets
  :after yasnippet)

Flycheck

Basic linter. Works pretty well.

(use-package flycheck
  :diminish flycheck-mode
  :config
  (global-flycheck-mode))

flycheck-pos-tip

Add suggestions at the cursor.

(use-package flycheck-pos-tip
  :after flycheck
  :config
  (flycheck-pos-tip-mode))

Company

Company is auto-complete for Emacs. Uses various backends, more of which are added later.

(use-package company
  :diminish company-mode
  :config
  (global-company-mode)
  (setq company-idle-delay 0)
  (setq company-minimum-prefix-length 1))

LSP Mode

Use LSP for completion suggestions. Causes too much memory usage, need to debug. Need to generate compile_flags for c/c++, can use bear but may need other tools.

(use-package lsp-mode
  :hook (((c-mode
           c++-mode
           tex-mode
           latex-mode
           TeX-mode
           LaTeX-mode
           rust-mode
           sh-mode
           ;; verilog-mode
           go-mode
           python-mode) . lsp))
  :init
  (setq lsp-keymap-prefix "C-c l")
  :commands lsp
  :config
  (add-hook 'lsp-mode-hook 'lsp-enable-which-key-integration)
  (setq read-process-output-max (* 1024 1024))
  (setq lsp-completion-provider :capf)
  (setq lsp-keep-workspace-alive 'nil)
  (add-to-list 'exec-path "~/.cargo/bin")
  (add-to-list 'exec-path "~/.local/bin"))

(use-package lsp-ui
  :commands lsp-ui-mode)

(use-package helm-lsp
  :commands helm-lsp-workspace-symbol)

Version control

Settings for emacs’ own version control system.

Enable version control on the mode line

(vc-mode)

Magit

Emacs git client. Pretty good and offers fairly decent features.

(use-package magit
  :commands magit-get-top-dir
  :bind ("C-x g" . magit-status)
  :init
  (progn
    ;; make magit status go full-screen but remember previous window
    ;; settings
    ;; from: http://whattheemacsd.com/setup-magit.el-01.html
    (defadvice magit-status (around magit-fullscreen activate)
      (window-configuration-to-register :magit-fullscreen)
      ad-do-it
      (delete-other-windows))

    ;; Close popup when committing - this stops the commit window
    ;; hanging around
    ;; From: http://git.io/rPBE0Q
    (defadvice git-commit-commit (after delete-window activate)
      (delete-window))

    (defadvice git-commit-abort (after delete-window activate)
      (delete-window))

    :config
    (progn
      ;; restore previously hidden windows
      (defadvice magit-quit-window (around magit-restore-screen activate)
        (let ((current-mode major-mode))
          ad-do-it
          ;; we only want to jump to register when the last seen buffer
          ;; was a magit-status buffer.
          (when (eq 'magit-status-mode current-mode)
            (jump-to-register :magit-fullscreen)))))

    ;; magit settings
    (setq
     ;; don't put "origin-" in front of new branch names by default
     magit-default-tracking-name-function 'magit-default-tracking-name-branch-only
     ;; open magit status in same window as current buffer
     magit-status-buffer-switch-function 'switch-to-buffer
     ;; highlight word/letter changes in hunk diffs
     magit-diff-refine-hunk t
     ;; ask me if I want to include a revision when rewriting
     magit-rewrite-inclusive 'ask
     ;; ask me to save buffers
     magit-save-some-buffers t
     ;; pop the process buffer if we're taking a while to complete
     magit-process-popup-time 10
     ;; ask me if I want a tracking upstream
     magit-set-upstream-on-push 'askifnotset
     ))
  )

More general yes and no prompt

The default setting can miss some. Don’t redefine the regex in case this is too general.

;;(when-let ((regex "[\[\(]]?\\([Yy]\\(es\\)?\\)[/|]\\([Nn]o?\\)[\]\)]")
(defun magit-process-general-yn-prompt-hook (proc str)
  "Handle [y/n] prompts"
  (when-let ((beg (string-match "[\[\(]]?\\([Yy]\\(es\\)?\\)[/|]\\([Nn]o?\\)[\]\)]" str)))
    (let ;; ((max-mini-window-height 30))
        (process-send-string
         proc
         (downcase
          (concat
           (match-string
            (if (save-match-data
                  (magit-process-kill-on-abort proc
                    (y-or-n-p (substring str 0 beg)))) 1 2)
            str)
           "\n"))))))

(add-hook 'magit-process-prompt-functions
          #'magit-process-general-yn-prompt-hook)

CEDET

gdb-many-windows

Enhances the use of GDB in emacs. Shows register contents, variable contents and others in addition to GDB shell. Also shows source code while debugging.

(setq
 gdb-many-windows t
 gdb-show-main t)

Tree sitter

Parser library. Provides better syntax highlighting and some other neat features.

(use-package tree-sitter
  :diminish t)
(use-package tree-sitter-langs
  :config
  (global-tree-sitter-mode)
  (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))

Language specific configs

C/C++

Flycheck

Flycheck clang

Add the clang backend for linting.

(use-package flycheck-clang-analyzer
  :after flycheck
  :config
  (with-eval-after-load 'flycheck
    (require 'flycheck-clang-analyzer)
    (flycheck-clang-analyzer-setup)))
Flycheck project root

Flycheck tends to fail finding the project root, giving errors about missing files. This should remove them.

(defun setup-flycheck-project-path ()
  (let ((root (ignore-errors (projectile-project-root))))
    (when root
      (add-to-list
       (make-variable-buffer-local 'flycheck-clang-include-path)
       root)
      (add-to-list
       (make-variable-buffer-local 'flycheck-gcc-include-path)
       root))))

(add-hook 'c-mode-hook 'setup-flycheck-project-path)
(add-hook 'c++-mode-hook 'setup-flycheck-project-path)

Clang-format

Automatically format buffer on save.

(defun set-clang-format-style ()
  (if (file-exists-p (concat
                      (projectile-project-root)
                      ".clang-format"))
      (setq-local clang-format-style nil)
    (setq-local clang-format-style (concat "{BasedOnStyle: LLVM,"
                                           "IndentWidth: " (format "%s" tab-width) ","
                                           "TabWidth: " (format "%s" tab-width) ","
                                           "UseTab: " (if (eq indent-tabs-mode nil)
                                                          "Never"
                                                        "AlignWithSpaces")
                                           ","
                                           "BreakBeforeBraces: Linux,"
                                           "AllowShortIfStatementsOnASingleLine: false,"
                                           "PointerAlignment: Left,"
                                           "IndentCaseBlocks: true,"
                                           "IndentCaseLabels: false,"
                                           "SortUsingDeclarations: true}"))))
(add-hook 'c-mode-common-hook 'set-clang-format-style)

(use-package clang-format)

;;   (defun clang-format-on-save ()
;;     (add-hook 'before-save-hook 'clang-format-buffer nil t))
;;   (add-hook 'c-mode-hook 'clang-format-on-save nil t)
;;   (add-hook 'c++-mode-hook 'clang-format-on-save nil t))

emacs-lisp

Latex

AucTex

AucTex contains many additions to make tex editing good.

(use-package tex
  :ensure auctex
  :straight auctex
  :config
  (setq TeX-auto-save t
        TeX-parse-self t
        TeX-view-program-selection '((output-pdf "PDF Tools"))
        TeX-source-correlate-start-server t)
  (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer))

Company

Help company complete tex math and references.

(use-package company-math
  :after company
  :config
  (add-to-list 'company-backends '(company-math-symbols-unicode company-math-symbols-latex
                                                                company-latex-commands))
  (setq company-math-allow-latex-symbols-in-faces t))

(use-package company-reftex
  :after company
  :config
  (add-to-list 'company-backends 'company-reftex-citations))

(use-package company-auctex
  :after company
  :config
  (company-auctex-init))

(use-package company-bibtex
  :after company
  (add-to-list 'company-backends 'company-bibtex))

TeXcount

Word counts in latex. Uses a Perl script.

(defun get-texcount-latest()
  (if (not(file-directory-p "~/.texcount"))
      (make-directory "~/.texcount"))
  (url-copy-file "https://app.uio.no/ifi/texcount/download.php?file=texcount_3_2_0_41.zip" "~/.texcount/texcount.zip" 1)
  (shell-command "unzip -o ~/.texcount/texcount.zip -d ~/.texcount")
  (add-to-list 'exec-path "~/.texcount/texcount.pl"))

(if (not(or (file-exists-p "~/.texcount/texcount.pl") (file-exists-p "/usr/bin/texcount")))
    (get-texcount-latest))

(defun texcount ()
  (interactive)
  (let*
      ( (this-file (buffer-file-name))
        (enc-str (symbol-name buffer-file-coding-system))
        (enc-opt
         (cond
          ((string-match "utf-8" enc-str) "-utf8")
          ((string-match "latin" enc-str) "-latin1")
          ("-encoding=guess")
          ) )
        (word-count
         (with-output-to-string
           (with-current-buffer standard-output
             (call-process "texcount" nil t nil "-0" enc-opt this-file)
             ) ) ) )
    (message word-count)
    ) )
(add-hook 'LaTeX-mode-hook (lambda () (define-key LaTeX-mode-map (kbd "C-c c") 'texcount)))
(add-hook 'latex-mode-hook (lambda () (define-key latex-mode-map (kbd "C-c c") 'texcount)))

PlantUML

Sets the PlantUML path for the mode to generate models.

(use-package plantuml-mode
  :init
  (cond ((eq system-type 'windows-nt)
         (when (file-exists-p "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar")
           (setq plantuml-jar-path "c:/ProgramData/chocolatey/lib/plantuml/tools/plantuml.jar")
           (setq plantuml-default-exec-mode 'jar)))
        ((eq system-type 'gnu/linux)
         (when (file-exists-p "/usr/share/java/plantuml/plantuml.jar")
           (setq plantuml-jar-path "/usr/share/java/plantuml/plantuml.jar")
           (setq plantuml-default-exec-mode 'jar)))))

Verilog

Get latest version

Use latest version from repositories.

(use-package verilog-mode
  :pin gnu
  :config
  (autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
  (add-to-list 'auto-mode-alist '("\\.[ds]?va?h?\\'" . verilog-mode))
  (setq-default verilog-align-ifelse t
                verilog-auto-delete-trailing-whitespace t
                verilog-auto-inst-param-value t
                verilog-auto-lineup 'all
                verilog-auto-newline nil
                verilog-auto-save-policy nil
                verilog-auto-template-warn-unused t
                verilog-auto-endcomments nil
                verilog-highlight-grouping-keywords t
                verilog-highlight-modules t
                verilog-tab-to-comment t
                verilog-indent-begin-after-if nil
                verilog-indent-lists nil
                verilog-case-indent 4
                verilog-cexp-indent 0
                verilog-indent-level 4
                verilog-indent-level-behavioral 4
                verilog-indent-level-declaration 4
                verilog-indent-level-directive 4
                verilog-indent-level-module 4))

FPGA

(use-package fpga
  :init
  (setq fpga-feature-list '(xilinx)))

Run and test

Run the open buffer and display the output in a new buffer.

(defun run-verilator ()
  (interactive)
  (save-buffer)
  (if (not (eq (shell-command (concat "verilator --binary -j 0 " (buffer-file-name)) "*verilator output*") 0))
      (display-buffer "*verilator output*" 'display-buffer-reuse-window)
    (shell-command (concat (file-name-directory (buffer-file-name))
                           '"obj_dir/V"
                           (file-name-nondirectory (file-name-sans-extension (buffer-file-name))))
                   "*test output*")
    (display-buffer "*test output*" 'display-buffer-reuse-window))
  t)
(define-key verilog-mode-map (kbd "C-c c") 'run-verilator)

MATLAB

Mode for editing MATLAB m-files.

(use-package matlab
  :ensure matlab-mode
  :straight matlab-mode
  :config
  (autoload 'matlab-mode "matlab" "Matlab Editing Mode" t)
  (add-to-list
   'auto-mode-alist
   '("\\.m$" . matlab-mode))
  (setq matlab-indent-function t)
  (setq matlab-shell-command "matlab")
  (matlab-cedet-setup)
  (add-to-list 'company-backends 'company-matlab-shell))

Rust

Major mode

Get the major mode for rust files.

(use-package rust-mode
  :config
  ;; style guide suggests spaces not tabs
  (add-hook 'rust-mode-hook (lambda () (setq indent-tabs-mode nil)))
  (setq rust-format-on-save t))

(use-package toml-mode)

Cargo integration

Integrate Cargo, rust’s package manager.

(use-package cargo
  :hook
  (rust-mode . cargo-minor-mode))

Flycheck

Linting with flycheck.

(use-package flycheck-rust
  :config
  (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))

Go

Major mode

(use-package go-mode
  :config
  (add-hook 'before-save-hook #'gofmt-before-save))

Flycheck

(use-package flycheck-golangci-lint
  :config
  (add-hook 'flycheck-mode-hook #'flycheck-golangci-lint-setup))

Company

(use-package company-go)

Python

LSP server

Use pyright, idk why.

(use-package lsp-pyright
  :config
  (add-to-list 'lsp-disabled-clients 'pyls)
  (add-to-list 'lsp-enabled-clients 'jedi))

Org mode

Small tweaks

Small quality of life changes to org-mode.

(setq org-src-fontify-natively t
      org-src-tab-acts-natively t
      org-confirm-babel-evaluate nil
      org-export-with-smart-quotes t
      org-src-window-setup 'current-window)
(add-hook 'org-mode-hook 'org-indent-mode)
(diminish 'org-indent-mode)
(diminish 'visual-line-mode)

Spell checking for code and latex

(add-to-list 'ispell-skip-region-alist '("#\\+BEGIN_SRC" . "#\\+END_SRC"))
(add-to-list 'ispell-skip-region-alist '("\\$" . "\\$"))
(add-to-list 'ispell-skip-region-alist '("\\$\\$" . "\\$\\$"))

Line wrapping

Enable line wrapping for long lines.

(add-hook 'org-mode-hook
          '(lambda ()
             (visual-line-mode 1)))

Fancy org points

Use bullets of different colours and styles instead of the “\*\*\*” to denote indentation levels.

(use-package org-superstar
  :config
  (add-hook 'org-mode-hook (lambda () (org-superstar-mode 1))))

Org Babel

Allows the execution of code from within an org buffer. Code output can also be input to the buffer.

Languages

Add a bunch of languages to org babel supported languages

(org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t)
                                                         (C . t)
                                                         (python . t)
                                                         (latex . t)
                                                         (scheme . t)
                                                         (gnuplot . t)
                                                         (matlab . t)
                                                         (fortran . t)
                                                         (java . t)
                                                         (plantuml . t)))

PlantUML path

Org uses its own path for some reason.

(setq org-plantuml-jar-path plantuml-jar-path)

Async export

Allow the editing of files while execution of blocks is occurring. Needs :async tag in src header.

(use-package ob-async)

Latex preview fragments match colour

Make the previews match theme colour of Emacs. Gets very annoying very quickly without it.

(let ((dvipng--plist (alist-get 'dvipng org-preview-latex-process-alist)))
  (plist-put dvipng--plist :use-xcolor t)
  (plist-put dvipng--plist :image-converter '("dvipng -D %D -T tight -o %O %f")))

Org export additions

Pandoc

Call pandoc on org buffer from org export. Need to add #+OPTIONS: H:99 to enable large level header exports.

(when (executable-find "pandoc")
  (use-package ox-pandoc))