[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4ac3736 243/272: New feature: virtual views in ivy-switch-
From: |
Oleh Krehel |
Subject: |
[elpa] master 4ac3736 243/272: New feature: virtual views in ivy-switch-buffer |
Date: |
Mon, 25 Apr 2016 10:13:28 +0000 |
branch: master
commit 4ac3736c996f7af2d3874891dd62c0743e242b52
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
New feature: virtual views in ivy-switch-buffer
* ivy.el (ivy-views): New defvar that stores the pre-defined views.
(ivy-source-views): New defun.
(ivy-set-view-recur): New defun.
(ivy--switch-buffer-action): Extend.
(ivy-set-sources): Attach `ivy-source-views' as an additional source to
`ivy-switch-buffer'.
How to use: just set `ivy-views' appropriately. An example value is
provided (but nulled, so that it's empty initially).
---
ivy.el | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 72 insertions(+), 6 deletions(-)
diff --git a/ivy.el b/ivy.el
index 7052f48..da89d97 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2538,6 +2538,67 @@ When VIRTUAL is non-nil, add virtual buffers."
(and virtual
(ivy--virtual-buffers)))))
+(defvar ivy-views (and nil
+ `(("ivy + *scratch* {}"
+ (vert
+ (file ,(expand-file-name "ivy.el"))
+ (buffer "*scratch*")))
+ ("swiper + *scratch* {}"
+ (horz
+ (file ,(expand-file-name "swiper.el"))
+ (buffer "*scratch*")))))
+ "Store window configurations selectable by `ivy-switch-buffer'.
+
+The default value is given as an example.
+
+Each element is a list of (NAME TREE). NAME is a string, it's
+recommended to end it with a distinctive snippet e.g. \"{}\" so
+that it's easy to distinguish the window configurations.
+
+TREE is a nested list with the following valid cars:
+- vert: split the window vertically
+- horz: split the window horizontally
+- file: open the specified file
+- buffer: open the specified buffer
+
+TREE can be nested multiple times to have mulitple window splits.")
+
+(defun ivy-source-views ()
+ (mapcar #'car ivy-views))
+
+(ivy-set-sources
+ 'ivy-switch-buffer
+ '((original-source)
+ (ivy-source-views)))
+
+(defun ivy-set-view-recur (view)
+ (cond ((eq (car view) 'vert)
+ (let ((wnd1 (selected-window))
+ (wnd2 (split-window-vertically)))
+ (with-selected-window wnd1
+ (ivy-set-view-recur (nth 1 view)))
+ (with-selected-window wnd2
+ (ivy-set-view-recur (nth 2 view)))))
+ ((eq (car view) 'horz)
+ (let ((wnd1 (selected-window))
+ (wnd2 (split-window-horizontally)))
+ (with-selected-window wnd1
+ (ivy-set-view-recur (nth 1 view)))
+ (with-selected-window wnd2
+ (ivy-set-view-recur (nth 2 view)))))
+ ((eq (car view) 'file)
+ (let* ((name (cadr view))
+ (virtual (assoc name ivy--virtual-buffers))
+ buffer)
+ (cond ((setq buffer (get-buffer name))
+ (switch-to-buffer buffer nil 'force-same-window))
+ (virtual
+ (find-file (cdr virtual)))
+ ((file-exists-p name)
+ (find-file name)))))
+ ((eq (car view) 'buffer)
+ (switch-to-buffer (cadr view)))))
+
(defun ivy--switch-buffer-action (buffer)
"Switch to BUFFER.
BUFFER may be a string or nil."
@@ -2545,12 +2606,17 @@ BUFFER may be a string or nil."
(if (zerop (length buffer))
(switch-to-buffer
ivy-text nil 'force-same-window)
- (let ((virtual (assoc buffer ivy--virtual-buffers)))
- (if (and virtual
- (not (get-buffer buffer)))
- (find-file (cdr virtual))
- (switch-to-buffer
- buffer nil 'force-same-window))))))
+ (let ((virtual (assoc buffer ivy--virtual-buffers))
+ (view (assoc buffer ivy-views)))
+ (cond ((and virtual
+ (not (get-buffer buffer)))
+ (find-file (cdr virtual)))
+ (view
+ (delete-other-windows)
+ (ivy-set-view-recur (cadr view)))
+ (t
+ (switch-to-buffer
+ buffer nil 'force-same-window)))))))
(defun ivy--switch-buffer-other-window-action (buffer)
"Switch to BUFFER in other window.
- [elpa] master ebd3fb9 254/272: Fix read-file-name with specified dir, (continued)
- [elpa] master ebd3fb9 254/272: Fix read-file-name with specified dir, Oleh Krehel, 2016/04/25
- [elpa] master 7dc86b3 084/272: Add a lot of sections to the documentation, Oleh Krehel, 2016/04/25
- [elpa] master d2a89ea 261/272: doc/ivy.org: Add a note on :predicate, Oleh Krehel, 2016/04/25
- [elpa] master 63a77ba 162/272: swiper.el (swiper-occur): Fix for non-file buffers, Oleh Krehel, 2016/04/25
- [elpa] master d899181 199/272: README.md: Add a section on Contributing, Oleh Krehel, 2016/04/25
- [elpa] master 119a151 242/272: Make "j"/"k" feedback more solid in ivy-occur buffers, Oleh Krehel, 2016/04/25
- [elpa] master 6a00275 187/272: ivy.el (ivy-switch-buffer-occur): Add, Oleh Krehel, 2016/04/25
- [elpa] master 181cd43 154/272: Add counsel-mode, Oleh Krehel, 2016/04/25
- [elpa] master 92b802f 176/272: counsel.el (counsel-ag): Add dir prompt for "C-u", Oleh Krehel, 2016/04/25
- [elpa] master 4998ba8 208/272: ivy.el (ivy-completing-read): Use the "t" key of ivy-sort-functions-alist, Oleh Krehel, 2016/04/25
- [elpa] master 4ac3736 243/272: New feature: virtual views in ivy-switch-buffer,
Oleh Krehel <=
- [elpa] master 46a00dc 227/272: Modified ivy to pass predicate when selecting buffers, Oleh Krehel, 2016/04/25
- [elpa] master b48a09d 245/272: Use Ivy to browse eshell and shell history entries, Oleh Krehel, 2016/04/25
- [elpa] master e7f41bb 236/272: swiper.el (swiper-mc): Remove interactive, Oleh Krehel, 2016/04/25
- [elpa] master 147ae80 096/272: Fix an extra action being called for `completing-read', Oleh Krehel, 2016/04/25
- [elpa] master c4b9e25 249/272: Add much faster scrolling to counsel-grep, Oleh Krehel, 2016/04/25
- [elpa] master 7f6d39f 193/272: counsel.el (counsel-linux-app-action-file): New action on "M-o f", Oleh Krehel, 2016/04/25
- [elpa] master ac4bedf 175/272: counsel.el (counsel-find-file): Bind "M-o f" to find-file-other-window, Oleh Krehel, 2016/04/25
- [elpa] master 41e2e41 246/272: Clean-up previous change, Oleh Krehel, 2016/04/25
- [elpa] master 90a09fa 086/272: doc/ivy.org: CUSTOM_ID should not end in "?", Oleh Krehel, 2016/04/25
- [elpa] master 6254e88 244/272: Allow a sexp node in ivy-views, Oleh Krehel, 2016/04/25