tkareine / emacs.d

My Emacs configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My Emacs setup

My public Emacs configuration, in order to synchronize them to computers I work with. The configuration for selected command line tools is in my dotfiles repository.

I have copied or adapted some contents from others. For small chunks of code, I have embedded the source URL in a comment inside the file. When copying has been extensive, I have retained the original copyright in the file. Thank you all!

Setup highlights

A screenshot, featuring syntax coloring of a shell script file (the left buffer), magit (the right buffer), and Ivy's counsel-projectile-rg (the bottom buffer), in the base16-gruvbox-dark-pale color theme of base16-theme:

Setup showcase

The font in use is Input (customization).

Show relevant information in mode-line

I've tuned the mode-line to show only information that I think is relevant. For instance, only a selection of enabled minor modes is shown. See etc/tk-looks.el, grep for mode-line-format.

JavaScript, TypeScript, and JSX source file editing

I have customized js-mode (for .js and .jsx sources) and typescript-mode (.ts, .tsx) major modes to work together with lsp-mode, Prettier (via prettier.el), company-mode, and Flycheck. For instance, when I save a .ts buffer, Flycheck validates the file and Prettier reformats it. See etc/tk-dev.el.

Small editing improvements

There are a bunch of small improvements to editing in etc/tk-editing.el, such as:

  • Key binding C-a (tk-editing/back-to-indentation-or-move-beginning-of-line) switches the point between the start of line content or the beginning of the line.
  • Key binding M-/ (tk-editing/comment-or-uncomment-region-or-line) comments or uncomments either the current line the point is on (if no region is active) or active region. And if the point was on the beginning of the line, automatically move point to the next line.
  • By default, highlight trailing whitespace with high-key color and show tabs with low-key color (easy to see, but not to disturb you). Toggle showing trailing whitespace with C-x W (tk-editing/toggle-show-trailing-whitespace).
  • Copy the path of the current buffer to the OS clipboard with C-c P (tk-editing/file-path-to-clipboard), helping you to pass the path to other programs quickly.
  • Use Smartparens globally, so that it's easy to copy strings within quotes, for example.
  • Save the history of recent files periodically, in order to avoid losing the information if Emacs crashes.

Installation

Installing Mitsuharu Yamamoto's Emacs Mac port, using Homebrew on macOS:

brew tap railwaycat/emacsmacport
brew install railwaycat/emacsmacport/emacs-mac --with-modern-icon

You'll need Node.js and npm for some of the 3rd party tools (see below). For managing Node.js versions, I recommend using chnode together with the latest LTS version of Node.js:

brew tap tkareine/chnode
brew install tkareine/chnode/chnode
brew install node@20
mkdir -p ~/.nodes
ln -s /usr/local/opt/node@20 ~/.nodes/node-20

Then, put the following into your shell's (Bash or Zsh) init script:

source chnode.sh
chnode node-20

3rd party tools in use

GNU Global

GNU Global is used by the ggtags minor mode to generate and find source code symbols. It's configured in etc/tk-dev.el. Ggtags mode gets enabled in selected major modes, such as sh-mode, scss-mode, and yaml-mode, automatically. It's especially useful for navigating vars in Ansible playbooks.

Configure Global to use Exuberant Ctags for finding symbol definitions and Pygments for symbol references.

Installation, with Homebrew on macOS:

brew install global

I use configuration files for Ctags and Global.

ripgrep (rg)

I use two frontends for ripgrep, the fast search tool:

  1. deadgrep for situations when I want to persist the search results (C-c a for deadgrep), and
  2. Ivy's counsel-projectile-rg (C-c s) when I want to discard search results right away.

Installation with Homebrew:

brew install ripgrep

jq

jq is used by Flycheck in json-mode to check JSON syntax. It's configured in etc/tk-dev.el.

Installation with Homebrew:

brew install jq

Marked

Marked generates the HTML output from Markdown sources, used by markdown-mode. It's configured in etc/tk-dev.el.

Installation with npm:

npm install -g marked

Prettier

Prettier is a popular code formatter, used by prettier.el to reformat the buffer upon save. It's configured in etc/tk-dev.el and enabled for js-mode, typescript-mode, html-mode, json-mode, and yaml-mode automatically.

Installation with npm:

npm install -g prettier

TypeScript

I use the tsserver CLI tool of of TypeScript and typescript-language-server as the server for lsp-mode, configured in etc/tk-dev.el.

Installation with npm:

npm install -g typescript typescript-language-server

About

My Emacs configuration

License:MIT License


Languages

Language:Emacs Lisp 96.4%Language:Makefile 3.6%