Beispiel #1
0
static bool
reread_doc_file (Lisp_Object file)
{
  if (NILP (file))
    Fsnarf_documentation (Vdoc_file_name);
  else
    Fload (file, Qt, Qt, Qt, Qnil);

  return 1;
}
Beispiel #2
0
/* Given a selection-name and desired type, this looks up our local copy of
   the selection value and converts it to the type. */
static Lisp_Object
get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
{
  Lisp_Object local_value = assq_no_quit (selection_symbol, Vselection_alist);

  if (!NILP (local_value))
    {
      Lisp_Object value_list = XCAR (XCDR (local_value));
      Lisp_Object value;

      /* First try to find an entry of the appropriate type */
      value = assq_no_quit (target_type, value_list);

      if (!NILP (value))
	return XCDR (value);
    }

  return Qnil;
}
Beispiel #3
0
static void
record_backtrace (log_t *log, EMACS_INT count)
{
  Lisp_Object backtrace;
  ptrdiff_t index;

  if (!INTEGERP (log->next_free))
    /* FIXME: transfer the evicted counts to a special entry rather
       than dropping them on the floor.  */
    evict_lower_half (log);
  index = XINT (log->next_free);

  /* Get a "working memory" vector.  */
  backtrace = HASH_KEY (log, index);
  get_backtrace (backtrace);

  { /* We basically do a `gethash+puthash' here, except that we have to be
       careful to avoid memory allocation since we're in a signal
       handler, and we optimize the code to try and avoid computing the
       hash+lookup twice.  See fns.c:Fputhash for reference.  */
    EMACS_UINT hash;
    ptrdiff_t j = hash_lookup (log, backtrace, &hash);
    if (j >= 0)
      {
	EMACS_INT old_val = XINT (HASH_VALUE (log, j));
	EMACS_INT new_val = saturated_add (old_val, count);
	set_hash_value_slot (log, j, make_number (new_val));
      }
    else
      { /* BEWARE!  hash_put in general can allocate memory.
	   But currently it only does that if log->next_free is nil.  */
	int j;
	eassert (!NILP (log->next_free));
	j = hash_put (log, backtrace, make_number (count), hash);
	/* Let's make sure we've put `backtrace' right where it
	   already was to start with.  */
	eassert (index == j);

	/* FIXME: If the hash-table is almost full, we should set
	   some global flag so that some Elisp code can offload its
	   data elsewhere, so as to avoid the eviction code.
	   There are 2 ways to do that, AFAICT:
	   - Set a flag checked in QUIT, such that QUIT can then call
	     Fprofiler_cpu_log and stash the full log for later use.
	   - Set a flag check in post-gc-hook, so that Elisp code can call
	     profiler-cpu-log.  That gives us more flexibility since that
	     Elisp code can then do all kinds of fun stuff like write
	     the log to disk.  Or turn it right away into a call tree.
	   Of course, using Elisp is generally preferable, but it may
	   take longer until we get a chance to run the Elisp code, so
	   there's more risk that the table will get full before we
	   get there.  */
      }
  }
}
Beispiel #4
0
/* This callback is called when the FD is available for read.  The inotify
   events are read from FD and converted into input_events.  */
