?? gnuserv.el
字號:
; Lisp Interface code between GNU Emacs and gnuserv.;; This file is part of GNU Emacs.;; Copying is permitted under those conditions described by the GNU; General Public License.;; Copyright (C) 1989 Free Software Foundation, Inc.;; Author: Andy Norman (ange@hplb.hpl.hp.com) based on; 'lisp/server.el' from the 18.52 GNU Emacs distribution.;; Please mail bugs and suggestions to the author at the above address.;; Updated for Lucid Emacs, GNU Emacs 19 and Epoch V4 to use multiple frames; by Bob Weiner, <weiner@mot.com>, 1/20/94. (Still works with Emacs V18, too.); Modified 'server-process-filter' to use \^D as end of request terminator; as gnuclient and gnudoit have been modified to send. This permits; multi-line requests.; Modified 'server-make-window-visible' to work with multiple frames.; Modified 'server-find-file' to display in a separate frame when possible.; Modified 'server-edit' to delete newly created frame when used to; terminate an edit and to signal an error if called within a; non-server-edit buffer.; Bob Weiner, <weiner@mot.com>, 5/9/94.; Added 'server-done-function' variable. Made default value 'kill-buffer'; instead of 'bury-buffer' as in original gnuserv.el.;; Darrell Kindred <dkindred+@cmu.edu> May/1994; Updated to allow multi-line return values:; - output to gnuserv is "m/n:xxx" where m is the client number,; n is the length of the data, and xxx is the data itself, followed ; by newline;; Arup Mukherjee <arup+@cmu.edu> May/1994; Updated for Lucid Emacs 19.10, and others:; - use find-file-other-screen if present; - new variable gnuserv-screen can be set to a frame or screen which is ; is used for all edited files. ; - check to see if server.el is already loaded and complain if it is, since; gnuserv.el can't coexist with server.el; - rename server-start to gnuserv-start, although server-start remains as; an alias. This allows gnuserv-start to be autoloaded from gnuserv.el; - changed server-get-buffer to take into account that in newer emacsen,; get buffer returns nil on deleted buffers.; - only try to create/delete frames or screens if window-system is non-nil ; (otherwise things don't work w/ emacs19 on a dumb terminal);(defconst gnuserv-rcs-header-id "$Header: gnuserv.el,v 2.0 94/08/14 12:36:52 arup Exp $");; server.el and gnuserv.el can't coexist because of conflicting defvar's and;; function names. (if (and (boundp 'server-buffer-clients) (not (featurep 'gnuserv))) (error "can't run gnuserv because server.el appears to be loaded already"))(defvar gnuserv-screen nil "*If non-nil, the screen (lucid emacs) or frame (gnu-emacs 19) to be used to display all edited files. If nil, then a new screen or frameis created for each file edited. This variable has no effect in lucid emacsversions older than 19.9")(defvar server-done-function 'kill-buffer "*Value is a function of one argument, a buffer, which removes the buffer after editing. 'Kill-buffer' and 'bury-buffer' are good values.")(defvar server-program "gnuserv" "*The program to use as the edit server")(defvar server-process nil "the current server process")(defvar server-string "" "the last input string from the server")(defvar current-client nil "the client we are currently talking to")(defvar server-clients nil "List of current server clients.Each element is (CLIENTID BUFFER...) where CLIENTID is an integerthat can be given to the server process to identify a client.When a buffer is killed, it is removed from this list.")(defvar server-buffer-clients nil "List of clientids for clients requesting editing of current buffer.")(make-variable-buffer-local 'server-buffer-clients)(setq-default server-buffer-clients nil)(or (assq 'server-buffer-clients minor-mode-alist) (setq minor-mode-alist (cons '(server-buffer-clients " Server") minor-mode-alist)))(defun server-log (string) "If a *server* buffer exists, write STRING to it for logging purposes." (if (get-buffer "*server*") (save-excursion (set-buffer "*server*") (goto-char (point-max)) (insert string) (or (bolp) (newline)))))(defun server-sentinel (proc msg) (cond ((eq (process-status proc) 'exit) (server-log (message "Server subprocess exited"))) ((eq (process-status proc) 'signal) (server-log (message "Server subprocess killed")))))(defun server-process-display-error (string) "When an error has been reported from the server, display the error in apop-up window." (let ((cur (selected-window)) (pop-up-windows t)) (pop-to-buffer (get-buffer-create "*server*")) (set-window-start (selected-window) (point)) (server-log string) (select-window cur))) (defun server-process-filter (proc string) "Process incoming requests from the server for GNU Emacs to do some actions." (setq server-string (concat server-string string)) (if (string-match "\^D$" server-string) ;requests end with ctrl-D (if (string-match "^[0-9]+" server-string) ;client request id (progn (server-log server-string) (let ((header (read-from-string server-string))) (setq current-client (car header)) (condition-case oops (eval (car (read-from-string server-string (cdr header)))) (error (setq server-string "") (server-write-to-client current-client oops) (setq current-client nil) (signal (car oops) (cdr oops))) (quit (setq server-string "") (server-write-to-client current-client oops) (setq current-client nil) (signal 'quit nil))) (setq server-string ""))) (progn ;error string from server (server-process-display-error server-string) (setq server-string "")))))(defun server-release-outstanding-buffers () "Release all buffers that have clients waiting for them to be finished." (interactive) (while server-clients (let ((buffer (nth 1 (car server-clients)))) ;for all buffers... (server-buffer-done buffer)))) ; destructively modifies server-clients;;;###autoload(defun gnuserv-start (&optional leave-dead) "Allow this Emacs process to be a server for client processes.This starts a server communications subprocess through whichclient \"editors\" (gnuclient and gnudoit) can send editing commands to this Emacs job. See the gnuserv(1) manual page for more details.Prefix arg means just kill any existing server communications subprocess." (interactive "P") ;; kill it dead! (if server-process (progn (server-release-outstanding-buffers) (set-process-sentinel server-process nil) (condition-case () (delete-process server-process) (error nil)))) ;; If we already had a server, clear out associated status. (if leave-dead nil (if server-process (server-log (message "Restarting server"))) (setq server-string "") (setq current-client nil) (let ((process-connection-type t)) (setq server-process (start-process "server" nil server-program))) (set-process-sentinel server-process 'server-sentinel) (set-process-filter server-process 'server-process-filter) (process-kill-without-query server-process)));; make gnuserv-start an alias to server-start, for backward compatibility(fset 'server-start (function gnuserv-start))(defun server-write-to-client (client form) "Write the given form to the given client via the server process." (if (and client (eq (process-status server-process) 'run)) (let* ((result (format "%s" form)) (s (format "%s/%d:%s\n" client (length result) result))) (process-send-string server-process s) (server-log s))))(defun server-eval (form) "Evaluate form and return result to client." (server-write-to-client current-client (eval form)) (setq current-client nil))(defun server-eval-quickly (form) "Let client know that we've received the request, but eval the formafterwards in order to not keep the client waiting." (server-write-to-client current-client nil) (setq current-client nil) (eval form))(defun server-make-window-visible () "Try to make this window even more visible." (and (boundp 'window-system) (boundp 'window-system-version) (eq window-system 'x) (eq window-system-version 11) (cond ((fboundp 'deiconify-screen) (deiconify-screen (selected-screen)) (raise-screen (selected-screen))) ((fboundp 'raise-frame) (raise-frame (selected-frame))) ((fboundp 'mapraised-screen) (mapraised-screen)) ((fboundp 'x-remap-window) (x-remap-window) ;; give window chance to re-display text (accept-process-output)))))(defun server-find-file (file) "Edit file FILENAME.Switch to a buffer visiting file FILENAME,creating one if none already exists." (let ((obuf (get-file-buffer file))) (if (and obuf (set-buffer obuf)) (if (file-exists-p file) (if (or (not (verify-visited-file-modtime obuf)) (buffer-modified-p obuf)) (revert-buffer t nil)) (if (y-or-n-p (concat "File no longer exists: " file ", write buffer to file? ")) (write-file file)))) (cond ((and window-system gnuserv-screen (fboundp 'live-screen-p) ;; lemacs 19.9+ (live-screen-p gnuserv-screen)) (select-screen gnuserv-screen)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -