📄 dispnew.c
字号:
must delete first to avoid losing data in the insert */ if (endmatch && nlen < olen + nsp - osp) { move_cursor (vpos, nlen - endmatch + osp - nsp); delete_chars (olen + nsp - osp - nlen); olen = nlen - (nsp - osp); } move_cursor (vpos, osp); insert_chars ((char *)0, nsp - osp); } olen += nsp - osp; tem = nsp + begmatch + endmatch; if (nlen != tem || olen != tem) { move_cursor (vpos, nsp + begmatch); if (!endmatch || nlen == olen) { /* If new text being written reaches right margin, there is no need to do clear-to-eol at the end. (and it would not be safe, since cursor is not going to be "at the margin" after the text is done) */ if (nlen == screen_width) olen = 0; output_chars (nbody + nsp + begmatch, nlen - tem);#ifdef obsolete/* the following code loses disastrously if tem == nlen. Rather than trying to fix that case, I am trying the simpler solution found above. */ /* If the text reaches to the right margin, it will lose one way or another (depending on AutoWrap) to clear to end of line after outputting all the text. So pause with one character to go and clear the line then. */ if (nlen == screen_width && fast_clear_end_of_line && olen > nlen) { /* endmatch must be zero, and tem must equal nsp + begmatch */ output_chars (nbody + tem, nlen - tem - 1); clear_end_of_line (olen); olen = 0; /* Don't let it be cleared again later */ output_chars (nbody + nlen - 1, 1); } else output_chars (nbody + nsp + begmatch, nlen - tem);#endif } else if (nlen > olen) { output_chars (nbody + nsp + begmatch, olen - tem); insert_chars (nbody + nsp + begmatch + olen - tem, nlen - olen); olen = nlen; } else if (olen > nlen) { output_chars (nbody + nsp + begmatch, nlen - tem); delete_chars (olen - nlen); olen = nlen; } } just_erase: /* If any unerased characters remain after the new line, erase them. */ if (olen > nlen) { move_cursor (vpos, nlen); clear_end_of_line (olen); } /* Exchange contents between current_screen and new_screen. */ temp = new_screen->contents[vpos]; new_screen->contents[vpos] = current_screen->contents[vpos]; current_screen->contents[vpos] = temp;}count_blanks (str) char *str;{ register char *p = str; while (*str++ == ' '); return str - p - 1;}count_match (str1, str2) char *str1, *str2;{ register char *p1 = str1; register char *p2 = str2; while (*p1++ == *p2++); return p1 - str1 - 1;}DEFUN ("open-termscript", Fopen_termscript, Sopen_termscript, 1, 1, "FOpen termscript file: ", "Start writing all terminal output to FILE as well as the terminal.\n\FILE = nil means just close any termscript file currently open.") (file) Lisp_Object file;{ if (termscript != 0) fclose (termscript); termscript = 0; if (! NULL (file)) { file = Fexpand_file_name (file, Qnil); termscript = fopen (XSTRING (file)->data, "w"); if (termscript == 0) report_file_error ("Opening termscript", Fcons (file, Qnil)); } return Qnil;}DEFUN ("set-screen-height", Fset_screen_height, Sset_screen_height, 1, 2, 0, "Tell redisplay that the screen has LINES lines.\n\Optional second arg non-nil means that redisplay should use LINES lines\n\but that the idea of the actual height of the screen should not be changed.") (n, pretend) Lisp_Object n, pretend;{ CHECK_NUMBER (n, 0); change_screen_size (XINT (n), 0, !NULL (pretend)); return Qnil;}DEFUN ("set-screen-width", Fset_screen_width, Sset_screen_width, 1, 2, 0, "Tell redisplay that the screen has COLS columns.\n\Optional second arg non-nil means that redisplay should use COLS columns\n\but that the idea of the actual width of the screen should not be changed.") (n, pretend) Lisp_Object n, pretend;{ CHECK_NUMBER (n, 0); change_screen_size (0, XINT (n), !NULL (pretend)); return Qnil;}DEFUN ("screen-height", Fscreen_height, Sscreen_height, 0, 0, 0, "Return number of lines on screen available for display.") (){ return make_number (screen_height);}DEFUN ("screen-width", Fscreen_width, Sscreen_width, 0, 0, 0, "Return number of columns on screen available for display.") (){ return make_number (screen_width);}#ifdef SIGWINCHwindow_change_signal (){ int width, height; extern int errno; int old_errno = errno; get_screen_size (&width, &height); /* Record the new size, but don't reallocate the data structures now. Let that be done later outside of the signal handler. */ in_display++; change_screen_size (height, width, 0); in_display--; signal (SIGWINCH, window_change_signal); errno = old_errno;}#endif /* SIGWINCH *//* Do any change in screen size that was requested by a signal. */do_pending_window_change (){ /* If change_screen_size should have run before, run it now. */ while (delayed_size_change) { int newwidth = delayed_screen_width; int newheight = delayed_screen_height; delayed_size_change = 0; change_screen_size_1 (newheight, newwidth, 0); }}/* Change the screen height and/or width. Values may be given as zero to indicate no change is to take place. PRETEND is normally 0; 1 means change used-size only but don't change the size used for calculations; -1 means don't redisplay. */change_screen_size (newlength, newwidth, pretend) register int newlength, newwidth, pretend;{ /* If we can't deal with the change now, queue it for later. */ if (in_display) { delayed_screen_width = newwidth; delayed_screen_height = newlength; delayed_size_change = 1; return; } delayed_size_change = 0; change_screen_size_1 (newlength, newwidth, pretend);}change_screen_size_1 (newlength, newwidth, pretend) register int newlength, newwidth, pretend;{ if ((newlength == 0 || newlength == screen_height) && (newwidth == 0 || newwidth == screen_width)) return; if (newlength && newlength != screen_height) { set_window_height (XWINDOW (minibuf_window)->prev, newlength - 1, 0); XFASTINT (XWINDOW (minibuf_window)->top) = newlength - 1; set_window_height (minibuf_window, 1, 0); screen_height = newlength; if (pretend <= 0) ScreenRows = newlength; set_terminal_window (0); } if (newwidth && newwidth != screen_width) { set_window_width (XWINDOW (minibuf_window)->prev, newwidth, 0); set_window_width (minibuf_window, newwidth, 0); screen_width = newwidth; if (pretend <= 0) ScreenCols = newwidth; } remake_screen_structures (); screen_garbaged = 1; calculate_costs (); if (pretend >= 0) redisplay_preserve_echo_area ();}DEFUN ("baud-rate", Fbaud_rate, Sbaud_rate, 0, 0, 0, "Return the output baud rate of the terminal.") (){ Lisp_Object temp; XSET (temp, Lisp_Int, baud_rate); return temp;}DEFUN ("send-string-to-terminal", Fsend_string_to_terminal, Ssend_string_to_terminal, 1, 1, 0, "Send STRING to the terminal without alteration.\n\Control characters in STRING will have terminal-dependent effects.") (str) Lisp_Object str;{ CHECK_STRING (str, 0); fwrite (XSTRING (str)->data, 1, XSTRING (str)->size, stdout); fflush (stdout); if (termscript) { fwrite (XSTRING (str)->data, 1, XSTRING (str)->size, termscript); fflush (termscript); } return Qnil;}DEFUN ("ding", Fding, Sding, 0, 1, 0, "Beep, or flash the screen.\n\Terminates any keyboard macro currently executing unless an argument\n\is given.") (arg) Lisp_Object arg;{ if (!NULL (arg)) { bell (); fflush (stdout); } else bell (); return Qnil;}bell (){ if (noninteractive) putchar (07); else if (!FROM_KBD) /* Stop executing a keyboard macro. */ error ("Keyboard macro terminated by a command ringing the bell"); else ring_bell (); fflush (stdout);}DEFUN ("sleep-for", Fsleep_for, Ssleep_for, 1, 1, 0, "Pause, without updating display, for ARG seconds.") (n) Lisp_Object n;{ register int t;#ifndef subprocesses#ifdef HAVE_TIMEVAL struct timeval timeout, end_time, garbage1;#endif /* HAVE_TIMEVAL */#endif /* no subprocesses */ CHECK_NUMBER (n, 0); t = XINT (n); if (t <= 0) return Qnil;#ifdef subprocesses wait_reading_process_input (t, 0, 0);#else /* No subprocesses */ immediate_quit = 1; QUIT;#ifdef VMS sys_sleep (t);#else /* not VMS *//* The reason this is done this way (rather than defined (H_S) && defined (H_T)) is because the VMS preprocessor doesn't grok `defined' */#ifdef HAVE_SELECT#ifdef HAVE_TIMEVAL gettimeofday (&end_time, &garbage1); end_time.tv_sec += t; while (1) { gettimeofday (&timeout, &garbage1); timeout.tv_sec = end_time.tv_sec - timeout.tv_sec; timeout.tv_usec = end_time.tv_usec - timeout.tv_usec; if (timeout.tv_usec < 0) timeout.tv_usec += 1000000, timeout.tv_sec--; if (timeout.tv_sec < 0) break; if (!select (1, 0, 0, 0, &timeout)) break; }#else /* not HAVE_TIMEVAL */ /* Is it safe to quit out of `sleep'? I'm afraid to trust it. */ sleep (t);#endif /* HAVE_TIMEVAL */#else /* not HAVE_SELECT */ sleep (t);#endif /* HAVE_SELECT */#endif /* not VMS */ immediate_quit = 0;#endif /* no subprocesses */ return Qnil;}DEFUN ("sit-for", Fsit_for, Ssit_for, 1, 2, 0, "Perform redisplay, then wait for ARG seconds or until input is available.\n\Optional second arg non-nil means don't redisplay.\n\Redisplay is preempted as always if input arrives, and does not happen\n\if input is available before it starts.\n\Value is t if waited the full time with no input arriving.") (n, nodisp) Lisp_Object n, nodisp;{#ifndef subprocesses#ifdef HAVE_TIMEVAL struct timeval timeout;#else int timeout_sec;#endif int waitchannels;#endif /* no subprocesses */ CHECK_NUMBER (n, 0); if (detect_input_pending ()) return Qnil; if (EQ (nodisp, Qnil)) redisplay_preserve_echo_area (); if (XINT (n) > 0) {#ifdef subprocesses#ifdef SIGIO gobble_input ();#endif /* SIGIO */ wait_reading_process_input (XINT (n), 1, 1);#else /* no subprocesses */ immediate_quit = 1; QUIT; waitchannels = 1;#ifdef VMS input_wait_timeout (XINT (n));#else /* not VMS */#ifndef HAVE_TIMEVAL timeout_sec = XINT (n); select (1, &waitchannels, 0, 0, &timeout_sec);#else /* HAVE_TIMEVAL */ timeout.tv_sec = XINT (n); timeout.tv_usec = 0; select (1, &waitchannels, 0, 0, &timeout);#endif /* HAVE_TIMEVAL */#endif /* not VMS */ immediate_quit = 0;#endif /* no subprocesses */ } return detect_input_pending () ? Qnil : Qt;}char *terminal_type;/* Initialization done when Emacs fork is started, before doing stty. *//* Determine terminal type and set terminal_driver *//* Then invoke its decoding routine to set up variables in the terminal package */init_display (){#ifdef HAVE_X_WINDOWS extern Lisp_Object Vxterm; Vxterm = Qnil;#endif Vwindow_system = Qnil; meta_key = 0; inverse_video = 0; cursor_in_echo_area = 0; terminal_type = (char *) 0; if (!inhibit_window_system) {#ifdef HAVE_X_WINDOWS extern char *alternate_display; char *disp = (char *) egetenv ("DISPLAY"); /* Note KSH likes to provide an empty string as an envvar value. */ if (alternate_display || (disp && *disp)) { x_term_init (); Vxterm = Qt; Vwindow_system = intern ("x");#ifdef X11 Vwindow_system_version = make_number (11);#else Vwindow_system_version = make_number (10);#endif goto term_init_done; }#endif /* HAVE_X_WINDOWS */ ; } /* Record we aren't using a window system. */ inhibit_window_system = 1; /* Look at the TERM variable */ terminal_type = (char *) getenv ("TERM"); if (!terminal_type) {#ifdef VMS fprintf (stderr, "Please specify your terminal type.\n\For types defined in VMS, use set term /device=TYPE.\n\For types not defined in VMS, use define emacs_term \"TYPE\".\n\\(The quotation marks are necessary since terminal types are lower case.)\n");#else fprintf (stderr, "Please set the environment variable TERM; see tset(1).\n");#endif exit (1); } term_init (terminal_type); term_init_done: remake_screen_structures (); calculate_costs ();#ifdef SIGWINCH#ifndef CANNOT_DUMP if (initialized)#endif /* CANNOT_DUMP */ if (inhibit_window_system) signal (SIGWINCH, window_change_signal);#endif /* SIGWINCH */}syms_of_display (){ defsubr (&Sopen_termscript); defsubr (&Sding); defsubr (&Ssit_for); defsubr (&Sscreen_height); defsubr (&Sscreen_width); defsubr (&Sset_screen_height); defsubr (&Sset_screen_width); defsubr (&Ssleep_for); defsubr (&Sbaud_rate); defsubr (&Ssend_string_to_terminal); DEFVAR_BOOL ("inverse-video", &inverse_video, "*Non-nil means use inverse-video."); DEFVAR_BOOL ("visible-bell", &visible_bell, "*Non-nil means try to flash the screen to represent a bell."); DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter, "*Non-nil means no need to redraw entire screen after suspending.\n\It is up to you to set this variable to inform Emacs."); DEFVAR_LISP ("window-system", &Vwindow_system, "A symbol naming the window-system under which Emacs is running,\n\\(such as `x'), or nil if emacs is running on an ordinary terminal."); DEFVAR_LISP ("window-system-version", &Vwindow_system_version, "Version number of the window system Emacs is running under."); DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area, "Non-nil means put cursor in minibuffer after any message displayed there."); /* Initialize `window-system', unless init_display already decided it. */#ifdef CANNOT_DUMP if (noninteractive)#endif { Vwindow_system_version = Qnil; Vwindow_system = Qnil; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -