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

Integrating bm with org-mode: expanding tree on jump #35

Closed
mcraveiro opened this issue Apr 18, 2021 · 4 comments
Closed

Integrating bm with org-mode: expanding tree on jump #35

mcraveiro opened this issue Apr 18, 2021 · 4 comments

Comments

@mcraveiro
Copy link

Hi bm-mode developers,

Thanks very much for an incredibly useful mode which I have been using daily for many years. I'd like to improve my workflow with regards to how bm integrates with org-mode, but I did not manage to find any solutions via googling. My basic problem is that I tend to collapse org documents a lot, as they are quite large, and then make use of bm to find particular spots of interest as required. However, the problem then is that the tree does not uncollapse as I move to the bookmark. Apparently a similar issue is face with traditional bookmakrs [1, 2], and it is addressed by the following function: org-bookmark-jump-unhide. It is used like so:

(add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide)

My question is: what is the bm equivalent to bookmark-after-jump-hook so that I can bind this function in a similar fashion? I assume bm does not use this hook as I tried this binding to no avail, but if my assumption is incorrect do let me know.

Many thanks for your time.

[1] SO: bookmark-jump to org-mode file with collapsed headings not working as expected
[2] SO: Go to a bookmark that is not visible currently due to narrowing

@mcraveiro mcraveiro changed the title Integrating bm with org-mode: expanding tree on jum Integrating bm with org-mode: expanding tree on jump Apr 18, 2021
@joodland
Copy link
Owner

joodland commented Apr 19, 2021

Hi,

There is no equivalent functionality in bm.el today.

I have tried adding it, but I have no experience with org-mode. Can you try to evaluate this code snippet and see if it solves your problem?

(defvar bm-after-goto-hook nil
  "Hook run after jumping to a bookmark in `bm-goto'.")

(add-hook 'bm-after-goto-hook 'org-bookmark-jump-unhide)

(defun bm-goto (bookmark)
  "Goto specified BOOKMARK."
  (if (bm-bookmarkp bookmark)
      (progn
        (if bm-goto-position
            (goto-char (max
                        ;; sometimes marker-position is before start of overlay
                        ;; marker is not updated when overlay hooks are called.
                        (overlay-start bookmark)
                        (marker-position (overlay-get bookmark 'position))))
          (goto-char (overlay-start bookmark)))
        (run-hooks 'bm-after-goto-hook)
        (setq bm-wrapped nil)           ; turn off wrapped state
        (if bm-recenter
            (recenter))
        (let ((annotation (overlay-get bookmark 'annotation)))
          (if annotation
              (message annotation)))
        (when  (overlay-get bookmark 'temporary-bookmark)
          (bm-bookmark-remove  bookmark)))
    (when (> bm-verbosity-level 0)
      (message "Bookmark not found."))))

@mcraveiro
Copy link
Author

Absolute geinus @joodland, that's exactly what I needed :-) Thanks very much. Would this be patched in to bm or should I just add it to my own init file? I think it would be useful to any org-mode users.

Also, if you do not use org-mode, may I say I think its one of the most interesting applications of the Emacs platform, so I highly recommend it :-) I pretty much use it for everything, from time management, to writing my PhD thesis, bookmarks, REST API work via verb-mode, etc. Honestly, cannot recommend it enough.

@joodland
Copy link
Owner

I have pushed this change to master, so it should be available now.

@mcraveiro
Copy link
Author

You're a star, thanks very much @joodland.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants