Search code examples
emacsmarkdown

emacs markdown mode selecting org-mode header level?


in markdown mode, emacs allows SHIFT-TAB to cycle between content view (1 level), outline view (all levels), and document view (all text). I would like to have one of them go down only two levels or add another view that just has two levels. Is there a customization variable I could stick into .emacs that would do this?


Solution

  • I don't see a way to add an additional cycling level by way of user customization.

    A separate command that should show the 2-level view is C-2 M-x outline-hide-sublevels. But, it isn't convenient breaking the cycle.

    One possibility is writing a custom version of markdown-shifttab, which doesn't require too much copy pasta.

    (defun my-markdown-shifttab ()
      "Do `markdown-shifttab' with added 2-level view."
      (interactive)
      (cond ((markdown-table-at-point-p)
             (call-interactively #'markdown-table-backward-cell))
            (t (cond ((and (eq last-command this-command)
                           (eq markdown-cycle-global-status 3))
                      ;; Add extra view between "CONTENTS" and "SHOW ALL"
                      (setq this-command 'my-markdown-shifttab--extra)
                      (outline-hide-sublevels 2)
                      (markdown-outline-fix-visibility))
                     (t (when (eq last-command 'my-markdown-shifttab--extra)
                          ;; Enter back into default cycling
                          (setq last-command 'my-markdown-shifttab))
                        (markdown-cycle t))))))