Skip to content

Latest commit

 

History

History
526 lines (392 loc) · 12.4 KB

config.org

File metadata and controls

526 lines (392 loc) · 12.4 KB

Setup for Mac

d12frosted/homebrew-emacs-plus#398 (comment) https://blog.lambda.cx/posts/using-emacsclient-on-macos/

User Info

(setq user-full-name "Kyle Bolton")
(setq user-mail-address "[email protected]")

Environment Setup

Disable Backups

(setq backup-directory-alist (quote ((".*" . "~/.emacs_temp/backups"))))
(setq auto-save-file-name-transforms `(("\\(?:[^/]*/\\)*\\(.*\\)"
,"~/.emacs_temp/autosaves" t)))

Packages

Configure package archives to pull from

(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/"))
(add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/"))
(package-initialize)

Configure use-package

I use use-package to install and configure my packages. My init.el includes the initial setup for package.el and ensures that use-package is installed, since I wanna do that right away.

This makes sure that use-package will install the package if it’s not already available. It also means that I should be able to open Emacs for the first time on a fresh Debian box and have my whole environment automatically installed. I’m not totally sure about that, but we’re gettin’ close.

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

Defer loading packages unless explicitly demanded

(setq use-package-always-defer t)

Always compile packages, and use the newest version available.

(use-package auto-compile
  :demand t
  :config (auto-compile-on-load-mode))
  (setq load-prefer-newer t)

Environment Setup

(use-package exec-path-from-shell
  :ensure t)
(when (daemonp)
  (exec-path-from-shell-initialize))

Modus Themes

(use-package modus-themes
  :ensure t
  :demand
  :init
  (require 'modus-themes)
  (setq modus-themes-to-toggle '(modus-operandi-tinted modus-vivendi-tinted))
  (setq modus-themes-common-palette-overrides
  '((bg-region bg-lavender)
    (fg-region unspecified)
    (bg-mode-line-active bg-blue-intense)
    (fg-mode-line-active fg-main)
    (border-mode-line-active blue-intense)))

  ;; Add all customizations prior to loading the theme
  ;;
  ;; NOTE: Explictly pass a value to the second arg for NO-CONFIRM so that
  ;; emacs loads the theme w/o prompting.
  (load-theme 'modus-vivendi-tinted t))

Magit

Magit is a text based UI for git.

(use-package magit
  :ensure t
  :bind ("C-c m" . magit-status))

Multiple Cursurs

This mode provides the ability to edit multiple lines within a buffer at the same time.

(use-package multiple-cursors
  :ensure t)

Flycheck

Syntax checking

(use-package flycheck
  :ensure t
  :init (global-flycheck-mode))

Go

(use-package go-mode
  :ensure t)

Fill structs

Assumes `go install github.com/davidrjenni/reftools/cmd/fillstruct@latest` has been run.

(use-package go-fill-struct
  :ensure t
  :bind (:map go-mode-map
		("C-c f s" . go-fill-struct)))

Yasnippet

Helpful autocomplete via shorthand. For example `err` will expand to default error handling block in Go. Yasnippet proper no longer maintains snippets for various languages, which is why we also include yassnippet-snippets which is the official collection of snippets for yasnippet.

(use-package yasnippet
  :ensure t)

(use-package yasnippet-snippets
  :ensure t
  :init (yas-global-mode))

LSP/Code

LSP Mode aims to provide IDE-like experience by providing optional integration with the most popular Emacs packages like company, flycheck and projectile.

(use-package lsp-mode
  :ensure t
  :config
(define-key lsp-mode-map (kbd "C-c l") lsp-command-map)
(setq lsp-completion-provider :none)
(setq lsp-file-watch-threshold 2000))

(use-package lsp-ui
  :ensure t)

Go

Assumes delve debugger has been installed for Go.

(use-package dap-mode
  :ensure t) ;; package contains the sub mode
(require 'dap-dlv-go)

Enable Go for LSP.

(add-hook 'go-mode-hook #'lsp)

Set tab-width to 4.

(add-hook 'go-mode-hook (lambda ()
    (setq tab-width 4)))

Set gofmt to goimports and set hook to run on file save.

(setq gofmt-command "goimports")
(add-hook 'before-save-hook 'gofmt-before-save)

Ruby

Outside of the config we need to install the language server we want to use, which is Ruby LSP. Easier to install it to the system ruby gems, instead of through a project Gemfile as this avoids needing to use bundler to find the executable.

Protobuf

(use-package protobuf-mode
  :ensure t)

Docker

(use-package dockerfile-mode
  :ensure t)

Copilot

copilot.el is not on a package manager and I don’t want to figure out how to use straight.el. Going with the manual install route for now.

This blog has some suggestions on restricting copilot in certain modes, but for now I’m just going to enable it globally and will disable copilot in specific modes if it becomes a problem.

Clone the repository via `git clone https://github.com/zerolfx/copilot.el.git`

Install dependencies

(use-package dash
  :ensure t)
(use-package s
  :ensure t)
(use-package editorconfig
  :ensure t)

Load the library

(load-file "/Users/kyle/Developer/copilot.el/copilot.el")
(require 'copilot)
(add-hook 'prog-mode-hook 'copilot-mode)
(define-key copilot-completion-map (kbd "<tab>") 'copilot-accept-completion)

Git Link

Open Github from a point in a local git file

(use-package git-link
  :ensure t
  :bind (("C-c g l" . git-link)))

Projectile

Project navigation and management library.

(use-package projectile
  :ensure t
  :init
  (projectile-mode)
  (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map))

Marginalia

Annotations in mini-buffer completion view.

(use-package marginalia
  :ensure t
  :custom
  (marginalia-align 'right)
  :init
  (marginalia-mode))

Vertico

Minibuffer completions in vertical format.

(use-package vertico
  :ensure t
  :init (vertico-mode))

Configure directory extension. These settings make vertico interaction align with my previous workflow that used ido-mode.

  • vertico-directory-enter will populate that document selection (similar to the default TAB functionality) w/o actually opening the directory
  • vertico-directory-delete-word will remove the leaf directory node up to the /
(use-package vertico-directory
  :after vertico
  :ensure nil
  ;; More convenient directory navigation commands
  :bind (:map vertico-map
              ("RET" . vertico-directory-enter)
              ("<backspace>" . vertico-directory-delete-word)))

Orderless

Completion styles.

(use-package orderless
  :ensure t
  :init (setq completion-styles '(orderless flex)))

Corfu

Enhanced completion at point.

(use-package corfu
  :custom
  (corfu-auto t)          ;; Enable auto completion
  ;; (corfu-separator ?_) ;; Set to orderless separator, if not using space
  (corfu-auto-prefix 2)
  :bind
  ;; Another key binding can be used, such as S-SPC.
  ;; (:map corfu-map ("M-SPC" . corfu-insert-separator))
  :init (global-corfu-mode))

Org

Custom hook code to be called by org mode.

(defun kb/org-mode-setup ()
  (auto-fill-mode)
  (visual-line-mode))

Install org mode and call our hook above. Additionally change the default rollup symbols of “…” to a carrot to make things a be cleaner.

(use-package org
  :ensure t
  :config
  (setq org-ellipsis "")
  :hook (org-mode . kb/org-mode-setup))

Show org-mode bullets as UTF-8 characters.

(use-package org-bullets
  :ensure t
  :after org
  :hook (org-mode . org-bullets-mode))

Replace list hyphen with dot in org-mode

(font-lock-add-keywords 'org-mode
                        '(("^ *\\([-]\\) "
                           (0 (prog1 ()(compose-region(match-beginning 1) (match-end 1) ""))))))

Custom hook code to be called by visual fill column.

(defun kb/org-mode-visual-fill ()
  (setq visual-fill-column-width 100
        visual-fill-column-center-text t)
  (visual-fill-column-mode 1))

Install visual-fill-column and call our hook above. This package allows us to specific when to wrap lines instead of the emacs default of wrapping at the window edge.

(use-package visual-fill-column
  :ensure t
  :hook (org-mode . kb/org-mode-visual-fill))

Keybindings

Resize Windows

(global-set-key (kbd "C-c <left>") 'shrink-window-horizontally)
(global-set-key (kbd "C-c <right>") 'enlarge-window-horizontally)
(global-set-key (kbd "C-c <down>") 'shrink-window)
(global-set-key (kbd "C-c <up>") 'enlarge-window)

Comment Region

(global-set-key (kbd "C-c / ") 'comment-or-uncomment-region)

Recursive Grep

(global-set-key (kbd "C-c r g") 'rgrep)

Org finder

Open a file within the folder org files are kept in.

(defun my-org-finder ()
  (interactive)
  (ido-find-file-in-dir "~/Documents/org/"))
(global-set-key (kbd "C-c o") 'my-org-finder)

Preferences

Emacs Chrome

Disable the tool bar that lives in the chrome title bar area

(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))

Yes/No

Shorten confirmation prompt to be y/n keys.

(defalias 'yes-or-no-p 'y-or-n-p)

Buffers

Disable scroll bars on buffers

(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))

Shift + arrow key to jump between visible buffers.

(windmove-default-keybindings)

Set iBuffer as the default.

(defalias 'list-buffers 'ibuffer)

Show dot-files in nav

(setq nav-hidden t)

Trim trailing whitespace when writing a file.

(add-hook 'write-file-functions 'delete-trailing-whitespace)

Always show column number in mode line

(column-number-mode 1)

Enable save place mode, which will put the cursor at the last location of cursor in file

(save-place-mode 1)

Revert buffers when the underlying file has changed

(global-auto-revert-mode 1)

Enable recentf mode to recall recently opened files

;; TODO set a keybinding for recentf-open-file
(recentf-mode 1)

Fonts

;; Set reusable font name variables
(defvar kb/fixed-width-font "JetBrains Mono"
  "The font to use for monospaced (fixed width) text.")

(defvar kb/variable-width-font "Iosevka Aile"
  "The font to use for variable-pitch (document) text.")

;; NOTE: These settings might not be ideal for your machine, tweak them as needed!
 (set-face-attribute 'default nil :font kb/fixed-width-font :weight 'light :height 150)
 (set-face-attribute 'fixed-pitch nil :font kb/fixed-width-font :weight 'light :height 160)
 (set-face-attribute 'variable-pitch nil :font kb/variable-width-font :weight 'light :height 1.3)