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

Add vlf-application customization which refines control over when

vlf-mode is automatically invoked or offered.
This commit is contained in:
Andrey Kotlarski 2013-12-11 02:54:44 +02:00
parent c0a85cdcfe
commit c68c34ea90

67
vlf.el
View File

@ -45,10 +45,23 @@
(defcustom vlf-batch-size 1024 (defcustom vlf-batch-size 1024
"Defines how large each batch of file data is (in bytes)." "Defines how large each batch of file data is (in bytes)."
:type 'integer :group 'vlf
:group 'vlf) :type 'integer)
(put 'vlf-batch-size 'permanent-local t) (put 'vlf-batch-size 'permanent-local t)
;;;###autoload
(defcustom vlf-application 'default
"Determines when `vlf' will be offered on opening files.
Possible values are: nil to never use it;
`default' offer `vlf' when file size is beyond `large-file-warning-threshold';
`dont-ask' automatically use `vlf' for large files;
`always' use `vlf' for all files."
:group 'vlf
:type '(radio (const :format "%v " nil)
(const :format "%v " default)
(const :format "%v " dont-ask)
(const :format "%v" always)))
;;; Keep track of file position. ;;; Keep track of file position.
(defvar vlf-start-pos 0 (defvar vlf-start-pos 0
"Absolute position of the visible chunk start.") "Absolute position of the visible chunk start.")
@ -150,28 +163,36 @@ You can customize number of bytes displayed by customizing
"If file SIZE larger than `large-file-warning-threshold', \ "If file SIZE larger than `large-file-warning-threshold', \
allow user to view file with `vlf', open it normally, or abort. allow user to view file with `vlf', 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 (cond
(> size large-file-warning-threshold) ((not vlf-application)
(let ((char nil)) ad-do-it)
(while (not (memq (setq char ((eq vlf-application 'always)
(read-event (vlf filename)
(propertize (error ""))
(format ((and large-file-warning-threshold
"File %s is large (%s): \ (> size large-file-warning-threshold))
(if (eq vlf-application 'dont-ask)
(progn (vlf filename)
(error ""))
(let ((char nil))
(while (not (memq (setq char
(read-event
(propertize
(format
"File %s is large (%s): \
%s normally (o), %s with vlf (v) or abort (a)" %s normally (o), %s with vlf (v) or abort (a)"
(if filename (if filename
(file-name-nondirectory filename) (file-name-nondirectory filename)
"") "")
(file-size-human-readable size) (file-size-human-readable size)
op-type op-type) op-type op-type)
'face 'minibuffer-prompt))) 'face 'minibuffer-prompt)))
'(?o ?O ?v ?V ?a ?A)))) '(?o ?O ?v ?V ?a ?A))))
(cond ((memq char '(?o ?O))) (cond ((memq char '(?v ?V))
((memq char '(?v ?V)) (vlf filename)
(vlf filename) (error ""))
(error "")) ((memq char '(?a ?A))
((memq char '(?a ?A)) (error "Aborted"))))))))
(error "Aborted"))))))
;; scroll auto batching ;; scroll auto batching