📄 window.c
字号:
while (1) { if (!NULL (XWINDOW (window)->hchild)) window = XWINDOW (window)->hchild; else if (!NULL (XWINDOW (window)->vchild)) window = XWINDOW (window)->vchild; else break; while (tem = XWINDOW (window)->next, !NULL (tem)) window = tem; } } while (EQ (window, minibuf_window) && minibuf_level == 0); return window;}DEFUN ("other-window", Fother_window, Sother_window, 1, 1, "p", "Select the ARG'th different window.") (n) register Lisp_Object n;{ register int i; register Lisp_Object w; CHECK_NUMBER (n, 0); w = selected_window; i = XINT (n); while (i > 0) { w = Fnext_window (w, Qnil); i--; } while (i < 0) { w = Fprevious_window (w); i++; } Fselect_window (w); return Qnil;}static Lisp_Objectwindow_loop (type, obj) int type; register Lisp_Object obj;{ register Lisp_Object w, tem, ret_w; Lisp_Object w1, start_w; register struct window *p, *q; w = minibuf_window; ret_w = Qnil; while (1) { p = XWINDOW (w); w1 = Fnext_window (w, Qt); if (!EQ (w, minibuf_window)) switch (type) { case 1: if (XBUFFER (p->buffer) == XBUFFER (obj)) return w; break; case 2: /* t as arg means consider only full-width windows */ if (!NULL (obj) && XFASTINT (p->width) != screen_width) break; if (NULL (ret_w) || XFASTINT (XWINDOW (ret_w)->use_time) > XFASTINT (p->use_time)) ret_w = w; break; case 3: if (p != XWINDOW (obj)) Fdelete_window (w); break; case 4: if (EQ (p->buffer, obj)) { if (NULL (p->parent)) { tem = Fother_buffer (obj); if (NULL (tem)) tem = Fget_buffer_create (build_string ("*scratch*")); Fset_window_buffer (w, tem); Fset_buffer (p->buffer); } else Fdelete_window (w); } break; case 5: q = XWINDOW (ret_w); if (NULL (ret_w) || (XFASTINT (p->height) * XFASTINT (p->width)) > (XFASTINT (q->height) * XFASTINT (q->width))) ret_w = w; break; case 6: if (EQ (p->buffer, obj)) { tem = Fother_buffer (obj); if (NULL (tem)) tem = Fget_buffer_create (build_string ("*scratch*")); Fset_window_buffer (w, tem); } break; } w = w1; if (EQ (w, minibuf_window)) return ret_w; }} DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 0, 0, "Return the window least recently selected or used for display.") (){ register Lisp_Object w; /* First try for a window that is full-width */ w = window_loop (2, Qt); if (!NULL (w) && !EQ (w, selected_window)) return w; /* If none of them, try the rest */ return window_loop (2, Qnil);}DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 0, 0, "Return the largest window in area.") (){ return window_loop (5, Qnil);}DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 1, 0, "Return a window currently displaying BUFFER, or nil if none.") (buffer) Lisp_Object buffer;{ buffer = Fget_buffer (buffer); if (XTYPE (buffer) == Lisp_Buffer) return window_loop (1, buffer); else return Qnil;}DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows, 0, 1, "", "Make WINDOW (or the selected window) fill the screen.") (w) Lisp_Object w;{ window_loop (3, !NULL (w) ? w : selected_window); return Qnil;}DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on, 1, 1, "bDelete windows on (buffer): ", "Delete all windows showing BUFFER.") (buffer) Lisp_Object buffer;{ if (!NULL (buffer)) { buffer = Fget_buffer (buffer); CHECK_BUFFER (buffer, 0); window_loop (4, buffer); } return Qnil;}DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, Sreplace_buffer_in_windows, 1, 1, "bReplace buffer in windows: ", "Replace BUFFER with some other buffer in all windows showing it.") (buffer) Lisp_Object buffer;{ if (!NULL (buffer)) { buffer = Fget_buffer (buffer); CHECK_BUFFER (buffer, 0); window_loop (6, buffer); } return Qnil;}/* Set the height of WINDOW and all its inferiors. *//* Normally the window is deleted if it gets too small. nodelete nonzero means do not do this. (The caller should check later and do so if appropriate) */set_window_height (window, height, nodelete) Lisp_Object window; int height; int nodelete;{ register struct window *w = XWINDOW (window); register struct window *c; int oheight = XFASTINT (w->height); int top, pos, lastbot, opos, lastobot; Lisp_Object child; if (window_min_height < 2) window_min_height = 2; if (!nodelete && ! NULL (w->parent) && height < (EQ(window, minibuf_window) ? 1 : window_min_height)) { Fdelete_window (window); return; } XFASTINT (w->last_modified) = 0; windows_or_buffers_changed++; XFASTINT (w->height) = height; if (!NULL (w->hchild)) { for (child = w->hchild; !NULL (child); child = XWINDOW (child)->next) { XWINDOW (child)->top = w->top; set_window_height (child, height, nodelete); } } else if (!NULL (w->vchild)) { lastbot = top = XFASTINT (w->top); lastobot = 0; for (child = w->vchild; !NULL (child); child = c->next) { c = XWINDOW (child); opos = lastobot + XFASTINT (c->height); XFASTINT (c->top) = lastbot; pos = (((opos * height) << 1) + oheight) / (oheight << 1); /* Avoid confusion: inhibit deletion of child if becomes too small */ set_window_height (child, pos + top - lastbot, 1); /* Now advance child to next window, and set lastbot if child was not just deleted. */ lastbot = pos + top, lastobot = opos; } /* Now delete any children that became too small. */ if (!nodelete) for (child = w->vchild; !NULL (child); child = XWINDOW (child)->next) { set_window_height (child, XINT (XWINDOW (child)->height), 0); } }}/* Recursively set width of WINDOW and its inferiors. */set_window_width (window, width, nodelete) Lisp_Object window; int width; int nodelete;{ register struct window *w = XWINDOW (window); register struct window *c; int owidth = XFASTINT (w->width); int left, pos, lastright, opos, lastoright; Lisp_Object child; if (!nodelete && ! NULL (w->parent) && width < window_min_width) { Fdelete_window (window); return; } XFASTINT (w->last_modified) = 0; windows_or_buffers_changed++; XFASTINT (w->width) = width; if (!NULL (w->vchild)) { for (child = w->vchild; !NULL (child); child = XWINDOW (child)->next) { XWINDOW (child)->left = w->left; set_window_width (child, width, nodelete); } } else if (!NULL (w->hchild)) { lastright = left = XFASTINT (w->left); lastoright = 0; for (child = w->hchild; !NULL (child); child = c->next) { c = XWINDOW (child); opos = lastoright + XFASTINT (c->width); XFASTINT (c->left) = lastright; pos = (((opos * width) << 1) + owidth) / (owidth << 1); /* Inhibit deletion for becoming too small */ set_window_width (child, pos + left - lastright, 1); /* Now advance child to next window, and set lastright if child was not just deleted. */ lastright = pos + left, lastoright = opos; } /* Delete children that became too small */ if (!nodelete) for (child = w->hchild; !NULL (child); child = XWINDOW (child)->next) { set_window_width (child, XINT (XWINDOW (child)->width), 0); } }}static int window_select_count;DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 2, 0, "Make WINDOW display BUFFER as its contents.\n\BUFFER can be a buffer or buffer name.") (window, buffer) register Lisp_Object window, buffer;{ register Lisp_Object tem; register struct window *w = decode_window (window); buffer = Fget_buffer (buffer); CHECK_BUFFER (buffer, 1); if (NULL (XBUFFER (buffer)->name)) error ("Attempt to display deleted buffer"); tem = w->buffer; if (!NULL (tem)) unshow_buffer (w); w->buffer = buffer; Fset_marker (w->pointm, make_number (BUF_PT (XBUFFER (buffer))), buffer); set_marker_restricted (w->start, make_number (XBUFFER (buffer)->last_window_start), buffer); w->start_at_line_beg = Qnil; XFASTINT (w->last_modified) = 0; windows_or_buffers_changed++; if (EQ (window, selected_window)) Fset_buffer (buffer); return Qnil;}/* Record info on buffer window w is displaying when it is about to cease to display that buffer. */staticunshow_buffer (w) register struct window *w;{ register Lisp_Object buf; buf = w->buffer; if (XBUFFER (buf) != XMARKER (w->pointm)->buffer) abort (); if (w == XWINDOW (selected_window) || ! EQ (buf, XWINDOW (selected_window)->buffer)) /* Do this except when the selected window's buffer is being removed from some other window. */ XBUFFER (buf)->last_window_start = marker_position (w->start); /* Point in the selected window's buffer is actually stored in that buffer, and the window's pointm isn't used. So don't clobber point in that buffer. */ if (! EQ (buf, XWINDOW (selected_window)->buffer)) BUF_PT (XBUFFER (buf)) = marker_position (w->pointm);}DEFUN ("select-window", Fselect_window, Sselect_window, 1, 1, 0, "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\The main editor command loop selects the buffer of the selected window\n\before each command.") (window) register Lisp_Object window;{ register struct window *w; register struct window *ow = XWINDOW (selected_window); CHECK_WINDOW (window, 0); w = XWINDOW (window); if (NULL (w->buffer)) error ("Trying to select window with no buffer"); XFASTINT (w->use_time) = ++window_select_count; if (EQ (window, selected_window)) return window; Fset_marker (ow->pointm, make_number (BUF_PT (XBUFFER (ow->buffer))), ow->buffer); selected_window = window; record_buffer (w->buffer); Fset_buffer (w->buffer); /* Go to the point recorded in the window. This is important when the buffer is in more than one window. It also matters when redisplay_window has altered point after scrolling, because it makes the change only in the window. */ SET_PT (marker_position (w->pointm)); if (point < BEGV) point = BEGV; if (point > ZV) point = ZV; windows_or_buffers_changed++; return window;}DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 2, 0, "Make BUFFER appear in some window but don't select it.\n\BUFFER can be a buffer or a buffer name.\n\If BUFFER is shown already in some window, just uses that one,\n\unless the window is the selected window and NOTTHISWINDOW is non-nil.\n\Returns the window displaying BUFFER.") (buffer, notthiswindow) register Lisp_Object buffer, notthiswindow;{ register Lisp_Object window; buffer = Fget_buffer (buffer); CHECK_BUFFER (buffer, 0); if (NULL (notthiswindow) && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer)) return selected_window; window = Fget_buffer_window (buffer); if (!NULL (window) && (NULL (notthiswindow) || !EQ (window, selected_window))) return window; if (pop_up_windows) { /* Don't try to create a window if would get an error */ if (window_min_height < 2) window_min_height = 2; if (split_height_threshold < window_min_height << 1) split_height_threshold = window_min_height << 1; window = Fget_largest_window (); if (window_height (window) >= split_height_threshold && XFASTINT (XWINDOW (window)->width) == screen_width) window = Fsplit_window (window, Qnil, Qnil); else { window = Fget_lru_window (); if ((EQ (window, selected_window) || (EQ (selected_window, minibuf_window) && EQ (window, XWINDOW (minibuf_window)->prev))) && window_height (window) >= window_min_height << 1) window = Fsplit_window (window, Qnil, Qnil); } } else window = Fget_lru_window (); Fset_window_buffer (window, buffer); return window;}temp_output_buffer_show (buf) register Lisp_Object buf;{ register struct buffer *old = current_buffer; register Lisp_Object window; register struct window *w; Fset_buffer (buf); XBUFFER (buf)->save_modified = MODIFF; BEGV = BEG; ZV = Z; SET_PT (BEG); clip_changed = 1; set_buffer_internal (old); if (!EQ (Vtemp_buffer_show_hook, Qnil)) call1 (Vtemp_buffer_show_hook, buf); else { window = Fdisplay_buffer (buf, Qnil); Vminibuf_scroll_window = window; w = XWINDOW (window); XFASTINT (w->hscroll) = 0; set_marker_restricted (w->start, make_number (1), buf); set_marker_restricted (w->pointm, make_number (1), buf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -