[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 478e4e4 32/54: Make line numbers in swiper into display pr
From: |
Oleh Krehel |
Subject: |
[elpa] master 478e4e4 32/54: Make line numbers in swiper into display properties |
Date: |
Tue, 29 Sep 2015 14:09:58 +0000 |
branch: master
commit 478e4e4fe29abf11fd3ccbf9a8c10c9a1cb34dfc
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Make line numbers in swiper into display properties
* swiper.el (swiper--candidates): Each candidate is now a single space
plus the original string. The display property of the single space
holds the line number. This means that it's no longer possible to
match line numbers in queries. Also, the preselect of the current line
is slightly worse (in case there are two identical lines in a buffer).
(swiper--ivy): Update the preselect to not include the line
number. Also, call `ivy--action' on `ivy-current' instead of `res',
because `res' doesn't have the string property that points to the line
number.
(swiper--update-input-ivy): Update.
(swiper--action): Update.
Fixes #224
---
swiper.el | 70 ++++++++++++++++++++++++++++++------------------------------
1 files changed, 35 insertions(+), 35 deletions(-)
diff --git a/swiper.el b/swiper.el
index ac1b0cc..258b530 100644
--- a/swiper.el
+++ b/swiper.el
@@ -191,19 +191,21 @@
(unless (zerop n-lines)
(setq swiper--width (1+ (floor (log n-lines 10))))
(setq swiper--format-spec
- (format "%%-%dd %%s" swiper--width))
+ (format "%%-%dd " swiper--width))
(let ((line-number 0)
candidates)
(save-excursion
(goto-char (point-min))
(swiper-font-lock-ensure)
(while (< (point) (point-max))
- (push (format swiper--format-spec
- (cl-incf line-number)
- (buffer-substring
- (line-beginning-position)
- (line-end-position)))
- candidates)
+ (let ((str (concat " " (buffer-substring
+ (line-beginning-position)
+ (line-end-position)))))
+ (put-text-property 0 1 'display
+ (format swiper--format-spec
+ (cl-incf line-number))
+ str)
+ (push str candidates))
(forward-line 1))
(nreverse candidates))))))
@@ -262,12 +264,9 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
Please remove it and update the \"swiper\" package."))
(swiper--init)
(let ((candidates (swiper--candidates))
- (preselect (format
- swiper--format-spec
- (line-number-at-pos)
- (buffer-substring-no-properties
- (line-beginning-position)
- (line-end-position))))
+ (preselect (buffer-substring-no-properties
+ (line-beginning-position)
+ (line-end-position)))
res)
(unwind-protect
(setq res (ivy-read
@@ -283,7 +282,7 @@ Please remove it and update the \"swiper\" package."))
:history 'swiper-history))
(if (null ivy-exit)
(goto-char swiper--opoint)
- (swiper--action res ivy-text)))))
+ (swiper--action ivy--current ivy-text)))))
(defun swiper--ensure-visible ()
"Remove overlays hiding point."
@@ -309,27 +308,28 @@ Please remove it and update the \"swiper\" package."))
"Called when `ivy' input is updated."
(with-ivy-window
(swiper--cleanup)
- (let* ((re (funcall ivy--regex-function ivy-text))
- (re (if (stringp re) re (caar re)))
- (str ivy--current)
- (num (if (string-match "^[0-9]+" str)
- (string-to-number (match-string 0 str))
- 0)))
- (goto-char (point-min))
- (when (cl-plusp num)
+ (when (> (length ivy--current) 0)
+ (let* ((re (funcall ivy--regex-function ivy-text))
+ (re (if (stringp re) re (caar re)))
+ (str (get-text-property 0 'display ivy--current))
+ (num (if (string-match "^[0-9]+" str)
+ (string-to-number (match-string 0 str))
+ 0)))
(goto-char (point-min))
- (forward-line (1- num))
- (if (and (equal ivy-text "")
- (>= swiper--opoint (line-beginning-position))
- (<= swiper--opoint (line-end-position)))
- (goto-char swiper--opoint)
- (re-search-forward re (line-end-position) t))
- (isearch-range-invisible (line-beginning-position)
- (line-end-position))
- (unless (and (>= (point) (window-start))
- (<= (point) (window-end (ivy-state-window ivy-last) t)))
- (recenter)))
- (swiper--add-overlays re))))
+ (when (cl-plusp num)
+ (goto-char (point-min))
+ (forward-line (1- num))
+ (if (and (equal ivy-text "")
+ (>= swiper--opoint (line-beginning-position))
+ (<= swiper--opoint (line-end-position)))
+ (goto-char swiper--opoint)
+ (re-search-forward re (line-end-position) t))
+ (isearch-range-invisible (line-beginning-position)
+ (line-end-position))
+ (unless (and (>= (point) (window-start))
+ (<= (point) (window-end (ivy-state-window ivy-last) t)))
+ (recenter)))
+ (swiper--add-overlays re)))))
(defun swiper--add-overlays (re &optional beg end)
"Add overlays for RE regexp in visible part of the current buffer.
@@ -377,7 +377,7 @@ BEG and END, when specified, are the point bounds."
(if (null x)
(user-error "No candidates")
(goto-char (point-min))
- (forward-line (1- (read x)))
+ (forward-line (1- (read (get-text-property 0 'display x))))
(re-search-forward
(ivy--regex input) (line-end-position) t)
(swiper--ensure-visible)
- [elpa] master 39dfc80 05/54: Fix :dynamic-collection not being sorted, (continued)
- [elpa] master 39dfc80 05/54: Fix :dynamic-collection not being sorted, Oleh Krehel, 2015/10/07
- [elpa] master 970b984 01/54: Fix up ivy-recentf and ivy-switch-buffer window-wise, Oleh Krehel, 2015/10/07
- [elpa] master b844b69 19/54: ivy.el (ivy--format-minibuffer-line): Use add-face-text-property, Oleh Krehel, 2015/10/07
- [elpa] master c78a306 09/54: ivy.el (ivy-kill-ring-save): Add and bind to "M-w", Oleh Krehel, 2015/10/07
- [elpa] master 6bf2913 25/54: Declare some SLIME functions, Oleh Krehel, 2015/10/07
- [elpa] master 5db65db 34/54: swiper.el (swiper--ivy): Fix compiler warning, Oleh Krehel, 2015/10/07
- [elpa] master 05d5e63 02/54: (counsel-locate): Allow customizing locate options, Oleh Krehel, 2015/10/07
- [elpa] master 33fa81e 14/54: counsel.el (counsel-jedi): New command, Oleh Krehel, 2015/10/07
- [elpa] master 435f2b6 38/54: Add work-around for minibuffer not re-sizing for many frames, Oleh Krehel, 2015/10/07
- [elpa] master 438e51d 24/54: counsel.el (counsel-git-grep-function): Fix up, Oleh Krehel, 2015/10/07
- [elpa] master 478e4e4 32/54: Make line numbers in swiper into display properties,
Oleh Krehel <=
- [elpa] master 8fccfd3 03/54: (counsel-locate): Support OS X, Oleh Krehel, 2015/10/07
- [elpa] master 7684455 15/54: counsel.el (counsel--py-action): Work with "C-M-n", Oleh Krehel, 2015/10/07
- [elpa] master 9a509df 47/54: ivy.el (ivy--resize-minibuffer-to-fit): Make compatible with 24.3, Oleh Krehel, 2015/10/07
- [elpa] master d5ae6a3 30/54: ivy.el (ivy--resize-minibuffer-to-fit): Make compatible with 24.3, Oleh Krehel, 2015/10/07
- [elpa] master d8d7ed4 42/54: Fix minibuffer collapses to one line, Oleh Krehel, 2015/10/07
- [elpa] master db8fb1b 39/54: Make "<left>" and "<right>" behave as in fundamental-mode, Oleh Krehel, 2015/10/07
- [elpa] master 8b73497 54/54: Merge commit 'ba49407c5b4c719dd5dcc298c260513abf0c70df' from swiper, Oleh Krehel, 2015/10/07
- [elpa] master 9413acb 52/54: counsel.el (counsel--find-symbol): Allow to jump back with pop-tag-mark, Oleh Krehel, 2015/10/07
- [elpa] master aa3e1dd 51/54: swiper.el (swiper-font-lock-ensure): Add mu4e, Oleh Krehel, 2015/10/07
- [elpa] master 680f6e2 44/54: swiper.el (swiper--ivy): Use minibuffer-allow-text-properties, Oleh Krehel, 2015/10/07