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

📄 indent.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	break;      pos++;      col++;      if (c == '\t')	{	  col += tab_width - 1;	  col = col / tab_width * tab_width;	}      else if (ctl_arrow && (c < 040 || c == 0177))        col++;      else if (c < 040 || c >= 0177)        col += 3;    }  SET_PT (pos);  last_known_column = col;  last_known_column_point = point;  last_known_column_modified = MODIFF;  XFASTINT (val) = col;  return val;}struct position val_compute_motion;struct position *compute_motion (from, fromvpos, fromhpos, to, tovpos, tohpos, width, hscroll, tab_offset)     int from, fromvpos, fromhpos, to, tovpos, tohpos;     register int width;     int hscroll, tab_offset;{/* Note that `cpos' is CURRENT_VPOS << SHORTBITS + CURRENT_HPOS,   and that CURRENT_HPOS may be negative.  Use these macros   to extract the hpos or the vpos from cpos or anything like it. */#ifndef SHORT_CAST_BUG#define HPOS(VAR) (short) (VAR)#else#define HPOS(VAR) (((VAR) & (1 << (SHORTBITS - 1)) \		    ? ~((1 << SHORTBITS) - 1) : 0) \		   | (VAR) & ((1 << SHORTBITS) - 1))/* #define HPOS(VAR) (((VAR) & 0x8000 ? 0xffff0000 : 0) | ((VAR) & 0xffff)) */#endif /* SHORT_CAST_BUG */#define VPOS(VAR) (((VAR) >> SHORTBITS) + (HPOS (VAR) < 0))#ifndef TAHOE_REGISTER_BUG  register#endif /* TAHOE_REGISTER_BUG */    int cpos = fromhpos + (fromvpos << SHORTBITS);  register int target = tohpos + (tovpos << SHORTBITS);  register int pos;  register int c;  register int tab_width = XFASTINT (current_buffer->tab_width);  register int ctl_arrow = !NULL (current_buffer->ctl_arrow);  int selective    = XTYPE (current_buffer->selective_display) == Lisp_Int      ? XINT (current_buffer->selective_display)	: !NULL (current_buffer->selective_display) ? -1 : 0;  int prevpos;  if (tab_width <= 0 || tab_width > 20) tab_width = 8;  for (pos = from; pos < to && cpos < target; pos++)    {      prevpos = cpos;      c = FETCH_CHAR (pos);      if (c >= 040 && c < 0177)	cpos++;      else if (c == '\t')	{	  cpos += tab_width	    - HPOS (cpos + tab_offset + hscroll - (hscroll > 0)		    /* Add tab_width here to make sure positive.		       cpos can be negative after continuation		       but can't be less than -tab_width.  */		    + tab_width)	      % tab_width;	}      else if (c == '\n')	{	  if (selective > 0 && position_indentation (pos + 1) >= selective)	    {	      /* Skip any number of invisible lines all at once */	      do		{		  while (++pos < to && FETCH_CHAR(pos) != '\n');		}	      while (selective > 0 && position_indentation (pos + 1) >= selective);	      pos--;	      /* Allow for the " ..." that is displayed for them. */	      if (!NULL (current_buffer->selective_display_ellipses))		{		  cpos += 4;		  if (HPOS (cpos) >= width)		    cpos -= HPOS (cpos) - width;		}	    }	  else	    cpos += (1 << SHORTBITS) - HPOS (cpos);	  cpos -= hscroll;	  if (hscroll > 0) cpos++; /* Count the ! on column 0 */	  tab_offset = 0;	}      else if (c == CR && selective < 0)	{	  /* In selective display mode,	     everything from a ^M to the end of the line is invisible */	  while (pos < to && FETCH_CHAR(pos) != '\n') pos++;	  pos--;	  /* Allow for the " ..." that is displayed for them. */	  if (!NULL (current_buffer->selective_display_ellipses))	    {	      cpos += 4;	      if (HPOS (cpos) >= width)		cpos -= HPOS (cpos) - width;	    }	}      else	cpos += (ctl_arrow && c < 0200) ? 2 : 4;      if (HPOS (cpos) >= width	  && (HPOS (cpos) > width	      || (pos < ZV - 1		  && FETCH_CHAR (pos + 1) != '\n')))	{	  if (cpos >= target)	    break;	  if (hscroll	      || (truncate_partial_width_windows		  && width + 1 < screen_width)	      || !NULL (current_buffer->truncate_lines))	    {	      while (pos < to && FETCH_CHAR(pos) != '\n') pos++;	      pos--;	    }	  else	    {	      cpos += (1 << SHORTBITS) - width;	      tab_offset += width;	    }	}    }  val_compute_motion.bufpos = pos;  val_compute_motion.hpos = HPOS (cpos);  val_compute_motion.vpos = VPOS (cpos);  val_compute_motion.prevhpos = HPOS (prevpos);  /* Nonzero if have just continued a line */  val_compute_motion.contin    = pos != from      && (val_compute_motion.vpos != VPOS (prevpos))      && c != '\n';  return &val_compute_motion;}#undef HPOS#undef VPOSpos_tab_offset (w, pos)     struct window *w;     register int pos;{  int opoint = point;  int col;  if (pos == BEGV || FETCH_CHAR (pos - 1) == '\n')    return 0;  SET_PT (pos);  col = current_column ();  SET_PT (opoint);  return col - (col % (XFASTINT (w->width) - 1));}/* start_hpos is the hpos of the first character of the buffer:   zero except for the minibuffer window,   where it is the width of the prompt.  */struct position val_vmotion;struct position *vmotion (from, vtarget, width, hscroll, window)     register int from, vtarget, width;     int hscroll;     Lisp_Object window;{  struct position pos;  /* vpos is cumulative vertical position, changed as from is changed */  register int vpos = 0;  register int prevline;  register int first;  int lmargin = hscroll > 0 ? 1 - hscroll : 0;  int selective    = XTYPE (current_buffer->selective_display) == Lisp_Int      ? XINT (current_buffer->selective_display)	: !NULL (current_buffer->selective_display) ? -1 : 0;  int start_hpos = (EQ (window, minibuf_window) ? minibuf_prompt_width : 0); retry:  if (vtarget > vpos)    {      /* Moving downward is simple, but must calculate from beg of line 	 to determine hpos of starting point */      if (from > BEGV && FETCH_CHAR (from - 1) != '\n')	{	  prevline = find_next_newline (from, -1);	  while (selective > 0		 && prevline > BEGV		 && position_indentation (prevline) >= selective)	    prevline = find_next_newline (prevline - 1, -1);	  pos = *compute_motion (prevline, 0,				 lmargin + (prevline == 1 ? start_hpos : 0),				 from, 10000, 10000,				 width, hscroll, 0);	}      else	{	  pos.hpos = lmargin + (from == 1 ? start_hpos : 0);	  pos.vpos = 0;	}      return compute_motion (from, vpos, pos.hpos,			     ZV, vtarget, - (1 << (SHORTBITS - 1)),			     width, hscroll, pos.vpos * width);    }  /* To move upward, go a line at a time until     we have gone at least far enough */  first = 1;  while ((vpos > vtarget || first) && from > BEGV)    {      prevline = from;      while (1)	{	  prevline = find_next_newline (prevline - 1, -1);	  if (prevline == BEGV	      || selective <= 0	      || position_indentation (prevline) < selective)	    break;	}      pos = *compute_motion (prevline, 0,			     lmargin + (prevline == 1 ? start_hpos : 0),			     from, 10000, 10000,			     width, hscroll, 0);      vpos -= pos.vpos;      first = 0;      from = prevline;    }  /* If we made exactly the desired vertical distance,     or if we hit beginning of buffer,     return point found */  if (vpos >= vtarget)    {      val_vmotion.bufpos = from;      val_vmotion.vpos = vpos;      val_vmotion.hpos = lmargin;      val_vmotion.contin = 0;      val_vmotion.prevhpos = 0;      return &val_vmotion;    }    /* Otherwise find the correct spot by moving down */  goto retry;}DEFUN ("vertical-motion", Fvertical_motion, Svertical_motion, 1, 1, 0,  "Move to start of screen line LINES lines down.\n\If LINES is negative, this is moving up.\n\Sets point to position found; this may be start of line\n\ or just the start of a continuation line.\n\Returns number of lines moved; may be closer to zero than LINES\n\ if beginning or end of buffer was reached.")  (lines)     Lisp_Object lines;{  struct position pos;  register struct window *w = XWINDOW (selected_window);  CHECK_NUMBER (lines, 0);  pos = *vmotion (point, XINT (lines),		  XFASTINT (w->width) - 1		  - (XFASTINT (w->width) + XFASTINT (w->left)		     != XFASTINT (XWINDOW (minibuf_window)->width)),		  /* Not XFASTINT since perhaps could be negative */		  XINT (w->hscroll), selected_window);  SET_PT (pos.bufpos);  return make_number (pos.vpos);}syms_of_indent (){  DEFVAR_BOOL ("indent-tabs-mode", &indent_tabs_mode,    "*Indentation can insert tabs if this is non-nil.\n\Setting this variable automatically makes it local to the current buffer.");  indent_tabs_mode = 1;  defsubr (&Scurrent_indentation);  defsubr (&Sindent_to);  defsubr (&Scurrent_column);  defsubr (&Smove_to_column);  defsubr (&Svertical_motion);}

⌨️ 快捷键说明

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