* bug#13251: Wishlist: Add ability to set initial buffer for new frames.
@ 2012-12-21 21:16 Constantin Kulikov
2012-12-21 21:30 ` Constantin Kulikov
2012-12-22 15:42 ` martin rudalics
0 siblings, 2 replies; 10+ messages in thread
From: Constantin Kulikov @ 2012-12-21 21:16 UTC (permalink / raw)
To: 13251
[-- Attachment #1: Type: text/plain, Size: 2361 bytes --]
// Discussion in devel.
https://lists.gnu.org/archive/html/emacs-devel/2012-12/msg00521.html
Short:
I want to be able to set buffer that will be displayed in window of newly
created frame.
I need it for my emacs package, that will save and restore some emacs state
including
last window configurations, opened and displayed buffers and such.
I tried this: add hook to `after-make-frame-functions'. Inside this hook I
do
`(switch-to-buffer <some-buffer>)' and frame is switched to that
<some-buffer> at first,
but after a short time it's switched to *scratch*.
The one way I found how to overcome this behaviour is by setting the
`initial-buffer-choice' in the `after-make-frame-functions' hook. One
drawback of this
approach is that it could only be set to name of file, t or nil and so
there is no way to
force switching to buffer without underlying file. This could be fixed int
server.el:1258
replacing
(unless (or files commands)
(if (stringp initial-buffer-choice)
(find-file initial-buffer-choice)
(switch-to-buffer (get-buffer-create "*scratch*")
'norecord)))
to
(unless (or files commands)
(switch-to-buffer
(get-buffer-create
(or (cond
((stringp initial-buffer-choice) (find-file-noselect
initial-buffer-choice))
((functionp initial-buffer-choice) (funcall
initial-buffer-choice)))
"*scratch*"))
'norecord))
and modified defcustom in in startup.el:41 would be:
(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. If function, switch to a buffer returned by this function.
A string value also causes emacsclient to open the specified file
or directory when no target file is specified."
:type '(choice
(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"
:group 'initialization)
This code allows setting `initial-buffer-choice' to a function returning
needed buffer.
[-- Attachment #2: Type: text/html, Size: 3137 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#13251: Wishlist: Add ability to set initial buffer for new frames.
2012-12-21 21:16 bug#13251: Wishlist: Add ability to set initial buffer for new frames Constantin Kulikov
@ 2012-12-21 21:30 ` Constantin Kulikov
2012-12-22 15:42 ` martin rudalics
1 sibling, 0 replies; 10+ messages in thread
From: Constantin Kulikov @ 2012-12-21 21:30 UTC (permalink / raw)
To: 13251
[-- Attachment #1: Type: text/plain, Size: 2938 bytes --]
ah sorry, don't need that `or' in server.el:
(unless (or files commands)
(switch-to-buffer
(get-buffer-create
(cond
((stringp initial-buffer-choice) (find-file-noselect
initial-buffer-choice))
((functionp initial-buffer-choice) (funcall
initial-buffer-choice))
(t "*scratch*")))
'norecord))
2012/12/22 Constantin Kulikov <zxnotdead@gmail.com>
> // Discussion in devel.
> https://lists.gnu.org/archive/html/emacs-devel/2012-12/msg00521.html
> Short:
> I want to be able to set buffer that will be displayed in window of newly
> created frame.
> I need it for my emacs package, that will save and restore some emacs
> state including
> last window configurations, opened and displayed buffers and such.
> I tried this: add hook to `after-make-frame-functions'. Inside this hook I
> do
> `(switch-to-buffer <some-buffer>)' and frame is switched to that
> <some-buffer> at first,
> but after a short time it's switched to *scratch*.
>
> The one way I found how to overcome this behaviour is by setting the
> `initial-buffer-choice' in the `after-make-frame-functions' hook. One
> drawback of this
> approach is that it could only be set to name of file, t or nil and so
> there is no way to
> force switching to buffer without underlying file. This could be fixed int
> server.el:1258
> replacing
>
> (unless (or files commands)
> (if (stringp initial-buffer-choice)
> (find-file initial-buffer-choice)
> (switch-to-buffer (get-buffer-create "*scratch*")
> 'norecord)))
>
> to
> (unless (or files commands)
> (switch-to-buffer
> (get-buffer-create
> (or (cond
> ((stringp initial-buffer-choice) (find-file-noselect
> initial-buffer-choice))
> ((functionp initial-buffer-choice) (funcall
> initial-buffer-choice)))
> "*scratch*"))
> 'norecord))
>
> and modified defcustom in in startup.el:41 would be:
>
> (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. If function, switch to a buffer returned by this function.
>
> A string value also causes emacsclient to open the specified file
> or directory when no target file is specified."
> :type '(choice
> (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"
> :group 'initialization)
>
> This code allows setting `initial-buffer-choice' to a function returning
> needed buffer.
>
>
[-- Attachment #2: Type: text/html, Size: 4068 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#13251: Wishlist: Add ability to set initial buffer for new frames.
2012-12-21 21:16 bug#13251: Wishlist: Add ability to set initial buffer for new frames Constantin Kulikov
2012-12-21 21:30 ` Constantin Kulikov
@ 2012-12-22 15:42 ` martin rudalics
2012-12-22 19:51 ` Constantin Kulikov
1 sibling, 1 reply; 10+ messages in thread
From: martin rudalics @ 2012-12-22 15:42 UTC (permalink / raw)
To: Constantin Kulikov; +Cc: 13251
> (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. If function, switch to a buffer returned by this function.
As for the last sentence I'd prefer "If it is a function, switch to the
buffer returned by that function."
> A string value also causes emacsclient to open the specified file
> or directory when no target file is specified."
> :type '(choice
> (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"
Too late for "23.1" use "24.4" instead.
> :group 'initialization)
>
> This code allows setting `initial-buffer-choice' to a function returning
> needed buffer.
Could you please send us a patch based on these remarks (including the
change you sketched in your second mail)?
Thanks, martin
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#13251: Wishlist: Add ability to set initial buffer for new frames.
2012-12-22 15:42 ` martin rudalics
@ 2012-12-22 19:51 ` Constantin Kulikov
2012-12-22 20:18 ` Constantin Kulikov
2012-12-23 10:14 ` martin rudalics
0 siblings, 2 replies; 10+ messages in thread
From: Constantin Kulikov @ 2012-12-22 19:51 UTC (permalink / raw)
To: martin rudalics; +Cc: 13251
[-- Attachment #1.1: Type: text/plain, Size: 1269 bytes --]
Thanks for the tips.
2012/12/22 martin rudalics <rudalics@gmx.at>
> > (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. If function, switch to a buffer returned by this function.
>
> As for the last sentence I'd prefer "If it is a function, switch to the
> buffer returned by that function."
>
> > A string value also causes emacsclient to open the specified file
> > or directory when no target file is specified."
> > :type '(choice
> > (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"
>
> Too late for "23.1" use "24.4" instead.
>
> > :group 'initialization)
> >
> > This code allows setting `initial-buffer-choice' to a function returning
> > needed buffer.
>
> Could you please send us a patch based on these remarks (including the
> change you sketched in your second mail)?
>
> Thanks, martin
>
[-- Attachment #1.2: Type: text/html, Size: 1913 bytes --]
[-- Attachment #2: initial-buffer-choice-as-function.patch --]
[-- Type: application/octet-stream, Size: 1918 bytes --]
=== modified file 'lisp/server.el'
--- lisp/server.el 2012-11-09 06:28:27 +0000
+++ lisp/server.el 2012-12-22 19:36:57 +0000
@@ -1256,12 +1256,18 @@
(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)
+ (switch-to-buffer
+ (get-buffer-create
+ (cond
+ ((stringp initial-buffer-choice)
+ (find-file-noselect initial-buffer-choice))
+ ((functionp initial-buffer-choice)
+ (funcall initial-buffer-choice))
+ (t "*scratch*")))
+ 'norecord))
;; Delete the client if necessary.
(cond
=== modified file 'lisp/startup.el'
--- lisp/startup.el 2012-12-01 02:08:30 +0000
+++ lisp/startup.el 2012-12-22 19:35:08 +0000
@@ -43,7 +43,7 @@
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.
+buffer. If function, witch to a buffer returned by this function.
A string value also causes emacsclient to open the specified file
or directory when no target file is specified."
@@ -51,8 +51,9 @@
(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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#13251: Wishlist: Add ability to set initial buffer for new frames.
2012-12-22 19:51 ` Constantin Kulikov
@ 2012-12-22 20:18 ` Constantin Kulikov
2012-12-23 10:14 ` martin rudalics
1 sibling, 0 replies; 10+ messages in thread
From: Constantin Kulikov @ 2012-12-22 20:18 UTC (permalink / raw)
To: martin rudalics; +Cc: 13251
[-- Attachment #1.1: Type: text/plain, Size: 1441 bytes --]
argh. :( Sorry made a small typo in patch attached in previous message.
2012/12/22 Constantin Kulikov <zxnotdead@gmail.com>
> Thanks for the tips.
>
>
>
> 2012/12/22 martin rudalics <rudalics@gmx.at>
>
>> > (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. If function, switch to a buffer returned by this function.
>>
>> As for the last sentence I'd prefer "If it is a function, switch to the
>> buffer returned by that function."
>>
>> > A string value also causes emacsclient to open the specified file
>> > or directory when no target file is specified."
>> > :type '(choice
>> > (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"
>>
>> Too late for "23.1" use "24.4" instead.
>>
>> > :group 'initialization)
>> >
>> > This code allows setting `initial-buffer-choice' to a function returning
>> > needed buffer.
>>
>> Could you please send us a patch based on these remarks (including the
>> change you sketched in your second mail)?
>>
>> Thanks, martin
>>
>
>
[-- Attachment #1.2: Type: text/html, Size: 2408 bytes --]
[-- Attachment #2: initial-buffer-choice-as-function.patch --]
[-- Type: application/octet-stream, Size: 1919 bytes --]
=== modified file 'lisp/server.el'
--- lisp/server.el 2012-11-09 06:28:27 +0000
+++ lisp/server.el 2012-12-22 19:36:57 +0000
@@ -1256,12 +1256,18 @@
(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)
+ (switch-to-buffer
+ (get-buffer-create
+ (cond
+ ((stringp initial-buffer-choice)
+ (find-file-noselect initial-buffer-choice))
+ ((functionp initial-buffer-choice)
+ (funcall initial-buffer-choice))
+ (t "*scratch*")))
+ 'norecord))
;; Delete the client if necessary.
(cond
=== modified file 'lisp/startup.el'
--- lisp/startup.el 2012-12-01 02:08:30 +0000
+++ lisp/startup.el 2012-12-22 20:09:27 +0000
@@ -43,7 +43,7 @@
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.
+buffer. If function, switch to a buffer returned by this function.
A string value also causes emacsclient to open the specified file
or directory when no target file is specified."
@@ -51,8 +51,9 @@
(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
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#13251: Wishlist: Add ability to set initial buffer for new frames.
2012-12-22 19:51 ` Constantin Kulikov
2012-12-22 20:18 ` Constantin Kulikov
@ 2012-12-23 10:14 ` martin rudalics
[not found] ` <CAFkz2yrdFMbXSCknkhQZTmbMsYBWCAO9uOayun6BZT_LJdhrjw@mail.gmail.com>
1 sibling, 1 reply; 10+ messages in thread
From: martin rudalics @ 2012-12-23 10:14 UTC (permalink / raw)
To: Constantin Kulikov; +Cc: 13251
> Thanks for the tips.
Thanks for the patch. Unfortunately, we are not yet done :-(
> === modified file 'lisp/server.el'
> --- lisp/server.el 2012-11-09 06:28:27 +0000
> +++ lisp/server.el 2012-12-22 19:36:57 +0000
> @@ -1256,12 +1256,18 @@
> (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)
Here we have to make sure that we do _not_ switch to *scratch* when
`initial-buffer-choice' is nil but show the initial start screen.
> + (switch-to-buffer
> + (get-buffer-create
> + (cond
> + ((stringp initial-buffer-choice)
> + (find-file-noselect initial-buffer-choice))
> + ((functionp initial-buffer-choice)
> + (funcall initial-buffer-choice))
Let's make sure that both `find-file-noselect' and the function called
via `initial-buffer-choice' really returned a live buffer. So please
add a call to `buffer-live-p' for these cases. Which also means that
Stefan's initial proposal for a let-bound `buf' is the better choice ;-)
(he's usually always right in these things).
> + (t "*scratch*")))
> + 'norecord))
>
> ;; Delete the client if necessary.
> (cond
>
> === modified file 'lisp/startup.el'
> --- lisp/startup.el 2012-12-01 02:08:30 +0000
> +++ lisp/startup.el 2012-12-22 20:09:27 +0000
> @@ -43,7 +43,7 @@
> 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'.
I suppose this is no longer true. Let's say "switch to a buffer
visiting the file or directory specified by the string" instead.
> If t, open the `*scratch*'
> -buffer.
This should come after the function item. Note that we are not overly
precise in the doc-string - any non-nil value of `initial-buffer-choice'
will show *scratch*. But it's better to not tell that in the doc-string
so we have room for future changes - just like the one you proposed.
> +buffer. If function, switch to a buffer returned by this function.
"If the value is a function, switch to the buffer returned by that
function." seems more precise here.
> A string value also causes emacsclient to open the specified file
> or directory when no target file is specified."
> @@ -51,8 +51,9 @@
> (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
And now comes the last problem. The function `command-line-1' (in
startup.el) contains these lines:
(when (eq initial-buffer-choice t)
;; When initial-buffer-choice equals t make sure that *scratch*
;; exists.
(get-buffer-create "*scratch*"))
I'd remove them because we can handle them here:
(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))))
If we allow `initial-buffer-choice' to specify a function, we have to
handle it here in the same way as in server.el.
martin
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2013-01-02 8:03 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-21 21:16 bug#13251: Wishlist: Add ability to set initial buffer for new frames Constantin Kulikov
2012-12-21 21:30 ` Constantin Kulikov
2012-12-22 15:42 ` martin rudalics
2012-12-22 19:51 ` Constantin Kulikov
2012-12-22 20:18 ` Constantin Kulikov
2012-12-23 10:14 ` martin rudalics
[not found] ` <CAFkz2yrdFMbXSCknkhQZTmbMsYBWCAO9uOayun6BZT_LJdhrjw@mail.gmail.com>
2012-12-23 17:04 ` bug#13251: Fwd: " Constantin Kulikov
2012-12-24 18:05 ` martin rudalics
2012-12-24 19:37 ` Constantin Kulikov
2013-01-02 8:03 ` martin rudalics
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.