Skip to content

Commit bdbeeba

Browse files
committed
feat: add vars for stdpath config and data
1 parent b352826 commit bdbeeba

File tree

4 files changed

+56
-43
lines changed

4 files changed

+56
-43
lines changed

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pilot.setup({
161161
placeholders = {
162162
vars = {
163163
-- example to add custom placeholders
164-
hello_world = function() return "Hello, World!" end,
164+
new_temp_file = function() return vim.fn.tempname() end,
165165
template_path = function() return pilot.utils.interpolate("{{pilot_data_path}}/templates") end,
166166
},
167167
},
@@ -261,21 +261,23 @@ running C source code files.
261261

262262
**Variables**
263263

264-
| Placeholder | Resolved value |
265-
| ---------------------------- | ---------------------------------------------------------------- |
266-
| `{{file_path}}` | Current buffer's absolute file path |
267-
| `{{file_path_relative}}` | Current buffer's file path relative to current working directory |
268-
| `{{file_name}}` | Current buffer's file name (file extension included) |
269-
| `{{file_name_no_extension}}` | Current buffer's file name without the file extension |
270-
| `{{file_type}}` | The Neovim file type of the current buffer (`vim.bo.filetype`) |
271-
| `{{file_extension}}` | File extension of current buffer's file name |
272-
| `{{dir_path}}` | Absolute path of the directory containing the current buffer |
273-
| `{{dir_name}}` | Name of the directory containing the current buffer |
274-
| `{{cwd_path}}` | Absolute path of the current working directory |
275-
| `{{cwd_name}}` | Directory name of the current working directory |
276-
| `{{pilot_data_path}}` | Absolute path to `vim.fn.stdpath("data") .. "/pilot"` |
277-
| `{{cword}}` | Word under the cursor |
278-
| `{{cWORD}}` | Complete word (between spaces) under the cursor |
264+
| Placeholder | Resolved value |
265+
| ---------------------------- | ---------------------------------------------------------------------------- |
266+
| `{{file_path}}` | Current buffer's absolute file path |
267+
| `{{file_path_relative}}` | Current buffer's file path relative to current working directory |
268+
| `{{file_name}}` | Current buffer's file name (file extension included) |
269+
| `{{file_name_no_extension}}` | Current buffer's file name without the file extension |
270+
| `{{file_type}}` | The Neovim file type of the current buffer (`vim.bo.filetype`) |
271+
| `{{file_extension}}` | File extension of current buffer's file name |
272+
| `{{dir_path}}` | Absolute path of the directory containing the current buffer |
273+
| `{{dir_name}}` | Name of the directory containing the current buffer |
274+
| `{{cwd_path}}` | Absolute path of the current working directory |
275+
| `{{cwd_name}}` | Directory name of the current working directory |
276+
| `{{config_path}}` | Absolute path to your Neovim configuration directory |
277+
| `{{data_path}}` | Absolute path to Neovim plugins data directory |
278+
| `{{pilot_data_path}}` | Absolute path to the pilot directory inside of Neovim plugins data directory |
279+
| `{{cword}}` | Word under the cursor |
280+
| `{{cWORD}}` | Complete word (between spaces) under the cursor |
279281

280282
**Modifier Functions**
281283

doc/pilot.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ EXAMPLE CONFIGURATION *pilot-example-configuration*
311311
placeholders = {
312312
vars = {
313313
-- example to add custom placeholders
314-
hello_world = function() return "Hello, World!" end,
314+
new_temp_file = function() return vim.fn.tempname() end,
315315
template_path = function() return pilot.utils.interpolate("{{pilot_data_path}}/templates") end,
316316
},
317317
funcs = {},
@@ -412,13 +412,12 @@ Simple placeholders that expand to a string. Define them in `placeholders.vars`
412412
as functions that return a string, and use them as `{{name}}` in config paths
413413
or commands.
414414

415-
--------------------------------------------------------------------------
415+
--------------------------------------------------------------------------------
416416
Placeholder Resolved value
417-
---------------------------- ---------------------------------------------
417+
---------------------------- ---------------------------------------------------
418418
{{file_path}} Current buffer’s absolute file path
419419

420-
{{file_path_relative}} File path relative to current working
421-
directory
420+
{{file_path_relative}} File path relative to current working directory
422421

423422
{{file_name}} File name (with extension)
424423

@@ -430,20 +429,24 @@ or commands.
430429

431430
{{dir_path}} Directory containing the current buffer
432431

433-
{{dir_name}} Name of the directory containing the current
434-
buffer
432+
{{dir_name}} Name of the directory containing the current buffer
435433

436-
{{cwd_path}} Absolute path of the current working
437-
directory
434+
{{cwd_path}} Absolute path of the current working directory
438435

439436
{{cwd_name}} Name of the current working directory
440437

441-
{{pilot_data_path}} Path to vim.fn.stdpath("data") .. "/pilot"
438+
{{config_path}} Absolute path to your Neovim configuration
439+
directory
440+
441+
{{data_path}} Absolute path to Neovim plugins data directory
442+
443+
{{pilot_data_path}} Absolute path to the pilot directory inside of
444+
Neovim plugins data directory
442445

443446
{{cword}} Word under the cursor
444447

445448
{{cWORD}} WORD under the cursor
446-
--------------------------------------------------------------------------
449+
--------------------------------------------------------------------------------
447450
**Modifier Functions**
448451

449452
Callable placeholders that accept an argument and return a string. Define them

docs/pilot.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pilot.setup({
274274
placeholders = {
275275
vars = {
276276
-- example to add custom placeholders
277-
hello_world = function() return "Hello, World!" end,
277+
new_temp_file = function() return vim.fn.tempname() end,
278278
template_path = function() return pilot.utils.interpolate("{{pilot_data_path}}/templates") end,
279279
},
280280
funcs = {},
@@ -376,21 +376,23 @@ Simple placeholders that expand to a string. Define them in
376376
`placeholders.vars` as functions that return a string, and use them as
377377
`{{name}}` in config paths or commands.
378378

379-
| Placeholder | Resolved value |
380-
| ---------------------------- | --------------------------------------------------- |
381-
| `{{file_path}}` | Current buffer's absolute file path |
382-
| `{{file_path_relative}}` | File path relative to current working directory |
383-
| `{{file_name}}` | File name (with extension) |
384-
| `{{file_name_no_extension}}` | File name without extension |
385-
| `{{file_type}}` | Filetype of current buffer (`vim.bo.filetype`) |
386-
| `{{file_extension}}` | File extension |
387-
| `{{dir_path}}` | Directory containing the current buffer |
388-
| `{{dir_name}}` | Name of the directory containing the current buffer |
389-
| `{{cwd_path}}` | Absolute path of the current working directory |
390-
| `{{cwd_name}}` | Name of the current working directory |
391-
| `{{pilot_data_path}}` | Path to `vim.fn.stdpath("data") .. "/pilot"` |
392-
| `{{cword}}` | Word under the cursor |
393-
| `{{cWORD}}` | WORD under the cursor |
379+
| Placeholder | Resolved value |
380+
| ---------------------------- | ---------------------------------------------------------------------------- |
381+
| `{{file_path}}` | Current buffer's absolute file path |
382+
| `{{file_path_relative}}` | File path relative to current working directory |
383+
| `{{file_name}}` | File name (with extension) |
384+
| `{{file_name_no_extension}}` | File name without extension |
385+
| `{{file_type}}` | Filetype of current buffer (`vim.bo.filetype`) |
386+
| `{{file_extension}}` | File extension |
387+
| `{{dir_path}}` | Directory containing the current buffer |
388+
| `{{dir_name}}` | Name of the directory containing the current buffer |
389+
| `{{cwd_path}}` | Absolute path of the current working directory |
390+
| `{{cwd_name}}` | Name of the current working directory |
391+
| `{{config_path}}` | Absolute path to your Neovim configuration directory |
392+
| `{{data_path}}` | Absolute path to Neovim plugins data directory |
393+
| `{{pilot_data_path}}` | Absolute path to the pilot directory inside of Neovim plugins data directory |
394+
| `{{cword}}` | Word under the cursor |
395+
| `{{cWORD}}` | WORD under the cursor |
394396

395397
**Modifier Functions**
396398

lua/default_config.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ M.default_opts = {
130130
vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
131131
)
132132
end,
133+
config_path = function()
134+
return vim.fn.fnameescape(vim.fn.stdpath("config"))
135+
end,
136+
data_path = function()
137+
return vim.fn.fnameescape(vim.fn.stdpath("data"))
138+
end,
133139
pilot_data_path = function()
134140
local pilot_data_path =
135141
vim.fs.joinpath(vim.fn.stdpath("data"), "pilot")

0 commit comments

Comments
 (0)