Skip to content

Commit

Permalink
Add a convenience function to start fstar-mode from the command line
Browse files Browse the repository at this point in the history
Suggested-By: @mtzguido.
  • Loading branch information
cpitclaudel committed Aug 3, 2018
1 parent a42763c commit 1138058
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ F*-mode's completion uses `company-mode` under the hood. Try `M-x customize-gro

Customize the variable `fstar-flycheck-checker` to pick your favorite style of real-time verification (full-buffer verification or lightweight typechecking). F*-mode's real-time checking uses `flycheck-mode` under the hood: try `M-x customize-group flycheck` to tweak Flycheck further.

### Starting F*-mode from the command line

Use `emacs -f fstar-debug-invocation path/to/fstar.exe …arguments file-name.fst` to edit `file-name.fst` in F*-mode, with `fstar-subp-prover-args` set to `…arguments` and `fstar-executable` set to `path/to/fstar.exe`. This is particularly convenient when you want to diagnose an issue happening on the command line in Emacs: just prepend `emacs -f fstar-debug-invocation` to it.

## Troubleshooting

### Performance issues
Expand Down
24 changes: 24 additions & 0 deletions fstar-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -5147,6 +5147,30 @@ Non-nil NO-IDE means don't include `--ide' and `--in'."
,@(-mapcat (lambda (dir) `("--include" ,dir))
(fstar-subp--prover-includes-for-compiler-hacking))))

;;;###autoload
(defun fstar-debug-invocation ()
"Compute F*'s arguments from `argv' and visit the corresponding file.
This is useful to quickly debug a failing invocation: just prefix
the whole command line with `emacs -f fstar-debug-invocation'."
(pcase-let ((fname (car (last argv)))
(`(,executable . ,args) (butlast argv))
(fstar-exec-re "fstar\\.\\(exe\\|byte\\|native\\)?\\'")
(err-header (format "Unsupported invocation: %S." argv)))
(unless fname
(user-error "%s
Last argument must be a file name, not %S" err-header fname))
(unless (and executable (string-match executable fstar-exec-re))
(user-error "%s
First argument must be an F* executable, not %S" err-header fname))
(with-current-buffer (find-file-existing fname)
(setq-local fstar-subp-prover-args args)
(message "\
F* binary: %S
F* arguments: %S
Current file: %S" fstar-executable fstar-subp-prover-args buffer-file-name)
(setq argv nil))))

(defun fstar-subp--buffer-file-name ()
"Find name of current buffer, as sent to F*."
(if (fstar--remote-p)
Expand Down

0 comments on commit 1138058

Please sign in to comment.