Skip to content

Latest commit

 

History

History
381 lines (334 loc) · 12.4 KB

basemacs-modules.org

File metadata and controls

381 lines (334 loc) · 12.4 KB

basemacs modules

About

This is a set of modules for basemacs. As with the rest of basemacs, the modules are only a starting point, these even moreso. They can be used as is, but they are intended to be examples of some of the cool packages that Emacs has to offer.

They are slightly more opinionated than the initial configuration, but are simple and easy to modify.

UI

;;; basemacs-ui.el --- -*- lexical-binding: t -*-

The UI module contains some things that make Emacs look nicer.

rainbow-delimiters

rainbow-delimiters is a “rainbow parentheses”-like mode which highlights delimiters such as parentheses, brackets or braces according to their depth. Each successive level is highlighted in a different color. This makes it easy to spot matching delimiters, orient yourself in the code, and tell which statements are at a given depth.

Turn this on only for programming modes.

(use-package rainbow-delimiters
  :straight t
  :ghook 'prog-mode-hook)

variable-pitch

variable-pitch-mode allows us to have multiple fonts in a single buffer. This is useful for org-mode which can have prose, code, and other things, in the same file.

Turn variable-pitch-mode on for org-mode.

(use-package face-remap
  :straight nil
  :ghook
  ('org-mode-hook #'variable-pitch-mode))

font

Now we set the main font to use in all buffers, and the proportional and mono fonts in variable-pitch-mode.

(use-package faces
  :straight nil
  :config
  ;; Main typeface
  (set-face-attribute 'default nil :family "DejaVu Sans Mono" :height 110)
  ;; Proportionately spaced typeface
  (set-face-attribute 'variable-pitch nil :family "DefaVu Serif" :height 1.0)
  ;; Monospaced typeface
  (set-face-attribute 'fixed-pitch nil :family "DejaVu Sans Mono" :height 1.0))

The :height value for the default face is the font size multiplied by 10, e.g. 11 x 10 = 110. The :height values for the variable-pitch and fixed-pitch faces are their sizes relative to the default face. This is because they use a floating point number. An integer may be used here, but then fonts will not scale gracefully.

modus-themes

These light and dark themes are WCAG compliant, have support for variable-pitch-mode in org-mode, and are highly customizable.

Light theme

(use-package modus-themes
  :straight t
  :init
  (setq modus-themes-italic-constructs t
        modus-themes-bold-constructs t
        modus-themes-region '(bg-only no-extend))
  (modus-themes-load-themes)
  :config
  (modus-themes-load-operandi))

EOF

(provide 'basemacs-ui)
;;; basemacs-ui.el ends here

Narrowing

One of the biggest changes that we can make to the usability of Emacs are these “narrowing” or “completion” frameworks. For example, using M-x is rather unhelpful by default as you have to know what the command is or press <TAB> for options. These packages make things a bit easier because they show a list of commands to choose from, as you type the choices in the list will narrow down. This is useful for lots of things in Emacs, like finding files, switching buffers, using the help, and more.

There are 4 options to choose from:

  1. ido - built in, with a few extra packages it is pretty nice
  2. helm - the most features, been around for the longest (after ido), most different from others
  3. ivy - uses minibuffer (like ido does), includes swiper as a replacement for isearch
  4. selectrum - similar to ivy, newer, simpler code, includes ctrlf as a replacement for isearch

NOTE Only one of these modules should be used at a time - all of these modules all change M-x, and basemacs-ivy and basemacs-selectrum change C-s. The packages themselves can all be installed at once without issue.

basemacs-ido

The built-in ido-mode is pretty good with some good default settings and extra packages.

;;; basemacs-ido.el --- -*- lexical-binding: t -*-
(use-package ido
  :straight nil
  :custom
  (ido-enable-flex-matching t)
  (ido-everywhere t)
  :config
  (ido-mode +1))
(use-package ido-vertical-mode
  :straight t
  :custom
  (ido-vertical-define-keys 'C-n-and-C-p-only)
  :config
  (ido-vertical-mode +1))
(use-package ido-completing-read+
  :straight t
  :config
  (ido-ubiquitous-mode +1))
(use-package amx
  :straight t
  :config
  (amx-mode +1))
(provide 'basemacs-ido)
;;; basemacs-ido.el ends here

basemacs-helm

Helm is an Emacs framework for incremental completions and narrowing selections.

;;; basemacs-helm.el --- -*- lexical-binding: t -*-

helm is the most feature packed out of all the other options here. It is also the most different as it does not use the minibuffer, rather it opens up its own window.

(use-package helm
  :straight t
  :demand t
  :ghook
  'after-init-hook
  :general
  ("M-x" 'helm-M-x)
  ("C-x r b" 'helm-filtered-bookmarks)
  ("C-x C-f" 'helm-find-files))

(provide 'basemacs-helm)
;;; basemacs-helm.el ends here

basemacs-ivy

Ivy is a generic completion mechanism for Emacs

;;; basemacs-ivy.el --- -*- lexical-binding: t -*-
(use-package ivy
  :straight t
  :demand t
  :ghook
  'after-init-hook
  :general
  ("<f6>" 'ivy-resume)
  :custom
  (ivy-use-virtual-buffers t)
  (enable-recursive-minibuffers t)
  (ivy-count-format "(%d/%d) ")
  (ivy-height 20))

Counsel, a collection of Ivy-enhanced versions of common Emacs commands.

(use-package counsel
  :straight t
  :after ivy
  :demand t
  :general
  ("M-x" 'counsel-M-x)
  ("C-x C-f" 'counsel-find-file)
  ("<f1> f" 'counsel-describe-function)
  ("<f1> v" 'counsel-describe-variable)
  ("<f1> l" 'counsel-find-library)
  ("<f2> i" 'counsel-info-lookup-symbol)
  ("<f2> u" 'counsel-unicode-char)
  ("C-c g" 'counsel-git)
  ("C-c j" 'counsel-git-grep)
  ("C-c k" 'counsel-rg)
  ("C-x l" 'counsel-locate)
  ("C-S-r" 'counsel-expression-history)
  :config
  ;; use ripgrep for counsel-git-grep
  (setq counsel-git-cmd "rg --files")
  (setq counsel-rg-base-command
        "rg -i -M 120 --no-heading --line-number --color never %s ."))
(use-package counsel-etags
  :straight t
  :after counsel)

Make ivy look a bit nicer

(use-package ivy-rich
  :straight t
  :after (ivy counsel)
  :config
  (ivy-rich-mode +1)
  (setcdr (assq t ivy-format-functions-alist) #'ivy-format-function-line))

Replace keybindings for emacs search with swiper.

(use-package swiper
  :straight t
  :after ivy
  :general
  ("C-s" 'swiper))
(provide 'basemacs-ivy)
;;; basemacs-ivy.el ends here

basemacs-selectrum

selectrum is the newest out of all the options, it is similar to ivy but with simpler code, and it was created by the author of straight.el.

;;; basemacs-selectrum.el --- -*- lexical-binding: t -*-
(use-package selectrum
  :straight t
  :demand t
  :ghook
  'after-init-hook)

(use-package prescient
  :straight t
  :after selectrum
  :config
  (prescient-persist-mode +1))

(use-package selectrum-prescient
  :straight t
  :after (selectrum prescient)
  :config
  (selectrum-prescient-mode +1))

(use-package ctrlf
  :straight t
  :config
  (ctrlf-mode +1))

(provide 'basemacs-selectrum)
;;; basemacs-selectrum.el ends here

Vim Emulation

Go to the dark side with evil and get near perfect vim emulation.

;;; basemacs-evil.el --- -*- lexical-binding: t -*-

Set the leader keys to SPC, e.g. Doom/Spacemacs.

(use-package emacs
  :straight (:type built-in)
  :custom
  (basemacs-leader "SPC")
  (basemacs-local-leader "SPC m"))

Evil mode is vim in emacs! Using undo-fu here instead of undo-tree as I have found that undo-fu seems to be quicker and less buggy than undo-tree.

(use-package evil
  :straight t
  :init
  (use-package undo-fu :straight t)
  :custom
  (evil-want-keybinding nil)  ;; evil-collection assumes this
  (evil-undo-system 'undo-fu)
  :config
  (evil-mode +1))

Use evil bindings in various modes.

(use-package evil-collection
  :straight t
  :after evil
  :config
  (evil-collection-init))

surround.vim emulation.

(use-package evil-surround
  :straight t
  :after evil
  :config
  (global-evil-surround-mode 1))

vim-commentary emulation.

(use-package evil-commentary
  :straight t
  :config
  (evil-commentary-mode 1))
(provide 'basemacs-evil)
;;; basemacs-evil.el ends here

Programming

Programming is probably the main reason most people use Emacs, so there are lots of settings and packages for it.

General Code

Two of the most important features for me while coding are autocompletion and error checking/linting. Here is a simple setup that provides that, along with a collection of code snippets.

;;; basemacs-code.el --- -*- lexical-binding: t -*-

Company is a text completion framework for Emacs.

Company is essentially the standard package that is used for Emacs code completion. It works decently out of the box, has backends for nearly all languages, and is integrated with LSP.

(use-package company
  :straight t
  :config
  (global-company-mode +1))

Flycheck is a modern on-the-fly syntax checking extension for GNU Emacs

Flycheck works out of the box for just about everything and is integrated with lots of other packages.

(use-package flycheck
  :straight t
  :config
  (global-flycheck-mode +1))

YA Snippet is a template system for Emacs.

Set the snippets directory to be in this folder, automatically create it if it does not exist.

(use-package yasnippet
  :straight t
  :preface
  (defconst basemacs-snippets-dir (expand-file-name "snippets/" user-emacs-directory))
  (make-directory basemacs-snippets-dir :parents)
  :custom
  (yas-snippet-dirs (list basemacs-snippets-dir))
  :config
  (yas-global-mode +1))

Install the official snippet collection, this contains snippets for several programming languages.

(use-package yasnippet-snippets
  :straight t
  :after yasnippet)
(provide 'basemacs-code)
;;; basemacs-code.el ends here