branch: elpa/markdown-mode
commit 0be0589c4042c914eec9d2f0bd2ddd4eb678beb6
Author: Shohei YOSHIDA <syo...@gmail.com>
Commit: Shohei YOSHIDA <syo...@gmail.com>

    Fix `markdown-heading-at-point` at the end of line
---
 CHANGES.md             | 2 ++
 markdown-mode.el       | 3 ++-
 tests/markdown-test.el | 6 +++++-
 3 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/CHANGES.md b/CHANGES.md
index c1300fc3b6..53d3881294 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -15,6 +15,7 @@
     - Hide wikilink markup as part of `markdown-toggle-markup-hiding` 
[GH-847][]
     - Angle URL fontify issue which was introduced by [GH-861][] [GH-895][]
     - Fix list item bound calculation when tab indentation is used [GH-904][]
+    - Fix `markdown-heading-at-point` at the end of line [GH-912][]
 
 *   Improvements:
     - Support drag and drop features on Windows and multiple files' drag and 
drop
@@ -29,6 +30,7 @@
   [gh-895]: https://github.com/jrblevin/markdown-mode/issues/895
   [gh-904]: https://github.com/jrblevin/markdown-mode/issues/904
   [gh-910]: https://github.com/jrblevin/markdown-mode/issues/910
+  [gh-912]: https://github.com/jrblevin/markdown-mode/issues/912
 
 # Markdown Mode 2.7
 
diff --git a/markdown-mode.el b/markdown-mode.el
index c80483d96e..5de66b3867 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -2904,7 +2904,8 @@ data.  See `markdown-inline-code-at-point-p' for inline 
code."
 (defun markdown-heading-at-point (&optional pos)
   "Return non-nil if there is a heading at the POS.
 Set match data for `markdown-regex-header'."
-  (let ((match-data (get-text-property (or pos (point)) 'markdown-heading)))
+  (let* ((p (or pos (if (and (eolp) (>= (point) 2)) (1- (point)) (point))))
+         (match-data (get-text-property p 'markdown-heading)))
     (when match-data
       (set-match-data match-data)
       t)))
diff --git a/tests/markdown-test.el b/tests/markdown-test.el
index 5454794a99..9d8ba2a610 100644
--- a/tests/markdown-test.el
+++ b/tests/markdown-test.el
@@ -4398,7 +4398,11 @@ x: x
       (forward-line -1)
       (should (markdown-heading-at-point))
       (should (equal (match-data t) (get-text-property (point) 
'markdown-heading)))
-      (should (equal (match-data t) (get-text-property (point) 
'markdown-heading-1-setext))))))
+      (should (equal (match-data t) (get-text-property (point) 
'markdown-heading-1-setext))))
+    ;; Detail: https://github.com/jrblevin/markdown-mode/issues/912
+    (markdown-test-string "# header\nsection"
+      (goto-char (line-end-position))
+      (should (markdown-heading-at-point)))))
 
 (ert-deftest test-markdown-parsing/inline-link-in-code-block ()
   "Test `markdown-match-generic-links'."

Reply via email to