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

‘org-element-at-point’ cannot be used in non-Org buffer #29

Open
tkossak opened this issue Sep 17, 2024 · 11 comments
Open

‘org-element-at-point’ cannot be used in non-Org buffer #29

tkossak opened this issue Sep 17, 2024 · 11 comments

Comments

@tkossak
Copy link

tkossak commented Sep 17, 2024

Reposting syl20bnr/spacemacs#16575 since it seems to be an issue with helm-org.

When I press SPC j i (command spacemacs/helm-jump-in-buffer) I get multiple errors:
⛔ Warning (org-element): ‘org-element-at-point’ cannot be used in non-Org buffer #<buffer *helm org inbuffer*> (helm-major-mode)

Reproduction

  1. Install spacemacs from scratch
mv ~/.emacs.d ~/.emacs.d.old
mv ~/.spacemacs ~/.spacemacs.old

git clone --recursive https://github.com/syl20bnr/spacemacs ~/.emacs.d
  1. Create dotfile as ~/.spacemacs. Only few lines changed from default dotfile - I added org layer, removed multi cursor layer and added these 2 lines:

    (setq helm-org-format-outline-path nil)
    (setq org-startup-indented 't)
    
  2. Create sample org file eg test.org with content:

    * heading1
    blabla
    
  3. Start spacemacs and perform first time installation of all packages it asks for

  4. Open test.org and press SPC j i. Result:
    image

@fnussbaum
Copy link

FWIW in Spacemacs SPC j i in an Org buffer calls helm-org-in-buffer-headings. The warnings seems to come from helm-org-indent-headings-1 enabling org-indent-mode in the Helm buffer.

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Sep 17, 2024 via email

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Sep 20, 2024 via email

@fnussbaum
Copy link

So what is calling org-element-at-point?

I got the following backtrace on my system with Org 9.7.11:

Debugger entered--entering a function:
* org-element-at-point()
  org-at-item-p()
  org-indent-add-properties(1 24)
  org-indent-refresh-maybe(1 24 0)
  helm-insert-header("Org headings (test.org)" nil)
  helm-insert-header-from-source(...)
  helm-render-source(...)
  helm-update("\\* test")
  helm-read-from-minibuffer(nil nil "\\* test" nil nil nil nil)
  helm-internal(...)
  helm(...)
  helm(...)
  helm-org-in-buffer-headings(nil)
  funcall-interactively(helm-org-in-buffer-headings nil)
  call-interactively(helm-org-in-buffer-headings)

Reproduction steps from ./emacs-helm.sh --load-packages org,helm-org, in particular with org-version 9.7.11:

Evaluate

(progn 
  (setq org-startup-indented t)
  (setq helm-org-format-outline-path nil))

Create a buffer test.org with the following content:

* test
test

Optionally evaluate

(add-hook
 'org-indent-mode-hook
 (defun debug-on-org-element-at-point ()
   (debug-on-entry #'org-element-at-point)))

Execute M-x helm-org-in-buffer-headings. This should reproduce the warnings (or enter the debugger).

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Sep 20, 2024 via email

@fnussbaum
Copy link

Thanks, I agree that in this case of helm-org, it is likely completely safe to ignore the warning.

In general, org-element-at-point can apparently cause random errors in non-org buffers, and the Org developers do not seem to intend to support every such use case, see for example https://list.orgmode.org/874jeuont7.fsf@localhost/. Hence I do not think that this needs to be reported upstream.

@alphapapa
Copy link
Member

there is no reason to limit this code to org-mode buffers (emacs-29 was not doing this).

AFAIU that is (unfortunately for downstream developers) no longer the case, hence the new warning. I've had to apply fixes for this in some of my own projects.

AFAIK one should generally not call org functions in non-Org buffers unless one knows it will work, including the whole chain of functions that such a call entails. (This may not have been the case in the past, but as Org is trying to become more modular and well-organized, it's probably a good rule of thumb now.)

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Sep 21, 2024 via email

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Sep 21, 2024 via email

@alphapapa
Copy link
Member

Hi Thierry,

Out of curiosity, how did you fix this? Thanks.

AFAIR you should either avoid using the function or make sure the buffer is in org-mode. There might be some exceptions in which you can get away with it, but there's no promise that they'll continue to work that way in the future, so it's probably not a good idea.

@thierryvolpiatto
Copy link
Member

thierryvolpiatto commented Sep 22, 2024 via email

thierryvolpiatto added a commit that referenced this issue Sep 22, 2024
No need to call org-indent-mode, just modify headings according to
state of org buffer(s).
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

4 participants