[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 8818a01 36/67: swiper.el: Fix error for empty buffer
From: |
Oleh Krehel |
Subject: |
[elpa] master 8818a01 36/67: swiper.el: Fix error for empty buffer |
Date: |
Sun, 22 Mar 2015 17:34:01 +0000 |
branch: master
commit 8818a01c1c60aae892c206963cbbb978e6de97fd
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
swiper.el: Fix error for empty buffer
* swiper.el (swiper--candidates): Update.
(swiper--action): Update.
Fixes #17.
---
swiper.el | 56 +++++++++++++++++++++++++++++---------------------------
1 files changed, 29 insertions(+), 27 deletions(-)
diff --git a/swiper.el b/swiper.el
index af6dc04..4a01239 100644
--- a/swiper.el
+++ b/swiper.el
@@ -84,24 +84,24 @@
(defun swiper--candidates ()
"Return a list of this buffer lines."
- (let* ((line-width (1+ (floor (log (count-lines
- (point-min) (point-max))
- 10))))
- (fspec (format "%%-%dd %%s" line-width))
- (line-number 0)
- candidates)
- (save-excursion
- (goto-char (point-min))
- (swiper-font-lock-ensure)
- (while (< (point) (point-max))
- (push (format fspec
- (cl-incf line-number)
- (buffer-substring
- (line-beginning-position)
- (line-end-position)))
- candidates)
- (zerop (forward-line 1)))
- (nreverse candidates))))
+ (let ((n-lines (count-lines (point-min) (point-max))))
+ (unless (zerop n-lines)
+ (let* ((line-width (1+ (floor (log n-lines 10))))
+ (fspec (format "%%-%dd %%s" line-width))
+ (line-number 0)
+ candidates)
+ (save-excursion
+ (goto-char (point-min))
+ (swiper-font-lock-ensure)
+ (while (< (point) (point-max))
+ (push (format fspec
+ (cl-incf line-number)
+ (buffer-substring
+ (line-beginning-position)
+ (line-end-position)))
+ candidates)
+ (zerop (forward-line 1)))
+ (nreverse candidates))))))
(defvar swiper-helm-keymap
(let ((map (make-sparse-keymap)))
@@ -363,15 +363,17 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
(defun swiper--action (x input)
"Goto line X and search for input."
- (goto-char (point-min))
- (forward-line (1- (read x)))
- (re-search-forward
- (ivy--regex input) (line-end-position) t)
- (swiper--ensure-visible)
- (when (/= (point) swiper--opoint)
- (unless (and transient-mark-mode mark-active)
- (push-mark swiper--opoint t)
- (message "Mark saved where search started"))))
+ (if (null x)
+ (user-error "No candidates")
+ (goto-char (point-min))
+ (forward-line (1- (read x)))
+ (re-search-forward
+ (ivy--regex input) (line-end-position) t)
+ (swiper--ensure-visible)
+ (when (/= (point) swiper--opoint)
+ (unless (and transient-mark-mode mark-active)
+ (push-mark swiper--opoint t)
+ (message "Mark saved where search started")))))
(provide 'swiper)
- [elpa] master baa9df7 30/67: Truncate candidates to window width in the minibuffer, (continued)
- [elpa] master baa9df7 30/67: Truncate candidates to window width in the minibuffer, Oleh Krehel, 2015/03/22
- [elpa] master 7c6d00d 32/67: ivy.el (ivy-read): Return immediately for less than 2 candidates, Oleh Krehel, 2015/03/22
- [elpa] master 315be36 31/67: counsel.el: Add, Oleh Krehel, 2015/03/22
- [elpa] master 0772929 29/67: Add some rudimentary history handling, Oleh Krehel, 2015/03/22
- [elpa] master 045fb60 28/67: ivy.el (ivy-previous-line): Change to `cl-decf', Oleh Krehel, 2015/03/22
- [elpa] master e1cdb29 37/67: counsel.el: Add Clojure completion at point, Oleh Krehel, 2015/03/22
- [elpa] master 7ff3dd9 35/67: Need to check value of variable, Oleh Krehel, 2015/03/22
- [elpa] master c78cc15 34/67: swiper.el: Clean up overlays better on "C-g", Oleh Krehel, 2015/03/22
- [elpa] master e7b560c 38/67: swiper.el (swiper--opoint): Fix bad defvar, Oleh Krehel, 2015/03/22
- [elpa] master d78caee 33/67: Open invisible overlays using isearch, Oleh Krehel, 2015/03/22
- [elpa] master 8818a01 36/67: swiper.el: Fix error for empty buffer,
Oleh Krehel <=
- [elpa] master 984346c 40/67: swiper.el (swiper-font-lock-ensure): Exclude a few modes, Oleh Krehel, 2015/03/22
- [elpa] master cb26121 41/67: ivy.el: Fix ivy-history recording the full text instead of input, Oleh Krehel, 2015/03/22
- [elpa] master de80846 39/67: Work around magit highlighting problem, Oleh Krehel, 2015/03/22
- [elpa] master 7bb5320 42/67: swiper.el (swiper--helm): Require helm-match-plugin, Oleh Krehel, 2015/03/22
- [elpa] master caa69f2 43/67: counsel.el: Add git file completion, Oleh Krehel, 2015/03/22
- [elpa] master fcb18e5 44/67: ivy.el (ivy-read): Bring last history candidate to front, Oleh Krehel, 2015/03/22
- [elpa] master e32bc63 46/67: swiper.el: Fix non-matching lines issue with initial-input, Oleh Krehel, 2015/03/22
- [elpa] master f1672c7 45/67: Add isearch-like history behavior, Oleh Krehel, 2015/03/22
- [elpa] master 41732be 48/67: ivy.el: Return nil when there is no match, Oleh Krehel, 2015/03/22
- [elpa] master 588dab6 49/67: ivy-test.el: Add testing, Oleh Krehel, 2015/03/22