config-programming.el (4201B)
1 ;;; config-programming.el --- -*- lexical-binding: t; -*- 2 ;;; Commentary: 3 ;;; Configure general programming 4 ;;; Code: 5 6 (declare-function vde-project--project-root-or-default-directory "proj-func") 7 8 (defun my-recompile (args) 9 (interactive "P") 10 (cond 11 ((eq major-mode #'emacs-lisp-mode) 12 (call-interactively 'eros-eval-defun)) 13 ((bound-and-true-p my-vterm-command) 14 (my-vterm-execute-region-or-current-line my-vterm-command)) 15 ((get-buffer "*compilation*") 16 (with-current-buffer"*compilation*" 17 (recompile))) 18 ((get-buffer "*Go Test*") 19 (with-current-buffer "*Go Test*" 20 (recompile))) 21 ((and (eq major-mode #'go-mode) 22 buffer-file-name 23 (string-match 24 "_test\\'" (file-name-sans-extension buffer-file-name))) 25 (my-gotest-maybe-ts-run)) 26 ((and (get-buffer "*cargo-test*") 27 (boundp 'my-rustic-current-test-compile) 28 my-rustic-current-test-compile) 29 (with-current-buffer "*cargo-test*" 30 (rustic-cargo-test-run my-rustic-current-test-compile))) 31 ((get-buffer "*cargo-run*") 32 (with-current-buffer "*cargo-run*" 33 (rustic-cargo-run-rerun))) 34 ((get-buffer "*pytest*") 35 (with-current-buffer "*pytest*" 36 (recompile))) 37 ((eq major-mode #'python-mode) 38 (compile (concat python-shell-interpreter " " (buffer-file-name)))) 39 ((call-interactively 'compile)))) 40 41 (defun run-command-recipes-make--commands (makefile) 42 "Return the list of commands names that was defined in MAKEFILE." 43 (let ((s (f-read makefile)) 44 (commands nil) 45 (pos 0)) 46 (while (string-match "^\\([^ \n]+\\):" s pos) 47 (push (match-string 1 s) commands) 48 (setq pos (match-end 0))) 49 commands)) 50 51 ;; TODO github run-command: if remote is github.com, add a gh create pr command, and other "goodies"… 52 ;; TODO tektoncd run-command: if project is tektoncd 53 ;; TODO redhat run-command: if it's a redhat project 54 ;; TODO local run-command: figure out how it works 55 56 (use-package run-command 57 :bind ("C-c c" . run-command) 58 :config 59 (defun run-command-recipe-make() 60 "Returns a dynamic list of commands based of a Makefile. 61 62 This is condition to the following: 63 - `make' executable found 64 - `Makefile' file present in project root *or* the default directory." 65 (let* ((dir (vde-project--project-root-or-default-directory)) 66 (makefile (expand-file-name "Makefile" dir))) 67 (when (and 68 (executable-find "make") 69 (file-exists-p makefile)) 70 (message "Makefile present") 71 (let ((targets (run-command-recipes-make--commands makefile))) 72 (mapcar (lambda (target) 73 (unless (or (string-prefix-p "." target) 74 (string-prefix-p "$" target) 75 (string= "FORCE" target)) 76 (list :command-line (concat "make " target) 77 :command-name target 78 :working-dir dir 79 :runner 'run-command-runner-compile))) 80 targets))))) 81 (defun run-command-recipe-hack () 82 "Returns a dynamic list of commands based of the presence of an `hack' folder 83 in the project root *or* the default-directory." 84 (let* ((dir (vde-project--project-root-or-default-directory)) 85 (hack-dir (expand-file-name "hack" dir)) 86 (files (or (ignore-errors (directory-files hack-dir)) []))) 87 (when (file-accessible-directory-p hack-dir) 88 (mapcar (lambda (file) 89 (let ((hack-file (expand-file-name file hack-dir))) 90 (when (and (file-regular-p hack-file) 91 (file-executable-p hack-file)) 92 (list :command-line hack-file 93 :command-name file 94 :working-dir dir 95 :runner 'run-command-runner-compile)))) 96 files)))) 97 (add-to-list 'run-command-recipes 'run-command-recipe-hack) 98 (add-to-list 'run-command-recipes 'run-command-recipe-make)) 99 100 ;; try out consult-gh 101 ;; (use-package consult-gh 102 ;; :after consult 103 ;; :config 104 ;; (add-to-list 'consult-gh-default-orgs-list "vdemeester") 105 ;; (setq consult-gh-default-orgs-list (append consult-gh-default-orgs-list (remove "" (split-string (or (consult-gh--command-to-string "org" "list") "") "\n")))) 106 ;; (require 'consult-gh-embark) 107 ;; (require 'consult-gh-transient) 108 ;; (setq consult-gh-show-preview t) 109 ;; (setq consult-gh-preview-key "M-o")) 110 111 (provide 'config-programming) 112 ;;; config-programming.el ends here