1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-04-01 00:18:05 +01:00

Fix follow functionality and explicitly set variable as buffer local.

This commit is contained in:
Andrey Kotlarski 2014-01-07 01:43:14 +02:00
parent 95e625938e
commit 66db665d82
3 changed files with 16 additions and 12 deletions

View File

@ -29,6 +29,7 @@
(defvar vlf-follow-timer nil (defvar vlf-follow-timer nil
"Contains timer if vlf buffer is set to continuously recenter.") "Contains timer if vlf buffer is set to continuously recenter.")
(make-variable-buffer-local 'vlf-follow-timer)
(put 'vlf-follow-timer 'permanent-local t) (put 'vlf-follow-timer 'permanent-local t)
(defun vlf-recenter (vlf-buffer) (defun vlf-recenter (vlf-buffer)
@ -57,8 +58,9 @@
(defun vlf-stop-follow () (defun vlf-stop-follow ()
"Stop continuous recenter." "Stop continuous recenter."
(when vlf-follow-timer
(cancel-timer vlf-follow-timer) (cancel-timer vlf-follow-timer)
(setq vlf-follow-timer nil)) (setq vlf-follow-timer nil)))
(defun vlf-start-follow (interval) (defun vlf-start-follow (interval)
"Continuously recenter chunk around point every INTERVAL seconds." "Continuously recenter chunk around point every INTERVAL seconds."

View File

@ -126,7 +126,7 @@ Prematurely ending indexing will still show what's found so far."
(with-temp-buffer (with-temp-buffer
(setq buffer-file-name file) (setq buffer-file-name file)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(set (make-local-variable 'vlf-batch-size) batch-size) (setq-local vlf-batch-size batch-size)
(vlf-mode 1) (vlf-mode 1)
(goto-char (point-min)) (goto-char (point-min))
(vlf-with-undo-disabled (vlf-with-undo-disabled

20
vlf.el
View File

@ -51,12 +51,15 @@
;;; Keep track of file position. ;;; Keep track of file position.
(defvar vlf-start-pos 0 (defvar vlf-start-pos 0
"Absolute position of the visible chunk start.") "Absolute position of the visible chunk start.")
(make-variable-buffer-local 'vlf-start-pos)
(put 'vlf-start-pos 'permanent-local t) (put 'vlf-start-pos 'permanent-local t)
(defvar vlf-end-pos 0 "Absolute position of the visible chunk end.") (defvar vlf-end-pos 0 "Absolute position of the visible chunk end.")
(make-variable-buffer-local 'vlf-end-pos)
(put 'vlf-end-pos 'permanent-local t) (put 'vlf-end-pos 'permanent-local t)
(defvar vlf-file-size 0 "Total size of presented file.") (defvar vlf-file-size 0 "Total size of presented file.")
(make-variable-buffer-local 'vlf-file-size)
(put 'vlf-file-size 'permanent-local t) (put 'vlf-file-size 'permanent-local t)
(autoload 'vlf-write "vlf-write" "Write current chunk to file.") (autoload 'vlf-write "vlf-write" "Write current chunk to file.")
@ -69,6 +72,8 @@
"Make whole file occur style index for REGEXP.") "Make whole file occur style index for REGEXP.")
(autoload 'vlf-toggle-follow "vlf-follow" (autoload 'vlf-toggle-follow "vlf-follow"
"Toggle continuous chunk recenter around current point.") "Toggle continuous chunk recenter around current point.")
(autoload 'vlf-stop-follow "vlf-follow"
"Stop continuous recenter.")
(defvar vlf-mode-map (defvar vlf-mode-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
@ -112,22 +117,19 @@
:keymap vlf-prefix-map :keymap vlf-prefix-map
(if vlf-mode (if vlf-mode
(progn (progn
(set (make-local-variable 'require-final-newline) nil) (setq-local require-final-newline nil)
(add-hook 'write-file-functions 'vlf-write nil t) (add-hook 'write-file-functions 'vlf-write nil t)
(set (make-local-variable 'revert-buffer-function) (setq-local revert-buffer-function 'vlf-revert)
'vlf-revert)
(make-local-variable 'vlf-batch-size) (make-local-variable 'vlf-batch-size)
(set (make-local-variable 'vlf-file-size) (setq vlf-file-size (vlf-get-file-size buffer-file-truename)
(vlf-get-file-size buffer-file-truename)) vlf-start-pos 0
(set (make-local-variable 'vlf-start-pos) 0) vlf-end-pos 0)
(set (make-local-variable 'vlf-end-pos) 0)
(set (make-local-variable 'vlf-follow-timer) nil)
(let* ((pos (position-bytes (point))) (let* ((pos (position-bytes (point)))
(start (* (/ pos vlf-batch-size) vlf-batch-size))) (start (* (/ pos vlf-batch-size) vlf-batch-size)))
(goto-char (byte-to-position (- pos start))) (goto-char (byte-to-position (- pos start)))
(vlf-move-to-batch start))) (vlf-move-to-batch start)))
(kill-local-variable 'revert-buffer-function) (kill-local-variable 'revert-buffer-function)
(vlf-stop-following) (vlf-stop-follow)
(when (or (not large-file-warning-threshold) (when (or (not large-file-warning-threshold)
(< vlf-file-size large-file-warning-threshold) (< vlf-file-size large-file-warning-threshold)
(y-or-n-p (format "Load whole file (%s)? " (y-or-n-p (format "Load whole file (%s)? "