vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

text-objects.h

(2767B)


      1 #ifndef TEXT_OBJECTS_H
      2 #define TEXT_OBJECTS_H
      3 
      4 /* these functions all take a file position. If this position is part of the
      5  * respective text-object, a corresponding range is returned. If there is no
      6  * such text-object at the given location, an empty range is returned.
      7  */
      8 
      9 #include <stddef.h>
     10 #include "text.h"
     11 
     12 /* return range covering the entire text */
     13 Filerange text_object_entire(Text*, size_t pos);
     14 /* word which happens to be at pos without any neighbouring white spaces */
     15 Filerange text_object_word(Text*, size_t pos);
     16 /* includes trailing white spaces. If at pos happens to be a white space
     17  * include all neighbouring leading white spaces and the following word. */
     18 Filerange text_object_word_outer(Text*, size_t pos);
     19 /* find next occurrence of `word' (as word not substring) in forward/backward direction */
     20 Filerange text_object_word_find_next(Text*, size_t pos, const char *word);
     21 Filerange text_object_word_find_prev(Text*, size_t pos, const char *word);
     22 /* find next occurrence of a literal string (not regex) in forward/backward direction */
     23 Filerange text_object_find_next(Text *txt, size_t pos, const char *search);
     24 Filerange text_object_find_prev(Text *txt, size_t pos, const char *search);
     25 /* same semantics as above but for a longword (i.e. delimited by white spaces) */
     26 Filerange text_object_longword(Text*, size_t pos);
     27 Filerange text_object_longword_outer(Text*, size_t pos);
     28 
     29 Filerange text_object_line(Text*, size_t pos);
     30 Filerange text_object_line_inner(Text*, size_t pos);
     31 Filerange text_object_sentence(Text*, size_t pos);
     32 Filerange text_object_paragraph(Text*, size_t pos);
     33 Filerange text_object_paragraph_outer(Text*, size_t pos);
     34 
     35 /* these are inner text objects i.e. the delimiters themself are not
     36  * included in the range */
     37 Filerange text_object_square_bracket(Text*, size_t pos);
     38 Filerange text_object_curly_bracket(Text*, size_t pos);
     39 Filerange text_object_angle_bracket(Text*, size_t pos);
     40 Filerange text_object_parenthesis(Text*, size_t pos);
     41 Filerange text_object_quote(Text*, size_t pos);
     42 Filerange text_object_single_quote(Text*, size_t pos);
     43 Filerange text_object_backtick(Text*, size_t pos);
     44 /* match a search term in either forward or backward direction */
     45 Filerange text_object_search_forward(Text*, size_t pos, Regex*);
     46 Filerange text_object_search_backward(Text*, size_t pos, Regex*);
     47 /* match all lines with same indentation level as the current one */
     48 Filerange text_object_indentation(Text*, size_t pos);
     49 
     50 /* extend a range to cover whole lines */
     51 Filerange text_range_linewise(Text*, Filerange*);
     52 /* trim leading and trailing white spaces from range */
     53 Filerange text_range_inner(Text*, Filerange*);
     54 /* test whether a given range covers whole lines */
     55 bool text_range_is_linewise(Text*, Filerange*);
     56 
     57 #endif