Skip to content

Latest commit

 

History

History
787 lines (570 loc) · 21.4 KB

programming.org

File metadata and controls

787 lines (570 loc) · 21.4 KB

Programming

Configuration for programming and languages support.

;;; -*- lexical-binding: t -*-

Treesit

(setq treesit-language-source-alist
   '((bash "https://github.com/tree-sitter/tree-sitter-bash")
     (cmake "https://github.com/uyha/tree-sitter-cmake")
     (css "https://github.com/tree-sitter/tree-sitter-css")
     (elisp "https://github.com/Wilfred/tree-sitter-elisp")
     (go "https://github.com/tree-sitter/tree-sitter-go")
     (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")
     (make "https://github.com/alemuller/tree-sitter-make")
     (markdown "https://github.com/ikatyang/tree-sitter-markdown")
     (python "https://github.com/tree-sitter/tree-sitter-python")
     (toml "https://github.com/tree-sitter/tree-sitter-toml")
     (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
     (typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
     (yaml "https://github.com/ikatyang/tree-sitter-yaml")
     (clojure "https://github.com/sogaiu/tree-sitter-clojure")
     (rust "https://github.com/tree-sitter/tree-sitter-rust")))

Lower font lock level

(setq treesit-font-lock-level 2)

Hideshow

(add-hook 'prog-mode-hook 'hs-minor-mode)

Eldoc

Display Current Function

Which Function Mode

Display current function name in header-line.

(require 'which-func)

(setq which-func-update-delay 0.25)
(setq which-func-display 'mode)

(which-function-mode  1)

Code Formatter

(straight-use-package 'format-all)

(keymap-set prog-mode-map "C-c f" 'format-all-buffer)

Force save file

(defun meomacs-save-buffer-always ()
  "Save the buffer even if it is not modified."
  (interactive)
  (set-buffer-modified-p t)
  (save-buffer))

(global-set-key (kbd "C-c w") 'meomacs-save-buffer-always)

Lisp Parenthese

Paredit

(straight-use-package 'paredit)

(require 'paredit)

(add-hook 'clojure-mode-hook 'paredit-mode)
(add-hook 'clojure-ts-mode-hook 'paredit-mode)
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)

LSP

Eglot

Use eglot as LSP client.

(autoload 'eglot "eglot" nil t)

(setq eglot-ignored-server-capabilities
      '(:documentHighlightProvider
        :inlayHintProvider
        :workspaceSymbolProvider
        :documentSymbolProvider
        :codeLensProvider))

(setq eglot-autoshutdown t)

(setq eglot-stay-out-of '(yasnippet))

(setq eglot-send-changes-idle-time 0)

(defun eglot-setup-eldoc ()
  (setq-local eldoc-documentation-functions '(flymake-eldoc-function
                                              eglot-signature-eldoc-function
                                              eglot-hover-eldoc-function)))

(add-hook 'eglot-mode-hook 'eglot-setup-eldoc)

(with-eval-after-load "eglot"
  (define-key eglot-mode-map (kbd "<C-return>") 'eglot-code-actions))

Turn off event logs

(with-eval-after-load "eglot"
  (setq eglot-events-buffer-config '(:size 0 :format full))
  (setq eglot-events-buffer-size 0))

(with-eval-after-load "jsonrpc"
  (fset #'jsonrpc--log-event #'ignore)
  (setq jsonrpc-event-hook nil))

Use lsp-booster

(straight-use-package
 '(eglot-booster :host github
                 :repo "jdtsmith/eglot-booster"))

(setq eglot-booster-io-only t)

(add-hook 'eglot-mode-hook 'eglot-booster-mode)

Key Binding

KeyCommand
seglot
aeglot-code-actions
oeglot-code-action-organize-imports
reglot-rename
keglot-shutdown
ieglot-find-implementation
(meomacs-keymap-table eglot-keymap keymap-table)
(global-set-key (kbd "C-c e") 'eglot-keymap)

Configuration

(setq-default eglot-workspace-configuration
              '(:rust-analyzer (:hover (:memoryLayout (:enable :json-false))
                                :typing (:excludeChars "([{"))))

Flymake

(setq flymake-no-changes-timeout 0.5)

(with-eval-after-load "flymake"
  (keymap-set flymake-mode-map "C-c ! k" 'flymake-show-buffer-diagnostics)
  (keymap-set flymake-mode-map "C-c ! a" 'flymake-show-project-diagnostics)
  (keymap-set flymake-mode-map "C-c ! n" 'flymake-goto-next-error)
  (keymap-set flymake-mode-map "C-c ! p" 'flymake-goto-prev-error))

Clojure

Clojure-mode

Use clojure-ts-mode instead of clojure-mode.

(straight-use-package 'clojure-mode)

(setq clojure-toplevel-inside-comment-form t
      clojure-indent-style 'always-indent
      clojure-indent-keyword-style 'always-indent
      clojure-enable-indent-specs nil)

Cider for REPL connection

(straight-use-package 'cider)

(autoload 'cider-jack-in "cider" nil t)

(setq cider-offer-to-open-cljs-app-in-browser nil
      cider-font-lock-dynamically '(macro deprecated)
      cider-preferred-build-tool 'shadow-cljs
      cider-repl-type 'shadow
      cider-use-xref t
      cider-enhanced-cljs-completion-p nil)

(add-to-list 'meow-mode-state-list '(cider-inspector-mode . motion))

Jarchive

For opening .jar files. This is required for Eglot.

(straight-use-package 'jarchive)

(with-eval-after-load "clojure-ts-mode"
  (jarchive-mode)
  (diminish 'jarchive-mode))

(with-eval-after-load "clojure-mode"
  (jarchive-mode)
  (diminish 'jarchive-mode))

Svelte

svelte-mode

(straight-use-package 'svelte-mode)

Typescript

typescript-mode

(setq-default typescript-indent-level 4
              typescript-ts-mode-indent-offset 4)

(add-to-list 'auto-mode-alist (cons "\\.ts\\'" 'typescript-ts-mode))
(add-to-list 'auto-mode-alist (cons "\\.tsx\\'" 'tsx-ts-mode))

(setq lsp-typescript-preferences-quote-style "single"
      lsp-typescript-surveys-enabled nil
      lsp-typescript-format-enable nil)

(add-hook 'tsx-ts-mode-hook
          (lambda ()
            (setq-local lsp-enable-indentation nil)))

Deno support

(straight-use-package 'deno-ts-mode)

prisma

(straight-use-package '(prisma-mode :host github
                                    :repo "davidarenas/prisma-mode"))

(autoload 'prisma-mode "prisma-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.prisma\\'" . prisma-mode))

(with-eval-after-load "prisma-mode"
  (define-key prisma-mode-map (kbd "C-c C-f") 'prisma-fmt-buffer))

Lua

(straight-use-package 'lua-mode)

Rust

cargo.el

(straight-use-package '(cargo :host github
                              :repo "DogLooksGood/cargo.el"))

(autoload 'cargo-minor-mode "cargo" nil t)
(add-hook 'rust-ts-mode-hook 'cargo-minor-mode)

(setq cargo-process--custom-path-to-bin nil
      cargo-process--rustc-cmd nil)

(with-eval-after-load "cargo"
  (define-key cargo-process-mode-map (kbd "/") 'scroll-down)
  (define-key cargo-process-mode-map (kbd "@") 'scroll-up)
  (define-key cargo-process-mode-map (kbd "\\") 'toggle-truncate-lines))

rust-ts-mode

(straight-use-package 'rust-mode)
(straight-use-package 'rust-ts-mode)

(add-hook 'rust-ts-mode-hook
          (lambda ()
            (require 'rust-mode)
            (require 'rust-compile)))

(add-to-list 'auto-mode-alist (cons "\\.rs\\'" 'rust-ts-mode))

(setq lsp-rust-analyzer-completion-add-call-parenthesis nil
      lsp-rust-analyzer-proc-macro-enable t
      lsp-rust-analyzer-server-format-inlay-hints nil)

Write a command to switch between wasm32 and native target triple.

(defun rust-toggle-lsp-target ()
  (interactive)
  (require 'lsp-rust)
  (when
      (y-or-n-p (format "Current target is [%s], switch?"
                           (or lsp-rust-analyzer-cargo-target "default")))
    (if lsp-rust-analyzer-cargo-target
        (setq lsp-rust-analyzer-cargo-target nil
              cargo-process--command-check "check")
      (setq lsp-rust-analyzer-cargo-target "wasm32-unknown-unknown"
            cargo-process--command-check "check --target wasm32-unknown-unknown"))))

Nix

(straight-use-package 'nix-mode)

(autoload 'nix-mode "nix-mode" nil t)

(add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))

nixpkgs-fmt

(straight-use-package 'nixpkgs-fmt)

(with-eval-after-load "nixpkgs-fmt"
  (define-key nix-mode-map (kbd "C-c C-f") 'nixpkgs-fmt)
  (add-hook 'nix-mode-hook 'nixpkgs-fmt-on-save-mode))

Solidity

(straight-use-package 'solidity-mode)

(straight-use-package 'company-solidity)
(straight-use-package 'solidity-flycheck)

(with-eval-after-load "solidity-mode"
  (require 'company-solidity)
  (require 'solidity-flycheck))

Restclient

(straight-use-package 'restclient)
(add-to-list 'auto-mode-alist '("\\.restclient" . restclient-mode))

HTML

(straight-use-package 'web-mode)
(setq web-mode-markup-indent-offset 2
      web-mode-css-indent-offset 4)

(add-to-list 'auto-mode-alist
             '("\\.html\\'" . web-mode))
(setq-default css-indent-offset 4
              js-indent-level 4)

Emmet

(straight-use-package 'emmet-mode)

(autoload 'emmet-expand-line "emmet-mode" nil t)

(with-eval-after-load "mhtml-mode"
  (define-key mhtml-mode-map (kbd "M-RET") 'emmet-expand-line))

(with-eval-after-load "svelte-mode"
  (define-key svelte-mode-map (kbd "M-RET") 'emmet-expand-line))

Move

(straight-use-package 'move-mode)

KDL

kdl-mode

(straight-use-package '(kdl-mode :host github
                                 :repo "bobuk/kdl-mode"))

(add-to-list 'auto-mode-alist '("\\.kdl\\'" . kdl-mode))
(add-hook 'kdl-mode-hook (lambda () (setq-local tab-width 2)))
(autoload 'kdl-mode "kdl-mode")

Just

Just-mode

(straight-use-package 'just-mode)

(autoload 'just-mode "just-mode" nil t)

(add-to-list 'auto-mode-alist '("/[Jj]ustfile\\'" . just-mode))
(add-to-list 'auto-mode-alist '("\\.[Jj]ust\\(file\\)?\\'" . just-mode))

(defun +just-mode-hook ()
  (modify-syntax-entry ?- "_"))

(add-hook 'just-mode-hook '+just-mode-hook)

Justl

Execute recipes in Justfile.

(straight-use-package 'justl)

(autoload 'justl-exec-recipe-in-dir "justl" t t)

(keymap-set global-map "C-c j" 'justl-exec-recipe-in-dir)

Rerun

Execute the last recipe by finding the *just* buffer and call justl-recompile.

(defun justl-execute-last-recipe ()
  (interactive)
  (when-let* ((curr-win (selected-window))
              (just-buf (get-buffer "*just*")))
    (with-current-buffer just-buf
      (direnv-update-directory-environment)
      (call-interactively 'justl-recompile))
    (select-window curr-win)))

(keymap-set global-map "C-c J" 'justl-execute-last-recipe)

YAML

(straight-use-package 'yaml-mode)

(autoload 'yaml-mode "yaml-mode" nil t)

(add-to-list 'auto-mode-alist '("\\.\\(e?ya?\\|ra\\)ml\\'" . yaml-mode))
(add-to-list 'magic-mode-alist '("^%YAML\\s-+[0-9]+\\.[0-9]+\\(\\s-+#\\|\\s-*$\\)" . yaml-mode))

Docker

(straight-use-package 'docker)
(straight-use-package 'dockerfile-ts-mode)

(add-to-list 'auto-mode-alist '("/Dockerfile\\'" . dockerfile-ts-mode))

(autoload 'docker "docker" nil t)

Xref configuration

(setq xref-show-definitions-function 'xref-show-definitions-completing-read)

Compilation mode support

(setq compile-command "")

(require 'ansi-color)

(add-hook 'compilation-filter-hook 'ansi-color-compilation-filter)

C

(setq-default c-basic-offset 4)

Scheme

(straight-use-package 'geiser)
(straight-use-package 'geiser-guile)
(setq geiser-debug-jump-to-debug nil)

GLSL

(straight-use-package 'glsl-mode)

String inflection

Cycle cases for symbol

(straight-use-package 'string-inflection)