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-make-toc error in 'wrong-type-argument stringp nil' with headline that has no text #13

Open
zhaojiangbin opened this issue May 3, 2020 · 3 comments · May be fixed by #28
Open

org-make-toc error in 'wrong-type-argument stringp nil' with headline that has no text #13

zhaojiangbin opened this issue May 3, 2020 · 3 comments · May be fixed by #28
Assignees
Labels

Comments

@zhaojiangbin
Copy link

The org buffer to reproduce:


* TOC
:PROPERTIES:
:TOC:      :include all :ignore (this)
:END:
:CONTENTS:

:END:

* one

* 

Note the last headline has no text. This causes the string-match-p call in line 332 to fail. The following is the top few stack frames of the debugger:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("\\`COMMENT\\(?:[[:blank:]]\\|\\'\\)" nil nil)
  string-match-p("\\`COMMENT\\(?:[[:blank:]]\\|\\'\\)" nil)
  (or (and (not (funcall --cl-arg-has-- force 'ignore)) (funcall --cl-entry-match-- :ignore 'this)) (seq-intersection org-make-toc-exclude-tags (org-get-tags)) (string-match-p "\\`COMMENT\\(?:[[:blank:]]\\|\\'\\)" (nth 4 (org-heading-components))))

Applying the following patch can work around the error:

modified   org-make-toc.el
@@ -330,7 +330,7 @@ with the destination of the published file."
                                  ;; NOTE: The "COMMENT" keyword is not returned as the to-do keyword
                                  ;; by `org-heading-components', so it can't be tested as a keyword.
                                  (string-match-p (rx bos "COMMENT" (or blank eos))
-                                                 (nth 4 (org-heading-components))))
+                                                 (or (nth 4 (org-heading-components)) "")))
                        (funcall org-make-toc-link-type-fn)))
               (entry-match (property value)
                            (when-let* ((found-value (entry-property property)))

but it can also produce incorrect TOC with the org buffers like below:


* TOC
:PROPERTIES:
:TOC:      :include all :ignore (this)
:END:
:CONTENTS:
- [[#four][four]]
:END:

* 

** four
@alphapapa
Copy link
Owner

Thanks. This should probably be fixed to, at least, give a useful error. What do you think should happen for "anonymous" headings?

@alphapapa alphapapa self-assigned this May 4, 2020
@alphapapa alphapapa added the bug label May 4, 2020
@zhaojiangbin
Copy link
Author

If links can be generated to the "anonymous" headings without too much effort for you, perhaps we can have "placeholder" entries in place of such anonymous headings in the TOC?

An error message would be good enough otherwise. An org doc with such headings is unfinished and thoese headings must to be fixed anyway.

@alphapapa
Copy link
Owner

I don't know what links GitHub's renderer generates for anonymous headings. Maybe the best approach would be to show a warning at TOC-generation time and omit that entry from the TOC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants