blob: 26c20399e2d4f45e201d21e6e79c9f7a073e773a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
;;; bookmark.el --- Saved files and directories on my filesystem -*- lexical-binding: t -*-
;; Author: William Carroll <wpcarro@gmail.com>
;; Version: 0.0.1
;; Package-Requires: ((emacs "24.3"))
;;; Commentary:
;; After enjoying and relying on Emacs's builtin `jump-to-register' command, I'd
;; like to recreate this functionality with a few extensions.
;;
;; Everything herein will mimmick my previous KBDs for `jump-to-register', which
;; were <leader>-j-<register-kbd>. If the `bookmark-path' is a file, Emacs will
;; open a buffer with that file. If the `bookmark-path' is a directory, Emacs
;; will open an ivy window searching that directory.
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dependencies
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'f)
(require 'buffer)
(require 'list)
(require 'string)
(require 'set)
(require 'constants)
(require 'general)
(require 'tvl)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cl-defstruct bookmark label path kbd)
(defun bookmark-handle-directory-dwim (path)
"Open PATH as either a project directory or a regular directory."
(with-temp-buffer
(cd path)
(call-interactively #'project-find-file)))
(defconst bookmark-handle-directory #'bookmark-handle-directory-dwim
"Function to call when a bookmark points to a directory.")
(defconst bookmark-handle-file #'counsel-find-file-action
"Function to call when a bookmark points to a file.")
(defconst bookmark-whitelist
(list
(make-bookmark :label "depot"
:path tvl-depot-path
:kbd "d"))
"List of registered bookmarks.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; API
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun bookmark-open (b)
"Open bookmark, B, in a new buffer or an ivy minibuffer."
(let ((path (bookmark-path b)))
(cond
((f-directory? path)
(funcall bookmark-handle-directory path))
((f-file? path)
(funcall bookmark-handle-file path)))))
(defun bookmark-install-kbds ()
"Install the keybindings defined herein."
(->> bookmark-whitelist
(list-map
(lambda (b)
(general-define-key
:prefix "<SPC>"
:states '(normal)
(format "J%s" (bookmark-kbd b))
(lambda () (interactive) (find-file (bookmark-path b)))
(format "j%s" (bookmark-kbd b))
;; TODO: Consider `cl-labels' so `which-key' minibuffer is more
;; helpful.
(lambda () (interactive) (bookmark-open b)))))))
(provide 'bookmark)
;;; bookmark.el ends here
|