mirror of
				https://github.com/m00natic/vlfi.git
				synced 2025-10-31 07:03:35 +00:00 
			
		
		
		
	Check for unsaved changes before search query and don't enable undo if
it was previously disabled.
This commit is contained in:
		
							
								
								
									
										38
									
								
								vlf.el
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								vlf.el
									
									
									
									
									
								
							| @@ -272,16 +272,18 @@ Ask for confirmation if NOCONFIRM is nil." | |||||||
|  |  | ||||||
| (defmacro vlf-with-undo-disabled (&rest body) | (defmacro vlf-with-undo-disabled (&rest body) | ||||||
|   "Execute BODY with temporarily disabled undo." |   "Execute BODY with temporarily disabled undo." | ||||||
|   (declare (indent defun)) |   `(let ((undo-enabled (not (eq buffer-undo-list t)))) | ||||||
|   `(progn (buffer-disable-undo) |      (if undo-enabled | ||||||
|  |          (buffer-disable-undo)) | ||||||
|      (unwind-protect (progn ,@body) |      (unwind-protect (progn ,@body) | ||||||
|             (buffer-enable-undo)))) |        (if undo-enabled | ||||||
|  |            (buffer-enable-undo))))) | ||||||
|  |  | ||||||
| (defmacro vlf-no-modifications (&rest body) | (defun vlf-no-modifications () | ||||||
|   "Ensure there are no modifications and execute BODY." |   "Ensure there are no buffer modifications." | ||||||
|   `(if (buffer-modified-p) |   (if (buffer-modified-p) | ||||||
|       (error "Save or discard your changes first") |       (error "Save or discard your changes first") | ||||||
|      ,@body)) |     t)) | ||||||
|  |  | ||||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||||
| ;;; batch movement | ;;; batch movement | ||||||
| @@ -596,27 +598,27 @@ successful.  Return nil if nothing found." | |||||||
| (defun vlf-re-search-forward (regexp count) | (defun vlf-re-search-forward (regexp count) | ||||||
|   "Search forward for REGEXP prefix COUNT number of times. |   "Search forward for REGEXP prefix COUNT number of times. | ||||||
| Search is performed chunk by chunk in `vlf-batch-size' memory." | Search is performed chunk by chunk in `vlf-batch-size' memory." | ||||||
|   (interactive (list (read-regexp "Search whole file" |   (interactive (if (vlf-no-modifications) | ||||||
|  |                    (list (read-regexp "Search whole file" | ||||||
|                                       (if regexp-history |                                       (if regexp-history | ||||||
|                                           (car regexp-history))) |                                           (car regexp-history))) | ||||||
|                      (or current-prefix-arg 1))) |                          (or current-prefix-arg 1)))) | ||||||
|   (vlf-no-modifications |   (vlf-re-search regexp count nil (/ vlf-batch-size 8))) | ||||||
|    (vlf-re-search regexp count nil (/ vlf-batch-size 8)))) |  | ||||||
|  |  | ||||||
| (defun vlf-re-search-backward (regexp count) | (defun vlf-re-search-backward (regexp count) | ||||||
|   "Search backward for REGEXP prefix COUNT number of times. |   "Search backward for REGEXP prefix COUNT number of times. | ||||||
| Search is performed chunk by chunk in `vlf-batch-size' memory." | Search is performed chunk by chunk in `vlf-batch-size' memory." | ||||||
|   (interactive (list (read-regexp "Search whole file backward" |   (interactive (if (vlf-no-modifications) | ||||||
|  |                    (list (read-regexp "Search whole file backward" | ||||||
|                                       (if regexp-history |                                       (if regexp-history | ||||||
|                                           (car regexp-history))) |                                           (car regexp-history))) | ||||||
|                      (or current-prefix-arg 1))) |                          (or current-prefix-arg 1)))) | ||||||
|   (vlf-no-modifications |   (vlf-re-search regexp count t (/ vlf-batch-size 8))) | ||||||
|    (vlf-re-search regexp count t (/ vlf-batch-size 8)))) |  | ||||||
|  |  | ||||||
| (defun vlf-goto-line (n) | (defun vlf-goto-line (n) | ||||||
|   "Go to line N.  If N is negative, count from the end of file." |   "Go to line N.  If N is negative, count from the end of file." | ||||||
|   (interactive "nGo to line: ") |   (interactive (if (vlf-no-modifications) | ||||||
|   (vlf-no-modifications |                    (list (read-number "Go to line: ")))) | ||||||
|   (let ((start-pos vlf-start-pos) |   (let ((start-pos vlf-start-pos) | ||||||
|         (end-pos vlf-end-pos) |         (end-pos vlf-end-pos) | ||||||
|         (pos (point)) |         (pos (point)) | ||||||
| @@ -633,7 +635,7 @@ Search is performed chunk by chunk in `vlf-batch-size' memory." | |||||||
|       (if success |       (if success | ||||||
|           (message "Onto line %s" n) |           (message "Onto line %s" n) | ||||||
|         (vlf-move-to-chunk start-pos end-pos) |         (vlf-move-to-chunk start-pos end-pos) | ||||||
|          (goto-char pos)))))) |         (goto-char pos))))) | ||||||
|  |  | ||||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||||
| ;;; occur | ;;; occur | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user