Fix `emacsclient -ne '(+ 2 2)'' (reported by Han Boetes), and clean up some corner...
authorKaroly Lorentey <lorentey@elte.hu>
Sat, 10 Sep 2005 23:51:08 +0000 (23:51 +0000)
committerKaroly Lorentey <lorentey@elte.hu>
Sat, 10 Sep 2005 23:51:08 +0000 (23:51 +0000)
* lib-src/emacsclient.c (decode_options): Make --no-wait imply
  --current-frame, except when it is the only option given.  Make sure no
  frame is opened when --current-frame is set.
  (main): Pass --current-frame to server.el.

* lisp/server.el (server-process-filter): Handle -current-frame command.
  Don't create frames when it is given.  Don't bind X frames to the
  client when we are in -no-wait mode.

git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-407

README.multi-tty
lib-src/emacsclient.c
lisp/server.el

index 93fb58b..e6dde3b 100644 (file)
@@ -386,11 +386,6 @@ is probably not very interesting for anyone else.)
 THINGS TO DO
 ------------
 
-** cus-start.el has some suspicious uses of window-system, introduced
-   in patch-404.
-
-** emacsclient --no-wait and --eval is currently broken.
-
 ** xt-mouse.el needs to be adapted for multi-tty.  It currently
    signals an error on kill-emacs under X, which prevents the user
    from exiting Emacs. (Reported by Mnemonikk on freenode.)
index 4908d49..ecd0d18 100644 (file)
@@ -67,6 +67,9 @@ int nowait = 0;
 /* Nonzero means args are expressions to be evaluated.  --eval.  */
 int eval = 0;
 
+/* Nonzero means don't open a new frame.  --current-frame.  */
+int current_frame = 0;
+
 /* Nonzero means open a new graphical frame. */
 int window_system = 0;
 
@@ -112,11 +115,6 @@ decode_options (argc, argv)
   if (display && strlen (display) == 0)
     display = NULL;
 
-  if (display)
-    window_system = 1;
-  else
-    tty = 1;
-
   while (1)
     {
       int opt = getopt_long (argc, argv,
@@ -159,12 +157,10 @@ decode_options (argc, argv)
 
         case 't':
           tty = 1;
-          window_system = 0;
           break;
 
         case 'c':
-          window_system = 0;
-          tty = 0;
+          current_frame = 1;
           break;
 
        case 'H':
@@ -178,10 +174,24 @@ decode_options (argc, argv)
        }
     }
 
-  if (tty) {
-    nowait = 0;
-    display = 0;
-  }
+  if (!tty && display)
+    window_system = 1;
+  else
+    tty = 1;
+
+  /* `emacsclient --no-wait' should open a new permanent frame, then exit.
+     Otherwise, --no-wait always implies --current-frame.  */
+  if (nowait && argc - optind > 0)
+    current_frame = 1;
+
+  if (current_frame)
+    {
+      tty = 0;
+      window_system = 0;
+    }
+
+  if (tty)
+    window_system = 0;
 }
 
 void
@@ -710,6 +720,9 @@ To start the server in Emacs, type \"M-x server-start\".\n",
   if (nowait)
     fprintf (out, "-nowait ");
 
