Skip to content

Commit 7eb8305

Browse files
authored
Merge pull request #913 from jrblevin/issue-912
Fix `markdown-heading-at-point` at the end of line
2 parents f8ffa30 + 0be0589 commit 7eb8305

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Hide wikilink markup as part of `markdown-toggle-markup-hiding` [GH-847][]
1616
- Angle URL fontify issue which was introduced by [GH-861][] [GH-895][]
1717
- Fix list item bound calculation when tab indentation is used [GH-904][]
18+
- Fix `markdown-heading-at-point` at the end of line [GH-912][]
1819

1920
* Improvements:
2021
- Support drag and drop features on Windows and multiple files' drag and drop
@@ -29,6 +30,7 @@
2930
[gh-895]: https://github.com/jrblevin/markdown-mode/issues/895
3031
[gh-904]: https://github.com/jrblevin/markdown-mode/issues/904
3132
[gh-910]: https://github.com/jrblevin/markdown-mode/issues/910
33+
[gh-912]: https://github.com/jrblevin/markdown-mode/issues/912
3234

3335
# Markdown Mode 2.7
3436

markdown-mode.el

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2904,7 +2904,8 @@ data. See `markdown-inline-code-at-point-p' for inline code."
29042904
(defun markdown-heading-at-point (&optional pos)
29052905
"Return non-nil if there is a heading at the POS.
29062906
Set match data for `markdown-regex-header'."
2907-
(let ((match-data (get-text-property (or pos (point)) 'markdown-heading)))
2907+
(let* ((p (or pos (if (and (eolp) (>= (point) 2)) (1- (point)) (point))))
2908+
(match-data (get-text-property p 'markdown-heading)))
29082909
(when match-data
29092910
(set-match-data match-data)
29102911
t)))

tests/markdown-test.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4398,7 +4398,11 @@ x: x
43984398
(forward-line -1)
43994399
(should (markdown-heading-at-point))
44004400
(should (equal (match-data t) (get-text-property (point) 'markdown-heading)))
4401-
(should (equal (match-data t) (get-text-property (point) 'markdown-heading-1-setext))))))
4401+
(should (equal (match-data t) (get-text-property (point) 'markdown-heading-1-setext))))
4402+
;; Detail: https://github.com/jrblevin/markdown-mode/issues/912
4403+
(markdown-test-string "# header\nsection"
4404+
(goto-char (line-end-position))
4405+
(should (markdown-heading-at-point)))))
44024406

44034407
(ert-deftest test-markdown-parsing/inline-link-in-code-block ()
44044408
"Test `markdown-match-generic-links'."

0 commit comments

Comments
 (0)