/literate-rust-emacs

Initial repository for my literate rust-emacs configuration.

Primary LanguageEmacs Lisp

My literate Rust-Emacs configuration

Introduction

This is my personal literate emacs configuration which aims to become a dank Rust IDE configuration. This is my first attempt at creating an Emacs configuration form scratch. It aims to use the Emacs keybinding style with keymaps designed for aesthetics.

Core

Bootstrap straight.el

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

use-package.el

Use use-package for aesthetics, ensure that packages are installed automatically if not present in the system

(straight-use-package '(use-package
                         :ensure t))
(require 'use-package-ensure)
(setq straight-use-package-by-default t
      use-package-always-ensure t)

doom-one.el

(use-package doom-themes
  :config
  (load-theme 'doom-one t))

doom-modeline.el

(use-package doom-modeline
  :hook (after-init . doom-modeline-mode)
  :config
  (display-battery-mode 1))

dashboard.el

To be presented with basic information when starting Emacs.

(use-package dashboard
  :config
  (setq dashboard-banner-logo-title "Welcome to Rust Emacs"
        dashboard-items '((recents . 5)
                          (projects . 5)
                          (bookmarks . 5)
                          (agenda . 5)
                          (registers . 5))
        dashboard-footer-message '("Happy hacking!")
        dashboard-set-heading-icons t
        dashboard-set-file-icons t
        dashboard-center-content t)
  (dashboard-setup-startup-hook))

projectile.el

Project management

(use-package projectile
  :config
  (setq projectile-mode-line-prefix " Proj "
        projectile-project-search-path '("/storage/src/unnsvc")
        projectile-globally-ignored-file-suffixes '(".log" ".gz" ".zip")
        projectile-enable-caching t
        projectile-completion-system 'default
        projectile-switch-project-action 'projectile-dired)
  (projectile-mode +1))

orderless.el

Enable fuzzy matching and searching of terms in any order as you type them

(use-package orderless)

vertico.el

(use-package vertico
  :init
  (vertico-mode)
  :custom
  (vertico-reverse-list nil)
  (vertico-cycle t)
  (vertico-count 100)
  (vertico-resize nil)
  (vertico-history nil))

linum-relative.el

Relative line numbers don’t seem to work at present, fix.

(use-package display-line-numbers
  :straight nil
  :custom
  (display-line-numbers-type 'relative)
  (display-line-numbers 't)
  :init
  (display-line-numbers-mode)
  )

savehist.el

Enable persistent history?

(use-package savehist
  :straight nil
  :config
  ;;(setq savehist-additional-variables '(vertico-sort-function
  ;;                                      vertico-recency-type))
  (savehist-mode 1))

magit.el

(use-package magit)

Observability, Introspection, and Search

which-key.el

For observability into key combinations

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

consult.el

This is used for searching

(use-package consult
  :after projectile
  ;; :bind (("C-s" . consult-line)
  ;;        ("C-x b" . consult-buffer)
  ;;        ("M-y" . consult-yank-pop)
  ;;        :map vertico-map
  ;;        ("/" . consult-line))
  :custom
  ;;(consult-preview-key nil)
  (consult-project-root-function #'projectile-project-root)
  (consult-find-command 'rg)
  (consult-line-point-placement #'word-begin)
  ;; Integrate with vertico
  (consult-project-root-function #'projectile-project-root))
  ;; Determine what these are for and if they will be needed
  ;;(xref-show-xrefs-function #'consul-xref)
  ;;(xref-show-definitions-function #'consul-xref)
  ;;(xref-prompt-for-identifier
  ;; '(not xref-find-definitions xref-find-definitions-other-window xref-find-references)))
;; Provides consult-projectile-find-file
(use-package consult-projectile
  :after consult)

helpful.el

Observability into variables, functions, and keys

(use-package helpful
  :bind (("C-h f" . #'helpful-callable)
         ("C-h v" . #'helpful-variable)
         ("C-h k" . #'helpful-key)))

Language

LSP

lsp-mode.el

(use-package lsp-mode
  :hook (rust-mode . lsp)
  :commands lsp
  :custom
  (lsp-rust-server 'rust-analyzer))

lsp-ui.el

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

consult-lsp.el

(use-package consult-lsp
  :commands consult-lsp-symbols)

Rust

rust-mode.el

(use-package rust-mode
  :hook (rust-mode . (lambda ()
                       (setq-local lsp-ui-doc-enable t
                                   lsp-ui-doc-position 'at-point
                                   lsp-ui-doc-header t
                                   lsp-ui-doc-border (face-foreground 'default)
                                   lsp-ui-sideline-enable nil))))

Keymap

Configure C-k to be a prefix key

;; Create a new keymap
(use-package bind-key
  :after (simple magit)
  :config

  (defvar buffers-keymap (make-sparse-keymap))
  (unbind-key "C-b")
  (bind-key "C-b" buffers-keymap)

  (defvar search-keymap (make-sparse-keymap))
  (unbind-key "C-s")
  (bind-key "C-s" search-keymap)

  (defvar git-keymap (make-sparse-keymap))
  (unbind-key "C-g")
  (bind-key "C-g" git-keymap))

buffers-keymap

;; Group together keybindings for that keymap in a meta-package (virtual package)
(use-package meta-buffers-keymap
  :straight (:type built-in)
  :after bind-key
  :bind (:map buffers-keymap
              ("k" . kill-current-buffer)
              ("b" . consult-buffer)
              ("s" . consult-line)))

search-keymap

(use-package meta-search-keymap
  :straight (:type built-in)
  :after bind-key
  :bind (:map search-keymap
              ("s" . consult-find)
              ("R" . consult-recent-file)
              ("r" . consult-ripgrep)
              ("p" . consult-projectile-find-file)))

git-keymap

(use-package meta-git-keymap
  :straight (:type built-in)
  :after (bind-key magit)
  :bind (:map git-keymap
              ("g" . magit-status)))

Miscellaneous

Remove the menu bar from the top of emacs

(use-package menu-bar
  :straight (:type built-in)
  :config
  (menu-bar-mode -1))

Minibuffer to use orderless and vertico

Minibuffer is a built-in package so :straight nil otherwise it will try to pull minibuffer.el from repos.

(use-package minibuffer
  :straight (:type built-in)
  :after (orderless vertico)
  :custom
  (completion-styles '(orderless))
  (completion-category-defaults nil)
  (completion-category-overrides '((file (styles . (partial-completion))))))

org-make-toc.el

For a table of contents in the github README. Org mode is already loaded through (org-babble-load-file “README.org”) by init.el, this means that we need to use the provided version of org mode or there will be a version mismatch.

(use-package org
  :straight (:type built-in)
  :custom
  (org-startup-indented t))
(use-package org-make-toc
  :after org
  ;; Don't use straight, to use the built-in org mode otherwise straight will attempt to load a more recent org mode
  :hook (org-mode . #'org-mode-toc-mode))