static void
inotify_callback (int fd, void *_)
{
  int to_read;
  if (ioctl (fd, FIONREAD, &to_read) < 0)
    report_file_notify_error ("Error while retrieving file system events",
			      Qnil);
  USE_SAFE_ALLOCA;
  char *buffer = SAFE_ALLOCA (to_read);
  ssize_t n = read (fd, buffer, to_read);
  if (n < 0)
    report_file_notify_error ("Error while reading file system events", Qnil);

  struct input_event event;
  EVENT_INIT (event);
  event.kind = FILE_NOTIFY_EVENT;

  for (ssize_t i = 0; i < n; )
    {
      struct inotify_event *ev = (struct inotify_event *) &buffer[i];
      Lisp_Object descriptor = INTEGER_TO_CONS (ev->wd);
      Lisp_Object prevtail = find_descriptor (descriptor);

      if (! NILP (prevtail))
        {
	  Lisp_Object tail = CONSP (prevtail) ? XCDR (prevtail) : watch_list;
	  for (Lisp_Object watches = XCDR (XCAR (tail)); ! NILP (watches);
	       watches = XCDR (watches))
            {
              event.arg = inotifyevent_to_event (XCAR (watches), ev);
              if (!NILP (event.arg))
                kbd_buffer_store_event (&event);
            }
          /* If event was removed automatically: Drop it from watch list.  */
          if (ev->mask & IN_IGNORED)
	    remove_descriptor (prevtail, true);
        }
      i += sizeof (*ev) + ev->len;
    }

  SAFE_FREE ();
}
Beispiel #5
0
static int
gtk_get_button_size (struct frame *f, Lisp_Object window,
		     struct toolbar_button *tb, int vert, int pos)
{
  int shadow_thickness = 2;
  int size;

  if (tb->blank)
    {
      if (!NILP (tb->down_glyph))
	size = XINT (tb->down_glyph);
      else
	size = DEFAULT_TOOLBAR_BLANK_SIZE;
    }
  else
    {
      struct window *w = XWINDOW (window);
      Lisp_Object glyph = get_toolbar_button_glyph (w, tb);

      /* Unless, of course, the user has done something stupid like
         change the glyph out from under us.  Use a blank placeholder
         in that case. */
      if (NILP (glyph))
	return XINT (f->toolbar_size[pos]);

      if (vert)
	size = glyph_height (glyph, window);
      else
	size = glyph_width (glyph, window);
    }

  if (!size)
    {
      /* If the glyph doesn't have a size we'll insert a blank
         placeholder instead. */
      return XINT (f->toolbar_size[pos]);
    }

  size += shadow_thickness * 2;

