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

Improve moving header commands in GFM #41

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions markdown-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -3554,8 +3554,8 @@ Assumes match data is available for `markdown-regex-italic'."
(define-key map (kbd "<S-tab>") 'markdown-shifttab)
(define-key map (kbd "<backtab>") 'markdown-shifttab)
;; Header navigation
(define-key map (kbd "C-c C-n") 'outline-next-visible-heading)
(define-key map (kbd "C-c C-p") 'outline-previous-visible-heading)
(define-key map (kbd "C-c C-n") 'markdown-next-visible-heading)
(define-key map (kbd "C-c C-p") 'markdown-previous-visible-heading)
(define-key map (kbd "C-c C-f") 'outline-forward-same-level)
(define-key map (kbd "C-c C-b") 'outline-backward-same-level)
(define-key map (kbd "C-c C-u") 'outline-up-heading)
Expand Down Expand Up @@ -4310,12 +4310,30 @@ Calls `markdown-cycle' with argument t."
(interactive)
(markdown-cycle t))

(defun markdown-move-visible-header-common (move-fn arg)
(let ((blocks (markdown-collect-gfm-code-blocks)))
(funcall move-fn arg)
(while (markdown-gfm-code-block-p blocks (point))
(funcall move-fn arg))))

(defun markdown-next-visible-heading (arg)
(interactive "p")
(markdown-move-visible-header-common #'outline-next-visible-heading arg))

(defun markdown-previous-visible-heading (arg)
(interactive "p")
(markdown-move-visible-header-common #'outline-previous-visible-heading arg))

(defun markdown-outline-level ()
"Return the depth to which a statement is nested in the outline."
(cond
((match-end 1) 1)
((match-end 3) 2)
((- (match-end 5) (match-beginning 5)))))
(let ((blocks (save-match-data
(markdown-collect-gfm-code-blocks))))
(if (markdown-gfm-code-block-p blocks (point))
7
(cond
((match-end 1) 1)
((match-end 3) 2)
((- (match-end 5) (match-beginning 5)))))))

(defun markdown-promote-subtree (&optional arg)
"Promote the current subtree of ATX headings.
Expand Down