mirror of
				https://github.com/m00natic/vlfi.git
				synced 2025-10-30 06:33:37 +00:00 
			
		
		
		
	Add backward whole file search.
This commit is contained in:
		
							
								
								
									
										47
									
								
								vlfi.el
									
									
									
									
									
								
							
							
						
						
									
										47
									
								
								vlfi.el
									
									
									
									
									
								
							| @@ -62,6 +62,7 @@ | |||||||
|         (interactive) |         (interactive) | ||||||
|         (vlfi-change-batch-size t))) |         (vlfi-change-batch-size t))) | ||||||
|     (define-key map "\C-c\C-s" 'vlfi-re-search-forward) |     (define-key map "\C-c\C-s" 'vlfi-re-search-forward) | ||||||
|  |     (define-key map "\C-c\C-r" 'vlfi-re-search-backward) | ||||||
|     map) |     map) | ||||||
|   "Keymap for `vlfi-mode'.") |   "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) | (fset 'abort-if-file-too-large 'vlfi-if-file-too-large) | ||||||
|  |  | ||||||
| ;;; search | ;;; search | ||||||
| (defun vlfi-re-search-forward (regexp &optional count) | (defun vlfi-re-search (regexp backward count) | ||||||
|   "Search for REGEXP COUNT number of times." |   "Search for REGEXP BACKWARD or forward COUNT number of times." | ||||||
|   (interactive "sSearch: \np") |  | ||||||
|   (let ((start vlfi-start-pos) |   (let ((start vlfi-start-pos) | ||||||
|         (end vlfi-end-pos) |         (end vlfi-end-pos) | ||||||
|         (pos (point)) |         (pos (point)) | ||||||
|         (to-find count) |         (to-find count) | ||||||
|         (search-reporter (make-progress-reporter |         (search-reporter (make-progress-reporter | ||||||
|                           (concat "Searching for " regexp) |                           (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 |     (unwind-protect | ||||||
|         (catch 'end-of-file |         (catch 'end-of-file | ||||||
|           (while (not (zerop to-find)) |           (if backward | ||||||
|             (cond ((re-search-forward regexp nil t) |               (while (not (zerop to-find)) | ||||||
|                    (setq to-find (1- to-find))) |                 (cond ((re-search-backward regexp nil t) | ||||||
|                   ((= vlfi-end-pos vlfi-file-size) |                        (setq to-find (1- to-find))) | ||||||
|                    (throw 'end-of-file nil)) |                       ((zerop vlfi-start-pos) | ||||||
|                   (t (vlfi-next-batch 1) |                        (throw 'end-of-file nil)) | ||||||
|                      (progress-reporter-update search-reporter |                       (t (vlfi-prev-batch 1) | ||||||
|                                                vlfi-end-pos))))) |                          (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) |       (progress-reporter-done search-reporter) | ||||||
|       (or (zerop to-find) |       (or (zerop to-find) | ||||||
|           (if (< to-find count) |           (if (< to-find count) | ||||||
| @@ -257,6 +270,16 @@ OP-TYPE specifies the file operation being performed over FILENAME." | |||||||
|             (vlfi-update-buffer-name) |             (vlfi-update-buffer-name) | ||||||
|             (message "Not found")))))) |             (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) | (provide 'vlfi) | ||||||
|  |  | ||||||
| ;;; vlfi.el ends here | ;;; vlfi.el ends here | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user