mirror of
https://github.com/m00natic/vlfi.git
synced 2025-02-07 13:40:49 +00:00
Review fixes:
- move put statements to top level - add write-file-functions hook locally - vlfi-if-file-too-large becomes around advice - minor style changes
This commit is contained in:
parent
c1aedbc307
commit
8ed919209a
33
vlfi.el
33
vlfi.el
@ -70,23 +70,22 @@
|
|||||||
map)
|
map)
|
||||||
"Keymap for `vlfi-mode'.")
|
"Keymap for `vlfi-mode'.")
|
||||||
|
|
||||||
|
(put 'vlfi-batch-size 'permanent-local t)
|
||||||
|
(put 'vlfi-start-pos 'permanent-local t)
|
||||||
|
(put 'vlfi-end-pos 'permanent-local t)
|
||||||
|
(put 'vlfi-file-size 'permanent-local t)
|
||||||
(define-derived-mode vlfi-mode special-mode "VLFI"
|
(define-derived-mode vlfi-mode special-mode "VLFI"
|
||||||
"Mode to browse large files in."
|
"Mode to browse large files in."
|
||||||
(setq buffer-read-only t)
|
(setq buffer-read-only t)
|
||||||
(set-buffer-modified-p nil)
|
(set-buffer-modified-p nil)
|
||||||
(buffer-disable-undo)
|
(buffer-disable-undo)
|
||||||
(make-local-variable 'write-file-functions)
|
(add-hook 'write-file-functions 'vlfi-write nil t)
|
||||||
(add-hook 'write-file-functions 'vlfi-write)
|
|
||||||
(make-local-variable 'revert-buffer-function)
|
(make-local-variable 'revert-buffer-function)
|
||||||
(setq revert-buffer-function 'vlfi-revert)
|
(setq revert-buffer-function 'vlfi-revert)
|
||||||
(make-local-variable 'vlfi-batch-size)
|
(make-local-variable 'vlfi-batch-size)
|
||||||
(put 'vlfi-batch-size 'permanent-local t)
|
|
||||||
(make-local-variable 'vlfi-start-pos)
|
(make-local-variable 'vlfi-start-pos)
|
||||||
(put 'vlfi-start-pos 'permanent-local t)
|
|
||||||
(make-local-variable 'vlfi-end-pos)
|
(make-local-variable 'vlfi-end-pos)
|
||||||
(put 'vlfi-end-pos 'permanent-local t)
|
(make-local-variable 'vlfi-file-size))
|
||||||
(make-local-variable 'vlfi-file-size)
|
|
||||||
(put 'vlfi-file-size 'permanent-local t))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun vlfi (file)
|
(defun vlfi (file)
|
||||||
@ -117,9 +116,12 @@ buffer. You can customize number of bytes displayed by customizing
|
|||||||
'(define-key dired-mode-map "V" 'dired-vlfi))
|
'(define-key dired-mode-map "V" 'dired-vlfi))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun vlfi-if-file-too-large (size op-type &optional filename)
|
(defadvice abort-if-file-too-large (around vlfi-if-file-too-large
|
||||||
|
(size op-type
|
||||||
|
&optional filename)
|
||||||
|
compile activate)
|
||||||
"If file SIZE larger than `large-file-warning-threshold', \
|
"If file SIZE larger than `large-file-warning-threshold', \
|
||||||
allow user to view file with `vlfi', open it normally or abort.
|
allow user to view file with `vlfi', open it normally, or abort.
|
||||||
OP-TYPE specifies the file operation being performed over FILENAME."
|
OP-TYPE specifies the file operation being performed over FILENAME."
|
||||||
(and large-file-warning-threshold size
|
(and large-file-warning-threshold size
|
||||||
(> size large-file-warning-threshold)
|
(> size large-file-warning-threshold)
|
||||||
@ -144,15 +146,12 @@ OP-TYPE specifies the file operation being performed over FILENAME."
|
|||||||
((memq char '(?a ?A))
|
((memq char '(?a ?A))
|
||||||
(error "Aborted"))))))
|
(error "Aborted"))))))
|
||||||
|
|
||||||
;; hijack `abort-if-file-too-large'
|
|
||||||
;;;###autoload
|
|
||||||
(fset 'abort-if-file-too-large 'vlfi-if-file-too-large)
|
|
||||||
|
|
||||||
;; scroll auto batching
|
;; scroll auto batching
|
||||||
(defadvice scroll-up (around vlfi-scroll-up
|
(defadvice scroll-up (around vlfi-scroll-up
|
||||||
activate compile)
|
activate compile)
|
||||||
"Slide to next batch if at end of buffer in `vlfi-mode'."
|
"Slide to next batch if at end of buffer in `vlfi-mode'."
|
||||||
(if (and (eq major-mode 'vlfi-mode)
|
(if (and (derived-mode-p 'vlfi-mode)
|
||||||
(eobp))
|
(eobp))
|
||||||
(progn (vlfi-next-batch 1)
|
(progn (vlfi-next-batch 1)
|
||||||
(goto-char (point-min)))
|
(goto-char (point-min)))
|
||||||
@ -161,7 +160,7 @@ OP-TYPE specifies the file operation being performed over FILENAME."
|
|||||||
(defadvice scroll-down (around vlfi-scroll-down
|
(defadvice scroll-down (around vlfi-scroll-down
|
||||||
activate compile)
|
activate compile)
|
||||||
"Slide to previous batch if at beginning of buffer in `vlfi-mode'."
|
"Slide to previous batch if at beginning of buffer in `vlfi-mode'."
|
||||||
(if (and (eq major-mode 'vlfi-mode)
|
(if (and (derived-mode-p 'vlfi-mode)
|
||||||
(bobp))
|
(bobp))
|
||||||
(progn (vlfi-prev-batch 1)
|
(progn (vlfi-prev-batch 1)
|
||||||
(goto-char (point-max)))
|
(goto-char (point-max)))
|
||||||
@ -181,8 +180,6 @@ OP-TYPE specifies the file operation being performed over FILENAME."
|
|||||||
Normally, the value is doubled;
|
Normally, the value is doubled;
|
||||||
with the prefix argument DECREASE it is halved."
|
with the prefix argument DECREASE it is halved."
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(or (assq 'vlfi-batch-size (buffer-local-variables))
|
|
||||||
(error "%s is not local in this buffer" 'vlfi-batch-size))
|
|
||||||
(setq vlfi-batch-size (if decrease
|
(setq vlfi-batch-size (if decrease
|
||||||
(/ vlfi-batch-size 2)
|
(/ vlfi-batch-size 2)
|
||||||
(* vlfi-batch-size 2)))
|
(* vlfi-batch-size 2)))
|
||||||
@ -298,8 +295,8 @@ When prefix argument is negative
|
|||||||
(if do-prepend
|
(if do-prepend
|
||||||
vlfi-start-pos
|
vlfi-start-pos
|
||||||
vlfi-end-pos))
|
vlfi-end-pos))
|
||||||
(setq vlfi-start-pos start)
|
(setq vlfi-start-pos start
|
||||||
(setq pos (+ pos (vlfi-adjust-chunk)))
|
pos (+ pos (vlfi-adjust-chunk)))
|
||||||
(goto-char (or (byte-to-position (- (position-bytes (point-max))
|
(goto-char (or (byte-to-position (- (position-bytes (point-max))
|
||||||
pos))
|
pos))
|
||||||
(point-max))))
|
(point-max))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user