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

Apply chunk decoding adjustment implicitly.

This commit is contained in:
Andrey Kotlarski 2013-04-14 19:48:02 +03:00
parent 469900878d
commit 538a9e6049

46
vlfi.el
View File

@ -67,7 +67,6 @@
(define-key map "e" 'vlfi-edit-mode) (define-key map "e" 'vlfi-edit-mode)
(define-key map "j" 'vlfi-jump-to-chunk) (define-key map "j" 'vlfi-jump-to-chunk)
(define-key map "l" 'vlfi-goto-line) (define-key map "l" 'vlfi-goto-line)
(define-key map "a" 'vlfi-adjust-chunk)
map) map)
"Keymap for `vlfi-mode'.") "Keymap for `vlfi-mode'.")
@ -264,6 +263,7 @@ When prefix argument is negative
end) end)
(goto-char pos)) (goto-char pos))
(setq vlfi-end-pos end)) (setq vlfi-end-pos end))
(vlfi-adjust-chunk)
(set-visited-file-modtime) (set-visited-file-modtime)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(vlfi-update-buffer-name)) (vlfi-update-buffer-name))
@ -290,8 +290,9 @@ When prefix argument is negative
(if do-prepend (if do-prepend
vlfi-start-pos vlfi-start-pos
vlfi-end-pos)) vlfi-end-pos))
(goto-char (- (point-max) pos)) (setq vlfi-start-pos start)
(setq vlfi-start-pos start)) (vlfi-adjust-chunk)
(goto-char (- (point-max) pos)))
(set-visited-file-modtime) (set-visited-file-modtime)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(vlfi-update-buffer-name)) (vlfi-update-buffer-name))
@ -311,6 +312,7 @@ When given MINIMAL flag, skip non important operations."
(erase-buffer) (erase-buffer)
(insert-file-contents buffer-file-name nil (insert-file-contents buffer-file-name nil
vlfi-start-pos vlfi-end-pos) vlfi-start-pos vlfi-end-pos)
(vlfi-adjust-chunk)
(goto-char pos)) (goto-char pos))
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(unless minimal (unless minimal
@ -329,12 +331,31 @@ When given MINIMAL flag, skip non important operations."
(erase-buffer) (erase-buffer)
(insert-file-contents buffer-file-name nil (insert-file-contents buffer-file-name nil
vlfi-start-pos vlfi-end-pos) vlfi-start-pos vlfi-end-pos)
(vlfi-adjust-chunk)
(goto-char pos)) (goto-char pos))
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(unless minimal (unless minimal
(set-visited-file-modtime) (set-visited-file-modtime)
(vlfi-update-buffer-name))) (vlfi-update-buffer-name)))
(defun vlfi-adjust-chunk ()
"Adjust chunk beginning until content can be properly decoded."
(or (zerop vlfi-start-pos)
(let ((pos (point)))
(while (/= (- vlfi-end-pos vlfi-start-pos)
(length (encode-coding-region
(point-min) (point-max)
buffer-file-coding-system t)))
(setq pos (1- pos)
vlfi-start-pos (1- vlfi-start-pos))
(let ((inhibit-read-only t))
(erase-buffer)
(insert-file-contents buffer-file-name nil
vlfi-start-pos vlfi-end-pos)))
(set-buffer-modified-p nil)
(goto-char pos))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; search ;;; search
@ -461,25 +482,6 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
(vlfi-move-to-chunk start-pos end-pos) (vlfi-move-to-chunk start-pos end-pos)
(goto-char pos))))) (goto-char pos)))))
(defun vlfi-adjust-chunk ()
"Adjust chunk beginning until content can be properly decoded."
(interactive)
(or (zerop vlfi-start-pos)
(let ((pos (point)))
(while (/= (- vlfi-end-pos vlfi-start-pos)
(length (encode-coding-region
(point-min) (point-max)
buffer-file-coding-system t)))
(setq pos (1- pos)
vlfi-start-pos (1- vlfi-start-pos))
(let ((inhibit-read-only t))
(erase-buffer)
(insert-file-contents buffer-file-name nil
vlfi-start-pos vlfi-end-pos)))
(set-buffer-modified-p nil)
(goto-char pos))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; editing ;;; editing