summaryrefslogtreecommitdiff
path: root/lisp/init-projectile.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-02-20 23:52:32 -0500
committerKyle Meyer <kyle@kyleam.com>2015-02-28 00:29:49 -0500
commit69d32ae7c455b67391d1e19bacac172533c47b07 (patch)
tree5b80abc023ff64d6a35a002d7574d4e74971e723 /lisp/init-projectile.el
parent0904a666fbb935f47a86b4abd4798a0c0d66bccd (diff)
downloademacs.d-69d32ae7c455b67391d1e19bacac172533c47b07.tar.gz
Add projectile-project-save-thing
Add commands to save and restore a buffer, file, or window configuration for a project. Projectile supports restoring window configuration with persp-projectile.el. (A recent change to Projectile [1] removed projectile-remember-window-configs in favor of using perspective.el.) However, I want to explicitly choose which (if any) window configuration is saved for a project and also want the ability to save buffers or files. [1] c94c5f5ad385f58682c2ac3414066ec24dd75abe
Diffstat (limited to 'lisp/init-projectile.el')
-rw-r--r--lisp/init-projectile.el68
1 files changed, 68 insertions, 0 deletions
diff --git a/lisp/init-projectile.el b/lisp/init-projectile.el
index cb13af1..84614aa 100644
--- a/lisp/init-projectile.el
+++ b/lisp/init-projectile.el
@@ -49,11 +49,70 @@ Interactive arguments are processed according to
(kill-new fname))
(message "%s" fname)))
+(defvar km/projectile-project-saved-thing nil
+ "Property list of saved thing for projects.
+The keys are project roots (strings), so use `lax-plist-put' and
+`lax-plist-get'.")
+
+(defun km/projectile-save-thing (thing)
+ "Save thing for current project.
+
+Thing is a character representing
+- . point marker
+- (b)uffer
+- (f)ile
+- (w)indow configuration
+
+- (d)elete saved thing"
+ (interactive (list
+ (let ((letters '(?. ?b ?f ?w ?d)))
+ (read-char-choice (concat "Save [" letters "]: ")
+ letters))))
+ (let ((value (cl-case thing
+ (?.
+ (point-marker))
+ (?b
+ (current-buffer))
+ (?f
+ (buffer-file-name))
+ (?w
+ (current-window-configuration))
+ (?d nil))))
+ (setq km/projectile-project-saved-thing
+ (lax-plist-put km/projectile-project-saved-thing
+ (projectile-project-root)
+ (cons thing value)))))
+
+(defun km/projectile-restore-thing ()
+ "Restore saved thing for current project.
+Return nil if there is no thing saved for the current project."
+ (interactive)
+ (-when-let* ((thing-value (lax-plist-get km/projectile-project-saved-thing
+ (projectile-project-root)))
+ (thing (car thing-value))
+ (value (cdr thing-value)))
+ (cl-case thing
+ (?.
+ (-if-let (buf (marker-buffer value))
+ (progn (switch-to-buffer buf)
+ (goto-char value))
+ (user-error "Buffer no longer exists")))
+ (?b
+ (if (buffer-live-p value)
+ (switch-to-buffer value)
+ (user-error "Buffer no longer exists")))
+ (?f
+ (find-file value))
+ (?w
+ (set-window-configuration value)))
+ t))
+
(define-key projectile-command-map (kbd "4 v")
'km/projectile-view-file-other-window)
(define-key projectile-command-map "."
'km/projectile-copy-project-filename-as-kill)
+(define-key projectile-command-map "e" 'km/projectile-restore-thing)
;; This overrides `projectile-find-file-dwim'.
(define-key projectile-command-map "g" 'projectile-vc)
;; Swap `projectile-invalidate-cache' and `projectile-ibuffer'.
@@ -66,6 +125,7 @@ Interactive arguments are processed according to
(define-key projectile-command-map "s" 'projectile-grep)
;; This overrides `projectile-vc', which is now on 'g'.
(define-key projectile-command-map "v" 'km/projectile-view-file)
+(define-key projectile-command-map "w" 'km/projectile-save-thing)
(key-chord-define-global "jq" 'projectile-commander)
(key-chord-define-global "gp" 'projectile-switch-project)
@@ -101,6 +161,10 @@ Interactive arguments are processed according to
"Find a project directory in other window."
(call-interactively 'projectile-find-dir-other-window))
+(def-projectile-commander-method ?e
+ "Restore saved thing."
+ (km/projectile-restore-thing))
+
(def-projectile-commander-method ?F
"Find project file in other window."
(call-interactively 'projectile-find-file-other-window))
@@ -137,6 +201,10 @@ Interactive arguments are processed according to
"View project file in other window."
(km/projectile-view-file-other-window))
+(def-projectile-commander-method ?w
+ "Save thing."
+ (call-interactively #'km/projectile-save-thing))
+
(projectile-global-mode)
(provide 'init-projectile)