Narrow to subtree with org-velocity

只愿长相守 提交于 2020-01-15 12:15:47

问题


I would like to use org-velocity as my primary means of navigating large .org files but with the following changes:

  1. After running a search in org-velocity, I would like the buffer to automatically narrow to that subtree, once I make my selection.

  2. Org-velocity should run its search against the entire file, even if the buffer is narrowed.

For part (1) I think something like this should work:

(add-hook 'org-follow-link-hook (lambda () (org-narrow-to-subtree)))

But this is not the right hook. Not sure how to approach (2). Any ideas? Thanks!


回答1:


I am writing a partial answer for part (2) of the question since the following does not fit nicely into a comment. Note, that I do not use org-velocity. So, the following is not really tested. save-restriction saves the current narrowing to the org-subtree and widen removes this narrowing temporarily during the search. To see exactly how it works read the help for the functions save-restriction and widen with C-h f and consult the info C-h i for elisp and there the Section "Advising functions".

(defadvice org-velocity (around search-all activate)
  "Widen for search with org-velocity"
  (save-restriction
    (widen)
    ad-do-it
    ))



回答2:


Okay, I think I have a complete solution!

  1. Make sure you have this fork of org-velocity installed:

    https://github.com/Fuco1/org-velocity

  2. Open your org-velocity.el file and replace lines 763-765 with this:

    (progn
      (with-current-buffer (org-velocity-match-buffer)
        (kill-buffer-and-window))
      (org-narrow-to-subtree)
      (show-all))))))
    

    The additional code tells org-velocity to first narrow the buffer to the selected subtree and secondly to expand that node.

  3. Put this code somewhere in your search path (init.el, .emacs, etc.)

    (defadvice org-velocity (around search-all activate)
       "Widen for search with org-velocity"
       (widen)
       ad-do-it)
    

    And that's it!

Thank you Tobias, Paul and Matúš for walking me through this!!

Take care,

-Adam



来源:https://stackoverflow.com/questions/26822973/narrow-to-subtree-with-org-velocity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!