[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-hydra 69fedaa 098/395: counsel.el (counsel-esh-hist
From: |
Basil L. Contovounesios |
Subject: |
[elpa] externals/ivy-hydra 69fedaa 098/395: counsel.el (counsel-esh-history, counsel-shell-history): Set indices |
Date: |
Thu, 25 Feb 2021 08:31:40 -0500 (EST) |
branch: externals/ivy-hydra
commit 69fedaa67b6df93db899184d33cb225148b6c7b8
Author: Brian Leung <bkleung89@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>
counsel.el (counsel-esh-history, counsel-shell-history): Set indices
ivy.el (ivy-completion-in-region-action): Handle history pairs.
ivy.el (ivy-reverse-i-search): Update action to handle different type.
counsel.el (counsel-esh--index-last,
counsel-shell-history--index-last,
counsel-slime-repl-history--index-last): New variables.
counsel.el (counsel-set-eshell-history-index,
counsel-set-comint-history-index): New functions.
Fixes #2234
---
counsel.el | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
ivy.el | 21 +++++++++++++++----
2 files changed, 80 insertions(+), 11 deletions(-)
diff --git a/counsel.el b/counsel.el
index fa1afd4..76be2f8 100644
--- a/counsel.el
+++ b/counsel.el
@@ -4459,11 +4459,34 @@ An extra action allows to switch to the process buffer."
(let ((enable-recursive-minibuffers t))
(ivy-read "History: " (ivy-history-contents minibuffer-history-variable)
:keymap ivy-reverse-i-search-map
- :action #'insert
+ :action (lambda (x)
+ (insert (substring-no-properties (car x))))
:caller 'counsel-minibuffer-history)))
;;** `counsel-esh-history'
-(defun counsel--browse-history (ring)
+(defvar comint-input-ring-index)
+(defvar eshell-history-index)
+(defvar slime-repl-input-history-position)
+
+(defvar counsel-esh--index-last)
+(defvar counsel-shell-history--index-last)
+(defvar counsel-slime-repl-history--index-last)
+
+(defun counsel--browse-history-action (pair)
+ (let ((snd (cdr pair)))
+ (cl-case (ivy-state-caller ivy-last)
+ (counsel-esh-history
+ (setq eshell-history-index snd
+ counsel-esh--index-last snd))
+ (counsel-shell-history
+ (setq comint-input-ring-index snd
+ counsel-shell-history--index-last snd))
+ (counsel-slime-repl-history
+ (setq slime-repl-input-history-position snd
+ counsel-slime-repl-history--index-last snd)))
+ (ivy-completion-in-region-action (car pair))))
+
+(defun counsel--browse-history (ring &key caller)
"Use Ivy to navigate through RING."
(let* ((proc (get-buffer-process (current-buffer)))
(end (point))
@@ -4477,35 +4500,68 @@ An extra action allows to switch to the process buffer."
(ivy-read "History: " (ivy-history-contents ring)
:keymap ivy-reverse-i-search-map
:initial-input input
- :action #'ivy-completion-in-region-action
- :caller 'counsel-shell-history)))
+ :action #'counsel--browse-history-action
+ :caller caller)))
(defvar eshell-history-ring)
+(defvar eshell-matching-input-from-input-string)
+
+(defvar counsel-esh--index-last nil
+ "Index corresponding to last selection with `counsel-esh-history'.")
;;;###autoload
(defun counsel-esh-history ()
"Browse Eshell history."
(interactive)
(require 'em-hist)
- (counsel--browse-history eshell-history-ring))
+ (counsel--browse-history eshell-history-ring
+ :caller #'counsel-esh-history))
+
+(defadvice eshell-previous-matching-input (before
+ counsel-set-eshell-history-index
+ activate)
+ "Reassign `eshell-history-index'."
+ (when (and (memq last-command '(ivy-alt-done ivy-done))
+ (equal (ivy-state-caller ivy-last) 'counsel-esh-history))
+ (setq eshell-history-index counsel-esh--index-last)))
(defvar comint-input-ring)
+(defvar comint-matching-input-from-input-string)
+
+(defvar counsel-shell-history--index-last nil
+ "Index corresponding to last selection with `counsel-shell-history'.")
;;;###autoload
(defun counsel-shell-history ()
"Browse shell history."
(interactive)
(require 'comint)
- (counsel--browse-history comint-input-ring))
+ (counsel--browse-history comint-input-ring
+ :caller #'counsel-shell-history))
+
+(defadvice comint-previous-matching-input (before
+ counsel-set-comint-history-index
+ activate)
+ "Reassign `comint-input-ring-index'."
+ (when (and (memq last-command '(ivy-alt-done ivy-done))
+ (equal (ivy-state-caller ivy-last) 'counsel-shell-history))
+ (setq comint-input-ring-index counsel-shell-history--index-last)))
(defvar slime-repl-input-history)
+(defvar counsel-slime-repl-history--index-last nil
+ "Index corresponding to last selection with `counsel-slime-repl-history'.")
+
;;;###autoload
(defun counsel-slime-repl-history ()
"Browse Slime REPL history."
(interactive)
(require 'slime-repl)
- (counsel--browse-history slime-repl-input-history))
+ (counsel--browse-history slime-repl-input-history
+ :caller #'counsel-slime-repl-history))
+
+;; TODO: add advice for slime-repl-input-previous/next to properly
+;; reassign the ring index and match string
;;** `counsel-hydra-heads'
(defvar hydra-curr-body-fn)
diff --git a/ivy.el b/ivy.el
index fdabb01..88ad8ed 100644
--- a/ivy.el
+++ b/ivy.el
@@ -4644,6 +4644,19 @@ This list can be rotated with
`ivy-rotate-preferred-builders'."
(setq ivy--regex-function 'ivy--regex-plus)
(setq ivy--regex-function 'ivy--regex-fuzzy)))
+(defun ivy--label-and-delete-dups (entries)
+ "Label ENTRIES with history indices."
+ (let ((ht (make-hash-table :test 'equal))
+ (idx 0)
+ entry
+ accum)
+ (while (setq entry (pop entries))
+ (unless (gethash entry ht)
+ (puthash entry t ht)
+ (push `(,entry . ,idx) accum))
+ (cl-incf idx))
+ (nreverse accum)))
+
(defvar ivy--reverse-i-search-symbol nil
"Store the history symbol.")
@@ -4673,14 +4686,14 @@ A copy is necessary so that we don't clobber any string
attributes.
Also set `ivy--reverse-i-search-symbol' to HISTORY."
(setq ivy--reverse-i-search-symbol history)
(cond ((symbolp history)
- (delete-dups
+ (ivy--label-and-delete-dups
(copy-sequence (symbol-value history))))
((ring-p history)
- (delete-dups
+ (ivy--label-and-delete-dups
(when (> (ring-size history) 0)
(ring-elements history))))
((sequencep history)
- (delete-dups
+ (ivy--label-and-delete-dups
(copy-sequence history)))
(t
(error "Expected a symbol, ring, or sequence: %S" history))))
@@ -4708,7 +4721,7 @@ You can also delete an element from history with
\\[ivy-reverse-i-search-kill]."
(ivy--reset-state
(setq ivy-last old-last))
(delete-minibuffer-contents)
- (insert (substring-no-properties x))
+ (insert (substring-no-properties (car x)))
(ivy--cd-maybe))
:caller 'ivy-reverse-i-search)))))
- [elpa] externals/ivy-hydra 65f5783 395/395: Select files relevant for the ivy-hydra package, (continued)
- [elpa] externals/ivy-hydra 65f5783 395/395: Select files relevant for the ivy-hydra package, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 968eea5 057/395: ivy.el (ivy-partial-or-done): Check if completion-cycle-threshold is a number, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 9619e3c 340/395: counsel.el (counsel-compile-get-make-help-invocations): new helper, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 066ed7b 362/395: Added pretty counsel-linux-app-format-function, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 764b978 378/395: Revert last change to ivy-update-candidates, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra dab134d 229/395: ivy.el (ivy-read): Don't clear the first item of history, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 83ba4bd 089/395: counsel.el (counsel--switch-buffer-update-fn): Allow marking, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra c83f6bc 088/395: ivy.el (ivy-call): Don't modify ivy-marked-candidates, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra baac6e1 090/395: swiper.el (swiper--re-builder): Fix "^$" for swiper, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra cdd3995 100/395: ivy.el (ivy--buffer-list): Avoid unnecessarily touching remote connections, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 69fedaa 098/395: counsel.el (counsel-esh-history, counsel-shell-history): Set indices,
Basil L. Contovounesios <=
- [elpa] externals/ivy-hydra 32019df 102/395: ivy.el (ivy-read-action-by-key): Allow to read e.g. C-d, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 6941b8a 214/395: Revert ".dir-locals.el (outline-regexp): "^(" is not an outline start", Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 93929ec 257/395: * ivy.el (ivy--shorter-matches-first): Simplify, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1b6f3cf 244/395: Improve ivy-switch-buffer-transformer, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 68ce6e6 384/395: Mention caveats for non-exiting commands in manual, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1deef76 394/395: Bump version to point release 0.13.2, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 4235010 387/395: Re-revert last change to ivy-update-candidates, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra d8ed11e 388/395: Make ivy-switch-buffer-kill respect current predicate, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra c1a61dc 084/395: ivy-test.el (ivy-empty-directory-open): Test opening empty directory, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 316d4dd 232/395: counsel-kmacro: Create actions for cycling the ring and setting a saved counter value., Basil L. Contovounesios, 2021/02/25