  return (size);
}
Beispiel #6
0
static void
ensure_not_printing (struct device *d)
{
  if (!NILP (DEVICE_FRAME_LIST (d)))
  {
    Lisp_Object device = wrap_device (d);

    invalid_operation ("Cannot change settings while print job is active",
		       device);
  }
}
Beispiel #7
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 #8
0
Datei: menu.c Projekt: ueno/emacs
void
save_menu_items (void)
{
  Lisp_Object saved = list4 (!NILP (menu_items_inuse) ? menu_items : Qnil,
			     make_number (menu_items_used),
			     make_number (menu_items_n_panes),
			     make_number (menu_items_submenu_depth));
  record_unwind_protect (restore_menu_items, saved);
  menu_items_inuse = Qnil;
  menu_items = Qnil;
}
Beispiel #9
0
struct console *
decode_console (Lisp_Object console)
{
  if (NILP (console))
    console = Fselected_console ();
  /* quietly accept devices and frames for the console arg */
  if (DEVICEP (console) || FRAMEP (console))
    console = DEVICE_CONSOLE (decode_device (console));
  CHECK_LIVE_CONSOLE (console);
  return XCONSOLE (console);
}
Beispiel #10
0
Datei: menu.c Projekt: ueno/emacs
void
discard_menu_items (void)
{
  /* Free the structure if it is especially large.
     Otherwise, hold on to it, to save time.  */
  if (menu_items_allocated > 200)
    {
      menu_items = Qnil;
      menu_items_allocated = 0;
    }
  eassert (NILP (menu_items_inuse));
}
Beispiel #11
0
static Lisp_Object
gtk_device_to_console_connection (Lisp_Object connection, Error_behavior errb)
{
  /* Strip the trailing .# off of the connection, if it's there. */

  if (NILP (connection))
    return Qnil;
  else
    {
	connection = build_string ("gtk");
    }
  return connection;
}
Beispiel #12
0
int find_env(int exp_id) {
  int level = call_depth;
  int found = L_NIL;

  while (level >= 0) {
    found = env[(level << 8) + expression[exp_id]];
    if (!NILP(found)){
      return found;
    }
    level -= 1;
  }
  return L_NIL;
}
Beispiel #13
0
T lookup(T name, Environment env) {
	assert(name->type == T_SYM);

	for (; !NILP(env); env=CDR(env)) {
		T binding;
		binding = CAR(env);
		if (CAR(binding) == name) {
			return CDR(binding);
		}
	}

	return NIL;
}
Beispiel #14
0
static int
get_logical_cursor_bitmap (struct window *w, Lisp_Object cursor)
{
  Lisp_Object cmap, bm = Qnil;

  if ((cmap = BVAR (XBUFFER (w->buffer), fringe_cursor_alist)), !NILP (cmap))
    {
      bm = Fassq (cursor, cmap);
      if (CONSP (bm))
	{
	  if ((bm = XCDR (bm)), NILP (bm))
	    return NO_FRINGE_BITMAP;
	  return lookup_fringe_bitmap (bm);
	}
    }
  if (EQ (cmap, BVAR (&buffer_defaults, fringe_cursor_alist)))
    return NO_FRINGE_BITMAP;
  bm = Fassq (cursor, BVAR (&buffer_defaults, fringe_cursor_alist));
  if (!CONSP (bm) || ((bm = XCDR (bm)), NILP (bm)))
    return NO_FRINGE_BITMAP;
  return lookup_fringe_bitmap (bm);
}
Beispiel #15
0
Datei: menu.c Projekt: ueno/emacs
static void
restore_menu_items (Lisp_Object saved)
{
  menu_items = XCAR (saved);
  menu_items_inuse = (! NILP (menu_items) ? Qt : Qnil);
  menu_items_allocated = (VECTORP (menu_items) ? ASIZE (menu_items) : 0);
  saved = XCDR (saved);
  menu_items_used = XINT (XCAR (saved));
  saved = XCDR (saved);
  menu_items_n_panes = XINT (XCAR (saved));
  saved = XCDR (saved);
  menu_items_submenu_depth = XINT (XCAR (saved));
}
Beispiel #16
0
static void
record_point (ptrdiff_t pt)
{
  bool at_boundary;

  /* Don't record position of pt when undo_inhibit_record_point holds.  */
  if (undo_inhibit_record_point)
    return;

  /* Allocate a cons cell to be the undo boundary after this command.  */
  if (NILP (pending_boundary))
    pending_boundary = Fcons (Qnil, Qnil);

  if ((current_buffer != last_undo_buffer)
      /* Don't call Fundo_boundary for the first change.  Otherwise we
	 risk overwriting last_boundary_position in Fundo_boundary with
	 PT of the current buffer and as a consequence not insert an
	 undo boundary because last_boundary_position will equal pt in
	 the test at the end of the present function (Bug#731).  */
      && (MODIFF > SAVE_MODIFF))
    Fundo_boundary ();
  last_undo_buffer = current_buffer;

  at_boundary = ! CONSP (BVAR (current_buffer, undo_list))
                || NILP (XCAR (BVAR (current_buffer, undo_list)));

  if (MODIFF <= SAVE_MODIFF)
    record_first_change ();

  /* If we are just after an undo boundary, and
     point wasn't at start of deleted range, record where it was.  */
  if (at_boundary
      && current_buffer == last_boundary_buffer
      && last_boundary_position != pt)
    bset_undo_list (current_buffer,
		    Fcons (make_number (last_boundary_position),
			   BVAR (current_buffer, undo_list)));
}
Beispiel #17
0
static int
reread_doc_file (Lisp_Object file)
{
#if 0
  Lisp_Object reply, prompt[3];
  struct gcpro gcpro1;
  GCPRO1 (file);
  prompt[0] = build_string ("File ");
  prompt[1] = NILP (file) ? Vdoc_file_name : file;
  prompt[2] = build_string (" is out of sync.  Reload? ");
  reply = Fy_or_n_p (Fconcat (3, prompt));
  UNGCPRO;
  if (NILP (reply))
    return 0;
#endif

  if (NILP (file))
    Fsnarf_documentation (Vdoc_file_name);
  else
    Fload (file, Qt, Qt, Qt, Qnil);

  return 1;
}
Beispiel #18
0
void gcpro_popup_callbacks(LWLIB_ID id)
{
	struct popup_data *pdata;
	Lisp_Object lid = make_int(id);
	Lisp_Object lpdata;

	assert(NILP(assq_no_quit(lid, Vpopup_callbacks)));
	pdata = alloc_lcrecord_type(struct popup_data, &lrecord_popup_data);
	pdata->id = id;
	pdata->last_menubar_buffer = Qnil;
	pdata->menubar_contents_up_to_date = 0;
	XSETPOPUP_DATA(lpdata, pdata);
	Vpopup_callbacks = Fcons(Fcons(lid, lpdata), Vpopup_callbacks);
}
Beispiel #19
0
static ad_device_data *
sound_oss_create(Lisp_Object oss_options)
{
	/* result */
	sound_oss_data_t *sod = NULL;
	int keep_open = 0;
	/* option keywords */
	Lisp_Object opt_device;
	Lisp_Object opt_keepopen;

	/* parse options */
	opt_device = Fplist_get(oss_options, Q_device, Qnil);
	if (!NILP(opt_device) && !STRINGP(opt_device)) {
		wrong_type_argument(Qstringp, opt_device);
		return NULL;
	}

	opt_keepopen = Fplist_get(oss_options, Q_keep_open, Qnil);
	if (!NILP(opt_keepopen))
		keep_open = 1;

	/* initialise and fill */
	sod = xnew_and_zero(sound_oss_data_t);
	sod->device = opt_device;
	sod->keep_open = keep_open;
	sod->device_fd = -1;
	SXE_MUTEX_INIT(&sod->mtx);

	/* Open the device */


	if (!keep_open) {
		sod->device_fd = -1;
	}

	return (ad_device_data*)sod;
}
Beispiel #20
0
Lisp_Object
menu_parse_submenu_keywords (Lisp_Object desc, Lisp_Object gui_item)
{
  Lisp_Gui_Item *pgui_item = XGUI_ITEM (gui_item);

  /* Menu descriptor should be a list */
  CHECK_CONS (desc);

  /* First element may be menu name, although can be omitted.
     Let's think that if stuff begins with anything than a keyword
     or a list (submenu), this is a menu name, expected to be a string */
  if (!KEYWORDP (XCAR (desc)) && !CONSP (XCAR (desc)))
    {
      CHECK_STRING (XCAR (desc));
      pgui_item->name = XCAR (desc);
      desc = XCDR (desc);
      if (!NILP (desc))
	CHECK_CONS (desc);
    }

  /* Walk along all key-value pairs */
  while (!NILP(desc) && KEYWORDP (XCAR (desc)))
    {
      Lisp_Object key, val;
      key = XCAR (desc);
      desc = XCDR (desc);
      CHECK_CONS (desc);
      val = XCAR (desc);
      desc = XCDR (desc);
      if (!NILP (desc))
	CHECK_CONS (desc);
      gui_item_add_keyval_pair (gui_item, key, val, ERROR_ME);
    }

  /* Return the rest - supposed to be a list of items */
  return desc;
}
Beispiel #21
0
/* Invalidate the cache positions after POS, if the string to be
   inserted contains a newline.  If the string is too large (larger
   than LINE_NUMBER_LARGE_STRING), invalidate the cache positions
   after POS without prior search.

   This will do nothing if the cache is uninitialized.  */
