Skip to content

Latest commit

 

History

History
939 lines (867 loc) · 44.2 KB

spacemacs.org

File metadata and controls

939 lines (867 loc) · 44.2 KB

spacemacs

This is my .spacemacs configuration.

This is a self-documenting dotfile file whereby the code blocks below comprise the actual dotfile configuration. This is also known as “Literate Programming”. This is done with GNU Emacs and org-mode. See Extracing Source Code org-mode docs for more on how this works.

My dotspacemacs

Usage

By setting the :HEADER-ARGS: to :tangle ~/.spacemacs, the code blocks are “tangled” (by calling org-babel-tangle) together and written to ~~/.spacemacs~.

After re-tangling, use SPC f e R to reload the config.

Opening Comment

;; -*- MODE: EMACS-LISP -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.

layers

There are many layers available. These are what I use along with some configuration. The code comments were generated by Spacemacs and I’m leaving them there for now.

(defun dotspacemacs/layers ()
  "Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
  (setq-default
   ;; Base distribution to use. This is a layer contained in the directory
   ;; `+distribution'. For now available distributions are `spacemacs-base'
   ;; or `spacemacs'. (default 'spacemacs)
   dotspacemacs-distribution 'spacemacs
   ;; Lazy installation of layers (i.e. layers are installed only when a file
   ;; with a supported type is opened). Possible values are `all', `unused'
   ;; and `nil'. `unused' will lazy install only unused layers (i.e. layers
   ;; not listed in variable `dotspacemacs-configuration-layers'), `all' will
   ;; lazy install any layer that support lazy installation even the layers
   ;; listed in `dotspacemacs-configuration-layers'. `nil' disable the lazy
   ;; installation feature and you have to explicitly list a layer in the
   ;; variable `dotspacemacs-configuration-layers' to install it.
   ;; (default 'unused)
   dotspacemacs-enable-lazy-installation 'unused
   ;; If non-nil then Spacemacs will ask for confirmation before installing
   ;; a layer lazily. (default t)
   dotspacemacs-ask-for-lazy-installation t
   ;; If non-nil layers with lazy install support are lazy installed.
   ;; List of additional paths where to look for configuration layers.
   ;; Paths must have a trailing slash (i.e. `~/.mycontribs/')
   dotspacemacs-configuration-layer-path '("~/spacemacs/private/layers/")
   ;; List of configuration layers to load.
   dotspacemacs-configuration-layers
   '(
     (auto-completion :variables
                      auto-completion-tab-key-behavior 'cycle
                      auto-completion-return-key-behavior 'complete
                      auto-completion-enable-snippets-in-popup t
                      auto-completion-enable-help-tooltip nil
                      auto-completion-use-company-box nil
                      auto-completion-enable-sort-by-usage nil)
     (c-c++ :variables
            c-c++-backend 'lsp-ccls
            c-c++-lsp-enable-semantic-highlight 'rainbow
            c-c++-dap-adapters '(dap-lldb dap-cpptools))
     colors
     csv
     (dap :variables
          dap-auto-configure-features '(expressions repl))
     dash
     docker
     (elixir :variables
             elixir-backend 'alchemist)
     emacs-lisp
     erlang
     git
     (groovy :variables
             groovy-backend 'company-groovy
             groovy-indent-offset 2)
     html
     (javascript :variables
                 javascript-import-tool 'import-js
                 javascript-backend 'lsp
                 javascript-lsp-linter nil
                 node-add-modules-path t)
     lsp
     markdown
     (mermaid-layer :variables
                    mermaid-layer-cli-path "~/node_modules/.bin/mmdc")
(multiple-cursors :variables
                  multiple-cursors-backend 'evil-mc)

See evil-mc See also this tutorial post

Most of the time I would use iedit, but it’s occasionally useful to be able to create multiple cursors. With evil-mc, I g r I creates cursors to visually selected regions. g r q to remove them.

nginx
(openai-layer :variables
              openai-layer-codegpt-tunnel 'chat
              openai-layer-codegpt-model "gpt-3.5-turbo") ;; See https://github.com/apmiller108/openai-layer
osx
(org :variables
      org-enable-reveal-js-support t
      org-enable-roam-support t
      org-plantuml-jar-path (expand-file-name "~/plantuml.jar")
      org-ellipsis ""
      org-export-date-timestamp-format "Y-%m-%d %H:%M %p"
      org-agenda-files '("~/slip-box/personal/agenda")
      org-agenda-start-with-log-mode t
      org-log-done 'time
      org-log-into-drawer t
      org-image-actual-width nil)
pandoc

See pandoc layer for more. Basically, I have this so I can export pandoc program installed.

  (plantuml :variables
            plantuml-default-exec-mode 'jar)
  python
  (ranger :variables
          ranger-show-preview t)
  (ruby :variables
        ruby-version-manager 'rbenv
        ruby-test-runner 'rspec
        ruby-insert-encoding-magic-comment nil
        ruby-enable-ruby-on-rails-support t
        ruby-align-chained-calls t
        ruby-backend 'lsp)
  ruby-on-rails
  (shell :variables
          shell-default-shell 'vterm
          shell-default-height 30
          shell-default-position 'bottom)
  (spell-checking :variables
                  spell-checking-enable-by-default nil
                  ispell-program-name "aspell")
  sql
  syntax-checking
  (themes-megapack :packages
                    molokai-theme
                    jbeans-theme
                    naquadah-theme
                    seti-theme)
  (typescript :variables
              typescript-backend 'lsp)
  yaml
  (vue :variables
        vue-backend 'lsp
        node-add-modules-path t)
  )
;; List of additional packages that will be installed without being
;; wrapped in a layer. If you need some configuration for these
;; packages, then consider creating a layer. You can also put the
;; configuration in `dotspacemacs/user-config'.
dotspacemacs-additional-packages
'(
  editorconfig
  color-theme-sanityinc-tomorrow
  sqlite3
  )
;; A list of packages that cannot be updated.
dotspacemacs-frozen-packages '()
;; A list of packages that will not be installed and loaded.
dotspacemacs-excluded-packages '()
;; Defines the behaviour of Spacemacs when installing packages.
;; Possible values are `used-only', `used-but-keep-unused' and `all'.
;; `used-only' installs only explicitly used packages and uninstall any
;; unused packages as well as their unused dependencies.
;; `used-but-keep-unused' installs only the used packages but won't uninstall
;; them if they become unused. `all' installs *all* packages supported by
;; Spacemacs and never uninstall them. (default is `used-only')
dotspacemacs-install-packages 'used-only))

init

(defun dotspacemacs/init ()
  "Initialization function.
This function is called at the very startup of Spacemacs initialization
before layers configuration.
You should not put any user code in there besides modifying the variable
values."
  ;; This setq-default sexp is an exhaustive list of all the supported
  ;; spacemacs settings.
  (setq-default
   ;; If non nil ELPA repositories are contacted via HTTPS whenever it's
   ;; possible. Set it to nil if you have no way to use HTTPS in your
   ;; environment, otherwise it is strongly recommended to let it set to t.
   ;; This variable has no effect if Emacs is launched with the parameter
   ;; `--insecure' which forces the value of this variable to nil.
   ;; (default t)
   dotspacemacs-elpa-https t
   ;; Maximum allowed time in seconds to contact an ELPA repository.
   dotspacemacs-elpa-timeout 5
   ;; If non nil then spacemacs will check for updates at startup
   ;; when the current branch is not `develop'. Note that checking for
   ;; new versions works via git commands, thus it calls GitHub services
   ;; whenever you start Emacs. (default nil)
   dotspacemacs-check-for-update t
   ;; If non-nil, a form that evaluates to a package directory. For example, to
   ;; use different package directories for different Emacs versions, set this
   ;; to `emacs-version'.
   dotspacemacs-elpa-subdirectory nil
   ;; One of `vim', `emacs' or `hybrid'.
   ;; `hybrid' is like `vim' except that `insert state' is replaced by the
   ;; `hybrid state' with `emacs' key bindings. The value can also be a list
   ;; with `:variables' keyword (similar to layers). Check the editing styles
   ;; section of the documentation for details on available variables.
   ;; (default 'vim)
   dotspacemacs-editing-style 'vim
   ;; If non nil output loading progress in `*Messages*' buffer. (default nil)
   dotspacemacs-verbose-loading nil
   ;; Specify the startup banner. Default value is `official', it displays
   ;; the official spacemacs logo. An integer value is the index of text
   ;; banner, `random' chooses a random text banner in `core/banners'
   ;; directory. A string value must be a path to an image format supported
   ;; by your Emacs build.
   ;; If the value is nil then no banner is displayed. (default 'official)
   dotspacemacs-startup-banner 'official
   ;; List of items to show in startup buffer or an association list of
   ;; the form `(list-type . list-size)`. If nil then it is disabled.
   ;; Possible values for list-type are:
   ;; `recents' `bookmarks' `projects' `agenda' `todos'."
   ;; List sizes may be nil, in which case
   ;; `spacemacs-buffer-startup-lists-length' takes effect.
   dotspacemacs-startup-lists '((projects . 7)
                                (recents . 5))
   ;; True if the home buffer should respond to resize events.
   dotspacemacs-startup-buffer-responsive t
   ;; Default major mode of the scratch buffer (default `text-mode')
   dotspacemacs-scratch-mode 'text-mode
   ;; List of themes, the first of the list is loaded when spacemacs starts.
   ;; Press <SPC> T n to cycle to the next theme in the list (works great
   ;; with 2 themes variants, one dark and one light)
   dotspacemacs-themes '(spacemacs-dark)
   ;; If non nil the cursor color matches the state color in GUI Emacs.
   dotspacemacs-colorize-cursor-according-to-state t
   ;; Default font, or prioritized list of fonts. `powerline-scale' allows to
   ;; quickly tweak the mode-line size to make separators look not too crappy.
   dotspacemacs-default-font '(("Menlo"
                               :size 14
                               :weight normal
                               :width normal
                               :powerline-offset: 2
                               :powerline-scale 1.1)
                               ("Fira Code"
                                :size 14
                                :weight normal
                                :width normal
                                :powerline-offset: 2
                                :powerline-scale 1.1))
   ;; The leader key
   dotspacemacs-leader-key "SPC"
   ;; The key used for Emacs commands (M-x) (after pressing on the leader key).
   ;; (default "SPC")
   dotspacemacs-emacs-command-key "SPC"
   ;; The key used for Vim Ex commands (default ":")
   dotspacemacs-ex-command-key ":"
   ;; The leader key accessible in `emacs state' and `insert state'
   ;; (default "M-m")
   dotspacemacs-emacs-leader-key "M-m"
   ;; Major mode leader key is a shortcut key which is the equivalent of
   ;; pressing `<leader> m`. Set it to `nil` to disable it. (default ",")
   dotspacemacs-major-mode-leader-key ","
   ;; Major mode leader key accessible in `emacs state' and `insert state'.
   ;; (default "C-M-m")
   dotspacemacs-major-mode-emacs-leader-key "C-M-m"
   ;; These variables control whether separate commands are bound in the GUI to
   ;; the key pairs C-i, TAB and C-m, RET.
   ;; Setting it to a non-nil value, allows for separate commands under <C-i>
   ;; and TAB or <C-m> and RET.
   ;; In the terminal, these pairs are generally indistinguishable, so this only
   ;; works in the GUI. (default nil)
   dotspacemacs-distinguish-gui-tab nil
   ;; If non nil `Y' is remapped to `y$' in Evil states. (default nil)
   dotspacemacs-remap-Y-to-y$ nil
   ;; If non-nil, the shift mappings `<' and `>' retain visual state if used
   ;; there. (default t)
   dotspacemacs-retain-visual-state-on-shift t
   ;; If non-nil, J and K move lines up and down when in visual mode.
   ;; (default nil)
   dotspacemacs-visual-line-move-text nil
   ;; If non nil, inverse the meaning of `g' in `:substitute' Evil ex-command.
   ;; (default nil)
   dotspacemacs-ex-substitute-global nil
   ;; Name of the default layout (default "Default")
   dotspacemacs-default-layout-name "Default"
   ;; If non nil the default layout name is displayed in the mode-line.
   ;; (default nil)
   dotspacemacs-display-default-layout nil
   ;; If non nil then the last auto saved layouts are resume automatically upon
   ;; start. (default nil)
   dotspacemacs-auto-resume-layouts nil
   ;; Size (in MB) above which spacemacs will prompt to open the large file
   ;; literally to avoid performance issues. Opening a file literally means that
   ;; no major mode or minor modes are active. (default is 1)
   dotspacemacs-large-file-size 1
   ;; Location where to auto-save files. Possible values are `original' to
   ;; auto-save the file in-place, `cache' to auto-save the file to another
   ;; file stored in the cache directory and `nil' to disable auto-saving.
   ;; (default 'cache)
   dotspacemacs-auto-save-file-location 'cache
   ;; Maximum number of rollback slots to keep in the cache. (default 5)
   dotspacemacs-max-rollback-slots 5
   ;; If non nil, `helm' will try to minimize the space it uses. (default nil)
   dotspacemacs-helm-resize nil
   ;; if non nil, the helm header is hidden when there is only one source.
   ;; (default nil)
   dotspacemacs-helm-no-header nil
   ;; define the position to display `helm', options are `bottom', `top',
   ;; `left', or `right'. (default 'bottom)
   dotspacemacs-helm-position 'bottom
   ;; Controls fuzzy matching in helm. If set to `always', force fuzzy matching
   ;; in all non-asynchronous sources. If set to `source', preserve individual
   ;; source settings. Else, disable fuzzy matching in all sources.
   ;; (default 'always)
   dotspacemacs-helm-use-fuzzy 'always
   ;; If non nil the paste micro-state is enabled. When enabled pressing `p`
   ;; several times cycle between the kill ring content. (default nil)
   dotspacemacs-enable-paste-transient-state nil
   ;; Which-key delay in seconds. The which-key buffer is the popup listing
   ;; the commands bound to the current keystroke sequence. (default 0.4)
   dotspacemacs-which-key-delay 0.4
   ;; Which-key frame position. Possible values are `right', `bottom' and
   ;; `right-then-bottom'. right-then-bottom tries to display the frame to the
   ;; right; if there is insufficient space it displays it at the bottom.
   ;; (default 'bottom)
   dotspacemacs-which-key-position 'bottom
   ;; If non nil a progress bar is displayed when spacemacs is loading. This
   ;; may increase the boot time on some systems and emacs builds, set it to
   ;; nil to boost the loading time. (default t)
   dotspacemacs-loading-progress-bar t
   ;; If non nil the frame is fullscreen when Emacs starts up. (default nil)
   ;; (Emacs 24.4+ only)
   dotspacemacs-fullscreen-at-startup nil
   ;; If non nil `spacemacs/toggle-fullscreen' will not use native fullscreen.
   ;; Use to disable fullscreen animations in OSX. (default nil)
   dotspacemacs-fullscreen-use-non-native nil
   ;; If non nil the frame is maximized when Emacs starts up.
   ;; Takes effect only if `dotspacemacs-fullscreen-at-startup' is nil.
   ;; (default nil) (Emacs 24.4+ only)
   dotspacemacs-maximized-at-startup t
   ;; A value from the range (0..100), in increasing opacity, which describes
   ;; the transparency level of a frame when it's active or selected.
   ;; Transparency can be toggled through `toggle-transparency'. (default 90)
   dotspacemacs-active-transparency 90
   ;; A value from the range (0..100), in increasing opacity, which describes
   ;; the transparency level of a frame when it's inactive or deselected.
   ;; Transparency can be toggled through `toggle-transparency'. (default 90)
   dotspacemacs-inactive-transparency 90
   ;; If non nil show the titles of transient states. (default t)
   dotspacemacs-show-transient-state-title t
   ;; If non nil show the color guide hint for transient state keys. (default t)
   dotspacemacs-show-transient-state-color-guide t
   ;; If non nil unicode symbols are displayed in the mode line. (default t)
   dotspacemacs-mode-line-unicode-symbols t
   ;; If non nil smooth scrolling (native-scrolling) is enabled. Smooth
   ;; scrolling overrides the default behavior of Emacs which recenters point
   ;; when it reaches the top or bottom of the screen. (default t)
   dotspacemacs-smooth-scrolling t
   ;; If non nil line numbers are turned on in all `prog-mode' and `text-mode'
   ;; derivatives. If set to `relative', also turns on relative line numbers.
   ;; (default nil)
   dotspacemacs-line-numbers t
   ;; Code folding method. Possible values are `evil' and `origami'.
   ;; (default 'evil)
   dotspacemacs-folding-method 'origami
   ;; If non-nil smartparens-strict-mode will be enabled in programming modes.
   ;; (default nil)
   dotspacemacs-smartparens-strict-mode nil
   ;; If non-nil pressing the closing parenthesis `)' key in insert mode passes
   ;; over any automatically added closing parenthesis, bracket, quote, etc…
   ;; This can be temporary disabled by pressing `C-q' before `)'. (default nil)
   dotspacemacs-smart-closing-parenthesis nil
   ;; Select a scope to highlight delimiters. Possible values are `any',
   ;; `current', `all' or `nil'. Default is `all' (highlight any scope and
   ;; emphasis the current one). (default 'all)
   dotspacemacs-highlight-delimiters 'all
   ;; If non nil, advise quit functions to keep server open when quitting.
   ;; (default nil)
   dotspacemacs-persistent-server nil
   ;; List of search tool executable names. Spacemacs uses the first installed
   ;; tool of the list. Supported tools are `ag', `pt', `ack' and `grep'.
   ;; (default '("rg" "ag" "pt" "ack" "grep"))
   dotspacemacs-search-tools '("rg" "ag" "pt" "ack" "grep")
   ;; The default package repository used if no explicit repository has been
   ;; specified with an installed package.
   ;; Not used for now. (default nil)
   dotspacemacs-default-package-repository nil
   ;; Delete whitespace while saving buffer. Possible values are `all'
   ;; to aggressively delete empty line and long sequences of whitespace,
   ;; `trailing' to delete only the whitespace at end of lines, `changed'to
   ;; delete only whitespace for changed lines or `nil' to disable cleanup.
   ;; (default nil)
   dotspacemacs-whitespace-cleanup nil
   dotspacemacs-mode-line-theme 'spacemacs
   ))

user-init

(defun dotspacemacs/user-init ()
  "Initialization function for user code.
It is called immediately after `dotspacemacs/init', before layer configuration
executes.
 This function is mostly useful for variables that need to be set
before packages are loaded. If you are unsure, you should try in setting them in
`dotspacemacs/user-config' first."
  (setq ns-use-srgb-colorspace nil) ;; fixes the graphic anomaly in the tab bar
  (setq create-lockfiles nil) ;; Disable lockfiles (eg, `.#somefile.cr`)
  (setq helm-split-window-inside-p t) ;; Possible fix for Neotree window bug
  (setq-default flycheck-disabled-checkers '(scss)) ;; disabled checkers
  (setq org-roam-directory "~/slip-box") ;; sets org-roam dir
  (setq custom-file "~/spacemacs/.cache/.custom-settings") ;; place to store emacs custom settings https://github.com/syl20bnr/spacemacs/issues/7891
  (setq dotspacemacs-read-process-output-max (* 1024 1024 2)) ;; 2mb to help with handling LSP server communication
  (setq native-comp-async-report-warnings-errors nil) ;; For emacs28 with native comp so it doesn't spam warnings (can also be silent)
  (setq rbenv-installation-dir "/usr/local/") ;; rbenv location
  )

user-env

(defun dotspacemacs/user-env ()
    "Environment variables setup.
  This function defines the environment variables for your Emacs session. By
  default it calls `spacemacs/load-spacemacs-env' which loads the environment
  variables declared in `~/.spacemacs.env' or `~/.spacemacs.d/.spacemacs.env'.
  See the header of this file for more information."
    (spacemacs/load-spacemacs-env)
 )

user-config

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."

Variables

(setq css-indent-offset 2)
(setq json-encoding-default-indentation 2)
(setq javascript-indent-level 2)
(setq js2-mode-show-strict-warnings nil)
(setq js-indent-level 2)
(setq typescript-indent-level 2)
(setq web-mode-markup-indent-offset 2) ; web-mode: html tag in html file
(setq web-mode-css-indent-offset 2) ; web-mode: css in html file
(setq web-mode-code-indent-offset 2) ; web-mode: js code in html file
(setq web-mode-attr-indent-offset 2)
(setq sh-basic-offset 2)
(setq sh-indentation 2)

(require 'whitespace)
(setq-default whitespace-style '(face trailing))
(setq-default whitespace-line-column 80)
(setq whitespace-global-modes '(not web-mode))

(set-fontset-font t 'unicode "Apple Color Emoji" nil 'prepend)

(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
(setq mouse-wheel-progressive-speed t) ;; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
(setq scroll-step 1) ;; keyboard scroll one line at a time

(setq flycheck-elixir-credo-strict t)

(setq-default fill-column 80)
(set-face-foreground 'fill-column-indicator "#274690") ;; face color for display-fill-column-indicator-mode
(setq fci-rule-color "#274690") ;; color for fci mode

(setq-default git-magit-status-fullscreen t)
(setq magit-repository-directories
      '(("~/dev/" . 0) ("~/dev/apps/" . 1) ("~/code/" . 1) ("~/dotfiles/" . 0)))

;; Files to open with the OS' default or custom program
(setq org-file-apps
      '((auto-mode . emacs)
        (directory . emacs)
        ("\\.mm\\'" . default)
        ("\\.x?html?\\'" . default)
        ("\\.pdf\\'" . default)
        ("\\.docx\\'" . default)))
;; Tree-Sitter
(setq treesit-language-source-alist
   '((bash "https://github.com/tree-sitter/tree-sitter-bash")
     (css "https://github.com/tree-sitter/tree-sitter-css")
     (elisp "https://github.com/Wilfred/tree-sitter-elisp")
     (html "https://github.com/tree-sitter/tree-sitter-html")
     (javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")
     (json "https://github.com/tree-sitter/tree-sitter-json")
     (markdown "https://github.com/ikatyang/tree-sitter-markdown")
     (org "https://github.com/tree-sitter/tree-sitter-org")
     (ruby "https://github.com/ikatyang/tree-sitter-ruby")
     (scss "https://github.com/ikatyang/tree-sitter-scss")
     (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
     (typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
     (vue "https://github.com/ikatyang/tree-sitter-vue")
     (yaml "https://github.com/ikatyang/tree-sitter-yaml")))

;; Map major modes to TS major modes. Enable this to use TS
;; (setq major-mode-remap-alist
;;       '((typescript-mode . typescript-ts-mode)))

;; Fixes issues when resizing the emacs window in some window managers (ie, MacOS)
(setq frame-resize-pixelwise t)

Hooks

(add-hook 'js2-mode-hook
          (lambda ()
            (spacemacs/toggle-auto-completion-on)))
(add-hook 'vue-mode-hook
          (lambda ()
            (flycheck-add-mode 'javascript-eslint 'vue-mode))) ;; Add eslint as a selectable checker in vue-mode
(add-hook 'prog-mode-hook
          (lambda ()
            (display-fill-column-indicator-mode) ;; For 80 char column line
            (rainbow-mode)
            (setq display-line-numbers t)))

(require 'ansi-color)
(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter) ;; color support compiliation output

(setq rspec-use-spring-when-possible nil) ;; define this instead in a .dir-locals
(eval-after-load 'rspec-mode
  ;; Override this function to just use spring if the variable is set and not
  ;; do all this extra checking the see if spring can be used on the host.
  ;; This is problematic for using spring with Docker.
  '(defun rspec-spring-p () rspec-use-spring-when-possible)
  )

Keys

(spacemacs/declare-prefix "o" "custom")
(spacemacs/set-leader-keys "on" 'org-roam-node-find)

(spacemacs/declare-prefix-for-mode 'vue-mode "o" "custom")
(spacemacs/declare-prefix-for-mode 'js2-mode "o" "custom")

Other settings

(spacemacs/toggle-highlight-current-line-globally-off) ;; Turns off highlight current line
(global-visual-line-mode 1) ; wrap line by default
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-mode))
(add-to-list 'auto-mode-alist '("\\.json\\.erb\\'" . json-mode))
(custom-set-faces
 '(company-tooltip-common
   ((t (:inherit company-tooltip :weight bold :underline nil))))
 '(company-tooltip-common-selection
   ((t (:inherit company-tooltip-selection :weight bold :underline nil)))))

load-path

Folder for custom pacakages like…

Or anything I just want to manually install. You can optionally require them as well. Or just eval (require 'bazel) to load on demand.

This will add the /.emacs.d/lisp and all sub directories to the load-path

(let ((default-directory  "~/.emacs.d/lisp/")) ;; Put custom pacakages here.
  (normal-top-level-add-subdirs-to-load-path))

typescript-mode

Apply multiple checkers for typescript-mode. See https://www.flycheck.org/en/27/_downloads/flycheck.html#Applying-multiple-checkers

(defun my/setup-typescript-mode-checkers ()
  "Adds eslint as the next flycheck checker to lsp"
  (interactive)
  (flycheck-add-next-checker 'lsp '(warning . javascript-eslint)))

(spacemacs/set-leader-keys-for-major-mode 'typescript-mode "oc" 'my/setup-typescript-mode-checkers)

org-mode

With pandoc, I can use ox-gfm to export org files to GitHub Flavor Markdown

(eval-after-load "org"
  '(require 'ox-gfm nil t))

Override the 3rd level heading color for dakrone theme

(defun my/org-mode-faces ()
  "Org-mode face remapping for `org-mode-hook'."
  (when (string-equal "dakrone" spacemacs--cur-theme)
    (face-remap-add-relative 'org-level-3
                             :foreground "dark magenta")))
  • Automatically set the #+updated: file property before save.
  • Hide bold, italics and code markers
  • Turn off underline ellipsis. It looks weird.
  • Auto wrap text.
  • Spell check my org notes.
(add-hook 'org-mode-hook
          (lambda ()
            (setq-local time-stamp-active t
                        time-stamp-start "#\\+updated: [ \t]*"
                        time-stamp-end "$"
                        time-stamp-format "%Y-%m-%d %H:%M %p"
                        org-hide-emphasis-markers t)
            (add-hook 'before-save-hook 'time-stamp nil 'local)
            (set-face-underline 'org-ellipsis nil)
            (auto-fill-mode 1)
            (spacemacs/toggle-spelling-checking-on)
            (my/org-mode-faces)
            (display-fill-column-indicator-mode)
            (turn-on-smartparens-mode)))

org-roam

org-roam-directory set in user-init function. See syl20bnr/spacemacs#14477 (comment)

The capture templates map to different directories most of which are backed by different git repos. Some are public, some are not.

(setq org-roam-db-location "~/slip-box/db/org-roam.db")
(setq org-roam-tag-sources '(prop vanilla))
(setq org-roam-capture-templates
      '(("d" "default" plain "%?"
         :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org"
                           "#+title: ${title}\n#+date: %<%Y-%m-%d %H:%M %p>\n#+updated: \n")
         :unnarrowed t)
        ("c" "cmm" plain "%?"
         :target (file+head "cmm/%<%Y%m%d%H%M%S>-${slug}.org"
                          "#+title: ${title}\n")
         :unnarrowed t)
        ("p" "personal" plain "%?"
         :target (file+head "personal/%<%Y%m%d%H%M%S>-${slug}.org"
                          "#+title: ${title}\n#+date: %<%Y-%m-%d %H:%M %p>\n#+updated: \n")
         :unnarrowed t)
        ("l" "local" plain "%?"
         :target (file+head "local/%<%Y%m%d%H%M%S>-${slug}.org"
                            "#+title: ${title}\n")
         :unnarrowed t)))
(setq org-roam-node-display-template
      (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))

dap-mode helper functions

See also my dap-mode notes.

Automatically open dap-hydra when a breakpoint is triggered. (Commenting this out for now…not sure I really like this)

;; (add-hook 'dap-stopped-hook' (lambda (arg) (call-interactively #'dap-hydra)))

Some projects I work on need special configurations. I declare a couple variables here that can optionally be set in a .dir-locals.el file.

(defvar my/dap-debug-url nil)
(defvar my/dap-debug-project-root nil)

This is a thing because some projects I work on have SPA client(s) in the same repo as the server backend API, in their own folders. In such cases, I use a .dir-locals.el file in the root of each client app to set the my/dap-debug-project-root variable. That way I have accurate paths to the source map files. So, this is a helper function used in the code below.

(defun my/dap-debug-determine-project-root ()
  (or my/dap-debug-project-root (projectile-project-root)))

Chrome browser debug configuration

Setting up the links to source map files is a pain in the arse, but so far this worked for me.

(spacemacs/set-leader-keys-for-major-mode 'js2-mode "od" 'my/dap-debug-chrome)
(spacemacs/set-leader-keys-for-major-mode 'vue-mode "od" 'my/dap-debug-chrome)

(defun my/dap-debug-chrome ()
  (interactive)
  (require 'dap-chrome)
  (dap-debug (list :type "chrome"
                   :cwd (or my/dap-debug-project-root (projectile-project-root))
                   :mode "url"
                   :request "launch"
                   :userDataDir: nil
                   :localRoot (my/dap-debug-determine-project-root)
                   :remoteRoot (concat my/dap-debug-url "v2/")
                   :webRoot (my/dap-debug-determine-project-root)
                   :url (or my/dap-debug-url "http://localhost:8080")
                   :name "Chrome Javascript Debug Config")))

Mocha test runner debug configuration

(spacemacs/set-leader-keys-for-major-mode 'js2-mode "om" 'my/dap-debug-mocha-vue)
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode "om" 'my/dap-debug-mocha-vue)

(defun my/dap-debug-mocha-vue ()
  (interactive)
  (require 'dap-node)
  (dap-debug (list :type "node"
                   :request "launch"
                   :console "internalConsole"
                   :env (list :NODE_ENV "test")
                   :cwd (or my/dap-debug-project-root (projectile-project-root))
                   :program (concat (my/dap-debug-determine-project-root) "node_modules/@vue/cli-service/bin/vue-cli-service.js")
                   :args (list "test:unit" "--inspect-brk" "--watch" "--timeout" "999999" "--include" "tests/setup.js" (buffer-file-name))
                   :port 9229
                   :name "Node Mocha Current File")))

Vitest unit tests

This kills the previous test run buffers if they exist, otherwise they just stack up. See loop examples. Then it runs dap-debug with a configuration for running vitest. Output is displayed in a small buffer at the bottom.

This is broken. Dap-mode doesn’t yet support the newest VSCode debugging tools. emacs-lsp/dap-mode#736.

(spacemacs/set-leader-keys-for-major-mode 'js2-mode "ov" 'my/dap-debug-vitest)
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode "ov" 'my/dap-debug-vitest)

(defun my/dap-debug-vitest ()
  (interactive)
  (require 'dap-node)
  (require 'cl-lib)
  (cl-loop for buffer in (buffer-list)
     when (string-prefix-p "*Vitest Current File" (buffer-name buffer))
     do (kill-buffer buffer))
  (dap-debug (list :type "node"
                   :request "launch"
                   :console "integratedTerminal"
                   :autoAttachChildProcesses t
                   :smartStep t
                   :cwd (or my/dap-debug-project-root (projectile-project-root))
                   :program (concat (my/dap-debug-determine-project-root) "node_modules/vitest/vitest.mjs")
                   :args (list "run" (file-relative-name buffer-file-name my/dap-debug-project-root))
                   :port 9229
                   :name "Vitest Current File")))

Running Vitest tests

If my/run-js-tests-in-docker is specified in the project’s .dir-locals.el (or wherever), delegate the test run to it, otherwise run it locally.

(spacemacs/set-leader-keys-for-major-mode 'js2-mode "ot" 'my/run-current-vuejs-unit-test)
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode "ot" 'my/run-current-vuejs-unit-test)

(defun my/run-current-vuejs-unit-test ()
  (interactive)
  (compile
   (concat
    (cond (my/run-js-tests-in-docker
           (concat "docker exec " my/docker-container-name " ./node_modules/vitest/vitest.mjs "))
          (t
           (concat "cd " (my/dap-debug-determine-project-root) " && " "./node_modules/vitest/vitest.mjs ")))
    "run "
    (file-relative-name buffer-file-name my/dap-debug-project-root))
    t))

Open project file in VScode

Open file in VScode using the projectile project root as the folder (ie, where a .vscode directory lives). I use this where I need to debug node applications since dap-mode doesn’t work at the moment.

(defun my/open-in-code ()
  (interactive)
  (call-process-shell-command (concat "code " "-a " (projectile-project-root) " " buffer-file-name) nil 0))

Super highlighting

My default visual select (region) highlight is kind of light and hard to see in bright rooms. This makes it very visible.

(spacemacs/set-leader-keys "oh" 'my/super-highlight-region)

(defun my/super-highlight-region ()
  "Darken the region and lighten the selected text"
  (interactive)
  (set-face-attribute 'region nil :background "#666" :foreground "#ffffff"))

Fill region

Key binding to wrap text.

(spacemacs/set-leader-keys "of" 'fill-region)

Unfilling is useful. This comes from the Emacs Wiki.

(defun unfill-region (beg end)
  "Unfill the region, joining text paragraphs into a single
    logical line.  This is useful, e.g., for use with
    `visual-line-mode'."
  (interactive "*r")
  (let ((fill-column (point-max)))
    (fill-region beg end)))

(spacemacs/set-leader-keys "ou" 'unfill-region)

Eslint fix up

Calls the project’s eslint binary to fix up the current buffer.

(spacemacs/set-leader-keys-for-major-mode 'js2-mode "oe" 'my/eslint-fix)
(spacemacs/set-leader-keys-for-major-mode 'vue-mode "oe" 'my/eslint-fix)
(spacemacs/set-leader-keys-for-major-mode 'typescript-mode "oe" 'my/eslint-fix)

(defun my/eslint-fix ()
  (interactive)
  (shell-command
   (concat (my/dap-debug-determine-project-root) "node_modules/.bin/eslint --fix " (buffer-file-name))))

Eslint check

(spacemacs/set-leader-keys-for-major-mode 'vue-mode "ol" 'my/eslint-check-buffer)
(spacemacs/set-leader-keys-for-major-mode 'js2-mode "ol" 'my/eslint-check-buffer)

(defun my/eslint-check-buffer ()
  "run eslint on current buffer"
  (interactive)
  (compile
   (concat
    (my/dap-debug-determine-project-root)
    "node_modules/.bin/eslint "
    (buffer-file-name))
   t))

RSpec tests in Kubernetes cluster

This depends on having kubectl cli utility installed and the following variables defined (preferably in a .dir-locals.el)

  • my/kube-namespace
  • my/kube-container
  • my/dap-debug-project-root
  • rspec-use-spring-when-possible

It’s a little silly. This kinda re-implements some of what rspec-mode already does, albeit in a simpler way.

TODO: add –only-failures

(spacemacs/set-leader-keys-for-major-mode 'ruby-mode "ob" 'my/rspec-verify-k8s)
(spacemacs/set-leader-keys-for-major-mode 'ruby-mode "or" 'my/rspec-rerun-k8s)
(spacemacs/set-leader-keys-for-major-mode 'ruby-mode "ot" 'my/rspec-verify-single-k8s)

(defvar my/rspec-last-command nil)

(defun my/rspec-k8s-cmd (file options)
  (setq my/rspec-last-command
    (concat "kubectl exec -it $(kubectl get po --template '{{range.items}}{{.metadata.name}}{{end}}' -n "
            my/kube-namespace
            " --selector=component="
            my/kube-container
            ") -c "
            my/kube-container
            " -n "
            my/kube-namespace
            " -- bash -c 'bundle exec "
            (if rspec-use-spring-when-possible
                "spring "
                "")
            "rspec "
            file
            "'"))
  my/rspec-last-command)

(defun my/rspec-verify-k8s ()
  "Run the specs in the current buffer"
  (interactive)
  (compile
   (my/rspec-k8s-cmd (file-relative-name buffer-file-name my/dap-debug-project-root) "")
   t))

(defun my/rspec-verify-single-k8s ()
  "Run the specs at point in the current buffer"
  (interactive)
  (compile
   (my/rspec-k8s-cmd
    (concat (file-relative-name buffer-file-name my/dap-debug-project-root)
            ":"
            (number-to-string (line-number-at-pos)))
    "")
   t))

(defun my/rspec-rerun-k8s ()
  "Re-run the last RSpec command"
  (interactive)
  (if (not my/rspec-last-command)
      (error "No last command to run")
    (compile my/rspec-last-command t))
  )

Vue

This is forces lsp-mode to find typescript where it should be

;; https://github.com/emacs-lsp/lsp-mode/issues/4313#issuecomment-2051461893
(with-eval-after-load 'lsp-volar
  (lsp-dependency 'typescript
                  '(:npm :package "typescript"
                        :path "tsserver")))

End of user-config function

)