aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorVinicius Jose Latorre2010-08-21 01:43:04 -0300
committerVinicius Jose Latorre2010-08-21 01:43:04 -0300
commit80525855696044e98ecb3a781f294f4b31f13558 (patch)
treeac5577fc52a35da74eb61779873666bffd91f2ad /lisp
parent0c9b8993e006e37d5bf48dd09d96e821fcfdcd6f (diff)
downloademacs-80525855696044e98ecb3a781f294f4b31f13558.tar.gz
emacs-80525855696044e98ecb3a781f294f4b31f13558.zip
Fix slow cursor movement.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog19
-rw-r--r--lisp/whitespace.el178
2 files changed, 163 insertions, 34 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index bfe106253ff..3a38a6c031a 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12010-08-21 Vinicius Jose Latorre <viniciusjl@ig.com.br>
2
3 * whitespace.el: Fix slow cursor movement. Reported by Christoph
4 Groth <cwg@falma.de> and Liu Xin <x_liu@neusoft.com>. New version
5 13.0.
6 (whitespace-empty-at-bob-regexp, whitespace-empty-at-eob-regexp):
7 Adjust initialization.
8 (whitespace-bob-marker, whitespace-eob-marker)
9 (whitespace-buffer-changed): New vars.
10 (whitespace-cleanup, whitespace-color-on, whitespace-color-off)
11 (whitespace-empty-at-bob-regexp, whitespace-empty-at-eob-regexp)
12 (whitespace-post-command-hook, whitespace-display-char-on): Adjust
13 code.
14 (whitespace-looking-back, whitespace-buffer-changed): New funs.
15 (whitespace-space-regexp, whitespace-tab-regexp): Eliminated
16 funs.
17
12010-08-19 Stefan Monnier <monnier@iro.umontreal.ca> 182010-08-19 Stefan Monnier <monnier@iro.umontreal.ca>
2 19
3 * files.el (locate-file-completion-table): Only list the .el and .elc 20 * files.el (locate-file-completion-table): Only list the .el and .elc
@@ -6244,7 +6261,7 @@
6244 6261
6245 * ps-print.el (ps-face-attributes): It was not returning the 6262 * ps-print.el (ps-face-attributes): It was not returning the
6246 attribute face for faces specified as string. Reported by harven 6263 attribute face for faces specified as string. Reported by harven
6247 <harven@free.fr>. 6264 <harven@free.fr>. (Bug#5254)
6248 (ps-print-version): New version 7.3.5. 6265 (ps-print-version): New version 7.3.5.
6249 6266
62502009-12-18 Ulf Jasper <ulf.jasper@web.de> 62672009-12-18 Ulf Jasper <ulf.jasper@web.de>
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 79ce9a330d4..9655593893f 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -6,7 +6,7 @@
6;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br> 6;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
7;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br> 7;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
8;; Keywords: data, wp 8;; Keywords: data, wp
9;; Version: 12.1 9;; Version: 13.0
10;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre 10;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
11 11
12;; This file is part of GNU Emacs. 12;; This file is part of GNU Emacs.
@@ -812,7 +812,7 @@ Used when `whitespace-style' includes `indentation',
812 :group 'whitespace) 812 :group 'whitespace)
813 813
814 814
815(defcustom whitespace-empty-at-bob-regexp "\\`\\(\\([ \t]*\n\\)+\\)" 815(defcustom whitespace-empty-at-bob-regexp "^\\(\\([ \t]*\n\\)+\\)"
816 "Specify regexp for empty lines at beginning of buffer. 816 "Specify regexp for empty lines at beginning of buffer.
817 817
818If you're using `mule' package, there may be other characters besides: 818If you're using `mule' package, there may be other characters besides:
@@ -827,7 +827,7 @@ Used when `whitespace-style' includes `empty'."
827 :group 'whitespace) 827 :group 'whitespace)
828 828
829 829
830(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]+\\)\\'" 830(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]+\\)"
831 "Specify regexp for empty lines at end of buffer. 831 "Specify regexp for empty lines at end of buffer.
832 832
833If you're using `mule' package, there may be other characters besides: 833If you're using `mule' package, there may be other characters besides:
@@ -1228,6 +1228,19 @@ Used by `whitespace-trailing-regexp' function (which see).")
1228 "Used to save locally the font-lock refontify state. 1228 "Used to save locally the font-lock refontify state.
1229Used by `whitespace-post-command-hook' function (which see).") 1229Used by `whitespace-post-command-hook' function (which see).")
1230 1230
1231(defvar whitespace-bob-marker nil
1232 "Used to save locally the bob marker value.
1233Used by `whitespace-post-command-hook' function (which see).")
1234
1235(defvar whitespace-eob-marker nil
1236 "Used to save locally the eob marker value.
1237Used by `whitespace-post-command-hook' function (which see).")
1238
1239(defvar whitespace-buffer-changed nil
1240 "Used to indicate locally if buffer changed.
1241Used by `whitespace-post-command-hook' and `whitespace-buffer-changed'
1242functions (which see).")
1243
1231 1244
1232;;;###autoload 1245;;;###autoload
1233(defun whitespace-toggle-options (arg) 1246(defun whitespace-toggle-options (arg)
@@ -1463,10 +1476,10 @@ documentation."
1463 (let (overwrite-mode) ; enforce no overwrite 1476 (let (overwrite-mode) ; enforce no overwrite
1464 (goto-char (point-min)) 1477 (goto-char (point-min))
1465 (when (re-search-forward 1478 (when (re-search-forward
1466 whitespace-empty-at-bob-regexp nil t) 1479 (concat "\\`" whitespace-empty-at-bob-regexp) nil t)
1467 (delete-region (match-beginning 1) (match-end 1))) 1480 (delete-region (match-beginning 1) (match-end 1)))
1468 (when (re-search-forward 1481 (when (re-search-forward
1469 whitespace-empty-at-eob-regexp nil t) 1482 (concat whitespace-empty-at-eob-regexp "\\'") nil t)
1470 (delete-region (match-beginning 1) (match-end 1))))))) 1483 (delete-region (match-beginning 1) (match-end 1)))))))
1471 ;; PROBLEM 3: 8 or more SPACEs at bol 1484 ;; PROBLEM 3: 8 or more SPACEs at bol
1472 ;; PROBLEM 4: SPACEs before TAB 1485 ;; PROBLEM 4: SPACEs before TAB
@@ -2146,8 +2159,15 @@ resultant list will be returned."
2146 (set (make-local-variable 'whitespace-point) 2159 (set (make-local-variable 'whitespace-point)
2147 (point)) 2160 (point))
2148 (set (make-local-variable 'whitespace-font-lock-refontify) 2161 (set (make-local-variable 'whitespace-font-lock-refontify)
2162 0)
2163 (set (make-local-variable 'whitespace-bob-marker)
2164 (point-min-marker))
2165 (set (make-local-variable 'whitespace-eob-marker)
2166 (point-max-marker))
2167 (set (make-local-variable 'whitespace-buffer-changed)
2149 nil) 2168 nil)
2150 (add-hook 'post-command-hook #'whitespace-post-command-hook nil t) 2169 (add-hook 'post-command-hook #'whitespace-post-command-hook nil t)
2170 (add-hook 'before-change-functions #'whitespace-buffer-changed nil t)
2151 ;; turn off font lock 2171 ;; turn off font lock
2152 (set (make-local-variable 'whitespace-font-lock-mode) 2172 (set (make-local-variable 'whitespace-font-lock-mode)
2153 font-lock-mode) 2173 font-lock-mode)
@@ -2158,7 +2178,7 @@ resultant list will be returned."
2158 nil 2178 nil
2159 (list 2179 (list
2160 ;; Show SPACEs 2180 ;; Show SPACEs
2161 (list #'whitespace-space-regexp 1 whitespace-space t) 2181 (list whitespace-space-regexp 1 whitespace-space t)
2162 ;; Show HARD SPACEs 2182 ;; Show HARD SPACEs
2163 (list whitespace-hspace-regexp 1 whitespace-hspace t)) 2183 (list whitespace-hspace-regexp 1 whitespace-hspace t))
2164 t)) 2184 t))
@@ -2167,7 +2187,7 @@ resultant list will be returned."
2167 nil 2187 nil
2168 (list 2188 (list
2169 ;; Show TABs 2189 ;; Show TABs
2170 (list #'whitespace-tab-regexp 1 whitespace-tab t)) 2190 (list whitespace-tab-regexp 1 whitespace-tab t))
2171 t)) 2191 t))
2172 (when (memq 'trailing whitespace-active-style) 2192 (when (memq 'trailing whitespace-active-style)
2173 (font-lock-add-keywords 2193 (font-lock-add-keywords
@@ -2296,7 +2316,8 @@ resultant list will be returned."
2296 ;; turn off font lock 2316 ;; turn off font lock
2297 (when (whitespace-style-face-p) 2317 (when (whitespace-style-face-p)
2298 (font-lock-mode 0) 2318 (font-lock-mode 0)
2299 (remove-hook 'post-command-hook #'whitespace-post-command-hook) 2319 (remove-hook 'post-command-hook #'whitespace-post-command-hook t)
2320 (remove-hook 'before-change-functions #'whitespace-buffer-changed t)
2300 (when whitespace-font-lock 2321 (when whitespace-font-lock
2301 (setq whitespace-font-lock nil 2322 (setq whitespace-font-lock nil
2302 font-lock-keywords whitespace-font-lock-keywords)) 2323 font-lock-keywords whitespace-font-lock-keywords))
@@ -2317,37 +2338,128 @@ resultant list will be returned."
2317(defun whitespace-empty-at-bob-regexp (limit) 2338(defun whitespace-empty-at-bob-regexp (limit)
2318 "Match spaces at beginning of buffer which do not contain the point at \ 2339 "Match spaces at beginning of buffer which do not contain the point at \
2319beginning of buffer." 2340beginning of buffer."
2320 (and (/= whitespace-point 1) 2341 (let ((b (point))
2321 (re-search-forward whitespace-empty-at-bob-regexp limit t))) 2342 r)
2343 (cond
2344 ;; at bob
2345 ((= b 1)
2346 (setq r (and (/= whitespace-point 1)
2347 (looking-at whitespace-empty-at-bob-regexp)))
2348 (if r
2349 (set-marker whitespace-bob-marker (match-end 1))
2350 (set-marker whitespace-bob-marker b)))
2351 ;; inside bob empty region
2352 ((<= limit whitespace-bob-marker)
2353 (setq r (looking-at whitespace-empty-at-bob-regexp))
2354 (if r
2355 (when (< (match-end 1) limit)
2356 (set-marker whitespace-bob-marker (match-end 1)))
2357 (set-marker whitespace-bob-marker b)))
2358 ;; intersection with end of bob empty region
2359 ((<= b whitespace-bob-marker)
2360 (setq r (looking-at whitespace-empty-at-bob-regexp))
2361 (if r
2362 (set-marker whitespace-bob-marker (match-end 1))
2363 (set-marker whitespace-bob-marker b)))
2364 ;; it is not inside bob empty region
2365 (t
2366 (setq r nil)))
2367 ;; move to end of matching
2368 (and r (goto-char (match-end 1)))
2369 r))
2370
2371
2372(defsubst whitespace-looking-back (regexp limit)
2373 (save-excursion
2374 (when (/= 0 (skip-chars-backward " \t\n" limit))
2375 (unless (bolp)
2376 (forward-line 1))
2377 (looking-at regexp))))
2322 2378
2323 2379
2324(defun whitespace-empty-at-eob-regexp (limit) 2380(defun whitespace-empty-at-eob-regexp (limit)
2325 "Match spaces at end of buffer which do not contain the point at end of \ 2381 "Match spaces at end of buffer which do not contain the point at end of \
2326buffer." 2382buffer."
2327 (and (/= whitespace-point (1+ (buffer-size))) 2383 (let ((b (point))
2328 (re-search-forward whitespace-empty-at-eob-regexp limit t))) 2384 (e (1+ (buffer-size)))
2329 2385 r)
2330 2386 (cond
2331(defun whitespace-space-regexp (limit) 2387 ;; at eob
2332 "Match spaces." 2388 ((= limit e)
2333 (setq whitespace-font-lock-refontify t) 2389 (when (/= whitespace-point e)
2334 (re-search-forward whitespace-space-regexp limit t)) 2390 (goto-char limit)
2335 2391 (setq r (whitespace-looking-back whitespace-empty-at-eob-regexp b)))
2336 2392 (if r
2337(defun whitespace-tab-regexp (limit) 2393 (set-marker whitespace-eob-marker (match-beginning 1))
2338 "Match tabs." 2394 (set-marker whitespace-eob-marker limit)
2339 (setq whitespace-font-lock-refontify t) 2395 (goto-char b))) ; return back to initial position
2340 (re-search-forward whitespace-tab-regexp limit t)) 2396 ;; inside eob empty region
2397 ((>= b whitespace-eob-marker)
2398 (goto-char limit)
2399 (setq r (whitespace-looking-back whitespace-empty-at-eob-regexp b))
2400 (if r
2401 (when (> (match-beginning 1) b)
2402 (set-marker whitespace-eob-marker (match-beginning 1)))
2403 (set-marker whitespace-eob-marker limit)
2404 (goto-char b))) ; return back to initial position
2405 ;; intersection with beginning of eob empty region
2406 ((>= limit whitespace-eob-marker)
2407 (goto-char limit)
2408 (setq r (whitespace-looking-back whitespace-empty-at-eob-regexp b))
2409 (if r
2410 (set-marker whitespace-eob-marker (match-beginning 1))
2411 (set-marker whitespace-eob-marker limit)
2412 (goto-char b))) ; return back to initial position
2413 ;; it is not inside eob empty region
2414 (t
2415 (setq r nil)))
2416 r))
2417
2418
2419(defun whitespace-buffer-changed (beg end)
2420 "Set `whitespace-buffer-changed' variable to t."
2421 (setq whitespace-buffer-changed t))
2341 2422
2342 2423
2343(defun whitespace-post-command-hook () 2424(defun whitespace-post-command-hook ()
2344 "Save current point into `whitespace-point' variable. 2425 "Save current point into `whitespace-point' variable.
2345Also refontify when necessary." 2426Also refontify when necessary."
2346 (setq whitespace-point (point)) 2427 (setq whitespace-point (point)) ; current point position
2347 (let ((refontify (or (eolp) ; end of line 2428 (let ((refontify
2348 (= whitespace-point 1)))) ; beginning of buffer 2429 (or
2349 (when (or whitespace-font-lock-refontify refontify) 2430 ;; it is at end of line ...
2350 (setq whitespace-font-lock-refontify refontify) 2431 (and (eolp)
2432 ;; ... with trailing SPACE or TAB
2433 (or (= (preceding-char) ?\ )
2434 (= (preceding-char) ?\t)))
2435 ;; it is at beginning of buffer (bob)
2436 (= whitespace-point 1)
2437 ;; the buffer was modified and ...
2438 (and whitespace-buffer-changed
2439 (or
2440 ;; ... or inside bob whitespace region
2441 (<= whitespace-point whitespace-bob-marker)
2442 ;; ... or at bob whitespace region border
2443 (and (= whitespace-point (1+ whitespace-bob-marker))
2444 (= (preceding-char) ?\n))))
2445 ;; it is at end of buffer (eob)
2446 (= whitespace-point (1+ (buffer-size)))
2447 ;; the buffer was modified and ...
2448 (and whitespace-buffer-changed
2449 (or
2450 ;; ... or inside eob whitespace region
2451 (>= whitespace-point whitespace-eob-marker)
2452 ;; ... or at eob whitespace region border
2453 (and (= whitespace-point (1- whitespace-eob-marker))
2454 (= (following-char) ?\n)))))))
2455 (when (or refontify (> whitespace-font-lock-refontify 0))
2456 (setq whitespace-buffer-changed nil)
2457 ;; adjust refontify counter
2458 (setq whitespace-font-lock-refontify
2459 (if refontify
2460 1
2461 (1- whitespace-font-lock-refontify)))
2462 ;; refontify
2351 (jit-lock-refontify)))) 2463 (jit-lock-refontify))))
2352 2464
2353 2465
@@ -2386,11 +2498,11 @@ Also refontify when necessary."
2386 (unless whitespace-display-table-was-local 2498 (unless whitespace-display-table-was-local
2387 (setq whitespace-display-table-was-local t 2499 (setq whitespace-display-table-was-local t
2388 whitespace-display-table 2500 whitespace-display-table
2501 (copy-sequence buffer-display-table))
2502 ;; asure `buffer-display-table' is unique
2503 ;; when two or more windows are visible.
2504 (setq buffer-display-table
2389 (copy-sequence buffer-display-table))) 2505 (copy-sequence buffer-display-table)))
2390 ;; asure `buffer-display-table' is unique
2391 ;; when two or more windows are visible.
2392 (set (make-local-variable 'buffer-display-table)
2393 (copy-sequence buffer-display-table))
2394 (unless buffer-display-table 2506 (unless buffer-display-table
2395 (setq buffer-display-table (make-display-table))) 2507 (setq buffer-display-table (make-display-table)))
2396 (dolist (entry whitespace-display-mappings) 2508 (dolist (entry whitespace-display-mappings)