diff --git a/modules/lang/fortran/autoload.el b/modules/lang/fortran/autoload.el index c0dc09df8..04be5aea2 100644 --- a/modules/lang/fortran/autoload.el +++ b/modules/lang/fortran/autoload.el @@ -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." diff --git a/modules/lang/fortran/config.el b/modules/lang/fortran/config.el index 674866f9b..42bd6c3cc 100644 --- a/modules/lang/fortran/config.el +++ b/modules/lang/fortran/config.el @@ -29,10 +29,10 @@ :desc "run (gfortran)" "r" #'+fortran/gfortran-run) (easy-menu-define f90-menu f90-mode-map "Simpler menu for F90 mode." - '("F90" - ["Compile" +fortran/fpm-build :active t :help "Compile with FPM"] - ["Run" +fortran/fpm-run :active t :help "Run the Executable"] - ["Test" +fortran/fpm-test :active t :help "Run the Unit Tests"]))) + `("F90" + ["Compile" +fortran/build :active t :help "Compile the Project"] + ["Run" +fortran/run :active t :help "Run the Executable"] + ["Test" +fortran/fpm-test :active (+fortran--fpm-toml) :help "Run the Unit Tests"]))) (use-package! fortran ;; The `.for' extension is automatically recognized by Emacs and invokes