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

Buffer with HTML comment at EOB causes error #327

Closed
kaushalmodi opened this issue Apr 5, 2018 · 4 comments
Closed

Buffer with HTML comment at EOB causes error #327

kaushalmodi opened this issue Apr 5, 2018 · 4 comments

Comments

@kaushalmodi
Copy link

kaushalmodi commented Apr 5, 2018

A buffer with HTML comment like <!--more--> at EOB (no trailing newline!) causes error: (wrong-type-argument integer-or-marker-p nil)

Expected Behavior

That error should not happen.

Actual Behavior

Error happens.

Steps to Reproduce

(see the following post in this thread)

Backtrace

I get this after having the markdown mode file buffer contain just <!--more-->. I have require-final-newline set to nil, go to the end of that line, do C-d, then save (C-x C-s), and then M-x revert-buffer to get this.

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  remove-text-properties(nil 12 (markdown-tilde-fence-begin nil markdown-tilde-fence-end nil markdown-fenced-code nil markdown-yaml-metadata-begin nil markdown-yaml-metadata-end nil markdown-yaml-metadata-section nil markdown-gfm-block-begin nil markdown-gfm-block-end nil markdown-gfm-code nil markdown-list-item nil markdown-pre nil markdown-blockquote nil markdown-hr nil markdown-comment nil markdown-heading nil markdown-heading-1-setext nil markdown-heading-2-setext nil markdown-heading-1-atx nil markdown-heading-2-atx nil markdown-heading-3-atx nil markdown-heading-4-atx nil markdown-heading-5-atx nil markdown-heading-6-atx nil markdown-metadata-key nil markdown-metadata-value nil markdown-metadata-markup nil))
  markdown-syntax-propertize-comments(6 12)
  markdown-syntax-propertize-comments(1 12)
  markdown-syntax-propertize(1 12)
  markdown-font-lock-extend-region-function(12 12 1)
  run-hook-with-args(markdown-font-lock-extend-region-function 12 12 1)
  jit-lock-after-change(12 12 1)
  delete-char(1)
  org-delete-char(1)
  funcall-interactively(org-delete-char 1)
  call-interactively(org-delete-char nil nil)
  command-execute(org-delete-char)

Software Versions

  • Markdown Mode: markdown-mode, version 2.4-dev
  • Emacs: GNU Emacs 27.0.50 (build 37, x86_64-pc-linux-gnu, GTK+ Version 2.24.23) of 2018-04-05
  • OS: RHEL 6.6

/cc @zzamboni

This issue originated from kaushalmodi/ox-hugo#152.

@kaushalmodi
Copy link
Author

kaushalmodi commented Apr 5, 2018

OK, found an emacs -Q recipe:

Content of test.md

(Save that file after setting require-final-newline to nil.)

<!--more-->

Command

emacs -Q -l markdown-mode.el test.md --eval "(toggle-debug-on-error)"

Steps

  1. Type above command
  2. C-e
  3. C-d
  4. Error!

