aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2010-08-22 00:12:25 -0400
committerChong Yidong2010-08-22 00:12:25 -0400
commit41a20de9f4bc77586ed2e7cb4c21cb7f89baaea8 (patch)
treeb12017eeb564a4349b6ca38363cd059e63c11535
parente0143335522bda205591cab09407e3bec41c9a40 (diff)
downloademacs-41a20de9f4bc77586ed2e7cb4c21cb7f89baaea8.tar.gz
emacs-41a20de9f4bc77586ed2e7cb4c21cb7f89baaea8.zip
merge whitespace.el change from trunk
-rw-r--r--lisp/ChangeLog18
-rw-r--r--lisp/whitespace.el176
2 files changed, 161 insertions, 33 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2318ce84600..3905bf6db80 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12010-08-21 Vinicius Jose Latorre <viniciusjl@ig.com.br>
2
3 * whitespace.el: Fix slow cursor movement (Bug#6172). Reported by
4 Christoph Groth <cwg@falma.de> and Liu Xin <x_liu@neusoft.com>.
5 New version 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):
13 Adjust code.
14 (whitespace-looking-back, whitespace-buffer-changed): New funs.
15 (whitespace-space-regexp, whitespace-tab-regexp): Eliminate funs.
16
12010-08-21 Leo <sdl.web@gmail.com> 172010-08-21 Leo <sdl.web@gmail.com>
2 18
3 Fix buffer-list rename&refresh after after killing a buffer in ido. 19 Fix buffer-list rename&refresh after after killing a buffer in ido.
@@ -2295,7 +2311,7 @@
2295 2311
2296 * ps-print.el (ps-face-attributes): It was not returning the 2312 * ps-print.el (ps-face-attributes): It was not returning the
2297 attribute face for faces specified as string. Reported by harven 2313 attribute face for faces specified as string. Reported by harven
2298 <harven@free.fr>. 2314 <harven@free.fr>. (Bug#5254)
2299 (ps-print-version): New version 7.3.5. 2315 (ps-print-version): New version 7.3.5.
2300 2316
23012009-12-18 Ulf Jasper <ulf.jasper@web.de> 23172009-12-18 Ulf Jasper <ulf.jasper@web.de>
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 5c7d4e95caf..9f4b033e75f 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.
@@ -813,7 +813,7 @@ Used when `whitespace-style' includes `indentation',
813 :group 'whitespace) 813 :group 'whitespace)
814 814
815 815
816(defcustom whitespace-empty-at-bob-regexp "\\`\\(\\([ \t]*\n\\)+\\)" 816(defcustom whitespace-empty-at-bob-regexp "^\\(\\([ \t]*\n\\)+\\)"
817 "Specify regexp for empty lines at beginning of buffer. 817 "Specify regexp for empty lines at beginning of buffer.
818 818
819If you're using `mule' package, there may be other characters besides: 819If you're using `mule' package, there may be other characters besides:
@@ -828,7 +828,7 @@ Used when `whitespace-style' includes `empty'."
828 :group 'whitespace) 828 :group 'whitespace)
829 829
830 830
831(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]+\\)\\'" 831(defcustom whitespace-empty-at-eob-regexp "^\\([ \t\n]+\\)"
832 "Specify regexp for empty lines at end of buffer. 832 "Specify regexp for empty lines at end of buffer.
833 833
834If you're using `mule' package, there may be other characters besides: 834If you're using `mule' package, there may be other characters besides:
@@ -1229,6 +1229,19 @@ Used by `whitespace-trailing-regexp' function (which see).")
1229 "Used to save locally the font-lock refontify state. 1229 "Used to save locally the font-lock refontify state.
1230Used by `whitespace-post-command-hook' function (which see).") 1230Used by `whitespace-post-command-hook' function (which see).")
1231 1231
1232(defvar whitespace-bob-marker nil
1233 "Used to save locally the bob marker value.
1234Used by `whitespace-post-command-hook' function (which see).")
1235
1236(defvar whitespace-eob-marker nil
1237 "Used to save locally the eob marker value.
1238Used by `whitespace-post-command-hook' function (which see).")
1239
1240(defvar whitespace-buffer-changed nil
1241 "Used to indicate locally if buffer changed.
1242Used by `whitespace-post-command-hook' and `whitespace-buffer-changed'
1243functions (which see).")
1244
1232 1245
1233;;;###autoload 1246;;;###autoload
1234(defun whitespace-toggle-options (arg) 1247(defun whitespace-toggle-options (arg)
@@ -1464,10 +1477,10 @@ documentation."
1464 (let (overwrite-mode) ; enforce no overwrite 1477 (let (overwrite-mode) ; enforce no overwrite
1465 (goto-char (point-min)) 1478 (goto-char (point-min))
1466 (when (re-search-forward 1479 (when (re-search-forward
1467 whitespace-empty-at-bob-regexp nil t) 1480 (concat "\\`" whitespace-empty-at-bob-regexp) nil t)
1468 (delete-region (match-beginning 1) (match-end 1))) 1481 (delete-region (match-beginning 1) (match-end 1)))
1469 (when (re-search-forward 1482 (when (re-search-forward
1470 whitespace-empty-at-eob-regexp nil t) 1483 (concat whitespace-empty-at-eob-regexp "\\'") nil t)
1471 (delete-region (match-beginning 1) (match-end 1))))))) 1484 (delete-region (match-beginning 1) (match-end 1)))))))
1472 ;; PROBLEM 3: 8 or more SPACEs at bol 1485 ;; PROBLEM 3: 8 or more SPACEs at bol
1473 ;; PROBLEM 4: SPACEs before TAB 1486 ;; PROBLEM 4: SPACEs before TAB
@@ -2147,8 +2160,15 @@ resultant list will be returned."
2147 (set (make-local-variable 'whitespace-point) 2160 (set (make-local-variable 'whitespace-point)
2148 (point)) 2161 (point))
2149 (set (make-local-variable 'whitespace-font-lock-refontify) 2162 (set (make-local-variable 'whitespace-font-lock-refontify)
2163 0)
2164 (set (make-local-variable 'whitespace-bob-marker)
2165 (point-min-marker))
2166 (set (make-local-variable 'whitespace-eob-marker)
2167 (point-max-marker))
2168 (set (make-local-variable 'whitespace-buffer-changed)
2150 nil) 2169 nil)
2151 (add-hook 'post-command-hook #'whitespace-post-command-hook nil t) 2170 (add-hook 'post-command-hook #'whitespace-post-command-hook nil t)
2171 (add-hook 'before-change-functions #'whitespace-buffer-changed nil t)
2152 ;; turn off font lock 2172 ;; turn off font lock
2153 (set (make-local-variable 'whitespace-font-lock-mode) 2173 (set (make-local-variable 'whitespace-font-lock-mode)
2154 font-lock-mode) 2174 font-lock-mode)
@@ -2159,7 +2179,7 @@ resultant list will be returned."
2159 nil 2179 nil
2160 (list 2180 (list
2161 ;; Show SPACEs 2181 ;; Show SPACEs
2162 (list #'whitespace-space-regexp 1 whitespace-space t) 2182 (list whitespace-space-regexp 1 whitespace-space t)
2163 ;; Show HARD SPACEs 2183 ;; Show HARD SPACEs
2164 (list whitespace-hspace-regexp 1 whitespace-hspace t)) 2184 (list whitespace-hspace-regexp 1 whitespace-hspace t))
2165 t)) 2185 t))
@@ -2168,7 +2188,7 @@ resultant list will be returned."
2168 nil 2188 nil
2169 (list 2189 (list
2170 ;; Show TABs 2190 ;; Show TABs
2171 (list #'whitespace-tab-regexp 1 whitespace-tab t)) 2191 (list whitespace-tab-regexp 1 whitespace-tab t))
2172 t)) 2192 t))
2173 (when (memq 'trailing whitespace-active-style) 2193 (when (memq 'trailing whitespace-active-style)
2174 (font-lock-add-keywords 2194 (font-lock-add-keywords
@@ -2298,6 +2318,7 @@ resultant list will be returned."
2298 (when (whitespace-style-face-p) 2318 (when (whitespace-style-face-p)
2299 (font-lock-mode 0) 2319 (font-lock-mode 0)
2300 (remove-hook 'post-command-hook #'whitespace-post-command-hook t) 2320 (remove-hook 'post-command-hook #'whitespace-post-command-hook t)
2321 (remove-hook 'before-change-functions #'whitespace-buffer-changed t)
2301 (when whitespace-font-lock 2322 (when whitespace-font-lock
2302 (setq whitespace-font-lock nil 2323 (setq whitespace-font-lock nil
2303 font-lock-keywords whitespace-font-lock-keywords)) 2324 font-lock-keywords whitespace-font-lock-keywords))
@@ -2318,37 +2339,128 @@ resultant list will be returned."
2318(defun whitespace-empty-at-bob-regexp (limit) 2339(defun whitespace-empty-at-bob-regexp (limit)
2319 "Match spaces at beginning of buffer which do not contain the point at \ 2340 "Match spaces at beginning of buffer which do not contain the point at \
2320beginning of buffer." 2341beginning of buffer."
2321 (and (/= whitespace-point 1) 2342 (let ((b (point))
2322 (re-search-forward whitespace-empty-at-bob-regexp limit t))) 2343 r)
2344 (cond
2345 ;; at bob
2346 ((= b 1)
2347 (setq r (and (/= whitespace-point 1)
2348 (looking-at whitespace-empty-at-bob-regexp)))
2349 (if r
2350 (set-marker whitespace-bob-marker (match-end 1))
2351 (set-marker whitespace-bob-marker b)))
2352 ;; inside bob empty region
2353 ((<= limit whitespace-bob-marker)
2354 (setq r (looking-at whitespace-empty-at-bob-regexp))
2355 (if r
2356 (when (< (match-end 1) limit)
2357 (set-marker whitespace-bob-marker (match-end 1)))
2358 (set-marker whitespace-bob-marker b)))
2359 ;; intersection with end of bob empty region
2360 ((<= b whitespace-bob-marker)
2361 (setq r (looking-at whitespace-empty-at-bob-regexp))
2362 (if r
2363 (set-marker whitespace-bob-marker (match-end 1))
2364 (set-marker whitespace-bob-marker b)))
2365 ;; it is not inside bob empty region
2366 (t
2367 (setq r nil)))
2368 ;; move to end of matching
2369 (and r (goto-char (match-end 1)))
2370 r))
2371
2372
2373(defsubst whitespace-looking-back (regexp limit)
2374 (save-excursion
2375 (when (/= 0 (skip-chars-backward " \t\n" limit))
2376 (unless (bolp)
2377 (forward-line 1))
2378 (looking-at regexp))))
2323 2379
2324 2380
2325(defun whitespace-empty-at-eob-regexp (limit) 2381(defun whitespace-empty-at-eob-regexp (limit)
2326 "Match spaces at end of buffer which do not contain the point at end of \ 2382 "Match spaces at end of buffer which do not contain the point at end of \
2327buffer." 2383buffer."
2328 (and (/= whitespace-point (1+ (buffer-size))) 2384 (let ((b (point))
2329 (re-search-forward whitespace-empty-at-eob-regexp limit t))) 2385 (e (1+ (buffer-size)))
2330 2386 r)
2331 2387 (cond
2332(defun whitespace-space-regexp (limit) 2388 ;; at eob
2333 "Match spaces." 2389 ((= limit e)
2334 (setq whitespace-font-lock-refontify t) 2390 (when (/= whitespace-point e)
2335 (re-search-forward whitespace-space-regexp limit t)) 2391 (goto-char limit)
2336 2392 (setq r (whitespace-looking-back whitespace-empty-at-eob-regexp b)))
2337 2393 (if r
2338(defun whitespace-tab-regexp (limit) 2394 (set-marker whitespace-eob-marker (match-beginning 1))
2339 "Match tabs." 2395 (set-marker whitespace-eob-marker limit)
2340 (setq whitespace-font-lock-refontify t) 2396 (goto-char b))) ; return back to initial position
2341 (re-search-forward whitespace-tab-regexp limit t)) 2397 ;; inside eob empty region
2398 ((>= b whitespace-eob-marker)
2399 (goto-char limit)
2400 (setq r (whitespace-looking-back whitespace-empty-at-eob-regexp b))
2401 (if r
2402 (when (> (match-beginning 1) b)
2403 (set-marker whitespace-eob-marker (match-beginning 1)))
2404 (set-marker whitespace-eob-marker limit)
2405 (goto-char b))) ; return back to initial position
2406 ;; intersection with beginning of eob empty region
2407 ((>= limit whitespace-eob-marker)
2408 (goto-char limit)
2409 (setq r (whitespace-looking-back whitespace-empty-at-eob-regexp b))
2410 (if r
2411 (set-marker whitespace-eob-marker (match-beginning 1))
2412 (set-marker whitespace-eob-marker limit)
2413 (goto-char b))) ; return back to initial position
2414 ;; it is not inside eob empty region
2415 (t
2416 (setq r nil)))
2417 r))
2418
2419
2420(defun whitespace-buffer-changed (beg end)
2421 "Set `whitespace-buffer-changed' variable to t."
2422 (setq whitespace-buffer-changed t))
2342 2423
2343 2424
2344(defun whitespace-post-command-hook () 2425(defun whitespace-post-command-hook ()
2345 "Save current point into `whitespace-point' variable. 2426 "Save current point into `whitespace-point' variable.
2346Also refontify when necessary." 2427Also refontify when necessary."
2347 (setq whitespace-point (point)) 2428 (setq whitespace-point (point)) ; current point position
2348 (let ((refontify (or (eolp) ; end of line 2429 (let ((refontify
2349 (= whitespace-point 1)))) ; beginning of buffer 2430 (or
2350 (when (or whitespace-font-lock-refontify refontify) 2431 ;; it is at end of line ...
2351 (setq whitespace-font-lock-refontify refontify) 2432 (and (eolp)
2433 ;; ... with trailing SPACE or TAB
2434 (or (= (preceding-char) ?\ )
2435 (= (preceding-char) ?\t)))
2436 ;; it is at beginning of buffer (bob)
2437 (= whitespace-point 1)
2438 ;; the buffer was modified and ...
2439 (and whitespace-buffer-changed
2440 (or
2441 ;; ... or inside bob whitespace region
2442 (<= whitespace-point whitespace-bob-marker)
2443 ;; ... or at bob whitespace region border
2444 (and (= whitespace-point (1+ whitespace-bob-marker))
2445 (= (preceding-char) ?\n))))
2446 ;; it is at end of buffer (eob)
2447 (= whitespace-point (1+ (buffer-size)))
2448 ;; the buffer was modified and ...
2449 (and whitespace-buffer-changed
2450 (or
2451 ;; ... or inside eob whitespace region
2452 (>= whitespace-point whitespace-eob-marker)
2453 ;; ... or at eob whitespace region border
2454 (and (= whitespace-point (1- whitespace-eob-marker))
2455 (= (following-char) ?\n)))))))
2456 (when (or refontify (> whitespace-font-lock-refontify 0))
2457 (setq whitespace-buffer-changed nil)
2458 ;; adjust refontify counter
2459 (setq whitespace-font-lock-refontify
2460 (if refontify
2461 1
2462 (1- whitespace-font-lock-refontify)))
2463 ;; refontify
2352 (jit-lock-refontify)))) 2464 (jit-lock-refontify))))
2353 2465
2354 2466
@@ -2387,11 +2499,11 @@ Also refontify when necessary."
2387 (unless whitespace-display-table-was-local 2499 (unless whitespace-display-table-was-local
2388 (setq whitespace-display-table-was-local t 2500 (setq whitespace-display-table-was-local t
2389 whitespace-display-table 2501 whitespace-display-table
2502 (copy-sequence buffer-display-table))
2503 ;; asure `buffer-display-table' is unique
2504 ;; when two or more windows are visible.
2505 (setq buffer-display-table
2390 (copy-sequence buffer-display-table))) 2506 (copy-sequence buffer-display-table)))
2391 ;; asure `buffer-display-table' is unique
2392 ;; when two or more windows are visible.
2393 (set (make-local-variable 'buffer-display-table)
2394 (copy-sequence buffer-display-table))
2395 (unless buffer-display-table 2507 (unless buffer-display-table
2396 (setq buffer-display-table (make-display-table))) 2508 (setq buffer-display-table (make-display-table)))
2397 (dolist (entry whitespace-display-mappings) 2509 (dolist (entry whitespace-display-mappings)