dotfiles/emacs/.emacs.d/config.org

5.9 KiB

Packet

  (require 'package)
  (setq package-archives '(("melpa" . "https://melpa.org/packages/")
                           ("gnu" . "https://elpa.gnu.org/packages/")))
  (package-initialize)
  (package-refresh-contents)

Use Package

  (unless (package-installed-p 'use-package)
    (package-refresh-contents)
    (package-install 'use-package))

  (require 'use-package)
  (setq use-package-always-ensure t)

Plugins

Quick online installs

  (use-package no-littering)
  (use-package org-bullets)
  (use-package rainbow-delimiters)
  (use-package flycheck :ensure)
  (use-package solidity-mode)
  (use-package undo-tree)

Evil

  (use-package evil
    :init
    (setq evil-want-keybinding nil)
    :config
    (evil-mode 1)
    (setq evil-search-module 'evil-search))

  (use-package evil-collection
    :config
    (evil-collection-init))

projectile

  (use-package projectile
    :ensure t
    :init
    (projectile-mode +1)
    :bind (:map projectile-mode-map
                ("s-p" . projectile-command-map)
                ("C-c p" . projectile-command-map)))

ledger-mode

  (use-package ledger-mode
    :mode ("\\.ledger\\'")
    :config
    (autoload 'ledger-mode "ledger-mode" "A major mode for Ledger" t)
    (add-to-list 'load-path
                 (expand-file-name "~/Documents/paisa/"))
    (add-to-list 'auto-mode-alist '("\\.ledger$" . ledger-mode)))

Global

emacs-one-themes

  (use-package one-themes
    :init
    (load-theme 'one-dark t))

Menubar

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

Symlinks

  (setq vc-follow-symlinks t)

spaces>tabs

  (setq-default indent-tabs-mode nil)

lsp inlay hints globally

(setq-local lsp-inlay-hint-enable t)

Org-mode

hook

  (add-hook 'org-mode-hook 
            (lambda () 
              (org-bullets-mode 1)
              (setq org-pretty-entities f)
              (setq org-src-fontify-natively 1)))

Rust

Rustic

  (use-package rustic
    :ensure
    :bind (:map rustic-mode-map
                ("M-j" . lsp-ui-imenu)
                ("M-?" . lsp-find-references)
                ("C-c C-c l" . flycheck-list-errors)
                ("C-c C-c a" . lsp-execute-code-action)
                ("C-c C-c r" . lsp-rename)
                ("C-c C-c q" . lsp-workspace-restart)
                ("C-c C-c Q" . lsp-workspace-shutdown)
                ("C-c C-c s" . lsp-rust-analyzer-status))
    :config
    ;; uncomment for less flashiness
    ;; (setq lsp-eldoc-hook nil)
    ;; (setq lsp-enable-symbol-highlighting nil)
    ;; (setq lsp-signature-auto-activate nil)

    ;; comment to disable rustfmt on save
    (setq rustic-format-on-save t)
    (add-hook 'rustic-mode-hook 'rk/rustic-mode-hook))

  (defun rk/rustic-mode-hook ()
    ;; so that run C-c C-c C-r works without having to confirm, but don't try to
    ;; save rust buffers that are not file visiting. Once
    ;; https://github.com/brotzeit/rustic/issues/253 has been resolved this should
    ;; no longer be necessary.
    (when buffer-file-name
      (setq-local buffer-save-without-query t))
    (add-hook 'before-save-hook 'lsp-format-buffer nil t))

LSP

  (use-package lsp-mode
    :ensure
    :commands lsp
    :custom
    ;; what to use when checking on-save. "check" is default, I prefer clippy
    (lsp-rust-analyzer-cargo-watch-command "clippy")
    (lsp-eldoc-render-all t)
    (lsp-idle-delay 0.6)
    ;; enable / disable the hints as you prefer:
    (lsp-inlay-hint-enable t)
    ;; These are optional configurations. See https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/#lsp-rust-analyzer-display-chaining-hints for a full list
    (lsp-rust-analyzer-display-lifetime-elision-hints-enable "skip_trivial")
    (lsp-rust-analyzer-display-chaining-hints t)
    (lsp-rust-analyzer-display-lifetime-elision-hints-use-parameter-names nil)
    (lsp-rust-analyzer-display-closure-return-type-hints t)
    (lsp-rust-analyzer-display-parameter-hints nil)
    (lsp-rust-analyzer-display-reborrow-hints nil)
    :config
    (add-hook 'lsp-mode-hook 'lsp-ui-mode))

  (use-package lsp-ui
    :ensure
    :commands lsp-ui-mode
    :custom
    (lsp-ui-peek-always-show t)
    (lsp-ui-sideline-show-hover t)
    (lsp-ui-doc-enable nil))

company

  (use-package company
    :ensure
    :custom
    (company-idle-delay 0.5) ;; how long to wait until popup
    ;; (company-begin-commands nil) ;; uncomment to disable popup
    :bind
    (:map company-active-map
          ("C-n". company-select-next)
          ("C-p". company-select-previous)
          ("M-<". company-select-first)
          ("M->". company-select-last)
          ("<tab>". tab-indent-or-complete)
          ("TAB". tab-indent-or-complete)))

  (use-package yasnippet
    :ensure
    :config
    (yas-reload-all)
    (add-hook 'prog-mode-hook 'yas-minor-mode)
    (add-hook 'text-mode-hook 'yas-minor-mode))
  (defun company-yasnippet-or-completion ()
    (interactive)
    (or (do-yas-expand)
        (company-complete-common)))

  (defun check-expansion ()
    (save-excursion
      (if (looking-at "\\_>") t
        (backward-char 1)
        (if (looking-at "\\.") t
          (backward-char 1)
          (if (looking-at "::") t nil)))))

  (defun do-yas-expand ()
    (let ((yas/fallback-behavior 'return-nil))
      (yas/expand)))

  (defun tab-indent-or-complete ()
    (interactive)
    (if (minibufferp)
        (minibuffer-complete)
      (if (or (not yas/minor-mode)
              (null (do-yas-expand)))
          (if (check-expansion)
              (company-complete-common)
            (indent-for-tab-command)))))