Hey Sacha,
On 2026-05-22 10:49, Sacha Chua wrote:
> Has anyone else noticed that if you are currently narrowed to a
> region and then you use C-u org-refile to jump to a heading that is
> in the same buffer but outside your current narrowing, it doesn't
> move your point because (goto-char ...) with a position outside your
> narrowed region just takes you to either the point-min or point-max?
1+, I’ve noticed this too, mostly when narrowed to a subtree.
> I'm not entirely sure what the correct behaviour should be. Maybe
> it's good that it respects narrowing, maybe people might expect it
> to jump to the un-narrowed part. I want to get it to widen first and
> then jump to the part I want, which necessitates tinkering with the
> innards of org-refile since I don't want to unconditionally widen.
My preference would be to try to preserve it, i.e. if I start narrowed
then we should end up narrowed to the target subtree. For example, if
I start narrowed to ‘A’ or some region/block and jump to ‘B’, I’d like
to to end narrowed to ‘B’:
* A
* B
A more niche preference is that if I’m jumping to a child of the
currently narrowed item, e.g. if I start narrowed to ‘A’ or some
region/block within and jump to ‘1’, I might want to end up narrowed
to ‘A’ instead:
* A
** 1
** 2
* B
> This isn't a formal patch yet, just wanted to sketch things out in
> case other people had thoughts.
Another perspective: I use ‘imenu’ to jump between headings within a
buffer (since it works in a /lot/ of places outside Org). It will
widen if the target is outside the narrowed region:
(if (or (< position (point-min))
(> position (point-max)))
;; Widen if outside narrowing.
(widen))
(goto-char position))
and narrowing after reaching the target can be influenced with
‘imenu-after-jump-hook’, e.g. Org’s default:
(add-hook 'imenu-after-jump-hook
(lambda () (when (derived-mode-p 'org-mode)
(org-fold-show-context 'org-goto))))
Thanks,
--
Jacob S. Gordon
[email protected]
Please don’t send me HTML emails or MS Office/Apple iWork documents.
https://useplaintext.email/#etiquette
https://www.fsf.org/campaigns/opendocument