Skip to content

Latest commit

 

History

History
383 lines (356 loc) · 10.3 KB

config.org

File metadata and controls

383 lines (356 loc) · 10.3 KB

Emacs Config

Prelude

(setf inhibit-startup-screen t
      ring-bell-function 'ignore
      visible-bell nil
      make-backup-files nil)

(set-default 'indent-tabs-mode nil)

(setf help-window-select t)

(if (display-graphic-p)
    (progn
      (scroll-bar-mode -1)
      (tool-bar-mode -1)
      (set-fringe-mode 15)))
(menu-bar-mode -1)
(global-hl-line-mode 1)

(setf debug-on-error t)

Hooks

(add-hook 'before-save-hook 'delete-trailing-whitespace)

Interface

Themes

(use-package solarized-theme)
;; (use-package nord-theme)
(add-hook 'after-init-hook
          (lambda ()
            (load-theme (if (display-graphic-p)
                            'solarized-selenized-dark
                          'solarized-gruvbox-dark))))

Etc

(use-package zoom
  :config (zoom-mode 1))

(use-package writeroom-mode
  :config
  (setf writeroom-width 120
        writeroom-mode-line t
        ;; writeroom-header-line t
        writeroom-maximize-window nil
        writeroom-global-effects (remq 'writeroom-set-fullscreen
                                       writeroom-global-effects)
        writeroom-major-modes '(text-mode prog-mode))
  (global-writeroom-mode))

(use-package which-key
  :config (which-key-mode))

(use-package rainbow-delimiters
  :config (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))

Completion/Nerrowing

(use-package smex
  :commands (smex smex-initialize))

;; TODO: Also setup helm and try it later.
(use-package counsel
  :config (ivy-mode 1)
  :bind (("C-s" . 'swiper-isearch)
         ("M-x" . 'counsel-M-x)
         ("M-y" . 'counsel-yank-pop)
         ("C-x C-f" . 'counsel-find-file)
         ("C-x b" . 'ivy-switch-buffer)
         ("C-c f j" . 'counsel-file-jump)))

Programming

Formatting

;; An alternative package: https://github.com/lassik/emacs-format-all-the-code
(use-package apheleia
  :config
  (setf (alist-get 'isort apheleia-formatters)
        '("isort" "--stdout" "-")
        (alist-get 'python-mode apheleia-mode-alist)
        '(isort black)
        apheleia-formatters-respect-indent-level nil)
  (apheleia-global-mode 1))

Flycheck

(use-package flycheck
  :config (global-flycheck-mode))

LSP

;; TODO: try (use-package eglot)
;; TODO: lsp-mode overrides flycheck checkers by default so no next checker is set
;;       after ls. Wich is kinda annoying for python for instance.
(use-package lsp-mode
  :init
  (setf lsp-keymap-prefix "C-c l")
  (when (eq system-type 'darwin)
    (setf lsp-clients-typescript-npm-location "/opt/homebrew/bin/npm"))
  :hook (((typescript-mode js-mode) . lsp-deferred)
         ((clojure-mode-hook
           clojurescript-mode-hook
           clojurec-mode-hook) . lsp-deferred)
         ;; (python-mode . lsp-deferred)
         ;; which-key integration
         (lsp-mode . lsp-enable-which-key-integration))
  :commands (lsp lsp-deferred))
(use-package lsp-ui)
(use-package lsp-ivy)

Languages

Python

(use-package pyvenv)

Typescript

(use-package typescript-mode
  :mode "\\.tsx?\\'")

Web

(use-package web-mode
  :mode (("\\.html?\\'" . web-mode)
         ;;  ("\\.phtml\\'" . web-mode)
         ;; ("\\.tpl\\.php\\'" . web-mode)
         ;; ("\\.[agj]sp\\'" . web-mode)
         ;; ("\\.as[cp]x\\'" . web-mode)
         ;; ("\\.erb\\'" . web-mode)
         ;; ("\\.mustache\\'" . web-mode)
         ;; ("\\.djhtml\\'" . web-mode)
         )
  :custom
  (web-mode-code-indent-offset 2)
  (web-mode-css-indent-offset 2)
  (web-mode-markup-indent-offset 2)
  (web-mode-sql-indent-offset 2))


(use-package pug-mode
  :mode "\\.pug$")

Clojure

  • [ ] TODO: format on save.
(use-package clojure-mode)
(use-package cider)

Yaml

(use-package yaml-mode
  :config
  (add-hook 'yaml-mode-hook
            '(lambda ()
               (define-key yaml-mode-map "\C-m" 'newline-and-indent)))
  :mode "\\.ya?ml\\'")

HashiCorp HCLTerraform

(use-package hcl-mode)
(use-package terraform-mode)

VCS

(use-package vc-fossil
  ;; Keep from loading unnecessarily at startup.
  :defer t
  ;; This allows VC to load vc-fossil when needed.
  :init (add-to-list 'vc-handled-backends 'Fossil t))

(use-package magit
  :config
  (with-eval-after-load 'project
    ;; Make [m] magit available when switching projects.
    (require 'magit-extras)))

Docker

(use-package docker
  :bind ("C-c d" . docker))
(use-package dockerfile-mode
  :defer t)

Editing

;; (use-package paredit)
(use-package smartparens-mode
  :ensure smartparens  ;; install the package
  :hook (prog-mode text-mode markdown-mode) ;; add `smartparens-mode` to these hooks
  :config
  ;; load default config
  (require 'smartparens-config))

Evil

  • [ ] prevent evil from kicking in in repls.
(use-package evil
  :init
  (setf evil-split-window-below t
        evil-vsplit-window-right t
        evil-want-C-u-scroll t
        evil-want-keybinding nil
        evil-undo-system 'undo-redo)
  :config
  (evil-mode 1))

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

Keys

;; -------- ;; Search: ;; <prefix> j g . git grep ;; <prefix> j r . rg ;; <prefix> j a . ag ;; counsel-ack ;; occur ;; multi-occur ;; ;; -------- ;; Toggle: ;; writeroom ;; flycheck ;; zoom ;; evil ;; whitespace ;; lsp/eglot? ;; TreeMacs ;; ;; -------- ;; Moving ;; paragraphs ;; s-exp ;; functions ;; ;; -------- ;; Jumps ;; definition ;; search for a symbol by name ;; bookmark? ;; ;; -------- ;; C-` Jump to terminal and back to the buffer (create term if not exists) ;; ;; -------- ;; etc: ;; ivy-resume ;; ;; -------- ;; lsp bindings

Bindings

(unbind-key "C-z" global-map)

(defvar custom-keymap (make-sparse-keymap))
(require 'bind-key) ;; bind-key is a part of use-package.

(bind-keys :map custom-keymap
           ("s a" . counsel-ag)
           ("s r" . counsel-rg)
           ("t w" . writeroom-mode)
           ("t W" . whitespace-mode)
           ("t c" . flycheck-mode)
           ("t F" . toggle-frame-fullscreen)
           ("t z" . zoom-mode)
           ("M-r" . ivy-resume)
           ("s-r" . ivy-resume))

(bind-key "s-p" custom-keymap)
(bind-key "M-p" custom-keymap)

Stats

(use-package keyfreq
  :config
  (keyfreq-mode 1)
  (keyfreq-autosave-mode 1))

Misc settings

;; Enable commands useful commands.
(put 'erase-buffer 'disabled nil)

Dired

(require 'sort)
(require 'dired)


(defun my/sort-directory-first (reverse beg end)
  (interactive "P\nr")
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (sort-subr nil
                 'forward-line
                 'end-of-line
                 ;; We're interested in the first letter of the record, if it's ?d,
                 ;; we're looking at a directory.
                 (lambda ()
                   (skip-chars-forward "[:space:]")
                   (char-after))
                 ;; ENDKEYFUNC is not needed for STARTKEYFUNC returns a non-nil value.
                 nil
                 ;; Sort a before b if a is directory and b is not.
                 (lambda (a b)
                   (and
                    (eql a ?d)
                    (not (eql b ?d))))))))

(defun my/dired-directory-first-hook ()
  (save-excursion
    (goto-char (point-min))
    (let ((inhibit-read-only t)
          donep)
      (while (not donep)
        (my/sort-directory-first nil
                                 (progn (forward-line)  ;; Skip the header.
                                        (point))
                                 (progn (forward-paragraph)
                                        (point)))
        (let ((next-subdir-point (dired-next-subdir 1 t t)))
          (setf donep (or
                       ;; No more subdirs.
                       (not next-subdir-point)
                       ;; A new subdir was added, and we're narrowed to its scope.
                       ;; This guards us from entering and infinite loop where dired-next-subdir
                       ;; returns non-nil, but we can't advance point.
                       (eql next-subdir-point (point-max))))))
      (set-buffer-modified-p nil))))

(defun my/toggle-dired-directory-first (&optional on?off?switch)
  (interactive "P")
  (let ((on (lambda ()
              (add-hook 'dired-after-readin-hook
                        'my/dired-directory-first-hook)
              (message "Dired order directories first ON")))
        (off (lambda ()
               (remove-hook 'dired-after-readin-hook
                            'my/dired-directory-first-hook)
               (message "Dired order directories first OFF"))))
    (if (null on?off?switch)
        (if (memq 'my/dired-directory-first-hook
                  dired-after-readin-hook)
            (funcall off)
          (funcall on))
      (if (< (prefix-numeric-value on?off?switch) 0)
          (funcall off)
        (funcall on)))
    (when (eq major-mode 'dired-mode)
      (revert-buffer))))


(my/toggle-dired-directory-first 1)

Maybe/Try [0/2]

  • [ ] TODO: (desktop-save-mode 1)
  • [-] Wanted packages/features: [2/12]
    • [ ] Rename both file and buffer
    • [X] helm/swiper
    • [ ] multiple-cursors
    • [ ] mode-line?
    • [ ] window-management
    • [ ] hydra?
    • [ ] grow/shrink regions?
    • [ ] tree-sitter
    • [ ] ace-jump ace-* ?
    • [X] smartparent
    • [ ] expand-region
    • [ ] copany-mode