Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[bpt/emacs.git] / lisp / server.el
index 4a87157..03d4bfc 100644 (file)
@@ -1257,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