* Re:
[not found] <CAFkz2yroLhknptDnWyC9B1fbZKEwTCV-T0VttHQiwZoaAW-j6A@mail.gmail.com>
@ 2012-12-20 8:36 ` Константин Куликов
2012-12-20 11:05 ` Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c' martin rudalics
0 siblings, 1 reply; 12+ messages in thread
From: Константин Куликов @ 2012-12-20 8:36 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2929 bytes --]
found how code it more correct:
No need to change anything in startup.el
Code for server.el will be:
(unless (or files commands)
(let ((type (type-of initial-buffer-choice)))
(cond
((eq 'string type) (find-file initial-buffer-choice))
((eq 'buffer type) (switch-to-buffer initial-buffer-choice
'norecord))
(t (switch-to-buffer (get-buffer-create "*scratch*")
'norecord)))))
So, someone who has write access to emacs, maybe add this change to trunk?
(if u see no bugs with this code of course =p)
2012/12/20 Константин Куликов <zxnotdead@gmail.com>
> I discribed my problem here:
> http://comments.gmane.org/gmane.emacs.help/88218 .
> short:
> > when you run 'emacsclient -c' the new frame created and window in that
> frame is switched to
> > *scratch* buffer or file with name that is set in
> `initial-buffer-choice'.
> So, I can set `initial-buffer-choice' in the `after-make-frame-functions'
> to switch to buffer other than *scratch* on frame creation, but can't set
> somehow to buffer without underlying file.
>
> I found place where this behaviour handled(server.el:1258):
>
> ;; 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)))
>
> Changed it to this:
> (unless (or files commands)
> (typecase initial-buffer-choice
> (string (find-file initial-buffer-choice))
> (buffer (switch-to-buffer initial-buffer-choice 'norecord))
> (t (switch-to-buffer (get-buffer-create "*scratch*")
> 'norecord)))
>
> then emacsclient -c it create frame and after short time destroys it with
> error:
> "*ERROR*: Wrong type argument: stringp, #<buffer *scratch*>"
>
> ok. I grepped sources, find startup.el:2325 :
> (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))))
>
> replaced it to:
> (when initial-buffer-choice
> (typecase initial-buffer-choice
> (symbol (when (eq initial-buffer-choice t)
> (switch-to-buffer (get-buffer-create "*scratch*"))))
> (string (find-file initial-buffer-choice))
> (buffer (switch-to-buffer initial-buffer-choice))))
>
> But still get same error:
> "*ERROR*: Wrong type argument: stringp, #<buffer *scratch*>"
>
> Any suggestions?
>
>
[-- Attachment #2: Type: text/html, Size: 4048 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
2012-12-20 8:36 ` Константин Куликов
@ 2012-12-20 11:05 ` martin rudalics
2012-12-20 12:13 ` Константин Куликов
[not found] ` <CAFkz2ypcP-fmRH7jJWdhYRaRVB-VEtn0=5qWYQ_S+QCTmZ=TRQ@mail.gmail.com>
0 siblings, 2 replies; 12+ messages in thread
From: martin rudalics @ 2012-12-20 11:05 UTC (permalink / raw)
To: Константин Куликов
Cc: emacs-devel
> found how code it more correct:
> No need to change anything in startup.el
> Code for server.el will be:
>
> (unless (or files commands)
> (let ((type (type-of initial-buffer-choice)))
> (cond
> ((eq 'string type) (find-file initial-buffer-choice))
> ((eq 'buffer type) (switch-to-buffer initial-buffer-choice
> 'norecord))
> (t (switch-to-buffer (get-buffer-create "*scratch*")
> 'norecord)))))
>
> So, someone who has write access to emacs, maybe add this change to trunk?
> (if u see no bugs with this code of course =p)
We probably should verify that the buffer is live and add an appropriate
customization type for `initial-buffer-choice'.
In any case, please file a bug report for this, preferably marked as a
wishlist item. And, as further motivation, tell which buffer you want
to show here in practice. This is far from obvious since initially we
usually have only two non-file-visiting buffers - *Messages* and
*scratch*.
Just received this:
> hint: For example it's could be needed if you want to restore to last
> opened buffer on new frame(and it could be buffer like *ielm* or
> *ansi-term*, etc).
Where do you get this from if you have `initial-buffer-choice' set to
such a buffer and that buffer does not exist? It doesn't sound like a
good idea, in particular so, because `switch-to-buffer' leaves it to
`set-window-buffer' to bark about displaying a deleted buffer.
Thanks, martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
2012-12-20 11:05 ` Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c' martin rudalics
@ 2012-12-20 12:13 ` Константин Куликов
[not found] ` <CAFkz2ypcP-fmRH7jJWdhYRaRVB-VEtn0=5qWYQ_S+QCTmZ=TRQ@mail.gmail.com>
1 sibling, 0 replies; 12+ messages in thread
From: Константин Куликов @ 2012-12-20 12:13 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1509 bytes --]
//sorry, for send you double ;p
>We probably should verify that the buffer is live
yes, it's reasonable
>file a bug report for this
only after discussion on this mail-list :)
>which buffer you want to show here in practice
it's could be just *any* buffer
>set to such a buffer and that buffer does not exist?
then, I think that we could fall back to *scratch*
>add an appropriate customization type for `initial-buffer-choice'
I don't think that it's will be useful for users to customise, but who
knows...
>It doesn't sound like a good idea, in particular so
Here the scenario:
I want new frames to switch to some buffer so I added hook to
`after-make-frame-functions'.
Inside this hook I do `(switch-to-buffer <some-buffer>)' the window on this
frame is switched to that <some-buffer> at first, but after a short time
it's
switched to *scratch*. So as I think it would be better that
`after-make-frame-functions' will be called after this 'default switching to
*scratch* behaviour' is performed. And than will be no need for me to
add code to server.el.
// New version:
(unless (or files commands)
(let ((type (type-of initial-buffer-choice))
(buf "*scratch*"))
(cond
((eq 'string type) (setq buf (find-file-noselect
initial-buffer-choice)))
((eq 'buffer type) (when (buffer-live-p
initial-buffer-choice)
(setq buf initial-buffer-choice))))
(switch-to-buffer (get-buffer-create buf) 'norecord)))
[-- Attachment #2: Type: text/html, Size: 2299 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
[parent not found: <CAFkz2ypcP-fmRH7jJWdhYRaRVB-VEtn0=5qWYQ_S+QCTmZ=TRQ@mail.gmail.com>]
* Re: Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
[not found] ` <CAFkz2ypcP-fmRH7jJWdhYRaRVB-VEtn0=5qWYQ_S+QCTmZ=TRQ@mail.gmail.com>
@ 2012-12-20 13:52 ` martin rudalics
2012-12-20 14:46 ` Thien-Thi Nguyen
0 siblings, 1 reply; 12+ messages in thread
From: martin rudalics @ 2012-12-20 13:52 UTC (permalink / raw)
To: Константин Куликов
Cc: help-gnu-emacs
>> add an appropriate customization type for `initial-buffer-choice'
> I don't think that it's will be useful for users to customise, but who
> knows...
`initial-buffer-choice' _is_ an option specified via `defcustom' in
startup.el. We cannot implicitly ignore this fact in `command-line-1'.
But we could, for example, allow a function here and you could specify a
function to provide the buffer of your choice here.
> Here the scenario:
> I want new frames to switch to some buffer so I added hook to
> `after-make-frame-functions'.
> Inside this hook I do `(switch-to-buffer <some-buffer>)' the window on this
> frame is switched to that <some-buffer> at first, but after a short time
> it's
> switched to *scratch*. So as I think it would be better that
> `after-make-frame-functions' will be called after this 'default switching to
> *scratch* behaviour' is performed.
I'm afraid that this would mean a quite intrusive change to the sequence
of operations performed by the startup code. Are there any reasons why
you can't use `emacs-startup-hook' or `term-setup-hook' instead?
> And than will be no need for me to
> add code to server.el.
> // New version:
> (unless (or files commands)
> (let ((type (type-of initial-buffer-choice))
> (buf "*scratch*"))
> (cond
> ((eq 'string type) (setq buf (find-file-noselect
> initial-buffer-choice)))
> ((eq 'buffer type) (when (buffer-live-p
> initial-buffer-choice)
> (setq buf initial-buffer-choice))))
> (switch-to-buffer (get-buffer-create buf) 'norecord)))
Looks good to me.
martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
2012-12-20 13:52 ` martin rudalics
@ 2012-12-20 14:46 ` Thien-Thi Nguyen
2012-12-20 17:06 ` Stefan Monnier
0 siblings, 1 reply; 12+ messages in thread
From: Thien-Thi Nguyen @ 2012-12-20 14:46 UTC (permalink / raw)
To: martin rudalics; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 966 bytes --]
() martin rudalics <rudalics@gmx.at>
() Thu, 20 Dec 2012 14:52:31 +0100
> (unless (or files commands)
> (let ((type (type-of initial-buffer-choice))
> (buf "*scratch*"))
> (cond
> ((eq 'string type) (setq buf (find-file-noselect initial-buffer-choice)))
> ((eq 'buffer type) (when (buffer-live-p initial-buffer-choice)
> (setq buf initial-buffer-choice))))
> (switch-to-buffer (get-buffer-create buf) 'norecord)))
Looks good to me.
It would be better w/o local vars and ‘setq’, though.
--
Thien-Thi Nguyen ..................................... GPG key: 4C807502
. NB: ttn at glug dot org is not me .
. (and has not been since 2007 or so) .
. ACCEPT NO SUBSTITUTES .
........... please send technical questions to mailing lists ...........
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
2012-12-20 14:46 ` Thien-Thi Nguyen
@ 2012-12-20 17:06 ` Stefan Monnier
2012-12-21 13:10 ` Thien-Thi Nguyen
0 siblings, 1 reply; 12+ messages in thread
From: Stefan Monnier @ 2012-12-20 17:06 UTC (permalink / raw)
To: help-gnu-emacs
> (unless (or files commands)
> (let ((type (type-of initial-buffer-choice))
> (buf "*scratch*"))
> (cond
> ((eq 'string type) (setq buf (find-file-noselect initial-buffer-choice)))
> ((eq 'buffer type) (when (buffer-live-p initial-buffer-choice)
> (setq buf initial-buffer-choice))))
> (switch-to-buffer (get-buffer-create buf) 'norecord)))
> It would be better w/o local vars and ‘setq’, though.
You mean like
(unless (or files commands)
(let ((buf
(cond
((stringp initial-buffer-choice)
(find-file-noselect initial-buffer-choice))
((buffer-live-p initial-buffer-choice) initial-buffer-choice)
(t "*scratch*"))))
(switch-to-buffer (get-buffer-create buf) 'norecord)))
-- Stefan
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
2012-12-20 17:06 ` Stefan Monnier
@ 2012-12-21 13:10 ` Thien-Thi Nguyen
2012-12-21 15:43 ` Constantin Kulikov
2012-12-22 17:46 ` Stefan Monnier
0 siblings, 2 replies; 12+ messages in thread
From: Thien-Thi Nguyen @ 2012-12-21 13:10 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1773 bytes --]
() Stefan Monnier <monnier@iro.umontreal.ca>
() Thu, 20 Dec 2012 12:06:54 -0500
You mean like
(unless (or files commands)
(let ((buf
(cond
((stringp initial-buffer-choice)
(find-file-noselect initial-buffer-choice))
((buffer-live-p initial-buffer-choice) initial-buffer-choice)
(t "*scratch*"))))
(switch-to-buffer (get-buffer-create buf) 'norecord)))
Almost. To rid ourselves of the last local var:
(unless (or files commands)
(switch-to-buffer
(get-buffer-create
(cond ((stringp initial-buffer-choice)
(find-file-noselect initial-buffer-choice))
((buffer-live-p initial-buffer-choice)
initial-buffer-choice)
(t "*scratch*")))
'norecord))
or (hewing closer to OP approach):
(unless (or files commands)
(switch-to-buffer
(get-buffer-create
(or (case (type-of initial-buffer-choice)
(string (find-file-noselect initial-buffer-choice))
(buffer (when (buffer-live-p initial-buffer-choice)
initial-buffer-choice)))
"*scratch*"))
'norecord))
Same difference; more stack, less state... Since we're talking style,
i'd say the most important thing is sane indentation, but luckily we
have Emacs for that. :-D
--
Thien-Thi Nguyen ..................................... GPG key: 4C807502
. NB: ttn at glug dot org is not me .
. (and has not been since 2007 or so) .
. ACCEPT NO SUBSTITUTES .
........... please send technical questions to mailing lists ...........
[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
@ 2012-12-20 9:59 martin rudalics
0 siblings, 0 replies; 12+ messages in thread
From: martin rudalics @ 2012-12-20 9:59 UTC (permalink / raw)
To: zxnotdead; +Cc: help-gnu-emacs
> Heh, found, that it I can set `initial-buffer-choice' to some
> file-name and it will be opened instead of switching to *scratch*.
> But can't specify buffer without underlying file though.
I wonder which buffer you want to display here if it doesn't correspond
to a file.
martin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c'
@ 2012-12-19 13:14 Константин Куликов
2012-12-20 0:43 ` Константин Куликов
0 siblings, 1 reply; 12+ messages in thread
From: Константин Куликов @ 2012-12-19 13:14 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 458 bytes --]
If you run command emacsclient -c the new frame will be created and then
selected window(that have cursor and input focus) of this frame is switched
to display *scratch* buffer.
I added hook to `after-make-frame-functions', that already perform
switching to another buffer that I need, but it's then switched to
*scratch*.
Can I somehow override this behaviour, by disabling switching to *scratch*
buffer in new frame, that was created by 'emacsclient -c' ?
[-- Attachment #2: Type: text/html, Size: 545 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2012-12-22 17:46 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <CAFkz2yroLhknptDnWyC9B1fbZKEwTCV-T0VttHQiwZoaAW-j6A@mail.gmail.com>
2012-12-20 8:36 ` Константин Куликов
2012-12-20 11:05 ` Overriding switch to *scratch* buffer after creating new frame with 'emacsclient -c' martin rudalics
2012-12-20 12:13 ` Константин Куликов
[not found] ` <CAFkz2ypcP-fmRH7jJWdhYRaRVB-VEtn0=5qWYQ_S+QCTmZ=TRQ@mail.gmail.com>
2012-12-20 13:52 ` martin rudalics
2012-12-20 14:46 ` Thien-Thi Nguyen
2012-12-20 17:06 ` Stefan Monnier
2012-12-21 13:10 ` Thien-Thi Nguyen
2012-12-21 15:43 ` Constantin Kulikov
2012-12-22 17:46 ` Stefan Monnier
2012-12-20 9:59 martin rudalics
-- strict thread matches above, loose matches on Subject: below --
2012-12-19 13:14 Константин Куликов
2012-12-20 0:43 ` Константин Куликов
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.