From dc646358274fbfdab6ef3dfb7717bc4a52f607f3 Mon Sep 17 00:00:00 2001 From: Constantin Kulikov Date: Mon, 24 Dec 2012 18:49:19 +0100 Subject: [PATCH] Allow function as value of initial-buffer-choice (Bug#13251). * 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 | 3 +++ lisp/ChangeLog | 9 +++++++++ lisp/server.el | 17 +++++++++++------ lisp/startup.el | 22 ++++++++++++++-------- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 6d97e9a5772..3c4a76b188e 100644 --- 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. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1438a230550..2181a6dde7e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-12-24 Constantin Kulikov (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 * mail/smtpmail.el (smtpmail-try-auth-method): Refactored out into diff --git a/lisp/server.el b/lisp/server.el index c78e3e376aa..59f75722ccb 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -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 diff --git a/lisp/startup.el b/lisp/startup.el index ec6d45a294d..6a207bab0bf 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -41,9 +41,10 @@ (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 -- 2.39.5