在emacs中更轻松地进行轮廓导航

时间:2012-10-16 13:14:54

标签: emacs org-mode

我为Org-mode找到了这个漂亮的小功能:

;;; Move to next heading with dedicated buffer preview
(defun ded/org-show-next-heading-tidily ()
  "Show next entry, keeping other entries closed."
  (if (save-excursion (end-of-line) (outline-invisible-p))
      (progn (org-show-entry) (show-children))
    (outline-next-heading)
    (unless (and (bolp) (org-on-heading-p))
      (org-up-heading-safe)
      (hide-subtree)
      (error "Boundary reached"))
    (org-overview)
    (org-reveal t)
    (org-show-entry)
    (show-children)))

它从标题转移到标题,并显示其直接内容和孩子。 我喜欢这个想法,但我宁愿使用(org-tree-to-indirect-buffer)在专用缓冲​​区中显示。

我试着这样做:

(defun ded/org-show-next-heading-test ()
  "Show next entry, keeping other entries closed."
  (if (save-excursion (end-of-line) (outline-invisible-p))
      (progn (org-show-entry) (org-tree-to-indirect-buffer))
    (outline-next-heading)
    (unless (and (bolp) (org-on-heading-p))
      (org-up-heading-safe)
      (hide-subtree)
      (error "Boundary reached"))
    (org-overview)
    (org-reveal t)
    (org-tree-to-indirect-buffer)
    (show-children)))

然后我必须双击该键 - 一旦它在专用缓冲​​区中显示该条目,其次它仍然显示该条目。 我试图删除progn函数,但它完全不起作用。

我不是一个lisp程序员,我试着用它玩了一个小时左右但是无济于事,所以我希望有经验的人能帮我解决这个问题:)

很有责任。

2 个答案:

答案 0 :(得分:2)

不太确定你想要什么,但据我所知,你应该在最后致电org-tree-to-indirect-buffer

;;; Move to next heading with dedicated buffer preview
(defun ded/org-show-next-heading-tidily ()
  "Show next entry, keeping other entries closed."
  (if (save-excursion (end-of-line) (outline-invisible-p))
      (progn (org-show-entry) (show-children))
    (outline-next-heading)
    (unless (and (bolp) (org-on-heading-p))
      (org-up-heading-safe)
      (hide-subtree)
      (error "Boundary reached"))
    (org-overview)
    (org-reveal t)
    (org-show-entry)
    (show-children)
    (org-tree-to-indirect-buffer)))

如果它不是您想要的,那么请您提供更多详细信息。

答案 1 :(得分:1)

我最终制作了自己的简单功能,以便更轻松地导航:

(defun forward-and-preview ()
    "Go to same level next heading and show preview in dedicated buffer"
    (hide-subtree)
    (org-speed-move-safe (quote outline-next-visible-heading))
    (show-children)
    (org-tree-to-indirect-buffer)
    )
(defun back-and-preview ()
    "Go to same level previous heading and show preview in dedicated buffer"
    (hide-subtree)
    (org-speed-move-safe (quote outline-previous-visible-heading))
    (show-children)
    (org-tree-to-indirect-buffer)
    )
(defun up-back-and-preview ()
    "Go to previous level heading and show preview in dedicated buffer"
    (org-speed-move-safe (quote outline-up-heading))
    (org-tree-to-indirect-buffer)
    (hide-subtree)
    )
(defun up-forward-and-preview ()
    "Go to previous level next heading and show preview in dedicated buffer"
    (org-speed-move-safe (quote outline-up-heading))
    (hide-subtree)
    (org-speed-move-safe (quote outline-next-visible-heading))
    (org-tree-to-indirect-buffer)
    )
(defun inside-and-preview ()
    "Go to next level heading and show preview in dedicated buffer"
    (org-speed-move-safe (quote outline-next-visible-heading))
    (show-children)
    (org-tree-to-indirect-buffer)
    )
(add-to-list 'org-speed-commands-user '("l" inside-and-preview))
(add-to-list 'org-speed-commands-user '("j" forward-and-preview))
(add-to-list 'org-speed-commands-user '("k" back-and-preview))
(add-to-list 'org-speed-commands-user '("J" up-forward-and-preview))
(add-to-list 'org-speed-commands-user '("K" up-back-and-preview))