emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/vlf 375c96f 018/310: Add backward whole file search.


From: Stefan Monnier
Subject: [elpa] externals/vlf 375c96f 018/310: Add backward whole file search.
Date: Sat, 28 Nov 2020 00:32:38 -0500 (EST)

branch: externals/vlf
commit 375c96f89be16e03e0f1db18d1673cff52baa338
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>

    Add backward whole file search.
---
 vlfi.el | 47 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/vlfi.el b/vlfi.el
index e6dd2db..537fcbe 100644
--- a/vlfi.el
+++ b/vlfi.el
@@ -62,6 +62,7 @@
         (interactive)
         (vlfi-change-batch-size t)))
     (define-key map "\C-c\C-s" 'vlfi-re-search-forward)
+    (define-key map "\C-c\C-r" 'vlfi-re-search-backward)
     map)
   "Keymap for `vlfi-mode'.")
 
@@ -222,26 +223,38 @@ OP-TYPE specifies the file operation being performed over 
FILENAME."
 (fset 'abort-if-file-too-large 'vlfi-if-file-too-large)
 
 ;;; search
-(defun vlfi-re-search-forward (regexp &optional count)
-  "Search for REGEXP COUNT number of times."
-  (interactive "sSearch: \np")
+(defun vlfi-re-search (regexp backward count)
+  "Search for REGEXP BACKWARD or forward COUNT number of times."
   (let ((start vlfi-start-pos)
         (end vlfi-end-pos)
         (pos (point))
         (to-find count)
         (search-reporter (make-progress-reporter
                           (concat "Searching for " regexp)
-                          vlfi-start-pos vlfi-file-size)))
+                          (if backward
+                              (- vlfi-file-size vlfi-start-pos)
+                            vlfi-start-pos)
+                          vlfi-file-size)))
     (unwind-protect
         (catch 'end-of-file
-          (while (not (zerop to-find))
-            (cond ((re-search-forward regexp nil t)
-                   (setq to-find (1- to-find)))
-                  ((= vlfi-end-pos vlfi-file-size)
-                   (throw 'end-of-file nil))
-                  (t (vlfi-next-batch 1)
-                     (progress-reporter-update search-reporter
-                                               vlfi-end-pos)))))
+          (if backward
+              (while (not (zerop to-find))
+                (cond ((re-search-backward regexp nil t)
+                       (setq to-find (1- to-find)))
+                      ((zerop vlfi-start-pos)
+                       (throw 'end-of-file nil))
+                      (t (vlfi-prev-batch 1)
+                         (progress-reporter-update
+                          search-reporter (- vlfi-file-size
+                                             vlfi-end-pos)))))
+            (while (not (zerop to-find))
+              (cond ((re-search-forward regexp nil t)
+                     (setq to-find (1- to-find)))
+                    ((= vlfi-end-pos vlfi-file-size)
+                     (throw 'end-of-file nil))
+                    (t (vlfi-next-batch 1)
+                       (progress-reporter-update search-reporter
+                                                 vlfi-end-pos))))))
       (progress-reporter-done search-reporter)
       (or (zerop to-find)
           (if (< to-find count)
@@ -257,6 +270,16 @@ OP-TYPE specifies the file operation being performed over 
FILENAME."
             (vlfi-update-buffer-name)
             (message "Not found"))))))
 
+(defun vlfi-re-search-forward (regexp count)
+  "Search forward for REGEXP COUNT number of times."
+  (interactive "sSearch whole file: \np")
+  (vlfi-re-search regexp nil count))
+
+(defun vlfi-re-search-backward (regexp count)
+  "Search backward for REGEXP COUNT number of times."
+  (interactive "sSearch whole file backward: \np")
+  (vlfi-re-search regexp t count))
+
 (provide 'vlfi)
 
 ;;; vlfi.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]