programming-config.el (5898B)
1 ;;; programming-config.el --- -*- lexical-binding: t -*- 2 ;;; Commentary: 3 ;;; Configuration files mode configuration 4 ;;; Code: 5 6 (defconst src-dir "~/src/" 7 "Where all my sources are.") 8 (set-register ?s `(file . ,src-dir)) 9 10 (use-package highlight-indentation 11 :hook ((yaml-ts-mode . highlight-indentation-mode) 12 (yaml-ts-mode . highlight-indentation-current-column-mode))) 13 14 (use-package yaml-ts-mode 15 :mode "\\.ya?ml\\'" 16 :hook ((yaml-ts-mode . display-line-numbers-mode))) 17 18 (use-package conf-mode 19 :mode ("\\.to?ml\\'" . conf-toml-mode)) 20 21 (use-package adoc-mode 22 :mode ("\\.adoc\\'" . conf-toml-mode)) 23 24 (defun repeatize (keymap) 25 "Add `repeat-mode' support to a KEYMAP." 26 (map-keymap 27 (lambda (_key cmd) 28 (when (symbolp cmd) 29 (put cmd 'repeat-map keymap))) 30 (symbol-value keymap))) 31 32 (defvar flymake-repeat-map 33 (let ((map (make-sparse-keymap))) 34 (define-key map (kbd "n") 'flymake-goto-next-error) 35 (define-key map (kbd "p") 'flymake-goto-prev-error) 36 (define-key map (kbd "f") 'attrap-flymake) 37 (define-key map (kbd "M-n") 'flymake-goto-next-error) 38 (define-key map (kbd "M-p") 'flymake-goto-prev-error) 39 map)) 40 41 (use-package flymake 42 :defer t 43 :bind 44 (("C-c f e" . flymake-show-project-diagnostics)) 45 (:map flymake-mode-map 46 ("M-n" . flymake-goto-next-error) 47 ("M-p" . flymake-goto-prev-error)) 48 ( 49 :map flymake-diagnostics-buffer-mode-map 50 ("p" . 51 (lambda()(interactive) 52 (previous-line) 53 (save-excursion 54 (flymake-show-diagnostic(point))))) 55 ("n" . 56 (lambda()(interactive) 57 (next-line) 58 (save-excursion 59 (flymake-show-diagnostic(point))))) 60 ( 61 :map flymake-project-diagnostics-mode-map 62 ("p" . 63 (lambda()(interactive) 64 (previous-line) 65 (save-excursion 66 (flymake-show-diagnostic(point))))) 67 ("n" . 68 (lambda()(interactive) 69 (next-line) 70 (save-excursion 71 (flymake-show-diagnostic(point))))))) 72 :config 73 (repeatize 'flymake-repeat-map) 74 :hook 75 ;; (prog-mode . flyspell-prog-mode) rebind flyspell-auto-correct-previous-word 76 (prog-mode . flymake-mode)) 77 78 (defun my-gotest-get-current-test() 79 "Get the current test name, if we have a subtest (starting with name) then use it." 80 (interactive) 81 (require 'which-func) 82 (let ((subtest (when-let* ((subtest 83 (progn 84 (save-excursion 85 (goto-char (line-beginning-position)) 86 (re-search-forward "name:[[:blank:]]*\"\\([^\"]*\\)\"" (line-end-position) t))))) 87 (if subtest 88 (shell-quote-argument (replace-regexp-in-string " " "_" (match-string-no-properties 1)))))) 89 (gotest (when-let* ((test-name (which-function))) 90 (if test-name test-name 91 (error "No test selected"))))) 92 (concat (format "^%s%s$" gotest (if subtest (concat "/" subtest) ""))))) 93 94 (use-package dape 95 :commands (my-dape-go-test-at-point) 96 :after go-ts-mode 97 :bind 98 (:map go-ts-mode-map 99 ("<f5>" . (lambda()(interactive) 100 (if (dape--live-connections) 101 (call-interactively 'dape-continue) 102 (call-interactively 'dape)))) 103 ("S-<f5>" . dape-stop) 104 ("C-S-<f5>" . dape-restart) 105 ("<f9>" . dape-breakpoint-toggle) 106 ("<f10>" . dape-next) 107 ("<f11>" . dape-step-in) 108 ("S-<f11>" . dape-step-out)) 109 :hook 110 (go-ts-mode . (lambda() 111 (interactive) 112 (if (string-suffix-p "_test.go" (buffer-name)) 113 (setq-local dape-command '(delve-unit-test))))) 114 :config 115 (defun my-dape-go-test-at-point () 116 (interactive) 117 (dape (dape--config-eval-1 118 `(modes (go-mode go-ts-mode) 119 ensure dape-ensure-command 120 fn dape-config-autoport 121 command "dlv" 122 command-args ("dap" "--listen" "127.0.0.1::autoport") 123 command-cwd dape-cwd-fn 124 port :autoport 125 :type "debug" 126 :request "launch" 127 :mode "test" 128 :cwd dape-cwd-fn 129 :program (lambda () (concat "./" (file-relative-name default-directory (funcall dape-cwd-fn)))) 130 :args (lambda () 131 (when-let* ((test-name (my-gotest-get-current-test))) 132 (if test-name `["-test.run" ,test-name] 133 (error "No test selected"))))))))) 134 135 (use-package markdown-mode 136 :commands (markdown-mode gfm-mode) 137 :mode (("README\\.md\\'" . gfm-mode) 138 ("\\.md\\'" . markdown-mode) 139 ("\\.markdown\\'" . markdown-mode)) 140 :hook ((markdown-mode . visual-line-mode) 141 (gfm-mode . visual-line-mode))) 142 143 (use-package orgalist 144 :commands (orgalist-mode) 145 :hook ((markdown-mode . orgalist-mode) 146 (gfm-mode . orgalist-mode))) 147 148 ;; (use-package copilot 149 ;; :preface 150 ;; (unless (package-installed-p 'copilot) 151 ;; (package-vc-install "https://github.com/zerolfx/copilot.el")) 152 ;; :hook 153 ;; (prog-mode . copilot-mode) 154 ;; ;; (markdown-mode . copilot-mode) 155 ;; ;; (text-mode . copilot-mode) 156 ;; (log-edit-mode . copilot-mode) 157 ;; (vc-git-log-edit-mode . copilot-mode) 158 ;; :bind 159 ;; (:map copilot-completion-map 160 ;; ("C-g" . copilot-clear-overlay) 161 ;; ("C-j" . copilot-next-completion) 162 ;; ("C-k" . copilot-previous-completion) 163 ;; ("M-RET" . copilot-accept-completion) 164 ;; ("C-f" . copilot-accept-completion) 165 ;; ("C-l" . copilot-panel-complete) 166 ;; ("C-<tab>" . copilot-next-completion) 167 ;; ("C-S-<tab>" . copilot-previous-completion)) 168 ;; :custom 169 ;; (copilot-idle-delay 1)) 170 171 (provide 'programming-config) 172 ;;; programming-config.el ends here