mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
build: build Vim plugin files for Ghostty config file
Generate Vim syntax and ftplugin files for the Ghostty config file that highlight Ghostty config keywords and offer completion for valid config keys. The list of configuration keys is generated at compile time. The plugin files are installed to ${prefix}/share/vim/vimfiles, which is a standard location for installing 3rd party Vim plugin files.
This commit is contained in:
108
build.zig
108
build.zig
@ -13,6 +13,7 @@ const LibtoolStep = @import("src/build/LibtoolStep.zig");
|
|||||||
const LipoStep = @import("src/build/LipoStep.zig");
|
const LipoStep = @import("src/build/LipoStep.zig");
|
||||||
const XCFrameworkStep = @import("src/build/XCFrameworkStep.zig");
|
const XCFrameworkStep = @import("src/build/XCFrameworkStep.zig");
|
||||||
const Version = @import("src/build/Version.zig");
|
const Version = @import("src/build/Version.zig");
|
||||||
|
const Config = @import("src/config/Config.zig");
|
||||||
|
|
||||||
// Do a comptime Zig version requirement. The required Zig version is
|
// Do a comptime Zig version requirement. The required Zig version is
|
||||||
// somewhat arbitrary: it is meant to be a version that we feel works well,
|
// somewhat arbitrary: it is meant to be a version that we feel works well,
|
||||||
@ -402,6 +403,113 @@ pub fn build(b: *std.Build) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Vim plugin
|
||||||
|
{
|
||||||
|
const wf = b.addWriteFiles();
|
||||||
|
|
||||||
|
// syntax/ghostty.vim
|
||||||
|
{
|
||||||
|
var buf = std.ArrayList(u8).init(b.allocator);
|
||||||
|
defer buf.deinit();
|
||||||
|
|
||||||
|
const writer = buf.writer();
|
||||||
|
try writer.print(
|
||||||
|
\\" Vim syntax file
|
||||||
|
\\" Language: Ghostty config file
|
||||||
|
\\" Maintainer: Ghostty <https://github.com/mitchellh/ghostty>
|
||||||
|
\\"
|
||||||
|
\\" THIS FILE IS AUTO-GENERATED
|
||||||
|
\\
|
||||||
|
\\if exists('b:current_syntax')
|
||||||
|
\\ finish
|
||||||
|
\\endif
|
||||||
|
\\
|
||||||
|
\\let b:current_syntax = 'ghostty'
|
||||||
|
\\
|
||||||
|
\\let s:cpo_save = &cpo
|
||||||
|
\\set cpo&vim
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
, .{});
|
||||||
|
|
||||||
|
const config_fields = @typeInfo(Config).Struct.fields;
|
||||||
|
var keywords = try std.ArrayList([]const u8).initCapacity(b.allocator, config_fields.len);
|
||||||
|
defer keywords.deinit();
|
||||||
|
|
||||||
|
inline for (config_fields) |field| {
|
||||||
|
// Ignore fields which begin with _
|
||||||
|
if (field.name[0] != '_') {
|
||||||
|
keywords.appendAssumeCapacity(field.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try writer.print(
|
||||||
|
\\syn keyword ghosttyConfigKeyword
|
||||||
|
\\ \ {s}
|
||||||
|
\\
|
||||||
|
\\syn match ghosttyConfigComment /#.*/ contains=@Spell
|
||||||
|
\\
|
||||||
|
\\hi def link ghosttyConfigComment Comment
|
||||||
|
\\hi def link ghosttyConfigKeyword Keyword
|
||||||
|
\\
|
||||||
|
\\let &cpo = s:cpo_save
|
||||||
|
\\unlet s:cpo_save
|
||||||
|
\\
|
||||||
|
, .{
|
||||||
|
try std.mem.join(b.allocator, "\n\t\\ ", keywords.items),
|
||||||
|
});
|
||||||
|
|
||||||
|
_ = wf.add("syntax/ghostty.vim", buf.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ftdetect/ghostty.vim
|
||||||
|
{
|
||||||
|
_ = wf.add(
|
||||||
|
"ftdetect/ghostty.vim",
|
||||||
|
"au BufRead,BufNewFile */.config/ghostty/config set ft=ghostty\n",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ftplugin/ghostty.vim
|
||||||
|
{
|
||||||
|
var buf = std.ArrayList(u8).init(b.allocator);
|
||||||
|
defer buf.deinit();
|
||||||
|
|
||||||
|
const writer = buf.writer();
|
||||||
|
try writer.writeAll(
|
||||||
|
\\" Vim filetype plugin file
|
||||||
|
\\" Language: Ghostty config file
|
||||||
|
\\" Maintainer: Ghostty <https://github.com/mitchellh/ghostty>
|
||||||
|
\\"
|
||||||
|
\\" THIS FILE IS AUTO-GENERATED
|
||||||
|
\\
|
||||||
|
\\if exists('b:did_ftplugin')
|
||||||
|
\\ finish
|
||||||
|
\\endif
|
||||||
|
\\let b:did_ftplugin = 1
|
||||||
|
\\
|
||||||
|
\\setlocal commentstring=#%s
|
||||||
|
\\setlocal iskeyword+=-
|
||||||
|
\\
|
||||||
|
\\" Use syntax keywords for completion
|
||||||
|
\\setlocal omnifunc=syntaxcomplete#Complete
|
||||||
|
\\
|
||||||
|
\\let b:undo_ftplugin = 'setl cms< isk< ofu<'
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
|
||||||
|
_ = wf.add("ftplugin/ghostty.vim", buf.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
const install_vim_plugin = b.addInstallDirectory(.{
|
||||||
|
.source_dir = wf.getDirectory(),
|
||||||
|
.install_dir = .prefix,
|
||||||
|
.install_subdir = "share/vim/vimfiles",
|
||||||
|
});
|
||||||
|
install_vim_plugin.step.dependOn(&wf.step);
|
||||||
|
b.getInstallStep().dependOn(&install_vim_plugin.step);
|
||||||
|
}
|
||||||
|
|
||||||
// App (Linux)
|
// App (Linux)
|
||||||
if (target.isLinux()) {
|
if (target.isLinux()) {
|
||||||
// https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html
|
// https://developer.gnome.org/documentation/guidelines/maintainer/integrating.html
|
||||||
|
Reference in New Issue
Block a user