neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

plines.h (2968B)


      1 #pragma once
      2 
      3 #include <stdbool.h>
      4 #include <stdint.h>
      5 
      6 #include "nvim/marktree_defs.h"
      7 #include "nvim/pos_defs.h"
      8 #include "nvim/types_defs.h"
      9 
     10 typedef bool CSType;
     11 
     12 enum {
     13  kCharsizeRegular,
     14  kCharsizeFast,
     15 };
     16 
     17 /// Argument for char size functions.
     18 typedef struct {
     19  win_T *win;
     20  char *line;                ///< Start of the line.
     21 
     22  bool use_tabstop;          ///< Use 'tabstop' instead of char2cells() for a TAB.
     23  int indent_width;          ///< Width of 'showbreak' and 'breakindent' on wrapped
     24                             ///< parts of lines, INT_MIN if not yet calculated.
     25 
     26  int virt_row;              ///< Row for virtual text, -1 if no virtual text.
     27  int cur_text_width_left;   ///< Width of virtual text left of cursor.
     28  int cur_text_width_right;  ///< Width of virtual text right of cursor.
     29 
     30  int max_head_vcol;         ///< See charsize_regular().
     31  MarkTreeIter iter[1];
     32 } CharsizeArg;
     33 
     34 typedef struct {
     35  int width;
     36  int head;  ///< Size of 'breakindent' etc. before the character (included in width).
     37 } CharSize;
     38 
     39 #include "plines.h.generated.h"
     40 #include "plines.h.inline.generated.h"
     41 
     42 /// Get the number of cells taken up on the screen by the given character at vcol.
     43 /// "csarg->cur_text_width_left" and "csarg->cur_text_width_right" are set
     44 /// to the extra size for inline virtual text.
     45 ///
     46 /// When "csarg->max_head_vcol" is positive, only count in "head" the size
     47 /// of 'showbreak'/'breakindent' before "csarg->max_head_vcol".
     48 /// When "csarg->max_head_vcol" is negative, only count in "head" the size
     49 /// of 'showbreak'/'breakindent' before where cursor should be placed.
     50 static inline CharSize win_charsize(CSType cstype, int vcol, char *ptr, int32_t chr,
     51                                    CharsizeArg *csarg)
     52  FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
     53 {
     54  if (cstype == kCharsizeFast) {
     55    return charsize_fast(csarg, ptr, vcol, chr);
     56  } else {
     57    return charsize_regular(csarg, ptr, vcol, chr);
     58  }
     59 }
     60 
     61 /// Return the number of cells the string "s" will take on the screen,
     62 /// taking into account the size of a tab.
     63 ///
     64 /// @param s
     65 ///
     66 /// @return Number of cells the string will take on the screen.
     67 static inline int linetabsize_str(char *s)
     68  FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
     69 {
     70  return linetabsize_col(0, s);
     71 }
     72 
     73 /// Like linetabsize_str(), but for a given window instead of the current one.
     74 /// Doesn't count the size of 'listchars' "eol".
     75 ///
     76 /// @param wp
     77 /// @param line
     78 /// @param len
     79 ///
     80 /// @return Number of cells the string will take on the screen.
     81 static inline int win_linetabsize(win_T *wp, linenr_T lnum, char *line, colnr_T len)
     82  FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALWAYS_INLINE
     83 {
     84  CharsizeArg csarg;
     85  CSType const cstype = init_charsize_arg(&csarg, wp, lnum, line);
     86  if (cstype == kCharsizeFast) {
     87    return linesize_fast(&csarg, 0, len);
     88  } else {
     89    return linesize_regular(&csarg, 0, len);
     90  }
     91 }