src/nvim/eval/funcs.c
/*
 * Get buffer by number or pattern.
 */
Get buffer by number or pattern.
Get buffer by number or pattern .
buf_T *tv_get_buf(typval_T *tv, int curtab_only)
{
  char_u      *name = tv->vval.v_string;
  int save_magic;
  char_u      *save_cpo;
  buf_T       *buf;
  if (tv->v_type == VAR_NUMBER)
    return buflist_findnr((int)tv->vval.v_number);
  if (tv->v_type != VAR_STRING)
    return NULL;
  if (name == NULL || *name == NUL)
    return curbuf;
  if (name[0] == '$' && name[1] == NUL)
    return lastbuf;
  save_magic = p_magic;
  p_magic = TRUE;
  save_cpo = p_cpo;
  p_cpo = (char_u *)"";
  buf = buflist_findnr(buflist_findpat(name, name + STRLEN(name),
                                       TRUE, FALSE, curtab_only));
  p_magic = save_magic;
  p_cpo = save_cpo;
  if (buf == NULL) {
    buf = find_buffer(tv);
  }
  return buf;
}
buf_T * tv_get_buf ( typval_T * tv , int curtab_only ) { char_u * name = tv -> vval . v_string ; int save_magic ; char_u * save_cpo ; buf_T * buf ; if ( tv -> v_type == VAR_NUMBER ) return buflist_findnr ( ( int ) tv -> vval . v_number ) ; if ( tv -> v_type != VAR_STRING ) return NULL ; if ( name == NULL || * name == NUL ) return curbuf ; if ( name [ 0 ] == ' ' && name [ 1 ] == NUL ) return lastbuf ; save_magic = p_magic ; p_magic = TRUE ; save_cpo = p_cpo ; p_cpo = ( char_u * ) " " ; buf = buflist_findnr ( buflist_findpat ( name , name + STRLEN ( name ) , TRUE , FALSE , curtab_only ) ) ; p_magic = save_magic ; p_cpo = save_cpo ; if ( buf == NULL ) { buf = find_buffer ( tv ) ; } return buf ; }
Get buffer by number or pattern.
Get buffer by number or pattern .
// Ignore 'magic' and 'cpoptions' here to make scripts portable // If not found, try expanding the name, like done for bufexists().