Hazel Levine 1 year ago
commit
f26ff5cb7d
  1. 37
      README.org
  2. 96
      frc-mode.el

37
README.org

@ -0,0 +1,37 @@
#+TITLE: frc-mode
#+DATE: February 11, 2020
#+SINCE: 0.0.1
#+STARTUP: inlineimages nofold
* Table of Contents :TOC_3:noexport:
- [[#description][Description]]
- [[#dependencies][Dependencies]]
- [[#keybindings][Keybindings]]
- [[#configuration][Configuration]]
- [[#troubleshooting][Troubleshooting]]
* Description
Builds and deploys FRC Java code managed under GradleRIO. Uses Projectile to
locate the Gradle executable.
* Dependencies
+ [[https://github.com/bbatsov/projectile][Projectile]]
+ [[https://github.com/magnars/s.el][s]]
* Keybindings
+ ~C-x C-f b~: Builds the code, but doesn't deploy it to the roboRIO.
Alternatively, ~M-x frc-build~.
+ ~C-x C-f d~: Builds the code and deploys it to the roboRIO.
Alternatively, ~M-x frc-deploy~.
+ ~C-x C-f r~: Runs an arbitrary Gradle task.
Alternatively, ~M-x frc-execute~.
* Configuration
In ~init.el~:
#+BEGIN_SRC elisp
(load-file "path-to-frc-mode.el")
(add-hook 'java-mode-hook (lambda () (frc-mode 1)))
#+END_SRC
* Troubleshooting
Give up.

96
frc-mode.el

@ -0,0 +1,96 @@
;;; 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-x C-f b") 'frc-build)
(define-key map (kbd "C-x C-f d") 'frc-deploy)
(define-key map (kbd "C-x 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.")
(provide 'frc-mode)
;;; frc-mode.el ends here
Loading…
Cancel
Save