[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 6784185 17/57: Allow to use "^" in swiper
From: |
Oleh Krehel |
Subject: |
[elpa] master 6784185 17/57: Allow to use "^" in swiper |
Date: |
Tue, 19 May 2015 14:21:26 +0000 |
branch: master
commit 67841857c4cfeba45db57183158dd0759a632ec6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Allow to use "^" in swiper
* swiper.el (swiper--width): New defvar.
(swiper--candidates): Set `swiper--width'.
* ivy.el (ivy--transform-re): New defun - transform the regex
specifically for `swiper'.
(ivy--filter): Call `ivy--transform-re'.
* ivy-test.el (ivy--transform-re): Add test.
Fixes #82
---
ivy-test.el | 13 +++++++++++++
ivy.el | 18 +++++++++++++++++-
swiper.el | 6 +++++-
3 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 13a1467..fffc5fd 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -60,3 +60,16 @@
(ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
"z C-m")
"z")))
+
+(ert-deftest ivy--transform-re ()
+ (setq ivy-last
+ (make-ivy-state
+ :keymap swiper-map))
+ (setq swiper--width 4)
+ (setq ivy--regex-function #'ivy--regex-plus)
+ (should (string= (ivy--transform-re (funcall ivy--regex-function "^"))
+ "."))
+ (should (string= (ivy--transform-re (funcall ivy--regex-function "^a"))
+ "^[0-9 ]\\{5\\}a"))
+ (should (string= (ivy--transform-re (funcall ivy--regex-function "^a b"))
+ "\\(^[0-9 ]\\{5\\}a\\).*?\\(b\\)")))
diff --git a/ivy.el b/ivy.el
index 48dde66..a7e76e0 100644
--- a/ivy.el
+++ b/ivy.el
@@ -967,10 +967,26 @@ Should be run via minibuffer `post-command-hook'."
(font-lock-append-text-property 0 (length str) 'face face str))))
str)
+(defun ivy--transform-re (regex)
+ "Transform REGEX into another regex.
+This is a work-around for `swiper' and line starts."
+ (if (equal (ivy-state-keymap ivy-last) swiper-map)
+ (cond
+ ((equal regex "^")
+ ".")
+ ((string-match "^\\(?:\\\\(\\)?\\(\\^\\)" regex)
+ (setq ivy--old-re "")
+ (replace-match (format "^[0-9 ]\\{%d\\}"
+ (1+ swiper--width)) nil t regex 1))
+ (t
+ regex))
+ regex))
+
(defun ivy--filter (name candidates)
"Return all items that match NAME in CANDIDATES.
CANDIDATES are assumed to be static."
- (let* ((re (funcall ivy--regex-function name))
+ (let* ((re (ivy--transform-re
+ (funcall ivy--regex-function name)))
(cands (cond ((and (equal re ivy--old-re)
ivy--old-cands)
ivy--old-cands)
diff --git a/swiper.el b/swiper.el
index 2f8dc76..0879103 100644
--- a/swiper.el
+++ b/swiper.el
@@ -127,12 +127,16 @@
(defvar swiper--format-spec ""
"Store the current candidates format spec.")
+(defvar swiper--width nil
+ "Store the amount of digits needed for the longest line nubmer.")
+
(defun swiper--candidates ()
"Return a list of this buffer lines."
(let ((n-lines (count-lines (point-min) (point-max))))
(unless (zerop n-lines)
+ (setq swiper--width (1+ (floor (log n-lines 10))))
(setq swiper--format-spec
- (format "%%-%dd %%s" (1+ (floor (log n-lines 10)))))
+ (format "%%-%dd %%s" swiper--width))
(let ((line-number 0)
candidates)
(save-excursion
- [elpa] master 41bc3e8 03/57: Ignore case for "TAB", (continued)
- [elpa] master 41bc3e8 03/57: Ignore case for "TAB", Oleh Krehel, 2015/05/19
- [elpa] master 2c39e10 04/57: "TAB" shouldn't delete input when no candidate, Oleh Krehel, 2015/05/19
- [elpa] master 2d7f287 09/57: Improve "TAB" interaction with `confirm-nonexistent-file-or-buffer', Oleh Krehel, 2015/05/19
- [elpa] master 03ab827 07/57: Merge ivy--collection into ivy-last, Oleh Krehel, 2015/05/19
- [elpa] master dc219b3 12/57: Add counsel-load-library, Oleh Krehel, 2015/05/19
- [elpa] master 8b08cc0 08/57: ivy.el (ivy-done): Simplify and improve, Oleh Krehel, 2015/05/19
- [elpa] master cd083cc 18/57: Add swiper -> avy finalizer, Oleh Krehel, 2015/05/19
- [elpa] master f2a0966 16/57: Add ivy-partial: partial complete without exiting, Oleh Krehel, 2015/05/19
- [elpa] master 386184b 14/57: Merge ivy--update-fn into ivy-last, Oleh Krehel, 2015/05/19
- [elpa] master c5fce64 05/57: Make "TAB" switch directories properly, Oleh Krehel, 2015/05/19
- [elpa] master 6784185 17/57: Allow to use "^" in swiper,
Oleh Krehel <=
- [elpa] master fb3fce9 13/57: Add parents using 'display for `counsel-load-library', Oleh Krehel, 2015/05/19
- [elpa] master 5601653 06/57: Require dired when completing file names, Oleh Krehel, 2015/05/19
- [elpa] master 4a7ba2f 15/57: Try to prevent the resize of minibuffer window, Oleh Krehel, 2015/05/19
- [elpa] master 5a451a9 26/57: ivy.el (ivy-read): Add a re-builder argument, Oleh Krehel, 2015/05/19
- [elpa] master f7fc3ad 11/57: Work around grep-read-files, Oleh Krehel, 2015/05/19
- [elpa] master 056614d 22/57: Rename avy-swiper to swiper-avy, Oleh Krehel, 2015/05/19
- [elpa] master cf292da 23/57: Declare swiper-map, Oleh Krehel, 2015/05/19
- [elpa] master a953af0 19/57: Simplify ivy-partial-or-done, Oleh Krehel, 2015/05/19
- [elpa] master fe34d2c 10/57: ivy.el (ivy-partial-or-done): Handle empty input, Oleh Krehel, 2015/05/19
- [elpa] master 77abf00 25/57: ivy.el (ivy-backward-kill-word): Add and bind to "M-DEL", Oleh Krehel, 2015/05/19