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

📄 editfns.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
     int nargs;     register Lisp_Object *args;{  register int argnum;  register Lisp_Object tem;  char str[1];  for (argnum = 0; argnum < nargs; argnum++)    {      tem = args[argnum];    retry:      if (XTYPE (tem) == Lisp_Int)	{	  str[0] = XINT (tem);	  insert_before_markers (str, 1);	}      else if (XTYPE (tem) == Lisp_String)	{	  insert_before_markers (XSTRING (tem)->data, XSTRING (tem)->size);	}      else	{	  tem = wrong_type_argument (Qchar_or_string_p, tem);	  goto retry;	}    }  return Qnil;}DEFUN ("insert-char", Finsert_char, Sinsert_char, 2, 2, 0,  "Insert COUNT (second arg) copies of CHAR (first arg).\n\Both arguments are required.")  (chr, count)       Lisp_Object chr, count;{  register unsigned char *string;  register int strlen;  register int i, n;  CHECK_NUMBER (chr, 0);  CHECK_NUMBER (count, 1);  n = XINT (count);  if (n <= 0)    return Qnil;  strlen = max (n, 256);  string = (unsigned char *) alloca (strlen);  for (i = 0; i < strlen; i++)    string[i] = XFASTINT (chr);  while (n >= strlen)    {      insert (string, strlen);      n -= strlen;    }  if (n > 0)    insert (string, n);  return Qnil;}/* Return a string with the contents of the current region */DEFUN ("buffer-substring", Fbuffer_substring, Sbuffer_substring, 2, 2, 0,  "Return the contents of part of the current buffer as a string.\n\The two arguments specify the start and end, as character numbers.")  (b, e)     Lisp_Object b, e;{  register int beg, end;  validate_region (&b, &e);  beg = XINT (b);  end = XINT (e);  if (beg < GPT && end > GPT)    move_gap (beg);  return make_string (&FETCH_CHAR (beg), end - beg);}DEFUN ("buffer-string", Fbuffer_string, Sbuffer_string, 0, 0, 0,  "Return the contents of the current buffer as a string.")  (){  if (BEGV < GPT && ZV > GPT)    move_gap (BEGV);  return make_string (BEGV_ADDR, ZV - BEGV);}DEFUN ("insert-buffer-substring", Finsert_buffer_substring, Sinsert_buffer_substring,  1, 3, 0,  "Insert before point a substring of the contents buffer BUFFER.\n\BUFFER may be a buffer or a buffer name.\n\Arguments START and END are character numbers specifying the substring.\n\They default to the beginning and the end of BUFFER.")  (buf, b, e)     Lisp_Object buf, b, e;{  register int beg, end, exch;  register struct buffer *bp;  buf = Fget_buffer (buf);  bp = XBUFFER (buf);  if (NULL (b))    beg = BUF_BEGV (bp);  else    {      CHECK_NUMBER_COERCE_MARKER (b, 0);      beg = XINT (b);    }  if (NULL (e))    end = BUF_ZV (bp);  else    {      CHECK_NUMBER_COERCE_MARKER (e, 1);      end = XINT (e);    }  if (beg > end)    exch = beg, beg = end, end = exch;  /* Move the gap or create enough gap in the current buffer.  */  if (point != GPT)    move_gap (point);  if (GAP_SIZE < end - beg)    make_gap (end - beg - GAP_SIZE);  if (!(BUF_BEGV (bp) <= beg	&& beg <= end        && end <= BUF_ZV (bp)))    args_out_of_range (b, e);  /* Now the actual insertion will not do any gap motion,     so it matters not if BUF is the current buffer.  */  if (beg < BUF_GPT (bp))    {      insert (BUF_CHAR_ADDRESS (bp, beg), min (end, BUF_GPT (bp)) - beg);      beg = min (end, BUF_GPT (bp));    }  if (beg < end)    insert (BUF_CHAR_ADDRESS (bp, beg), end - beg);  return Qnil;}DEFUN ("subst-char-in-region", Fsubst_char_in_region,  Ssubst_char_in_region, 4, 5, 0,  "From START to END, replace FROMCHAR with TOCHAR each time it occurs.\n\If optional arg NOUNDO is non-nil, don't record this change for undo\n\and don't mark the buffer as really changed.")  (start, end, fromchar, tochar, noundo)     Lisp_Object start, end, fromchar, tochar, noundo;{  register int pos, stop, look;  validate_region (&start, &end);  CHECK_NUMBER (fromchar, 2);  CHECK_NUMBER (tochar, 3);  pos = XINT (start);  stop = XINT (end);  look = XINT (fromchar);  modify_region (pos, stop);  if (! NULL (noundo))    {      if (MODIFF - 1 == current_buffer->save_modified)	current_buffer->save_modified++;      if (MODIFF - 1 == current_buffer->auto_save_modified)	current_buffer->auto_save_modified++;    }  while (pos < stop)    {      if (FETCH_CHAR (pos) == look)	{	  if (NULL (noundo))	    record_change (pos, 1);	  FETCH_CHAR (pos) = XINT (tochar);	}      pos++;    }  return Qnil;}DEFUN ("delete-region", Fdelete_region, Sdelete_region, 2, 2, "r",  "Delete the text between point and mark.\n\When called from a program, expects two arguments,\n\character numbers specifying the stretch to be deleted.")  (b, e)     Lisp_Object b, e;{  validate_region (&b, &e);  del_range (XINT (b), XINT (e));  return Qnil;}DEFUN ("widen", Fwiden, Swiden, 0, 0, "",  "Remove restrictions from current buffer, allowing full text to be seen and edited.")  (){  BEGV = BEG;  SET_BUF_ZV (current_buffer, Z);  clip_changed = 1;  return Qnil;}DEFUN ("narrow-to-region", Fnarrow_to_region, Snarrow_to_region, 2, 2, "r",  "Restrict editing in this buffer to the current region.\n\The rest of the text becomes temporarily invisible and untouchable\n\but is not deleted; if you save the buffer in a file, the invisible\n\text is included in the file.  \\[widen] makes all visible again.\n\\n\When calling from a program, pass two arguments; character numbers\n\bounding the text that should remain visible.")  (b, e)     register Lisp_Object b, e;{  register int i;  CHECK_NUMBER_COERCE_MARKER (b, 0);  CHECK_NUMBER_COERCE_MARKER (e, 1);  if (XINT (b) > XINT (e))    {      i = XFASTINT (b);      b = e;      XFASTINT (e) = i;    }  if (!(BEG <= XINT (b) && XINT (b) <= XINT (e) && XINT (e) <= Z))    args_out_of_range (b, e);  BEGV = XFASTINT (b);  SET_BUF_ZV (current_buffer, XFASTINT (e));  if (point < XFASTINT (b))    SET_PT (XFASTINT (b));  if (point > XFASTINT (e))    SET_PT (XFASTINT (e));  clip_changed = 1;  return Qnil;}Lisp_Objectsave_restriction_save (){  register Lisp_Object bottom, top;  /* Note: I tried using markers here, but it does not win     because insertion at the end of the saved region     does not advance top and is considered "outside" the saved region. */  XFASTINT (bottom) = BEGV - BEG;  XFASTINT (top) = Z - ZV;  return Fcons (Fcurrent_buffer (), Fcons (bottom, top));}Lisp_Objectsave_restriction_restore (data)     Lisp_Object data;{  register struct buffer *buf;  register int newhead, newtail;  register Lisp_Object tem;  buf = XBUFFER (XCONS (data)->car);  data = XCONS (data)->cdr;  tem = XCONS (data)->car;  newhead = XINT (tem);  tem = XCONS (data)->cdr;  newtail = XINT (tem);  if (newhead + newtail > BUF_Z (buf) - BUF_BEG (buf))    {      newhead = 0;      newtail = 0;    }  BUF_BEGV (buf) = BUF_BEG (buf) + newhead;  SET_BUF_ZV (buf, BUF_Z (buf) - newtail);  clip_changed = 1;  /* If point is outside the new visible range, move it inside. */  SET_BUF_PT (buf, in_accessible_range (BUF_PT (buf)));  return Qnil;}DEFUN ("save-restriction", Fsave_restriction, Ssave_restriction, 0, UNEVALLED, 0,  "Execute the body, undoing at the end any changes to current buffer's restrictions.\n\Changes to restrictions are made by narrow-to-region or by widen.\n\Thus, the restrictions are the same after this function as they were before it.\n\The value returned is that returned by the last form in the body.\n\\n\This function can be confused if, within the body, you widen\n\and then make changes outside the area within the saved restrictions.\n\\n\Note: if you are using both save-excursion and save-restriction,\n\use save-excursion outermost.")  (body)     Lisp_Object body;{  register Lisp_Object val;  int count = specpdl_ptr - specpdl;  record_unwind_protect (save_restriction_restore, save_restriction_save ());  val = Fprogn (body);  unbind_to (count);  return val;}DEFUN ("message", Fmessage, Smessage, 1, MANY, 0,  "Print a one-line message at the bottom of the screen.\n\The first argument is a control string.\n\It may contain %s or %d or %c to print successive following arguments.\n\%s means print an argument as a string, %d means print as number in decimal,\n\%c means print a number as a single character.\n\The argument used by %s must be a string or a symbol;\n\the argument used by %d or %c must be a number.")  (nargs, args)     int nargs;     Lisp_Object *args;{  register Lisp_Object val;  val = Fformat (nargs, args);  message ("%s", XSTRING (val)->data);  return val;}DEFUN ("format", Fformat, Sformat, 1, MANY, 0,  "Format a string out of a control-string and arguments.\n\The first argument is a control string.\n\It, and subsequent arguments substituted into it, become the value, which is a string.\n\It may contain %s or %d or %c to substitute successive following arguments.\n\%s means print an argument as a string, %d means print as number in decimal,\n\%c means print a number as a single character.\n\The argument used by %s must be a string or a symbol;\n\the argument used by %d, %b, %o, %x or %c must be a number.")  (nargs, args)     int nargs;     register Lisp_Object *args;{  register int n;  register int total = 5;  char *buf;  register unsigned char *format;  register unsigned char **strings;  extern char *index ();  /* It should not be necessary to GCPRO ARGS, because     the caller in the interpreter should take care of that.  */  CHECK_STRING (args[0], 0);  format = XSTRING (args[0])->data;  /* We have to do so much work in order to prepare to call doprnt     that we might as well do all of it ourself...  (Which would also     circumvent C asciz cretinism by allowing ascii 000 chars to appear)   */  n = 0;  while (format = (unsigned char *) index (format, '%'))    {      format++;      while ((*format >= '0' && *format <= '9')	     || *format == '-' || *format == ' ')	format++;      if (*format == '%')	format++;      else if (++n >= nargs)	;      else if (XTYPE (args[n]) == Lisp_Symbol)	{	  XSET (args[n], Lisp_String, XSYMBOL (args[n])->name);	  goto string;	}      else if (XTYPE (args[n]) == Lisp_String)	{	string:	  total += XSTRING (args[n])->size;	}      /* would get MPV otherwise, since Lisp_Int's `point' to low memory */      else if (XTYPE (args[n]) == Lisp_Int && *format != 's')	total += 10;      else	{	  register Lisp_Object tem;	  tem = Fprin1_to_string (args[n]);	  args[n] = tem;	  goto string;	}    }  strings = (unsigned char **) alloca ((n + 1) * sizeof (unsigned char *));  for (; n >= 0; n--)    {      if (n >= nargs)	strings[n] = (unsigned char *) "";      else if (XTYPE (args[n]) == Lisp_Int)	/* We checked above that the correspondiong format effector	   isn't %s, which would cause MPV */	strings[n] = (unsigned char *) XINT (args[n]);      else	strings[n] = XSTRING (args[n])->data;    }  /* Format it in bigger and bigger buf's until it all fits. */  while (1)    {      buf = (char *) alloca (total + 1);      buf[total - 1] = 0;      doprnt (buf, total + 1, strings[0], nargs, strings + 1);      if (buf[total - 1] == 0)	break;      total *= 2;    }/*   UNGCPRO;  */  return build_string (buf);}/* VARARGS 1 */Lisp_Object#ifdef NO_ARG_ARRAYformat1 (string1, arg0, arg1, arg2, arg3, arg4)     int arg0, arg1, arg2, arg3, arg4;#elseformat1 (string1)#endif     char *string1;{  char buf[100];#ifdef NO_ARG_ARRAY  int args[5];  args[0] = arg0;  args[1] = arg1;  args[2] = arg2;  args[3] = arg3;  args[4] = arg4;  doprnt (buf, sizeof buf, string1, 5, args);#else  doprnt (buf, sizeof buf, string1, 5, &string1 + 1);#endif  return build_string (buf);}DEFUN ("char-equal", Fchar_equal, Schar_equal, 2, 2, 0,  "T if args (both characters (numbers)) match.  May ignore case.\n\Case is ignored if the current buffer specifies to do so.")  (c1, c2)     register Lisp_Object c1, c2;{  CHECK_NUMBER (c1, 0);  CHECK_NUMBER (c2, 1);  if (!NULL (current_buffer->case_fold_search)      ? downcase_table[0xff & XFASTINT (c1)] == downcase_table[0xff & XFASTINT (c2)]      : XINT (c1) == XINT (c2))    return Qt;  return Qnil;}#ifndef MAINTAIN_ENVIRONMENT /* it is done in environ.c in that case */DEFUN ("getenv", Fgetenv, Sgetenv, 1, 2, 0,  "One arg VAR, a string.  Return the value of environment variable VAR, as a string.")  (str)     Lisp_Object str;{  register char *val;  CHECK_STRING (str, 0);  val = (char *) egetenv (XSTRING (str)->data);  if (!val)    return Qnil;  return build_string (val);}#endif MAINTAIN_ENVIRONMENTvoidsyms_of_editfns (){  staticpro (&Vsystem_name);  staticpro (&Vuser_name);  staticpro (&Vuser_full_name);  staticpro (&Vuser_real_name);  defsubr (&Schar_equal);  defsubr (&Sgoto_char);  defsubr (&Sstring_to_char);  defsubr (&Schar_to_string);  defsubr (&Sbuffer_substring);  defsubr (&Sbuffer_string);  defsubr (&Spoint_marker);  defsubr (&Smark_marker);  defsubr (&Spoint);  defsubr (&Sregion_beginning);  defsubr (&Sregion_end);/*  defsubr (&Smark); *//*  defsubr (&Sset_mark); */  defsubr (&Ssave_excursion);  defsubr (&Sbufsize);  defsubr (&Spoint_max);  defsubr (&Spoint_min);  defsubr (&Spoint_min_marker);  defsubr (&Spoint_max_marker);  defsubr (&Sbobp);  defsubr (&Seobp);  defsubr (&Sbolp);  defsubr (&Seolp);  defsubr (&Sfollchar);  defsubr (&Sprevchar);  defsubr (&Schar_after);  defsubr (&Sinsert);  defsubr (&Sinsert_before_markers);  defsubr (&Sinsert_char);  defsubr (&Suser_login_name);  defsubr (&Suser_real_login_name);  defsubr (&Suser_uid);  defsubr (&Suser_real_uid);  defsubr (&Suser_full_name);  defsubr (&Scurrent_time_string);  defsubr (&Ssystem_name);  defsubr (&Smessage);  defsubr (&Sformat);#ifndef MAINTAIN_ENVIRONMENT /* in environ.c */  defsubr (&Sgetenv);#endif  defsubr (&Sinsert_buffer_substring);  defsubr (&Ssubst_char_in_region);  defsubr (&Sdelete_region);  defsubr (&Swiden);  defsubr (&Snarrow_to_region);  defsubr (&Ssave_restriction);}

⌨️ 快捷键说明

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