void
insert_invalidate_line_number_cache (struct buffer *b, Charbpos pos,
				     const Ibyte *nonreloc, Bytecount length)
{
  if (NILP (b->text->line_number_cache))
    return;

  if (length > LINE_NUMBER_LARGE_STRING
      ||
      /* We could also count how many newlines there are in the string
         and update the cache accordingly, but it would be too much
         work for too little gain. */
      memchr ((void *)nonreloc, '\n', length))
    invalidate_line_number_cache (b, pos);
}
Beispiel #22
0
/* Generate a file notification event.  */
static void
kqueue_generate_event
(Lisp_Object watch_object, Lisp_Object actions,
 Lisp_Object file, Lisp_Object file1)
{
  Lisp_Object flags, action, entry;
  struct input_event event;

  /* Check, whether all actions shall be monitored.  */
  flags = Fnth (make_number (2), watch_object);
  action = actions;
  do {
    if (NILP (action))
      break;
    entry = XCAR (action);
    if (NILP (Fmember (entry, flags))) {
      action = XCDR (action);
      actions = Fdelq (entry, actions);
    } else
      action = XCDR (action);
  } while (1);

  /* Store it into the input event queue.  */
  if (! NILP (actions)) {
    EVENT_INIT (event);
    event.kind = FILE_NOTIFY_EVENT;
    event.frame_or_window = Qnil;
    event.arg = list2 (Fcons (XCAR (watch_object),
			      Fcons (actions,
				     NILP (file1)
				     ? Fcons (file, Qnil)
				     : list2 (file, file1))),
		       Fnth (make_number (3), watch_object));
    kbd_buffer_store_event (&event);
  }
}
Beispiel #23
0
/* Add a new watch to watch-descriptor WD watching FILENAME and using
   CALLBACK.  Returns a cons (DESCRIPTOR . ID) uniquely identifying the
   new watch.  */
static Lisp_Object
add_watch (int wd, Lisp_Object filename,
	   Lisp_Object aspect, Lisp_Object callback)
{
  Lisp_Object descriptor = INTEGER_TO_CONS (wd);
  Lisp_Object tail = assoc_no_quit (descriptor, watch_list);
  Lisp_Object watch, watch_id;
  uint32_t imask = aspect_to_inotifymask (aspect);
  Lisp_Object mask = INTEGER_TO_CONS (imask);

  EMACS_INT id = 0;
  if (NILP (tail))
    {
      tail = list1 (descriptor);
      watch_list = Fcons (tail, watch_list);
    }
  else
    {
      /* Assign a watch ID that is not already in use, by looking
	 for a gap in the existing sorted list.  */
      for (; ! NILP (XCDR (tail)); tail = XCDR (tail), id++)
	if (!EQ (XCAR (XCAR (XCDR (tail))), make_number (id)))
	  break;
      if (MOST_POSITIVE_FIXNUM < id)
	emacs_abort ();
    }

  /* Insert the newly-assigned ID into the previously-discovered gap,
     which is possibly at the end of the list.  Inserting it there
     keeps the list sorted.  */
  watch_id = make_number (id);
  watch = list4 (watch_id, filename, callback, mask);
  XSETCDR (tail, Fcons (watch, XCDR (tail)));

  return Fcons (descriptor, watch_id);
}
Beispiel #24
0
static uint32_t
aspect_to_inotifymask (Lisp_Object aspect)
{
  if (CONSP (aspect) || NILP (aspect))
    {
      Lisp_Object x = aspect;
      uint32_t mask = 0;
      FOR_EACH_TAIL (x)
	mask |= symbol_to_inotifymask (XCAR (x));
      CHECK_LIST_END (x, aspect);
      return mask;
    }
  else
    return symbol_to_inotifymask (aspect);
}
Beispiel #25
0
static int binding_for_player( int player )
{
    char tmp[40];
    sprintf( tmp, "player%d", player );
    LSymbol *f = LSymbol::Find(tmp);
    if( !NILP(f) && DEFINEDP(f->GetValue()))
    {
        void *what = f->GetValue();
        if(what == LSymbol::FindOrCreate("keyboard"))
            return 1;
        else if(what == LSymbol::FindOrCreate("joystick"))
            return 2;
    }
    return 0;
}
Beispiel #26
0
Datei: menu.c Projekt: ueno/emacs
/* Set up data in menu_items for a menu bar item
   whose event type is ITEM_KEY (with string ITEM_NAME)
   and whose contents come from the list of keymaps MAPS.  */
