Skip to content

Instantly share code, notes, and snippets.

@gilbertw1
Created June 6, 2018 16:23
Show Gist options
  • Save gilbertw1/9fe4f6380fb0c95e38e30fdff2dfb6fb to your computer and use it in GitHub Desktop.
Save gilbertw1/9fe4f6380fb0c95e38e30fdff2dfb6fb to your computer and use it in GitHub Desktop.
(defun counsel-projectile-bookmark ()
"Forward to `bookmark-jump' or `bookmark-set' if bookmark doesn't exist."
(interactive)
(require 'bookmark)
(let ((projectile-bookmarks (projectile-bookmarks)))
(ivy-read "Create or jump to bookmark: "
projectile-bookmarks
:action (lambda (x)
(cond ((and counsel-bookmark-avoid-dired
(member x projectile-bookmarks)
(file-directory-p (bookmark-location x)))
(with-ivy-window
(let ((default-directory (bookmark-location x)))
(counsel-find-file))))
((member x projectile-bookmarks)
(with-ivy-window
(bookmark-jump x)))
(t
(bookmark-set x))))
:caller 'counsel-projectile-bookmark)))
(ivy-set-actions
'counsel-projectile-bookmark
'(("d" bookmark-delete "delete")
("e" bookmark-rename "edit")))
(defun projectile-bookmarks ()
(let ((bmarks (bookmark-all-names)))
(cl-remove-if-not #'workspace-bookmark-p bmarks)))
(defun workspace-bookmark-p (bmark)
(let ((bmark-path (expand-file-name (bookmark-location bmark))))
(string-prefix-p (bmacs-project-root) bmark-path)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment