Often, the git repos I work in have a similar layout (for example every python project has a setup.py with an install_requires line in it).

Is it possible to add a bookmark that points to a similar line in a file relative to (projectile-project-root)? Is it possible to have this only appear in the bookmark list if I am visiting a file in the right sort of repository?


We might have directories

  • /home/user/node-project1
  • /home/user/node-project2
  • /home/user/c-project1
  • /home/user/c-project2
  • /home/user/python-project1
  • /home/user/python-project1

In the c projects I might want to jump to (projectile-project-root)/Makefile but not in python or node projects. You might want to jump to the all: target.

In python projects I might want to jump (projectile-project-root)/setup.py but not in c or node projects. I might want to jump to the install_requires line.

In node projects I might want to jump to (projectile-project-root)/package.json, but not in c or python projects. I might want to jump to the "dependencies": { line.


Not quite sure what you're asking. Yes, you can have a bookmark that points to any position in any line in any file. But what do you mean by "have this only show up"?

If you are asking about whether a given bookmark is present in your displayed bookmark list (what you see with C-x r l) then yes, you can control that. One simple way to do that is to have multiple bookmark files.

If you use Bookmark+ then this kind of thing becomes easier. You can more easily have multiple bookmark files. You can more easily switch among them - including by bookmarking those files themselves (bookmark-file bookmarks), so you just jump to a bookmark to switch bookmark files.

You can also bookmark different bookmark-list display views. So you can, for example, hide some bookmarks from the display and then bookmark the resulting view, so that jumping to that bookmark-list bookmark gives you that view that hides particular bookmarks.

There are lots of possibilities. But you might want to try to make your question a bit clearer (more specific), to help you get better answers.

  • Thanks. I've updated the question taking your comments into account. I guess the conditional display of bookmarks could be achieved by having bookmark files be loaded depending upon the project type. I would prefer not to have a bookmark file for each separate repo, so this means I need some sort of "relative" bookmark. I guess what I'm really after is arbitrary control over what a bookmark does.
    – Att Righ
    Jan 11 '18 at 18:12
  • 1
    A bookmark itself can be any Lisp function (it is a function bookmark), which can use any conditional logic you want.
    – Drew
    Jan 11 '18 at 22:48
  • That looks like what I'm after. I'm using bmkp-make-function-bookmark. The following creates a bookmark that jumps to install_requires in setup.py relative to the project root (bmkp-make-function-bookmark "setup.py" (lambda () (find-file (expand-file-name "setup.py" (projectile-project-root))) (search-forward-regexp "install_requires")))
    – Att Righ
    Jan 12 '18 at 0:46
  • See also sequence bookmarks.
    – Drew
    Jan 12 '18 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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