bool
parse_single_submenu (Lisp_Object item_key, Lisp_Object item_name,
		      Lisp_Object maps)
{
  Lisp_Object length;
  EMACS_INT len;
  Lisp_Object *mapvec;
  ptrdiff_t i;
  bool top_level_items = 0;
  USE_SAFE_ALLOCA;

  length = Flength (maps);
  len = XINT (length);

  /* Convert the list MAPS into a vector MAPVEC.  */
  SAFE_ALLOCA_LISP (mapvec, len);
  for (i = 0; i < len; i++)
    {
      mapvec[i] = Fcar (maps);
      maps = Fcdr (maps);
    }

  /* Loop over the given keymaps, making a pane for each map.
     But don't make a pane that is empty--ignore that map instead.  */
  for (i = 0; i < len; i++)
    {
      if (!KEYMAPP (mapvec[i]))
	{
	  /* Here we have a command at top level in the menu bar
	     as opposed to a submenu.  */
	  top_level_items = 1;
	  push_menu_pane (Qnil, Qnil);
	  push_menu_item (item_name, Qt, item_key, mapvec[i],
			  Qnil, Qnil, Qnil, Qnil);
	}
      else
	{
	  Lisp_Object prompt;
	  prompt = Fkeymap_prompt (mapvec[i]);
	  single_keymap_panes (mapvec[i],
			       !NILP (prompt) ? prompt : item_name,
			       item_key, 10);
	}
    }

  SAFE_FREE ();
  return top_level_items;
}
Beispiel #27
0
/* Calculate the line number in buffer B at position POS.  If CACHEP
   is non-zero, initialize and facilitate the line-number cache.  The
   line number of the first line is 0.  If narrowing is in effect,
   count the lines are counted from the beginning of the visible
   portion of the buffer.

   The cache works as follows: To calculate the line number, we need
   two positions: position of point (POS) and the position from which
   to count newlines (BEG).  We start by setting BEG to BUF_BEGV.  If
   this would require too much searching (i.e. pos - BUF_BEGV >
   LINE_NUMBER_FAR), try to find a closer position in the ring.  If it
   is found, use that position for BEG, and increment the line number
   appropriately.

   If the calculation (with or without the cache lookup) required more
   than LINE_NUMBER_FAR characters of traversal, update the cache.  */
