* question about buffer mechanism
@ 2018-08-19 19:04 akrl
2018-08-19 20:34 ` Stefan Monnier
[not found] ` <mailman.5302.1534710880.1292.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: akrl @ 2018-08-19 19:04 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
The question is the following:
Say I have this function:
(defun my-open-at-point (&rest _)
(interactive)
(org-open-at-point)
(print (current-buffer)))
When I call it on an org link the link at point is opened and when
my-open-at-point has finished the current buffer is the one pointed by
the link.
What I cannot understand is why the buffer that is printed is still the
original one containing the link.
I would expect to see already there the buffer changed to the new one.
I miss also where and how is then set the new buffer.
I'm probably missing something really basic here.
Bests
Andrea
--
akrl@sdf.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about buffer mechanism
2018-08-19 19:04 question about buffer mechanism akrl
@ 2018-08-19 20:34 ` Stefan Monnier
[not found] ` <mailman.5302.1534710880.1292.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2018-08-19 20:34 UTC (permalink / raw)
To: help-gnu-emacs
> When I call it on an org link the link at point is opened and when
> my-open-at-point has finished the current buffer is the one pointed by
> the link.
Not sure what you mean by "the current buffer" above, but I suspect you
mean "the buffer that I visually see as being the current one"
(i.e. that corresponds to the buffer of the window that was selected at
the time the display is refreshed).
This is not the definition of `current-buffer`, although the two are
tightly linked in practice by the fact that `current-buffer` is set to
the buffer of the window that is selected at the time a user causes
a command to be run.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about buffer mechanism
[not found] ` <mailman.5302.1534710880.1292.help-gnu-emacs@gnu.org>
@ 2018-08-19 22:04 ` akrl
2018-08-19 22:55 ` Stefan Monnier
[not found] ` <mailman.5308.1534719353.1292.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 5+ messages in thread
From: akrl @ 2018-08-19 22:04 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> When I call it on an org link the link at point is opened and when
>> my-open-at-point has finished the current buffer is the one pointed by
>> the link.
>
> Not sure what you mean by "the current buffer" above, but I suspect you
> mean "the buffer that I visually see as being the current one"
> (i.e. that corresponds to the buffer of the window that was selected at
> the time the display is refreshed).
>
> This is not the definition of `current-buffer`, although the two are
> tightly linked in practice by the fact that `current-buffer` is set to
> the buffer of the window that is selected at the time a user causes
> a command to be run.
>
>
> Stefan
>
Hi Stefan,
for current buffer I mean the "current buffer" as indicated by the manual
(assuming my understanding of it is correct).
I'll try to be more clear about my problem.
If I have:
(defun my-open-at-point (&rest _)
(interactive)
(org-open-at-point)
(insert "foo"))
When I call it with point on an org link on buffer "A" I obtain two effects:
1- after the execution the cursor is at the right position in the buffer
"B" (the one containing the file targeted by the link)
2- "foo" is inserted in the buffer "A" (the one containing the link)
I would really expect "foo" being inserted in the buffer "B" instead but
this is not the case.
When insert is executed the current buffer seams to be "A" but when
my-open-at-point has finished seams to be "B".
Where the current buffer after my-open-at-point has returned is changed?
I suspect I'm really missing something basic.
Thanks!
Andrea
--
akrl@sdf.org
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about buffer mechanism
2018-08-19 22:04 ` akrl
@ 2018-08-19 22:55 ` Stefan Monnier
[not found] ` <mailman.5308.1534719353.1292.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2018-08-19 22:55 UTC (permalink / raw)
To: help-gnu-emacs
> I suspect I'm really missing something basic.
The "current buffer" can be *any* buffer; it's a global variable that
refers to one of the buffers and that variable can be changed with
`set-buffer`. Despite appearances, it is not directly related to which
buffer is displayed on screen.
org-open-at-point changes the buffer displayed on screen, but it happens
to do so while preserving the "current buffer", so when the function
returns, the current buffer is still the buffer in which you found the
link rather than the new buffer that is now displayed in its place.
As soon as the current *command* ends, the current buffer will be re-set
by the command loop to point to the buffer of the currently selected
window, i.e. the buffer which the user thinks of as "current" (in this
case, the new buffer containing the target of the link).
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: question about buffer mechanism
[not found] ` <mailman.5308.1534719353.1292.help-gnu-emacs@gnu.org>
@ 2018-08-23 8:49 ` akrl
0 siblings, 0 replies; 5+ messages in thread
From: akrl @ 2018-08-23 8:49 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> The "current buffer" can be *any* buffer; it's a global variable that
> refers to one of the buffers and that variable can be changed with
> `set-buffer`. Despite appearances, it is not directly related to which
> buffer is displayed on screen.
>
> org-open-at-point changes the buffer displayed on screen, but it happens
> to do so while preserving the "current buffer", so when the function
> returns, the current buffer is still the buffer in which you found the
> link rather than the new buffer that is now displayed in its place.
>
> As soon as the current *command* ends, the current buffer will be re-set
> by the command loop to point to the buffer of the currently selected
> window, i.e. the buffer which the user thinks of as "current" (in this
> case, the new buffer containing the target of the link).
>
>
> Stefan
Hi Stefan,
thanks this really helped me to understand how it works and to solve my
problem.
Bests
Andrea
--
akrl@sdf.org
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-08-23 8:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-19 19:04 question about buffer mechanism akrl
2018-08-19 20:34 ` Stefan Monnier
[not found] ` <mailman.5302.1534710880.1292.help-gnu-emacs@gnu.org>
2018-08-19 22:04 ` akrl
2018-08-19 22:55 ` Stefan Monnier
[not found] ` <mailman.5308.1534719353.1292.help-gnu-emacs@gnu.org>
2018-08-23 8:49 ` akrl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).