]> code.delx.au - gnu-emacs/blobdiff - lisp/server.el
Cleanup namespace of dos-w32.el.
[gnu-emacs] / lisp / server.el
index 7a356a90378e7d60b01a9b52de899570d86da7d2..a76b2d4ce5fdadafc193ba73eadc21b4c57e568f 100644 (file)
@@ -1,6 +1,7 @@
 ;;; server.el --- Lisp code for GNU Emacs running as server process -*- lexical-binding: t -*-
 
-;; Copyright (C) 1986-1987, 1992, 1994-2012  Free Software Foundation, Inc.
+;; Copyright (C) 1986-1987, 1992, 1994-2013 Free Software Foundation,
+;; Inc.
 
 ;; Author: William Sommerfeld <wesommer@athena.mit.edu>
 ;; Maintainer: FSF
@@ -153,7 +154,7 @@ long-lived shared key will decrease security (especially since
 the key is transmitted as plain-text).
 
 In some situations however, it can be difficult to share randomly
-generated passwords with remote hosts (eg. no shared directory),
+generated passwords with remote hosts (e.g., no shared directory),
 so you can set the key with this variable and then copy the
 server file to the remote host (with possible changes to IP
 address and/or port if that applies).
@@ -360,7 +361,7 @@ Updates `server-clients'."
 
 (defconst server-buffer " *server*"
   "Buffer used internally by Emacs's server.
-One use is to log the I/O for debugging purposes (see `server-log'),
+One use is to log the I/O for debugging purposes (see option `server-log'),
 the other is to provide a current buffer in which the process filter can
 safely let-bind buffer-local variables like `default-directory'.")
 
@@ -368,7 +369,7 @@ safely let-bind buffer-local variables like `default-directory'.")
   "If non-nil, log the server's inputs and outputs in the `server-buffer'.")
 
 (defun server-log (string &optional client)
-  "If `server-log' is non-nil, log STRING to `server-buffer'.
+  "If option `server-log' is non-nil, log STRING to `server-buffer'.
 If CLIENT is non-nil, add a description of it to the logged message."
   (when server-log
     (with-current-buffer (get-buffer-create server-buffer)
@@ -842,6 +843,15 @@ This handles splitting the command if it would be bigger than
     (unless (assq w window-system-initialization-alist)
       (setq w nil))
 
+    ;; Special case for ns.  This is because DISPLAY may not be set at all
+    ;; which in the ns case isn't an error.  The variable display then becomes
+    ;; the fully qualified hostname, which make-frame-on-display below
+    ;; does not understand and throws an error.
+    ;; It may also be a valid X display, but if Emacs is compiled for ns, it
+    ;; can not make X frames.
+    (if (featurep 'ns-win)
+       (setq w 'ns display "ns"))
+
     (cond (w
            ;; Flag frame as client-created, but use a dummy client.
            ;; This will prevent the frame from being deleted when
@@ -1247,12 +1257,17 @@ The following commands are accepted by the client:
           (mapc 'funcall (nreverse commands))
 
          ;; If we were told only to open a new client, obey
-         ;; `initial-buffer-choice' if it specifies a file.
-         (unless (or files commands)
-           (if (stringp initial-buffer-choice)
-               (find-file initial-buffer-choice)
-             (switch-to-buffer (get-buffer-create "*scratch*")
-                               'norecord)))
+         ;; `initial-buffer-choice' if it specifies a file
+          ;; or a function.
+          (unless (or files commands)
+            (let ((buf
+                   (cond ((stringp initial-buffer-choice)
+                         (find-file-noselect initial-buffer-choice))
+                        ((functionp initial-buffer-choice)
+                         (funcall initial-buffer-choice)))))
+             (switch-to-buffer
+              (if (buffer-live-p buf) buf (get-buffer-create "*scratch*"))
+              'norecord)))
 
           ;; Delete the client if necessary.
           (cond
@@ -1542,7 +1557,7 @@ be a cons cell (LINENUMBER . COLUMNNUMBER)."
                (setq next-buffer (car (process-get proc 'buffers))))
              (setq rest (cdr rest)))))
        (and next-buffer (server-switch-buffer next-buffer killed-one))
-       (unless (or next-buffer killed-one (window-dedicated-p (selected-window)))
+       (unless (or next-buffer killed-one (window-dedicated-p))
          ;; (switch-to-buffer (other-buffer))
          (message "No server buffers remain to edit")))
     (if (not (buffer-live-p next-buffer))
@@ -1569,16 +1584,16 @@ be a cons cell (LINENUMBER . COLUMNNUMBER)."
                   (unless (frame-live-p server-window)
                     (setq server-window (make-frame)))
                   (select-window (frame-selected-window server-window))))
-           (when (window-minibuffer-p (selected-window))
+           (when (window-minibuffer-p)
              (select-window (next-window nil 'nomini 0)))
            ;; Move to a non-dedicated window, if we have one.
-           (when (window-dedicated-p (selected-window))
+           (when (window-dedicated-p)
              (select-window
               (get-window-with-predicate
                (lambda (w)
                  (and (not (window-dedicated-p w))
                       (equal (frame-terminal (window-frame w))
-                             (frame-terminal (selected-frame)))))
+                             (frame-terminal))))
                'nomini 'visible (selected-window))))
            (condition-case nil
                (switch-to-buffer next-buffer)
@@ -1586,7 +1601,7 @@ be a cons cell (LINENUMBER . COLUMNNUMBER)."
              ;; a minibuffer/dedicated-window (if there's no other).
              (error (pop-to-buffer next-buffer)))))))
     (when server-raise-frame
-      (select-frame-set-input-focus (window-frame (selected-window))))))
+      (select-frame-set-input-focus (window-frame)))))
 
 ;;;###autoload
 (defun server-save-buffers-kill-terminal (arg)
@@ -1596,7 +1611,7 @@ With ARG non-nil, silently save all file-visiting buffers, then kill.
 
 If emacsclient was started with a list of filenames to edit, then
 only these files will be asked to be saved."
-  (let ((proc (frame-parameter (selected-frame) 'client)))
+  (let ((proc (frame-parameter nil 'client)))
     (cond ((eq proc 'nowait)
           ;; Nowait frames have no client buffer list.
           (if (cdr (frame-list))