(U-00024182): Apply new conventions for glyph granularity.
[chise/xemacs-chise.git.1] / lisp / gnuserv.el
index 04bf42a..206ef24 100644 (file)
@@ -1,7 +1,7 @@
 ;;; gnuserv.el --- Lisp interface code between Emacs and gnuserv
 ;; Copyright (C) 1989-1997 Free Software Foundation, Inc.
 
-;; Version: 3.11
+;; Version: 3.12
 ;; Author: Andy Norman (ange@hplb.hpl.hp.com), originally based on server.el
 ;;         Hrvoje Niksic <hniksic@xemacs.org>
 ;; Maintainer: Jan Vroonhof <vroonhof@math.ethz.ch>,
   :group 'processes
   :group 'terminals)
 
+;;;###autoload
+(defcustom gnuserv-mode-line-string " Server"
+  "*String to display in the modeline when Gnuserv is active.
+Set this to nil if you don't want a modeline indicator."
+:type '(choice string
+                (const :tag "none" nil))
+:group 'gnuserv)
+
 
 ;; Provide the old variables as aliases, to avoid breaking .emacs
 ;; files.  However, they are obsolete and should be converted to the
@@ -261,9 +269,10 @@ Each element is a gnuclient structure that identifies a client.")
 ;; We want the client-infested buffers to have some modeline
 ;; identification, so we'll make a "minor mode".
 (defvar gnuserv-minor-mode nil)
-(make-variable-buffer-local 'gnuserv-mode)
-(pushnew '(gnuserv-minor-mode " Server") minor-mode-alist
-         :test 'equal)
+(make-variable-buffer-local 'gnuserv-minor-mode)
+;;(pushnew '(gnuserv-minor-mode "Server") minor-mode-alist
+;;      :test 'equal)
+(add-minor-mode 'gnuserv-minor-mode 'gnuserv-mode-line-string)
 
 \f
 ;; Sample gnuserv-frame functions
@@ -271,6 +280,7 @@ Each element is a gnuclient structure that identifies a client.")
 (defun gnuserv-main-frame-function (type)
   "Return a sensible value for the main Emacs frame."
   (if (or (eq type 'x)
+         (eq type 'gtk)
          (eq type 'mswindows))
       (car (frame-list))
     nil))
@@ -280,6 +290,7 @@ Each element is a gnuclient structure that identifies a client.")
 This is meant in the X sense, so it will not return frames that are on another
 visual screen.  Totally visible frames are preferred.  If none found, return nil."
   (if (or (eq type 'x)
+         (eq type 'gtk)
          (eq type 'mswindows))
       (cond ((car (filtered-frame-list 'frame-totally-visible-p
                                       (selected-device))))
@@ -337,8 +348,8 @@ visual screen.  Totally visible frames are preferred.  If none found, return nil
   "Process gnuserv client requests to execute Emacs commands."
   (setq gnuserv-string (concat gnuserv-string string))
   ;; C-d means end of request.
-  (when (string-match "\C-d\\'" gnuserv-string)
-    (cond ((string-match "^[0-9]+" gnuserv-string) ; client request id
+  (when (string-match "\C-d\n?\\'" gnuserv-string)
+    (cond ((string-match "\\`[0-9]+" gnuserv-string) ; client request id
           (let ((header (read-from-string gnuserv-string)))
             ;; Set the client we are talking to.
             (setq gnuserv-current-client (car header))
@@ -359,8 +370,9 @@ visual screen.  Totally visible frames are preferred.  If none found, return nil
                     (signal 'quit nil)))
             (setq gnuserv-string "")))
          (t
-          (error "%s: invalid response from gnuserv" gnuserv-string)
-          (setq gnuserv-string "")))))
+          (let ((response (car (split-string gnuserv-string "\C-d"))))
+            (setq gnuserv-string "")
+            (error "%s: invalid response from gnuserv" response))))))
 
 ;; This function is somewhat of a misnomer.  Actually, we write to the
 ;; server (using `process-send-string' to gnuserv-process), which
@@ -396,6 +408,13 @@ This order is important as not to keep the client waiting."
   (eval form))
 
 \f
+
+(defun make-x-device-with-gtk-fallback (device)
+  (or (condition-case ()
+          (make-x-device device)
+        (error nil))
+      (make-gtk-device)))
+
 ;; "Execute" a client connection, called by gnuclient.  This is the
 ;; backbone of gnuserv.el.
 (defun gnuserv-edit-files (type list &rest flags)
@@ -427,7 +446,8 @@ If a flag is `view', view the files read-only."
                         ((null dest-frame)
                          (case (car type)
                            (tty (apply 'make-tty-device (cdr type)))
-                           (x   (make-x-device (cadr type)))
+                           (gtk (make-gtk-device))
+                           (x   (make-x-device-with-gtk-fallback (cadr type)))
                            (mswindows   (make-mswindows-device))
                            (t   (error "Invalid device type"))))
                         (t