+ 'face 'underline))
+ (set-buffer-modified-p nil)
+ (forward-char 2)
+ (vlf-occur-mode)
+ (setq default-directory dir
+ vlf-occur-vlf-file file
+ vlf-occur-vlf-buffer vlf-buffer
+ vlf-occur-regexp regexp
+ vlf-occur-hexl is-hexl
+ vlf-occur-lines line)))
+ (display-buffer occur-buffer)
+ (message "Occur finished for \"%s\" (%f secs)"
+ regexp (- (float-time) time))))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; save, load vlf-occur data
+
+(defun vlf-occur-save (file)
+ "Serialize `vlf-occur' results to FILE which can later be reloaded."
+ (interactive (list (or buffer-file-name
+ (read-file-name "Save vlf-occur results in: "
+ nil nil nil
+ (concat
+ (file-name-nondirectory
+ vlf-occur-vlf-file)
+ ".vlfo")))))
+ (setq buffer-file-name file)
+ (let ((vlf-occur-save-buffer
+ (generate-new-buffer (concat "*VLF-occur-save "
+ (file-name-nondirectory file)
+ "*"))))
+ (with-current-buffer vlf-occur-save-buffer
+ (setq buffer-file-name file
+ buffer-undo-list t)
+ (insert ";; -*- eval: (vlf-occur-load) -*-\n"))
+ (prin1 (list vlf-occur-vlf-file vlf-occur-regexp vlf-occur-hexl
+ vlf-occur-lines)
+ vlf-occur-save-buffer)
+ (save-excursion
+ (goto-char (point-min))
+ (let ((pmax (point-max)))
+ (while (/= pmax (goto-char (next-single-char-property-change
+ (1+ (point)) 'vlf-match)))
+ (let* ((pos (1+ (point)))
+ (line (get-char-property (1- pos) 'before-string)))
+ (if line
+ (prin1 (list (string-to-number line)
+ (get-text-property pos 'chunk-start)
+ (get-text-property pos 'chunk-end)
+ (get-text-property pos 'line-pos)
+ (buffer-substring-no-properties
+ pos (1- (next-single-char-property-change
+ pos 'vlf-match))))
+ vlf-occur-save-buffer))))))
+ (with-current-buffer vlf-occur-save-buffer
+ (save-buffer))
+ (kill-buffer vlf-occur-save-buffer))
+ t)
+
+;;;###autoload
+(defun vlf-occur-load ()
+ "Load serialized `vlf-occur' results from current buffer."
+ (interactive)
+ (goto-char (point-min))
+ (let* ((vlf-occur-data-buffer (current-buffer))
+ (header (read vlf-occur-data-buffer))
+ (vlf-file (nth 0 header))
+ (regexp (nth 1 header))
+ (all-lines (nth 3 header))
+ (file buffer-file-name)
+ (vlf-occur-buffer
+ (generate-new-buffer (concat "*VLF-occur "
+ (file-name-nondirectory file)
+ "*"))))
+ (switch-to-buffer vlf-occur-buffer)
+ (setq buffer-file-name file
+ buffer-undo-list t)
+ (goto-char (point-min))
+ (let ((match-count 0)
+ (form 0))
+ (while (setq form (ignore-errors (read vlf-occur-data-buffer)))
+ (goto-char (point-max))
+ (insert "\n:")
+ (let* ((overlay-pos (1- (point)))
+ (overlay (make-overlay overlay-pos (1+ overlay-pos)))
+ (line (number-to-string (nth 0 form)))
+ (pos (point)))
+ (overlay-put overlay 'before-string
+ (propertize line 'face 'shadow))
+ (overlay-put overlay 'vlf-match t)
+ (insert (propertize (nth 4 form) 'chunk-start (nth 1 form)
+ 'chunk-end (nth 2 form)
+ 'mouse-face '(highlight)
+ 'line-pos (nth 3 form)
+ 'help-echo (concat "Move to line "
+ line)))
+ (goto-char pos)
+ (while (re-search-forward regexp nil t)
+ (add-text-properties
+ (match-beginning 0) (match-end 0)
+ (list 'face 'match 'help-echo
+ (format "Move to match %d"
+ (setq match-count (1+ match-count))))))))
+ (kill-buffer vlf-occur-data-buffer)
+ (goto-char (point-min))
+ (insert (propertize
+ (format "%d matches from %d lines for \"%s\" in file: %s"
+ match-count all-lines regexp vlf-file)
+ 'face 'underline)))
+ (set-buffer-modified-p nil)
+ (vlf-occur-mode)
+ (setq vlf-occur-vlf-file vlf-file
+ vlf-occur-regexp regexp
+ vlf-occur-hexl (nth 2 header)
+ vlf-occur-lines all-lines)))