[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf 4134de0 177/310: Add intelligent recenter chunk aro
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf 4134de0 177/310: Add intelligent recenter chunk around point functionality. |
Date: |
Sat, 28 Nov 2020 00:33:10 -0500 (EST) |
branch: externals/vlf
commit 4134de068fe97e308dff2c684adce9fd2af468ca
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Add intelligent recenter chunk around point functionality.
---
README.org | 13 +++++++++++++
vlf.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
diff --git a/README.org b/README.org
index 045ab0c..9acd286 100644
--- a/README.org
+++ b/README.org
@@ -79,6 +79,9 @@ refresh with *C-c C-v g*.
** Move around
+Scrolling automatically triggers moving to previous or next chunk at
+the beginning or end respectively of the current one.
+
*C-c C-v n* and *C-c C-v p* move batch by batch. With positive
prefix argument they move prefix number of batches. With negative -
append prefix number of batches.
@@ -93,6 +96,16 @@ 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.
+** Follow point
+
+Intelligent continuous recenter around point in current buffer can be
+enabled with:
+
+*M-x vlf-start-following*
+
+You are asked for number of idle seconds interval for automatic
+update. To cancel following invoke *M-x vlf-stop-following*.
+
** Search whole file
*C-c C-v s* and *C-c C-v r* search forward and backward respectively
diff --git a/vlf.el b/vlf.el
index 73b133f..d38aa35 100644
--- a/vlf.el
+++ b/vlf.el
@@ -73,6 +73,11 @@ Possible values are: nil to never use it;
(defvar vlf-file-size 0 "Total size of presented file.")
(put 'vlf-file-size 'permanent-local t)
+(defvar vlf-follow-timer nil
+ "Contains timer and it's repeat interval if vlf buffer is set to\
+continuously recenter.")
+(put 'vlf-follow-timer 'permanent-local t)
+
(defvar vlf-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "n" 'vlf-next-batch)
@@ -125,11 +130,13 @@ Possible values are: nil to never use it;
(vlf-get-file-size buffer-file-truename))
(set (make-local-variable 'vlf-start-pos) 0)
(set (make-local-variable 'vlf-end-pos) 0)
+ (set (make-local-variable 'vlf-follow-timer) nil)
(let* ((pos (position-bytes (point)))
(start (* (/ pos vlf-batch-size) vlf-batch-size)))
(goto-char (byte-to-position (- pos start)))
(vlf-move-to-batch start)))
(kill-local-variable 'revert-buffer-function)
+ (vlf-stop-following)
(when (or (not large-file-warning-threshold)
(< vlf-file-size large-file-warning-threshold)
(y-or-n-p (format "Load whole file (%s)? "
@@ -564,6 +571,50 @@ This seems to be the case with GNU/Emacs before 24.4."
(string-lessp emacs-version "24.3.5"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; follow point
+
+(defun vlf-recenter (vlf-buffer)
+ "Recenter chunk around current point in VLF-BUFFER."
+ (and vlf-follow-timer
+ (eq (current-buffer) vlf-buffer)
+ (or (pos-visible-in-window-p (point-min))
+ (pos-visible-in-window-p (point-max)))
+ (let ((current-pos (+ vlf-start-pos (position-bytes (point))))
+ (half-batch (/ vlf-batch-size 2)))
+ (if (buffer-modified-p)
+ (progn
+ (let ((edit-end (+ (position-bytes (point-max))
+ vlf-start-pos)))
+ (vlf-move-to-chunk (min vlf-start-pos
+ (- current-pos half-batch))
+ (max edit-end
+ (+ current-pos half-batch))))
+ (goto-char (byte-to-position (- current-pos
+ vlf-start-pos))))
+ (vlf-move-to-batch (- current-pos half-batch))
+ (and (< half-batch current-pos)
+ (< half-batch (- vlf-file-size current-pos))
+ (goto-char (byte-to-position half-batch)))))))
+
+(defun vlf-stop-following ()
+ "Stop continuous recenter."
+ (interactive)
+ (when vlf-follow-timer
+ (cancel-timer (car vlf-follow-timer))
+ (setq vlf-follow-timer nil)))
+
+(defun vlf-start-following (interval)
+ "Continuously recenter chunk around point every INTERVAL seconds."
+ (interactive "nNumber of seconds: ")
+ (when vlf-mode
+ (vlf-stop-following)
+ (setq vlf-follow-timer (cons (run-with-idle-timer interval interval
+ 'vlf-recenter
+ (current-buffer))
+ interval))
+ (add-hook 'kill-buffer-hook 'vlf-stop-following nil t)))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; search
(defun vlf-re-search (regexp count backward batch-step)
- [elpa] externals/vlf a65f3a4 143/310: Check for unsaved changes before search query and don't enable undo if, (continued)
- [elpa] externals/vlf a65f3a4 143/310: Check for unsaved changes before search query and don't enable undo if, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 42e581d 144/310: Add command to unconditionally open fresh VLF buffer to visit occur, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 3e8098a 149/310: Rename vlf-discard-edit -> vlf-refresh., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c0a85cd 159/310: Fix position when moving to overlapping chunk., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2aea17a 163/310: Fix behaviour when size is missing (creating file) in, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 88924f9 164/310: Fix vlf-write behaviour for newly created file., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 9c50487 165/310: Introduce list of major modes where VLF will not activate., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 152462a 166/310: Fix autoloads in last commit., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e67895a 068/310: Optionally strip superfluous operations when inserting batches., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 6773248 104/310: Optimize a bit goto line., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4134de0 177/310: Add intelligent recenter chunk around point functionality.,
Stefan Monnier <=
- [elpa] externals/vlf 9b22b74 134/310: Add gitignore., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2dba838 140/310: In case original VLF buffer has been killed, try to find existing VLF, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf efae918 138/310: Turn vlf into minor mode., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e36492b 182/310: Optimize chunk jumping for current GNU Emacs releases. Fix moving by, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f1ade81 069/310: Add go to line command., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 3fb898e 070/310: Add automatic batching when scrolling., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf fc689d5 071/310: Make coding system conversion on write more idiomatic., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 74febeb 072/310: Remove ability to launch VLFI from file end. It's superseded by, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4699008 074/310: Make chunk adjusting automatic., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 538a9e6 075/310: Apply chunk decoding adjustment implicitly., Stefan Monnier, 2020/11/28