halfgaar / FlashMQ

FlashMQ is a fast light-weight MQTT broker/server, designed to take good advantage of multi-CPU environments
https://www.flashmq.org/
Open Software License 3.0
173 stars 24 forks source link

Generate vim syntax based on the documentation #99

Open quinox opened 1 month ago

quinox commented 1 month ago

Script for generating a fully up-to-date-and-correct vim syntax file based on the documentation.

Some notes:

How to use the generated file

Modify these instructions according to the flavor of vim you're using:

$ cat ~/.config/nvim/ftdetect/flashmq.vim
au BufNewFile,BufRead /etc/flashmq/*.conf,flashmq.conf         setf flashmq

$ ls -al ~/.config/nvim/syntax/flashmq.vim
/home/quinox/.config/nvim/syntax/flashmq.vim -> /home/quinox/projects/FlashMQ/man/flashmq.vim

Examples

flashmq_vim_good

flashmq_vim_bad

bigsmoke commented 1 month ago

I'm stoked to try this! 🎁

halfgaar commented 1 month ago

Great addition :+1:

I would like the .deb to install this globally. Step one is easy:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a1e7d49..0cad90f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -44,6 +44,7 @@ install(FILES flashmq.conf DESTINATION "/etc/flashmq")
 install(FILES debian/flashmq.service DESTINATION "/lib/systemd/system")
 install(FILES man/flashmq.conf.5 DESTINATION "/usr/share/man/man5")
 install(FILES man/flashmq.1 DESTINATION "/usr/share/man/man1")
+install(FILES man/flashmq.vim DESTINATION "/usr/share/vim/vimfiles/syntax")

And that installs it, even if the dir doesn't exist. From what I can tell, the vimfiles dir is for external installs. The vim82 (on my test system) is for what vim installs itself. Like nginx.vim, that is not provided by Nginx, but by vim.

But, I'm having issues getting the file type detection to work. I can edit /usr/share/vim/vim82/filetype.vim, but that makes no sense from a packaging perspective.

I'm also having a hard time to make the modeline work (# vim: set ft=flashmq). I would add it to the default config.

Also small note: I have to add a space after a keyword to make it green. I don't have to do that for Nginx config files.

quinox commented 1 month ago

I'm also having a hard time to make the modeline work (# vim: set ft=flashmq). I would add it to the default config.

This works for me, it switches syntax when I open the file:

# vim: set ft=flashmq:

bridge {
        listen 123
}

I can't offer more help, I never use that feature of vim. Double-check set modeline? and set modelines, or find out what limitations your vim flavor has when it comes to modeline.

Also small note: I have to add a space after a keyword to make it green. I don't have to do that for Nginx config files.

I see what you mean, yeah it's nice if that works. I pushed a fix for it. The problem is that I'm not using Keyword since it's too liberal for my taste. The solution was to add a second regular expression that matches a line ending with a directive.

bigsmoke commented 1 month ago

@halfgaar, Does your vim have the modeline option enabled? The modeline option is often disabled for root (or even globally) for security reasons. See, for example: https://superuser.com/a/1427691

More info in :help modelines

halfgaar commented 1 month ago

Note, @bigsmoke added a feature recently, now merged in master, which adds a listen and bridge option tcp_nodelay (two options). Because you prefixed stuff with listen__, that may need updating.

I haven't yet continued with my attempt to get the file type selection in order. I'd like to fix that for the .deb builds before I merge it in.