focus-editor / focus

A simple and fast text editor
GNU General Public License v3.0
1.81k stars 99 forks source link

Custom command on file saving #425

Open Flamaros opened 2 months ago

Flamaros commented 2 months ago

It would pretty nice to be able to execute custom command just before the file saving to be able to checkout the file on perforce by exemple.

Maybe some users may want to do this by file extensions for commands like linters, but for me it's more by project and if file is in read only state (I may check that in the custom command directly).

Some other features might helps here, like an easy way to copy the full path of the currently edited file.

focus-editor commented 2 months ago

There's currently a command Copy Current Line Info which copies the full path and the line number.

Would something like this be what you want?

[[hooks]]

[before save]
command:   ...
working_dir: ...
files: *.cpp *.h

[after save]
command:   ...
working_dir: ...
files: *.cpp *.h
Flamaros commented 2 months ago

Thx to point me the command for the line info.

Yes the format of hooks seems good, but I think that we also need some variables like: $relative_file_path (relative to the project path of file to save ?) $full_file_path (full path of file to save $working_directory $project_directory

Ex.

[[hooks]]

[before save]
command:   p4 synchronize $full_file_path
working_dir: $project_directory
files: *.cpp *.h
focus-editor commented 2 months ago

It will probably be a while before we get to this because there are other things higher up on the list.

Did you know you could use the build command system to achieve the same effect, with the only difference is that it would not auto-run on save but that you'd need to bind it to a key combination and execute explicitly?

There are variables available there already:

# %FILE%      - full path to currenly active file
# %FILE_DIR%  - the directory of the currently active file
# %FILE_NAME% - current file name, with extension
# %FILE_NAME_NO_EXTENSION% - current file name, without extension
# %BUILD_WORKING_DIR%  - working dir of the build command
# %RUN_WORKING_DIR%    - working dir of the run command
# %PROJECT_CONFIG_DIR% - the dir containing the active project config file
Flamaros commented 1 month ago

I tried that, on a personal project to trigger build, the navigation through errors is nice.