file-exec(3)file-exec - Executes the current buffer using a compiler or interpreter
file-format - Format the current buffer using a dedicated formatter
file-lint - check the current buffer for problems using a dedicated linter
major-mode-tools-setup - File major-mode tool setup
file-exec [ "command-line-arguments" ]
file-format
file-lint
major-mode-tools-setup
The file-exec macro for interpreted languages executes the current buffer using the command line interpreter defined for this language. In case of programming languages which needs to be compiled, first the code is compiled to machine code and then executed. Before the program is executed save-some-buffers(2) is executed to allow the user to ensure that all relevant buffers are saved. If bit 0x01 of the numeric argument n is clear then all modified buffers are automatically saved, when set (the default) the user is prompted for each buffer. If bit 0x02 of the numeric argument is clear (the default) the user is prompted for any additional command-line-arguments which are passed to application or the script command. The arguments given are stored in a buffer variable, and used as the default arguments next time the script is executed.
After executing the program, an *FHOOK-exec* buffer is opened with the output of the script or program. The script executes the current buffer if required using the current MicroEmacs character encodings.
The file-format macro formats the current buffer using a dedicated formatting tool for the buffer's programming language. For R for example, the package `formatR` must be pre-installed by the user, this is typically done by running `install.packages('formatR')` within an R console.
The file-lint macro checks the currently edited file using a language specific linter, for example for R, the package `lintr` must be installed by the user for instance using the usual `install.packages('lintr)` syntax from within a R console.
The command opens an *FHOOK-lint* buffer with the output from the linter, warnings or styling issues raised are typically high-lighted. the buffer is configured to for get-next-line(2) to make traverse through the issues as easy as possible.
The major-mode-tools-setup command can be used to configure the three tools for the current file's major mode, this dialog can be accessed by clicking on the bottom left Tools button in the major-mode-setup(3) dialog. Note, however, that as the tool configurations should work with all files of the same major-mode, the command-lines should use tags (%l...) rather than literal file names. Of particular importance are the %f, %p and %" tags, for further details see the documentation for the Command field of file-tool-setup(3), which uses the same format.
For creators of MicroEmacs file hooks, the file tools can also support the use of multiple interpreters/tools, e.g. clang and gcc to compile a C file. The configuration of each tool can include tests to verify the availability of the tool on the current computer as well as the required command-line to run.
To get the command file-exec, file-format and file-lint properly working a setup for the relevant tools for the current buffer's programming language is usually required. The setting are stored in variables like for instance for the C++ programming language:
; regex for highlighting and making it click aware add-next-line "*cpp-exec*" "^%f:%l:\\d+.+" add-next-line "*cpp-lint*" "^%f:%l:\\d+.+" ; the compiler set-variable .fhook-cpp.coms "\bg++\b" ; try outs for execution, formatting and linting, if 1 is fine 2 is not tried ; fields are \bcompiler/tool\btest command line\b ; hilight error\bhilight warning\bcommand line\b ; line breaks with indentation follow ups are just for better display ; we check with %v[com].exe for the Windows platform to call the build ; with backslash instead of slash from the current directory set-variable .fhook-cpp.exec1 "\b%v[com]\b%v[com].exe -v\b\b\b %v[com] -Wall -O3 -std=c++17 \"%p%f\" -o %b %& .\%b %v[args|20|Additional command-line arguments|]\b" set-variable .fhook-cpp.exec2 "\b%v[com]\b%v[com] -v\b\b\b %v[com] -Wall -O3 -std=c++17 \"%p%f\" -o ./%b %& ./%b %v[args|20|Additional command-line arguments|]\b" set-variable .fhook-cpp.format1 "\bastyle\bastyle -h\b0\b\b astyle --indent=spaces=4 %\"%f%\"\bAstyle\b" set-variable .fhook-cpp.format2 "\bclang-format\bclang-format -h\b0\b\b clang-format \"%f\% -- -std=c++17\bClang-format\b" set-variable .fhook-cpp.lint1 "\b%v[com]\b%v[com] --version\b0\b\b %v[com] -Wall -x c++ -fsyntax-only \"%p%f\"\bG++\b" set-variable .fhook-cpp.lint2 "\bclang-tidy\bclang-tidy --version\b0\b\b clang-tidy \"%f\" -- -std=c++17\bClang-tidy\b"
file-exec, file-format and file-lint are macros defined in hktools.emf. For programming lanuages like C++, Fortran and R there are already useful variable defaults defined in the hkHOOK.emf files, the user can overwrite these settings using major-mode-tools-setup.
The executables or the interpreters must be usually installed and in the system path for the command to function correctly or the full path might be given in the variable settings.
get-next-line(2), file-tool-setup(3), major-mode-setup(3) c(9), cpp(9), f90(9), go(9), pas(9), perl(9), py(9), r(9), tcl(9).
(c) Copyright JASSPA 2025
Last Modified: 2025/11/28
Generated On: 2025/12/01