aboutsummaryrefslogblamecommitdiff
path: root/nix/users/fcuny/configs/emacs/site-lisp/init-programming.el
blob: b3712e7a5901f66f39db54d3f8bed9c204793bbb (plain) (tree)





































































































































































































                                                                                              
;;; init-programming.el --- Configure things related to programming -*- lexical-binding: t -*-
;; Author: Franck Cuny <franck@fcuny.net>

;;; Commentary:

;; Configure things related to programming

;;; Code:

(use-package magit
  :bind ("C-x g" . magit-status)
  :custom
  (magit-diff-refine-hunk t)
  (magit-repository-directories '(("~/workspace" . 1)))
  (magit-repolist-column-flag-alist '((magit-untracked-files . "N")
				      (magit-unstaged-files . "U")
				      (magit-staged-files . "S")))
  (magit-repolist-columns '(("Name" 25 magit-repolist-column-ident nil)
			    ("" 3 magit-repolist-column-flag)
			    ("Version" 25 magit-repolist-column-version
			     ((:sort magit-repolist-version<)))
			    ("B<U" 3 magit-repolist-column-unpulled-from-upstream
			     ((:right-align t)
			      (:sort <)))
			    ("B>U" 3 magit-repolist-column-unpushed-to-upstream
			     ((:right-align t)
			      (:sort <)))
			    ("Path" 99 magit-repolist-column-path nil)))
  (magit-clone-default-directory "~/workspace/")
  :config
  ;; show ANSI colors in the process buffer, so it's easier to read what's going on
  ;; for some reasons if it's in the `:custom' section it does not get set
  (setq magit-process-finish-apply-ansi-colors t))

(use-package git-link
  :defines git-link-remote-alist
  :bind ("C-c Y" . git-link)
  :commands (git-link git-link-commit git-link-homepage)
  :custom
  (git-link-open-in-browser t)
  :config
  ;; sets up roblox git enterprise as a git-link handler
  (add-to-list 'git-link-remote-alist '("github\\.rblx\\.com" git-link-github))
  (add-to-list 'git-link-commit-remote-alist '("github\\.rblx\\.com" git-link-commit-github)))

(use-package elec-pair
  :hook (prog-mode . electric-pair-mode))

(use-package eldoc
  :diminish
  :hook ((emacs-lisp-mode) . eldoc-mode)
  :custom
  (eldoc-idle-delay 1)
  (eldoc-documentation-strategy #'eldoc-documentation-default)
  ;; Don't resize the echo area if the documentation is longer. This is very
  ;; distracting when combined with Eglot's highlight functionality.
  (eldoc-echo-area-use-multiline-p nil))

(use-package compile
  :hook (compilation-filter . ansi-color-compilation-filter)
  :custom
  (compilation-always-kill t)
  (compilation-context-lines 10)
  (compilation-disable-input t)
  (compilation-scroll-output 'first-error)
  (compilation-scroll-output t)
  (compilation-skip-threshold 2)
  ;; Save all buffers on M-x `compile'
  (compilation-ask-about-save nil))

(use-package direnv
  :custom
  (direnv-always-show-summary nil)
  :config
  (direnv-mode))

(use-package flymake
  :bind (:prefix "C-c !"
		 :prefix-map flymake-prefix-map
		 ("l" . consult-flymake)
		 ("d" . flymake-show-buffer-diagnostics)
		 ("D" . flymake-show-project-diagnostics)
		 ("n" . flymake-goto-next-error)
		 ("p" . flymake-goto-prev-error))
  :hook
  (prog-mode . flymake-mode)
  :custom
  (flymake-start-on-save-buffer t)
  (flymake-fringe-indicator-position 'left-fringe)
  (flymake-suppress-zero-counters t)
  (flymake-proc-compilation-prevents-syntax-check t)
  (flymake-no-changes-timeout 9999)
  (elisp-flymake-byte-compile-load-path load-path))

(use-package eglot
  :bind (:map eglot-mode-map
	      ("C-c l a" . eglot-code-actions)
	      ("C-c l r" . eglot-rename)
	      ("C-c l f" . eglot-format-buffer))
  :hook ((go-mode     . eglot-ensure)
	 (python-mode . eglot-ensure)
	 (nix-mode    . eglot-ensure))
  :custom
  (eglot-send-changes-idle-time 0.1)
  :config
  (setq eglot-autoshutdown t
	;; Disable logging of events.
	eglot-events-buffer-size 0)
  (setq-default eglot-workspace-configuration
                '(:pylsp (:plugins (:ruff (:enabled t)))
                  :nil (:formatting (:command ["nixfmt"]))
                  :gopls (:usePlaceholders t
					   :staticcheck t
					   :completeUnimported t
					   :matcher "CaseSensitive")))
  ;; uses https://github.com/nix-community/nixd for the LSP server instead of rnix
  (add-to-list 'eglot-server-programs '(nix-mode . ("nil"))))

(use-package emacs-lisp-mode
  :bind (:map emacs-lisp-mode-map
              ("C-c C-r" . eval-region)
              ("C-c C-d" . eval-defun)
              ("C-c C-b" . eval-buffer))
  :hook ((emacs-lisp-mode . flymake-mode)))

(use-package go-mode
  :hook ((go-mode . (lambda () (setq tab-width 4)))
         (go-mode . (lambda () (add-hook 'before-save-hook 'eglot-format-buffer nil t))))
  :bind (:map go-mode-map
              ("C-c C-c" . compile))
  :config
  (with-eval-after-load 'exec-path-from-shell
    (exec-path-from-shell-copy-envs '("GOPATH" "GOBIN"))))

(use-package gotest
  :after go-mode
  :custom
  (go-test-verbose t))

(use-package nix-mode
  :hook ((nix-mode . (lambda () (add-hook 'before-save-hook 'eglot-format-buffer nil t))))
  :custom
  (nix-indent-function 'nix-indent-line))

(use-package python-mode)

(use-package ruby-mode)

(use-package json-mode)

(use-package json-reformat
  :after json-mode)

(use-package jq-mode
  :mode "\\.jq\\'")

(use-package terraform-mode
  :mode "\.tf\\'")

(use-package hcl-mode
  :mode "\.nomad\\'")

(use-package toml-mode)

(use-package yaml-mode)

(use-package docker
  :bind ("C-c d" . docker)
  :diminish
  :init
  (use-package docker-image   :commands docker-images)
  (use-package docker-volume  :commands docker-volumes)
  (use-package docker-network :commands docker-containers)
  (use-package docker-compose :commands docker-compose)

  (use-package docker-container
    :commands docker-containers
    :custom
    (docker-containers-shell-file-name "/bin/bash")
    (docker-containers-show-all nil)))

(use-package docker-compose-mode
  :mode "docker-compose.*\.yml\\'")

(use-package dockerfile-mode
  :mode "Dockerfile[a-zA-Z.-]*\\'")

(use-package protobuf-mode
  :mode "\\.proto\\'")

(use-package css-mode
  :custom
  (css-indent-offset 2)
  (cssm-indent-level 1))

(provide 'init-programming)

;;; init-programming.el ends here