awth13 / org-appear

Toggle visibility of hidden Org mode element parts upon entering and leaving an element
MIT License
375 stars 19 forks source link

Bug:wrong-type-argument stringp nil #42

Closed Jousimies closed 2 years ago

Jousimies commented 2 years ago

my org appear config :

(leaf org-appear
  :config
  (add-hook 'org-mode-hook 'org-appear-mode)
  (setq org-appear-trigger 'manual)
  (setq org-appear-autolinks t)
  (add-hook 'meow-insert-enter-hook #'org-appear-manual-start)
  (add-hook 'meow-insert-exit-hook #'org-appear-manual-stop))

open scratch buffer , input something like (require 'org), and press Esc to exit meow insert mode, the error appeard.

The backtrace

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  looking-at(nil)
  org-element-context()
  (and t (org-element-context))
  (let* ((elem (and t (org-element-context)))) (if elem (let* ((elem-type (car elem)) (elem-end (- (org-element-property :end elem) (1- (org-element-property :post-blank elem)))) (link-ignore-p (and (eq elem-type 'link) (or (string-match-p "[Cc]ite" ...) (eq ... ...)))) (key-ignore-p (and (eq elem-type 'keyword) (not (memq ... org-hidden-keywords)))) (script-ignore-p (and (or (eq elem-type ...) (eq elem-type ...)) (not (org-element-property :use-brackets-p elem)) (not (eq org-use-sub-superscripts t))))) (if (and (memq elem-type org-appear-elements) (< (point) elem-end) (not link-ignore-p) (not key-ignore-p) (not script-ignore-p)) elem nil)) nil))
  org-appear--current-elem()
  (and t (org-appear--current-elem))
  (let* ((current-elem (and t (org-appear--current-elem)))) (if current-elem (org-appear--hide-invisible current-elem) nil))
  (progn (let* ((current-elem (and t (org-appear--current-elem)))) (if current-elem (org-appear--hide-invisible current-elem) nil)) (setq org-appear--elem-toggled nil))
  (if (not org-appear-manual-linger) (progn (let* ((current-elem (and t (org-appear--current-elem)))) (if current-elem (org-appear--hide-invisible current-elem) nil)) (setq org-appear--elem-toggled nil)))
  org-appear-manual-stop()
  run-hooks(meow-insert-exit-hook)
  meow-insert-mode(-1)
  meow--disable-current-state()
  meow-normal-mode(1)
  meow--switch-state(normal)
  meow-insert-exit()
  funcall-interactively(meow-insert-exit)
  call-interactively(meow-insert-exit nil nil)
  command-execute(meow-insert-exit)
awth13 commented 2 years ago

Hi! Thank you for posting the issue!

org-appear shouldn't be active in buffers other than Org buffers. I am not familiar with leaf so I'm not sure why, despite org-appear hooked into org-mode only, your configuration enabled org-appear in the scratch buffer. I will look into what we can do about it.

Jousimies commented 2 years ago

I don't think it related to leaf. (By the way , I use borg to manage emacs packages, The org-appear.el file will be byte compile to org-appear.elc file.)

I reset my config to

  (setq org-appear-trigger 'manual
    org-appear-autolinks t)

  (add-hook 'org-mode-hook #'org-appear-mode)

  (add-hook 'meow-insert-enter-hook #'org-appear-manual-start)
  (add-hook 'meow-insert-exit-hook #'org-appear-manual-stop)

In scratch buffer write something like (fdasfdasf), then exit meow insert mode, the error appeard. Need to input paren, otherwise no error appeared.

If I try M-x org-appear-mode , the message buffer give some infos like:

Org-Appear mode enabled in current buffer
Error in post-command-hook (org-appear--post-cmd): (wrong-type-argument stringp nil)
Jousimies commented 2 years ago

I try set scratch buffer to another mode , the error disappeared.

Emmm. Like the error only happened in emacs-lisp-mode.

awth13 commented 2 years ago

I don't think it related to leaf.

Oh, I didn't mean it is a leaf bug. Just that you shouldn't enable org-appear outside Org buffers and your configuration using leaf did enable org-appear outside Org buffers. Your new example is doing exactly that as well.

awth13 commented 2 years ago

If you want to make sure that org-appear functions are added to hooks in Org mode only, try this instead:

(add-hook 'org-mode-hook (lambda ()
                           (add-hook 'evil-insert-state-entry-hook
                                     #'org-appear-manual-start
                                     nil
                                     t)
                           (add-hook 'evil-insert-state-exit-hook
                                     #'org-appear-manual-stop
                                     nil
                                     t)))

Notice that there are four arguments to add-hook. The last argument makes the hook function buffer local and must be t to avoid enabling org-appear globally. Your configuration seems to omit the additional arguments, which, I think, might be the actual source of the problem.

Jousimies commented 2 years ago

Thank you for you help. Below config finally work as expected.

  (unless
      (fboundp 'org-appear-manual-start)
    (autoload #'org-appear-manual-start "org-appear" nil t))

  (unless
      (fboundp 'org-appear-manual-stop)
    (autoload #'org-appear-manual-stop "org-appear" nil t))

  (setq org-appear-trigger 'manual
    org-appear-autolinks t)

  (add-hook 'org-mode-hook 'org-appear-mode)

  (add-hook 'org-mode-hook (lambda ()
                 (add-hook 'meow-insert-enter-hook #'org-appear-manual-start nil t)
                 (add-hook 'meow-insert-exit-hook #'org-appear-manual-stop nil t)))