org-transclusion icon indicating copy to clipboard operation
org-transclusion copied to clipboard

Doom's recenter error

Open arozbiz opened this issue 4 years ago • 18 comments

I can transclude enter files, but nothing smaller than that. For example:

Source.org

#+TITLE: Source

* SourceHeading1

Heading 1 text

* SourceHeading2

Heading 2 text

Destination.org

#+TITLE: Destination

#+transclude: t 
[[file::Source.org]]

#+transclude: t 
[[file:Source.org::*SourceHeading2]]

The first transclusion works, but the second doesn't do anything. But I can click on the *SourceHeading2 link and go to the relevant headline, so the org link itself seems to work.

arozbiz avatar Jan 18 '21 01:01 arozbiz

I cannot reproduce the issue...

"Doesn't do anything" might mean that the program decided that there was nothing to include. Do you see any message if you show messages (C-h e to show the *messages* buffer)?

2021-01-18T124100_Transclusion-issue-51

I also tried the same sequence as you: a link to the whole buffer first, to a heading second; the same result. image

nobiot avatar Jan 18 '21 11:01 nobiot

Problem solved. I need to go to the source heading, run org-store-link and then, in the destination file, run org-insert-last-stored-link. Just typing [[file:Source.org::*SourceHeading2]] didn't work, even though typing [[file:Source.org]]. So whatever the problem is, it's not with org-transclusion.

arozbiz avatar Jan 18 '21 14:01 arozbiz

Very strange. Just typing should also work.

nobiot avatar Jan 18 '21 21:01 nobiot

Re-opening this because I do think there's something going on with Org-transclusion. These two screenshots are before and after enabling org-transclusion-mode. Both files are in the same folder.

One more issue that I just noted: after a failed transclusion entry, no more transclusions will work, even ones that have worked previously. E.g., the last transclusion is the same as the first transclusion, but the last transclusion doesn't work, presumably because transclusions 3 and 4 (the broken ones) are messing something up.

image

image

Here are the relevant contents of the Messages buffer, in case it's helpful:

