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

📄 window.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
    XSETINT (n, XINT (n) + ht);  XSETINT (n, - XINT (n));  Fvertical_motion (n);  Fset_marker (w->start, make_number (point), w->buffer);  w->start_at_line_beg = Fbolp ();  SET_PT (opoint);  w->force_start = Qt;  return Qnil;}DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,  1, 1, "P",  "Position point relative to window.\n\With no argument, position at text at center of window.\n\An argument specifies screen line; zero means top of window,\n\negative means relative to bottom of window.")  (arg)     register Lisp_Object arg;{  register struct window *w = XWINDOW (selected_window);  register int height = XFASTINT (w->height);  register int start;  if (!EQ (selected_window, minibuf_window)) height--;  if (NULL (arg))    XFASTINT (arg) = height / 2;  else    {      arg = Fprefix_numeric_value (arg);      if (XINT (arg) < 0)	XSETINT (arg, XINT (arg) + height);    }  start = marker_position (w->start);  if (start < BEGV || start > ZV)    {      Fvertical_motion (make_number (- height / 2));      Fset_marker (w->start, make_number (point), w->buffer);      w->start_at_line_beg = Fbolp ();      w->force_start = Qt;    }  else    SET_PT (start);  return Fvertical_motion (arg);}struct save_window_data  {    int size_from_Lisp_Vector_struct;    struct Lisp_Vector *next_from_Lisp_Vector_struct;    Lisp_Object screen_width, screen_height;    Lisp_Object current_window;    Lisp_Object current_buffer;    Lisp_Object minibuf_scroll_window;    /* A vector, interpreted as a struct saved_window */    Lisp_Object saved_windows;  };#define SAVE_WINDOW_DATA_SIZE 6 /* Arg to Fmake_vector *//* This is saved as a Lisp_Vector */struct saved_window  {    /* these first two must agree with struct Lisp_Vector in lisp.h */    int size_from_Lisp_Vector_struct;    struct Lisp_Vector *next_from_Lisp_Vector_struct;    Lisp_Object window;    Lisp_Object buffer, start, pointm, mark;    Lisp_Object left, top, width, height, hscroll;    Lisp_Object parent, prev;    Lisp_Object start_at_line_beg;  };#define SAVED_WINDOW_VECTOR_SIZE 13 /* Arg to Fmake_vector */#define SAVED_WINDOW_N(swv,n) \  ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))DEFUN ("set-window-configuration",       Fset_window_configuration, Sset_window_configuration,       1, 1, 0,       "Restore the configuration of Emacs' windows and buffers to\n\the state specified by CONFIGURATION.  CONFIGURATION must be a value\n\retrned by  current-window-configuration  -- see the documentation of that\n\function for more information.")     (arg)     Lisp_Object arg;{  register struct window *w;  register struct save_window_data *data;  struct Lisp_Vector *saved_windows;  register struct saved_window *p;  register Lisp_Object tem;  Lisp_Object new_current_buffer;  int k;  /* Save screen height here so we can go back to it at the end.  */  int previous_screen_height = screen_height;  int previous_screen_width = screen_width;  int screen_size_change = 0;  while (XTYPE (arg) != Lisp_Window_Configuration)    {      /* the function window-configuration-p isn't actually defined	 at present --- is there a need for it? */      arg = wrong_type_argument (intern ("window-configuration-p"), arg);    }  data = (struct save_window_data *) XVECTOR (arg);  saved_windows = XVECTOR (data->saved_windows);  /* Set the screen height to the value it had at save time.  */  if (XFASTINT (data->screen_height) != screen_height      || XFASTINT (data->screen_width) != screen_width)    {      change_screen_size (data->screen_height, data->screen_width, 0);      screen_size_change = 1;    }  windows_or_buffers_changed++;  new_current_buffer = data->current_buffer;  if (NULL (XBUFFER (new_current_buffer)->name))    new_current_buffer = Qnil;  for (k = 0; k < saved_windows->size; k++)    {      p = SAVED_WINDOW_N (saved_windows, k);      w = XWINDOW (p->window);      w->next = Qnil;      if (!NULL (p->parent))	w->parent = SAVED_WINDOW_N (saved_windows, XFASTINT (p->parent))->window;      else	w->parent = Qnil;      if (!NULL (p->prev))	{	  w->prev = SAVED_WINDOW_N (saved_windows, XFASTINT (p->prev))->window;	  XWINDOW (w->prev)->next = p->window;	}      else	{	  w->prev = Qnil;	  if (!NULL (w->parent))	    {	      if (EQ (p->width, XWINDOW (w->parent)->width))		{		  XWINDOW (w->parent)->vchild = p->window;		  XWINDOW (w->parent)->hchild = Qnil;		}	      else		{		  XWINDOW (w->parent)->hchild = p->window;		  XWINDOW (w->parent)->vchild = Qnil;		}	    }	}      w->left = p->left;      w->top = p->top;      w->width = p->width;      w->height = p->height;      w->hscroll = p->hscroll;      XFASTINT (w->last_modified) = 0;      /* Reinstall the saved buffer and pointers into it.  */      if (NULL (p->buffer))	w->buffer = p->buffer;      else	{	  if (!NULL (XBUFFER (p->buffer)->name))	    /* If saved buffer is alive, install it.  */	    {	      w->buffer = p->buffer;	      w->start_at_line_beg = p->start_at_line_beg;	      set_marker_restricted (w->start,				     Fmarker_position (p->start), w->buffer);	      set_marker_restricted (w->pointm,				     Fmarker_position (p->pointm), w->buffer);	      Fset_marker (XBUFFER (w->buffer)->mark,			   Fmarker_position (p->mark), w->buffer);	      if (!EQ (p->buffer, new_current_buffer) &&		  XBUFFER (p->buffer) == current_buffer)		Fgoto_char (w->pointm);	    }	  else if (NULL (XBUFFER (w->buffer)->name))	    /* Else if window's old buffer is dead too, get a live one.  */	    {	      w->buffer = Fcdr (Fcar (Vbuffer_alist));	      /* Set window markers at start of buffer.		 Rely on set_marker_restricted to put them		 within the restriction.  */	      set_marker_restricted (w->start, make_number (0), w->buffer);	      set_marker_restricted (w->pointm, make_number (0), w->buffer);	      w->start_at_line_beg = Qt;	    }	  else	    /* Keeping window's old buffer; make sure the markers are real.  */	    /* Else if window's old buffer is dead too, get a live one.  */	    {	      /* Set window markers at start of buffer.		 Rely on set_marker_restricted to put them within the restriction.  */	      if (XMARKER (w->start)->buffer == 0)		set_marker_restricted (w->start, make_number (0), w->buffer);	      if (XMARKER (w->pointm)->buffer == 0)		set_marker_restricted (w->pointm,				       make_number (BUF_PT (XBUFFER (w->buffer))),				       w->buffer);	      w->start_at_line_beg = Qt;	    }	}    }  /* Set the screen height to the value it had before this function.  */  if (screen_size_change)    change_screen_size (previous_screen_height, previous_screen_width, 0);  Fselect_window (data->current_window);  if (!NULL (new_current_buffer))    Fset_buffer (new_current_buffer);  else    Fset_buffer (XWINDOW (selected_window)->buffer);  Vminibuf_scroll_window = data->minibuf_scroll_window;  return (Qnil);}static intcount_windows (window)     register struct window *window;{  register int count = 1;  if (!NULL (window->next))    count += count_windows (XWINDOW (window->next));  if (!NULL (window->vchild))    count += count_windows (XWINDOW (window->vchild));  if (!NULL (window->hchild))    count += count_windows (XWINDOW (window->hchild));  return count;}DEFUN ("current-window-configuration",	Fcurrent_window_configuration, Scurrent_window_configuration, 0, 0, 0,       "Return an object representing Emacs' current window configuration,\n\namely the number of windows, their sizes and current buffers, and for\n\each displayed buffer, where display starts, and the positions of\n\point and mark.  An exception is made for point in (current-buffer) --\n\its value is -not- saved.")  (){  register Lisp_Object tem;  register int n_windows;  register struct save_window_data *data;  register int i;  n_windows = count_windows (XWINDOW (XWINDOW (minibuf_window)->prev));  data = (struct save_window_data *)           XVECTOR (Fmake_vector (make_number (SAVE_WINDOW_DATA_SIZE),				  Qnil));  XFASTINT (data->screen_width) = screen_width;  XFASTINT (data->screen_height) = screen_height;  data->current_window = selected_window;  XSET (data->current_buffer, Lisp_Buffer, current_buffer);  data->minibuf_scroll_window = Vminibuf_scroll_window;  tem = Fmake_vector (make_number (n_windows), Qnil);  data->saved_windows = tem;  for (i = 0; i < n_windows; i++)    XVECTOR (tem)->contents[i]      = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil);  save_window_save (XWINDOW (minibuf_window)->prev,		    XVECTOR (tem),		    0, n_windows);  XSET (tem, Lisp_Window_Configuration, data);  return (tem);}static intsave_window_save (window, vector, i, maxwindow)     Lisp_Object window;     struct Lisp_Vector *vector;     int i;     int maxwindow;{  register struct saved_window *p;  register struct window *w;  register Lisp_Object tem;  for (;!NULL (window); window = w->next)    {      /* If you get a crash here, you may be seeing a very weird bug.	 When it happened to me, it seems that count_windows returned	 a value that was too small--only two, when there were two	 visible windows, a parent, and the minibuffer (inactive).	 If this starts happening for you, please run under a debugger	 with a breakpoint at the abort, so that you can at least try calling	 count_windows again to see if it will lose again.	 If it does, you can find the bug.  */      if (i == maxwindow)	abort ();      p = SAVED_WINDOW_N (vector, i);      w = XWINDOW (window);      XFASTINT (w->temslot) = i++;      p->window = window;      p->buffer = w->buffer;      p->left = w->left;      p->top = w->top;      p->width = w->width;      p->height = w->height;      p->hscroll = w->hscroll;      if (!NULL (w->buffer))	{	  if (EQ (window, selected_window)	      && XBUFFER (w->buffer) == current_buffer)	    p->pointm = Fpoint_marker ();	  else	    p->pointm = Fcopy_marker (w->pointm);	  p->start = Fcopy_marker (w->start);	  p->start_at_line_beg = w->start_at_line_beg;	  tem = XBUFFER (w->buffer)->mark;	  p->mark = Fcopy_marker (tem);	}      else	{	  p->pointm = Qnil;	  p->start = Qnil;	  p->mark = Qnil;	  p->start_at_line_beg = Qnil;	}      if (NULL (w->parent))	p->parent = Qnil;      else	p->parent = XWINDOW (w->parent)->temslot;      if (NULL (w->prev))	p->prev = Qnil;      else	p->prev = XWINDOW (w->prev)->temslot;      if (!NULL (w->vchild))	i = save_window_save (w->vchild, vector, i, maxwindow);      if (!NULL (w->hchild))	i = save_window_save (w->hchild, vector, i, maxwindow);    }  return i;}DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,  0, UNEVALLED, 0,  "Execute body, preserving window sizes and contents.\n\Restores which buffer appears in which window, where display starts,\n\as well as the current buffer.\n\Does not restore the value of point in current buffer.")  (args)     Lisp_Object args;{  register Lisp_Object val;  register int count = specpdl_ptr - specpdl;  record_unwind_protect (Fset_window_configuration,			 Fcurrent_window_configuration ());  val = Fprogn (args);  unbind_to (count);  return val;}init_window_once (){  extern Lisp_Object get_minibuffer ();  register Lisp_Object root_window;  root_window = make_window (0);  minibuf_window = make_window (0);  XWINDOW (root_window)->next = minibuf_window;  XWINDOW (minibuf_window)->prev = root_window;  /* These values 9 and 10 are arbitrary,     just so that there is "something there."     Correct values are put in in init_xdisp */  XFASTINT (XWINDOW (root_window)->width) = 10;  XFASTINT (XWINDOW (minibuf_window)->width) = 10;  XFASTINT (XWINDOW (root_window)->height) = 9;  XFASTINT (XWINDOW (minibuf_window)->top) = 9;  XFASTINT (XWINDOW (minibuf_window)->height) = 1;  Fset_window_buffer (root_window, Fcurrent_buffer ());  Fset_window_buffer (minibuf_window, get_minibuffer (0));  selected_window = root_window;}syms_of_window (){  Qwindowp = intern ("windowp");  staticpro (&Qwindowp);  /* Make sure all windows get marked */  staticpro (&minibuf_window);  DEFVAR_LISP ("temp-buffer-show-hook", &Vtemp_buffer_show_hook,    "Non-nil means call as function to display a help buffer.\n\Used by with-output-to-temp-buffer.");  Vtemp_buffer_show_hook = Qnil;  DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window,    "Non-nil means it is the window that C-M-v in minibuffer should scroll.");  Vminibuf_scroll_window = Qnil;  DEFVAR_BOOL ("pop-up-windows", &pop_up_windows,    "*Non-nil means display-buffer should make new windows.");  pop_up_windows = 1;  DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines,    "*Number of lines of continuity when scrolling by screenfuls.");  next_screen_context_lines = 2;  DEFVAR_INT ("split-height-threshold", &split_height_threshold,    "*display-buffer would prefer to split the largest window if this large.\n\If there is only one window, it is split regardless of this value.");  split_height_threshold = 500;  DEFVAR_INT ("window-min-height", &window_min_height,    "*Delete any window less than this tall (including its mode line).");  window_min_height = 4;  DEFVAR_INT ("window-min-width", &window_min_width,    "*Delete any window less than this wide.");  window_min_width = 10;  defsubr (&Sselected_window);  defsubr (&Sminibuffer_window);  defsubr (&Swindowp);  defsubr (&Spos_visible_in_window_p);  defsubr (&Swindow_buffer);  defsubr (&Swindow_height);  defsubr (&Swindow_width);  defsubr (&Swindow_hscroll);  defsubr (&Sset_window_hscroll);  defsubr (&Swindow_edges);  defsubr (&Swindow_point);  defsubr (&Swindow_start);  defsubr (&Sset_window_point);  defsubr (&Sset_window_start);  defsubr (&Snext_window);  defsubr (&Sprevious_window);  defsubr (&Sother_window);  defsubr (&Sget_lru_window);  defsubr (&Sget_largest_window);  defsubr (&Sget_buffer_window);  defsubr (&Sdelete_other_windows);  defsubr (&Sdelete_windows_on);  defsubr (&Sreplace_buffer_in_windows);  defsubr (&Sdelete_window);  defsubr (&Sset_window_buffer);  defsubr (&Sselect_window);  defsubr (&Sdisplay_buffer);  defsubr (&Ssplit_window);  defsubr (&Senlarge_window);  defsubr (&Sshrink_window);  defsubr (&Sscroll_up);  defsubr (&Sscroll_down);  defsubr (&Sscroll_left);  defsubr (&Sscroll_right);  defsubr (&Sscroll_other_window);  defsubr (&Srecenter);  defsubr (&Smove_to_window_line);  defsubr (&Sset_window_configuration);  defsubr (&Scurrent_window_configuration);  defsubr (&Ssave_window_excursion);}keys_of_window (){  ndefkey (Vctl_x_map, '1', "delete-other-windows");  ndefkey (Vctl_x_map, '2', "split-window");  ndefkey (Vctl_x_map, '0', "delete-window");  ndefkey (Vctl_x_map, 'o', "other-window");  ndefkey (Vctl_x_map, '^', "enlarge-window");  ndefkey (Vctl_x_map, '<', "scroll-left");  ndefkey (Vctl_x_map, '>', "scroll-right");  ndefkey (Vglobal_map, Ctl ('V'), "scroll-up");  ndefkey (Vesc_map, Ctl ('V'), "scroll-other-window");  ndefkey (Vesc_map, 'v', "scroll-down");  ndefkey (Vglobal_map, Ctl('L'), "recenter");  ndefkey (Vesc_map, 'r', "move-to-window-line");}

⌨️ 快捷键说明

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