Ihor Radchenko <[email protected]> writes: >> I managed to fix the behaviour locally by applying the following change to >> org-capture--fill-template: >> >> --- a/lisp/org-capture.el >> +++ b/lisp/org-capture.el >> @@ -1696,7 +1696,7 @@ Expansion occurs in a temporary Org mode buffer." >> (message "no template") (ding) >> (sit-for 1)) >> (save-window-excursion >> - (switch-to-buffer-other-window (get-buffer-create "*Capture*")) >> + (set-buffer (get-buffer-create "*Capture*")) >> (erase-buffer) >> (setq buffer-file-name nil) >> (setq mark-active nil) >> >> This activates the buffer without changing the window layout. >> Does this change/fix seem reasonable? >> >> I suspect that the (save-window-excursion) should probably also be changed >> to a (save-excursion), but was unable to convince myself so far that there >> weren't other window-affecting operations in there. > > AFAIK, `switch-to-buffer-other-window' there is intentional. > In particular, it is useful when the template expansion involves > interactive prompt where we want the user to see the current state of > *Capture* buffer and also the original window where the capture command > was called. > > I think that the best we can do here on Org side is to document this > potential pitfall.
While documenting might be somewhat helpful, the ultimate problem can manifest itself any time some kind of user interaction that involves showing minibuffer (or any other buffer) is requested as a part of expanding the template. I believe that org-roam should simply save the point before calling "fill template" and search from that point. Any interactive function in Emacs may cause point motion. For example, see another, similar, report in https://list.orgmode.org/orgmode/sv0p279mb044207d5ba32189ecb15b4bec6...@sv0p279mb0442.norp279.prod.outlook.com/ -- Ihor Radchenko // yantar92, Org mode maintainer, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>
