mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 12:05:31 +00:00
Move vlf information from buffer name to the mode line.
This commit is contained in:
parent
a7be7136be
commit
d1a6800b5b
11
README.org
11
README.org
@ -91,6 +91,12 @@ default. Here's example how to add another prefix (*C-x v*):
|
|||||||
'(define-key vlf-prefix-map "\C-xv" vlf-mode-map))
|
'(define-key vlf-prefix-map "\C-xv" vlf-mode-map))
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
** Overall position indicators
|
||||||
|
|
||||||
|
To see which part of the file is currently visited and how many
|
||||||
|
batches there are in overall (using the current batch size), look at
|
||||||
|
the VLF section in the mode line, file size is also there.
|
||||||
|
|
||||||
** Batch size control
|
** Batch size control
|
||||||
|
|
||||||
By default *VLF* gathers statistics over how primitive operations
|
By default *VLF* gathers statistics over how primitive operations
|
||||||
@ -133,10 +139,7 @@ append prefix number of batches.
|
|||||||
*C-c C-v [* and *C-c C-v ]* take you to the beginning and end of file
|
*C-c C-v [* and *C-c C-v ]* take you to the beginning and end of file
|
||||||
respectively.
|
respectively.
|
||||||
|
|
||||||
*C-c C-v j* jumps to given chunk. To see where you are in file and
|
*C-c C-v j* jumps to particular batch number.
|
||||||
how many chunks there are (using the current batch size), look at the
|
|
||||||
parenthesized part of the buffer name, batch size is also indicated at
|
|
||||||
the end.
|
|
||||||
|
|
||||||
** Follow point
|
** Follow point
|
||||||
|
|
||||||
|
18
vlf-base.el
18
vlf-base.el
@ -71,15 +71,6 @@ FILE if given is filename to be used, otherwise `buffer-file-truename'."
|
|||||||
"Print FILE-SIZE in MB."
|
"Print FILE-SIZE in MB."
|
||||||
(format "%.3fMB" (/ file-size 1048576.0))))
|
(format "%.3fMB" (/ file-size 1048576.0))))
|
||||||
|
|
||||||
(defun vlf-update-buffer-name ()
|
|
||||||
"Update the current buffer name."
|
|
||||||
(rename-buffer (format "%s(%d/%d)[%s]"
|
|
||||||
(file-name-nondirectory buffer-file-name)
|
|
||||||
(/ vlf-end-pos vlf-batch-size)
|
|
||||||
(/ vlf-file-size vlf-batch-size)
|
|
||||||
(file-size-human-readable vlf-batch-size))
|
|
||||||
t))
|
|
||||||
|
|
||||||
(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."
|
||||||
`(let ((undo-list buffer-undo-list))
|
`(let ((undo-list buffer-undo-list))
|
||||||
@ -87,9 +78,8 @@ FILE if given is filename to be used, otherwise `buffer-file-truename'."
|
|||||||
(unwind-protect (progn ,@body)
|
(unwind-protect (progn ,@body)
|
||||||
(setq buffer-undo-list undo-list))))
|
(setq buffer-undo-list undo-list))))
|
||||||
|
|
||||||
(defun vlf-move-to-chunk (start end &optional minimal)
|
(defun vlf-move-to-chunk (start end)
|
||||||
"Move to chunk enclosed by START END bytes.
|
"Move to chunk enclosed by START END bytes.
|
||||||
When given MINIMAL flag, skip non important operations.
|
|
||||||
If same as current chunk is requested, do nothing.
|
If same as current chunk is requested, do nothing.
|
||||||
Return number of bytes moved back for proper decoding and number of
|
Return number of bytes moved back for proper decoding and number of
|
||||||
bytes added to the end."
|
bytes added to the end."
|
||||||
@ -105,17 +95,13 @@ bytes added to the end."
|
|||||||
0)))
|
0)))
|
||||||
(setq vlf-start-pos place
|
(setq vlf-start-pos place
|
||||||
vlf-end-pos place)
|
vlf-end-pos place)
|
||||||
(or minimal (vlf-update-buffer-name))
|
|
||||||
(cons (- start place) (- place end))))
|
(cons (- start place) (- place end))))
|
||||||
(if (derived-mode-p 'hexl-mode)
|
(if (derived-mode-p 'hexl-mode)
|
||||||
(setq start (- start (mod start hexl-bits))
|
(setq start (- start (mod start hexl-bits))
|
||||||
end (+ end (- hexl-bits (mod end hexl-bits)))))
|
end (+ end (- hexl-bits (mod end hexl-bits)))))
|
||||||
(if (or (/= start vlf-start-pos)
|
(if (or (/= start vlf-start-pos)
|
||||||
(/= end vlf-end-pos))
|
(/= end vlf-end-pos))
|
||||||
(let ((shifts (vlf-move-to-chunk-1 start end)))
|
(vlf-move-to-chunk-1 start end))))
|
||||||
(and shifts (not minimal)
|
|
||||||
(vlf-update-buffer-name))
|
|
||||||
shifts))))
|
|
||||||
|
|
||||||
(defun vlf-move-to-chunk-1 (start end)
|
(defun vlf-move-to-chunk-1 (start end)
|
||||||
"Move to chunk enclosed by START END keeping as much edits if any.
|
"Move to chunk enclosed by START END keeping as much edits if any.
|
||||||
|
@ -143,11 +143,11 @@ beginning of difference list."
|
|||||||
|
|
||||||
(defun vlf-next-chunk ()
|
(defun vlf-next-chunk ()
|
||||||
"Move to next chunk."
|
"Move to next chunk."
|
||||||
(vlf-move-to-chunk vlf-end-pos (+ vlf-end-pos vlf-batch-size) t))
|
(vlf-move-to-chunk vlf-end-pos (+ vlf-end-pos vlf-batch-size)))
|
||||||
|
|
||||||
(defun vlf-prev-chunk ()
|
(defun vlf-prev-chunk ()
|
||||||
"Move to previous chunk."
|
"Move to previous chunk."
|
||||||
(vlf-move-to-chunk (- vlf-start-pos vlf-batch-size) vlf-start-pos t))
|
(vlf-move-to-chunk (- vlf-start-pos vlf-batch-size) vlf-start-pos))
|
||||||
|
|
||||||
(defun vlf-ediff-next (buffer-A buffer-B ediff-buffer
|
(defun vlf-ediff-next (buffer-A buffer-B ediff-buffer
|
||||||
&optional next-func)
|
&optional next-func)
|
||||||
@ -205,10 +205,7 @@ logical chunks in case there is no difference at the current ones."
|
|||||||
(- vlf-file-size
|
(- vlf-file-size
|
||||||
vlf-start-pos))))
|
vlf-start-pos))))
|
||||||
(progress-reporter-done reporter)
|
(progress-reporter-done reporter)
|
||||||
(if (or (not end-A) (not end-B))
|
(when (and end-A end-B)
|
||||||
(progn (vlf-update-buffer-name)
|
|
||||||
(set-buffer buffer-A)
|
|
||||||
(vlf-update-buffer-name))
|
|
||||||
(if forward-p
|
(if forward-p
|
||||||
(let ((max-file-size vlf-file-size))
|
(let ((max-file-size vlf-file-size))
|
||||||
(vlf-move-to-chunk (- max-file-size vlf-batch-size)
|
(vlf-move-to-chunk (- max-file-size vlf-batch-size)
|
||||||
|
@ -90,7 +90,7 @@ Return t if search has been at least partially successful."
|
|||||||
batch-move
|
batch-move
|
||||||
match-start-pos)))
|
match-start-pos)))
|
||||||
(vlf-move-to-chunk (- end vlf-batch-size)
|
(vlf-move-to-chunk (- end vlf-batch-size)
|
||||||
end t))
|
end))
|
||||||
(goto-char (if (or is-hexl
|
(goto-char (if (or is-hexl
|
||||||
(<= vlf-end-pos
|
(<= vlf-end-pos
|
||||||
match-start-pos))
|
match-start-pos))
|
||||||
@ -124,8 +124,7 @@ Return t if search has been at least partially successful."
|
|||||||
batch-move
|
batch-move
|
||||||
match-end-pos)))
|
match-end-pos)))
|
||||||
(vlf-move-to-chunk start
|
(vlf-move-to-chunk start
|
||||||
(+ start vlf-batch-size)
|
(+ start vlf-batch-size)))
|
||||||
t))
|
|
||||||
(goto-char (if (or is-hexl
|
(goto-char (if (or is-hexl
|
||||||
(<= match-end-pos
|
(<= match-end-pos
|
||||||
vlf-start-pos))
|
vlf-start-pos))
|
||||||
@ -168,9 +167,8 @@ Return nil if nothing found."
|
|||||||
(message "Not found (%f secs)" (- (float-time) time))
|
(message "Not found (%f secs)" (- (float-time) time))
|
||||||
nil)
|
nil)
|
||||||
(let ((success (zerop to-find)))
|
(let ((success (zerop to-find)))
|
||||||
(if success
|
(or success
|
||||||
(vlf-update-buffer-name)
|
(vlf-move-to-chunk match-chunk-start match-chunk-end))
|
||||||
(vlf-move-to-chunk match-chunk-start match-chunk-end))
|
|
||||||
(setq vlf-batch-size (vlf-tune-optimal-load
|
(setq vlf-batch-size (vlf-tune-optimal-load
|
||||||
(if (derived-mode-p 'hexl-mode)
|
(if (derived-mode-p 'hexl-mode)
|
||||||
'(:hexl :raw)
|
'(:hexl :raw)
|
||||||
@ -310,7 +308,6 @@ Search is performed chunk by chunk in `vlf-batch-size' memory."
|
|||||||
(unless success
|
(unless success
|
||||||
(vlf-with-undo-disabled
|
(vlf-with-undo-disabled
|
||||||
(vlf-move-to-chunk-2 start-pos end-pos))
|
(vlf-move-to-chunk-2 start-pos end-pos))
|
||||||
(vlf-update-buffer-name)
|
|
||||||
(goto-char pos)
|
(goto-char pos)
|
||||||
(setq vlf-batch-size batch-size)
|
(setq vlf-batch-size batch-size)
|
||||||
(message "Unable to find line"))
|
(message "Unable to find line"))
|
||||||
|
@ -58,8 +58,7 @@ If changing size of chunk, shift remaining file content."
|
|||||||
(if hexl (vlf-tune-hexlify))
|
(if hexl (vlf-tune-hexlify))
|
||||||
(setq vlf-file-size (vlf-get-file-size
|
(setq vlf-file-size (vlf-get-file-size
|
||||||
buffer-file-truename)
|
buffer-file-truename)
|
||||||
vlf-end-pos vlf-file-size)
|
vlf-end-pos vlf-file-size))
|
||||||
(vlf-update-buffer-name))
|
|
||||||
(let* ((region-length (vlf-tune-encode-length (point-min)
|
(let* ((region-length (vlf-tune-encode-length (point-min)
|
||||||
(point-max)))
|
(point-max)))
|
||||||
(size-change (- vlf-end-pos vlf-start-pos
|
(size-change (- vlf-end-pos vlf-start-pos
|
||||||
@ -99,7 +98,6 @@ If changing size of chunk, shift remaining file content."
|
|||||||
vlf-batch-size)
|
vlf-batch-size)
|
||||||
(+ vlf-start-pos vlf-batch-size)
|
(+ vlf-start-pos vlf-batch-size)
|
||||||
vlf-end-pos))
|
vlf-end-pos))
|
||||||
(vlf-update-buffer-name)
|
|
||||||
(goto-char pos)
|
(goto-char pos)
|
||||||
(message "Save took %f seconds" (- (float-time) time)))))))
|
(message "Save took %f seconds" (- (float-time) time)))))))
|
||||||
(run-hook-with-args 'vlf-after-batch-functions 'write))
|
(run-hook-with-args 'vlf-after-batch-functions 'write))
|
||||||
|
16
vlf.el
16
vlf.el
@ -103,7 +103,11 @@ values are: `write', `ediff', `occur', `search', `goto-line'."
|
|||||||
|
|
||||||
(define-minor-mode vlf-mode
|
(define-minor-mode vlf-mode
|
||||||
"Mode to browse large files in."
|
"Mode to browse large files in."
|
||||||
:lighter " VLF" :group 'vlf :keymap vlf-prefix-map
|
:group 'vlf :keymap vlf-prefix-map
|
||||||
|
:lighter (:eval (format " VLF[%d/%d](%s)"
|
||||||
|
(/ vlf-end-pos vlf-batch-size)
|
||||||
|
(/ vlf-file-size vlf-batch-size)
|
||||||
|
(file-size-human-readable vlf-file-size)))
|
||||||
(cond (vlf-mode
|
(cond (vlf-mode
|
||||||
(set (make-local-variable 'require-final-newline) nil)
|
(set (make-local-variable 'require-final-newline) nil)
|
||||||
(add-hook 'write-file-functions 'vlf-write nil t)
|
(add-hook 'write-file-functions 'vlf-write nil t)
|
||||||
@ -146,8 +150,7 @@ values are: `write', `ediff', `occur', `search', `goto-line'."
|
|||||||
(let ((pos (+ vlf-start-pos (position-bytes (point)))))
|
(let ((pos (+ vlf-start-pos (position-bytes (point)))))
|
||||||
(vlf-with-undo-disabled
|
(vlf-with-undo-disabled
|
||||||
(insert-file-contents buffer-file-name t nil nil t))
|
(insert-file-contents buffer-file-name t nil nil t))
|
||||||
(goto-char (byte-to-position pos))))
|
(goto-char (byte-to-position pos)))))
|
||||||
(rename-buffer (file-name-nondirectory buffer-file-name) t))
|
|
||||||
(t (setq vlf-mode t))))
|
(t (setq vlf-mode t))))
|
||||||
|
|
||||||
(defun vlf-keep-alive ()
|
(defun vlf-keep-alive ()
|
||||||
@ -331,16 +334,15 @@ Ask for confirmation if NOCONFIRM is nil."
|
|||||||
(error "Save or discard your changes first")
|
(error "Save or discard your changes first")
|
||||||
t))
|
t))
|
||||||
|
|
||||||
(defun vlf-move-to-batch (start &optional minimal)
|
(defun vlf-move-to-batch (start)
|
||||||
"Move to batch determined by START.
|
"Move to batch determined by START.
|
||||||
Adjust according to file start/end and show `vlf-batch-size' bytes.
|
Adjust according to file start/end and show `vlf-batch-size' bytes."
|
||||||
When given MINIMAL flag, skip non important operations."
|
|
||||||
(vlf-verify-size)
|
(vlf-verify-size)
|
||||||
(let* ((start (max 0 start))
|
(let* ((start (max 0 start))
|
||||||
(end (min (+ start vlf-batch-size) vlf-file-size)))
|
(end (min (+ start vlf-batch-size) vlf-file-size)))
|
||||||
(if (= vlf-file-size end) ; re-adjust start
|
(if (= vlf-file-size end) ; re-adjust start
|
||||||
(setq start (max 0 (- end vlf-batch-size))))
|
(setq start (max 0 (- end vlf-batch-size))))
|
||||||
(vlf-move-to-chunk start end minimal)))
|
(vlf-move-to-chunk start end)))
|
||||||
|
|
||||||
(defun vlf-next-batch-from-point ()
|
(defun vlf-next-batch-from-point ()
|
||||||
"Display batch of file data starting from current point."
|
"Display batch of file data starting from current point."
|
||||||
|
Loading…
Reference in New Issue
Block a user