feat(fortran): generalised build options for menu

Specifically for when compilation is done through the modeline's Easy
Menu, the commands will use `fpm` or `gfortran` dynamically depending on
whether the current file is present in a project or not.
This commit is contained in:
Colin Woodbury 2022-03-06 12:05:12 -08:00 committed by Henrik Lissner
parent 5c52ba35e7
commit 137fca35d8
2 changed files with 35 additions and 5 deletions

View file

@ -1,5 +1,28 @@
;;; lang/fortran/autoload.el -*- lexical-binding: t; -*-
;;
;;; Generalised Building
;;;###autoload
(defun +fortran/build ()
"Compile a Fortran project or file.
If the current file is detected to be within an fpm project,
then building will occur with fpm. Otherwise it will default to gfortran."
(interactive)
(if (+fortran--fpm-toml)
(+fortran/fpm-build)
(+fortran/gfortran-compile)))
;;;###autoload
(defun +fortran/run ()
"Run a Fortran project or file.
If the current file is detected to be within an fpm project,
then building will occur with fpm. Otherwise it will default to gfortran."
(interactive)
(if (+fortran--fpm-toml)
(+fortran/fpm-run)
(+fortran/gfortran-run)))
;;
;;; GFortran
@ -32,10 +55,17 @@
(sleep-for 1))
(compile "./a.out"))
;;
;;; FPM
;;;###autoload
(defun +fortran--fpm-toml ()
"If this is an fpm project, find its toml file."
(when-let* ((project-root (doom-project-root))
(toml (expand-file-name "fpm.toml" project-root)))
(when (file-exists-p toml)
toml)))
;;;###autoload
(defun +fortran/fpm-build ()
"Build the current project using fpm."