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

📄 terminal.el

📁 早期freebsd实现
💻 EL
📖 第 1 页 / 共 3 页
字号:
;; Terminal emulator for GNU Emacs.;; Copyright (C) 1986, 1987 Free Software Foundation, Inc.;; Written by Richard Mlynarik, November 1986.;; This file is part of GNU Emacs.;; GNU Emacs is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 1, or (at your option);; any later version.;; GNU Emacs is distributed in the hope that it will be useful,;; but WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the;; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with GNU Emacs; see the file COPYING.  If not, write to;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.;;>>TODO;;>> terminfo?;;>> ** Nothing can be done about emacs' meta-lossage **;;>>  (without redoing keymaps `sanely' -- ask Mly for details);;>> One probably wants to do setenv MORE -c when running with;;>>   more-processing enabled.(provide 'terminal)(require 'ehelp)(defvar terminal-escape-char ?\C-^  "*All characters except for this are passed verbatim through theterminal-emulator.  This character acts as a prefix for commandsto the emulator program itself.  Type this character twice to sendit through the emulator.  Type ? after typing it for a list ofpossible commands.This variable is local to each terminal-emulator buffer.")(defvar terminal-scrolling t  "*If non-nil, the terminal-emulator will `scroll' when output occurspast the bottom of the screen.  If nil, output will `wrap' to the topof the screen.This variable is local to each terminal-emulator buffer.")(defvar terminal-more-processing t  "*If non-nil, do more-processing.This variable is local to each terminal-emulator buffer.");; If you are the sort of loser who uses scrolling without more breaks;; and expects to actually see anything, you should probably set this to;; around 400(defvar terminal-redisplay-interval 5000  "*Maximum number of characters which will be processed by theterminal-emulator before a screen redisplay is forced.Set this to a large value for greater throughput,set it smaller for more frequent updates but overall slowerperformance.")(defvar terminal-more-break-insertion  "*** More break -- Press space to continue ***")(defvar terminal-escape-map nil)(defvar terminal-map nil)(defvar terminal-more-break-map nil)(if terminal-map    nil  (let ((map (make-keymap)))    (fillarray map 'te-pass-through)    ;(define-key map "\C-l"    ;  '(lambda () (interactive) (te-pass-through) (redraw-display)))    (setq terminal-map map)));(setq terminal-escape-map nil)(if terminal-escape-map    nil  (let ((map (make-keymap)))    ;(fillarray map 'te-escape-extended-command-unread)    (fillarray map 'undefined)    (let ((s "0"))      (while (<= (aref s 0) ?9)	(define-key map s 'digit-argument)	(aset s 0 (1+ (aref s 0)))))    (define-key map "b" 'switch-to-buffer)    (define-key map "o" 'other-window)    (define-key map "e" 'te-set-escape-char)    (define-key map "\C-l" 'redraw-display)    (define-key map "\C-o" 'te-flush-pending-output)    (define-key map "m" 'te-toggle-more-processing)    (define-key map "x" 'te-escape-extended-command)    (define-key map "?" 'te-escape-help)    (define-key map (char-to-string help-char) 'te-escape-help)    (setq terminal-escape-map map)))(defvar te-escape-command-alist ());(setq te-escape-command-alist ())(if te-escape-command-alist    nil  (setq te-escape-command-alist	'(("Set Escape Character" . te-set-escape-char)	  ("Refresh" . redraw-display)	  ("Record Output" . te-set-output-log)	  ("Photo" . te-set-output-log)	  ("Tofu" . te-tofu) ;; confuse the uninitiated	  ("Stuff Input" . te-stuff-string)	  ("Flush Pending Output" . te-flush-pending-output)	  ("Enable More Processing" . te-enable-more-processing)	  ("Disable More Processing" . te-disable-more-processing)	  ("Scroll at end of page" . te-do-scrolling)	  ("Wrap at end of page" . te-do-wrapping)	  ("Switch To Buffer" . switch-to-buffer)	  ("Other Window" . other-window)	  ("Kill Buffer" . kill-buffer)	  ("Help" . te-escape-help)	  ("Set Redisplay Interval" . te-set-redisplay-interval)	  )));(setq terminal-more-break-map nil)(if terminal-more-break-map    nil  (let ((map (make-keymap)))    (fillarray map 'te-more-break-unread)    (define-key map (char-to-string help-char) 'te-more-break-help)    (define-key map " " 'te-more-break-resume)    (define-key map "\C-l" 'redraw-display)    (define-key map "\C-o" 'te-more-break-flush-pending-output)    ;;>>> this isn't right    ;(define-key map "\^?" 'te-more-break-flush-pending-output) ;DEL    (define-key map "\r" 'te-more-break-advance-one-line)    (setq terminal-more-break-map map)))  ;;;;  escape map(defun te-escape ()  (interactive)  (let (s 	(local (current-local-map))	(global (current-global-map)))    (unwind-protect	(progn	  (use-global-map terminal-escape-map)	  (use-local-map terminal-escape-map)	  (setq s (read-key-sequence		    (if prefix-arg			(format "Emacs Terminal escape> %d "				(prefix-numeric-value prefix-arg))		        "Emacs Terminal escape> "))))      (use-global-map global)      (use-local-map local))    (message "")    (cond ((string= s (make-string 1 terminal-escape-char))	   (setq last-command-char terminal-escape-char)	   (let ((terminal-escape-char -259))	     (te-pass-through)))	  ((setq s (lookup-key terminal-escape-map s))	   (call-interactively s)))))(defun te-escape-help ()  "Provide help on commands available after terminal-escape-char is typed."  (interactive)  (message "Terminal emulator escape help...")  (let ((char (single-key-description terminal-escape-char)))    (with-electric-help      (function (lambda ()	 (princ (format "Terminal-emulator escape, invoked by \"%s\"Type \"%s\" twice to send a single \"%s\" through.Other chars following \"%s\" are interpreted as follows:\n"			char char char char))	 (princ (substitute-command-keys "\\{terminal-escape-map}\n"))	 (princ (format "\nSubcommands of \"%s\" (%s)\n"			(where-is-internal 'te-escape-extended-command					   terminal-escape-map t)			'te-escape-extended-command))	 (let ((l (if (fboundp 'sortcar)		      (sortcar (copy-sequence te-escape-command-alist)			       'string<)		      (sort (copy-sequence te-escape-command-alist)			    (function (lambda (a b)                              (string< (car a) (car b))))))))	   (while l	     (let ((doc (or (documentation (cdr (car l)))			    "Not documented")))	       (if (string-match "\n" doc)		   ;; just use first line of documentation		   (setq doc (substring doc 0 (match-beginning 0))))	       (princ "  \"")	       (princ (car (car l)))	       (princ "\":\n     ")	       (princ doc)	       (write-char ?\n))	     (setq l (cdr l))))	 nil)))))			(defun te-escape-extended-command ()  (interactive)  (let ((c (let ((completion-ignore-case t))	     (completing-read "terminal command: "			      te-escape-command-alist			      nil t))))    (if c	(catch 'foo	  (setq c (downcase c))	  (let ((l te-escape-command-alist))	    (while l	      (if (string= c (downcase (car (car l))))		  (throw 'foo (call-interactively (cdr (car l))))		(setq l (cdr l)))))))));; not used.(defun te-escape-extended-command-unread ()  (interactive)  (setq unread-command-char last-input-char)  (te-escape-extended-command))(defun te-set-escape-char (c)  "Change the terminal-emulator escape character."  (interactive "cSet escape character to: ")  (let ((o terminal-escape-char))    (message (if (= o c)		 "\"%s\" is escape char"	         "\"%s\" is now escape; \"%s\" passes though")	     (single-key-description c)	     (single-key-description o))    (setq terminal-escape-char c)))(defun te-stuff-string (string)  "Read a string to send to through the terminal emulatoras though that string had been typed on the keyboard.Very poor man's file transfer protocol."  (interactive "sStuff string: ")  (process-send-string te-process string))(defun te-set-output-log (name)  "Record output from the terminal emulator in a buffer."  (interactive (list (if te-log-buffer			 nil		       (read-buffer "Record output in buffer: "				    (format "%s output-log"					    (buffer-name (current-buffer)))				    nil))))  (if (or (null name) (equal name ""))      (progn (setq te-log-buffer nil)	     (message "Output logging off."))    (if (get-buffer name)	nil      (save-excursion	(set-buffer (get-buffer-create name))	(fundamental-mode)	(buffer-flush-undo (current-buffer))	(erase-buffer)))    (setq te-log-buffer (get-buffer name))    (message "Recording terminal emulator output into buffer \"%s\""	     (buffer-name te-log-buffer))))(defun te-tofu ()  "Discontinue output log."  (interactive)  (te-set-output-log nil))  (defun te-toggle (sym arg)  (set sym (cond ((not (numberp arg)) arg)		 ((= arg 1) (not (symbol-value sym)))		 ((< arg 0) nil)		 (t t))))(defun te-toggle-more-processing (arg)  (interactive "p")  (message (if (te-toggle 'terminal-more-processing arg)	       "More processing on" "More processing off"))  (if terminal-more-processing (setq te-more-count -1)))(defun te-toggle-scrolling (arg)  (interactive "p")  (message (if (te-toggle 'terminal-scrolling arg)	       "Scroll at end of page" "Wrap at end of page")))(defun te-enable-more-processing ()  "Enable ** MORE ** processing"  (interactive)  (te-toggle-more-processing t))(defun te-disable-more-processing ()  "Disable ** MORE ** processing"  (interactive)  (te-toggle-more-processing nil))(defun te-do-scrolling ()  "Scroll at end of page (yuck)"  (interactive)  (te-toggle-scrolling t))(defun te-do-wrapping ()  "Wrap to top of window at end of page"  (interactive)  (te-toggle-scrolling nil))(defun te-set-redisplay-interval (arg)  "Set the maximum interval (in output characters) between screen updates.Set this number to large value for greater throughput,set it smaller for more frequent updates (but overall slower performance."  (interactive "NMax number of output chars between redisplay updates: ")  (setq arg (max arg 1))  (setq terminal-redisplay-interval arg	te-redisplay-count 0));;;; more map;; every command -must- call te-more-break-unwind;; or grave lossage will result(put 'te-more-break-unread 'suppress-keymap t)(defun te-more-break-unread ()  (interactive)  (if (= last-input-char terminal-escape-char)      (call-interactively 'te-escape)    (message "Continuing from more break (\"%s\" typed, %d chars output pending...)"	     (single-key-description last-input-char)	     (te-pending-output-length))    (setq te-more-count 259259)    (te-more-break-unwind)    (let ((terminal-more-processing nil))      (te-pass-through))))(defun te-more-break-resume ()  "Proceed past the **MORE** break,allowing the next page of output to appear"  (interactive)  (message "Continuing from more break")  (te-more-break-unwind))(defun te-more-break-help ()  "Provide help on commands available in a terminal-emulator **MORE** break"  (interactive)  (message "Terminal-emulator more break help...")  (sit-for 0)  (with-electric-help    (function (lambda ()      (princ "Terminal-emulator more break.\n\n")      (princ (format "Type \"%s\" (te-more-break-resume)\n%s\n"		     (where-is-internal 'te-more-break-resume					terminal-more-break-map t)		     (documentation 'te-more-break-resume)))      (princ (substitute-command-keys "\\{terminal-more-break-map}\n"))      (princ "Any other key is passed through to the programrunning under the terminal emulator and disables more processing untilall pending output has been dealt with.")      nil))))(defun te-more-break-advance-one-line ()  "Allow one more line of text to be output before doing another more break."  (interactive)  (setq te-more-count 1)  (te-more-break-unwind))(defun te-more-break-flush-pending-output ()  "Discard any output which has been received by the terminal emulator butnot yet proceesed and then proceed from the more break."  (interactive)  (te-more-break-unwind)  (te-flush-pending-output))(defun te-flush-pending-output ()  "Discard any as-yet-unprocessed output which has been received bythe terminal emulator."  (interactive)  ;; this could conceivably be confusing in the presence of  ;; escape-sequences spanning process-output chunks  (if (null (cdr te-pending-output))      (message "(There is no output pending)")    (let ((length (te-pending-output-length)))      (message "Flushing %d chars of pending output" length)

⌨️ 快捷键说明

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