feat: first version of the plugin
This first version adds syntax highlighting to .jjdescription files
which are edited with (neo)vim after running |jj describe|. It also sets
adequate options such as setting a maximum line width of 72 characters
and wrapping text automatically.
More syntax highlighting will need to be added in the future.
Change-Id: I40dbf342d511872a05862e44297c153826b930a6
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6c5c05b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,78 @@
+VIM LICENSE
+
+I) There are no restrictions on distributing unmodified copies of Vim except
+ that they must include this license text. You can also distribute
+ unmodified parts of Vim, likewise unrestricted except that they must
+ include this license text. You are also allowed to include executables
+ that you made from the unmodified Vim sources, plus your own usage
+ examples and Vim scripts.
+
+II) It is allowed to distribute a modified (or extended) version of Vim,
+ including executables and/or source code, when the following four
+ conditions are met:
+ 1) This license text must be included unmodified.
+ 2) The modified Vim must be distributed in one of the following five ways:
+ a) If you make changes to Vim yourself, you must clearly describe in
+ the distribution how to contact you. When the maintainer asks you
+ (in any way) for a copy of the modified Vim you distributed, you
+ must make your changes, including source code, available to the
+ maintainer without fee. The maintainer reserves the right to
+ include your changes in the official version of Vim. What the
+ maintainer will do with your changes and under what license they
+ will be distributed is negotiable. If there has been no negotiation
+ then this license, or a later version, also applies to your changes.
+ The current maintainers are listed here: https://github.com/orgs/vim/people.
+ If this changes it will be announced in appropriate places (most likely
+ vim.sf.net, www.vim.org and/or comp.editors). When it is completely
+ impossible to contact the maintainer, the obligation to send him
+ your changes ceases. Once the maintainer has confirmed that he has
+ received your changes they will not have to be sent again.
+ b) If you have received a modified Vim that was distributed as
+ mentioned under a) you are allowed to further distribute it
+ unmodified, as mentioned at I). If you make additional changes the
+ text under a) applies to those changes.
+ c) Provide all the changes, including source code, with every copy of
+ the modified Vim you distribute. This may be done in the form of a
+ context diff. You can choose what license to use for new code you
+ add. The changes and their license must not restrict others from
+ making their own changes to the official version of Vim.
+ d) When you have a modified Vim which includes changes as mentioned
+ under c), you can distribute it without the source code for the
+ changes if the following three conditions are met:
+ - The license that applies to the changes permits you to distribute
+ the changes to the Vim maintainer without fee or restriction, and
+ permits the Vim maintainer to include the changes in the official
+ version of Vim without fee or restriction.
+ - You keep the changes for at least three years after last
+ distributing the corresponding modified Vim. When the maintainer
+ or someone who you distributed the modified Vim to asks you (in
+ any way) for the changes within this period, you must make them
+ available to him.
+ - You clearly describe in the distribution how to contact you. This
+ contact information must remain valid for at least three years
+ after last distributing the corresponding modified Vim, or as long
+ as possible.
+ e) When the GNU General Public License (GPL) applies to the changes,
+ you can distribute the modified Vim under the GNU GPL version 2 or
+ any later version.
+ 3) A message must be added, at least in the output of the ":version"
+ command and in the intro screen, such that the user of the modified Vim
+ is able to see that it was modified. When distributing as mentioned
+ under 2)e) adding the message is only required for as far as this does
+ not conflict with the license used for the changes.
+ 4) The contact information as required under 2)a) and 2)d) must not be
+ removed or changed, except that the person himself can make
+ corrections.
+
+III) If you distribute a modified version of Vim, you are encouraged to use
+ the Vim license for your changes and make them available to the
+ maintainer, including the source code. The preferred way to do this is
+ by e-mail or by uploading the files to a server and e-mailing the URL.
+ If the number of changes is small (e.g., a modified Makefile) e-mailing a
+ context diff will do. The e-mail address to be used is
+ <maintainer@vim.org>
+
+IV) It is not allowed to remove this license from the distribution of the Vim
+ sources, parts of it or from a modified version. You may use this
+ license for previous Vim releases instead of the license that they came
+ with, at your option.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ed98da1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,22 @@
+# .jjdescription files plugin for Vim
+This plugin adds syntax highlighting and some sensible options for
+.jjdescription files. These are temporary files created by [JJ][1] and opened
+in your configured editor when you run `jj describe`, so you can write a
+description for your change.
+
+## Installation
+Use your favorite plugin manager to install the `avm99963/vim-jjdescription`
+plugin. For instance, with [vim-plug][2] you should add the following to the
+appropriate section in your `.vimrc`:
+
+``` vimscript
+Plug 'avm99963/vim-jjdescription'
+```
+
+## Credits
+This plugin is based on the native syntax highlighting and ftplugin for
+gitcommit, which is the format of the analogous temporary files used by Git.
+This is the reason why this plugin is licensed with the Vim license.
+
+[1]: https://github.com/martinvonz/jj
+[2]: https://github.com/junegunn/vim-plug
diff --git a/ftdetect/jjdescription.vim b/ftdetect/jjdescription.vim
new file mode 100644
index 0000000..fd1f7a2
--- /dev/null
+++ b/ftdetect/jjdescription.vim
@@ -0,0 +1 @@
+au BufRead,BufNewFile *.jjdescription set filetype=jjdescription
diff --git a/ftplugin/jjdescription.vim b/ftplugin/jjdescription.vim
new file mode 100644
index 0000000..f45a55e
--- /dev/null
+++ b/ftplugin/jjdescription.vim
@@ -0,0 +1,21 @@
+" jjdescription filetype plugin
+" Language: jjdescription file
+" Maintainer: Adrià Vilanova <me@avm99963.com>
+" Source: Based on ftplugin/gitcommit.vim
+" Last Change: 2024 Jan 30
+
+" Only do this when not done yet for this buffer
+if (exists("b:did_ftplugin"))
+ finish
+endif
+
+let b:did_ftplugin = 1
+
+setlocal nomodeline tabstop=8 formatoptions+=tl textwidth=72
+setlocal formatoptions-=c formatoptions-=r formatoptions-=o formatoptions-=q formatoptions+=n
+setlocal formatlistpat=^\\s*\\d\\+[\\]:.)}]\\s\\+\\\|^\\s*[-*+]\\s\\+
+
+let b:undo_ftplugin = 'setl modeline< tabstop< formatoptions< tw< com< cms< formatlistpat<'
+
+let &l:comments = ':JJ: '
+let &l:commentstring = 'JJ: %s'
diff --git a/syntax/jjdescription.vim b/syntax/jjdescription.vim
new file mode 100644
index 0000000..de3de98
--- /dev/null
+++ b/syntax/jjdescription.vim
@@ -0,0 +1,52 @@
+" jjdescription syntax file
+" Language: jjdescription file
+" Maintainer: Adrià Vilanova <me@avm99963.com>
+" Filenames: *.jjdescription
+" Source: Based on syntax/gitcommit.vim
+" Last Change: 2024 Jan 30
+
+if exists("b:current_syntax")
+ finish
+endif
+
+scriptencoding utf-8
+
+syn case match
+syn sync minlines=50
+syn sync linebreaks=1
+
+if has("spell")
+ syn spell toplevel
+endif
+
+if get(g:, 'jjdescription_summary_length') < 0
+ syn match jjdescriptionSummary "^.*$" contained containedin=jjdescriptionFirstLine nextgroup=jjdescriptionOverflow contains=@Spell
+elseif get(g:, 'jjdescription_summary_length', 1) > 0
+ exe 'syn match jjdescriptionSummary "^.*\%<' . (get(g:, 'jjdescription_summary_length', 50) + 1) . 'v." contained containedin=jjdescriptionFirstLine nextgroup=jjdescriptionOverflow contains=@Spell'
+endif
+syn match jjdescriptionOverflow ".*" contained contains=@Spell
+syn match jjdescriptionBlank "^.\+" contained contains=@Spell
+syn match jjdescriptionFirstLine "\%^.*" nextgroup=jjdescriptionBlank,jjdescriptionComment skipnl
+
+syn match jjdescriptionComment "^JJ: .*"
+
+syn match jjdescriptionHeader "\%(^JJ: \)\@<=\S.*:\%(\n^$\)\@!$" contained containedin=jjdescriptionComment
+
+syn match jjdescriptionType "\%(^JJ:\s\+\)\@<=[MADR]\ze " contained containedin=jjdescriptionComment nextgroup=jjdescriptionFile skipwhite
+syn match jjdescriptionFile ".*" contained
+
+syn region jjdescriptionSelected start=/^\z(^JJ: \)This commit contains the following changes:$/ end=/^\z1$\|^\z1\@!/ contains=jjdescriptionHeader,jjdescriptionSelectedType containedin=jjdescriptionComment containedin=jjdescriptionComment contained transparent fold
+
+syn match jjdescriptionSelectedType "\%(^JJ:\s\+\)\@<=[MADR]\ze " contained nextgroup=jjdescriptionSelectedFile skipwhite
+syn match jjdescriptionSelectedFile ".*" contained
+
+hi def link jjdescriptionSummary Keyword
+hi def link jjdescriptionComment Comment
+hi def link jjdescriptionSelectedType jjdescriptionType
+hi def link jjdescriptionType Type
+hi def link jjdescriptionHeader PreProc
+hi def link jjdescriptionSelectedFile jjdescriptionFile
+hi def link jjdescriptionFile Constant
+hi def link jjdescriptionBlank Error
+
+let b:current_syntax = "jjdescription"