From f2404ef0bf22d155ff1fe2bf52f1638c4a1178c9 Mon Sep 17 00:00:00 2001 From: Fanael Linithien Date: Fri, 17 Oct 2014 18:19:34 +0200 Subject: [PATCH] Remove dead code. The PPSS cache can never be inserted into in the middle, so testing whether to insert into the middle is unnecessary. rainbow-delimiters-syntax-ppss-run adds all the intermediate results to the front of the cache, so it always leaves the cache in a state where the elements are always exactly rainbow-delimiters-parse-partial-sexp-cache-max-span apart, so there's no gap bigger than rainbow-delimiters-parse-partial-sexp-cache-max-span to insert into. The before change hook always removes all elements until before the point of the change, leaving no gap either. The only way for a gap bigger than rainbow-delimiters-parse-partial-sexp-cache-max-span to arise is the user changing that variable, but that variable an implementation detail, so worrying about it changing is like worrying about (fset #'rainbow-delimiters-syntax-ppss-run #'ignore). All in all, it serves only to make the code more complicated. So remove it. --- rainbow-delimiters.el | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el index 19940e8..65291be 100644 --- a/rainbow-delimiters.el +++ b/rainbow-delimiters.el @@ -284,23 +284,19 @@ The list is ordered descending by car.") (setq it (cdr it))) (setq rainbow-delimiters-parse-partial-sexp-cache it))) -(defun rainbow-delimiters-syntax-ppss-run (from to oldstate cache-nearest-after) +(defun rainbow-delimiters-syntax-ppss-run (from to oldstate) "Run `parse-partial-sexp' from FROM to TO starting with state OLDSTATE. -CACHE-NEAREST-AFTER should be a list of cache entries starting at the first -entry after TO, or nil if there's no such entry. -Intermediate `parse-partial-sexp' results are added to the cache." +Intermediate `parse-partial-sexp' results are prepended to the cache." (if (= from to) (parse-partial-sexp from to nil nil oldstate) (while (< from to) - (let ((newpos (min to (+ from rainbow-delimiters-parse-partial-sexp-cache-max-span)))) - (let ((state (parse-partial-sexp from newpos nil nil oldstate))) - (if (/= newpos to) - (if cache-nearest-after - (setcdr cache-nearest-after (cons (cons newpos state) (cdr cache-nearest-after))) - (push (cons newpos state) rainbow-delimiters-parse-partial-sexp-cache))) - (setq oldstate state - from newpos)))) + (let* ((newpos (min to (+ from rainbow-delimiters-parse-partial-sexp-cache-max-span))) + (state (parse-partial-sexp from newpos nil nil oldstate))) + (when (/= newpos to) + (push (cons newpos state) rainbow-delimiters-parse-partial-sexp-cache)) + (setq oldstate state + from newpos))) oldstate)) (defun rainbow-delimiters-syntax-ppss (pos) @@ -313,16 +309,13 @@ upon. This is essentialy `syntax-ppss', only specific to rainbow-delimiters to work around a bug." (save-excursion - (let ((it rainbow-delimiters-parse-partial-sexp-cache) - (prev nil)) + (let ((it rainbow-delimiters-parse-partial-sexp-cache)) (while (and it (>= (caar it) pos)) - (setq prev it) (setq it (cdr it))) - (let* ((nearest-after (if (consp prev) prev nil)) - (nearest-before (if (consp it) (car it) it)) - (nearest-before-pos (if nearest-before (car nearest-before) (point-min))) - (nearest-before-data (if nearest-before (cdr nearest-before) nil))) - (rainbow-delimiters-syntax-ppss-run nearest-before-pos pos nearest-before-data nearest-after))))) + (let ((nearest-before (if (consp it) (car it) it))) + (if nearest-before + (rainbow-delimiters-syntax-ppss-run (car nearest-before) pos (cdr nearest-before)) + (rainbow-delimiters-syntax-ppss-run (point-min) pos nil)))))) ;;; Nesting level