]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow function as value of initial-buffer-choice (Bug#13251).
authorConstantin Kulikov <zxnotdead@gmail.com>
Mon, 24 Dec 2012 17:49:19 +0000 (18:49 +0100)
committerMartin Rudalics <rudalics@gmx.at>
Mon, 24 Dec 2012 17:49:19 +0000 (18:49 +0100)
* startup.el (initial-buffer-choice): Allow function as value
(Bug#13251).
(command-line-1): Handle case where initial-buffer-choice
specifies a function.
* server.el (server-execute): Handle case where
initial-buffer-choice specifies a function.

etc/NEWS
lisp/ChangeLog
lisp/server.el
lisp/startup.el

index 6d97e9a57725979cdf8ba8730677fc24092b2e58..3c4a76b188e5b5f027389c9b14625c5931af529c 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -39,6 +39,9 @@ if there is one.
 This unfinished feature was introduced by accident in Emacs 23.1;
 simply disabling Transient Mark mode does the same thing.
 
+** `initial-buffer-choice' can now specify a function to set up the
+initial buffer.
+
 ** ACL support has been added.
 +++
 *** Emacs preserves the ACL entries of files when backing up.
index 1438a230550cdc64064fb90daba294cf327cfffc..2181a6dde7e7e935eab7d795d8d96f22f9dea791 100644 (file)
@@ -1,3 +1,12 @@
+2012-12-24  Constantin Kulikov <zxnotdead@gmail.com>  (tiny change)
+
+       * startup.el (initial-buffer-choice): Allow function as value
+       (Bug#13251).
+       (command-line-1): Handle case where initial-buffer-choice
+       specifies a function.
+       * server.el (server-execute): Handle case where
+       initial-buffer-choice specifies a function.
+
 2012-12-24  Lars Ingebrigtsen  <larsi@gnus.org>
 
        * mail/smtpmail.el (smtpmail-try-auth-method): Refactored out into
index c78e3e376aa49ab57312afec68f9c96ed37de6ee..59f75722ccb9425493fb745b508fa5c7a6509a52 100644 (file)
@@ -1256,12 +1256,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
index ec6d45a294df551f901e4bef5530c8d043610a82..6a207bab0bf60e7e6f55b5ab3643b0b938e15a43 100644 (file)
 (defcustom initial-buffer-choice nil
   "Buffer to show after starting Emacs.
 If the value is nil and `inhibit-startup-screen' is nil, show the
-startup screen.  If the value is a string, visit the specified file
-or directory using `find-file'.  If t, open the `*scratch*'
-buffer.
+startup screen.  If the value is a string, switch to a buffer
+visiting the file or directory specified by that string.  If the
+value is a function, switch to the buffer returned by that
+function.  If t, open the `*scratch*' buffer.
 
 A string value also causes emacsclient to open the specified file
 or directory when no target file is specified."
@@ -51,8 +52,9 @@ or directory when no target file is specified."
          (const     :tag "Startup screen" nil)
          (directory :tag "Directory" :value "~/")
          (file      :tag "File" :value "~/.emacs")
+          (function  :tag "Function")
          (const     :tag "Lisp scratch buffer" t))
-  :version "23.1"
+  :version "24.4"
   :group 'initialization)
 
 (defcustom inhibit-startup-screen nil
@@ -2323,10 +2325,14 @@ A fancy display is used on graphic displays, normal otherwise."
             (set-buffer-modified-p nil))))
 
     (when initial-buffer-choice
-      (cond ((eq initial-buffer-choice t)
-            (switch-to-buffer (get-buffer-create "*scratch*")))
-           ((stringp initial-buffer-choice)
-            (find-file initial-buffer-choice))))
+      (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)))
 
     (if (or inhibit-startup-screen
            initial-buffer-choice