Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# ckgrep - a grep-like tool for searching CHEMKIN reaction mechanisms
#
# Build options:
# BUILD_TESTING Build the test suite (default ON, target: ckgrep_tests)
# BUILD_DOC Enable the Doxygen PDF manual (default OFF, target: docs)
# ENABLE_COVERAGE Clang source-based coverage (default OFF, target: coverage)
# BUILD_TESTING Build the test suite (default ON, target: ckgrep_tests)
# BUILD_DOC Enable the Doxygen PDF manual (default OFF, target: docs)
# ENABLE_COVERAGE Clang source-based coverage (default OFF, target: coverage)
# INSTALL_VIM_PLUGIN Install the Vim/Neovim plugin (default OFF)
#
# Layout:
# source/ core library + ckgrep executable
Expand All @@ -15,7 +16,7 @@
cmake_minimum_required(VERSION 3.20)
project(
ckgrep
VERSION 1.1.1
VERSION 1.1.2
LANGUAGES CXX
DESCRIPTION "A grep-like tool for searching CHEMKIN reaction mechanisms"
)
Expand Down Expand Up @@ -46,6 +47,16 @@ if(BUILD_DOC)
include(cmake/Documentation.cmake)
endif()

# Opt-in install of the Vim/Neovim plugin alongside the binary (see editor/vim)
option(
INSTALL_VIM_PLUGIN
"Install the Vim/Neovim plugin into <prefix>/share/ckgrep/vim"
OFF
)
if(INSTALL_VIM_PLUGIN)
include(cmake/VimPlugin.cmake)
endif()

# Tests are on by default; -DBUILD_TESTING=OFF also skips fetching googletest
option(BUILD_TESTING "Build the ckgrep test suite" ON)
if(BUILD_TESTING)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The `ckgrep` binary is produced at `build/source/ckgrep`.
| `BUILD_TESTING` | `ON` | Build the test suite (`ckgrep_tests`), run with `ctest`. |
| `BUILD_DOC` | `OFF` | Enable the `docs` target building the PDF manual. |
| `ENABLE_COVERAGE` | `OFF` | Instrument for coverage and enable the `coverage` target (Clang/AppleClang only). |
| `INSTALL_VIM_PLUGIN` | `OFF` | Install the [Vim/Neovim plugin](editor/vim) into `<prefix>/share/ckgrep/vim`. |

### Tests

Expand Down Expand Up @@ -74,7 +75,7 @@ cmake --install build # system prefix, e.g. /usr/local
cmake --install build --prefix "$HOME/.local" # custom prefix
```

Installs the `ckgrep` binary into `<prefix>/bin`, and the LICENSE — plus the PDF manual when it has been built — into `<prefix>/share/doc/ckgrep/`.
Installs the `ckgrep` binary into `<prefix>/bin`, and the LICENSE — plus the PDF manual when it has been built — into `<prefix>/share/doc/ckgrep/`. With `-DINSTALL_VIM_PLUGIN=ON`, the [Vim/Neovim plugin](editor/vim) is installed too, into `<prefix>/share/ckgrep/vim/` — see [its README](editor/vim/README.md#from-a-cmake-install) for pointing a plugin manager at it.

## Usage

Expand Down
23 changes: 23 additions & 0 deletions cmake/VimPlugin.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -----------------------------------------------------------------------------
# Installs the Vim/Neovim plugin (editor/vim) into
# <prefix>/share/ckgrep/vim/{plugin,autoload,doc}, so a plugin manager can
# point straight at an installed prefix instead of a git checkout, e.g. with
# lazy.nvim:
#
# {
# dir = "<prefix>/share/ckgrep/vim",
# name = "vim-ckgrep",
# cmd = "Ckgrep",
# init = function()
# vim.g.ckgrep_executable = "<prefix>/bin/ckgrep"
# end,
# }
# -----------------------------------------------------------------------------
include(GNUInstallDirs)
install(
DIRECTORY
${PROJECT_SOURCE_DIR}/editor/vim/plugin
${PROJECT_SOURCE_DIR}/editor/vim/autoload
${PROJECT_SOURCE_DIR}/editor/vim/doc
DESTINATION ${CMAKE_INSTALL_DATADIR}/ckgrep/vim
)
28 changes: 28 additions & 0 deletions editor/vim/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,34 @@ let g:ckgrep_executable = '/opt/ckgrep/bin/ckgrep'

The plugin lives in the `editor/vim` subdirectory of the ckgrep repository.

### From a CMake install

Building `ckgrep` from source with `-DINSTALL_VIM_PLUGIN=ON` installs this
plugin into `<prefix>/share/ckgrep/vim/` alongside the binary in
`<prefix>/bin/`, so a plugin manager can point straight at the installed
prefix instead of a separate git checkout:

```bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DINSTALL_VIM_PLUGIN=ON
cmake --build build
cmake --install build --prefix "$HOME/.tools/ckgrep"
```

With [lazy.nvim](https://github.com/folke/lazy.nvim):

```lua
{
dir = vim.fn.expand("~/.tools/ckgrep/share/ckgrep/vim"),
name = "vim-ckgrep",
cmd = "Ckgrep",
init = function()
vim.g.ckgrep_executable = vim.fn.expand("~/.tools/ckgrep/bin/ckgrep")
end,
}
```

### From a git checkout

With [vim-plug](https://github.com/junegunn/vim-plug):

```vim
Expand Down
2 changes: 1 addition & 1 deletion editor/vim/autoload/ckgrep.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function! ckgrep#search(bang, args) abort

" -H forces the file name on every hit so quickfix entries can jump; the
" pipe makes ckgrep emit plain (uncolored) output on its own.
let l:out = systemlist(l:exe . ' -H ' . l:args)
let l:out = systemlist(shellescape(l:exe) . ' -H ' . l:args)

if v:shell_error == 2
" Malformed query: ckgrep printed the reason on one line.
Expand Down
Loading