mirror of
https://github.com/m00natic/vlfi.git
synced 2025-02-07 05:30:47 +00:00
Add macro for file size determination.
This commit is contained in:
parent
705f9ce0eb
commit
6ea7a2aa1e
18
vlfi.el
18
vlfi.el
@ -94,7 +94,7 @@ buffer. You can customize number of bytes displayed by customizing
|
|||||||
(interactive "fFile to open: \nP")
|
(interactive "fFile to open: \nP")
|
||||||
(with-current-buffer (generate-new-buffer "*vlfi*")
|
(with-current-buffer (generate-new-buffer "*vlfi*")
|
||||||
(setq buffer-file-name file
|
(setq buffer-file-name file
|
||||||
vlfi-file-size (nth 7 (file-attributes file)))
|
vlfi-file-size (vlfi-get-file-size file))
|
||||||
(vlfi-insert-file from-end)
|
(vlfi-insert-file from-end)
|
||||||
(vlfi-mode)
|
(vlfi-mode)
|
||||||
(switch-to-buffer (current-buffer))))
|
(switch-to-buffer (current-buffer))))
|
||||||
@ -179,6 +179,10 @@ with the prefix argument DECREASE it is halved."
|
|||||||
"Update the current buffer name."
|
"Update the current buffer name."
|
||||||
(rename-buffer (vlfi-format-buffer-name) t))
|
(rename-buffer (vlfi-format-buffer-name) t))
|
||||||
|
|
||||||
|
(defmacro vlfi-get-file-size (file)
|
||||||
|
"Get size in bytes of FILE."
|
||||||
|
`(nth 7 (file-attributes ,file)))
|
||||||
|
|
||||||
(defun vlfi-insert-file (&optional from-end)
|
(defun vlfi-insert-file (&optional from-end)
|
||||||
"Insert first chunk of current file contents in current buffer.
|
"Insert first chunk of current file contents in current buffer.
|
||||||
With FROM-END prefix, start from the back."
|
With FROM-END prefix, start from the back."
|
||||||
@ -222,7 +226,7 @@ When prefix argument is negative
|
|||||||
(let ((end (+ vlfi-end-pos (* vlfi-batch-size
|
(let ((end (+ vlfi-end-pos (* vlfi-batch-size
|
||||||
(abs append)))))
|
(abs append)))))
|
||||||
(when (< vlfi-file-size end) ; re-check file size
|
(when (< vlfi-file-size end) ; re-check file size
|
||||||
(setq vlfi-file-size (nth 7 (file-attributes buffer-file-name)))
|
(setq vlfi-file-size (vlfi-get-file-size buffer-file-name))
|
||||||
(cond ((= vlfi-end-pos vlfi-file-size)
|
(cond ((= vlfi-end-pos vlfi-file-size)
|
||||||
(error "Already at EOF"))
|
(error "Already at EOF"))
|
||||||
((< vlfi-file-size end)
|
((< vlfi-file-size end)
|
||||||
@ -278,8 +282,7 @@ Adjust according to file start/end and show `vlfi-batch-size' bytes."
|
|||||||
(setq vlfi-start-pos (max 0 start)
|
(setq vlfi-start-pos (max 0 start)
|
||||||
vlfi-end-pos (+ vlfi-start-pos vlfi-batch-size))
|
vlfi-end-pos (+ vlfi-start-pos vlfi-batch-size))
|
||||||
(if (< vlfi-file-size vlfi-end-pos) ; re-check file size
|
(if (< vlfi-file-size vlfi-end-pos) ; re-check file size
|
||||||
(setq vlfi-file-size
|
(setq vlfi-file-size (vlfi-get-file-size buffer-file-name)
|
||||||
(nth 7 (file-attributes buffer-file-name))
|
|
||||||
vlfi-end-pos (min vlfi-end-pos vlfi-file-size)
|
vlfi-end-pos (min vlfi-end-pos vlfi-file-size)
|
||||||
vlfi-start-pos (max 0 (- vlfi-end-pos vlfi-batch-size))))
|
vlfi-start-pos (max 0 (- vlfi-end-pos vlfi-batch-size))))
|
||||||
(let ((inhibit-read-only t)
|
(let ((inhibit-read-only t)
|
||||||
@ -295,8 +298,7 @@ Adjust according to file start/end and show `vlfi-batch-size' bytes."
|
|||||||
(defun vlfi-move-to-chunk (start end)
|
(defun vlfi-move-to-chunk (start end)
|
||||||
"Move to chunk determined by START END."
|
"Move to chunk determined by START END."
|
||||||
(if (< vlfi-file-size end) ; re-check file size
|
(if (< vlfi-file-size end) ; re-check file size
|
||||||
(setq vlfi-file-size (nth 7
|
(setq vlfi-file-size (vlfi-get-file-size buffer-file-name)))
|
||||||
(file-attributes buffer-file-name))))
|
|
||||||
(setq vlfi-start-pos (max 0 start)
|
(setq vlfi-start-pos (max 0 start)
|
||||||
vlfi-end-pos (min end vlfi-file-size))
|
vlfi-end-pos (min end vlfi-file-size))
|
||||||
(let ((inhibit-read-only t)
|
(let ((inhibit-read-only t)
|
||||||
@ -497,7 +499,7 @@ Save anyway? ")))
|
|||||||
"Read `vlfi-batch-size' bytes from READ-POS and write them \
|
"Read `vlfi-batch-size' bytes from READ-POS and write them \
|
||||||
back at WRITE-POS. Return nil if EOF is reached, t otherwise."
|
back at WRITE-POS. Return nil if EOF is reached, t otherwise."
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(setq vlfi-file-size (nth 7 (file-attributes buffer-file-name)))
|
(setq vlfi-file-size (vlfi-get-file-size buffer-file-name))
|
||||||
(let ((read-end (+ read-pos vlfi-batch-size)))
|
(let ((read-end (+ read-pos vlfi-batch-size)))
|
||||||
(insert-file-contents-literally buffer-file-name nil
|
(insert-file-contents-literally buffer-file-name nil
|
||||||
read-pos
|
read-pos
|
||||||
@ -543,7 +545,7 @@ Done by saving content up front and then writing previous batch."
|
|||||||
"Read SIZE bytes in READ-BUFFER starting from READ-POS.
|
"Read SIZE bytes in READ-BUFFER starting from READ-POS.
|
||||||
Then write contents of WRITE-BUFFER to buffer file at WRITE-POS.
|
Then write contents of WRITE-BUFFER to buffer file at WRITE-POS.
|
||||||
Return nil if EOF is reached, t otherwise."
|
Return nil if EOF is reached, t otherwise."
|
||||||
(let* ((file-size (nth 7 (file-attributes buffer-file-name)))
|
(let* ((file-size (vlfi-get-file-size buffer-file-name))
|
||||||
(read-more (< read-pos file-size)))
|
(read-more (< read-pos file-size)))
|
||||||
(when read-more
|
(when read-more
|
||||||
;; read
|
;; read
|
||||||
|
Loading…
x
Reference in New Issue
Block a user