mirror of
				https://github.com/m00natic/vlfi.git
				synced 2025-10-30 22:53:37 +00:00 
			
		
		
		
	Fix chunk end adjustment and save for current and older Emacsen.
This commit is contained in:
		
							
								
								
									
										46
									
								
								vlf.el
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								vlf.el
									
									
									
									
									
								
							| @@ -373,9 +373,8 @@ Return t if move hasn't been canceled." | |||||||
|             (inhibit-read-only t)) |             (inhibit-read-only t)) | ||||||
|         (cond ((< end edit-end) |         (cond ((< end edit-end) | ||||||
|                (vlf-with-undo-disabled |                (vlf-with-undo-disabled | ||||||
|                 (delete-region (byte-to-position (1+ |                 (delete-region (byte-to-position | ||||||
|                                                   (- end |                                 (1+ (- end vlf-start-pos))) | ||||||
|                                                      vlf-start-pos))) |  | ||||||
|                                (point-max)))) |                                (point-max)))) | ||||||
|               ((< edit-end end) |               ((< edit-end end) | ||||||
|                (let ((edit-end-pos (point-max))) |                (let ((edit-end-pos (point-max))) | ||||||
| @@ -432,18 +431,17 @@ Return t if move hasn't been canceled." | |||||||
|  |  | ||||||
| (defun vlf-adjust-chunk (start end &optional adjust-start adjust-end | (defun vlf-adjust-chunk (start end &optional adjust-start adjust-end | ||||||
|                                position) |                                position) | ||||||
|   "Adjust chunk at absolute START to END till content can be \ |   "Adjust chunk at absolute START to END till content can be\ | ||||||
| properly decoded.  ADJUST-START determines if trying to prepend bytes\ | properly decoded.  ADJUST-START determines if trying to prepend bytes\ | ||||||
|  to the beginning, ADJUST-END - append to the end. |  to the beginning, ADJUST-END - append to the end. | ||||||
| Use buffer POSITION as start if given. | Use buffer POSITION as start if given. | ||||||
| Return number of bytes moved back for proper decoding and number of | Return number of bytes moved back for proper decoding and number of | ||||||
| bytes added to the end." | bytes added to the end." | ||||||
|   (let ((position (or position (point-min))) |   (let ((shift-start 0) | ||||||
|         (shift-start 0) |         (shift-end 0)) | ||||||
|         (shift-end 0) |  | ||||||
|         (chunk-size (- end start))) |  | ||||||
|     ;; adjust beginning |  | ||||||
|     (if adjust-start |     (if adjust-start | ||||||
|  |         (let ((position (or position (point-min))) | ||||||
|  |               (chunk-size (- end start))) | ||||||
|           (while (and (not (zerop start)) |           (while (and (not (zerop start)) | ||||||
|                       (< shift-start 4) |                       (< shift-start 4) | ||||||
|                       (< 4 (abs (- chunk-size |                       (< 4 (abs (- chunk-size | ||||||
| @@ -456,19 +454,35 @@ bytes added to the end." | |||||||
|                   chunk-size (1+ chunk-size)) |                   chunk-size (1+ chunk-size)) | ||||||
|             (delete-region position (point-max)) |             (delete-region position (point-max)) | ||||||
|             (goto-char position) |             (goto-char position) | ||||||
|           (insert-file-contents buffer-file-name nil start end))) |             (insert-file-contents buffer-file-name nil start end)))) | ||||||
|     ;; adjust end |     (if adjust-end | ||||||
|     (when (and adjust-end (< end vlf-file-size)) |         (cond ((vlf-partial-decode-shown-p) ;remove raw bytes from end | ||||||
|       (let ((expected-size (buffer-size))) ; in case partial symbol is not displayed |                (goto-char (point-max)) | ||||||
|         (while (and (= expected-size (buffer-size)) |                (while (eq (char-charset (preceding-char)) 'eight-bit) | ||||||
|                     (< end vlf-file-size)) |                  (setq shift-end (1- shift-end)) | ||||||
|  |                  (delete-char -1))) | ||||||
|  |               ((< end vlf-file-size) ;add bytes until new character is displayed | ||||||
|  |                (let ((position (or position (point-min))) | ||||||
|  |                      (expected-size (buffer-size))) | ||||||
|  |                  (while (and (progn | ||||||
|                                (setq shift-end (1+ shift-end) |                                (setq shift-end (1+ shift-end) | ||||||
|                                      end (1+ end)) |                                      end (1+ end)) | ||||||
|                                (delete-region position (point-max)) |                                (delete-region position (point-max)) | ||||||
|                                (goto-char position) |                                (goto-char position) | ||||||
|           (insert-file-contents buffer-file-name nil start end)))) |                                (insert-file-contents buffer-file-name | ||||||
|  |                                                      nil start end) | ||||||
|  |                                (< end vlf-file-size)) | ||||||
|  |                              (= expected-size (buffer-size)))))))) | ||||||
|     (cons shift-start shift-end))) |     (cons shift-start shift-end))) | ||||||
|  |  | ||||||
|  | (defun vlf-partial-decode-shown-p () | ||||||
|  |   "Determine if partial decode codes are displayed. | ||||||
|  | This seems to be the case with GNU/Emacs before 24.4." | ||||||
|  |   (cond ((< emacs-major-version 24) t) | ||||||
|  |         ((< 24 emacs-major-version) nil) | ||||||
|  |         (t ;; TODO: use (< emacs-minor-version 4) after 24.4 release | ||||||
|  |          (string-lessp emacs-version "24.3.5")))) | ||||||
|  |  | ||||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||||
| ;;; search | ;;; search | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user