Skip to content

Latest commit

 

History

History
1019 lines (821 loc) · 25.2 KB

config.org

File metadata and controls

1019 lines (821 loc) · 25.2 KB

Misc

Lower minimum warning level

(setq warning-minimum-level :emergency)

Straight

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name
        "straight/repos/straight.el/bootstrap.el"
        (or (bound-and-true-p straight-base-dir)
            user-emacs-directory)))
      (bootstrap-version 7))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(setq package-enable-at-startup nil)
(straight-use-package 'use-package)

tabs

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
(setq electric-indent-mode nil)

exec path from shell

(use-package exec-path-from-shell
  :straight t
  :init (when (memq window-system '(mac ns x))
          (exec-path-from-shell-initialize)))

os notifications

(use-package alert
  :straight t
  :config (setq alert-default-style 'libnotify))

Custom file

(setq-default custom-file "~/.emacs.d/custom.el")
(when (file-exists-p custom-file)
  (load custom-file))

Camel Case movement

(global-subword-mode 1)

Spaces instead of TABS

(setq-default indent-tabs-mode nil)

Matching paren

(setq blink-matching-paren nil)

Backup files

(setq create-lockfiles nil)
(setq backup-directory-alist
  `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
  `((".*" ,temporary-file-directory t)))

CamelCase to snake_case to SCREAMING_SNAKE_CASE

(use-package string-inflection
  :straight t)

Keep folders clean

(use-package no-littering
  :straight t)

(setq auto-save-file-name-transforms
  `((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))

UI

Basic UI configuration

(setq inhibit-startup-message t)
;; disable visible scrollbar
(scroll-bar-mode -1)        
;; disable the toolbar
(tool-bar-mode -1)          
;; disable tooltips
(tooltip-mode -1)
;; give some breathing room
(set-fringe-mode 10)        
;; disable the menu bar
(menu-bar-mode -1)          

;; set up the visible bell
(setq visible-bell nil)
(setq ring-bell-function 'ignore)

(column-number-mode)
(global-display-line-numbers-mode t)

;; disable line numbers for some modes
(dolist (mode '(org-mode-hook
                term-mode-hook
                vterm-mode-hook
                shell-mode-hook
                treemacs-mode-hook
                eshell-mode-hook))
  (add-hook mode (lambda () (display-line-numbers-mode 0))))

;; font configuration
(defvar efs/default-font-size 110)
(defvar efs/default-variable-font-size 110)

;; make frame transparency overridable
(defvar efs/frame-transparency '(90 . 90))

(set-face-attribute 'default nil :font "Fira Code" :height efs/default-font-size)

;; set the fixed pitch face
(set-face-attribute 'fixed-pitch nil :font "Fira Code" :height efs/default-font-size)

;; set the variable pitch face
(set-face-attribute 'variable-pitch nil :font "Cantarell" :height efs/default-variable-font-size :weight 'regular)

(use-package nerd-icons
  :straight t)

;; themes
(use-package doom-themes
  :straight t
  :init
  (load-theme 'doom-material))

(use-package doom-modeline
  :straight t
  :init (doom-modeline-mode 1))

(setq doom-modeline-time-icon t)
(setq doom-modeline-icon t)
(setq doom-modeline-buffer-file-name-style 'auto)
(setq doom-modeline-buffer-name t)
(setq doom-modeline-indent-info nil)
(setq doom-modeline-buffer-encoding t)
(setq doom-modeline-enable-word-count nil)

(use-package dashboard
  :straight t
  :config (dashboard-setup-startup-hook)
  :custom
  (dashboard-startup-banner 'logo)
  (dashboard-center-content t)
  (dashboard-footer-messages '("(╯°□°)╯︵ ┻━┻"))
  (dashboard-items '((recents  . 5)
                     (bookmarks . 5)
                     (agenda)))
  (dashboard-agenda-sort-strategy '(time-up)))

(use-package spinner
  :straight t)

Completion

wich key

(use-package which-key
  :straight t
  :defer 0
  :diminish which-key-mode
  :config
  (which-key-mode)
  (setq which-key-idle-delay 1))

vertico

(use-package vertico
  :straight t
  :config (vertico-mode 1))

marginalia

(use-package marginalia
  :straight t
  :config (marginalia-mode 1))

embark

(use-package embark
  :straight t

  :bind
  (("C-." . embark-act)         ;; pick some comfortable binding
   ("C-;" . embark-dwim)        ;; good alternative: M-.
   ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'

  :init

  ;; Optionally replace the key help with a completing-read interface
  (setq prefix-help-command #'embark-prefix-help-command)

  ;; Show the Embark target at point via Eldoc. You may adjust the
  ;; Eldoc strategy, if you want to see the documentation from
  ;; multiple providers. Beware that using this can be a little
  ;; jarring since the message shown in the minibuffer can be more
  ;; than one line, causing the modeline to move up and down:

  ;; (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
  ;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)

  :config

  ;; Hide the mode line of the Embark live/completions buffers
  (add-to-list 'display-buffer-alist
               '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
                 nil
                 (window-parameters (mode-line-format . none)))))


(use-package embark-consult
  :straight t ; only need to install it, embark loads it after consult if found
  :hook
  (embark-collect-mode . consult-preview-at-point-mode))

consult

(use-package consult
  :straight t
  :config (consult-mode 1)
  :bind (("C-s" . consult-line)
         ([remap list-buffers] . consult-buffer)))

orderless

(use-package orderless
  :straight t
  :custom 
  (completion-styles '(orderless basic))
  (completion-category-overrides '((file (styles basic partial-completion)))))

hydra

(use-package hydra
  :straight t
  :defer t)

(defhydra hydra-text-scale (:timeout 4)
  ("j" text-scale-increase "in")
  ("k" text-scale-decrease "out")
  ("f" nil "finished" :exit t))

Coding

asdf

(use-package asdf
  :straight (:host github :repo "tabfugnic/asdf.el")
  :init (asdf-enable))

version control

(use-package magit
  :straight t
  ;; :init
  ;; (setq magit-blame-styles '((margin
  ;;     			(margin-format " %s%f" " %C %a" " %H")
  ;;     			(margin-width . 42)
  ;;     			(margin-face . magit-blame-margin)
  ;;     			(margin-body-face magit-blame-dimmed))))
  ;; (setq magit-blame-echo-style 'margin)
  :custom
  ;; :hook (prog-mode . (lambda () (magit-blame-echo nil)))
  (magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)
  :bind (("C-x g" . magit-status)))

(use-package diff-hl
  :straight t
  :after magit
  :init
  (global-diff-hl-mode)
  (add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
  (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh))

dired

(use-package dired
  :straight nil
  :commands (dired dired-jump)
  :bind (("C-x C-j" . dired-jump)))

(use-package dired-hide-dotfiles
  :straight t)

neo tree

(use-package neotree
  :straight t)

lsp

(defun efs/lsp-mode-setup ()
  (setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols))
  (setq lsp-headerline-breadcrumb-icons-enable nil)
  (lsp-headerline-breadcrumb-mode))

(use-package lsp-mode
  :straight t
  :commands (lsp lsp-deferred)
  :hook (lsp-mode . efs/lsp-mode-setup)
  :init
  (setq lsp-keymap-prefix "C-c l")
  (setq lsp-elm-elm-path "/usr/local/bin/elm")
  (add-to-list 'exec-path "~/Dev/elixir/elixir-ls")
  ;; :config
  ;; (lsp-enable-which-key-integration t)
  :custom
  ;; (lsp-progress-function 'lsp-on-progress-legacy)
  (lsp-rust-server 'rust-analyzer)
  (rustic-lsp-server 'rust-analyzer)
  (lsp-rust-analyzer-cargo-watch-command "clippy")
  ;; (lsp-rust-analyzer-experimental-proc-attr-macros nil)
  ;; (lsp-rust-analyzer-proc-macro-enable nil)
  ;; https://emacs-lsp.github.io/lsp-mode/page/performance/
  (gc-cons-threshold 100000000)
  (read-process-output-max (* 1024 1024)) ;; 1mb
  (lsp-toggle-signature-auto-activate)
  (lsp-idle-delay 0.500)
  (lsp-rf-language-server-start-command '("~/.asdf/shims/python" "~/.vscode/extensions/robocorp.robotframework-lsp-1.9.0/src/robotframework_ls"))
  (lsp-progress-spinner-type 'moon)
  (lsp-elm-only-update-diagnostics-on-save t)
  (lsp-elm-disable-elmls-diagnostics t))

(use-package lsp-ui
  :straight t
  :hook (lsp-mode . lsp-ui-mode)
  :custom
  (lsp-ui-doc-enable nil)
  (lsp-ui-sideline-show-diagnostics t)
  (lsp-ui-sideline-show-hover nil)
  (lsp-ui-sideline-show-code-actions nil))

(use-package flycheck
  :straight t
  :hook (prog-mode . flycheck-mode))

;; (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))

(use-package lsp-treemacs
  :straight t
  :after lsp)

(use-package lsp-ivy
  :straight t
  :after lsp)

(use-package yasnippet
  :straight t
  :config
  (setq yas-snippet-dirs '("~/.emacs.d/snippets"))
  (yas-reload-all)
  (add-hook 'prog-mode-hook 'yas-minor-mode)
  (add-hook 'text-mode-hook 'yas-minor-mode))

company

(use-package company
  :straight t
  :hook
  (lsp-mode . company-mode)
  (eglot-mode . company-mode)
  (emacs-lisp-mode . company-mode)
  (scheme-mode . company-mode)
  (sql-interactive-mode . company-mode)
  (lisp-interaction-mode . company-mode)
  :bind ("C-c c TAB" . company-complete)
  :custom
  (company-minimum-prefix-length 1)
  (company-idle-delay 0.5))

rainbow

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

json

(use-package json-mode
  :straight t)

rust

(use-package toml-mode
  :straight t)

(use-package cargo
  :straight t
  :hook (rust-mode . cargo-minor-mode))  

(use-package flycheck-rust
  :straight t
  :config (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))

(use-package rustic
  :straight t
  :config
  (setq rustic-spinner-type 'moon)
  (setq rustic-format-on-save t))

scheme

(use-package paredit
  :straight t
  :hook
  (scheme-mode . paredit-mode)
  (emacs-lisp-mode . paredit-mode))

(use-package geiser-guile
  :straight t)

python

(use-package python-mode
  :straight t
  :hook (python-mode . lsp-deferred))

(use-package py-autopep8
  :straight t
  :hook (python-mode . py-autopep8-mode))
(use-package robot-mode
  :straight t
  :hook (robot-mode . lsp-deferred))

clojure

(use-package cider
  :straight t
  :hook (clojure-mode . lsp-deferred))

elixir

(use-package elixir-mode
  :straight t
  :hook (elixir-mode . lsp-deferred))

go

(use-package go-mode
  :straight t)

java

(use-package yaml
  :straight t)

(use-package lsp-java
  :straight t
  :config (add-hook 'java-mode-hook 'lsp))

kotlin

(use-package kotlin-mode
  :straight t
  :hook (kotlin-mode . lsp-deferred))

github copilot

(use-package copilot
  :straight t)

(use-package copilot-chat
  :straight t)

ellellemm

(use-package ellellemm
  :straight (:host github :repo "deepankarsharma/ellellemm"))

graphql

(use-package graphql-mode
  :straight t)

sql

(use-package sql
  :straight t
  :hook (sql-interactive-mode . toggle-truncate-lines)
  :config
  (setq sql-mysql-login-params (append sql-mysql-login-params '(port :default ,3306)))
  (setq sql-postgres-login-params (append sql-postgres-login-params '(port :default ,5432))))

markdown

(use-package markdown-mode
  :straight t
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode)
	   ("\\.md\\'" . markdown-mode)
	   ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "multimarkdown"))

elm

(use-package elm-mode
  :straight t
  :hook
  (elm-mode . lsp-deferred)
  (elm-mode . elm-format-on-save-mode))

php

(use-package php-mode
  :straight t
  :hook (php-mode . lsp-deferred))

yaml

(use-package yaml-mode
  :straight t)

commenting

(use-package evil-nerd-commenter
  :straight t
  :bind ("M-/" . evilnc-comment-or-uncomment-lines))

org

(use-package org
  :straight t
  :bind (([remap org-metaleft] . left-word)
         ([remap org-metaright] . right-word))
  :custom
  (org-agenda-files '("~/agenda.org"))
  (org-M-RET-may-split-line '((default . nil)))
  (org-insert-heading-respect-content t)
  (org-log-done 'time)
  (org-log-into-drawer t))

(use-package org-roam
  :straight t
  :init (org-roam-db-autosync-mode)
  :custom (org-roam-capture-templates '(("d"
                                         "default"
                                         plain
                                         "%?"
                                         :target (file+head "%<%Y%m%d%H%M%S>-${slug}.org" "#+title: ${title}\n")
                                         :unnarrowed t)
                                        ("l"
                                         "literature"
                                         plain
                                         "%?"
                                         :target (file+head "literature/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: literature/${title}\n"))
                                        ("f"
                                         "fleeting"
                                         plain
                                         "%?"
                                         :target (file+head "fleeting/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: fleeting/${title}\n"))
                                        ("p"
                                         "persistent"
                                         plain
                                         "%?"
                                         :target (file+head "persistent/%<%Y%m%d%H%M%S>-${slug}.org" "#+title: persistent/${title}\n")))))


(use-package org-alert
  :straight t
  :config (setq org-alert-interval 60
                org-alert-notify-cutoff 10
                org-alert-notify-after-event-cutoff 10)
  :init (org-alert-enable))

(use-package ox-hugo
  :straight t
  :after ox)

request

(use-package request
  :straight t)

terminal

(use-package multi-vterm
  :straight t)

(use-package vterm
  :straight t
  :hook (vterm-mode . vterm-clear)
  :bind
  ("C-c C-t" . vterm-copy-mode))

Editing & Movement

multiple cursors

(use-package multiple-cursors
  :straight t
  :bind
  ("C->" . mc/mark-next-like-this)
  ("C-<" . mc/mark-previous-like-this)
  ("C-c C-<" . mc/mark-all-like-this)
  ("C-c C-e" . mc/edit-lines))

ace jump

(use-package ace-jump-mode
  :straight t
  :bind ("C-c c SPC" . ace-jump-mode))

back-button

(use-package back-button
  :straight t
  :bind
  ("C-{" . back-button-local-backward)
  ("C-}" . back-button-local-forward)
  ("M-[" . back-button-global-backward)
  ("M-]" . back-button-global-forward))

window

(use-package ace-window
  :straight t
  :bind ([remap other-window] . ace-window))

undo

(use-package undo-tree
  :straight t
  :init (global-undo-tree-mode)
  :bind ([remap upcase-region] . undo-tree-visualize)
  :config
  (setq undo-tree-auto-save-history nil))

ag

(use-package ag
  :straight t)

rg

(use-package rg
  :straight t)

wgrep

(use-package wgrep
  :straight t)

Tramp

(use-package docker-tramp
  :straight t)

(use-package kubernetes-tramp
  :straight t)

Kubernetes

(use-package kubectx-mode
  :straight t)

Custom functions

select line

(defun visd0m/select-line ()
  "Select current line and leave the point at the end of the line."
  (interactive)
  (move-beginning-of-line nil)
  (set-mark-command nil)
  (move-end-of-line nil))

go to elixir hexdoc

(defun visd0m/elixir-doc ()
  "Open elixir documentation hexdocs.pm/elixir in external browser."
  (interactive)
  (let ((url "https://hexdocs.pm/elixir"))
    (browse-url-default-browser url)))

go to rust doc

(defun visd0m/elixir-doc-hex (hex)
  "Open elixir documentation hexdocs.pm/`HEX' in external browser."
  (interactive "sHex: ")
  (let ((url (format "https://hexdocs.pm/%s" hex)))
    (browse-url-default-browser url)))

(defun visd0m/rust-doc-crate (crate)
  "Open rust documentation doc.rust-lang.org/`CRATE' in external browser."
  (interactive "sCrate: ")
  (let ((url (format "https://docs.rs/%s" crate)))
    (browse-url-default-browser url)))

kill buffer file name

(defun visd0m/kill-buffer-file-truename ()
  "Kill current buffer file truename."
  (interactive)
  (if buffer-file-truename
      (kill-new buffer-file-truename)))

kill buffer file project relative name

(defun visd0m/buffer-file-project-relative-name ()
  "Get current buffer file git project relative name or nil."
  (let ((project-root-dir (vc-root-dir))
        (absolute-name buffer-file-truename))
    (if (and project-root-dir absolute-name)
        (let ((project-relative-buffer-file-name (string-remove-prefix
                                                  project-root-dir
                                                  absolute-name)))
          project-relative-buffer-file-name)
      nil)))

go to file at line

(defun visd0m/go-to-file-at-line (file-and-line)
  "Given a path `FILE-AND-LINE' like 'foo/bar:10' go to file: foo/bar at line: 10 in the current git project."
  (interactive "sWhere to: ")
  (let ((project-root-dir (vc-root-dir)))
    (if project-root-dir
        (let* ((tokens (split-string file-and-line ":"))
               (file-name (nth 0 tokens))
               (line (nth 1 tokens)))
          (find-file-existing (format "%s%s" project-root-dir file-name))
          (goto-line (string-to-number line))))))

open line in github

(defun visd0m/open-in-github ()
  "Open the the current file in the current branch in the current repo at the current line in github."
  (interactive)
  (let* ((remote-url (visd0m/git-remote-url))
         (github-remote (visd0m/parse-git-remote remote-url)))
    (if (eq (alist-get 'service github-remote) 'github)
        ;; github
        (let* ((base-url (alist-get 'base-url github-remote))
               (repo (alist-get 'repo github-remote))
               (current-branch (magit-get-current-branch))
               (current-buffer (visd0m/buffer-file-project-relative-name))
               (current-line (line-number-at-pos))
               (composed-url (format "%s/%s/blob/%s/%s#L%s"
                                     base-url
                                     repo
                                     current-branch
                                     current-buffer
                                     current-line)))
          (if (and
               current-branch
               base-url
               current-buffer
               github-remote
               repo
               current-line
               composed-url)
              (browse-url composed-url)
            (message "Something wrong handling github remote")))
      (message (format "Unhandled remote: %s" remote-url)))))

(defun visd0m/git-remote-url ()
  "Get git remote url."
  (with-temp-buffer
    ;; git config --get remote.origin.url
    (vc-git--call (current-buffer) "config" "--get" "remote.origin.url")
    (string-trim-right (buffer-string))))

(defun visd0m/parse-git-remote (remote-url)
  "Get git remote object parsing `REMOTE-URL'."
  (let* ((split (split-string remote-url ":"))
         (prefix (nth 0 split)))
    (pcase prefix
      ("git@github.com"
       (list
        (cons 'service 'github)
        (cons 'base-url "https://github.com")
        (cons 'repo (string-remove-suffix ".git" (nth 1 split)))))
      (_
       (list (cons 'service 'unhandled))))))

delete work backword without kill

(defun vid0m/backward-delete-word-no-kill (arg)
  "Delete characters backward until encountering the beginning of a word.
  With argument, do this that many times.
  This command does not push text to `kill-ring'."
  (interactive "p")
  (visd0m/delete-word-no-kill (- arg)))

(defun visd0m/delete-word-no-kill (arg)
  "Delete characters forward until encountering the end of a word.
  With argument, do this that many times.
  This command does not push text to `kill-ring'."
  (interactive "p")
  (delete-region
   (point)
   (progn
     (forward-word arg)
     (point))))

delete line no kill

(defun visd0m/delete-line-no-kill ()
  "Delete the current line.
  This command does not push text to `kill-ring'."
  (interactive)
  (save-excursion
    (delete-region
     (progn (forward-visible-line 0) (point))
     (progn (forward-visible-line 1) (point)))))

kill all “registered” lsp server

(defun visd0m/lsp-kill-all ()
  "Kill all currenlty running processes considered lsp servers."
  (interactive)
  (seq-each (lambda (process-to-kill) (signal-process process-to-kill 15))
            (seq-filter
             'to-kill?
             (process-list))))

(defun to-kill?
    (process)
  (let ((process-name (process-name process)))
    (or
     (string-match "^rust-analyzer$" process-name)
     (string-match "^elixir-ls$" process-name)
     (string-match "^elm-ls$" process-name)
     (string-match "^iph$" process-name))))

export sql query result to csv file

(defun visd0m/psql-export-query-result-to-csv (query-to-execute csv-file-name)
  "Export result of 'QUERY-TO-EXECUTE to csv file 'CSV-FILE-NAME."
  (interactive "sQuery to execute: \nFFile path: ")
  (sql-send-string (format "\\copy (%s) to '%s' csv header" query-to-execute csv-file-name)))

Feed

(use-package elfeed
  :straight t)

Telegram

(use-package telega
  :straight t
  :init (setq telega-use-docker t))

Mastodon

(use-package mastodon
  :straight t
  :custom
  (mastodon-instance-url "https://mastodon.social")
  (mastodon-active-user "visd0m"))

Global key bindings

(global-set-key (kbd "C-c c s") 'visd0m/select-line)
(global-set-key (kbd "M-<backspace>") 'vid0m/backward-delete-word-no-kill)
(global-set-key (kbd "C-<S-backspace>") 'visd0m/delete-line-no-kill)

Tips & Tricks

To have multiple sqli buffer do as follow: C-u M-x sql-<product>

To insert a new line in mini buffer: C-q C-j

To start recording a macro: F3 To stop recording a macro: F4 To use last recorded macro: F4