Beispiel #1
0
/* For use by abbrev_match(): Match SYMBOL's name against buffer text
   before point, case-insensitively.  When found, return non-zero, so
   that map_obarray terminates mapping.  */
static int abbrev_match_mapper(Lisp_Object symbol, void *arg)
{
	struct abbrev_match_mapper_closure *closure =
	    (struct abbrev_match_mapper_closure *)arg;
	Charcount abbrev_length;
	Lisp_Symbol *sym = XSYMBOL(symbol);
	Lisp_String *abbrev;

	/* symbol_value should be OK here, because abbrevs are not expected
	   to contain any SYMBOL_MAGIC stuff.  */
	if (UNBOUNDP(symbol_value(sym)) || NILP(symbol_value(sym))) {
		/* The symbol value of nil means that abbrev got undefined. */
		return 0;
	}
	abbrev = symbol_name(sym);
	abbrev_length = string_char_length(abbrev);
	if (abbrev_length > closure->maxlen) {
		/* This abbrev is too large -- it wouldn't fit. */
		return 0;
	}
	/* If `bar' is an abbrev, and a user presses `fubar<SPC>', we don't
	   normally want to expand it.  OTOH, if the abbrev begins with
	   non-word syntax (e.g. `#if'), it is OK to abbreviate it anywhere.  */
	if (abbrev_length < closure->maxlen && abbrev_length > 0
	    && (WORD_SYNTAX_P(closure->chartab, string_char(abbrev, 0)))
	    && (WORD_SYNTAX_P(closure->chartab,
			      BUF_FETCH_CHAR(closure->buf,
					     closure->point - (abbrev_length +
							       1))))) {
		return 0;
	}
	/* Match abbreviation string against buffer text.  */
	{
		Bufbyte *ptr = string_data(abbrev);
		Charcount idx;

		for (idx = 0; idx < abbrev_length; idx++) {
			if (DOWNCASE(closure->buf,
				     BUF_FETCH_CHAR(closure->buf,
						    closure->point -
						    abbrev_length + idx))
			    != DOWNCASE(closure->buf, charptr_emchar(ptr))) {
				break;
			}
			INC_CHARPTR(ptr);
		}
		if (idx == abbrev_length) {
			/* This is the one. */
			closure->found = sym;
			return 1;
		}
	}
	return 0;
}
Beispiel #2
0
/**
 ** Get the w_Package for a class, creating it if it does not already exist.
 */
w_package getPackageForClazz(w_clazz clazz, w_instance loader) {
  w_string class_name = clazz->dotified;
  w_instance effective_loader = loader ? loader : systemClassLoader;
  w_hashtable ht = loader2packages(effective_loader);
  w_string package_name;
  w_int i;
  w_int j;
  w_package p;

  for (i = 0; string_char(class_name, i) == '['; ++i); 
  for (j = string_length(class_name) - 1; string_char(class_name, j) != '.'; --j); 
  package_name = j > i ? w_substring(class_name, i, j - i) : registerString(string_empty);
  ht_lock(ht);
  p = (w_package)ht_read_no_lock(ht, (w_word)package_name);
  if (!p) {
    p = createPackage(package_name, effective_loader);
    ht_write_no_lock(ht, (w_word)package_name, (w_word)p);
  }
  clazz->package = p;
  ht_unlock(ht);
  deregisterString(package_name);

  return p;
}
Beispiel #3
0
int
string_column_at_point (Lisp_String* s, Bufpos init_pos, int tab_width)
{
  int col;
  int tab_seen;
  int post_tab;
  Bufpos pos = init_pos;
  Emchar c;

  if (tab_width <= 0 || tab_width > 1000) tab_width = 8;
  col = tab_seen = post_tab = 0;

  while (1)
    {
      if (pos <= 0)
	break;

      pos--;
      c = string_char (s, pos);
      if (c == '\t')
	{
	  if (tab_seen)
	    col = ((col + tab_width) / tab_width) * tab_width;

	  post_tab += col;
	  col = 0;
	  tab_seen = 1;
	}
      else if (c == '\n')
	break;
      else
#ifdef MULE
	  col += CHAR_COLUMNS (c);
#else
	  col ++;
#endif /* MULE */
    }

  if (tab_seen)
    {
      col = ((col + tab_width) / tab_width) * tab_width;
      col += post_tab;
    }

  return col;
}
Beispiel #4
0
/*
** Test whether the FQN of clazz matches match_pattern.
** 'match_pattern' may include a leading or trailing '*' as wildcard.
*/
w_boolean matchClassname(w_clazz clazz, w_string match_pattern) {
  w_int i;
  w_int j;
  w_int l;

  if (clazz->dotified == match_pattern) {
    woempa(7, "Direct match!\n");

    return TRUE;
  }

  l = string_length(match_pattern);
  if (string_char(match_pattern, 0) == '*') {
    for (i = 1, j = string_length(clazz->dotified) - l + 1; i < l; ++i, ++j) {
      if (string_char(clazz->dotified, j) != string_char(match_pattern, i)) {

        return FALSE;

      }
    }
    woempa(7, "Wildcard match %w = %w\n", clazz->dotified, match_pattern);

    return TRUE;
  }
  else if (string_char(match_pattern, l - 1) == '*') {
    --l;
    for (i = 0; i < l; ++i) {
      if (string_char(clazz->dotified, i) != string_char(match_pattern, i)) {

        return FALSE;

      }
    }
    woempa(7, "Wildcard match %w = %w\n", clazz->dotified, match_pattern);

    return TRUE;
  }

  return FALSE;
}