@@ -6963,15 +6963,18 @@ line_count_info(line, wc, cc, limit, eol_size)
69636963 * Give some info about the position of the cursor (for "g CTRL-G").
69646964 * In Visual mode, give some info about the selected region. (In this case,
69656965 * the *_count_cursor variables store running totals for the selection.)
6966+ * When "dict" is not NULL store the info there instead of showing it.
69666967 */
69676968 void
6968- cursor_pos_info ()
6969+ cursor_pos_info (dict )
6970+ dict_T * dict ;
69696971{
69706972 char_u * p ;
69716973 char_u buf1 [50 ];
69726974 char_u buf2 [40 ];
69736975 linenr_T lnum ;
69746976 long byte_count = 0 ;
6977+ long bom_count = 0 ;
69756978 long byte_count_cursor = 0 ;
69766979 long char_count = 0 ;
69776980 long char_count_cursor = 0 ;
@@ -6989,7 +6992,11 @@ cursor_pos_info()
69896992 */
69906993 if (curbuf -> b_ml .ml_flags & ML_EMPTY )
69916994 {
6992- MSG (_ (no_lines_msg ));
6995+ if (dict == NULL )
6996+ {
6997+ MSG (_ (no_lines_msg ));
6998+ return ;
6999+ }
69937000 }
69947001 else
69957002 {
@@ -7122,74 +7129,98 @@ cursor_pos_info()
71227129 if (!curbuf -> b_p_eol && (curbuf -> b_p_bin || !curbuf -> b_p_fixeol ))
71237130 byte_count -= eol_size ;
71247131
7125- if (VIsual_active )
7132+ if (dict == NULL )
71267133 {
7127- if (VIsual_mode == Ctrl_V && curwin -> w_curswant < MAXCOL )
7134+ if (VIsual_active )
71287135 {
7129- getvcols (curwin , & min_pos , & max_pos , & min_pos .col ,
7130- & max_pos .col );
7131- vim_snprintf ((char * )buf1 , sizeof (buf1 ), _ ("%ld Cols; " ),
7132- (long )(oparg .end_vcol - oparg .start_vcol + 1 ));
7136+ if (VIsual_mode == Ctrl_V && curwin -> w_curswant < MAXCOL )
7137+ {
7138+ getvcols (curwin , & min_pos , & max_pos , & min_pos .col ,
7139+ & max_pos .col );
7140+ vim_snprintf ((char * )buf1 , sizeof (buf1 ), _ ("%ld Cols; " ),
7141+ (long )(oparg .end_vcol - oparg .start_vcol + 1 ));
7142+ }
7143+ else
7144+ buf1 [0 ] = NUL ;
7145+
7146+ if (char_count_cursor == byte_count_cursor
7147+ && char_count == byte_count )
7148+ vim_snprintf ((char * )IObuff , IOSIZE ,
7149+ _ ("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Bytes" ),
7150+ buf1 , line_count_selected ,
7151+ (long )curbuf -> b_ml .ml_line_count ,
7152+ word_count_cursor , word_count ,
7153+ byte_count_cursor , byte_count );
7154+ else
7155+ vim_snprintf ((char * )IObuff , IOSIZE ,
7156+ _ ("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Chars; %ld of %ld Bytes" ),
7157+ buf1 , line_count_selected ,
7158+ (long )curbuf -> b_ml .ml_line_count ,
7159+ word_count_cursor , word_count ,
7160+ char_count_cursor , char_count ,
7161+ byte_count_cursor , byte_count );
71337162 }
71347163 else
7135- buf1 [0 ] = NUL ;
7136-
7137- if (char_count_cursor == byte_count_cursor
7138- && char_count == byte_count )
7139- vim_snprintf ((char * )IObuff , IOSIZE ,
7140- _ ("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Bytes" ),
7141- buf1 , line_count_selected ,
7164+ {
7165+ p = ml_get_curline ();
7166+ validate_virtcol ();
7167+ col_print (buf1 , sizeof (buf1 ), (int )curwin -> w_cursor .col + 1 ,
7168+ (int )curwin -> w_virtcol + 1 );
7169+ col_print (buf2 , sizeof (buf2 ), (int )STRLEN (p ),
7170+ linetabsize (p ));
7171+
7172+ if (char_count_cursor == byte_count_cursor
7173+ && char_count == byte_count )
7174+ vim_snprintf ((char * )IObuff , IOSIZE ,
7175+ _ ("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Byte %ld of %ld" ),
7176+ (char * )buf1 , (char * )buf2 ,
7177+ (long )curwin -> w_cursor .lnum ,
71427178 (long )curbuf -> b_ml .ml_line_count ,
71437179 word_count_cursor , word_count ,
71447180 byte_count_cursor , byte_count );
7145- else
7146- vim_snprintf ((char * )IObuff , IOSIZE ,
7147- _ ("Selected %s%ld of %ld Lines; %ld of %ld Words; %ld of %ld Chars; %ld of %ld Bytes" ),
7148- buf1 , line_count_selected ,
7181+ else
7182+ vim_snprintf ((char * )IObuff , IOSIZE ,
7183+ _ ("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Char %ld of %ld; Byte %ld of %ld" ),
7184+ (char * )buf1 , (char * )buf2 ,
7185+ (long )curwin -> w_cursor .lnum ,
71497186 (long )curbuf -> b_ml .ml_line_count ,
71507187 word_count_cursor , word_count ,
71517188 char_count_cursor , char_count ,
71527189 byte_count_cursor , byte_count );
7153- }
7154- else
7155- {
7156- p = ml_get_curline ();
7157- validate_virtcol ();
7158- col_print (buf1 , sizeof (buf1 ), (int )curwin -> w_cursor .col + 1 ,
7159- (int )curwin -> w_virtcol + 1 );
7160- col_print (buf2 , sizeof (buf2 ), (int )STRLEN (p ),
7161- linetabsize (p ));
7162-
7163- if (char_count_cursor == byte_count_cursor
7164- && char_count == byte_count )
7165- vim_snprintf ((char * )IObuff , IOSIZE ,
7166- _ ("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Byte %ld of %ld" ),
7167- (char * )buf1 , (char * )buf2 ,
7168- (long )curwin -> w_cursor .lnum ,
7169- (long )curbuf -> b_ml .ml_line_count ,
7170- word_count_cursor , word_count ,
7171- byte_count_cursor , byte_count );
7172- else
7173- vim_snprintf ((char * )IObuff , IOSIZE ,
7174- _ ("Col %s of %s; Line %ld of %ld; Word %ld of %ld; Char %ld of %ld; Byte %ld of %ld" ),
7175- (char * )buf1 , (char * )buf2 ,
7176- (long )curwin -> w_cursor .lnum ,
7177- (long )curbuf -> b_ml .ml_line_count ,
7178- word_count_cursor , word_count ,
7179- char_count_cursor , char_count ,
7180- byte_count_cursor , byte_count );
7190+ }
71817191 }
71827192
7193+ /* Don't shorten this message, the user asked for it. */
71837194#ifdef FEAT_MBYTE
7184- byte_count = bomb_size ();
7185- if (byte_count > 0 )
7195+ bom_count = bomb_size ();
7196+ if (bom_count > 0 )
71867197 sprintf ((char * )IObuff + STRLEN (IObuff ), _ ("(+%ld for BOM)" ),
7187- byte_count );
7198+ bom_count );
71887199#endif
7189- /* Don't shorten this message, the user asked for it. */
7190- p = p_shm ;
7191- p_shm = (char_u * )"" ;
7192- msg (IObuff );
7193- p_shm = p ;
7200+ if (dict == NULL )
7201+ {
7202+ p = p_shm ;
7203+ p_shm = (char_u * )"" ;
7204+ msg (IObuff );
7205+ p_shm = p ;
7206+ }
7207+ }
7208+ if (dict != NULL )
7209+ {
7210+ dict_add_nr_str (dict , "words" , (long )word_count , NULL );
7211+ dict_add_nr_str (dict , "chars" , (long )char_count , NULL );
7212+ dict_add_nr_str (dict , "bytes" , (long )byte_count + bom_count , NULL );
7213+ if (VIsual_active )
7214+ {
7215+ dict_add_nr_str (dict , "visual_bytes" , (long )byte_count_cursor , NULL );
7216+ dict_add_nr_str (dict , "visual_chars" , (long )char_count_cursor , NULL );
7217+ dict_add_nr_str (dict , "visual_words" , (long )word_count_cursor , NULL );
7218+ }
7219+ else
7220+ {
7221+ dict_add_nr_str (dict , "cursor_bytes" , (long )byte_count_cursor , NULL );
7222+ dict_add_nr_str (dict , "cursor_chars" , (long )char_count_cursor , NULL );
7223+ dict_add_nr_str (dict , "cursor_words" , (long )word_count_cursor , NULL );
7224+ }
71947225 }
71957226}
0 commit comments