branch: externals/vlf commit 6192573ee088079bf1f81abc2bf2a370a5a92397 Author: Stefan Monnier <monn...@iro.umontreal.ca> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Require Emacs-24.4; avoid `defadvice`; fix compiler warnings Try and make some docstrings fit 80 columns. Use `advice-add` instead of `defadvice`. Prefer #' to quote function names. Remove redundant `:group` arguments. * vlf.el: Remove duplicate `Maintainer:`. Require Emacs-24.4. Remove `URL:` since the development now happens in `elpa.git`. ("hexl"): Don't bother using `eval-after-load` since advice can be added before the functions themselves are defined. * vlf-setup.el (vlf-application): Fix typo in :type format. (file-size-human-readable): Delete backward compatibility definition. (vlf-disable-for-function): Delete macro. (vlf--disabled): New function to replace it. (tags-verify-table, tag-find-file-of-tag-noselect) (helm-etags-create-buffer): Use it along with `advice-add`. * .gitignore: Add ELPA patterns. * vlf-ediff.el (vlf-ediff-files): Avoid obsolete `ediff-add-to-history`. (vlf--ediff-next-difference, vlf--ediff-prev-difference): Use `with-current-buffer`. * vlf-write.el (vlf-save-in-place): Fix `const` format. --- .gitignore | 6 ++- vlf-base.el | 10 ++--- vlf-ediff.el | 33 +++++++-------- vlf-follow.el | 6 +-- vlf-occur.el | 23 +++++------ vlf-setup.el | 63 ++++++++++++----------------- vlf-tune.el | 20 ++++----- vlf-write.el | 7 ++-- vlf.el | 128 +++++++++++++++++++++++++++++----------------------------- 9 files changed, 141 insertions(+), 155 deletions(-) diff --git a/.gitignore b/.gitignore index 6ba3e70f49..36fce167ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.elc -*~ \ No newline at end of file +*~ + +# ELPA-generated files +/vlf-autoloads.el +/vlf-pkg.el diff --git a/vlf-base.el b/vlf-base.el index 1c1c8e255e..55ee3a5802 100644 --- a/vlf-base.el +++ b/vlf-base.el @@ -1,6 +1,6 @@ ;;; vlf-base.el --- VLF primitive operations -*- lexical-binding: t -*- -;; Copyright (C) 2014-2017 Free Software Foundation, Inc. +;; Copyright (C) 2014-2023 Free Software Foundation, Inc. ;; Keywords: large files, chunk ;; Author: Andrey Kotlarski <m00nati...@gmail.com> @@ -264,8 +264,8 @@ bytes added to the end." (defun vlf-insert-file-contents (start end adjust-start adjust-end &optional position) - "Adjust chunk at absolute START to END till content can be\ -properly decoded. ADJUST-START determines if trying to prepend bytes + "Adjust chunk at absolute START to END so it can be properly decoded. +ADJUST-START determines if trying to prepend bytes to the beginning, ADJUST-END - append to the end. Use buffer POSITION as start if given. Return number of bytes moved back for proper decoding and number of @@ -302,8 +302,8 @@ bytes added to the end." (vlf-tune-insert-file-contents start end)))) (defun vlf-adjust-start (start end position adjust-end) - "Adjust chunk beginning at absolute START to END till content can\ -be properly decoded. Use buffer POSITION as start. + "Adjust chunk beginning at absolute START to END so it can be properly decoded. +Use buffer POSITION as start. ADJUST-END is non-nil if end would be adjusted later. Return number of bytes moved back for proper decoding." (let* ((safe-start (max 0 (- start 4))) diff --git a/vlf-ediff.el b/vlf-ediff.el index a28e24e220..6f3c9357f1 100644 --- a/vlf-ediff.el +++ b/vlf-ediff.el @@ -1,6 +1,6 @@ ;;; vlf-ediff.el --- VLF ediff functionality -*- lexical-binding: t -*- -;; Copyright (C) 2014-2017 Free Software Foundation, Inc. +;; Copyright (C) 2014-2023 Free Software Foundation, Inc. ;; Keywords: large files, compare, ediff ;; Author: Andrey Kotlarski <m00nati...@gmail.com> @@ -86,7 +86,7 @@ respectively of difference list, runs ediff over the adjacent chunks." ediff-last-dir-B (file-name-directory f))) (progn - (ediff-add-to-history + (add-to-history 'file-name-history (ediff-abbreviate-file-name (expand-file-name @@ -100,18 +100,16 @@ respectively of difference list, runs ediff over the adjacent chunks." (let ((buffer-B (vlf file-B t))) (vlf-ediff-buffers buffer-A buffer-B)))) -(defadvice ediff-next-difference (around vlf-ediff-next-difference - compile activate) - "Move to the next VLF chunk and search for difference if at the end\ -of difference list." +(advice-add 'ediff-next-difference :around #'vlf--ediff-next-difference) +(defun vlf--ediff-next-difference (orig-fun &rest args) + "Move to the next VLF chunk if needed." (if (and vlf-ediff-session (<= (1- ediff-number-of-differences) ediff-current-difference)) (let ((buffer-A ediff-buffer-A) (buffer-B ediff-buffer-B) (ediff-buffer (current-buffer))) - (save-excursion - (set-buffer buffer-A) + (with-current-buffer buffer-A (vlf-next-chunk) (set-buffer buffer-B) (vlf-next-chunk) @@ -119,19 +117,17 @@ of difference list." 'vlf-next-chunk)) (or (zerop ediff-number-of-differences) (ediff-jump-to-difference 1))) - ad-do-it)) + (apply orig-fun args))) -(defadvice ediff-previous-difference (around vlf-ediff-prev-difference - compile activate) - "Move to the previous VLF chunk and search for difference if at the\ -beginning of difference list." +(advice-add 'ediff-previous-difference :around #'vlf--ediff-prev-difference) +(defun vlf--ediff-prev-difference (orig-fun &rest args) + "Move to the previous VLF chunk if needed." (if (and vlf-ediff-session (<= ediff-current-difference 0)) (let ((buffer-A ediff-buffer-A) (buffer-B ediff-buffer-B) (ediff-buffer (current-buffer))) - (save-excursion - (set-buffer buffer-A) + (with-current-buffer buffer-A (vlf-prev-chunk) (set-buffer buffer-B) (vlf-prev-chunk) @@ -139,7 +135,7 @@ beginning of difference list." 'vlf-prev-chunk)) (or (zerop ediff-number-of-differences) (ediff-jump-to-difference -1))) - ad-do-it)) + (apply orig-fun args))) (defun vlf-next-chunk () "Move to next chunk." @@ -151,8 +147,9 @@ beginning of difference list." (defun vlf-ediff-next (buffer-A buffer-B ediff-buffer &optional next-func) - "Find next pair of chunks that differ in BUFFER-A and BUFFER-B\ -governed by EDIFF-BUFFER. NEXT-FUNC is used to jump to the next + "Find next pair of chunks that differ in BUFFER-A and BUFFER-B. +The buffers are summed to be governed by EDIFF-BUFFER. +NEXT-FUNC is used to jump to the next logical chunks in case there is no difference at the current ones." (set-buffer buffer-A) (run-hook-with-args 'vlf-before-batch-functions 'ediff) diff --git a/vlf-follow.el b/vlf-follow.el index 52f35cd11d..7a92803dbb 100644 --- a/vlf-follow.el +++ b/vlf-follow.el @@ -1,6 +1,6 @@ ;;; vlf-follow.el --- VLF chunk follows point functionality -*- lexical-binding: t -*- -;; Copyright (C) 2014-2017 Free Software Foundation, Inc. +;; Copyright (C) 2014-2023 Free Software Foundation, Inc. ;; Keywords: large files, follow, recenter ;; Author: Andrey Kotlarski <m00nati...@gmail.com> @@ -67,9 +67,9 @@ (defun vlf-start-follow (interval) "Continuously recenter chunk around point every INTERVAL seconds." (setq vlf-follow-timer (run-with-idle-timer interval interval - 'vlf-recenter + #'vlf-recenter (current-buffer))) - (add-hook 'kill-buffer-hook 'vlf-stop-follow nil t)) + (add-hook 'kill-buffer-hook #'vlf-stop-follow nil t)) (defun vlf-toggle-follow () "Toggle continuous chunk recenter around current point." diff --git a/vlf-occur.el b/vlf-occur.el index 717513e599..604124df98 100644 --- a/vlf-occur.el +++ b/vlf-occur.el @@ -1,6 +1,6 @@ ;;; vlf-occur.el --- Occur-like functionality for VLF -*- lexical-binding: t -*- -;; Copyright (C) 2014-2017 Free Software Foundation, Inc. +;; Copyright (C) 2014-2023 Free Software Foundation, Inc. ;; Keywords: large files, indexing, occur ;; Author: Andrey Kotlarski <m00nati...@gmail.com> @@ -49,19 +49,19 @@ (defvar vlf-occur-mode-map (let ((map (make-sparse-keymap))) - (define-key map "n" 'vlf-occur-next-match) - (define-key map "p" 'vlf-occur-prev-match) - (define-key map "\C-m" 'vlf-occur-visit) - (define-key map "\M-\r" 'vlf-occur-visit-new-buffer) - (define-key map [mouse-1] 'vlf-occur-visit) - (define-key map "o" 'vlf-occur-show) - (define-key map [remap save-buffer] 'vlf-occur-save) + (define-key map "n" #'vlf-occur-next-match) + (define-key map "p" #'vlf-occur-prev-match) + (define-key map "\C-m" #'vlf-occur-visit) + (define-key map "\M-\r" #'vlf-occur-visit-new-buffer) + (define-key map [mouse-1] #'vlf-occur-visit) + (define-key map "o" #'vlf-occur-show) + (define-key map [remap save-buffer] #'vlf-occur-save) map) "Keymap for command `vlf-occur-mode'.") (define-derived-mode vlf-occur-mode special-mode "VLF[occur]" "Major mode for showing occur matches of VLF opened files." - (add-hook 'write-file-functions 'vlf-occur-save nil t)) + (add-hook 'write-file-functions #'vlf-occur-save nil t)) (defun vlf-occur-next-match () "Move cursor to next match." @@ -82,9 +82,8 @@ (point-max))))) (defun vlf-occur-show (&optional event) - "Visit current `vlf-occur' link in a vlf buffer but stay in the \ -occur buffer. If original VLF buffer has been killed, -open new VLF session each time. + "Visit current `vlf-occur' link in a vlf buffer but stay in the occur buffer. +If original VLF buffer has been killed, open new VLF session each time. EVENT may hold details of the invocation." (interactive (list last-nonmenu-event)) (let ((occur-buffer (if event diff --git a/vlf-setup.el b/vlf-setup.el index aa061d0f28..77aec7e901 100644 --- a/vlf-setup.el +++ b/vlf-setup.el @@ -1,6 +1,6 @@ ;;; vlf-setup.el --- VLF integration with other packages -*- lexical-binding: t -*- -;; Copyright (C) 2014-2017 Free Software Foundation, Inc. +;; Copyright (C) 2014-2023 Free Software Foundation, Inc. ;; Keywords: large files, integration ;; Author: Andrey Kotlarski <m00nati...@gmail.com> @@ -31,7 +31,7 @@ (defcustom vlf-batch-size 1000000 "Defines how large each batch of file data initially is (in bytes)." - :group 'vlf :type 'integer) + :type 'integer) (defcustom vlf-application 'ask "Determines when `vlf' will be offered on opening files. @@ -39,25 +39,20 @@ Possible values are: nil to never use it; `ask' 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 " ask) - (const :format "%v " dont-ask) - (const :format "%v" always))) + :type '(radio (const :format "%v " nil) + (const :format "%v " ask) + (const :format "%v " dont-ask) + (const :format "%v " always))) (defcustom vlf-forbidden-modes-list '(archive-mode tar-mode jka-compr git-commit-mode image-mode doc-view-mode doc-view-mode-maybe ebrowse-tree-mode) "Major modes which VLF will not be automatically applied to." - :group 'vlf :type '(list symbol)) + :type '(list symbol)) (defvar dired-mode-map) (declare-function dired-get-file-for-visit "dired") -(unless (fboundp 'file-size-human-readable) - (defun file-size-human-readable (file-size) - "Print FILE-SIZE in MB." - (format "%.3fMB" (/ file-size 1048576.0)))) - (defun vlf-determine-major-mode (filename) "Determine major mode from FILENAME." (let ((name filename) @@ -73,26 +68,26 @@ Possible values are: nil to never use it; (if (memq system-type '(windows-nt cygwin)) ;; System is case-insensitive. (let ((case-fold-search t)) - (assoc-default name auto-mode-alist 'string-match)) + (assoc-default name auto-mode-alist #'string-match)) ;; System is case-sensitive. (or ;; First match case-sensitively. (let ((case-fold-search nil)) - (assoc-default name auto-mode-alist 'string-match)) + (assoc-default name auto-mode-alist #'string-match)) ;; Fallback to case-insensitive match. (and auto-mode-case-fold (let ((case-fold-search t)) (assoc-default name auto-mode-alist - 'string-match)))))) + #'string-match)))))) (if (and mode (consp mode)) (cadr mode) mode))) (autoload 'vlf "vlf" "View Large FILE in batches." t) -(defadvice abort-if-file-too-large (around vlf-if-file-too-large - compile activate) - "If file SIZE larger than `large-file-warning-threshold', \ -allow user to view file with `vlf', open it normally, or abort. +(advice-add 'abort-if-file-too-large :around #'vlf--if-file-too-large) +(defun vlf--if-file-too-large (orig-fun size op-type filename &rest args) + "If file is too large, prompt user to view file with `vlf'. +\"Too large\" is defined by `large-file-warning-threshold'. OP-TYPE specifies the file operation being performed over FILENAME." (cond ((or (not size) (zerop size))) @@ -100,7 +95,7 @@ OP-TYPE specifies the file operation being performed over FILENAME." (not filename) (memq (vlf-determine-major-mode filename) vlf-forbidden-modes-list)) - ad-do-it) + (apply orig-fun size op-type filename args)) ((eq vlf-application 'always) (vlf filename) (error "")) @@ -131,29 +126,23 @@ OP-TYPE specifies the file operation being performed over FILENAME." (error "Aborted")))))))) ;; disable for some functions -(defmacro vlf-disable-for-function (func file) - "Build advice to disable VLF during execution of FUNC\ -defined in FILE." - `(eval-after-load ,file - '(defadvice ,func (around ,(intern (concat "vlf-" - (symbol-name func))) - compile activate) - "Temporarily disable `vlf-mode'." - (let ((vlf-application nil)) - ad-do-it)))) - -(vlf-disable-for-function tags-verify-table "etags") -(vlf-disable-for-function tag-find-file-of-tag-noselect "etags") -(vlf-disable-for-function helm-etags-create-buffer "helm-tags") - -;; dired +(defun vlf--disabled (orig-fun &rest args) + "Temporarily disable `vlf-mode'." + (let ((vlf-application nil)) + (apply orig-fun args))) + +(dolist (func '(tags-verify-table + tag-find-file-of-tag-noselect + helm-etags-create-buffer)) + (advice-add func :around #'vlf--disabled)) + (defun dired-vlf () "In Dired, visit the file on this line in VLF mode." (interactive) (vlf (dired-get-file-for-visit))) (eval-after-load "dired" - '(define-key dired-mode-map "V" 'dired-vlf)) + '(define-key dired-mode-map "V" #'dired-vlf)) (provide 'vlf-setup) diff --git a/vlf-tune.el b/vlf-tune.el index 7a860efde6..5b1590ebce 100644 --- a/vlf-tune.el +++ b/vlf-tune.el @@ -1,6 +1,6 @@ ;;; vlf-tune.el --- VLF tuning operations -*- lexical-binding: t -*- -;; Copyright (C) 2014-2017 Free Software Foundation, Inc. +;; Copyright (C) 2014-2023 Free Software Foundation, Inc. ;; Keywords: large files, batch size, performance ;; Author: Andrey Kotlarski <m00nati...@gmail.com> @@ -32,16 +32,16 @@ (defcustom vlf-batch-size 1000000 "Defines how large each batch of file data initially is (in bytes)." - :group 'vlf :type 'integer) + :type 'integer) (put 'vlf-batch-size 'permanent-local t) (defcustom vlf-tune-enabled t "Whether to allow automatic change of batch size. If nil, completely disable. If `stats', maintain measure statistics, but don't change batch size. If t, measure and change." - :group 'vlf :type '(choice (const :tag "Enabled" t) - (const :tag "Just statistics" stats) - (const :tag "Disabled" nil))) + :type '(choice (const :tag "Enabled" t) + (const :tag "Just statistics" stats) + (const :tag "Disabled" nil))) (defvar vlf-file-size 0 "Total size in bytes of presented file.") (make-variable-buffer-local 'vlf-file-size) @@ -65,16 +65,16 @@ but don't change batch size. If t, measure and change." 'standard-value))))) "Maximum batch size in bytes when auto tuning. Avoid increasing this after opening file with VLF." - :group 'vlf :type 'integer) + :type 'integer) (defcustom vlf-tune-step (/ vlf-tune-max 10000) "Step used for tuning in bytes. Avoid decreasing this after opening file with VLF." - :group 'vlf :type 'integer) + :type 'integer) (defcustom vlf-tune-load-time 1.0 "How many seconds should batch take to load for best user experience." - :group 'vlf :type 'float) + :type 'float) (defvar vlf-tune-insert-bps nil "Vector of bytes per second insert measurements.") @@ -351,8 +351,8 @@ INDEX if given, specifies search independent of current batch size." (setq vlf-batch-size (* (1+ idx) vlf-tune-step)))))) (defun vlf-tune-binary (types min max) - "Adjust `vlf-batch-size' to optimal value using binary search, \ -optimizing over TYPES. + "Adjust `vlf-batch-size' to optimal value using binary search. +Optimizes over TYPES. MIN and MAX specify interval of indexes to search." (let ((sum (+ min max))) (if (< (- max min) 3) diff --git a/vlf-write.el b/vlf-write.el index d5c87d5f6b..24057c4a06 100644 --- a/vlf-write.el +++ b/vlf-write.el @@ -1,6 +1,6 @@ ;;; vlf-write.el --- Saving functionality for VLF -*- lexical-binding: t -*- -;; Copyright (C) 2014-2017 Free Software Foundation, Inc. +;; Copyright (C) 2014-2023 Free Software Foundation, Inc. ;; Keywords: large files, saving ;; Author: Andrey Kotlarski <m00nati...@gmail.com> @@ -33,7 +33,7 @@ "Should VLF save in place when additional adjustment of file content\ is needed." :group 'vlf :type '(choice (const :tag "Always when applicable" t) - (const :tag "Ask when applicable" 'ask) + (const :tag "Ask when applicable" ask) (const :tag "Never" nil))) (defun vlf-write () @@ -128,8 +128,7 @@ FILE if given is filename to be used, otherwise `buffer-file-name'." (progress-reporter-done reporter))) (defun vlf-shift-batch (read-pos write-pos file) - "Read `vlf-batch-size' bytes from READ-POS and write them \ -back at WRITE-POS using FILE. + "Shift `vlf-batch-size' bytes from READ-POS to WRITE-POS in FILE. Return nil if EOF is reached, t otherwise." (erase-buffer) (vlf-verify-size t file) diff --git a/vlf.el b/vlf.el index 0bc628f839..ae918e0309 100644 --- a/vlf.el +++ b/vlf.el @@ -1,15 +1,15 @@ ;;; vlf.el --- View Large Files -*- lexical-binding: t -*- -;; Copyright (C) 2006-2020 Free Software Foundation, Inc. +;; Copyright (C) 2006-2023 Free Software Foundation, Inc. -;; Maintainer: Andrey Kotlarski <m00nati...@gmail.com> ;; Version: 1.7.2 +;; Package-Requires: ((emacs "24.4")) ;; Keywords: large files, utilities ;; Maintainer: Andrey Kotlarski <m00nati...@gmail.com> ;; Authors: 2006 Mathias Dahl <mathias.d...@gmail.com> ;; 2012 Sam Steingold <s...@gnu.org> ;; 2013-2017 Andrey Kotlarski <m00nati...@gmail.com> -;; URL: https://github.com/m00natic/vlfi +;; Old-URL: https://github.com/m00natic/vlfi ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -78,25 +78,25 @@ values are: `write', `ediff', `occur', `search', `goto-line'." (defvar vlf-mode-map (let ((map (make-sparse-keymap))) - (define-key map "n" 'vlf-next-batch) - (define-key map "p" 'vlf-prev-batch) - (define-key map " " 'vlf-next-batch-from-point) - (define-key map "+" 'vlf-change-batch-size) + (define-key map "n" #'vlf-next-batch) + (define-key map "p" #'vlf-prev-batch) + (define-key map " " #'vlf-next-batch-from-point) + (define-key map "+" #'vlf-change-batch-size) (define-key map "-" (lambda () "Decrease vlf batch size by factor of 2." (interactive) (vlf-change-batch-size t))) - (define-key map "s" 'vlf-re-search-forward) - (define-key map "r" 'vlf-re-search-backward) - (define-key map "%" 'vlf-query-replace) - (define-key map "o" 'vlf-occur) - (define-key map "[" 'vlf-beginning-of-file) - (define-key map "]" 'vlf-end-of-file) - (define-key map "j" 'vlf-jump-to-chunk) - (define-key map "l" 'vlf-goto-line) - (define-key map "e" 'vlf-ediff-buffers) - (define-key map "f" 'vlf-toggle-follow) - (define-key map "g" 'vlf-revert) + (define-key map "s" #'vlf-re-search-forward) + (define-key map "r" #'vlf-re-search-backward) + (define-key map "%" #'vlf-query-replace) + (define-key map "o" #'vlf-occur) + (define-key map "[" #'vlf-beginning-of-file) + (define-key map "]" #'vlf-end-of-file) + (define-key map "j" #'vlf-jump-to-chunk) + (define-key map "l" #'vlf-goto-line) + (define-key map "e" #'vlf-ediff-buffers) + (define-key map "f" #'vlf-toggle-follow) + (define-key map "g" #'vlf-revert) map) "Keymap for `vlf-mode'.") @@ -115,9 +115,9 @@ values are: `write', `ediff', `occur', `search', `goto-line'." (file-size-human-readable vlf-file-size))) (cond (vlf-mode (set (make-local-variable 'require-final-newline) nil) - (add-hook 'write-file-functions 'vlf-write nil t) + (add-hook 'write-file-functions #'vlf-write nil t) (set (make-local-variable 'revert-buffer-function) - 'vlf-revert) + #'vlf-revert) (make-local-variable 'vlf-batch-size) (setq vlf-file-size (vlf-get-file-size buffer-file-truename) vlf-start-pos 0 @@ -126,7 +126,7 @@ values are: `write', `ediff', `occur', `search', `goto-line'." (start (* (/ pos vlf-batch-size) vlf-batch-size))) (goto-char (byte-to-position (- pos start))) (vlf-move-to-batch start)) - (add-hook 'after-change-major-mode-hook 'vlf-keep-alive t t) + (add-hook 'after-change-major-mode-hook #'vlf-keep-alive t t) (vlf-keep-alive)) ((or (not large-file-warning-threshold) (< vlf-file-size large-file-warning-threshold) @@ -136,9 +136,9 @@ values are: `write', `ediff', `occur', `search', `goto-line'." (kill-local-variable 'revert-buffer-function) (vlf-stop-follow) (kill-local-variable 'require-final-newline) - (remove-hook 'write-file-functions 'vlf-write t) + (remove-hook 'write-file-functions #'vlf-write t) (remove-hook 'after-change-major-mode-hook - 'vlf-keep-alive t) + #'vlf-keep-alive t) (if (derived-mode-p 'hexl-mode) (let ((line (/ (1+ vlf-start-pos) hexl-bits)) (pos (point))) @@ -163,7 +163,7 @@ values are: `write', `ediff', `occur', `search', `goto-line'." (defun vlf-keep-alive () "Keep `vlf-mode' on major mode change." (if (derived-mode-p 'hexl-mode) - (set (make-local-variable 'revert-buffer-function) 'vlf-revert)) + (set (make-local-variable 'revert-buffer-function) #'vlf-revert)) (setq vlf-mode t)) ;;;###autoload @@ -225,60 +225,58 @@ When prefix argument is negative (vlf-move-to-chunk start end))) ;; scroll auto batching -(defadvice scroll-up (around vlf-scroll-up - activate compile) +(advice-add 'scroll-up :around #'vlf--scroll-up) +(defun vlf--scroll-up (orig-fun &rest args) "Slide to next batch if at end of buffer in `vlf-mode'." (if (and vlf-mode (pos-visible-in-window-p (point-max))) (progn (vlf-next-batch 1) (goto-char (point-min))) - ad-do-it)) + (apply orig-fun args))) -(defadvice scroll-down (around vlf-scroll-down - activate compile) +(advice-add 'scroll-down :around #'vlf--scroll-down) +(defun vlf--scroll-down (orig-fun &rest args) "Slide to previous batch if at beginning of buffer in `vlf-mode'." (if (and vlf-mode (pos-visible-in-window-p (point-min))) (progn (vlf-prev-batch 1) (goto-char (point-max))) - ad-do-it)) + (apply orig-fun args))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; hexl mode integration -(eval-after-load "hexl" - '(progn - (defadvice hexl-save-buffer (around vlf-hexl-save - activate compile) - "Prevent hexl save if `vlf-mode' is active." - (if vlf-mode - (vlf-write) - ad-do-it)) - - (defadvice hexl-scroll-up (around vlf-hexl-scroll-up - activate compile) - "Slide to next batch if at end of buffer in `vlf-mode'." - (if (and vlf-mode (pos-visible-in-window-p (point-max)) - (or (not (numberp arg)) (< 0 arg))) - (progn (vlf-next-batch 1) - (goto-char (point-min))) - ad-do-it)) - - (defadvice hexl-scroll-down (around vlf-hexl-scroll-down - activate compile) - "Slide to previous batch if at beginning of buffer in `vlf-mode'." - (if (and vlf-mode (pos-visible-in-window-p (point-min))) - (progn (vlf-prev-batch 1) - (goto-char (point-max))) - ad-do-it)) - - (defadvice hexl-mode-exit (around vlf-hexl-mode-exit - activate compile) - "Exit `hexl-mode' gracefully in case `vlf-mode' is active." - (if (and vlf-mode (not (buffer-modified-p))) - (vlf-with-undo-disabled - (erase-buffer) - ad-do-it - (vlf-move-to-chunk-2 vlf-start-pos vlf-end-pos)) - ad-do-it)))) +(advice-add 'hexl-save-buffer :around #'vlf--hexl-save) +(defun vlf--hexl-save (orig-fun &rest args) + "Prevent hexl save if `vlf-mode' is active." + (if vlf-mode + (vlf-write) + (apply orig-fun args))) + +(advice-add 'hexl-scroll-up :around #'vlf--hexl-scroll-up) +(defun vlf--hexl-scroll-up (orig-fun &rest args) + "Slide to next batch if at end of buffer in `vlf-mode'." + (if (and vlf-mode (pos-visible-in-window-p (point-max)) + (or (not (numberp (car args))) (< 0 (car args)))) + (progn (vlf-next-batch 1) + (goto-char (point-min))) + (apply orig-fun args))) + +(advice-add 'hexl-scroll-down :around #'vlf--hexl-scroll-down) +(defun vlf--hexl-scroll-down (orig-fun &rest args) + "Slide to previous batch if at beginning of buffer in `vlf-mode'." + (if (and vlf-mode (pos-visible-in-window-p (point-min))) + (progn (vlf-prev-batch 1) + (goto-char (point-max))) + (apply orig-fun args))) + +(advice-add 'hexl-mode-exit :around #'vlf--hexl-mode-exit) +(defun vlf--hexl-mode-exit (orig-fun &rest args) + "Exit `hexl-mode' gracefully in case `vlf-mode' is active." + (if (and vlf-mode (not (buffer-modified-p))) + (vlf-with-undo-disabled + (erase-buffer) + (apply orig-fun args) + (vlf-move-to-chunk-2 vlf-start-pos vlf-end-pos)) + (apply orig-fun args))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; utilities