Clipboard pasted as level 1 subtree [2 times]
progn: ‘recenter’ing a window that does not display current-buffer.
coming into #<window 3 on test2.org>
Error during redisplay: (org-transclusion--toggle-transclusion-when-out-of-focus #<window 3 on test2.org>) signaled (error "‘recenter’ing a window that does not display current-buffer.")
going into minibuffer
Nothing done. No transclusion exists here. [2 times]

arozbiz avatar Jan 24 '21 05:01 arozbiz

Are you using the latest commit of the package? This behaviour sounds to me like an issue fixed some time ago.

after a failed transclusion entry, no more transclusions will work

nobiot avatar Jan 24 '21 08:01 nobiot

Separate to my previous query, do you know what this “recentering” is?

"‘recenter’ing a window that does not display current-buffer.

I have never seen it before. Are you using Doom and have some other package for a sort of window management? I am wondering if this is interfering with transclusion.

nobiot avatar Jan 24 '21 08:01 nobiot

I still cannot reproduce the issue you are experiencing. I have just tried test files as you created them with emacs -q and manually evaluated org-transclusion.el -- so it's truly vanilla removing all the other packages.

The only conclusion I can make out of this is that there is something in your set up that is interfering with transclusion. I suggest to

  • Ensure you are using the latest commit of org-transclusion
  • See if you can reproduce the behaviour with emacs -q, open org-transclusion.el, and M-x eval-buffer; then test files agian

image

image

nobiot avatar Jan 24 '21 08:01 nobiot

Is it correct that you use Doom, and have org enabled with its init file?

I think this part of Doom has a conflict with the way Org-transclusion looks for the header link.

https://github.com/hlissner/doom-emacs/blob/develop/modules/lang/org/config.el#L544-L551

Is it possible for you to remove the advice and see if this is the case? It's probably the advice for org-link-search that is causing the problem you experience.

nobiot avatar Jan 24 '21 10:01 nobiot

I don't know how you can influence this defadvice! macro from Doom, but if you can override what Doom does for you, and add something like this would probably get Org-transclusion to work.

You could also look to remove the advice, and should also work.

(defadvice! +my/org--recenter-after-follow-link-a (&rest _args)
    "Recenter after following a link, but only internal or file links."
    :after '(org-link-search)
    (when (get-buffer-window)
      (ignore-errors (recenter))))

nobiot avatar Jan 24 '21 11:01 nobiot

OK, we're getting somewhere! I can confirm that this must be a Doom problem. When I run vanilla Emacs (emacs -q) all the transclusion works properly.

Unfortunately, modifying/removing advice goes beyond my current emacs knowledge, so I don't know how to fix this problem in Doom.

arozbiz avatar Jan 24 '21 17:01 arozbiz

This might work. I don't use Doom, I cannot test it.

https://github.com/hlissner/doom-emacs/blob/develop/core/core-lib.el#L598

(undefadvice! +org--recenter-after-follow-link-a)

Note that this completely disables this default advice that Doom puts in. There should be a better way, but as a test, this might get you going for now.

nobiot avatar Jan 24 '21 19:01 nobiot

[Editing this. I tried what Doom would do]

(advice-remove 'org-link-search '+org--recenter-after-follow-link-a) This should remove the advice.

But... More importantly, it's not this advice '+org--recenter-after-follow-link-a as I assumed. I have added these Doom macros and functions manually in my vanilla Emacs (see the code excerpt below), and tested my hypothesis.

image

Org-transclusion just works.

The error comes from Doom, but not from this advice. You would probably need to ask a Doom forum for help. With this, I have no idea where the error comes from (other than the fact that it's somewhere in Doom, or your config).

I would still suggest that you try this, though: (advice-remove 'org-link-search '+org--recenter-after-follow-link-a)

(defun doom-enlist (exp)
  "Return EXP wrapped in a list, or as-is if already a list."
  (declare (pure t) (side-effect-free t))
  (if (listp exp) exp (list exp)))

(defmacro defadvice! (symbol arglist &optional docstring &rest body)
  "Define an advice called SYMBOL and add it to PLACES.
ARGLIST is as in `defun'. WHERE is a keyword as passed to `advice-add', and
PLACE is the function to which to add the advice, like in `advice-add'.
DOCSTRING and BODY are as in `defun'.
\(fn SYMBOL ARGLIST &optional DOCSTRING &rest [WHERE PLACES...] BODY\)"
  (declare (doc-string 3) (indent defun))
  (unless (stringp docstring)
    (push docstring body)
    (setq docstring nil))
  (let (where-alist)
    (while (keywordp (car body))
      (push `(cons ,(pop body) (doom-enlist ,(pop body)))
            where-alist))
    `(progn
       (defun ,symbol ,arglist ,docstring ,@body)
       (dolist (targets (list ,@(nreverse where-alist)))
         (dolist (target (cdr targets))
           (advice-add target (car targets) #',symbol))))))

 (defadvice! +org--recenter-after-follow-link-a (&rest _args)
    "Recenter after following a link, but only internal or file links."
    :after '(org-footnote-action
             org-follow-timestamp-link
             org-link-open-as-file
             org-link-search)
    (when (get-buffer-window)
      (recenter)))

nobiot avatar Jan 24 '21 19:01 nobiot

Thanks! I added (advice-remove 'org-link-search '+org--recenter-after-follow-link-a) to my init. It removed the advice and transclusion now works.

I suspect lots of folks are using Org/Org-Roam with Doom, so probably something worth running down with the Doom people.

arozbiz avatar Jan 24 '21 21:01 arozbiz

Good to know that removing the advice has worked for you.

Hmm. So it's either my way of adding the Doom advice manually was incorrect, or there is something else compounding the advice causes the error.

In either case... Not sure what I can do within Org-transclusion.

nobiot avatar Jan 25 '21 07:01 nobiot

Thanks! I added (advice-remove 'org-link-search '+org--recenter-after-follow-link-a) to my init. It removed the advice and transclusion now works.

I suspect lots of folks are using Org/Org-Roam with Doom, so probably something worth running down with the Doom people.

I have just started using org-transclusion again and I had the same 're-centering' problem using Doom Emacs. Thanks a lot for your help, this has resolved the issue for me for now!

wuqui avatar May 20 '21 16:05 wuqui

I am reopening this to remind myself to do documentation or something about this. I don't think I should change the code at this stage.

@wuqui, thanks for letting me know about it.

nobiot avatar May 20 '21 18:05 nobiot

Added to README

nobiot avatar May 20 '21 18:05 nobiot

did some investigation as part of v0.2.0. recenter errors when used in with-temp-buffer. I'm not sure if I can do anything about this on my end unless the customization in Doom is changed to enclose recenter in ignore-errors or something.

I'll see if I can add something like this in my code again.

nobiot avatar Jun 12 '21 12:06 nobiot