emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]