mirror of
https://github.com/m00natic/vlfi.git
synced 2025-09-19 19:52:08 +01:00
Extend vlfi-goto-line to count lines from the end with negative
argument.
This commit is contained in:
18
vlfi.el
18
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)
|
(defun vlfi-re-search (regexp count backward batch-step)
|
||||||
"Search for REGEXP COUNT number of times forward or BACKWARD.
|
"Search for REGEXP COUNT number of times forward or BACKWARD.
|
||||||
BATCH-STEP is amount of overlap between successive chunks."
|
BATCH-STEP is amount of overlap between successive chunks."
|
||||||
|
(assert (< 0 count))
|
||||||
(let* ((match-chunk-start vlfi-start-pos)
|
(let* ((match-chunk-start vlfi-start-pos)
|
||||||
(match-chunk-end vlfi-end-pos)
|
(match-chunk-end vlfi-end-pos)
|
||||||
(match-start-pos (+ vlfi-start-pos (position-bytes (point))))
|
(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)))
|
(vlfi-re-search regexp count t (/ vlfi-batch-size 8)))
|
||||||
|
|
||||||
(defun vlfi-goto-line (n)
|
(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: ")
|
(interactive "nGo to line: ")
|
||||||
(let ((start-pos vlfi-start-pos)
|
(let ((start-pos vlfi-start-pos)
|
||||||
(end-pos vlfi-end-pos)
|
(end-pos vlfi-end-pos)
|
||||||
(pos (point))
|
(pos (point))
|
||||||
(success nil))
|
(success nil))
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(progn (vlfi-beginning-of-file)
|
(if (< 0 n)
|
||||||
(goto-char (point-min))
|
(progn (vlfi-beginning-of-file)
|
||||||
(setq success (vlfi-re-search "[\n\C-m]" (1- n)
|
(goto-char (point-min))
|
||||||
nil 0)))
|
(setq success (vlfi-re-search "[\n\C-m]" (1- n)
|
||||||
(unless success
|
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)
|
(vlfi-move-to-chunk start-pos end-pos)
|
||||||
(goto-char pos)))))
|
(goto-char pos)))))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user