|
;;; frc-mode.el --- Emacs integration with WPILib+GradleRIO -*- lexical-binding: t -*-
|
|
|
|
;; Copyright (C) 2020 by Hazel Levine
|
|
|
|
;; Author: Hazel Levine <rose.hazel@protonmail.ch>
|
|
;; Maintainer: Hazel Levine <rose.hazel@protonmail.ch>
|
|
;; URL: https://github.com/ralsei/frc-mode
|
|
;; Version: 0.0.1
|
|
;; Keywords: gradle, robotics, first
|
|
;; Package-Requires: ((s "1.12.0") (projectile "2.1.0"))
|
|
|
|
;; This file is NOT part of GNU Emacs.
|
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
;; it under the terms of the GNU General Public License as published by
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
;; (at your option) any later version.
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;; GNU General Public License for more details.
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;; Emacs integration with WPILib + GradleRIO via compile-mode and projectile.
|
|
|
|
;;; Code:
|
|
|
|
;;; DEPENDENCIES
|
|
(require 's)
|
|
(require 'compile)
|
|
(require 'projectile)
|
|
|
|
;;; INTERNALS
|
|
(defun frc-is-frc-project (dir)
|
|
"Determines if this DIR is a valid WPILib 2019+ project.
|
|
Due to the way WPILib under Visual Studio Code functions, this insists that
|
|
gradlew exists. More complex setups may cause this to break."
|
|
(and (file-exists-p (expand-file-name "build.gradle" dir))
|
|
(file-exists-p (expand-file-name "gradlew" dir))
|
|
(projectile-project-root)))
|
|
|
|
(defun frc-kill-compilation-buffer ()
|
|
"Kill the compile buffer."
|
|
(progn
|
|
(if (get-buffer "*compilation*")
|
|
(progn
|
|
(delete-windows-on (get-buffer "*compilation*"))
|
|
(kill-buffer "*compilation*")))))
|
|
|
|
(defun frc-run-gradlew (params)
|
|
"Run gradlew with the parameters or tasks PARAMS."
|
|
(frc-kill-compilation-buffer)
|
|
(if (not (projectile-project-root))
|
|
(error "Not a projectile project!")
|
|
(if (not (frc-is-frc-project (projectile-project-root)))
|
|
(error "Not an FRC project!")))
|
|
(let ((default-directory (projectile-project-root)))
|
|
(compile (s-join " " (list "./gradlew" params)))))
|
|
|
|
;;; INTERACTIVE FUNCTIONS
|
|
(defun frc-build ()
|
|
"Build the robot code without deploying it to the roboRIO."
|
|
(interactive)
|
|
(frc-run-gradlew "build"))
|
|
|
|
(defun frc-deploy ()
|
|
"Build the robot code and deploy it to the roboRIO."
|
|
(interactive)
|
|
(frc-run-gradlew "deploy"))
|
|
|
|
(defun frc-execute (params)
|
|
"Execute gradlew with the tasks specified by PARAMS."
|
|
(interactive "sType gradlew parameters: ")
|
|
(frc-run-gradlew params))
|
|
|
|
;;; KEYBINDINGS
|
|
(defvar frc-mode-map
|
|
(let ((map (make-sparse-keymap)))
|
|
(define-key map (kbd "C-c C-f b") 'frc-build)
|
|
(define-key map (kbd "C-c C-f d") 'frc-deploy)
|
|
(define-key map (kbd "C-c C-f r") 'frc-execute)
|
|
map)
|
|
"Keymap for FRC minor mode.")
|
|
|
|
;;;###autoload
|
|
(define-minor-mode frc-mode
|
|
"Emacs minor mode for integration with WPILib and GradleRIO."
|
|
:lighter " FRC"
|
|
:keymap 'frc-mode-map
|
|
:global t)
|
|
|
|
(provide 'frc-mode)
|
|
|
|
;;; frc-mode.el ends here
|