From 1ac1eece404f05ff175eb832b697c63b2d24130a Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Thu, 2 May 2013 12:04:12 +0300 Subject: [PATCH 1/2] Turn vlfi-get-file-size to function. --- vlfi.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vlfi.el b/vlfi.el index 70cc6b3..2c42013 100644 --- a/vlfi.el +++ b/vlfi.el @@ -200,9 +200,9 @@ with the prefix argument DECREASE it is halved." "Update the current buffer name." (rename-buffer (vlfi-format-buffer-name) t)) -(defmacro vlfi-get-file-size (file) +(defun vlfi-get-file-size (file) "Get size in bytes of FILE." - `(nth 7 (file-attributes ,file))) + (nth 7 (file-attributes file))) (defun vlfi-insert-file (&optional from-end) "Insert first chunk of current file contents in current buffer. From ae775f88f91957bff5ec093fd944f36b74529a4b Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Thu, 2 May 2013 14:18:41 +0300 Subject: [PATCH 2/2] Extend vlfi-goto-line to count lines from the end with negative argument. --- vlfi.el | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/vlfi.el b/vlfi.el index 2c42013..49548f1 100644 --- a/vlfi.el +++ b/vlfi.el @@ -373,6 +373,7 @@ Return number of bytes moved back for this to happen." (defun vlfi-re-search (regexp count backward batch-step) "Search for REGEXP COUNT number of times forward or BACKWARD. BATCH-STEP is amount of overlap between successive chunks." + (assert (< 0 count)) (let* ((match-chunk-start vlfi-start-pos) (match-chunk-end vlfi-end-pos) (match-start-pos (+ vlfi-start-pos (position-bytes (point)))) @@ -506,18 +507,23 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory." (vlfi-re-search regexp count t (/ vlfi-batch-size 8))) (defun vlfi-goto-line (n) - "Go to line N." + "Go to line N. If N is negative, count from the end of file." (interactive "nGo to line: ") (let ((start-pos vlfi-start-pos) (end-pos vlfi-end-pos) (pos (point)) (success nil)) (unwind-protect - (progn (vlfi-beginning-of-file) - (goto-char (point-min)) - (setq success (vlfi-re-search "[\n\C-m]" (1- n) - nil 0))) - (unless success + (if (< 0 n) + (progn (vlfi-beginning-of-file) + (goto-char (point-min)) + (setq success (vlfi-re-search "[\n\C-m]" (1- n) + nil 0))) + (vlfi-end-of-file) + (goto-char (point-max)) + (setq success (vlfi-re-search "[\n\C-m]" (- n) t 0))) + (if success + (message "Onto line %s" n) (vlfi-move-to-chunk start-pos end-pos) (goto-char pos)))))