develop.txt 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. *develop.txt* Nvim
  2. NVIM REFERENCE MANUAL
  3. Development of Nvim *development* *dev*
  4. This reference describes design constraints and guidelines, for developing
  5. Nvim applications or Nvim itself. See |dev-arch| for discussion of Nvim's
  6. architecture and internal concepts.
  7. Nvim is free and open source. Everybody is encouraged to contribute.
  8. https://github.com/neovim/neovim/blob/master/CONTRIBUTING.md
  9. Type |gO| to see the table of contents.
  10. ==============================================================================
  11. Design goals *design-goals*
  12. Most important things come first (roughly). Some items conflict; this is
  13. intentional. A balance must be found.
  14. NVIM IS... IMPROVED *design-improved*
  15. The Neo bits of Nvim should make it a better Vim, without becoming a
  16. completely different editor.
  17. - In matters of taste, prefer Vim/Unix tradition. If there is no relevant
  18. Vim/Unix tradition, consider the "common case".
  19. - There is no limit to the features that can be added. Select new features
  20. based on (1) what users ask for, (2) how much effort it takes to implement
  21. and (3) someone actually implementing it.
  22. - Backwards compatibility is a feature. The RPC API in particular should
  23. never break.
  24. NVIM IS... WELL DOCUMENTED *design-documented*
  25. - A feature that isn't documented is a useless feature. A patch for a new
  26. feature must include the documentation.
  27. - Documentation should be comprehensive and understandable. Use examples.
  28. - Don't make the text unnecessarily long. Less documentation means that an
  29. item is easier to find.
  30. NVIM IS... FAST AND SMALL *design-speed-size*
  31. Keep Nvim small and fast. This directly affects versatility and usability.
  32. - Computers are becoming faster and bigger each year. Vim can grow too, but
  33. no faster than computers are growing. Keep Vim usable on older systems.
  34. - Many users start Vim from a shell very often. Startup time must be short.
  35. - Commands must work efficiently. The time they consume must be as small as
  36. possible. Useful commands may take longer.
  37. - Don't forget that some people use Vim over a slow connection. Minimize the
  38. communication overhead.
  39. - Vim is a component among other components. Don't turn it into a massive
  40. application, but have it work well together with other programs
  41. ("composability").
  42. NVIM IS... MAINTAINABLE *design-maintain*
  43. - The source code should not become a mess. It should be reliable code.
  44. - Use comments in a useful way! Quoting the function name and argument names
  45. is NOT useful. Do explain what they are for.
  46. - Porting to another platform should be made easy, without having to change
  47. too much platform-independent code.
  48. - Use the object-oriented spirit: Put data and code together. Minimize the
  49. knowledge spread to other parts of the code.
  50. NVIM IS... NOT *design-not*
  51. Nvim is not an operating system; instead it should be composed with other
  52. tools or hosted as a component. Marvim once said: "Unlike Emacs, Nvim does not
  53. include the kitchen sink... but it's good for plumbing."
  54. ==============================================================================
  55. Developer guidelines *dev-guidelines*
  56. PROVIDERS *dev-provider*
  57. A primary goal of Nvim is to allow extension of the editor without special
  58. knowledge in the core. Some core functions are delegated to "providers"
  59. implemented as external scripts.
  60. Examples:
  61. 1. In the Vim source code, clipboard logic accounts for more than 1k lines of
  62. C source code (ui.c), to perform two tasks that are now accomplished with
  63. shell commands such as xclip or pbcopy/pbpaste.
  64. 2. Python scripting support: Vim has three files dedicated to embedding the
  65. Python interpreter: if_python.c, if_python3.c and if_py_both.h. Together
  66. these files sum about 9.5k lines of C source code. In contrast, Nvim Python
  67. scripting is performed by an external host process implemented in ~2k lines
  68. of Python.
  69. The provider framework invokes Vimscript from C. It is composed of two
  70. functions in eval.c:
  71. - eval_call_provider({name}, {method}, {arguments}, {discard}): Calls
  72. `provider#{name}#Call` with {method} and {arguments}. If {discard} is true, any
  73. value returned by the provider will be discarded and empty value will be
  74. returned.
  75. - eval_has_provider({name}): Checks the `g:loaded_{name}_provider` variable
  76. which must be set to 2 by the provider script to indicate that it is
  77. "enabled and working". Called by |has()| to check if features are available.
  78. For example, the Python provider is implemented by the
  79. "autoload/provider/python.vim" script, which sets `g:loaded_python_provider`
  80. to 2 only if a valid external Python host is found. Then `has("python")`
  81. reflects whether Python support is working.
  82. *provider-reload*
  83. Sometimes a GUI or other application may want to force a provider to
  84. "reload". To reload a provider, undefine its "loaded" flag, then use
  85. |:runtime| to reload it: >vim
  86. :unlet g:loaded_clipboard_provider
  87. :runtime autoload/provider/clipboard.vim
  88. DOCUMENTATION *dev-doc*
  89. - "Just say it". Avoid mushy, colloquial phrasing in all documentation
  90. (docstrings, user manual, website materials, newsletters, …). Don't mince
  91. words. Personality and flavor, used sparingly, are welcome--but in general,
  92. optimize for the reader's time and energy: be "precise yet concise".
  93. - Prefer the active voice: "Foo does X", not "X is done by Foo".
  94. - "The words you choose are an essential part of the user experience."
  95. https://developer.apple.com/design/human-interface-guidelines/writing
  96. - "...without being overly colloquial or frivolous."
  97. https://developers.google.com/style/tone
  98. - Write docstrings (as opposed to inline comments) with present tense ("Gets"),
  99. not imperative ("Get"). This tends to reduce ambiguity and improve clarity
  100. by describing "What" instead of "How". >
  101. ✅ OK:
  102. /// Gets a highlight definition.
  103. ❌ NO:
  104. /// Get a highlight definition.
  105. - Avoid starting docstrings with "The" or "A" unless needed to avoid
  106. ambiguity. This is a visual aid and reduces noise. >
  107. ✅ OK:
  108. /// @param dirname Path fragment before `pend`
  109. ❌ NO:
  110. /// @param dirname The path fragment before `pend`
  111. - Vim differences:
  112. - Do not prefix help tags with "nvim-". Use |vim_diff.txt| to catalog
  113. differences from Vim; no other distinction is necessary.
  114. - If a Vim feature is removed, delete its help section and move its tag to
  115. |vim_diff.txt|.
  116. - Mention deprecated features in |deprecated.txt| and delete their old doc.
  117. - Use consistent language.
  118. - "terminal" in a help tag always means "the embedded terminal emulator",
  119. not "the user host terminal".
  120. - Use "tui-" to prefix help tags related to the host terminal, and "TUI"
  121. in prose if possible.
  122. - Rough guidelines on where Lua documentation should end up:
  123. - Nvim API functions `vim.api.nvim_*` should be in `api.txt`.
  124. - If the module is big and not relevant to generic and lower-level Lua
  125. functionality, then it's a strong candidate for separation. Example:
  126. `treesitter.txt`
  127. - Otherwise, add them to `lua.txt`
  128. Documentation format ~
  129. For Nvim-owned docs, use the following strict subset of "vimdoc" to ensure
  130. the help doc renders nicely in other formats (such as HTML:
  131. https://neovim.io/doc/user ).
  132. Strict "vimdoc" subset:
  133. - Use lists (like this!) prefixed with "-" or "•", for adjacent lines that you
  134. don't want to auto-wrap. Lists are always rendered with "flow" layout
  135. (soft-wrapped) instead of preformatted (hard-wrapped) layout common in
  136. legacy :help docs.
  137. - Limitation: currently the parser https://github.com/neovim/tree-sitter-vimdoc
  138. does not understand numbered listitems, so use a bullet symbol (- or •)
  139. before numbered items, e.g. "• 1." instead of "1.".
  140. - Separate blocks (paragraphs) of content by a blank line.
  141. - Do not use indentation in random places—that prevents the page from using
  142. "flow" layout. If you need a preformatted section, put it in
  143. a |help-codeblock| starting with ">".
  144. - Parameters and fields are documented as `{foo}`.
  145. - Optional parameters and fields are documented as `{foo}?`.
  146. C docstrings ~
  147. Nvim API documentation lives in the source code, as docstrings (doc
  148. comments) on the function definitions. The |api| :help is generated
  149. from the docstrings defined in src/nvim/api/*.c.
  150. Docstring format:
  151. - Lines start with `///`
  152. - Special tokens start with `@` followed by the token name:
  153. `@note`, `@param`, `@return`
  154. - Markdown is supported.
  155. - Tags are written as `[tag]()`.
  156. - References are written as `[tag]`
  157. - Use ``` for code samples.
  158. Code samples can be annotated as `vim` or `lua`
  159. Example: the help for |nvim_open_win()| is generated from a docstring defined
  160. in src/nvim/api/win_config.c like this: >
  161. /// Opens a new window.
  162. /// ...
  163. ///
  164. /// Example (Lua): window-relative float
  165. ///
  166. /// ```lua
  167. /// vim.api.nvim_open_win(0, false, {
  168. /// relative='win',
  169. /// row=3,
  170. /// col=3,
  171. /// width=12,
  172. /// height=3,
  173. /// })
  174. /// ```
  175. ///
  176. /// @param buffer Buffer to display
  177. /// @param enter Enter the window
  178. /// @param config Map defining the window configuration. Keys:
  179. /// - relative: Sets the window layout, relative to:
  180. /// - "editor" The global editor grid.
  181. /// - "win" Window given by the `win` field.
  182. /// - "cursor" Cursor position in current window.
  183. /// ...
  184. /// @param[out] err Error details, if any
  185. ///
  186. /// @return Window handle, or 0 on error
  187. Lua docstrings ~
  188. *dev-lua-doc*
  189. Lua documentation lives in the source code, as docstrings on the function
  190. definitions. The |lua-vim| :help is generated from the docstrings.
  191. Docstring format:
  192. - Use LuaCATS annotations: https://luals.github.io/wiki/annotations/
  193. - Markdown is supported.
  194. - Tags are written as `[tag]()`.
  195. - References are written as `[tag]`
  196. - Use ``` for code samples.
  197. Code samples can be annotated as `vim` or `lua`
  198. - Use `@since <api-level>` to note the |api-level| when the function became
  199. "stable". If `<api-level>` is greater than the current stable release (or
  200. 0), it is marked as "experimental".
  201. - See scripts/util.lua for the mapping of api-level to Nvim version.
  202. - Use `@nodoc` to prevent documentation generation.
  203. - Use `@inlinedoc` to inline `@class` blocks into `@param` blocks.
  204. E.g. >lua
  205. --- Object with fields:
  206. --- @class myOpts
  207. --- @inlinedoc
  208. ---
  209. --- Documentation for some field
  210. --- @field somefield? integer
  211. --- @param opts? myOpts
  212. function foo(opts)
  213. end
  214. <
  215. Will be rendered as: >vimdoc
  216. foo({opts})
  217. Parameters:
  218. - {opts}? (table) Object with the fields:
  219. - {somefield}? (integer) Documentation
  220. for some field
  221. <
  222. - Files declared as `@meta` are only used for typing and documentation (similar to "*.d.ts" typescript files).
  223. Example: the help for |vim.paste()| is generated from a docstring decorating
  224. vim.paste in runtime/lua/vim/_editor.lua like this: >
  225. --- Paste handler, invoked by |nvim_paste()| when a conforming UI
  226. --- (such as the |TUI|) pastes text into the editor.
  227. ---
  228. --- Example: To remove ANSI color codes when pasting:
  229. ---
  230. --- ```lua
  231. --- vim.paste = (function()
  232. --- local overridden = vim.paste
  233. --- ...
  234. --- end)()
  235. --- ```
  236. ---
  237. --- @since 12
  238. --- @see |paste|
  239. ---
  240. --- @param lines ...
  241. --- @param phase ...
  242. --- @returns false if client should cancel the paste.
  243. STDLIB DESIGN GUIDELINES *dev-lua*
  244. See also |dev-naming|.
  245. - Keep the core Lua modules |lua-stdlib| simple. Avoid elaborate OOP or
  246. pseudo-OOP designs. Plugin authors just want functions to call, not a big,
  247. fancy inheritance hierarchy.
  248. - Avoid requiring or returning special objects in the Nvim stdlib. Plain
  249. tables or values are easier to serialize, easier to construct from literals,
  250. easier to inspect and print, and inherently compatible with all Lua plugins.
  251. (This guideline doesn't apply to opaque, non-data objects like `vim.cmd`.)
  252. - stdlib functions should follow these common patterns:
  253. - Return |lua-result-or-message| (`any|nil,nil|string`) to communicate
  254. failure, or choose from |dev-error-patterns| when appropriate.
  255. - Accept iterable instead of only table.
  256. - Note: in some cases iterable doesn't make sense, e.g. spair() sorts the
  257. input by definition, so there is no reason for it to accept an iterable,
  258. because the input needs to be "reified"; it can't operate on a "stream".
  259. - Return an iterable (generator) instead of table, if possible.
  260. - Mimic the pairs() or ipairs() interface if the function is intended for
  261. use in a |for-in| loop.
  262. *dev-error-patterns*
  263. To communicate failure to a consumer, choose from these patterns (in order of
  264. preference):
  265. 1. `retval, errmsg`
  266. - When failure is normal, or when it is practical for the consumer to
  267. continue (fallback) in some other way. See |lua-result-or-message|.
  268. 2. optional result, no errormsg
  269. - Special case of 1. When there is only a single case of "doesn't exist"
  270. (e.g. cache lookup, dict lookup).
  271. 3. `error("no luck")`
  272. - For invalid state ("must not happen"), when failure is exceptional, or at
  273. a low level where the consumers are unlikely to handle it in a meaningful
  274. way. Advantage is that propagation happens for free and it's harder to
  275. accidentally swallow errors. (E.g. using
  276. `uv_handle/pipe:write()` without checking return values is common.)
  277. 4. `on_error` callback
  278. - For async and "visitors" traversing a graph, where many errors may be
  279. collected while work continues.
  280. 5. `vim.notify` (sometimes with optional `opts.silent` (async, visitors ^))
  281. - High-level / application-level messages. End-user invokes these directly.
  282. *dev-patterns*
  283. Interface conventions ~
  284. Where possible, these patterns apply to _both_ Lua and the API:
  285. - When accepting a buffer id, etc., 0 means "current buffer", nil means "all
  286. buffers". Likewise for window id, tabpage id, etc.
  287. - Examples: |vim.lsp.codelens.clear()| |vim.diagnostic.enable()|
  288. - Any function signature that accepts a callback (example: |table.foreach()|)
  289. should place it as the LAST parameter (after opts), if possible (or ALWAYS
  290. for "continuation callbacks"—functions called exactly once).
  291. - Improves readability by placing the less "noisy" arguments near the start.
  292. - Consistent with luv.
  293. - Useful for future async lib which transforms functions of the form
  294. `function(<args>, cb(<ret)>))` => `function(<args>) -> <ret>`.
  295. - Example: >lua
  296. -- ✅ OK:
  297. filter(…, opts, function() … end)
  298. -- ❌ NO:
  299. filter(function() … end, …, opts)
  300. -- ❌ NO:
  301. filter(…, function() … end, opts)
  302. - "Enable" ("toggle") interface and behavior:
  303. - `enable(…, nil)` and `enable(…, {buf=nil})` are synonyms and control the
  304. the "global" enablement of a feature.
  305. - `is_enabled(nil)` and `is_enabled({buf=nil})`, likewise, query the
  306. global state of the feature.
  307. - `enable(…, {buf: number})` sets a buffer-local "enable" flag.
  308. - `is_enabled({buf: number})`, likewise, queries the buffer-local state of
  309. the feature.
  310. - See |vim.lsp.inlay_hint.enable()| and |vim.lsp.inlay_hint.is_enabled()|
  311. for a reference implementation of these "best practices".
  312. - NOTE: open questions: https://github.com/neovim/neovim/issues/28603
  313. API DESIGN GUIDELINES *dev-api*
  314. See also |dev-naming|.
  315. - When adding an API, check the following:
  316. - What precedents did you draw from? How does your solution compare to them?
  317. - Does your new API allow future expansion? How? Or why not?
  318. - Is the new API similar to existing APIs? Do we need to deprecate the old ones?
  319. - Did you cross-reference related concepts in the docs?
  320. - Avoid "mutually exclusive" parameters--via constraints or limitations, if
  321. necessary. For example nvim_create_autocmd() has mutually exclusive
  322. "callback" and "command" args; but the "command" arg could be eliminated by
  323. simply not supporting Vimscript function names, and treating a string
  324. "callback" arg as an Ex command (which can call Vimscript functions). The
  325. "buffer" arg could also be eliminated by treating a number "pattern" as
  326. a buffer number.
  327. - Avoid functions that depend on cursor position, current buffer, etc. Instead
  328. the function should take a position parameter, buffer parameter, etc.
  329. Where things go ~
  330. - API (libnvim/RPC): exposes low-level internals, or fundamental things (such
  331. as `nvim_exec_lua()`) needed by clients or C consumers.
  332. - Lua stdlib = high-level functionality that builds on top of the API.
  333. NAMING GUIDELINES *dev-naming*
  334. Naming is exceedingly important: the name of a thing is the primary interface
  335. for uses it, discusses it, searches for it, shares it... Consistent
  336. naming in the stdlib, API, and UI helps both users and developers discover and
  337. intuitively understand related concepts ("families"), and reduces cognitive
  338. burden. Discoverability encourages code re-use and likewise avoids redundant,
  339. overlapping mechanisms, which reduces code surface-area, and thereby minimizes
  340. bugs...
  341. Naming conventions ~
  342. In general, look for precedent when choosing a name, that is, look at existing
  343. (non-deprecated) functions. In particular, see below...
  344. *dev-name-common*
  345. Use existing common {verb} names (actions) if possible:
  346. - add: Appends or inserts into a collection
  347. - attach: Listens to something to get events from it (TODO: rename to "on"?)
  348. - call: Calls a function
  349. - cancel: Cancels or dismisses an event or interaction, typically
  350. user-initiated and without error. (Compare "abort", which
  351. cancels and signals error/failure.)
  352. - clear: Clears state but does not destroy the container
  353. - create: Creates a new (non-trivial) thing (TODO: rename to "def"?)
  354. - del: Deletes a thing (or group of things)
  355. - detach: Dispose attached listener (TODO: rename to "un"?)
  356. - enable: Enables/disables functionality. Signature should be
  357. `enable(enable?:boolean, filter?:table)`.
  358. - eval: Evaluates an expression
  359. - exec: Executes code, may return a result
  360. - fmt: Formats
  361. - get: Gets things. Two variants (overloads):
  362. 1. `get<T>(id: int): T` returns one item.
  363. 2. `get<T>(filter: dict): T[]` returns a list.
  364. - inspect: Presents a high-level, often interactive, view
  365. - is_enabled: Checks if functionality is enabled.
  366. - open: Opens something (a buffer, window, …)
  367. - parse: Parses something into a structured form
  368. - set: Sets a thing (or group of things)
  369. - start: Spin up a long-lived process. Prefer "enable" except when
  370. "start" is obviously more appropriate.
  371. - stop: Inverse of "start". Teardown a long-lived process.
  372. - try_{verb}: Best-effort operation, failure returns null or error obj
  373. Do NOT use these deprecated verbs:
  374. - disable: Prefer `enable(enable: boolean)`.
  375. - exit: Prefer "cancel" (or "stop" if appropriate).
  376. - is_disabled: Prefer `is_enabled()`.
  377. - list: Redundant with "get"
  378. - notify: Redundant with "print", "echo"
  379. - show: Redundant with "print", "echo"
  380. - toggle: Prefer `enable(not is_enabled())`.
  381. Use consistent names for {topic} in API functions: buffer is called "buf"
  382. everywhere, not "buffer" in some places and "buf" in others.
  383. - buf: Buffer
  384. - chan: |channel|
  385. - cmd: Command
  386. - cmdline: Command-line UI or input
  387. - fn: Function
  388. - hl: Highlight
  389. - pos: Position
  390. - proc: System process
  391. - tabpage: Tabpage
  392. - win: Window
  393. Do NOT use these deprecated nouns:
  394. - buffer Use "buf" instead
  395. - callback Use on_foo instead
  396. - command Use "cmd" instead
  397. - window Use "win" instead
  398. *dev-name-events*
  399. Use the "on_" prefix to name event-handling callbacks and also the interface for
  400. "registering" such handlers (on_key). The dual nature is acceptable to avoid
  401. a confused collection of naming conventions for these related concepts.
  402. Editor |events| (autocommands) are historically named like: >
  403. {Noun}{Event}
  404. Use this format to name API (RPC) events: >
  405. nvim_{noun}_{event-name}_event
  406. Example: >
  407. nvim_buf_changedtick_event
  408. <
  409. *dev-api-name*
  410. Use this format to name new RPC |API| functions: >
  411. nvim_{topic}_{verb}_{arbitrary-qualifiers}
  412. Do not add new nvim_buf/nvim_win/nvim_tabpage APIs, unless you are certain the
  413. concept will NEVER be applied to more than one "scope". That is, {topic}
  414. should be the TOPIC ("ns", "extmark", "option", …) that acts on the scope(s)
  415. (buf/win/tabpage/global), it should NOT be the scope. Instead the scope should
  416. be a parameter (typically manifest as mutually-exclusive buf/win/… flags like
  417. |nvim_get_option_value()|, or less commonly as a `scope: string` field like
  418. |nvim_get_option_info2()|).
  419. - Example: `nvim_get_keymap('v')` operates in a global context (first
  420. parameter is not a Buffer). The "get" verb indicates that it gets anything
  421. matching the given filter parameter. A "list" verb is unnecessary because
  422. `nvim_get_keymap('')` (empty filter) returns all items.
  423. - Example: `nvim_buf_del_mark` acts on a `Buffer` object (the first parameter)
  424. and uses the "del" {verb}.
  425. INTERFACE PATTERNS *dev-api-patterns*
  426. Prefer adding a single `nvim_{topic}_{verb}_…` interface for a given topic.
  427. Example: >
  428. nvim_ns_add(
  429. ns_id: int,
  430. filter: {
  431. handle: integer (buf/win/tabpage id)
  432. scope: "global" | "win" | "buf" | "tabpage"
  433. }
  434. ): { ok: boolean }
  435. nvim_ns_get(
  436. ns_id: int,
  437. filter: {
  438. handle: integer (buf/win/tabpage id)
  439. scope: "global" | "win" | "buf" | "tabpage"
  440. }
  441. ): { ids: int[] }
  442. nvim_ns_del(
  443. ns_id: int,
  444. filter: {
  445. handle: integer (buf/win/tabpage id)
  446. scope: "global" | "win" | "buf" | "tabpage"
  447. }
  448. ): { ok: boolean }
  449. Anti-Example:
  450. Creating separate `nvim_xx`, `nvim_buf_xx`, `nvim_win_xx`, and
  451. `nvim_tabpage_xx`, functions all for the same `xx` topic, requires 4x the
  452. amount of documentation, tests, boilerplate, and interfaces, which users must
  453. comprehend, maintainers must maintain, etc. Thus the following is NOT
  454. recommended (compare these 12(!) functions to the above 3 functions): >
  455. nvim_add_ns(…)
  456. nvim_buf_add_ns(…)
  457. nvim_win_add_ns(…)
  458. nvim_tabpage_add_ns(…)
  459. nvim_del_ns(…)
  460. nvim_buf_del_ns(…)
  461. nvim_win_del_ns(…)
  462. nvim_tabpage_del_ns(…)
  463. nvim_get_ns(…)
  464. nvim_buf_get_ns(…)
  465. nvim_win_get_ns(…)
  466. nvim_tabpage_get_ns(…)
  467. API-CLIENT *dev-api-client*
  468. *api-client*
  469. API clients wrap the Nvim |API| to provide idiomatic "SDKs" for their
  470. respective platforms (see |jargon|). You can build a new API client for your
  471. favorite platform or programming language.
  472. List of API clients:
  473. https://github.com/neovim/neovim/wiki/Related-projects#api-clients
  474. *node-client* *pynvim*
  475. These clients can be considered the "reference implementation" for API clients:
  476. - https://github.com/neovim/node-client
  477. - https://github.com/neovim/pynvim
  478. Standard Features ~
  479. - API clients exist to hide msgpack-rpc details. The wrappers can be
  480. automatically generated by reading the |api-metadata| from Nvim. |api-mapping|
  481. - Clients should call |nvim_set_client_info()| after connecting, so users and
  482. plugins can detect the client by handling the |ChanInfo| event. This avoids
  483. the need for special variables or other client hints.
  484. - Clients should handle |nvim_error_event| notifications, which will be sent
  485. if an async request to nvim was rejected or caused an error.
  486. Package Naming ~
  487. API client packages should NOT be named something ambiguous like "neovim" or
  488. "python-client". Use "nvim" as a prefix/suffix to some other identifier
  489. following ecosystem conventions.
  490. For example, Python packages tend to have "py" in the name, so "pynvim" is
  491. a good name: it's idiomatic and unambiguous. If the package is named "neovim",
  492. it confuses users, and complicates documentation and discussions.
  493. Examples of API-client package names:
  494. - ✅ OK: nvim-racket
  495. - ✅ OK: pynvim
  496. - ❌ NO: python-client
  497. - ❌ NO: neovim_
  498. API client implementation guidelines ~
  499. - Separate the transport layer from the rest of the library. |rpc-connecting|
  500. - Use a MessagePack library that implements at least version 5 of the
  501. MessagePack spec, which supports the BIN and EXT types used by Nvim.
  502. - Use a single-threaded event loop library/pattern.
  503. - Use a fiber/coroutine library for the language being used for implementing
  504. a client. These greatly simplify concurrency and allow the library to
  505. expose a blocking API on top of a non-blocking event loop without the
  506. complexity that comes with preemptive multitasking.
  507. - Don't assume anything about the order of responses to RPC requests.
  508. - Clients should expect requests, which must be handled immediately because
  509. Nvim is blocked while waiting for the client response.
  510. - Clients should expect notifications, but these can be handled "ASAP" (rather
  511. than immediately) because they won't block Nvim.
  512. - For C/C++ projects, consider libmpack instead of the msgpack.org library.
  513. https://github.com/libmpack/libmpack/
  514. libmpack is small (no dependencies, can inline into your C/C++ project) and
  515. efficient (no allocations). It also implements msgpack-RPC, the protocol
  516. required by Nvim.
  517. https://github.com/msgpack-rpc/msgpack-rpc
  518. EXTERNAL UI *dev-ui*
  519. External UIs should be aware of the |api-contract|. In particular, future
  520. versions of Nvim may add new items to existing events. The API is strongly
  521. backwards-compatible, but clients must not break if new (optional) fields are
  522. added to existing events.
  523. Standard Features ~
  524. External UIs are expected to implement these common features:
  525. - Call |nvim_set_client_info()| after connecting, so users and plugins can
  526. detect the UI by handling the |ChanInfo| event. This avoids the need for
  527. special variables and UI-specific config files (gvimrc, macvimrc, …).
  528. - Cursor style (shape, color) should conform to the 'guicursor' properties
  529. delivered with the mode_info_set UI event.
  530. - Send the ALT/META ("Option" on macOS) key as a |<M-| chord.
  531. - Send the "super" key (Windows key, Apple key) as a |<D-| chord.
  532. - Avoid mappings that conflict with the Nvim keymap-space; GUIs have many new
  533. chords (<C-,> <C-Enter> <C-S-x> <D-x>) and patterns ("shift shift") that do
  534. not potentially conflict with Nvim defaults, plugins, etc.
  535. - Consider the "option_set" |ui-global| event as a hint for other GUI
  536. behaviors. Various UI-related options ('guifont', 'ambiwidth', …) are
  537. published in this event. See also "mouse_on", "mouse_off".
  538. - UIs generally should NOT set |$NVIM_APPNAME| (unless explicitly requested by
  539. the user).
  540. - Support the text decorations/attributes given by |ui-event-hl_attr_define|.
  541. The "url" attr should be presented as a clickable hyperlink.
  542. vim:tw=78:ts=8:sw=4:et:ft=help:norl: