Plugins β> Plugin Admin... β> NppExec β> Install
<Notepad++>/plugins/NppExec/
and the Plugins β> NppExec
menu item will Plugins β> NppExec
LLVM-XXX-rYYYYYY-win64.exe
. The whole package can not be installed, it is enough to extract the file clang-format.exe
. You can use 7-zip: delete the .exe
extension from the .exe
, open the file with 7-zip and extract the clang-format.exe
file from the bin/
subdirectory bin/
. We place the file clang-format.exe
in the <Notepad++>/plugins/NppExec/clang-format/
directory..clang-format
or _clang-format
. They contain a set of rules (styles) of formatting, the format of which is described in the ClangFormat Style Options manual..clang-format
files downloaded from GitHub are placed in the appropriate directories:<Notepad++>/plugins/NppExec/clang-format/LINUX_KERNEL/
<Notepad++>/plugins/NppExec/clang-format/QT/
Plugins β> NppExec β> Execute...
or press F6
. Copy and paste the script text below into the window and save the script called clang-format
with the Save...
button. // Hide console NPP_CONSOLE 0 //------------------------------------------------------------------------------ // Uncomment a line to select a style //set style = LINUX_KERNEL set style = QT //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ set clangformatexe = $(CWD)\plugins\NppExec\clang-format\clang-format.exe set clangformatcfgdir = $(CWD)\plugins\NppExec\clang-format set tmpdir = $(SYS.TEMP) set clangformatcfgfile = $(clangformatcfgdir)\$(style)\.clang-format set srcfiletmp = $(tmpdir)\~src.tmp //------------------------------------------------------------------------------ cmd.exe /c if exist "$(clangformatexe)" (exit 0) else (exit 1) if $(EXITCODE) != 0 then NPP_CONSOLE 1 echo ERROR: "$(clangformatexe)" not found exit endif cmd.exe /c if exist "$(clangformatcfgfile)" (exit 0) else (exit 1) if $(EXITCODE) != 0 then NPP_CONSOLE 1 echo ERROR: "$(clangformatcfgfile)" not found exit endif // Copy $(clangformatcfgfile) to $(tmpdir)\.clang-format if their temestamps are different cmd.exe /v /c " for %i in ("$(clangformatcfgfile)") do set date1="%~ti" && for %i in ("$(tmpdir)\.clang-format") do set date2="%~ti" && if not "!date1!"=="!date2!" ( echo !date1! != !date2! && echo COPYING $(clangformatcfgfile) to $(tmpdir)\ && copy "$(clangformatcfgfile)" "$(tmpdir)\" /Y )" if $(EXITCODE) != 0 then NPP_CONSOLE 1 echo ERROR copying "$(clangformatcfgfile)" to "$(tmpdir)" exit endif // Get selected text length sci_sendmsg SCI_GETSELTEXT // If nothing is selected - select the current line if $(MSG_RESULT) == 1 then sci_sendmsg SCI_VCHOMEWRAP sci_sendmsg SCI_LINEENDWRAPEXTEND endif // Save selected text to $(srcfiletmp) sel_saveto "$(srcfiletmp)" :a cmd.exe /c if exist "$(srcfiletmp)" (exit 0) else (exit 1) if $(EXITCODE) != 0 then NPP_CONSOLE 1 echo ERROR: "$(srcfiletmp)" not found exit endif // Run ClangFormat $(clangformatexe) -i -style=file "$(srcfiletmp)" if $(EXITCODE) != 0 then NPP_CONSOLE 1 echo ERROR running "$(clangformatexe)" exit endif // Replace selected text with $(srcfiletmp) sel_loadfrom "$(srcfiletmp)" // Delete $(srcfiletmp) file cmd.exe /c del "$(srcfiletmp)"
style
variable, selects the required .clang-format
file, checks the date of its change and, if necessary, copies it to a temporary directory. There, the selected fragment of the source code is copied to the temporary file, after which clang-format.exe
. The formatted fragment is copied back to the Notepad ++ window. Then the temporary file is deleted..clang-format
configuration file. ClangFormat will search for it in the directory of the formatted file and, if it does not find it, will go to the search in the parent directories. After the script is .clang-format
file will remain in the temporary directory in order not to copy it every time you start formatting.Plugins β> NppExec β> Advanced Options...
, select the name of the clang-format
script in the drop-down list of the Associated script
and click on the Add/Modify
button.Plugins β> NppExec β> clang-format
will appear.Ctrl + I
combination by analogy with QtCreator. Open Settings β> Shortcut Mapper
.Ctrl + I
combination is busy, so you need to release it with the Clear
button in the Main Menu
tab (line 38 Split Lines
in the current version of Notepad ++). After that, in the tab Plugin commands
assign the Ctrl + I
combination to the clang-format
script.Ctrl + I
If nothing is selected, the current line will be formatted.Ctrl + Z
)..clang-format
configuration files in the <Notepad++>/plugins/NppExec/clang-format/
directory <Notepad++>/plugins/NppExec/clang-format/
set clangformat = "\path\to\clang-format.exe"
F6
and in the text of the clang-format
script, select the desired style by uncommenting one of the linesset style = STYLE_NAME
.Source: https://habr.com/ru/post/457972/
All Articles