[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 0c6f163 1/2: Fix el-search--change-p for atoms
From: |
Michael Heerdegen |
Subject: |
[elpa] master 0c6f163 1/2: Fix el-search--change-p for atoms |
Date: |
Wed, 2 Aug 2017 18:12:28 -0400 (EDT) |
branch: master
commit 0c6f163a7805fbf7a92cafe742908d9634111bd3
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>
Fix el-search--change-p for atoms
Factor out predicate `el-search--atomic-p'.
Fix a bug in the implementation of `change': Count any
el-search--atomic-p thing (e.g. a large string spanning multiple
lines) as a change even when not all of its lines have changed.
---
packages/el-search/el-search-x.el | 21 +++++++++++++++------
packages/el-search/el-search.el | 11 +++++++----
2 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/packages/el-search/el-search-x.el
b/packages/el-search/el-search-x.el
index a03b225..8e96682 100644
--- a/packages/el-search/el-search-x.el
+++ b/packages/el-search/el-search-x.el
@@ -35,8 +35,8 @@
;;; Code:
(eval-when-compile
- (require 'subr-x)
- (require 'thunk))
+ (require 'subr-x))
+(require 'thunk)
(require 'el-search)
@@ -251,11 +251,20 @@ Use variable `el-search--cached-changes' for caching."
(save-restriction
(widen)
(let ((changes (el-search--changes-from-diff-hl revision))
- (sexp-end (scan-sexps posn 1)))
- (while (and changes (< (cdar changes) sexp-end))
+ (sexp-end (scan-sexps posn 1))
+ (atomic? (thunk-delay (el-search--atomic-p
+ (save-excursion (goto-char posn)
+ (read (current-buffer)))))))
+ (while (and changes (or (< (cdar changes) posn)
+ (and
+ ;; a string spanning multiple lines is a change
even when not all
+ ;; lines are changed
+ (< (cdar changes) sexp-end)
+ (not (thunk-force atomic?)))))
(pop changes))
- (and changes
- (<= (caar changes) posn)))))
+ (and changes (or (<= (caar changes) posn)
+ (and (thunk-force atomic?)
+ (<= (caar changes) sexp-end)))))))
(defun el-search--changed-p (posn &optional revision)
;; Non-nil when sexp after POSN contains a change
diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index ace64d1..898c0ba 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/el-search.el
@@ -989,8 +989,8 @@ non-nil when this file or buffer or defun could contain a
match
for the pattern (NAME . ARGS), and nil when we can be sure that
it doesn't contain a match. \"Atom\" here means anything whose
parts aren't searched by el-searching, like integers or strings,
-but unlike arrays. When in doubt, the heuristic matcher function
-must return non-nil.
+but unlike arrays (see `el-search--atomic-p'). When in doubt,
+the heuristic matcher function must return non-nil.
When el-searching is started with a certain PATTERN, a heuristic
matcher function is constructed by recursively destructuring the
@@ -1090,14 +1090,17 @@ PATTERN and combining the heuristic matchers of the
subpatterns."
el-search--atom-list-cache))
atom-list))))))
+(defun el-search--atomic-p (object)
+ (or (not (sequencep object)) (stringp object) (null object)
+ (char-table-p object) (bool-vector-p object)))
+
(defun el-search--flatten-tree (tree)
(let ((elements ())
(walked-objects ;to avoid infinite recursion for circular TREEs
(make-hash-table :test #'eq))
(gc-cons-percentage 0.8)) ;Why is binding it here more effective than
binding it more top-level?
(cl-labels ((walker (object)
- (if (or (not (sequencep object)) (stringp object)
(null object)
- (char-table-p object) (bool-vector-p object))
+ (if (el-search--atomic-p object)
(push object elements)
(unless (gethash object walked-objects)
(puthash object t walked-objects)