[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auto-overlays 2fabf34 19/93: Various small enhancements
From: |
Stefan Monnier |
Subject: |
[elpa] externals/auto-overlays 2fabf34 19/93: Various small enhancements and bug-fixes |
Date: |
Mon, 14 Dec 2020 13:00:29 -0500 (EST) |
branch: externals/auto-overlays
commit 2fabf342f01a206f566b4bd7808cac86234a8755
Author: Toby Cubitt <toby-predictive@dr-qubit.org>
Commit: tsc25 <toby-predictive@dr-qubit.org>
Various small enhancements and bug-fixes
including rewrite of predictive prefix definition functions, and allowing
completion-UI accept and reject functions to pass more information to hook
functions.
---
auto-overlays.el | 84 +++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 59 insertions(+), 25 deletions(-)
diff --git a/auto-overlays.el b/auto-overlays.el
index 7f704c0..d7872d2 100644
--- a/auto-overlays.el
+++ b/auto-overlays.el
@@ -5,7 +5,7 @@
;; Copyright (C) 2005 2006 2007 Toby Cubitt
;; Author: Toby Cubitt <toby-predictive@dr-qubit.org>
-;; Version: 0.7.1
+;; Version: 0.7.2
;; Keywords: automatic, overlays
;; URL: http://www.dr-qubit.org/emacs.php
@@ -30,6 +30,10 @@
;;; Change Log:
;;
+;; Version 0.7.2
+;; * added md5 sum check for regexps to `auto-overlay-load-overlays', to
+;; ensure regexp definitions haven't changed since overlays were saved
+;;
;; Version 0.7.1
;; * fixed sharing of regexp sets
;;
@@ -510,12 +514,16 @@ other. TO-BUFFER defaults to the current buffer."
-(defun auto-overlay-start (set-id &optional buffer ignore-save-file)
+(defun auto-overlay-start (set-id &optional buffer ignore-save-file
+ no-regexp-check)
"Activate the set of auto-overlay regexps identified by SET-ID
in BUFFER, or the current buffer if none is specified.
If optional argument IGNORE-SAVE-FILE is non-nil, it will ignore
-any file of saved overlays."
+any file of saved overlays. If it is null, but optional argument
+NO-REGEXP-CHECK is non-nil, the file of saved overlays will be
+used, but no check will be made to ensure regexp refinitions are
+the same as when the overlays were saved."
(save-excursion
(when buffer (set-buffer buffer))
@@ -541,7 +549,8 @@ any file of saved overlays."
;; try to load overlays from file
(unless (and (null ignore-save-file)
(file-exists-p (auto-o-overlay-filename set-id))
- (auto-overlay-load-overlays set-id))
+ (auto-overlay-load-overlays set-id nil nil
+ no-regexp-check))
;; if loading was unsuccessful, search for new auto overlays
(let ((lines (count-lines (point-min) (point-max))))
@@ -562,12 +571,16 @@ any file of saved overlays."
-(defun auto-overlay-stop (set-id &optional buffer save)
+(defun auto-overlay-stop (set-id &optional buffer save leave-overlays)
"Clear all auto-overlays in the set identified by SET-ID
from BUFFER, or the current buffer if none is specified.
If SAVE is non-nil, save the overlays to a file to speed up
-loading if SET-ID is enabled again."
+loading if the same set of regexp definitions is enabled
+again. If LEAVE-OVERLAYS is non-nil, don't bother deleting the
+overlays from the buffer \(this is generally a bad idea, unless
+the buffer is about to be killed in which case it speeds things
+up a bit\)."
(save-excursion
(when buffer (set-buffer buffer))
@@ -581,15 +594,16 @@ loading if SET-ID is enabled again."
;; if SAVE is non-nil, save overlays to a file
(when save (auto-overlay-save-overlays set-id))
- ;; delete overlays
- (mapc 'delete-overlay
- (auto-overlays-in
- (point-min) (point-max)
- (list
- (list (lambda (overlay match) (or overlay match))
- '(auto-overlay auto-overlay-match))
- (list 'eq 'set-id set-id))
- nil 'inactive))
+ ;; delete overlays unless told not to bother
+ (unless leave-overlays
+ (mapc 'delete-overlay
+ (auto-overlays-in
+ (point-min) (point-max)
+ (list
+ (list (lambda (overlay match) (or overlay match))
+ '(auto-overlay auto-overlay-match))
+ (list 'eq 'set-id set-id))
+ nil 'inactive)))
;; if there are no more active auto-overlay definitions...
(unless (catch 'enabled
@@ -627,10 +641,12 @@ They can be loaded again later using
`auto-overlay-load-overlays'."
;; create temporary buffer
(let ((buff (generate-new-buffer " *auto-overlay-save*"))
overlay-list)
- ;; write md5 digest to first line
+ ;; write md5 digests to first two lines
(prin1 (md5 (current-buffer)) buff)
(terpri buff)
-
+ (prin1 (md5 (prin1-to-string (assq set-id auto-overlay-regexps))) buff)
+ (terpri buff)
+
;; get sorted list of all match overlays in set SET-ID
(setq overlay-list
(auto-overlays-in (point-min) (point-max)
@@ -671,13 +687,23 @@ They can be loaded again later using
`auto-overlay-load-overlays'."
;; 'error-message "Buffer has changed since overlays were saved to file")
-(defun auto-overlay-load-overlays (set-id &optional buffer file)
+(defun auto-overlay-load-overlays (set-id &optional buffer file
+ no-regexp-check)
"Load overlays for BUFFER from FILE.
Defaults to the current buffer. If FILE is not specified,
construct it from buffer name and SET-ID. Returns t if successful, nil
otherwise.
-The FILE should be generated by `auto-overlay-save-overlays'."
+The FILE should be generated by `auto-overlay-save-overlays'. By
+default, the buffer contents and regexp definitions cfor SET-ID
+will be checked to make sure neither have changed since the
+overlays were saved. If they don't match, the saved overlay data
+will not be loaded, and the function will return nil.
+
+If NO-REGEXP-CHECK is non-nil, the check for matching regexp
+definitions will be skipped; the saved overlays will be loaded
+even if different regexp definitions were active when the data
+was saved."
(save-excursion
(when buffer (set-buffer buffer))
@@ -688,20 +714,28 @@ The FILE should be generated by
`auto-overlay-save-overlays'."
(if (not (file-exists-p file))
(error "File %s does not exist" file)
(let ((buff (find-file-noselect file t))
- md5sum data o-match o-new lines
+ md5-buff md5-regexp data o-match o-new lines
(i 0))
- ;; read md5 digest from first line of FILE
+ ;; read md5 digests from first two lines of FILE
(save-excursion
(set-buffer buff)
(goto-char (point-min)))
- (setq md5sum (read buff))
+ (setq md5-buff (read buff))
+ (setq md5-regexp (read buff))
- ;; if md5sum doesn't match buffer contents, return nil
- (if (not (string= md5sum (md5 (current-buffer))))
+ ;; if saved buffer md5 sum doesn't match buffer contents, or if saved
+ ;; regexp md5 sum doesn't match regexp definitions and checking is not
+ ;; overridden, return nil
+ (if (not (and (string= md5-buff (md5 (current-buffer)))
+ (or no-regexp-check
+ (string= md5-regexp
+ (md5 (prin1-to-string
+ (assq set-id
+ auto-overlay-regexps)))))))
(progn (kill-buffer buff) nil)
-
+
;; count number of overlays, for progress message
(save-excursion
(set-buffer buff)
- [elpa] externals/auto-overlays f17a94b 88/93: Switch auto-overlays over to cl-lib and lexical binding., (continued)
- [elpa] externals/auto-overlays f17a94b 88/93: Switch auto-overlays over to cl-lib and lexical binding., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 19de2f7 02/93: Version 0.8 of the predictive completion package., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 6c24aa3 10/93: Fixed minor bug in auto-overlay-save-overlays., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 36efcfd 89/93: Handle empty group in auto-o-regexp-match., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 5996143 73/93: Refactor auto-overlays-(in|[highest-priority-]at-point) search functions:, Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays c795dc2 81/93: Fix bug in auto-overlay-trigger-update., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 00fb155 91/93: * auto-overlay: Mark or remove unused vars, Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays d207912 93/93: * docs/auto-overlay-manual.texinfo: Move as a consequence of the git split, Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 0f1ee97 08/93: Version 0.12.2 of the predictive completion package., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 5b53236 09/93: Version 0.13.1 of the predictive completion package., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 2fabf34 19/93: Various small enhancements and bug-fixes,
Stefan Monnier <=
- [elpa] externals/auto-overlays a530bba 29/93: Ensure properties due to match overlays that are being superceded are removed from overlays., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 8108af9 33/93: Replaced a couple of cl functions that had crept in., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays b08e944 23/93: Changes related to new LaTeX functionality:, Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 5db4a85 32/93: Fixed bug in auto-o-match-overlay that incorrectly set parent property, Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 67776d2 25/93: Parse functions must set basic overlay properties themselves, Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays c40d2a5 20/93: Shared regexp sets can once again be enabled and disabled independently in each buffer., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays 105a69b 34/93: Simplified predictive-define-all-prefixes., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays a21ba4b 44/93: Fix auto-overlay bug related to overlapping overlays., Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays dbf21cb 47/93: minor corrections auto-overlay docs, Stefan Monnier, 2020/12/14
- [elpa] externals/auto-overlays f268d75 42/93: Fixed bug in auto-overlay-unload-definition., Stefan Monnier, 2020/12/14