From d1a6800b5b95a1a0f108c57662b7906529552022 Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Fri, 12 Dec 2014 01:45:04 +0200 Subject: [PATCH] Move vlf information from buffer name to the mode line. --- README.org | 11 +++++++---- vlf-base.el | 18 ++---------------- vlf-ediff.el | 9 +++------ vlf-search.el | 11 ++++------- vlf-write.el | 4 +--- vlf.el | 16 +++++++++------- 6 files changed, 26 insertions(+), 43 deletions(-) diff --git a/README.org b/README.org index 309fb33..335621e 100644 --- a/README.org +++ b/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)) #+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 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 respectively. -*C-c C-v j* jumps to given chunk. To see where you are in file and -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. +*C-c C-v j* jumps to particular batch number. ** Follow point diff --git a/vlf-base.el b/vlf-base.el index 8ae0d31..21a176a 100644 --- a/vlf-base.el +++ b/vlf-base.el @@ -71,15 +71,6 @@ FILE if given is filename to be used, otherwise `buffer-file-truename'." "Print FILE-SIZE in MB." (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) "Execute BODY with temporarily disabled undo." `(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) (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. -When given MINIMAL flag, skip non important operations. If same as current chunk is requested, do nothing. Return number of bytes moved back for proper decoding and number of bytes added to the end." @@ -105,17 +95,13 @@ bytes added to the end." 0))) (setq vlf-start-pos place vlf-end-pos place) - (or minimal (vlf-update-buffer-name)) (cons (- start place) (- place end)))) (if (derived-mode-p 'hexl-mode) (setq start (- start (mod start hexl-bits)) end (+ end (- hexl-bits (mod end hexl-bits))))) (if (or (/= start vlf-start-pos) (/= end vlf-end-pos)) - (let ((shifts (vlf-move-to-chunk-1 start end))) - (and shifts (not minimal) - (vlf-update-buffer-name)) - shifts)))) + (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. diff --git a/vlf-ediff.el b/vlf-ediff.el index 0880660..e168cf9 100644 --- a/vlf-ediff.el +++ b/vlf-ediff.el @@ -143,11 +143,11 @@ beginning of difference list." (defun vlf-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 () "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 &optional next-func) @@ -205,10 +205,7 @@ logical chunks in case there is no difference at the current ones." (- vlf-file-size vlf-start-pos)))) (progress-reporter-done reporter) - (if (or (not end-A) (not end-B)) - (progn (vlf-update-buffer-name) - (set-buffer buffer-A) - (vlf-update-buffer-name)) + (when (and end-A end-B) (if forward-p (let ((max-file-size vlf-file-size)) (vlf-move-to-chunk (- max-file-size vlf-batch-size) diff --git a/vlf-search.el b/vlf-search.el index c7e0428..a6a9808 100644 --- a/vlf-search.el +++ b/vlf-search.el @@ -90,7 +90,7 @@ Return t if search has been at least partially successful." batch-move match-start-pos))) (vlf-move-to-chunk (- end vlf-batch-size) - end t)) + end)) (goto-char (if (or is-hexl (<= vlf-end-pos match-start-pos)) @@ -124,8 +124,7 @@ Return t if search has been at least partially successful." batch-move match-end-pos))) (vlf-move-to-chunk start - (+ start vlf-batch-size) - t)) + (+ start vlf-batch-size))) (goto-char (if (or is-hexl (<= match-end-pos vlf-start-pos)) @@ -168,9 +167,8 @@ Return nil if nothing found." (message "Not found (%f secs)" (- (float-time) time)) nil) (let ((success (zerop to-find))) - (if success - (vlf-update-buffer-name) - (vlf-move-to-chunk match-chunk-start match-chunk-end)) + (or success + (vlf-move-to-chunk match-chunk-start match-chunk-end)) (setq vlf-batch-size (vlf-tune-optimal-load (if (derived-mode-p 'hexl-mode) '(:hexl :raw) @@ -310,7 +308,6 @@ Search is performed chunk by chunk in `vlf-batch-size' memory." (unless success (vlf-with-undo-disabled (vlf-move-to-chunk-2 start-pos end-pos)) - (vlf-update-buffer-name) (goto-char pos) (setq vlf-batch-size batch-size) (message "Unable to find line")) diff --git a/vlf-write.el b/vlf-write.el index d495b7f..ae1eda6 100644 --- a/vlf-write.el +++ b/vlf-write.el @@ -58,8 +58,7 @@ If changing size of chunk, shift remaining file content." (if hexl (vlf-tune-hexlify)) (setq vlf-file-size (vlf-get-file-size buffer-file-truename) - vlf-end-pos vlf-file-size) - (vlf-update-buffer-name)) + vlf-end-pos vlf-file-size)) (let* ((region-length (vlf-tune-encode-length (point-min) (point-max))) (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-start-pos vlf-batch-size) vlf-end-pos)) - (vlf-update-buffer-name) (goto-char pos) (message "Save took %f seconds" (- (float-time) time))))))) (run-hook-with-args 'vlf-after-batch-functions 'write)) diff --git a/vlf.el b/vlf.el index f166197..e3c4f37 100644 --- a/vlf.el +++ b/vlf.el @@ -103,7 +103,11 @@ values are: `write', `ediff', `occur', `search', `goto-line'." (define-minor-mode vlf-mode "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 (set (make-local-variable 'require-final-newline) nil) (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))))) (vlf-with-undo-disabled (insert-file-contents buffer-file-name t nil nil t)) - (goto-char (byte-to-position pos)))) - (rename-buffer (file-name-nondirectory buffer-file-name) t)) + (goto-char (byte-to-position pos))))) (t (setq vlf-mode t)))) (defun vlf-keep-alive () @@ -331,16 +334,15 @@ Ask for confirmation if NOCONFIRM is nil." (error "Save or discard your changes first") t)) -(defun vlf-move-to-batch (start &optional minimal) +(defun vlf-move-to-batch (start) "Move to batch determined by START. -Adjust according to file start/end and show `vlf-batch-size' bytes. -When given MINIMAL flag, skip non important operations." +Adjust according to file start/end and show `vlf-batch-size' bytes." (vlf-verify-size) (let* ((start (max 0 start)) (end (min (+ start vlf-batch-size) vlf-file-size))) (if (= vlf-file-size end) ; re-adjust start (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 () "Display batch of file data starting from current point."