Backtrace

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  remove-text-properties(nil 12 (markdown-tilde-fence-begin nil markdown-tilde-fence-end nil markdown-fenced-code nil markdown-yaml-metadata-begin nil markdown-yaml-metadata-end nil markdown-yaml-metadata-section nil markdown-gfm-block-begin nil markdown-gfm-block-end nil markdown-gfm-code nil markdown-list-item nil markdown-pre nil markdown-blockquote nil markdown-hr nil markdown-comment nil markdown-heading nil markdown-heading-1-setext nil markdown-heading-2-setext nil markdown-heading-1-atx nil markdown-heading-2-atx nil markdown-heading-3-atx nil markdown-heading-4-atx nil markdown-heading-5-atx nil markdown-heading-6-atx nil markdown-metadata-key nil markdown-metadata-value nil markdown-metadata-markup nil))
  (let ((comment-end (match-end 0)) (comment-begin (nth 8 (syntax-ppss)))) (put-text-property (1- comment-end) comment-end 'syntax-table (string-to-syntax ">")) (remove-text-properties comment-begin comment-end markdown--syntax-properties) (put-text-property comment-begin comment-end 'markdown-comment (list comment-begin comment-end)) (markdown-syntax-propertize-comments (min (1+ comment-end) end (point-max)) end))
  (cond ((and (not in-comment) (re-search-forward markdown-regex-comment-start end t) (not (markdown-inline-code-at-point-p)) (not (markdown-code-block-at-point-p))) (let ((open-beg (match-beginning 0))) (put-text-property open-beg (1+ open-beg) 'syntax-table (string-to-syntax "<")) (markdown-syntax-propertize-comments (min (1+ (match-end 0)) end (point-max)) end))) ((and in-comment (re-search-forward markdown-regex-comment-end end t)) (let ((comment-end (match-end 0)) (comment-begin (nth 8 (syntax-ppss)))) (put-text-property (1- comment-end) comment-end 'syntax-table (string-to-syntax ">")) (remove-text-properties comment-begin comment-end markdown--syntax-properties) (put-text-property comment-begin comment-end 'markdown-comment (list comment-begin comment-end)) (markdown-syntax-propertize-comments (min (1+ comment-end) end (point-max)) end))) (t nil))
  (let* ((in-comment (nth 4 (syntax-ppss)))) (goto-char start) (cond ((and (not in-comment) (re-search-forward markdown-regex-comment-start end t) (not (markdown-inline-code-at-point-p)) (not (markdown-code-block-at-point-p))) (let ((open-beg (match-beginning 0))) (put-text-property open-beg (1+ open-beg) 'syntax-table (string-to-syntax "<")) (markdown-syntax-propertize-comments (min (1+ (match-end 0)) end (point-max)) end))) ((and in-comment (re-search-forward markdown-regex-comment-end end t)) (let ((comment-end (match-end 0)) (comment-begin (nth 8 (syntax-ppss)))) (put-text-property (1- comment-end) comment-end 'syntax-table (string-to-syntax ">")) (remove-text-properties comment-begin comment-end markdown--syntax-properties) (put-text-property comment-begin comment-end 'markdown-comment (list comment-begin comment-end)) (markdown-syntax-propertize-comments (min (1+ comment-end) end (point-max)) end))) (t nil)))
  markdown-syntax-propertize-comments(6 12)
  (let ((open-beg (match-beginning 0))) (put-text-property open-beg (1+ open-beg) 'syntax-table (string-to-syntax "<")) (markdown-syntax-propertize-comments (min (1+ (match-end 0)) end (point-max)) end))
  (cond ((and (not in-comment) (re-search-forward markdown-regex-comment-start end t) (not (markdown-inline-code-at-point-p)) (not (markdown-code-block-at-point-p))) (let ((open-beg (match-beginning 0))) (put-text-property open-beg (1+ open-beg) 'syntax-table (string-to-syntax "<")) (markdown-syntax-propertize-comments (min (1+ (match-end 0)) end (point-max)) end))) ((and in-comment (re-search-forward markdown-regex-comment-end end t)) (let ((comment-end (match-end 0)) (comment-begin (nth 8 (syntax-ppss)))) (put-text-property (1- comment-end) comment-end 'syntax-table (string-to-syntax ">")) (remove-text-properties comment-begin comment-end markdown--syntax-properties) (put-text-property comment-begin comment-end 'markdown-comment (list comment-begin comment-end)) (markdown-syntax-propertize-comments (min (1+ comment-end) end (point-max)) end))) (t nil))
  (let* ((in-comment (nth 4 (syntax-ppss)))) (goto-char start) (cond ((and (not in-comment) (re-search-forward markdown-regex-comment-start end t) (not (markdown-inline-code-at-point-p)) (not (markdown-code-block-at-point-p))) (let ((open-beg (match-beginning 0))) (put-text-property open-beg (1+ open-beg) 'syntax-table (string-to-syntax "<")) (markdown-syntax-propertize-comments (min (1+ (match-end 0)) end (point-max)) end))) ((and in-comment (re-search-forward markdown-regex-comment-end end t)) (let ((comment-end (match-end 0)) (comment-begin (nth 8 (syntax-ppss)))) (put-text-property (1- comment-end) comment-end 'syntax-table (string-to-syntax ">")) (remove-text-properties comment-begin comment-end markdown--syntax-properties) (put-text-property comment-begin comment-end 'markdown-comment (list comment-begin comment-end)) (markdown-syntax-propertize-comments (min (1+ comment-end) end (point-max)) end))) (t nil)))
  markdown-syntax-propertize-comments(1 12)
  (save-excursion (remove-text-properties start end markdown--syntax-properties) (markdown-syntax-propertize-fenced-block-constructs start end) (markdown-syntax-propertize-list-items start end) (markdown-syntax-propertize-pre-blocks start end) (markdown-syntax-propertize-blockquotes start end) (markdown-syntax-propertize-headings start end) (markdown-syntax-propertize-hrs start end) (markdown-syntax-propertize-comments start end))
  (progn (save-excursion (remove-text-properties start end markdown--syntax-properties) (markdown-syntax-propertize-fenced-block-constructs start end) (markdown-syntax-propertize-list-items start end) (markdown-syntax-propertize-pre-blocks start end) (markdown-syntax-propertize-blockquotes start end) (markdown-syntax-propertize-headings start end) (markdown-syntax-propertize-hrs start end) (markdown-syntax-propertize-comments start end)))
  (unwind-protect (progn (save-excursion (remove-text-properties start end markdown--syntax-properties) (markdown-syntax-propertize-fenced-block-constructs start end) (markdown-syntax-propertize-list-items start end) (markdown-syntax-propertize-pre-blocks start end) (markdown-syntax-propertize-blockquotes start end) (markdown-syntax-propertize-headings start end) (markdown-syntax-propertize-hrs start end) (markdown-syntax-propertize-comments start end))) (if modified nil (restore-buffer-modified-p nil)))
  (let* ((modified (buffer-modified-p)) (buffer-undo-list t) (inhibit-read-only t) (inhibit-modification-hooks t)) (unwind-protect (progn (save-excursion (remove-text-properties start end markdown--syntax-properties) (markdown-syntax-propertize-fenced-block-constructs start end) (markdown-syntax-propertize-list-items start end) (markdown-syntax-propertize-pre-blocks start end) (markdown-syntax-propertize-blockquotes start end) (markdown-syntax-propertize-headings start end) (markdown-syntax-propertize-hrs start end) (markdown-syntax-propertize-comments start end))) (if modified nil (restore-buffer-modified-p nil))))
  markdown-syntax-propertize(1 12)
  (progn (markdown-syntax-propertize (car res) (cdr res)))
  (unwind-protect (progn (markdown-syntax-propertize (car res) (cdr res))) (set-match-data save-match-data-internal 'evaporate))
  (let ((save-match-data-internal (match-data))) (unwind-protect (progn (markdown-syntax-propertize (car res) (cdr res))) (set-match-data save-match-data-internal 'evaporate)))
  (progn (let ((save-match-data-internal (match-data))) (unwind-protect (progn (markdown-syntax-propertize (car res) (cdr res))) (set-match-data save-match-data-internal 'evaporate))))
  (if (= end (point-max)) (progn (let ((save-match-data-internal (match-data))) (unwind-protect (progn (markdown-syntax-propertize (car res) (cdr res))) (set-match-data save-match-data-internal 'evaporate)))))
  (progn (if (= end (point-max)) (progn (let ((save-match-data-internal (match-data))) (unwind-protect (progn (markdown-syntax-propertize (car res) (cdr res))) (set-match-data save-match-data-internal 'evaporate))))) (setq jit-lock-start (car res) jit-lock-end (cdr res)))
  (if res (progn (if (= end (point-max)) (progn (let ((save-match-data-internal (match-data))) (unwind-protect (progn (markdown-syntax-propertize (car res) (cdr res))) (set-match-data save-match-data-internal 'evaporate))))) (setq jit-lock-start (car res) jit-lock-end (cdr res))))
  (let ((res (markdown-syntax-propertize-extend-region start end))) (if res (progn (if (= end (point-max)) (progn (let ((save-match-data-internal (match-data))) (unwind-protect (progn (markdown-syntax-propertize (car res) (cdr res))) (set-match-data save-match-data-internal 'evaporate))))) (setq jit-lock-start (car res) jit-lock-end (cdr res)))))
  markdown-font-lock-extend-region-function(12 12 1)
  run-hook-with-args(markdown-font-lock-extend-region-function 12 12 1)
  jit-lock-after-change(12 12 1)
  delete-char(1 nil)
  funcall-interactively(delete-char 1 nil)
  call-interactively(delete-char nil nil)
  command-execute(delete-char)

@kaushalmodi
Copy link
Author

@jrblevin Can you please look at this?

@jrblevin
Copy link
Owner

Thanks for the report. I think this is fixed now, but could you please confirm?

@gwern
Copy link

gwern commented Nov 13, 2019

I run into this problem regularly with my files. I just upgraded to the Github dev version after noticing that the stable version doesn't have this fix, and the problem appears to be gone for me. (Which I appreciate because, quite aside from all the syntax highlighting and features, I've managed to screw up a number of indented lists in affected pages by forgetting that non-markdown-mode doesn't indent enough...)

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