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:
		
							
								
								
									
										33
									
								
								vlfi.el
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								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,18 +223,30 @@ 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 | ||||
|           (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))) | ||||
| @@ -241,7 +254,7 @@ OP-TYPE specifies the file operation being performed over FILENAME." | ||||
|                      (throw 'end-of-file nil)) | ||||
|                     (t (vlfi-next-batch 1) | ||||
|                        (progress-reporter-update search-reporter | ||||
|                                                vlfi-end-pos))))) | ||||
|                                                  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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user