mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-31 02:00:47 +00:00
Check for unsaved changes before search query and don't enable undo if
it was previously disabled.
This commit is contained in:
parent
f34986a9b8
commit
a65f3a431d
82
vlf.el
82
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
|
||||||
(unwind-protect (progn ,@body)
|
(buffer-disable-undo))
|
||||||
(buffer-enable-undo))))
|
(unwind-protect (progn ,@body)
|
||||||
|
(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,44 +598,44 @@ 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)
|
||||||
(if regexp-history
|
(list (read-regexp "Search whole file"
|
||||||
(car regexp-history)))
|
(if regexp-history
|
||||||
(or current-prefix-arg 1)))
|
(car regexp-history)))
|
||||||
(vlf-no-modifications
|
(or current-prefix-arg 1))))
|
||||||
(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)
|
||||||
(if regexp-history
|
(list (read-regexp "Search whole file backward"
|
||||||
(car regexp-history)))
|
(if regexp-history
|
||||||
(or current-prefix-arg 1)))
|
(car regexp-history)))
|
||||||
(vlf-no-modifications
|
(or current-prefix-arg 1))))
|
||||||
(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))
|
||||||
(success nil))
|
(success nil))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(if (< 0 n)
|
(if (< 0 n)
|
||||||
(progn (vlf-beginning-of-file)
|
(progn (vlf-beginning-of-file)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(setq success (vlf-re-search "[\n\C-m]" (1- n)
|
(setq success (vlf-re-search "[\n\C-m]" (1- n)
|
||||||
nil 0)))
|
nil 0)))
|
||||||
(vlf-end-of-file)
|
(vlf-end-of-file)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(setq success (vlf-re-search "[\n\C-m]" (- n) t 0)))
|
(setq success (vlf-re-search "[\n\C-m]" (- n) t 0)))
|
||||||
(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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user