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
file-exec [ "command-line-arguments" ]
file-format
file-lint
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.
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 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 usually in the myHOOK.emf file or define their owns therin.
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.
(c) Copyright JASSPA 2025
Last Modified: 2025/07/30
Generated On: 2025/09/29