⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 buffer.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
}DEFUN ("rename-buffer", Frename_buffer, Srename_buffer, 1, 1,       "sRename buffer (to new name): ",  "Change current buffer's name to NEWNAME (a string).")  (name)     register Lisp_Object name;{  register Lisp_Object tem, buf;  CHECK_STRING (name, 0);  tem = Fget_buffer (name);  if (!NULL (tem))    error ("Buffer name \"%s\" is in use", XSTRING (name)->data);  current_buffer->name = name;  XSET (buf, Lisp_Buffer, current_buffer);  Fsetcar (Frassq (buf, Vbuffer_alist), name);  if (NULL (current_buffer->filename) && !NULL (current_buffer->auto_save_file_name))    call0 (intern ("rename-auto-save-file"));  return Qnil;}DEFUN ("other-buffer", Fother_buffer, Sother_buffer, 0, 1, 0,  "Return most recently selected buffer other than BUFFER.\n\Buffers not visible in windows are preferred to visible buffers.\n\If no other exists, the buffer *scratch* is returned.\n\If BUFFER is omitted or nil, some interesting buffer is returned.")  (buffer)     register Lisp_Object buffer;{  register Lisp_Object tail, buf, notsogood, tem;  notsogood = Qnil;  for (tail = Vbuffer_alist; !NULL (tail); tail = Fcdr (tail))    {      buf = Fcdr (Fcar (tail));      if (EQ (buf, buffer))	continue;      if (XSTRING (XBUFFER (buf)->name)->data[0] == ' ')	continue;      tem = Fget_buffer_window (buf);      if (NULL (tem))	return buf;      if (NULL (notsogood))	notsogood = buf;    }  if (!NULL (notsogood))    return notsogood;  return Fget_buffer_create (build_string ("*scratch*"));}DEFUN ("buffer-flush-undo", Fbuffer_flush_undo, Sbuffer_flush_undo, 1, 1, 0,  "Make BUFFER stop keeping undo information.")  (buf)     register Lisp_Object buf;{  CHECK_BUFFER (buf, 0);  XBUFFER (buf)->undo_list = Qt;  return Qnil;}DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,       0, 1, "",  "Start keeping undo information for buffer BUFFER (default is current buffer).")  (buf)     register Lisp_Object buf;{  if (NULL (buf))    {      if (EQ (current_buffer->undo_list, Qt))	current_buffer->undo_list = Qnil;    }  else    {      CHECK_BUFFER (buf, 0);      if (EQ (XBUFFER (buf)->undo_list, Qt))	XBUFFER (buf)->undo_list = Qnil;    }  return Qnil;}DEFUN ("kill-buffer", Fkill_buffer, Skill_buffer, 1, 1, "bKill buffer: ",  "One arg, a string or a buffer.  Get rid of the specified buffer.\n\Any processes that have this buffer as the `process-buffer' are killed\n\with `delete-process'.")  (bufname)     Lisp_Object bufname;{  Lisp_Object buf;  register struct buffer *b;  register Lisp_Object tem;  register struct Lisp_Marker *m;  struct gcpro gcpro1, gcpro2;  if (NULL (bufname))    buf = Fcurrent_buffer ();  else    buf = Fget_buffer (bufname);  if (NULL (buf))    nsberror (bufname);  b = XBUFFER (buf);  if (FROM_KBD && !NULL (b->filename)      && BUF_MODIFF (b) > b->save_modified)    {      GCPRO2 (buf, bufname);      tem = Fyes_or_no_p (format1 ("Buffer %s modified; kill anyway? ",				   XSTRING (b->name)->data));      UNGCPRO;      if (NULL (tem))	return Qnil;    }  /* We have no more questions to ask.  Verify that it is valid     to kill the buffer.  This must be done after the questions     since anything can happen within Fyes_or_no_p.  */  /* Don't kill the minibuffer now current.  */  if (EQ (buf, XWINDOW (minibuf_window)->buffer))    return Qnil;  if (NULL (b->name))    return Qnil;  /* Make this buffer not be current.     In the process, notice if this is the sole visible buffer     and give up if so.  */  if (b == current_buffer)    {      tem = Fother_buffer (buf);      Fset_buffer (tem);      if (b == current_buffer)	return Qnil;    }  /* Now there is no question: we can kill the buffer.  */#ifdef CLASH_DETECTION  /* Unlock this buffer's file, if it is locked.  */  unlock_buffer (b);#endif /* CLASH_DETECTION */#ifdef subprocesses  kill_buffer_processes (buf);#endif subprocesses  tem = Vinhibit_quit;  Vinhibit_quit = Qt;  Vbuffer_alist = Fdelq (Frassq (buf, Vbuffer_alist), Vbuffer_alist);  Freplace_buffer_in_windows (buf);  Vinhibit_quit = tem;  /* Unchain all markers of this buffer     and leave them pointing nowhere.  */  for (tem = b->markers; !EQ (tem, Qnil); )    {      m = XMARKER (tem);      m->buffer = 0;      tem = m->chain;      m->chain = Qnil;    }  b->markers = Qnil;  b->name = Qnil;  b->undo_list = Qnil;  free (BUF_BEG_ADDR (b));  return Qnil;}/* Put the element for buffer `buf' at the front of buffer-alist. This is done when a buffer is selected "visibly". It keeps buffer-alist in the order of recency of selection so that other_buffer will return something nice.  */record_buffer (buf)     Lisp_Object buf;{  register Lisp_Object link, prev;  prev = Qnil;  for (link = Vbuffer_alist; CONSP (link); link = XCONS (link)->cdr)    {      if (EQ (XCONS (XCONS (link)->car)->cdr, buf))	break;      prev = link;    }  /* Effectively do Vbuffer_alist = Fdelq (link, Vbuffer_alist)     but cannot use Fdelq here it that allows quitting.  */  if (NULL (prev))    Vbuffer_alist = XCONS (Vbuffer_alist)->cdr;  else    XCONS (prev)->cdr = XCONS (XCONS (prev)->cdr)->cdr;	  XCONS(link)->cdr = Vbuffer_alist;  Vbuffer_alist = link;}DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ",  "Select buffer BUFFER in the current window.\n\BUFFER may be a buffer or a buffer name.\n\Optional second arg NORECORD non-nil means\n\do not put this buffer at the front of the list of recently selected ones.\n\\n\WARNING: This is NOT the way to work on another buffer temporarily\n\within a Lisp program!  Use `set-buffer' instead.  That avoids messing with\n\the window-buffer correspondances.")  (bufname, norecord)     Lisp_Object bufname, norecord;{  register Lisp_Object buf;  if (EQ (minibuf_window, selected_window))    error ("Cannot switch buffers in minibuffer window");  if (NULL (bufname))    buf = Fother_buffer (Fcurrent_buffer ());  else    buf = Fget_buffer_create (bufname);  Fset_buffer (buf);  if (NULL (norecord))    record_buffer (buf);  Fset_window_buffer (EQ (selected_window, minibuf_window)		      ? Fnext_window (minibuf_window, Qnil) : selected_window,		      buf);  return Qnil;}DEFUN ("pop-to-buffer", Fpop_to_buffer, Spop_to_buffer, 1, 2, 0,  "Select buffer BUFFER in some window, preferably a different one.\n\If  pop-up-windows  is non-nil, windows can be split to do this.\n\If second arg  OTHER-WINDOW is non-nil, insist on finding another\n\window even if BUFFER is already visible in the selected window.")  (bufname, other)     Lisp_Object bufname, other;{  register Lisp_Object buf;  if (NULL (bufname))    buf = Fother_buffer (Fcurrent_buffer ());  else    buf = Fget_buffer_create (bufname);  Fset_buffer (buf);  record_buffer (buf);  Fselect_window (Fdisplay_buffer (buf, other));  return Qnil;}DEFUN ("current-buffer", Fcurrent_buffer, Scurrent_buffer, 0, 0, 0,  "Return the current buffer as a Lisp buffer object.")  (){  register Lisp_Object buf;  XSET (buf, Lisp_Buffer, current_buffer);  return buf;}DEFUN ("set-buffer", Fset_buffer, Sset_buffer, 1, 1, 0,  "Set the current buffer to the buffer or buffer name supplied as argument.\n\That buffer will then be the default for editing operations and printing.\n\This function's effect can't last past end of current command\n\because returning to command level\n\selects the chosen buffer of the current window,\n\and this function has no effect on what buffer that is.\n\See also `save-excursion' when you want to select a buffer temporarily.\n\Use `switch-to-buffer' or `pop-to-buffer' for interactive buffer selection.")  (bufname)     register Lisp_Object bufname;{  register Lisp_Object buffer;  buffer = Fget_buffer (bufname);  if (NULL (buffer))    nsberror (bufname);  if (NULL (XBUFFER (buffer)->name))    error ("Selecting deleted buffer");  set_buffer_internal (XBUFFER (buffer));  return buffer;}DEFUN ("barf-if-buffer-read-only", Fbarf_if_buffer_read_only,				   Sbarf_if_buffer_read_only, 0, 0, 0,  "Signal a  buffer-read-only  error if the current buffer is read-only.")  (){  while (!NULL (current_buffer->read_only))    Fsignal (Qbuffer_read_only, (Fcons (Fcurrent_buffer (), Qnil)));  return Qnil;}DEFUN ("bury-buffer", Fbury_buffer, Sbury_buffer, 0, 1, "",  "Put BUFFER at the end of the list of all buffers.\n\There it is the least likely candidate for other-buffer to return;\n\thus, the least likely buffer for \\[switch-to-buffer] to select by default.")  (buf)     register Lisp_Object buf;{  register Lisp_Object aelt, link;  if (NULL (buf))    {      XSET (buf, Lisp_Buffer, current_buffer);      Fswitch_to_buffer (Fother_buffer (buf), Qnil);    }  else    {      Lisp_Object buf1;      buf1 = Fget_buffer (buf);      if (NULL (buf1))	nsberror (buf);      buf = buf1;    }	    aelt = Frassq (buf, Vbuffer_alist);  link = Fmemq (aelt, Vbuffer_alist);  Vbuffer_alist = Fdelq (aelt, Vbuffer_alist);  XCONS (link)->cdr = Qnil;  Vbuffer_alist = nconc2 (Vbuffer_alist, link);  return Qnil;}extern int last_known_column_point;set_buffer_internal (b)     register struct buffer *b;{  register struct buffer *swb = 0;  register struct buffer *old_buf;  register Lisp_Object tail, valcontents;  enum Lisp_Type tem;  if (current_buffer == b)    return;#if 0  if (XWINDOW (selected_window) != 0)    swb = NULL (selected_window) ? 0 : XBUFFER (XWINDOW (selected_window)->buffer);#endif  windows_or_buffers_changed = 1;  /* Vcheck_symbol is set up to the symbol paragraph-start     in order to check for the bug that clobbers it.  *//* if (current_buffer && EQ (current_buffer->major_mode, Qlisp_mode)      && XFASTINT (Vcheck_symbol) != 0      && !NULL (Vcheck_symbol))    {      valcontents = XSYMBOL (Vcheck_symbol)->value;      if (XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value)	abort ();      if (current_buffer == XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)	  && (XTYPE (XCONS (valcontents)->car) != Lisp_String	      || XSTRING (XCONS (valcontents)->car)->size != 6))	abort ();    }*/#if 0  if (current_buffer == swb && !NULL (selected_window))    Fset_marker (XWINDOW (selected_window)->pointm, make_number (point),		 XWINDOW (selected_window)->buffer);#endif  old_buf = current_buffer;  current_buffer = b;#if 0  if (b == swb)    {      SET_PT (marker_position (XWINDOW (selected_window)->pointm));      if (point < BEGV)	point = BEGV;      if (point > ZV)	point = ZV;    }#endif  last_known_column_point = -1;   /* invalidate indentation cache */  /* Look down buffer's list of local Lisp variables     to find and update any that forward into C variables. */  for (tail = b->local_var_alist; !NULL (tail); tail = XCONS (tail)->cdr)    {      valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;      if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value	   || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value)	  && (tem = XTYPE (XCONS (valcontents)->car),	      (tem == Lisp_Boolfwd || tem == Lisp_Intfwd	       || tem == Lisp_Objfwd)))	/* Just reference the variable	     to cause it to become set for this buffer.  */	Fsymbol_value (XCONS (XCONS (tail)->car)->car);    }  /* Do the same with any others that were local to the previous buffer */  if (old_buf)    for (tail = old_buf->local_var_alist; !NULL (tail); tail = XCONS (tail)->cdr)      {	valcontents = XSYMBOL (XCONS (XCONS (tail)->car)->car)->value;	if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value	     || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value)	    && (tem = XTYPE (XCONS (valcontents)->car),		(tem == Lisp_Boolfwd || tem == Lisp_Intfwd		 || tem == Lisp_Objfwd)))	  /* Just reference the variable               to cause it to become set for this buffer.  */	  Fsymbol_value (XCONS (XCONS (tail)->car)->car);      }  /* Vcheck_symbol is set up to the symbol paragraph-start     in order to check for the bug that clobbers it.  *//*if (EQ (b->major_mode, Qlisp_mode)      && Vcheck_symbol      && !NULL (Vcheck_symbol))    {      valcontents = XSYMBOL (Vcheck_symbol)->value;      if (XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value)	abort ();      if (b == XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)	  && (XTYPE (XCONS (valcontents)->car) != Lisp_String	      || XSTRING (XCONS (valcontents)->car)->size != 6))	abort ();      Fsymbol_value (Vcheck_symbol);      valcontents = XSYMBOL (Vcheck_symbol)->value;      if (b != XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)	  || XTYPE (XCONS (valcontents)->car) != Lisp_String	  || XSTRING (XCONS (valcontents)->car)->size != 6)	abort ();    } */}DEFUN ("erase-buffer", Ferase_buffer, Serase_buffer, 0, 0, 0,  "Delete the entire contents of the current buffer.")  (){  Fwiden ();  del_range (BEG, Z);  current_buffer->last_window_start = 1;  /* Prevent warnings, or suspension of auto saving, that would happen     if future size is less than past size.  Use of erase-buffer     implies that the future text is not really related to the past text.  */  XFASTINT (current_buffer->save_length) = 0;  return Qnil;}validate_region (b, e)     register Lisp_Object *b, *e;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -