A minor mode for Emacs to build and deploy FRC robot code under GradleRIO.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.1 KiB

  1. ;;; frc-mode.el --- Emacs integration with WPILib+GradleRIO -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2020 by Hazel Levine
  3. ;; Author: Hazel Levine <rose.hazel@protonmail.ch>
  4. ;; Maintainer: Hazel Levine <rose.hazel@protonmail.ch>
  5. ;; URL: https://github.com/ralsei/frc-mode
  6. ;; Version: 0.0.1
  7. ;; Keywords: gradle, robotics, first
  8. ;; Package-Requires: ((s "1.12.0") (projectile "2.1.0"))
  9. ;; This file is NOT part of GNU Emacs.
  10. ;; This program is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; This program is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. ;;; Commentary:
  21. ;; Emacs integration with WPILib + GradleRIO via compile-mode and projectile.
  22. ;;; Code:
  23. ;;; DEPENDENCIES
  24. (require 's)
  25. (require 'compile)
  26. (require 'projectile)
  27. ;;; INTERNALS
  28. (defun frc-is-frc-project (dir)
  29. "Determines if this DIR is a valid WPILib 2019+ project.
  30. Due to the way WPILib under Visual Studio Code functions, this insists that
  31. gradlew exists. More complex setups may cause this to break."
  32. (and (file-exists-p (expand-file-name "build.gradle" dir))
  33. (file-exists-p (expand-file-name "gradlew" dir))
  34. (projectile-project-root)))
  35. (defun frc-kill-compilation-buffer ()
  36. "Kill the compile buffer."
  37. (progn
  38. (if (get-buffer "*compilation*")
  39. (progn
  40. (delete-windows-on (get-buffer "*compilation*"))
  41. (kill-buffer "*compilation*")))))
  42. (defun frc-run-gradlew (params)
  43. "Run gradlew with the parameters or tasks PARAMS."
  44. (frc-kill-compilation-buffer)
  45. (if (not (projectile-project-root))
  46. (error "Not a projectile project!")
  47. (if (not (frc-is-frc-project (projectile-project-root)))
  48. (error "Not an FRC project!")))
  49. (let ((default-directory (projectile-project-root)))
  50. (compile (s-join " " (list "./gradlew" params)))))
  51. ;;; INTERACTIVE FUNCTIONS
  52. (defun frc-build ()
  53. "Build the robot code without deploying it to the roboRIO."
  54. (interactive)
  55. (frc-run-gradlew "build"))
  56. (defun frc-deploy ()
  57. "Build the robot code and deploy it to the roboRIO."
  58. (interactive)
  59. (frc-run-gradlew "deploy"))
  60. (defun frc-execute (params)
  61. "Execute gradlew with the tasks specified by PARAMS."
  62. (interactive "sType gradlew parameters: ")
  63. (frc-run-gradlew params))
  64. ;;; KEYBINDINGS
  65. (defvar frc-mode-map
  66. (let ((map (make-sparse-keymap)))
  67. (define-key map (kbd "C-c C-f b") 'frc-build)
  68. (define-key map (kbd "C-c C-f d") 'frc-deploy)
  69. (define-key map (kbd "C-c C-f r") 'frc-execute)
  70. map)
  71. "Keymap for FRC minor mode.")
  72. ;;;###autoload
  73. (define-minor-mode frc-mode
  74. "Emacs minor mode for integration with WPILib and GradleRIO."
  75. :lighter " FRC"
  76. :keymap 'frc-mode-map
  77. :global t)
  78. (provide 'frc-mode)
  79. ;;; frc-mode.el ends here