2

Running emacs 25.2.2 spacemacs 0.200.13.

In an org file, I have defined several bookmarks(SPC f b) under different headings. Consider this:

* H1 Some text Bookmark 1 * H2 Some text Bookmark 2 

Suppose I am in H1 narrowed and I SPC f b Bookmark 2, nothing happens.

Similarly, if I am in another buffer and I jump to Bookmark 2 when the buffer is narrowed to H1, I just switch buffer!

How do I tell emacs to adjust narrowing such that the bookmarked location is visible?

2
  • 1
    I guess you need to find out what command SPC f b runs, and put an advice before it to widen the buffer. Commented Oct 25, 2018 at 12:08
  • @JohnKitchin SPC f b runs helm-filtered-bookmarks. This just lists all bookmarks and one can select the one needed by typing a few characters, like other helm functions. Also, a noob here. So, will you please tell me what advice do I add and how? I have checked this (gnu.org/software/emacs/manual/html_node/elisp/…) only to get confused :) Commented Oct 26, 2018 at 4:28

2 Answers 2

2

This was a lot trickier than I would have imagined. Here is the advice I finally came up with that seems to do what you want.

(defun widen-dwim (orig-func &rest args) (let* ((bmk-record (car args)) (file (bookmark-get-filename bmk-record))) (when file (with-current-buffer (find-file-noselect file) (widen))) (apply orig-func args) (when (string= "org" (file-name-extension (buffer-file-name))) (org-show-entry)))) (advice-add 'bookmark-default-handler :around 'widen-dwim) 
3
  • Note that bmkp-goto-position is a function in Bookmark+. You may want to post equivalent or similar code that uses only what is in vanilla bookmark.el, for people who do not want/need features offered by Bookmark+ Commented Oct 26, 2018 at 14:03
  • Good point. I updated the code. It works for me in a vanilla emacs. Commented Oct 26, 2018 at 15:10
  • @JohnKitchin Perfect. It now goes to the bookmark as expected. Commented Oct 29, 2018 at 7:49
0

If these are ordinary Emacs bookmarks, not something different, then you should be able to add a function to bookmark-after-jump-hook, to show the hidden stuff.

I'm no Org expert, but here's one suggestion:

(add-hook 'bookmark-after-jump-hook 'org-bookmark-jump-unhide) 
3
  • thanks. Yes. These are ordinary Emacs bookmarks, C-x r l shows these bookmarks. I tried your suggestion but it does not work. The cursor now goes to the end of narrowed region. Anything else that I might try? Commented Oct 26, 2018 at 4:36
  • Dunno. I don't use Org (ducks...). Do you mean that the cursor goes to the end of the narrowed region, which stays narrowed? If so, then clearly org-bookmark-jump-unhide is not the right function. But its doc says, at least, "Unhide the current position, to show the bookmark location." And it calls org-show-context, whose doc says, "Make sure point and context are visible..." Commented Oct 26, 2018 at 16:15
  • 1
    I am pretty sure org-bookmark-jump-unhide only deals with unhiding folded headings. That hook also happens too late to help with the narrowing issue. Commented Oct 26, 2018 at 17:21

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.