FarNet.FSharpFar
3.0.1
Prefix Reserved
See the version list below for details.
dotnet add package FarNet.FSharpFar --version 3.0.1
NuGet\Install-Package FarNet.FSharpFar -Version 3.0.1
<PackageReference Include="FarNet.FSharpFar" Version="3.0.1" />
paket add FarNet.FSharpFar --version 3.0.1
#r "nuget: FarNet.FSharpFar, 3.0.1"
// Install FarNet.FSharpFar as a Cake Addin #addin nuget:?package=FarNet.FSharpFar&version=3.0.1 // Install FarNet.FSharpFar as a Cake Tool #tool nuget:?package=FarNet.FSharpFar&version=3.0.1
FarNet.FSharpFar
F# scripting and interactive services in Far Manager
- Menus
- Commands
- Configuration
- Projects
- Debugging
- Interactive
- Editor services
- Using F# scripts
- Using fsx.exe tool
- FSharpFar packages
Project
- Source: FarNet/FSharpFar
- Author: Roman Kuzmin
Credits
- FSharpFar is based on FSharp.Compiler.Service.
Installation
- Far Manager
- Package FarNet
- Package FarNet.FSharpFar
How to install and update FarNet and modules:
https://github.com/nightroman/FarNet#readme
As a result, you get the complete F# scripting portable with Far Manager.
Use it with Far Manager by FSharpFar or without Far Manager by fsx.exe.
Menus
Use [F11]
\ FSharpFar
to open the module menu:
Interactive
Opens the default session interactive.
Sessions...
Shows the list of opened sessions. Keys:
[Enter]
Opens the session interactive.
[Del]
Closes the session and interactives.
[F4]
Edits the session configuration file.
Load
Evaluates the script opened in editor (
#load
).Tips
Shows help tips for the symbol at the caret.
Check
Checks the current F# file for errors.
Errors
Shows the errors of the last check.
Uses in file
Shows uses of the symbol in the file as a go to menu.
Uses in project
Shows uses of the symbol in the project in a new editor.
Enable|Disable auto tips
Toggles auto tips on mouse moves over symbols.
Enable|Disable auto checks
Toggles auto checks for errors on changes in the editor.
Commands
The command prefix is fs:
. It evaluates F# expressions and directives with
the specified or default session and runs special commands.
F# expressions:
fs: FarNet.Far.Api.Message "Hello"
fs: System.Math.PI / 3.
F# directives:
fs: #load @"C:\Scripts\FSharp\Script1.fsx"
fs: #time "on"
fs: #help
open
fs: open: with = <config>
with
(optional) configuration file
The open
command opens the interactive editor with the specified or default configuration.
Sample file association:
A file mask or several file masks:
*.fs.ini
Description of the association:
F# interactive
─────────────────────────────────────
[x] Execute command (used for Enter):
fs: open: with="!\!.!"
exec
fs: exec: <parameters>
fs: exec: <parameters> ;; <code>
Parameters:
file = <script> ; with = <config>
file
(optional) F# script filewith
(optional) configuration file
The exec
command invokes a script or F# code with the specified or default configuration.
The default is *.fs.ini
in the script folder or the active panel.
If there is none then the main configuration is used.
Examples:
fs: exec: file = Script1.fsx
fs: exec: file = Module1.fs ;; Module1.test "answer" 42
fs: exec: with = %TryPanelFSharp%\TryPanelFSharp.fs.ini ;; TryPanelFSharp.run ()
The first two commands evaluate the specified files on every call. The last
command loads files specified by the configuration once, then it just runs
the code after ;;
.
Sample file association:
A file mask or several file masks:
*.fsx;*.fs
Description of the association:
F# script
─────────────────────────────────────
[x] Execute command (used for Enter):
fs: exec: file="!\!.!"
[x] Execute command (used for Ctrl+PgDn):
fs: #load @"!\!.!"
compile
fs: compile: with = <config>
with
(optional) configuration file
Compiles a library (dll) with the specified or default configuration.
The default is *.fs.ini
in the active panel.
The command is used for making FarNet scripts or modules without installing anything else. But it may create any .NET libraries, not just for FarNet.
Configuration notes:
- At least one source file must be specified.
- The section
[out]
may specify{-o|--out}:<file.dll>
but if it is omitted then the FarNet script is assumed with its name derived from configuration or its folder.
project
fs: project: open = VS|VSCode; type = Normal|Script; with = <config>
Generates and opens F# project from the specified or default configuration.
The default is *.fs.ini
in the active panel.
Parameters:
open
(optional) tells how to open the project:VS
(default) for Visual StudioVSCode
for Visual Studio Code
type
(optional) specifies the project type:Normal
(default) for the default output or specified by[out]
Script
for%FARHOME%\FarNet\Scripts\<name>\<name>.dll
with
(optional) specifies the configuration file.
See also: Projects
Configuration
Each interactive session is associated with its configuration file path. If the
configuration is not specified then the default is used. The default is first
*.fs.ini
in the active panel, in alphabetical order. If there is none then
the main configuration is used: %FARPROFILE%\FarNet\FSharpFar\main.fs.ini.
Source file services use configuration files in source directories. If they are not found then the main configuration is used.
In commands with configurations (fs: //... with=...
)
you may specify configuration directory instead of file.
If you change configurations in Far Manager editors then affected sessions are closed automatically.
If you change them externally then you may need to reset affected sessions manually.
The configuration file format is similar to INI, with sections and options.
Empty lines and lines staring with ;
are ignored.
Available sections
[fsc]
This is the main section. It defines F# Compiler Options and source files. This section is often enough. Other sections may add extra or override defined options.
The specified paths may be absolute and relative with environment %variables% expanded.
Important: relative paths for -r|--reference
must start with dot(s) (".\
" or "..\
"),
otherwise they are treated as known assembly names like -r:System.ComponentModel.Composition
.
; Main section
[fsc]
--warn:4
--optimize-
--debug:full
--define:DEBUG
-r:%MyLib%\Lib1.dll
-r:..\packages\Lib2.dll
-r:System.ComponentModel.Composition
File1.fs
File2.fs
[out]
This section defines sources and options for fs: compile:
, and fs: project:
.
The output target {-o|--out}:<file.dll>
is respected by fs: compile:
and
fs: project: type=Normal
. If it is missing then the FarNet script target
location is assumed with the script name derived either from the
configuration file or its directory.
Example: TryPanelFSharp - how to make FarNet modules from sources.
; Build FarNet module TryPanelFSharp
[out]
Module.fs
-o:%FARHOME%\FarNet\Modules\TryPanelFSharp\TryPanelFSharp.dll
Options -a
and --target
are ignored, --target:library
is always used.
[use]
This section tells to include other configuration files, one per line, using relative or absolute paths. Thus, the current session may be easily composed from existing "projects" with some additional settings and files.
; Use the main configuration in this configuration
[use]
%FARPROFILE%\FarNet\FSharpFar\main.fs.ini
[fsi]
This section defines F# Interactive Options and source files used for interactive sessions and evaluating scripts.
--use
files are particularly useful for interactive commands. They normally
open frequently used namespaces and modules and define some helper functions
and variables.
; My predefined stuff for interactive
[fsi]
--use:Interactive.fsx
[etc]
This section defines options for "Editor Tips and Checks", hence the name.
It is useful in some cases, e.g. --define:DEBUG
is used in [etc]
for
tips and checks in #if DEBUG
code blocks.
Preprocessing
The specified paths are preprocessed as follows:
- Environment variables specified as
%VARIABLE%
are expanded to their values. - The variable
%$Version%
is replaced with common language runtime version. __SOURCE_DIRECTORY__
is replaced with the configuration file directory.- Not rooted paths are treated as relative to the configuration directory.
Predefined
Some F# compiler settings are predefined:
--lib
: %FARHOME%--reference
: FarNet.dll, FarNet.FSharp.dll, FSharpFar.dll
The compiler symbol FARNET
is defined on using with FSharpFar.
It is not defined in other cases, for example with fsx.exe.
Use #if FARNET
or #if !FARNET
for conditional compilation:
#if FARNET
// code for FSharpFar and FarNet
#else
// code for fsx.exe or fsi.exe
#endif
Troubleshooting
Mistakes in configurations cause session loading errors, often without much useful information. Check your configuration files:
- All the specified paths should be resolved to existing targets.
- Relative
-r|--reference
paths must start with.\
or..\
. - Interactive options are specified in
[fsi]
, not in[fsc]
. - Output options are specified in
[out]
, not in[fsc]
.
F# scripts and configurations
- Scripts, i.e.
*.fsx
files, should not be added to configurations, except--use
in[fsi]
. - Scripts may use
#I
,#r
,#load
directives instead of or in addition to configurations. - Configurations understand environment variables, script directives do not.
- Configurations may specify compiler options, scripts cannot do this.
Session source and use-files
Source and use-files (--use
) are used in order to load the session for checks and interactive work.
Use-files are invoked in the session as if they are typed interactively. The goal is to prepare the session for interactive work and reduce typing, i.e. open modules and namespaces, define some functions and values, etc.
Sample use-file:
// reference assemblies
#r "MyLib.dll"
// namespaces and modules
open FarNet
open System
// definitions for interactive
let show text = far.Message text
Projects
With a configuration file *.fs.ini
, use the following command in order to
generate *.fsproj
with the source files and open it by the associated program
(usually Visual Studio) or by VSCode:
fs: project: open=VS|VSCode; type=Normal|Script; with=<config>
VSCode should have installed the F# extension.
If type=Normal
and the configuration specifies the output section, the
generated project is configured accordingly. This may be used for building,
running, and debugging FarNet modules from sources.
Example: TryPanelFSharp - how to make FarNet modules from sources.
If type=Script
the output is %FARHOME%\FarNet\Scripts\<name>\<name>.dll
where <name>
is inferred from the configuration or its folder.
Without the configured output generated projects are still useful for working with sources in a more powerful IDE. You may build to make sure everything is correct but normally code checkers show errors quite well without building. Edit sources, save, switch to Far Manager (no restart needed), and invoke.
Generated projects include:
- References to FarNet and FSharpFar assemblies.
- References to assemblies in the
[fsc]
section. *.fs
source files in[fsc]
and[out]
.- Other
*.fs
files in the current panel. *.fsx
scripts in the current panel.
Generated projects are %TEMP%\_Project_X\Y.fsproj
where X and Y are based on
the configuration file and its parent directory names.
Associate .fsproj with Visual Studio 2022
On problems with associating .fsproj files with Visual Studio 2022, use this registry tweak:
HKEY_CLASSES_ROOT\fsproj_auto_file\shell\open\command
"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe" "%1"
Debugging
Direct script debugging is not possible because FSharp.Compiler.Service 38.0+ does not support this
For debugging, use temporary FarNet scripts or modules, see Projects.
Consider developing complex code as FarNet scripts and debug when needed. Then reference script assemblies and call their methods from F# scripts.
Interactive
F# interactive is the editor session for evaluating one or more lines of code.
Use [ShiftEnter]
for evaluating and [Tab]
for code completion. The output
of evaluated code is appended to the end with the text markers (*(
and )*)
.
The structure of interactive text in the editor:
< old F# code, use [ShiftEnter] to add it to new >
(*(
<standard output and error text from code, i.e. from printf, eprintf>
<output text from evaluator, i.e. loading info, types, and values>
<error stream text from evaluator>
<errors and warnings>
<exceptions>
)*)
< new F# code, use [ShiftEnter] to evaluate >
< end of file, next (*( output )*) >
Use [F5]
to show the interactive history.
The history list keys:
[Enter]
- append code to the interactive.[Del]
,[CtrlR]
- tidy up the history.- Other keys are for incremental filtering.
Note, interactive sessions are closed automatically when you edit and save configuration and source files in the same Far Manager or projects opened by "Project" from the same Far Manager. On editing files externally you may need to reset affected sessions manually.
Editor services
Editor services are automatically available for F# files opened in editors. If
files are not self-contained then use the configuration file *.fs.ini
in the
same directory. Specify source files and references, normally in [fsc]
.
Code completion
Use [Tab]
in order to complete code.
Source completion is based on the current file content and the configuration.
Interactive completion is based on the current session and its configuration.
Code evaluation
Use [F5]
or [F11]
\ FSharpFar
\ Load
in order to evaluate the file.
The file is automatically saved before loading.
The output is shown in a new editor.
Type info tips
Use [F11]
\ FSharpFar
\ Tips
in order to get type tips for the symbol at the caret.
Use [F11]
\ FSharpFar
\ Enable|Disable auto tips
in order to toggle auto tips on mouse moves over symbols.
Code issues
Use [F11]
\ FSharpFar
\ Check
in order to check the file for syntax and type errors.
Use [F11]
\ FSharpFar
\ Errors
in order to show the menu with the last check errors.
Use [F11]
\ FSharpFar
\ Enable|Disable auto checks
in order to toggle auto checks on typing.
Found errors and warnings are highlighted in the editor and kept until the editor text changes. Error messages are automatically shown when the mouse hovers over highlighted error areas.
To change highlighting colors, edit module settings:
[F11]
\ FarNet
\ Settings
\ FSharpFar\Settings
.
Symbol uses
Use [F11]
\ FSharpFar
\ Uses in file
and Uses in project
in order to
get definitions and references of the symbol at the caret. Same file uses are
shown as a go to menu. Project uses are shown in a new editor.
Using F# scripts
(See /samples for some example scripts.)
How to run F# script tools in Far Manager?
Running as commands
fs: exec: [file = <script>] [; with = <config>] [;; F# code]
Commands in Far Manager may be invoked is several ways:
- Typed in the panels command line.
- Typed in the "Invoke" input box.
- Stored in user menus.
- Stored in file associations.
- Invoked by macros bound to keys.
The first two option are available right away. In panels type commands in the
command line. In other areas use the menu F11
\ FarNet
\ Invoke
to open
the command input box.
Other ways need some work for defining and storing commands. But then commands are invoked without typing.
F# scripts in user menus
fs:
commands are easily added, edited, and called from the user menus.
By design, the user menu is available just in panels and opened by [F2]
.
NOTE: The main or custom user menus can be opened in other areas by macros
using mf.usermenu
. For the details about macros see Far Manager manuals.
F# scripts in file associations
Associate commands running F# scripts with their file extensions or more complex masks.
Use F9
\ Commands
\ File associations
, for example:
A file mask or several file masks:
*.fsx;*.fs
Description of the association:
F# Far script
─────────────────────────────────────
[x] Execute command (used for Enter):
fs: exec: file="!\!.!"
[x] Execute command (used for Ctrl+PgDn):
fs: #load @"!\!.!"
F# scripts assigned to keys
F# scripts may be assigned to keys using Far Manager macros. Example:
Macro {
area="Common"; key="CtrlShiftF9"; description="F# MyScript";
action=function()
Plugin.Call("10435532-9BB3-487B-A045-B0E6ECAAB6BC", [[fs: exec: file=C:\Scripts\Far\MyScript.fsx]])
end;
}
Using fsx.exe tool
The included fsx.exe
may be used for running
scripts or interactive sessions without Far Manager.
fsx.exe
does not depend on FarNet, FSharpFar, and Far Manager.
It just uses F# services installed with FSharpFar.
Comparing to the official F# interactive, fsx.exe
supports *.fs.ini
configurations and includes minor interactive improvements.
Usage
fsx.exe [*.ini] [options] [script [arguments]]
If the first argument is like *.ini
then it is treated as the configuration
file for F# compiler options, references, and sources from the [fsc]
section.
Other arguments are F# Interactive Options.
If the configuration is omitted then fsx.exe
looks for *.fs.ini
in the last
specified source file directory, or the current directory for a command without
sources.
Script environment and arguments
The environment variable %FARHOME%
is set to the fsx.exe
directory.
This variable may be used in configuration files for items "portable with Far Manager".
Script arguments specified in the command line are available as the array
fsi.CommandLineArgs
. The first item is the script name, others are script
arguments.
Note that if a script is invoked in FSharpFar then arguments are not used.
fsi.CommandLineArgs
is available but it contains just a dummy string.
Conditional compilation may be used for separating FarNet code from exclusively
designed for fsx
or fsi
. Use #if FARNET
or #if !FARNET
directives.
See /samples/fsx-sample.
FSharpFar packages
These packages are libraries for F# scripting using FSharpFar and fsx.
They are installed in the same way as FarNet modules but they are different.
The directory is %FARHOME%\FarNet\Lib
instead of %FARHOME%\FarNet\Modules
.
Once installed, the content of such packages is portable with Far Manager.
Each package has its *.ini
file for use in other F# configuration files.
-
FarNet friendly FSharp.Charting extension, see /samples.
The alternative package: FarNet.ScottPlot. It is suitable for all modules (C#, F#) and scripts (F#, PowerShell, JavaScript).
-
FSharp.Data package for FarNet.FSharpFar see /samples.
-
F# friendly PowerShell extension, see /samples.
-
Easy and handy assert expressions for tests, see /samples.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
4.1.0 | 83 | 11/16/2024 |
4.0.1 | 328 | 2/29/2024 |
4.0.0 | 337 | 11/19/2023 |
3.1.1 | 420 | 10/25/2023 |
3.1.0 | 355 | 10/13/2023 |
3.0.1 | 645 | 1/1/2023 |
3.0.0 | 473 | 11/18/2022 |
2.0.14 | 487 | 11/4/2022 |
2.0.13 | 488 | 11/1/2022 |
2.0.12 | 487 | 10/7/2022 |
2.0.11 | 484 | 10/5/2022 |
2.0.10 | 561 | 9/19/2022 |
2.0.9 | 504 | 9/4/2022 |
2.0.8 | 561 | 8/27/2022 |
2.0.7 | 564 | 8/25/2022 |
2.0.6 | 568 | 8/22/2022 |
2.0.5 | 501 | 8/18/2022 |
2.0.4 | 584 | 7/31/2022 |
2.0.3 | 587 | 7/31/2022 |
2.0.2 | 597 | 7/27/2022 |
2.0.1 | 561 | 7/26/2022 |
2.0.0 | 527 | 7/19/2022 |
1.17.2 | 588 | 5/12/2022 |
1.17.1 | 619 | 3/9/2022 |
1.17.0 | 1,087 | 12/3/2021 |
1.16.3 | 2,866 | 11/25/2021 |
1.16.2 | 420 | 11/17/2021 |
1.16.1 | 424 | 11/11/2021 |
1.16.0 | 474 | 11/4/2021 |
1.15.1 | 539 | 7/28/2021 |
1.15.0 | 531 | 2/11/2021 |
1.14.0 | 543 | 1/1/2021 |
1.13.6 | 550 | 12/26/2020 |
1.13.5 | 539 | 12/24/2020 |
1.13.4 | 608 | 12/21/2020 |
1.13.3 | 594 | 11/27/2020 |
1.13.1 | 574 | 10/28/2020 |
1.13.0 | 549 | 10/26/2020 |
1.12.0 | 614 | 7/28/2020 |
1.11.4 | 595 | 7/24/2020 |
1.11.3 | 531 | 7/21/2020 |
1.11.2 | 587 | 7/15/2020 |
1.11.1 | 719 | 7/11/2020 |
1.11.0 | 586 | 7/10/2020 |
1.10.8 | 605 | 7/3/2020 |
1.10.7 | 602 | 6/29/2020 |
1.10.6 | 638 | 6/24/2020 |
1.10.5 | 695 | 6/22/2020 |
1.10.4 | 569 | 6/18/2020 |
1.10.3 | 677 | 6/14/2020 |
1.10.2 | 648 | 6/9/2020 |
1.10.1 | 597 | 6/8/2020 |
1.10.0 | 616 | 6/5/2020 |
1.9.21 | 623 | 6/1/2020 |
1.9.20 | 663 | 5/29/2020 |
1.9.19 | 642 | 5/13/2020 |
1.9.18 | 645 | 3/17/2020 |
1.9.17 | 616 | 3/5/2020 |
1.9.16 | 761 | 2/24/2020 |
1.9.15 | 649 | 2/6/2020 |
1.9.14 | 732 | 1/29/2020 |
1.9.13 | 642 | 1/23/2020 |
1.9.12 | 696 | 12/10/2019 |
1.9.11 | 626 | 11/9/2019 |
1.9.10 | 637 | 10/1/2019 |
1.9.9 | 735 | 8/13/2019 |
1.9.8 | 684 | 8/9/2019 |
1.9.7 | 687 | 7/2/2019 |
1.9.6 | 760 | 5/28/2019 |
1.9.5 | 791 | 3/31/2019 |
1.9.4 | 708 | 2/28/2019 |
1.9.3 | 738 | 2/21/2019 |
1.9.2 | 804 | 2/16/2019 |
1.9.1 | 779 | 2/10/2019 |
1.9.0 | 802 | 2/2/2019 |
1.8.2 | 972 | 1/28/2019 |
1.8.1 | 997 | 1/10/2019 |
1.8.0 | 1,063 | 1/2/2019 |
1.7.0 | 890 | 12/15/2018 |
1.6.2 | 967 | 10/14/2018 |
1.6.1 | 939 | 9/9/2018 |
1.6.0 | 1,040 | 9/2/2018 |
1.5.7 | 1,012 | 8/25/2018 |
1.5.6 | 1,148 | 6/12/2018 |
1.5.5 | 1,106 | 4/2/2018 |
1.5.4 | 1,294 | 3/24/2018 |
1.5.3 | 1,160 | 3/17/2018 |
1.5.2 | 1,248 | 1/3/2018 |
1.5.1 | 1,072 | 9/15/2017 |
1.5.0 | 1,060 | 9/11/2017 |
1.4.2 | 1,035 | 9/7/2017 |
1.4.1 | 1,075 | 8/30/2017 |
1.4.0 | 1,033 | 8/26/2017 |
1.3.0 | 1,123 | 8/20/2017 |
1.2.8 | 1,164 | 5/17/2017 |
1.2.7 | 1,148 | 2/23/2017 |
1.2.6 | 1,130 | 2/13/2017 |
1.2.5 | 1,122 | 2/10/2017 |
1.2.4 | 1,217 | 1/24/2017 |
1.2.3 | 1,265 | 1/2/2017 |
1.2.2 | 1,121 | 12/28/2016 |
1.2.1 | 1,178 | 12/25/2016 |
1.2.0 | 1,218 | 12/18/2016 |
1.1.0 | 1,220 | 12/15/2016 |
1.0.4 | 1,177 | 12/12/2016 |
1.0.3 | 1,201 | 11/29/2016 |
1.0.2 | 1,153 | 11/10/2016 |
1.0.1 | 1,260 | 11/3/2016 |
1.0.0 | 1,186 | 10/24/2016 |
0.10.0 | 1,176 | 10/11/2016 |
0.9.0 | 1,161 | 10/1/2016 |
0.8.1 | 1,148 | 9/28/2016 |
0.8.0 | 1,451 | 9/26/2016 |
0.7.1 | 1,138 | 9/24/2016 |
0.7.0 | 1,260 | 9/22/2016 |
0.6.0 | 1,429 | 9/19/2016 |
0.5.0 | 1,340 | 9/18/2016 |
0.4.1 | 1,109 | 9/15/2016 |
0.4.0 | 1,148 | 9/14/2016 |
0.3.4 | 1,170 | 9/10/2016 |
0.3.3 | 1,132 | 9/8/2016 |
0.3.2 | 1,115 | 9/7/2016 |
0.3.1 | 1,096 | 9/6/2016 |
0.3.0 | 1,130 | 9/5/2016 |
0.2.0 | 1,106 | 9/3/2016 |
0.1.0 | 1,166 | 8/28/2016 |
0.0.2 | 1,164 | 8/26/2016 |
0.0.1 | 1,201 | 8/24/2016 |