Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doom's recenter error #52

Open
arozbiz opened this issue Jan 18, 2021 · 18 comments
Open

Doom's recenter error #52

arozbiz opened this issue Jan 18, 2021 · 18 comments

Comments

@arozbiz
Copy link

arozbiz commented Jan 18, 2021

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.

@nobiot
Copy link
Owner

nobiot commented Jan 18, 2021

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

@arozbiz
Copy link
Author

arozbiz commented Jan 18, 2021

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 arozbiz closed this as completed Jan 18, 2021
@nobiot
Copy link
Owner

nobiot commented Jan 18, 2021

Very strange. Just typing should also work.

@arozbiz arozbiz reopened this Jan 24, 2021
@arozbiz
Copy link
Author

arozbiz commented Jan 24, 2021

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]

@nobiot
Copy link
Owner

nobiot commented Jan 24, 2021

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
Copy link
Owner

nobiot commented Jan 24, 2021

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
Copy link
Owner

nobiot commented Jan 24, 2021

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
Copy link
Owner

nobiot commented Jan 24, 2021

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
Copy link
Owner

nobiot commented Jan 24, 2021

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))))

@arozbiz
Copy link
Author

arozbiz commented Jan 24, 2021

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.

@nobiot
Copy link
Owner

nobiot commented Jan 24, 2021

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
Copy link
Owner

nobiot commented Jan 24, 2021

[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)))

@arozbiz
Copy link
Author

arozbiz commented Jan 24, 2021

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.

@nobiot
Copy link
Owner

nobiot commented Jan 25, 2021

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.

@arozbiz arozbiz closed this as completed Apr 22, 2021
@wuqui
Copy link

wuqui commented May 20, 2021

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!

@nobiot
Copy link
Owner

nobiot commented May 20, 2021

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 nobiot reopened this May 20, 2021
nobiot added a commit that referenced this issue May 20, 2021
@nobiot
Copy link
Owner

nobiot commented May 20, 2021

Added to README

@nobiot nobiot closed this as completed May 20, 2021
@nobiot nobiot reopened this May 20, 2021
@nobiot
Copy link
Owner

nobiot commented Jun 12, 2021

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 nobiot changed the title Transclusion of anything other than files not working Doom's recenter error Jun 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants