-
Notifications
You must be signed in to change notification settings - Fork 19
/
possession.txt
422 lines (309 loc) · 15.7 KB
/
possession.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
*possession* Flexible session management for Neovim.
COMMANDS *possession-commands*
In commands with optional `name` argument, if the argument is omitted then
currently loaded session is used (unless noted otherwise).
*:PossessionSave*
:PossessionSave [{name}]~
Save the current session information under `session_dir`. Use
`:PossessionSave! [{name}]` to avoid asking for confirmation when overwriting
existing session file. If [{name}] is omitted and a session does not
already exist, you will be prompted for a name.
*:PossessionLoad*
:PossessionLoad [{name}]~
Load given session from disk. If `name` is omitted then use last
loaded session name.
*:PossessionSaveCwd*
:PossessionSaveCwd
Save session for current working directory. Use `!` to avoid confirmation
dialog. The session name will be the current working directory.
*:PossessionLoadCwd*
:PossessionLoadCwd [{name}]
Load given session for current working directory. If `name` is omitted
then use last session name for the current working directory.
*:PossessionRename*
:PossessionRename [{name} [{new_name}]]~
Rename session `name` to `new_name`. If `new_name` is omitted then it is taken
from |vim.ui.input|. If `name` is omitted then current session name is used.
*:PossessionClose*
:PossessionClose~
Close current session deleting all open buffers. To delete buffers with
unsaved changes use `:PossessionClose!`.
*:PossessionDelete*
:PossessionDelete [{name}]~
Delete given session file. `:PossessionDelete!` will not ask for confirmation.
*:PossessionShow*
:PossessionShow [{name}]~
Show given session info.
*:PossessionList*
:PossessionList~
List available sessions. `:PossessionList!` will not hide the `vimscript`
field that contains commands generated by |:mksession|.
:PossessionListCwd [{dir}]~
List available sessions with a cwd that matches the specified `dir`.
If `dir` is omitted the current working directory is used.
`:PossessionListCwd!` will not hide the `vimscript` field that contains
commands generated by |:mksession|.
*:PossessionMigrate*
:PossessionMigrate {dir_or_file}~
Migrate regular |:mksession|-based session file to current `session_dir`. If a
directory is specified all files inside it will be migrated. Migration tries
to generate valid possession JSON files. It is a best-effort algorithm that
tries to guess session name from file name (without extension) and parses
vimscript to find `cwd`.
CONFIGURATION *possession-config*
To configure the plugin use:
>
require('possession').setup { ... }
<
The following configuration options are available:
session_dir~
`string`
Path under which the session files are saved.
silent~
`boolean`
Suppress info/debug messages (still logged to file if enabled).
load_silent~
`boolean`
Suppress Vim output when sourcing vimscript that loads the session.
debug~
`boolean`
Show debug logs.
logfile~
`boolean | string`
Save logs to `stdpath('log') .. 'possession.log` if `true` or to the file
with given name if `string`.
prompt_no_cr~
`boolean`
When this option is set to true, yes/no prompts will use |getchar()| so
that there is no need to hit enter (`<CR>`) - just hit `y` or `n`. When
`prompt_no_cr = false`, `vim.ui.input` is used and you must hit enter to
confirm the answer.
commands~
`table | nil`
If set to falsy value then no commands will be created.
commands.*~
`string | nil`
Allows to change the name of the `:Possession*` commands (e.g.
`commands.save = 'SSave'`) or disable the command if set to a falsy value.
*possession-autosave*
autosave.current~
`boolean | function(name: string): boolean`
Automatically save current session if it exists. If no session has been
loaded yet, then `autosave.cwd` and `autosave.tmp` settings are checked.
autosave.cwd~
`boolean | function(): boolean`
Automatically save session based on current (global) working directory
if no session has been loaded yet. Higher priority than `autosave.tmp`.
autosave.tmp~
`boolean | function(): boolean`
Automatically save a temporary session if no session has been loaded yet.
`autosave.cwd` has higher priority if enabled.
autosave.tmp_name~
`string | function(): string`
Name used for the temporary session when `autosave.tmp` is enabled.
autosave.on_load~
`boolean`
Run auto-save when loading another session, e.g. when using the
`PossessionLoad` command.
autosave.on_quit~
`boolean`
Run auto-save when quitting Neovim during the |VimLeavePre| autocmd.
Note: to properly save current session when quitting, use |:quitall|, this
way the current window layout will be preserved.
*possession-autoload*
autoload~
`string | function(): string
Automatically load a session. Valid string values are:
- `last` loads the last saved session
- `auto_cwd` loads the session saved by `autosave.cwd` or `:PossessionSaveCwd`
- `last_cwd` loads the last session for the current working directory
If a function is provided, it needs to return the name of a session file
or a directory. If it is a directory, the last session for that directory
is loaded. The function can also return one of the above strings, in
which case the behaviour is as defined for that string.
Autoload is skipped when:
- Neovim is passed any files or folders as arguments
- `stdin` is piped to Neovim
*possession-hooks*
hooks.before_save~
`function(name: string) => table | nil`
Invoked on `possession.save` before any actions. Receives session name as
an argument. Should return a table of `user_data` to be stored in the
session file. This hook can also return a falsy value to abort session
saving.
hooks.after_save~
`function(name: string, user_data: table, aborted: boolean)`
Invoked just before `possession.save` returns. Receives the final
`user_data` that has been used for saving. If `aborted` is `true` then the
session haven't been saved.
hooks.before_load~
`function(name: string, user_data: table): table | nil`
Invoked on `possession.load` just after retrieving session data. Receives
session name and `user_data` for the session to be loaded. This hook
can modify `user_data` or return it as is. If a falsy value is returned
then loading will be aborted.
hooks.after_load~
`function(name: string, user_data: table)`
Invoked just before `possession.load` returns. Receives the `user_data`
from the `before_load` hook.
*possession-plugins-config*
plugins~
`table`
This table contains configuration options for |possession-plugins|. Some
keys are common to each plugin. The rest depends on a specific plugin.
plugins.*~
`table | boolean`
This is plugin configuration table. It can be set to `false` to disable a
plugin. If set to `true` the plugin will be enabled with an empty table,
which is sufficient with plugins that take no options.
plugins.*.hooks~
`table { string } | nil`
List of hook names which are enabled for this plugin. If set to `nil` then
all hooks will be enabled (only the ones actually used by the plugin).
Setting this to an empty table (`{}`) will disable all hooks.
*possession-close-windows*
Plugin that simply closes Vim windows on given hooks. Windows to close are
determined by configured matching rules.
Note: to delete buffers match them with |possession-close-windows| and wait
for |possession-delete-hidden-buffers| to do its job.
plugins.close_windows.preserve_layout~
`boolean | function(window: number): boolean`
When deleting a window preserve overall windows layout by replacing the
window's buffer with a throwaway scratch buffer.
plugins.close_windows.match~
`table`
Rules for selecting windows to be closed.
plugins.close_windows.match.floating~
`boolean`
Match floating windows. It is recommended to set this to `true` as
floating window may cause |:mksession| to mess up windows layout.
plugins.close_windows.match.buftype~
`table { string }`
List of 'buftype's that will match window's buffer.
plugins.close_windows.match.filetype~
`table { string }`
List of 'filetype's that will match window's buffer.
plugins.close_windows.match.custom~
`boolean | function(window: number): boolean`
Can be used for arbitrary window matching logic. Windows for which the
function returns `true` will be closed.
*possession-delete-hidden-buffers*
Plugin that deletes hidden buffers (buffers with no associated windows).
It will always run after |possession-close-windows| so all the previously
closed windows will also have their buffers deleted.
Note: instead of using this plugin on `before_save`, one could remove
`buffers` from 'sessionoptions' (or have both), which would ignore any
hidden buffers when saving sessions.
plugins.delete_hidden_buffers.force~
`boolean | function(buffer: number): boolean`
Delete buffers even if they contain changes.
WARNING: this may lead to loosing unsaved changes. Instead of using this
option consider removing `buffers` from 'sessionoptions'.
*possession-delete-buffers*
This plugin forcefully deletes all buffers before loading new session (on
`before_load` hook). This may be especially useful if using `buffers` in
'sessionopts' (if you need to store hidden buffers in sessions).
*possession-nvim-tree*
Saves nvim-tree explorer windows and restores them when loading the session.
Currently no configuration options beside enabling/disabling are available.
*possession-neo-tree*
Saves neo-tree windows and restores them when loading the session.
*possession-symbols-outline*
*possession-outline*
Saves symbols-outline.nvim/outline.nvim windows and restores when loading
session. NOTE: currently this only works for a single outline due to
symbols-outline.nvim limitations
*possession-tabby*
Saves tabby.nvim tab page names when saving the sessions and restores them
when loading.
Currently no configuration options beside enabling/disabling are available.
*possession-dap*
Saves nvim-dap breakpoints by filename and restores them when loading a
session.
*possession-dapui*
Closes and restores dapui view in a tab.
*possession-neotest*
Closes and restores the summary window.
*possession-stop-lsp-clients*
Stops all attached language server protocol clients.
*possession-telescope*
telescope~
`table`
Configuration for builtin possession telescope pickers.
telescope.previewer.enabled~
`boolean`
Show previewer in telescope picker.
telescope.previewer.previewer~
`'pretty'|'raw'|function(opts):Previewer`
Select previewer to use, either one of the ones included in this plugin or
a custom previewer that will be returned from the function.
telescope.previewer.wrap_lines~
`boolean`
|wrap| lines in the preview window.
telescope.previewer.include_empty_plugin_data~
`boolean`
Remove keys in `plugin_data` with no important data.
telescope.previewer.cwd_colors.cwd~
`string`
Color to use when highlighting sesion cwd in paths. Interpreted as hex
color if it starts with `#`, otherwise as a name of a highlight group.
telescope.previewer.cwd_colors.tab_cwd~
`string[]`
Colors to use when highlighting sesion tab_cwd in paths. Interpreted as hex
color if it starts with `#`, otherwise as a name of a highlight group.
The colors will be assigned to consecutive tab cwds, modulo-wrapping to
start if there are move tab cwds than colors defined for this settings.
telescope.list~
`table`
List available sessions.
telescope.default_action~
`string`
Action (key from `telescope.list.mappings`) that is executed on `<cr>`.
telescope.mappings.*~
`string|table`
Keys used to bind given action. Can be a table of bindings for normal/insert
mode or a string to use the same binding for both.
PLUGINS *possession-plugins*
Plugins are extensions that perform additional actions on hooks, similarly to
how user hooks work. Possession plugins are not equivalent to Vim plugins,
i.e. a possession plugin can implement actions related to an actual Vim
plugin (like closing/restoring `nvlm-tree` windows), but it could also do
any other work that is not related to any particular Vim plugin.
Plugins work by exposing hooks equivalent to the hooks provided to the user,
with some notable differences:
1. Hook functions take additional `config` parameter as first argument. It
contains current plugin configuration as defined under `plugins.<name>` in the
configuration table (set by `setup`, see |possession-config|).
Note: There is NO need to check if the plugin is enabled. This will be done
earlier, so if a plugin hook is called it means that it is enabled.
2. Instead of `user_data`, a `plugin_data` table is used. The plugin can use
it to store/retrieve data between sessions. Any hooks that would return
`user_data` should return this table. Returning `nil` will abort
saving/loading the session! The `plugin_data` table will be stored under
`plugins.<name>` path in the JSON file automatically.
SESSION FILE *possession-session-file*
Session files are stored in JSON format with the following keys:
name~
`string`
Session name. The session file name should be in the format `<name>.json`,
so the information is redundant and mismatch may sometimes lead to
unexpected results.
cwd~
`string`
Vim's current working directory (|getcwd()|) at the moment of session
creation.
vimscript~
`string`
Code genereated by |:mksession| that is used to restore a session.
user_data~
`table`
Used to store arbitrary user data. Value of this table is
generated/available in |possession-hooks|.
AUTOCOMMANDS *possession-autocommands*
The recommended way of integrating with session save/load events is to use the
provided |possession-hooks| or to create |possession-plugins| and define hooks
there. But there is also an option to perform simple actions using Neovim
|autocmd|. Neovim has a builtin |SessionLoadPost| autocmd which is executed
after loading the session. possession.nvim also defines |User| autocmd with
pattern `SessionSavePre` that will be executed just before |:mksession|.
vim:tw=78:et:ft=help:norl: