1

I am trying to write a function which will perform a bookmark-jump but then reset the the bookmark line to the top of the screen. So far I have:

  (defun foo ()
    (interactive)
    (bookmark-jump)
    (evil-scroll-line-to-top nil)
    )

  (define-key evil-normal-state-map [f9] 'foo)

But hitting F9 gives this message. What am I doing wrong please?

enter image description here

5
  • bookmark-jump needs a bookmark as argument: do C-h f bookmark-jump RET to see its doc string.
    – NickD
    Oct 22, 2020 at 23:41
  • In which case how come I can do M-x bookmark-jump<Enter>? Oct 23, 2020 at 14:02
  • 1
    When I do M-x bookmark-jump it asks me for a bookmark to jump to.
    – NickD
    Oct 23, 2020 at 14:51
  • Agreed. Which is why I don't get that calling the same command from script doesn't do the same thing. I would expect calling it from script to prompt me for a bookmark also. Oct 23, 2020 at 17:03
  • You need to use call-interactively for that as @Drew points out.
    – NickD
    Oct 23, 2020 at 17:31

1 Answer 1

0

Your command needs to call bookmark-jump interactively, so it can prompt for the bookmark you want to jump to. It requires a bookmark, to know where to take you.

(defun foo ()
    (interactive)
    (call-interactively #'bookmark-jump)
    (message "XXXXXXXXXX"))

On the other hand, if you always want foo to jump to the same bookmark, and you know which bookmark that is:

(defun foo ()
    (interactive)
    (bookmark-jump "my-bookmark-name")
    (message "XXXXXXXXXX"))
3
  • Thanks, I think this is what I need. I notice an issue though, which occurs calling the first foo function above and when doing M-x bookmark-jump: if the bookmark is in a buffer other than the visible one, the bookmarked buffer gets focus but the cursor position is unchanged - in other words the jump visits the correct buffer but not the correct location. Oct 23, 2020 at 18:57
  • You comment suggests a bug somewhere. Is this Emacs bug #44185? Does your recipe's "Start Emacs" use emacs -Q? If not, provide a recipe to repro the problem that does start with that (i.e., no init file).
    – Drew
    Oct 23, 2020 at 22:10
  • Yes, I submitted that bug report. Apologies if the recipe did not start with with emacs -Q, it should have. Oct 23, 2020 at 23:22

Your Answer

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

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