doc: enable mathjax support for sphinx documentation
[vis.git] / vis.h
blobb35458e2b1a749dc15dcc10e8e7d5d456620f979
1 #ifndef VIS_H
2 #define VIS_H
4 #include <signal.h>
5 #include <stddef.h>
6 #include <stdbool.h>
8 typedef struct Vis Vis;
9 typedef struct File File;
10 typedef struct Win Win;
12 #include "ui.h"
13 #include "view.h"
14 #include "text-regex.h"
15 #include "libutf.h"
17 #ifndef CONFIG_HELP
18 #define CONFIG_HELP 1
19 #endif
21 #if CONFIG_HELP
22 #define VIS_HELP_DECL(x) x
23 #define VIS_HELP_USE(x) x
24 #define VIS_HELP(x) (x),
25 #else
26 #define VIS_HELP_DECL(x)
27 #define VIS_HELP_USE(x) NULL
28 #define VIS_HELP(x)
29 #endif
31 /* simplify utility renames by distribution packagers */
32 #ifndef VIS_OPEN
33 #define VIS_OPEN "vis-open"
34 #endif
35 #ifndef VIS_CLIPBOARD
36 #define VIS_CLIPBOARD "vis-clipboard"
37 #endif
39 /* maximum bytes needed for string representation of a (pseudo) key */
40 #define VIS_KEY_LENGTH_MAX 64
42 /**
43 * Editor event handlers.
45 typedef struct {
46 void (*init)(Vis*);
47 void (*start)(Vis*);
48 void (*quit)(Vis*);
49 void (*mode_insert_input)(Vis*, const char *key, size_t len);
50 void (*mode_replace_input)(Vis*, const char *key, size_t len);
51 void (*file_open)(Vis*, File*);
52 bool (*file_save_pre)(Vis*, File*, const char *path);
53 void (*file_save_post)(Vis*, File*, const char *path);
54 void (*file_close)(Vis*, File*);
55 void (*win_open)(Vis*, Win*);
56 void (*win_close)(Vis*, Win*);
57 void (*win_highlight)(Vis*, Win*);
58 void (*win_status)(Vis*, Win*);
59 } VisEvent;
61 /** Union used to pass arguments to key action functions. */
62 typedef union {
63 bool b;
64 int i;
65 const char *s;
66 const void *v;
67 void (*w)(View*);
68 void (*f)(Vis*);
69 } Arg;
71 /**
72 * Key action handling function.
73 * @param keys Input queue content *after* the binding which invoked this function.
74 * @rst
75 * .. note:: An empty string ``""`` indicates that no further input is available.
76 * @endrst
77 * @return Pointer to first non-cosumed key.
78 * @rst
79 * .. warning:: Must be in range ``[keys, keys+strlen(keys)]`` or ``NULL`` to
80 * indicate that not enough input was available. In the latter case
81 * the function will be called again once more input has been received.
82 * @endrst
83 * @ingroup vis_action
85 typedef const char *KeyActionFunction(Vis*, const char *keys, const Arg*);
87 /** Key action definition. */
88 typedef struct {
89 const char *name; /**< Name of a pseudo key ``<name>`` which can be used in mappings. */
90 VIS_HELP_DECL(const char *help;) /**< One line human readable description, displayed by ``:help``. */
91 KeyActionFunction *func; /**< Key action implementation function. */
92 Arg arg; /**< Options passes as last argument to ``func``. */
93 } KeyAction;
95 /**
96 * A key binding, refers to an action or an alias
97 * @rst
98 * .. note:: Either ``action`` or ``alias`` must be ``NULL``.
99 * @endrst
101 typedef struct {
102 const char *key; /**< Symbolic key to trigger this binding. */
103 const KeyAction *action; /**< Action to invoke when triggering this binding. */
104 const char *alias; /**< Replaces ``key`` with ``alias`` at the front of the input queue. */
105 } KeyBinding;
108 * @defgroup vis_lifecycle
109 * @{
111 /** Create a new editor instance using the given user interface and event handlers. */
112 Vis *vis_new(Ui*, VisEvent*);
113 /** Free all resources associated with this editor instance, terminates UI. */
114 void vis_free(Vis*);
116 * Enter main loop, start processing user input.
117 * @return The editor exit status code.
119 int vis_run(Vis*);
120 /** Terminate editing session, the given ``status`` will be the return value of `vis_run`. */
121 void vis_exit(Vis*, int status);
123 * Emergency exit, print given message, perform minimal UI cleanup and exit process.
124 * @rst
125 * .. note:: This function does not return.
126 * @endrst
128 void vis_die(Vis*, const char *msg, ...) __attribute__((noreturn,format(printf, 2, 3)));
131 * Temporarily supsend the editor process.
132 * @rst
133 * .. note:: This function will generate a ``SIGTSTP`` signal.
134 * @endrst
136 void vis_suspend(Vis*);
138 * Resume editor process.
139 * @rst
140 * .. note:: This function is usually called in response to a ``SIGCONT`` signal.
141 * @endrst
143 void vis_resume(Vis*);
145 * Inform the editor core that a signal occured.
146 * @return Whether the signal was handled.
147 * @rst
148 * .. note:: Being designed as a library the editor core does *not* register any
149 * signal handlers on its own.
150 * .. note:: The remaining arguments match the prototype of ``sa_sigaction`` as
151 * specified in `sigaction(2)`.
152 * @endrst
154 bool vis_signal_handler(Vis*, int signum, const siginfo_t *siginfo, const void *context);
156 * Interrupt long running operation.
157 * @rst
158 * .. warning:: There is no guarantee that a long running operation is actually
159 * interrupted. It is analogous to cooperative multitasking where
160 * the operation has to voluntarily yield control.
161 * .. note:: It is invoked from `vis_signal_handler` when receiving ``SIGINT``.
162 * @endrst
164 void vis_interrupt(Vis*);
165 /** Check whether interruption was requested. */
166 bool vis_interrupt_requested(Vis*);
168 * @}
169 * @defgroup vis_draw
170 * @{
172 /** Draw user interface. */
173 void vis_draw(Vis*);
174 /** Completely redraw user interface. */
175 void vis_redraw(Vis*);
176 /** Blit user interface state to output device. */
177 void vis_update(Vis*);
179 * @}
180 * @defgroup vis_windows
181 * @{
184 * Create a new window and load the given file.
185 * @param filename If ``NULL`` a unamed, empty buffer is created.
186 * @rst
187 * .. note:: If the given file name is already opened in another window,
188 * the underlying File object is shared.
189 * .. warning:: This duplication detection is currently based on normalized,
190 * absolute file names. TODO: compare inodes instead.
191 * @endrst
193 bool vis_window_new(Vis*, const char *filename);
195 * Create a new window associated with a file descriptor.
196 * @rst
197 * .. note:: No data is read from `fd`, but write commands without an
198 * explicit filename will instead write to the file descriptor.
199 * @endrst
201 bool vis_window_new_fd(Vis*, int fd);
202 /** Reload the file currently displayed in the window from disk. */
203 bool vis_window_reload(Win*);
204 /** Check whether closing the window would loose unsaved changes. */
205 bool vis_window_closable(Win*);
206 /** Close window, redraw user interface. */
207 void vis_window_close(Win*);
208 /** Split the window, shares the underlying file object. */
209 bool vis_window_split(Win*);
210 /** Change status message of this window. */
211 void vis_window_status(Win*, const char *status);
212 void vis_window_draw(Win*);
213 void vis_window_invalidate(Win*);
214 /** Focus next window. */
215 void vis_window_next(Vis*);
216 /** Focus previous window. */
217 void vis_window_prev(Vis*);
218 /** Change currently focused window, receiving user input. */
219 void vis_window_focus(Win*);
220 /** Swap location of two windows. */
221 void vis_window_swap(Win*, Win*);
222 /** Query window dimension. */
223 int vis_window_width_get(const Win*);
224 /** Query window dimension. */
225 int vis_window_height_get(const Win*);
227 * @}
228 * @defgroup vis_info
229 * @{
232 * Display a user prompt with a certain title.
233 * @rst
234 * .. note:: The prompt is currently implemented as a single line height window.
235 * @endrst
237 void vis_prompt_show(Vis*, const char *title);
240 * Display a single line message.
241 * @rst
242 * .. note:: The message will automatically be hidden upon next input.
243 * @endrst
245 void vis_info_show(Vis*, const char *msg, ...) __attribute__((format(printf, 2, 3)));
246 /** Hide informational message. */
247 void vis_info_hide(Vis*);
249 /** Display arbitrary long message in a dedicated window. */
250 void vis_message_show(Vis*, const char *msg);
251 /** Close message window. */
252 void vis_message_hide(Vis*);
254 * @}
255 * @defgroup vis_changes
256 * @{
258 void vis_insert(Vis*, size_t pos, const char *data, size_t len);
259 void vis_delete(Vis*, size_t pos, size_t len);
260 void vis_replace(Vis*, size_t pos, const char *data, size_t len);
261 /** Perform insertion at all cursor positions. */
262 void vis_insert_key(Vis*, const char *data, size_t len);
264 * Perform character subsitution at all cursor positions.
265 * @rst
266 * .. note:: Does not replace new line characters.
267 * @endrst
269 void vis_replace_key(Vis*, const char *data, size_t len);
271 * Insert a tab at all cursor positions.
272 * @rst
273 * .. note:: Performs tab expansion according to current settings.
274 * @endrst
276 void vis_insert_tab(Vis*);
278 * Inserts a new line character at every cursor position.
279 * @rst
280 * .. note:: Performs auto indentation according to current settings.
281 * @endrst
283 void vis_insert_nl(Vis*);
285 /** @} */
286 /** Mode specifiers. */
287 enum VisMode {
288 VIS_MODE_NORMAL,
289 VIS_MODE_OPERATOR_PENDING,
290 VIS_MODE_VISUAL,
291 VIS_MODE_VISUAL_LINE, /**< Sub mode of `VIS_MODE_VISUAL`. */
292 VIS_MODE_INSERT,
293 VIS_MODE_REPLACE, /**< Sub mode of `VIS_MODE_INSERT`. */
294 VIS_MODE_INVALID,
298 * @defgroup vis_modes
299 * @{
302 * Switch mode.
303 * @rst
304 * .. note:: Will first trigger the leave event of the currently active
305 * mode, followed by an enter event of the new mode.
306 * No events are emitted, if the specified mode is already active.
307 * @endrst
309 void vis_mode_switch(Vis*, enum VisMode);
310 /** Get currently active mode. */
311 enum VisMode vis_mode_get(Vis*);
312 /** Translate human readable mode name to constant. */
313 enum VisMode vis_mode_from(Vis*, const char *name);
316 * @}
317 * @defgroup vis_keybind
318 * @{
320 KeyBinding *vis_binding_new(Vis*);
321 void vis_binding_free(Vis*, KeyBinding*);
324 * Set up a key binding.
325 * @param force Whether an existing mapping should be discarded.
326 * @param key The symbolic key to map.
327 * @param binding The binding to map.
328 * @rst
329 * .. note:: ``binding->key`` is always ignored in favor of ``key``.
330 * @endrst
332 bool vis_mode_map(Vis*, enum VisMode, bool force, const char *key, const KeyBinding*);
333 /** Analogous to `vis_mode_map`, but window specific. */
334 bool vis_window_mode_map(Win*, enum VisMode, bool force, const char *key, const KeyBinding*);
335 /** Unmap a symbolic key in a given mode. */
336 bool vis_mode_unmap(Vis*, enum VisMode, const char *key);
337 /** Analogous to `vis_mode_unmap`, but window specific. */
338 bool vis_window_mode_unmap(Win*, enum VisMode, const char *key);
340 * @}
341 * @defgroup vis_action
342 * @{
345 * Create new key action.
346 * @param name The name to be used as symbolic key when registering.
347 * @param help Optional single line help text.
348 * @param func The function implementing the key action logic.
349 * @param arg Argument passed to function.
351 KeyAction *vis_action_new(Vis*, const char *name, const char *help, KeyActionFunction*, Arg);
352 void vis_action_free(Vis*, KeyAction*);
354 * Register key action.
355 * @rst
356 * .. note:: Makes the key action available under the pseudo key name specified
357 * in ``keyaction->name``.
358 * @endrst
360 bool vis_action_register(Vis*, const KeyAction*);
363 * @}
364 * @defgroup vis_keymap
365 * @{
368 /** Add a key translation. */
369 bool vis_keymap_add(Vis*, const char *key, const char *mapping);
370 /** Temporarily disable the keymap for the next key press. */
371 void vis_keymap_disable(Vis*);
373 /** @} */
374 /** Operator specifiers. */
375 enum VisOperator {
376 VIS_OP_DELETE,
377 VIS_OP_CHANGE,
378 VIS_OP_YANK,
379 VIS_OP_PUT_AFTER,
380 VIS_OP_SHIFT_RIGHT,
381 VIS_OP_SHIFT_LEFT,
382 VIS_OP_JOIN,
383 VIS_OP_MODESWITCH,
384 VIS_OP_REPLACE,
385 VIS_OP_CURSOR_SOL,
386 VIS_OP_CASE_SWAP,
387 VIS_OP_FILTER,
388 VIS_OP_INVALID, /* denotes the end of the "real" operators */
389 /* pseudo operators: keep them at the end to save space in array definition */
390 VIS_OP_CASE_LOWER,
391 VIS_OP_CASE_UPPER,
392 VIS_OP_CURSOR_EOL,
393 VIS_OP_PUT_AFTER_END,
394 VIS_OP_PUT_BEFORE,
395 VIS_OP_PUT_BEFORE_END,
396 VIS_OP_LAST, /* has to be last enum member */
400 * @defgroup vis_operators
401 * @{
403 typedef struct OperatorContext OperatorContext;
406 * An operator performs a certain function on a given text range.
407 * @rst
408 * .. note:: The operator must return the new cursor position or ``EPOS`` if
409 * the cursor should be disposed.
410 * .. note:: The last used operator can be repeated using `vis_repeat`.
411 * @endrst
413 typedef size_t (VisOperatorFunction)(Vis*, Text*, OperatorContext*);
416 * Register an operator.
417 * @return Operator ID. Negative values indicate an error, positive ones can be
418 * used with `vis_operator`.
420 int vis_operator_register(Vis*, VisOperatorFunction*, void *context);
423 * Set operator to execute.
425 * Has immediate effect if:
426 * - A visual mode is active.
427 * - The same operator was already set (range will be the current line).
429 * Otherwise the operator will be executed on the range determinded by:
430 * - A motion (see `vis_motion`).
431 * - A text object (`vis_textobject`).
433 * The expected varying arguments are:
435 * - `VIS_OP_FILTER` a char pointer referring to the command to run.
436 * - `VIS_OP_JOIN` a char pointer referring to the text to insert between lines.
437 * - `VIS_OP_MODESWITCH` an ``enum VisMode`` indicating the mode to switch to.
438 * - `VIS_OP_REPLACE` a char pointer reffering to the replacement character.
440 bool vis_operator(Vis*, enum VisOperator, ...);
442 /** Repeat last operator, possibly with a new count if one was provided in the meantime. */
443 void vis_repeat(Vis*);
445 /** Cancel pending operator, reset count, motion, text object, register etc. */
446 void vis_cancel(Vis*);
448 /** @} */
449 /** Motion specifiers. */
450 enum VisMotion {
451 VIS_MOVE_LINE_DOWN,
452 VIS_MOVE_LINE_UP,
453 VIS_MOVE_SCREEN_LINE_UP,
454 VIS_MOVE_SCREEN_LINE_DOWN,
455 VIS_MOVE_SCREEN_LINE_BEGIN,
456 VIS_MOVE_SCREEN_LINE_MIDDLE,
457 VIS_MOVE_SCREEN_LINE_END,
458 VIS_MOVE_LINE_PREV,
459 VIS_MOVE_LINE_BEGIN,
460 VIS_MOVE_LINE_START,
461 VIS_MOVE_LINE_FINISH,
462 VIS_MOVE_LINE_LASTCHAR,
463 VIS_MOVE_LINE_END,
464 VIS_MOVE_LINE_NEXT,
465 VIS_MOVE_LINE,
466 VIS_MOVE_COLUMN,
467 VIS_MOVE_CHAR_PREV,
468 VIS_MOVE_CHAR_NEXT,
469 VIS_MOVE_LINE_CHAR_PREV,
470 VIS_MOVE_LINE_CHAR_NEXT,
471 VIS_MOVE_CODEPOINT_PREV,
472 VIS_MOVE_CODEPOINT_NEXT,
473 VIS_MOVE_WORD_NEXT,
474 VIS_MOVE_WORD_START_NEXT,
475 VIS_MOVE_WORD_END_PREV,
476 VIS_MOVE_WORD_END_NEXT,
477 VIS_MOVE_WORD_START_PREV,
478 VIS_MOVE_LONGWORD_NEXT,
479 VIS_MOVE_LONGWORD_START_PREV,
480 VIS_MOVE_LONGWORD_START_NEXT,
481 VIS_MOVE_LONGWORD_END_PREV,
482 VIS_MOVE_LONGWORD_END_NEXT,
483 VIS_MOVE_SENTENCE_PREV,
484 VIS_MOVE_SENTENCE_NEXT,
485 VIS_MOVE_PARAGRAPH_PREV,
486 VIS_MOVE_PARAGRAPH_NEXT,
487 VIS_MOVE_FUNCTION_START_PREV,
488 VIS_MOVE_FUNCTION_START_NEXT,
489 VIS_MOVE_FUNCTION_END_PREV,
490 VIS_MOVE_FUNCTION_END_NEXT,
491 VIS_MOVE_BLOCK_START,
492 VIS_MOVE_BLOCK_END,
493 VIS_MOVE_PARENTHESE_START,
494 VIS_MOVE_PARENTHESE_END,
495 VIS_MOVE_BRACKET_MATCH,
496 VIS_MOVE_LEFT_TO,
497 VIS_MOVE_RIGHT_TO,
498 VIS_MOVE_LEFT_TILL,
499 VIS_MOVE_RIGHT_TILL,
500 VIS_MOVE_FILE_BEGIN,
501 VIS_MOVE_FILE_END,
502 VIS_MOVE_MARK,
503 VIS_MOVE_MARK_LINE,
504 VIS_MOVE_SEARCH_WORD_FORWARD,
505 VIS_MOVE_SEARCH_WORD_BACKWARD,
506 VIS_MOVE_SEARCH_REPEAT_FORWARD,
507 VIS_MOVE_SEARCH_REPEAT_BACKWARD,
508 VIS_MOVE_WINDOW_LINE_TOP,
509 VIS_MOVE_WINDOW_LINE_MIDDLE,
510 VIS_MOVE_WINDOW_LINE_BOTTOM,
511 VIS_MOVE_CHANGELIST_NEXT,
512 VIS_MOVE_CHANGELIST_PREV,
513 VIS_MOVE_JUMPLIST_NEXT,
514 VIS_MOVE_JUMPLIST_PREV,
515 VIS_MOVE_NOP,
516 VIS_MOVE_PERCENT,
517 VIS_MOVE_BYTE,
518 VIS_MOVE_BYTE_LEFT,
519 VIS_MOVE_BYTE_RIGHT,
520 VIS_MOVE_INVALID, /* denotes the end of the "real" motions */
521 /* pseudo motions: keep them at the end to save space in array definition */
522 VIS_MOVE_TOTILL_REPEAT,
523 VIS_MOVE_TOTILL_REVERSE,
524 VIS_MOVE_SEARCH_FORWARD,
525 VIS_MOVE_SEARCH_BACKWARD,
526 VIS_MOVE_SEARCH_REPEAT,
527 VIS_MOVE_SEARCH_REPEAT_REVERSE,
528 VIS_MOVE_LAST, /* denotes the end of all motions */
532 * @defgroup vis_motions
533 * @{
536 * Set motion to perform.
538 * The following motions take an additional argument:
540 * - `VIS_MOVE_SEARCH_FORWARD` and `VIS_MOVE_SEARCH_BACKWARD`
542 * The search pattern as ``const char *``.
544 * - ``VIS_MOVE_{LEFT,RIGHT}_{TO,TILL}``
546 * The character to search for as ``const char *``.
548 * - `VIS_MOVE_MARK` and `VIS_MOVE_MARK_LINE`
550 * A valid ``enum VisMark``.
552 bool vis_motion(Vis*, enum VisMotion, ...);
554 enum VisMotionType {
555 VIS_MOTIONTYPE_LINEWISE = 1 << 0,
556 VIS_MOTIONTYPE_CHARWISE = 1 << 1,
559 /** Force currently specified motion to behave in line or character wise mode. */
560 void vis_motion_type(Vis *vis, enum VisMotionType);
563 * Motions take a starting position and transform it to an end position.
564 * @rst
565 * .. note:: Should a motion not be possible, the original position must be returned.
566 * TODO: we might want to change that to ``EPOS``?
567 * @endrst
569 typedef size_t (VisMotionFunction)(Vis*, Win*, void *context, size_t pos);
572 * Register a motion function.
573 * @return Motion ID. Negative values indicate an error, positive ones can be
574 * used with `vis_motion`.
576 int vis_motion_register(Vis*, enum VisMotionType, void *context, VisMotionFunction*);
579 * @}
580 * @defgroup vis_count
581 * @{
583 /** No count was specified. */
584 #define VIS_COUNT_UNKNOWN (-1)
585 /** Get count, might return `VIS_COUNT_UNKNOWN`. */
586 int vis_count_get(Vis*);
587 /** Get count, if none was specified, return ``def``. */
588 int vis_count_get_default(Vis*, int def);
589 /** Set a count. */
590 void vis_count_set(Vis*, int count);
592 typedef struct {
593 Vis *vis;
594 int iteration;
595 int count;
596 } VisCountIterator;
598 /** Get iterator initialized with current count or ``def`` if not specified. */
599 VisCountIterator vis_count_iterator_get(Vis*, int def);
600 /** Get iterator initialized with a count value. */
601 VisCountIterator vis_count_iterator_init(Vis*, int count);
603 * Increment iterator counter.
604 * @return Whether iteration should continue.
605 * @rst
606 * .. note:: Terminates iteration if the edtior was
607 * `interrupted <vis_interrupt>`_ in the meantime.
608 * @endrst
610 bool vis_count_iterator_next(VisCountIterator*);
612 /** @} */
613 /** Text object specifier. */
614 enum VisTextObject {
615 VIS_TEXTOBJECT_INNER_WORD,
616 VIS_TEXTOBJECT_OUTER_WORD,
617 VIS_TEXTOBJECT_INNER_LONGWORD,
618 VIS_TEXTOBJECT_OUTER_LONGWORD,
619 VIS_TEXTOBJECT_SENTENCE,
620 VIS_TEXTOBJECT_PARAGRAPH,
621 VIS_TEXTOBJECT_OUTER_SQUARE_BRACKET,
622 VIS_TEXTOBJECT_INNER_SQUARE_BRACKET,
623 VIS_TEXTOBJECT_OUTER_CURLY_BRACKET,
624 VIS_TEXTOBJECT_INNER_CURLY_BRACKET,
625 VIS_TEXTOBJECT_OUTER_ANGLE_BRACKET,
626 VIS_TEXTOBJECT_INNER_ANGLE_BRACKET,
627 VIS_TEXTOBJECT_OUTER_PARANTHESE,
628 VIS_TEXTOBJECT_INNER_PARANTHESE,
629 VIS_TEXTOBJECT_OUTER_QUOTE,
630 VIS_TEXTOBJECT_INNER_QUOTE,
631 VIS_TEXTOBJECT_OUTER_SINGLE_QUOTE,
632 VIS_TEXTOBJECT_INNER_SINGLE_QUOTE,
633 VIS_TEXTOBJECT_OUTER_BACKTICK,
634 VIS_TEXTOBJECT_INNER_BACKTICK,
635 VIS_TEXTOBJECT_OUTER_ENTIRE,
636 VIS_TEXTOBJECT_INNER_ENTIRE,
637 VIS_TEXTOBJECT_OUTER_LINE,
638 VIS_TEXTOBJECT_INNER_LINE,
639 VIS_TEXTOBJECT_INDENTATION,
640 VIS_TEXTOBJECT_SEARCH_FORWARD,
641 VIS_TEXTOBJECT_SEARCH_BACKWARD,
642 VIS_TEXTOBJECT_INVALID,
646 * @defgroup vis_textobjs
647 * @{
651 * Text objects take a starting position and return a text range.
652 * @rst
653 * .. note:: The originating position does not necessarily have to be contained in
654 * the resulting range.
655 * @endrst
657 typedef Filerange (VisTextObjectFunction)(Vis*, Win*, void *context, size_t pos);
660 * Register a new text object.
661 * @return Text object ID. Negative values indicate an error, positive ones can be
662 * used with `vis_textobject`.
664 int vis_textobject_register(Vis*, int type, void *data, VisTextObjectFunction*);
666 /** Set text object to use. */
667 bool vis_textobject(Vis*, enum VisTextObject);
669 /** @} */
670 /** Mark specifiers. */
671 enum VisMark {
672 VIS_MARK_SELECTION_START, /* '< */
673 VIS_MARK_SELECTION_END, /* '> */
674 VIS_MARK_a, VIS_MARK_b, VIS_MARK_c, VIS_MARK_d, VIS_MARK_e,
675 VIS_MARK_f, VIS_MARK_g, VIS_MARK_h, VIS_MARK_i, VIS_MARK_j,
676 VIS_MARK_k, VIS_MARK_l, VIS_MARK_m, VIS_MARK_n, VIS_MARK_o,
677 VIS_MARK_p, VIS_MARK_q, VIS_MARK_r, VIS_MARK_s, VIS_MARK_t,
678 VIS_MARK_u, VIS_MARK_v, VIS_MARK_w, VIS_MARK_x, VIS_MARK_y,
679 VIS_MARK_z,
680 VIS_MARK_INVALID, /* has to be the last enum member */
684 * @}
685 * @defgroup vis_marks
686 * @{
688 /** Translate single character mark name to corresponding constant. */
689 enum VisMark vis_mark_from(Vis*, char mark);
691 * Set a mark.
692 * @rst
693 * .. note:: The same semantics as for `text_mark_set` apply.
694 * @endrst
696 void vis_mark_set(Vis*, enum VisMark mark, size_t pos);
698 /** @} */
699 /** Register specifiers. */
700 enum VisRegister {
701 VIS_REG_DEFAULT, /* used when no other register is specified */
702 VIS_REG_ZERO, /* yank register */
703 VIS_REG_AMPERSAND, /* last regex match */
704 VIS_REG_1, /* 1-9 last sub-expression matches */
705 VIS_REG_2,
706 VIS_REG_3,
707 VIS_REG_4,
708 VIS_REG_5,
709 VIS_REG_6,
710 VIS_REG_7,
711 VIS_REG_8,
712 VIS_REG_9,
713 VIS_REG_BLACKHOLE, /* /dev/null register */
714 VIS_REG_CLIPBOARD, /* system clipboard register */
715 VIS_REG_DOT, /* last inserted text, copy of VIS_MACRO_OPERATOR */
716 VIS_REG_SEARCH, /* last used search pattern "/ */
717 VIS_REG_COMMAND, /* last used :-command ": */
718 VIS_REG_SHELL, /* last used shell command given to either <, >, |, or ! */
719 VIS_REG_NUMBER, /* cursor number */
720 VIS_REG_a, VIS_REG_b, VIS_REG_c, VIS_REG_d, VIS_REG_e,
721 VIS_REG_f, VIS_REG_g, VIS_REG_h, VIS_REG_i, VIS_REG_j,
722 VIS_REG_k, VIS_REG_l, VIS_REG_m, VIS_REG_n, VIS_REG_o,
723 VIS_REG_p, VIS_REG_q, VIS_REG_r, VIS_REG_s, VIS_REG_t,
724 VIS_REG_u, VIS_REG_v, VIS_REG_w, VIS_REG_x, VIS_REG_y,
725 VIS_REG_z,
726 VIS_MACRO_OPERATOR, /* records entered keys after an operator */
727 VIS_REG_PROMPT, /* internal register which shadows DEFAULT in PROMPT mode */
728 VIS_REG_INVALID, /* has to be the last 'real' register */
729 VIS_REG_A, VIS_REG_B, VIS_REG_C, VIS_REG_D, VIS_REG_E,
730 VIS_REG_F, VIS_REG_G, VIS_REG_H, VIS_REG_I, VIS_REG_J,
731 VIS_REG_K, VIS_REG_L, VIS_REG_M, VIS_REG_N, VIS_REG_O,
732 VIS_REG_P, VIS_REG_Q, VIS_REG_R, VIS_REG_S, VIS_REG_T,
733 VIS_REG_U, VIS_REG_V, VIS_REG_W, VIS_REG_X, VIS_REG_Y,
734 VIS_REG_Z,
735 VIS_MACRO_LAST_RECORDED, /* pseudo macro referring to last recorded one */
739 * @defgroup vis_registers
740 * @{
742 /** Translate single character register name to corresponding constant. */
743 enum VisRegister vis_register_from(Vis*, char reg);
745 * Specify register to use.
746 * @rst
747 * .. note:: If none is specified `VIS_REG_DEFAULT` will be used.
748 * @endrst
750 void vis_register(Vis*, enum VisRegister);
751 /** Get register content. */
752 const char *vis_register_get(Vis*, enum VisRegister, size_t *len);
753 const char *vis_register_slot_get(Vis*, enum VisRegister, size_t slot, size_t *len);
754 /** Set register content. */
755 bool vis_register_put(Vis*, enum VisRegister, const char *data, size_t len);
756 bool vis_register_slot_put(Vis*, enum VisRegister, size_t slot, const char *data, size_t len);
758 * @}
759 * @defgroup vis_macros
760 * @{
763 * Start recording a macro.
764 * @rst
765 * .. note:: Fails if a recording is already ongoing.
766 * @endrst
768 bool vis_macro_record(Vis*, enum VisRegister);
769 /** Stop recording, fails if there is nothing to stop. */
770 bool vis_macro_record_stop(Vis*);
771 /** Check whether a recording is currently ongoing. */
772 bool vis_macro_recording(Vis*);
774 * Replay a macro.
775 * @rst
776 * .. note:: A macro currently being recorded can not be replayed.
777 * @endrst
779 bool vis_macro_replay(Vis*, enum VisRegister);
782 * @}
783 * @defgroup vis_cmds
784 * @{
787 /** Execute a ``:``-command. */
788 bool vis_cmd(Vis*, const char *cmd);
790 /** Command handler function. */
791 typedef bool (VisCommandFunction)(Vis*, Win*, void *data, bool force,
792 const char *argv[], Cursor*, Filerange*);
794 * Register new ``:``-command.
795 * @param name The command name.
796 * @param help Optional single line help text.
797 * @param context User supplied context pointer passed to the handler function.
798 * @param func The function implementing the command logic.
799 * @rst
800 * .. note:: Any unique prefix of the command name will invoke the command.
801 * @endrst
803 bool vis_cmd_register(Vis*, const char *name, const char *help, void *context, VisCommandFunction*);
805 /** Unregister ``:``-command. */
806 bool vis_cmd_unregister(Vis*, const char *name);
809 * @}
810 * @defgroup vis_options
811 * @{
813 /** Option properties. */
814 enum VisOption {
815 VIS_OPTION_TYPE_BOOL = 1 << 0,
816 VIS_OPTION_TYPE_STRING = 1 << 1,
817 VIS_OPTION_TYPE_NUMBER = 1 << 2,
818 VIS_OPTION_VALUE_OPTIONAL = 1 << 3,
819 VIS_OPTION_NEED_WINDOW = 1 << 4,
823 * Option handler function.
824 * @param win The window to which option should apply, might be ``NULL``.
825 * @param context User provided context pointer as given to `vis_option_register`.
826 * @param force Whether the option was specfied with a bang ``!``.
827 * @param name Name of option which was set.
828 * @param arg The new option value.
830 typedef bool (VisOptionFunction)(Vis*, Win*, void *context, bool toggle,
831 enum VisOption, const char *name, Arg *value);
834 * Register a new ``:set`` option.
835 * @param names A ``NULL`` terminated array of option names.
836 * @param option Option properties.
837 * @param func The function handling the option.
838 * @param context User supplied context pointer passed to the handler function.
839 * @param help Optional single line help text.
840 * @rst
841 * .. note:: Fails if any of the given option names is already registered.
842 * @endrst
844 bool vis_option_register(Vis*, const char *names[], enum VisOption,
845 VisOptionFunction*, void *context, const char *help);
847 * Unregister an existing ``:set`` option.
848 * @rst
849 * .. note:: Also unregisters all aliases as given to `vis_option_register`.
850 * @endrst
852 bool vis_option_unregister(Vis*, const char *name);
854 /** Execute any kind (``:``, ``?``, ``/``) of prompt command */
855 bool vis_prompt_cmd(Vis*, const char *cmd);
858 * Pipe a given file range to an external process.
860 * If the range is invalid 'interactive' mode is enabled, meaning that
861 * stdin and stderr are passed through the underlying command, stdout
862 * points to vis' stderr.
864 * If ``argv`` contains only one non-NULL element the command is executed
865 * through an intermediate shell (using ``/bin/sh -c argv[0]``) that is
866 * argument expansion is performed by the shell. Otherwise the argument
867 * list will be passed unmodified to ``execvp(argv[0], argv)``.
869 * If the ``read_stdout`` and ``read_stderr`` callbacks are non-NULL they
870 * will be invoked when output from the forked process is available.
872 * @rst
873 * .. warning:: The editor core is blocked until this function returns.
874 * @endrst
876 * @return The exit status of the forked process.
878 int vis_pipe(Vis*, File*, Filerange*, const char *argv[],
879 void *stdout_context, ssize_t (*read_stdout)(void *stdout_context, char *data, size_t len),
880 void *stderr_context, ssize_t (*read_stderr)(void *stderr_context, char *data, size_t len));
883 * Pipe a Filerange to an external process, return its exit status and capture
884 * everything that is written to stdout/stderr.
885 * @param argv Argument list, must be ``NULL`` terminated.
886 * @param out Data written to ``stdout``, will be ``NUL`` terminated.
887 * @param err Data written to ``stderr``, will be ``NUL`` terminated.
888 * @rst
889 * .. warning:: The pointers stored in ``out`` and ``err`` need to be `free(3)`-ed
890 * by the caller.
891 * @endrst
893 int vis_pipe_collect(Vis*, File*, Filerange*, const char *argv[], char **out, char **err);
896 * @}
897 * @defgroup vis_keys
898 * @{
901 * Advance to the start of the next symbolic key.
903 * Given the start of a symbolic key, returns a pointer to the start of the one
904 * immediately following it.
906 const char *vis_keys_next(Vis*, const char *keys);
907 /** Convert next symbolic key to an Unicode code point, returns ``-1`` for unknown keys. */
908 long vis_keys_codepoint(Vis*, const char *keys);
910 * Convert next symbolic key to a UTF-8 sequence.
911 * @return Whether conversion was successful, if not ``utf8`` is left unmodified.
912 * @rst
913 * .. note:: Guarantees that ``utf8`` is NUL terminated on success.
914 * @endrst
916 bool vis_keys_utf8(Vis*, const char *keys, char utf8[static UTFmax+1]);
917 /** Process symbolic keys as if they were user originated input. */
918 void vis_keys_feed(Vis*, const char *keys);
920 * @}
921 * @defgroup vis_misc
922 * @{
926 * Get a regex object matching pattern.
927 * @param regex The regex pattern to compile, if ``NULL`` the most recently used
928 * one is substituted.
929 * @return A Regex object or ``NULL`` in case of an error.
930 * @rst
931 * .. warning:: The caller must free the regex object using `text_regex_free`.
932 * @endrst
934 Regex *vis_regex(Vis*, const char *pattern);
937 * Take an undo snaphost to which we can later revert to.
938 * @rst
939 * .. note:: Does nothing when invoked while replaying a macro.
940 * @endrst
942 void vis_file_snapshot(Vis*, File*);
943 /** @} */
945 /* TODO: expose proper API to iterate through files etc */
946 Text *vis_text(Vis*);
947 View *vis_view(Vis*);
948 Win *vis_window(Vis*);
950 /* Get value of autoindent */
951 bool vis_get_autoindent(const Vis*);
953 #endif