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

First feature complete version of vlfi-occur.

This commit is contained in:
Andrey Kotlarski 2013-04-16 14:29:42 +03:00
parent 681d3d94fc
commit 641ff4b961

80
vlfi.el
View File

@ -526,6 +526,8 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(define-key map "n" 'vlfi-occur-next-match) (define-key map "n" 'vlfi-occur-next-match)
(define-key map "p" 'vlfi-occur-prev-match) (define-key map "p" 'vlfi-occur-prev-match)
(define-key map "\C-m" 'vlfi-occur-visit)
(define-key map [mouse-1] 'vlfi-occur-visit)
map) map)
"Keymap for command `vlfi-occur-mode'.") "Keymap for command `vlfi-occur-mode'.")
@ -550,6 +552,34 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(goto-char (or (previous-single-property-change (point) 'face) (goto-char (or (previous-single-property-change (point) 'face)
(point-max))))) (point-max)))))
(defun vlfi-occur-visit (&optional event)
"Visit current `vlfi-occur' link in a vlfi buffer.
The same for mouse EVENT."
(interactive (list last-nonmenu-event))
(when event
(switch-to-buffer (window-buffer (posn-window (event-end event))))
(goto-char (posn-point (event-end event))))
(let* ((pos (point))
(pos-relative (- pos (line-beginning-position)))
(file (get-char-property pos 'file)))
(if file
(let ((chunk-start (get-char-property pos 'chunk-start))
(chunk-end (get-char-property pos 'chunk-end))
(buffer (get-char-property pos 'buffer))
(match-pos (or (get-char-property pos 'match-pos)
(+ (get-char-property pos 'line-pos)
(if (< 8 pos-relative)
(- pos-relative 8)
0)))))
(unless (buffer-live-p buffer)
(let ((occur-buffer (current-buffer)))
(setq buffer (vlfi file))
(switch-to-buffer occur-buffer)))
(pop-to-buffer buffer)
(vlfi-move-to-chunk chunk-start chunk-end)
(set-buffer buffer)
(goto-char match-pos)))))
(defun vlfi-occur (regexp) (defun vlfi-occur (regexp)
"Make occur style index for REGEXP." "Make occur style index for REGEXP."
(interactive (list (read-regexp "List lines matching regexp" (interactive (list (read-regexp "List lines matching regexp"
@ -567,7 +597,7 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(defun vlfi-build-occur (regexp) (defun vlfi-build-occur (regexp)
"Build occur style index for REGEXP." "Build occur style index for REGEXP."
(let ((line 1) (let ((line 1)
(last-line-result 0) (last-match-line 0)
(last-line-pos (point-min)) (last-line-pos (point-min))
(file buffer-file-name) (file buffer-file-name)
(match-end-pos (+ vlfi-start-pos (position-bytes (point)))) (match-end-pos (+ vlfi-start-pos (position-bytes (point))))
@ -592,30 +622,42 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(if (match-string 5) (if (match-string 5)
(setq line (1+ line) (setq line (1+ line)
last-line-pos (point)) last-line-pos (point))
(let ((line-text (buffer-substring (let* ((chunk-start vlfi-start-pos)
(line-beginning-position) (chunk-end vlfi-end-pos)
(line-end-position)))) (vlfi-buffer (current-buffer))
(line-pos (line-beginning-position))
(line-text (buffer-substring
line-pos (line-end-position))))
(with-current-buffer occur-buffer (with-current-buffer occur-buffer
(or (= line last-line-result) (unless (= line last-match-line)
(insert (propertize (insert (propertize
(format "%6d:%s\n" line (format "%7d:" line)
line-text) 'file file
'file file 'buffer vlfi-buffer
'chunk-start vlfi-start-pos 'chunk-start chunk-start
'chunk-end vlfi-end-pos 'chunk-end chunk-end
'match-pos 'face 'shadow
(match-beginning 10)))) 'mouse-face '(highlight)
'line-pos line-pos))
(insert (propertize
(format "%s\n" line-text)
'file file
'buffer vlfi-buffer
'chunk-start chunk-start
'chunk-end chunk-end
'mouse-face '(highlight)
'line-pos line-pos)))
(forward-line -1) (forward-line -1)
(let ((line-start (+ (line-beginning-position) (let ((line-start (+ (line-beginning-position)
7))) 8))
(match-pos (match-beginning 10)))
(add-text-properties (add-text-properties
(+ line-start (match-beginning 10) (+ line-start match-pos (- last-line-pos))
(- last-line-pos))
(+ line-start (match-end 10) (+ line-start (match-end 10)
(- last-line-pos)) (- last-line-pos))
(list 'face 'match))) (list 'face 'match 'match-pos match-pos)))
(forward-line) (forward-line)
(setq last-line-result line))))) (setq last-match-line line)))))
(let ((batch-move (- vlfi-end-pos batch-step))) (let ((batch-move (- vlfi-end-pos batch-step)))
(vlfi-move-to-batch (if (< batch-move match-end-pos) (vlfi-move-to-batch (if (< batch-move match-end-pos)
match-end-pos match-end-pos
@ -625,6 +667,8 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
vlfi-start-pos)) vlfi-start-pos))
(point-min)) (point-min))
(point-min))) (point-min)))
(setq last-match-line 0
last-line-pos (point-min))
(progress-reporter-update reporter vlfi-end-pos))) (progress-reporter-update reporter vlfi-end-pos)))
(progress-reporter-done reporter)) (progress-reporter-done reporter))
(with-current-buffer occur-buffer (with-current-buffer occur-buffer