EMACS_INT
buffer_line_number (struct buffer *b, Charbpos pos, Boolint cachep,
                    Boolint respect_narrowing)
{
  Charbpos beg = respect_narrowing ? BUF_BEGV (b) : BUF_BEG (b);
  EMACS_INT cached_lines = 0;
  EMACS_INT shortage, line;

  if ((pos > beg ? pos - beg : beg - pos) <= LINE_NUMBER_FAR)
    cachep = 0;

  if (cachep && (respect_narrowing || BUF_BEG (b) == BUF_BEGV (b)))
    {
      if (NILP (b->text->line_number_cache))
	allocate_line_number_cache (b);
      /* If we don't know the line number of BUF_BEGV, calculate it now.  */
      if (XFIXNUM (LINE_NUMBER_BEGV (b)) == -1)
	{
	  LINE_NUMBER_BEGV (b) = Qzero;
	  /* #### This has a side-effect of changing the cache.  */
	  LINE_NUMBER_BEGV (b) =
	    make_fixnum (buffer_line_number (b, BUF_BEGV (b), 1, 0));
	}
      cached_lines = XFIXNUM (LINE_NUMBER_BEGV (b));
      get_nearest_line_number (b, &beg, pos, &cached_lines);
    }

  scan_buffer (b, '\n', beg, pos,
               pos > beg ? MOST_POSITIVE_FIXNUM : -MOST_POSITIVE_FIXNUM,
	       &shortage, 0);

  line = MOST_POSITIVE_FIXNUM - shortage;
  if (beg > pos)
    line = -line;
  line += cached_lines;

  if (cachep && (respect_narrowing || BUF_BEG (b) == BUF_BEGV (b)))
    {
      /* If too far, update the cache. */
      if ((pos > beg ? pos - beg : beg - pos) > LINE_NUMBER_FAR)
	add_position_to_cache (b, pos, line);
      /* Account for narrowing.  If cache is not used, this is
	 unnecessary, because we counted from BUF_BEGV anyway.  */
      line -= XFIXNUM (LINE_NUMBER_BEGV (b));
    }

  return line;
}
Beispiel #28
0
void
draw_fringe_bitmap (struct window *w, struct glyph_row *row, int left_p)
{
  int overlay = 0;

  if (left_p == row->reversed_p && row->cursor_in_fringe_p)
    {
      Lisp_Object cursor = Qnil;

      switch (w->phys_cursor_type)
	{
	case HOLLOW_BOX_CURSOR:
	  if (row->visible_height >= STANDARD_BITMAP_HEIGHT (hollow_rectangle_bits))
	    cursor = Qhollow;
	  else
	    cursor = Qhollow_small;
	  break;
	case FILLED_BOX_CURSOR:
	  cursor = Qbox;
	  break;
	case BAR_CURSOR:
	  cursor = Qbar;
	  break;
	case HBAR_CURSOR:
	  cursor = Qhbar;
	  break;
	case NO_CURSOR:
	default:
	  w->phys_cursor_on_p = 0;
	  row->cursor_in_fringe_p = 0;
	  break;
	}
      if (!NILP (cursor))
	{
	  int bm = get_logical_cursor_bitmap (w, cursor);
	  if (bm != NO_FRINGE_BITMAP)
	    {
	      draw_fringe_bitmap_1 (w, row, left_p, 2, bm);
	      overlay = EQ (cursor, Qbox) ? 3 : 1;
	    }
	}
    }

  draw_fringe_bitmap_1 (w, row, left_p, overlay, NO_FRINGE_BITMAP);

  if (left_p && row->overlay_arrow_bitmap != NO_FRINGE_BITMAP)
    draw_fringe_bitmap_1 (w, row, 1, 1, row->overlay_arrow_bitmap);
}
Beispiel #29
0
/* Invalidate the cache positions after FROM, if the region to be
   deleted contains a newline.  If the region-to-be-deleted is larger
   than LINE_NUMBER_LARGE_STRING, invalidate the cache positions after
   FROM without unconditionally.

   This will do nothing if the cache is uninitialized.  */
void
delete_invalidate_line_number_cache (struct buffer *b, Charbpos from, Charbpos to)
{
  if (NILP (b->text->line_number_cache))
    return;

  if ((to - from) > LINE_NUMBER_LARGE_STRING)
    invalidate_line_number_cache (b, from);
  else
    {
      EMACS_INT shortage;
      scan_buffer (b, '\n', from, to, 1, &shortage, 0);
      if (!shortage)
	invalidate_line_number_cache (b, from);
    }
}
Beispiel #30
0
/* Flag LINE_NUMBER_BEGV (b) as dirty.  Do it only if the line number
   cache is already initialized.  */
void
narrow_line_number_cache (struct buffer *b)
{
  if (NILP (b->text->line_number_cache))
    return;

  if (BUF_BEG (b) == BUF_BEGV (b))
    /* The is the case Fwiden and save_restriction_restore.  Since we
       know the correct value, we can update it now.  */
    LINE_NUMBER_BEGV (b) = Qzero;
  else
    /* Calculating the line number of BUF_BEGV here is a bad idea,
       because there is absolutely no reason to do it before the next
       redisplay.  We simply mark it as dirty instead.  */
    LINE_NUMBER_BEGV (b) = make_fixnum (-1);
}