monnier pushed a commit to branch master in repository elpa. commit 1b56b170befc762d98ecffc81cb6449e43d2441b Author: Teemu Likonen <tliko...@iki.fi> Date: Fri May 22 11:20:27 2009 +0000
Sallitaan lausekkeen täsmääminen heti edellisen perään Merkkijonoja etsiessään aiempi toteutus siirtyi joka kerta automaattisesti yhden merkin verran eteenpäin ennen kuin etsii seuraavaa merkkijonoa. Aiemmassa toteutuksessa oli se huono puoli, että puskurissa ei voi koskaan täsmätä kaksi välittömästi peräkkäin olevaan merkkijonoa. Esimerkiksi, jos säännöllinen lauseke on "\w\{4\}" ja puskurissa on sana "12345678", niin aiempi toteutus täsmäsi vain sanan ensimmäiseen neljän merkin osaan "1234", koska sen jälkeen siirryttiin yksi merkki eteenpäin eikä loppuosa enää voinut täsmätä. Uusi toteutus täsmää sekä alkuosaan "1234" ja loppuosaan "5678". Uudessa toteutuksessa poistutaan silmukasta heti, jos etsimiskerralla ei siirrytty lainkaan eteenpäin. Tällä estetään ikuinen silmukka, mikäli lauseke täsmää aina samassa paikassa. --- wcheck-mode.el | 42 +++++++++++++++++++++++++----------------- 1 files changed, 25 insertions(+), 17 deletions(-) diff --git a/wcheck-mode.el b/wcheck-mode.el index 834e68a..91aa83e 100644 --- a/wcheck-mode.el +++ b/wcheck-mode.el @@ -672,27 +672,35 @@ only visible text elements; all hidden parts are omitted." (buffer (window-buffer window)) (discard (wcheck-query-language-data language 'regexp-discard t)) (case-fold-search nil) + (old-point 0) words) - (with-syntax-table syntax (goto-char w-start) - (while (re-search-forward regexp w-end t) - (cond ((get-char-property (match-beginning 1) - 'invisible buffer) - ;; This point is invisible. Let's jump forward to - ;; next change of "invisible" property. - (goto-char (next-single-char-property-change - (match-beginning 1) 'invisible buffer w-end))) - - ((or (equal discard "") - (not (string-match discard - (match-string-no-properties 1)))) - ;; Add the match to the word list. - (add-to-list 'words - (match-string-no-properties 1) - 'append) - (goto-char (1+ (point))))))) + (catch 'infinite + (while (re-search-forward regexp w-end t) + (cond ((= (point) old-point) + ;; Make sure we don't end up in an infinite loop + ;; when the regexp always matches with zero width + ;; in the current point position. + (throw 'infinite t)) + + ((get-char-property (match-beginning 1) + 'invisible buffer) + ;; This point is invisible. Let's jump forward to + ;; next change of "invisible" property. + (goto-char (next-single-char-property-change + (match-beginning 1) 'invisible buffer + w-end))) + + ((or (equal discard "") + (not (string-match + discard (match-string-no-properties 1)))) + ;; Add the match to the word list. + (add-to-list 'words + (match-string-no-properties 1) + 'append))) + (setq old-point (point))))) words)))))