+  if (current_frame)
+    fprintf (out, "-current-frame ");
+  
   if (display)
     {
       fprintf (out, "-display ");
index 0104e27..27596c3 100644 (file)
@@ -481,6 +481,9 @@ The following commands are accepted by the server:
 `-env NAME VALUE'
   An environment variable on the client side.
 
+`-current-frame'
+  Forbid the creation of new frames.
+
 `-nowait'
   Request that the next frame created should not be
   associated with this client.
@@ -560,6 +563,7 @@ The following commands are accepted by the client:
                                    (or file-name-coding-system
                                        default-file-name-coding-system)))
                (client (server-client proc))
+               current-frame
                nowait ; t if emacsclient does not want to wait for us.
                frame ; The frame that was opened for the client (if any).
                display ; Open the frame on this display.
@@ -592,6 +596,9 @@ The following commands are accepted by the client:
                 ;; -nowait:  Emacsclient won't wait for a result.
                 ((equal "-nowait" arg) (setq nowait t))
 
+                ;; -current-frame:  Don't create frames.
+                ((equal "-current-frame" arg) (setq current-frame t))
+
                 ;; -display DISPLAY:
                 ;; Open X frames on the given instead of the default.
                 ((and (equal "-display" arg) (string-match "\\([^ ]*\\) " request))
@@ -602,26 +609,31 @@ The following commands are accepted by the client:
                 ((equal "-window-system" arg)
                  (unless (server-client-get client 'version)
                    (error "Protocol error; make sure to use the correct version of emacsclient"))
-                 (if (fboundp 'x-create-frame)
-                     (progn
-                       (setq frame (make-frame-on-display
-                                    (or display
-                                        (frame-parameter nil 'device)
-                                        (getenv "DISPLAY")
-                                        (error "Please specify display"))
-                                    (list (cons 'client proc))))
-                       ;; XXX We need to ensure the client parameter is
-                       ;; really set because Emacs forgets initialization
-                       ;; parameters for X frames at the moment.
-                       (modify-frame-parameters frame (list (cons 'client proc)))
-                       (select-frame frame)
-                       (server-client-set client 'frame frame)
-                       (server-client-set client 'device (frame-display frame))
-                       (setq dontkill t))
-                   ;; This emacs does not support X.
-                   (server-log "Window system unsupported" proc)
-                   (server-send-string proc "-window-system-unsupported \n")
-                   (setq dontkill t)))
+                 (unless current-frame
+                   (if (fboundp 'x-create-frame)
+                       (let ((params (if nowait
+                                         nil
+                                       (list (cons 'client proc)))))
+                         (setq frame (make-frame-on-display
+                                      (or display
+                                          (frame-parameter nil 'device)
+                                          (getenv "DISPLAY")
+                                          (error "Please specify display"))
+                                      params))
+                         (server-log (format "%s created" frame) proc)
+                         ;; XXX We need to ensure the parameters are
+                         ;; really set because Emacs forgets unhandled
+                         ;; initialization parameters for X frames at
+                         ;; the moment.
+                         (modify-frame-parameters frame params)
+                         (select-frame frame)
+                         (server-client-set client 'frame frame)
+                         (server-client-set client 'device (frame-display frame))
+                         (setq dontkill t))
+                     ;; This emacs does not support X.
+                     (server-log "Window system unsupported" proc)
+                     (server-send-string proc "-window-system-unsupported \n")
+                     (setq dontkill t))))
 
                 ;; -resume:  Resume a suspended tty frame.
                 ((equal "-resume" arg)
@@ -652,23 +664,26 @@ The following commands are accepted by the client:
                    (setq request (substring request (match-end 0)))
                    (unless (server-client-get client 'version)
                      (error "Protocol error; make sure you use the correct version of emacsclient"))
-                   (server-with-client-environment proc
-                       ("LANG" "LC_CTYPE" "LC_ALL"
-                        ;; For tgetent(3); list according to ncurses(3).
-                        "BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES"
-                        "NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING"
-                        "NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO"
-                        "TERMINFO_DIRS" "TERMPATH")
-                     (setq frame (make-frame-on-tty tty type
-                                                    `((client . ,proc)))))
-                   (select-frame frame)
-                   (server-client-set client 'frame frame)
-                   (server-client-set client 'tty (display-name frame))
-                   (server-client-set client 'device (frame-display frame))
-
-                   ;; Reply with our pid.
-                   (server-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n"))
-                   (setq dontkill t)))
+                   (unless current-frame
+                     (server-with-client-environment proc
+                         ("LANG" "LC_CTYPE" "LC_ALL"
+                          ;; For tgetent(3); list according to ncurses(3).
+                          "BAUDRATE" "COLUMNS" "ESCDELAY" "HOME" "LINES"
+                          "NCURSES_ASSUMED_COLORS" "NCURSES_NO_PADDING"
+                          "NCURSES_NO_SETBUF" "TERM" "TERMCAP" "TERMINFO"
+                          "TERMINFO_DIRS" "TERMPATH")
+                       (setq frame (make-frame-on-tty tty type
+                                                      ;; Ignore nowait here; we always need to clean
+                                                      ;; up opened ttys when the client dies.
+                                                      `((client . ,proc)))))
+                     (select-frame frame)
+                     (server-client-set client 'frame frame)
+                     (server-client-set client 'tty (display-name frame))
+                     (server-client-set client 'device (frame-display frame))
+
+                     ;; Reply with our pid.
+                     (server-send-string proc (concat "-emacs-pid " (number-to-string (emacs-pid)) "\n"))
+                     (setq dontkill t))))
 
                 ;; -position LINE:  Go to the given line in the next file.
                 ((and (equal "-position" arg) (string-match "\\(\\+[0-9]+\\) " request))