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?

  • 1
    I guess you need to find out what command SPC f b runs, and put an advice before it to widen the buffer. 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 :)
    – deshmukh
    Oct 26, 2018 at 4:28

2 Answers 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)
    (apply orig-func args)
    (when (string= "org" (file-name-extension (buffer-file-name)))

(advice-add 'bookmark-default-handler :around 'widen-dwim)
  • 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+
    – Drew
    Oct 26, 2018 at 14:03
  • Good point. I updated the code. It works for me in a vanilla emacs. Oct 26, 2018 at 15:10
  • @JohnKitchin Perfect. It now goes to the bookmark as expected.
    – deshmukh
    Oct 29, 2018 at 7:49

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)
  • 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?
    – deshmukh
    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..."
    – Drew
    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. Oct 26, 2018 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.