[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ELPA-diffs] elpa r420: * packages/vlf/vlf.el: Version 0.4.
From: |
Stefan Monnier |
Subject: |
[ELPA-diffs] elpa r420: * packages/vlf/vlf.el: Version 0.4. |
Date: |
Mon, 22 Jul 2013 05:12:46 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 420
revision-id: address@hidden
parent: address@hidden
author: Andrey Kotlarski <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: elpa
timestamp: Mon 2013-07-22 01:12:44 -0400
message:
* packages/vlf/vlf.el: Version 0.4.
(vlf-mode-map): Add bindings to search and jump to BOF/EOF.
(vlf-format-buffer-name): Change position into a percentage.
(vlf-next-batch, vlf-prev-batch): Keep stable cursor position when moving
through chunks.
(vlf-move-to-chunk, vlf-insert-file): New functions.
(vlf): Use them. Disable undo information. Change arg order.
(dired-vlf): Adjust call.
(vlf-re-search-forward, vlf-re-search-backward, vlf-end-search): New
functions.
modified:
packages/vlf/vlf.el vlf.el-20120614203028-urlm47rgs71aoaqu-2
=== modified file 'packages/vlf/vlf.el'
--- a/packages/vlf/vlf.el 2013-07-22 04:58:34 +0000
+++ b/packages/vlf/vlf.el 2013-07-22 05:12:44 +0000
@@ -2,7 +2,7 @@
;; Copyright (C) 2006, 2012, 2013 Free Software Foundation, Inc.
-;; Version: 0.3
+;; Version: 0.4
;; Keywords: large files, utilities
;; Authors: 2006 Mathias Dahl <address@hidden>
;; 2012 Sam Steingold <address@hidden>
@@ -60,8 +60,16 @@
(define-key map (kbd "M-+") 'vlf-change-batch-size)
(define-key map (kbd "M--")
(lambda () "Decrease vlf batch size by factor of 2."
- (interactive)
- (vlf-change-batch-size t)))
+ (interactive)
+ (vlf-change-batch-size t)))
+ (define-key map "s" 'vlf-re-search-forward)
+ (define-key map "r" 'vlf-re-search-backward)
+ (define-key map ">" (lambda () "Jump to end of file content."
+ (interactive)
+ (vlf-insert-file buffer-file-name t)))
+ (define-key map "<" (lambda () "Jump to beginning of file content."
+ (interactive)
+ (vlf-insert-file buffer-file-name)))
map)
"Keymap for `vlf-mode'.")
@@ -81,17 +89,18 @@
(or (assq 'vlf-batch-size (buffer-local-variables))
(error "%s is not local in this buffer" 'vlf-batch-size))
(setq vlf-batch-size
- (if decrease
- (/ vlf-batch-size 2)
- (* vlf-batch-size 2)))
+ (if decrease
+ (/ vlf-batch-size 2)
+ (* vlf-batch-size 2)))
(vlf-update-buffer-name))
(defun vlf-format-buffer-name ()
"Return format for vlf buffer name."
- (format "%s(%s)[%d,%d](%d)"
- (file-name-nondirectory buffer-file-name)
- (file-size-human-readable vlf-file-size)
- vlf-start-pos vlf-end-pos vlf-batch-size))
+ (format "%s(%s)[%.2f%%%%](%d)"
+ (file-name-nondirectory buffer-file-name)
+ (file-size-human-readable vlf-file-size)
+ (/ (* 100 vlf-end-pos) (float vlf-file-size))
+ vlf-batch-size))
(defun vlf-update-buffer-name ()
"Update the current buffer name."
@@ -105,24 +114,26 @@
append next APPEND number of batches to the existing buffer."
(interactive "p")
(let ((end (+ vlf-end-pos (* vlf-batch-size
- (abs append)))))
+ (abs append)))))
(when (< vlf-file-size end) ; re-check file size
(setq vlf-file-size (nth 7 (file-attributes buffer-file-name)))
(cond ((= vlf-end-pos vlf-file-size)
- (error "Already at EOF"))
- ((< vlf-file-size end)
- (setq end vlf-file-size))))
+ (error "Already at EOF"))
+ ((< vlf-file-size end)
+ (setq end vlf-file-size))))
(let ((inhibit-read-only t)
- (do-append (< append 0)))
+ (do-append (< append 0))
+ (pos (point)))
(if do-append
- (goto-char (point-max))
- (setq vlf-start-pos (- end vlf-batch-size))
- (erase-buffer))
+ (goto-char (point-max))
+ (setq vlf-start-pos (- end vlf-batch-size))
+ (erase-buffer))
(insert-file-contents buffer-file-name nil
- (if do-append
- vlf-end-pos
- vlf-start-pos)
- end))
+ (if do-append
+ vlf-end-pos
+ vlf-start-pos)
+ end)
+ (goto-char pos))
(setq vlf-end-pos end))
(set-buffer-modified-p nil)
(vlf-update-buffer-name))
@@ -137,42 +148,59 @@
(if (zerop vlf-start-pos)
(error "Already at BOF"))
(let ((inhibit-read-only t)
- (start (max 0 (- vlf-start-pos (* vlf-batch-size
- (abs prepend)))))
- (do-prepend (< prepend 0)))
+ (start (max 0 (- vlf-start-pos (* vlf-batch-size
+ (abs prepend)))))
+ (do-prepend (< prepend 0))
+ (pos (- (point-max) (point))))
(if do-prepend
- (goto-char (point-min))
+ (goto-char (point-min))
(setq vlf-end-pos (+ start vlf-batch-size))
(erase-buffer))
(insert-file-contents buffer-file-name nil start
- (if do-prepend
- vlf-start-pos
- vlf-end-pos))
+ (if do-prepend
+ vlf-start-pos
+ vlf-end-pos))
+ (goto-char (- (point-max) pos))
(setq vlf-start-pos start))
(set-buffer-modified-p nil)
(vlf-update-buffer-name))
+(defun vlf-move-to-chunk (start end)
+ "Move to chunk determined by START END."
+ (if (< vlf-file-size end) ; re-check file size
+ (setq vlf-file-size (nth 7
+ (file-attributes buffer-file-name))))
+ (setq vlf-start-pos (max 0 start)
+ vlf-end-pos (min end vlf-file-size))
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert-file-contents buffer-file-name nil
+ vlf-start-pos vlf-end-pos))
+ (set-buffer-modified-p nil)
+ (vlf-update-buffer-name))
+
+(defun vlf-insert-file (file &optional from-end)
+ "Insert first chunk of FILE contents in current buffer.
+With FROM-END prefix, start from the back."
+ (if from-end
+ (setq vlf-start-pos (max 0 (- vlf-file-size vlf-batch-size))
+ vlf-end-pos vlf-file-size)
+ (setq vlf-start-pos 0
+ vlf-end-pos (min vlf-batch-size vlf-file-size)))
+ (vlf-move-to-chunk vlf-start-pos vlf-end-pos))
+
;;;###autoload
-(defun vlf (from-end file)
- "View a Large File in Emacs.
-With FROM-END prefix, view from the back.
-FILE is the file to open.
-Batches of the file data from FILE will be displayed in a
- read-only buffer.
-You can customize the number of bytes to
- display by customizing `vlf-batch-size'."
- (interactive "P\nfFile to open: ")
+(defun vlf (file &optional from-end)
+ "View Large FILE. With FROM-END prefix, view from the back.
+Batches of the file data from FILE will be displayed in a read-only
+buffer. You can customize number of bytes displayed by customizing
+`vlf-batch-size'."
+ (interactive "fFile to open: \nP")
(with-current-buffer (generate-new-buffer "*vlf*")
+ (buffer-disable-undo)
(setq buffer-file-name file
- vlf-file-size (nth 7 (file-attributes file)))
- (if from-end
- (setq vlf-start-pos (max 0 (- vlf-file-size vlf-batch-size))
- vlf-end-pos vlf-file-size)
- (setq vlf-start-pos 0
- vlf-end-pos (min vlf-batch-size vlf-file-size)))
- (vlf-update-buffer-name)
- (insert-file-contents buffer-file-name nil
- vlf-start-pos vlf-end-pos)
+ vlf-file-size (nth 7 (file-attributes file)))
+ (vlf-insert-file file from-end)
(vlf-mode)
(switch-to-buffer (current-buffer))))
@@ -181,7 +209,7 @@
"In Dired, visit the file on this line in VLF mode.
With FROM-END prefix, view from the back."
(interactive "P")
- (vlf from-end (dired-get-file-for-visit)))
+ (vlf (dired-get-file-for-visit) from-end))
;;;###autoload
(eval-after-load "dired"
@@ -198,7 +226,8 @@
(while (not (memq (setq char
(read-event
(propertize
- (format "File %s is large (%s): %s normally
(o), %s with vlf (v) or abort (a)"
+ (format "File %s is large (%s): \
+%s normally (o), %s with vlf (v) or abort (a)"
(file-name-nondirectory filename)
(file-size-human-readable size)
op-type op-type)
@@ -215,12 +244,131 @@
;;;###autoload
(fset 'abort-if-file-too-large 'vlf-if-file-too-large)
-(defun dired-vlf ()
- "In Dired, visit the file on this line in VLF mode."
- (interactive)
- (vlf (dired-get-file-for-visit)))
-
-(eval-after-load "dired" '(define-key dired-mode-map "V" 'dired-vlf))
+(defun vlf-re-search-forward (regexp count)
+ "Search forward for REGEXP prefix COUNT number of times."
+ (interactive (list (read-regexp "Search whole file"
+ (if regexp-history
+ (car regexp-history))
+ 'regexp-history)
+ (or current-prefix-arg 1)))
+ (let ((match-chunk-start vlf-start-pos)
+ (match-chunk-end vlf-end-pos)
+ (match-start-pos (point))
+ (match-end-pos (point))
+ (to-find count)
+ (search-reporter (make-progress-reporter
+ (concat "Searching for " regexp)
+ vlf-start-pos vlf-file-size))
+ (initial-chunk t))
+ (unwind-protect
+ (catch 'end-of-file
+ (while (not (zerop to-find))
+ (cond ((re-search-forward regexp nil t)
+ (setq to-find (if (= match-start-pos
+ (match-beginning 0))
+ to-find
+ (1- to-find))
+ match-start-pos (match-beginning 0)
+ match-end-pos (match-end 0)
+ match-chunk-start vlf-start-pos
+ match-chunk-end vlf-end-pos)
+ (if (and (< vlf-batch-size match-start-pos)
+ (> (- vlf-end-pos vlf-start-pos)
+ vlf-batch-size))
+ (setq match-chunk-start
+ (+ match-chunk-start vlf-batch-size)
+ match-start-pos (- match-start-pos
+ vlf-batch-size)
+ match-end-pos (- match-end-pos
+ vlf-batch-size))))
+ ((= vlf-end-pos vlf-file-size)
+ (throw 'end-of-file nil))
+ (t (if initial-chunk
+ (progn (setq initial-chunk nil)
+ (vlf-next-batch -1))
+ (vlf-move-to-chunk (+ vlf-start-pos
+ vlf-batch-size)
+ (+ vlf-end-pos
+ vlf-batch-size)))
+ (goto-char (if (< vlf-start-pos match-chunk-end)
+ match-start-pos
+ (point-min)))
+ (goto-char match-start-pos)
+ (progress-reporter-update search-reporter
+ vlf-end-pos))))
+ (progress-reporter-done search-reporter))
+ (vlf-end-search match-chunk-start match-chunk-end
+ match-end-pos count to-find))))
+
+(defun vlf-re-search-backward (regexp count)
+ "Search backward for REGEXP prefix COUNT number of times."
+ (interactive (list (read-regexp "Search whole file"
+ (if regexp-history
+ (car regexp-history))
+ 'regexp-history)
+ (or current-prefix-arg 1)))
+ (let ((match-chunk-start vlf-start-pos)
+ (match-chunk-end vlf-end-pos)
+ (match-start-pos (point))
+ (match-end-pos (point))
+ (to-find count)
+ (search-reporter (make-progress-reporter
+ (concat "Searching for " regexp)
+ (- vlf-file-size vlf-end-pos)
+ vlf-file-size))
+ (initial-chunk t))
+ (unwind-protect
+ (catch 'start-of-file
+ (while (not (zerop to-find))
+ (cond ((re-search-backward regexp nil t)
+ (setq to-find (if (= match-end-pos
+ (match-end 0))
+ to-find
+ (1- to-find))
+ match-start-pos (match-beginning 0)
+ match-end-pos (match-end 0)
+ match-chunk-start vlf-start-pos
+ match-chunk-end vlf-end-pos)
+ (if (and (< match-end-pos vlf-batch-size)
+ (> (- vlf-end-pos vlf-start-pos)
+ vlf-batch-size))
+ (setq match-chunk-end
+ (- match-chunk-end
+ vlf-batch-size))))
+ ((zerop vlf-start-pos)
+ (throw 'start-of-file nil))
+ (t (if initial-chunk
+ (progn (setq initial-chunk nil)
+ (vlf-prev-batch -1))
+ (vlf-move-to-chunk (- vlf-start-pos
+ vlf-batch-size)
+ (- vlf-end-pos
+ vlf-batch-size)))
+ (goto-char (if (< match-chunk-start vlf-end-pos)
+ match-end-pos
+ (point-max)))
+ (setq last-chunk-match nil)
+ (progress-reporter-update search-reporter
+ (- vlf-file-size
+ vlf-start-pos)))))
+ (progress-reporter-done search-reporter))
+ (vlf-end-search match-chunk-start match-chunk-end
+ match-start-pos count to-find))))
+
+(defun vlf-end-search (match-chunk-start match-chunk-end
+ match-pos count to-find)
+ "Move to chunk determined by MATCH-CHUNK-START and MATCH-CHUNK-END.
+Go to MATCH-POS and according to COUNT and left TO-FIND show if search
+has been successful. Return nil if nothing found."
+ (vlf-move-to-chunk match-chunk-start match-chunk-end)
+ (goto-char match-pos)
+ (cond ((zerop to-find) t)
+ ((< to-find count)
+ (message "Moved to the %d match which is last found"
+ (- count to-find))
+ t)
+ (t (message "Not found")
+ nil)))
(provide 'vlf)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ELPA-diffs] elpa r420: * packages/vlf/vlf.el: Version 0.4.,
Stefan Monnier <=