aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVinicius Jose Latorre2008-03-01 19:00:24 +0000
committerVinicius Jose Latorre2008-03-01 19:00:24 +0000
commit94dc593ff454b8754c8a381c9a356e81da10f2ff (patch)
tree0d67e40a79fb3b89c71e4fe5d1fb732fb06e15bb
parente0c8ae101a411f2de94cd03ff8d27c5809e7bdff (diff)
downloademacs-94dc593ff454b8754c8a381c9a356e81da10f2ff.tar.gz
emacs-94dc593ff454b8754c8a381c9a356e81da10f2ff.zip
New version 9.3.
-rw-r--r--lisp/ChangeLog29
-rw-r--r--lisp/whitespace.el325
2 files changed, 294 insertions, 60 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8f446aead30..045be916d24 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,32 @@
12008-03-01 Vinicius Jose Latorre <viniciusjl@ig.com.br>
2
3 * whitespace.el: New version 9.3. As the glyph code generation was
4 fixed, it is possible now to use character code above ?\x1FFFF in the
5 display table. Fix `whitespace-indentation-regexp' to not include an
6 extra ending character. Reported by Michael Welsh Duggan
7 <mwd@cert.org>. Added hook actions when buffer is written or killed as
8 the original whitespace package had. Suggested by Eric Cooper
9 <ecc@cmu.edu>. Doc fix.
10 (whitespace-action): New option.
11 (whitespace-display-mappings): Changed default newline visualization to
12 display downwards arrow, as the glyph code generation was fixed.
13 (whitespace-unload-function): Assure that all local whitespace mode is
14 turned off.
15 (whitespace-global-modes): Fix type customization.
16 (whitespace-mode, global-whitespace-mode, whitespace-cleanup-region)
17 (whitespace-insert-option-mark, whitespace-help-on, whitespace-turn-on)
18 (whitespace-turn-off, whitespace-color-on, whitespace-display-char-on):
19 Fix code.
20 (whitespace-buffer): Command removed.
21 (whitespace-trailing-regexp, whitespace-mark-x)
22 (whitespace-display-window, whitespace-action-when-on)
23 (whitespace-add-local-hook, whitespace-remove-local-hook)
24 (whitespace-write-file-hook, whitespace-kill-buffer-hook)
25 (whitespace-action): New funs.
26 (whitespace-report-list, whitespace-report-text)
27 (whitespace-report-buffer-name): New consts.
28 (whitespace-report, whitespace-report-region): New commands.
29
12008-03-01 Juanma Barranquero <lekktu@gmail.com> 302008-03-01 Juanma Barranquero <lekktu@gmail.com>
2 31
3 * disp-table.el (make-glyph-code): Don't test the result of 32 * disp-table.el (make-glyph-code): Don't test the result of
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 5c65e24d405..d156d47f12c 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: 9.2 9;; Version: 9.3
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.
@@ -162,15 +162,18 @@
162;; 162;;
163;; There are also the following useful commands: 163;; There are also the following useful commands:
164;; 164;;
165;; `whitespace-report'
166;; Report some blank problems in buffer.
167;;
168;; `whitespace-report-region'
169;; Report some blank problems in a region.
170;;
165;; `whitespace-cleanup' 171;; `whitespace-cleanup'
166;; Cleanup some blank problems in all buffer or at region. 172;; Cleanup some blank problems in all buffer or at region.
167;; 173;;
168;; `whitespace-cleanup-region' 174;; `whitespace-cleanup-region'
169;; Cleanup some blank problems at region. 175;; Cleanup some blank problems at region.
170;; 176;;
171;; `whitespace-buffer'
172;; Turn on `whitespace-mode' forcing some settings.
173;;
174;; The problems, which are cleaned up, are: 177;; The problems, which are cleaned up, are:
175;; 178;;
176;; 1. empty lines at beginning of buffer. 179;; 1. empty lines at beginning of buffer.
@@ -188,7 +191,7 @@
188;; 191;;
189;; 5. SPACEs or TABs at end of line. 192;; 5. SPACEs or TABs at end of line.
190;; If `whitespace-chars' includes the value `trailing', remove all 193;; If `whitespace-chars' includes the value `trailing', remove all
191;; SPACEs or TABs at end of line." 194;; SPACEs or TABs at end of line.
192;; 195;;
193;; 6. 8 or more SPACEs after TAB. 196;; 6. 8 or more SPACEs after TAB.
194;; If `whitespace-chars' includes the value `space-after-tab', 197;; If `whitespace-chars' includes the value `space-after-tab',
@@ -280,10 +283,16 @@
280;; `whitespace-mode' is automagically 283;; `whitespace-mode' is automagically
281;; turned on. 284;; turned on.
282;; 285;;
286;; `whitespace-action' Specify which action is taken when a
287;; buffer is visited, killed or written.
288;;
283;; 289;;
284;; Acknowledgements 290;; Acknowledgements
285;; ---------------- 291;; ----------------
286;; 292;;
293;; Thanks to Eric Cooper <ecc@cmu.edu> for the suggestion to have hook actions
294;; when buffer is written or killed as the original whitespace package had.
295;;
287;; Thanks to nschum (EmacsWiki) for the idea about highlight "long" 296;; Thanks to nschum (EmacsWiki) for the idea about highlight "long"
288;; lines tail. See EightyColumnRule (EmacsWiki). 297;; lines tail. See EightyColumnRule (EmacsWiki).
289;; 298;;
@@ -786,9 +795,6 @@ and `whitespace-chars' includes `lines' or `lines-tail'."
786 795
787;; Hacked from `visible-whitespace-mappings' in visws.el 796;; Hacked from `visible-whitespace-mappings' in visws.el
788(defcustom whitespace-display-mappings 797(defcustom whitespace-display-mappings
789 ;; Due to limitations of glyph representation, the char code can not
790 ;; be above ?\x1FFFF. Probably, this will be fixed after Emacs
791 ;; unicode merging.
792 '( 798 '(
793 (?\ [?\xB7] [?.]) ; space - centered dot 799 (?\ [?\xB7] [?.]) ; space - centered dot
794 (?\xA0 [?\xA4] [?_]) ; hard space - currency 800 (?\xA0 [?\xA4] [?_]) ; hard space - currency
@@ -797,8 +803,8 @@ and `whitespace-chars' includes `lines' or `lines-tail'."
797 (?\xE20 [?\xE24] [?_]) ; hard space - currency 803 (?\xE20 [?\xE24] [?_]) ; hard space - currency
798 (?\xF20 [?\xF24] [?_]) ; hard space - currency 804 (?\xF20 [?\xF24] [?_]) ; hard space - currency
799 ;; NEWLINE is displayed using the face `whitespace-newline' 805 ;; NEWLINE is displayed using the face `whitespace-newline'
800 (?\n [?$ ?\n]) ; end-of-line - dollar sign 806 (?\n [?\u21B5 ?\n] [?$ ?\n]) ; end-of-line - downwards arrow
801 ;; (?\n [?\u21B5 ?\n] [?$ ?\n]) ; end-of-line - downwards arrow 807 ;; (?\n [?$ ?\n]) ; end-of-line - dollar sign
802 ;; (?\n [?\xB6 ?\n] [?$ ?\n]) ; end-of-line - pilcrow 808 ;; (?\n [?\xB6 ?\n] [?$ ?\n]) ; end-of-line - pilcrow
803 ;; (?\n [?\x8AF ?\n] [?$ ?\n]) ; end-of-line - overscore 809 ;; (?\n [?\x8AF ?\n] [?$ ?\n]) ; end-of-line - overscore
804 ;; (?\n [?\x8AC ?\n] [?$ ?\n]) ; end-of-line - negation 810 ;; (?\n [?\x8AC ?\n] [?$ ?\n]) ; end-of-line - negation
@@ -863,7 +869,8 @@ of the list is negated if it begins with `not'. For example:
863 869
864means that `whitespace-mode' is turned on for buffers in C and 870means that `whitespace-mode' is turned on for buffers in C and
865C++ modes only." 871C++ modes only."
866 :type '(choice (const :tag "None" nil) 872 :type '(choice :tag "Global Modes"
873 (const :tag "None" nil)
867 (const :tag "All" t) 874 (const :tag "All" t)
868 (set :menu-tag "Mode Specific" :tag "Modes" 875 (set :menu-tag "Mode Specific" :tag "Modes"
869 :value (not) 876 :value (not)
@@ -872,6 +879,41 @@ C++ modes only."
872 (symbol :tag "Mode")))) 879 (symbol :tag "Mode"))))
873 :group 'whitespace) 880 :group 'whitespace)
874 881
882
883(defcustom whitespace-action nil
884 "*Specify which action is taken when a buffer is visited, killed or written.
885
886It's a list containing some or all of the following values:
887
888 nil no action is taken.
889
890 cleanup cleanup any bogus whitespace always when local
891 whitespace is turned on.
892 See `whitespace-cleanup' and
893 `whitespace-cleanup-region'.
894
895 report-on-bogus report if there is any bogus whitespace always
896 when local whitespace is turned on.
897
898 auto-cleanup cleanup any bogus whitespace when buffer is
899 written or killed.
900 See `whitespace-cleanup' and
901 `whitespace-cleanup-region'.
902
903 abort-on-bogus abort if there is any bogus whitespace and the
904 buffer is written or killed.
905
906Any other value is treated as nil."
907 :type '(choice :tag "Actions"
908 (const :tag "None" nil)
909 (repeat :tag "Action List"
910 (choice :tag "Action"
911 (const :tag "Cleanup When On" cleanup)
912 (const :tag "Report On Bogus" report-on-bogus)
913 (const :tag "Auto Cleanup" auto-cleanup)
914 (const :tag "Abort On Bogus" abort-on-bogus))))
915 :group 'whitespace)
916
875 917
876;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 918;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
877;;;; User commands - Local mode 919;;;; User commands - Local mode
@@ -893,7 +935,8 @@ Only useful with a windowing system."
893 (noninteractive ; running a batch job 935 (noninteractive ; running a batch job
894 (setq whitespace-mode nil)) 936 (setq whitespace-mode nil))
895 (whitespace-mode ; whitespace-mode on 937 (whitespace-mode ; whitespace-mode on
896 (whitespace-turn-on)) 938 (whitespace-turn-on)
939 (whitespace-action-when-on))
897 (t ; whitespace-mode off 940 (t ; whitespace-mode off
898 (whitespace-turn-off)))) 941 (whitespace-turn-off))))
899 942
@@ -918,7 +961,7 @@ Only useful with a windowing system."
918 (setq global-whitespace-mode nil)) 961 (setq global-whitespace-mode nil))
919 (global-whitespace-mode ; global-whitespace-mode on 962 (global-whitespace-mode ; global-whitespace-mode on
920 (save-excursion 963 (save-excursion
921 (add-hook 'find-file-hook 'whitespace-turn-on-if-enabled t) 964 (add-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
922 (dolist (buffer (buffer-list)) ; adjust all local mode 965 (dolist (buffer (buffer-list)) ; adjust all local mode
923 (set-buffer buffer) 966 (set-buffer buffer)
924 (unless whitespace-mode 967 (unless whitespace-mode
@@ -1259,14 +1302,14 @@ The problems cleaned up are:
1259 (while (re-search-forward 1302 (while (re-search-forward
1260 whitespace-indentation-regexp rend t) 1303 whitespace-indentation-regexp rend t)
1261 (setq tmp (current-indentation)) 1304 (setq tmp (current-indentation))
1305 (goto-char (match-beginning 0))
1262 (delete-horizontal-space) 1306 (delete-horizontal-space)
1263 (unless (eolp) 1307 (unless (eolp)
1264 (indent-to tmp)))) 1308 (indent-to tmp))))
1265 ;; problem 3: SPACEs or TABs at eol 1309 ;; problem 3: SPACEs or TABs at eol
1266 ;; action: remove all SPACEs or TABs at eol 1310 ;; action: remove all SPACEs or TABs at eol
1267 (when (memq 'trailing whitespace-chars) 1311 (when (memq 'trailing whitespace-chars)
1268 (let ((regexp (concat "\\(\\(" whitespace-trailing-regexp 1312 (let ((regexp (whitespace-trailing-regexp)))
1269 "\\)+\\)$")))
1270 (goto-char rstart) 1313 (goto-char rstart)
1271 (while (re-search-forward regexp rend t) 1314 (while (re-search-forward regexp rend t)
1272 (delete-region (match-beginning 1) (match-end 1))))) 1315 (delete-region (match-beginning 1) (match-end 1)))))
@@ -1300,24 +1343,103 @@ The problems cleaned up are:
1300 1343
1301 1344
1302;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1345;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1303;;;; User command - old whitespace compatibility 1346;;;; User command - report
1347
1348
1349(defun whitespace-trailing-regexp ()
1350 "Make the `whitespace-trailing-regexp' regexp."
1351 (concat "\\(\\(" whitespace-trailing-regexp "\\)+\\)$"))
1352
1353
1354(defconst whitespace-report-list
1355 (list
1356 (cons 'empty whitespace-empty-at-bob-regexp)
1357 (cons 'empty whitespace-empty-at-eob-regexp)
1358 (cons 'indentation whitespace-indentation-regexp)
1359 (cons 'space-before-tab whitespace-space-before-tab-regexp)
1360 (cons 'trailing (whitespace-trailing-regexp))
1361 (cons 'space-after-tab whitespace-space-after-tab-regexp)
1362 )
1363 "List of whitespace bogus symbol and corresponding regexp.")
1364
1365
1366(defconst whitespace-report-text
1367 "\
1368 Whitespace Report
1369
1370 Current Setting Whitespace Problem
1371
1372 empty [] [] empty lines at beginning of buffer.
1373 empty [] [] empty lines at end of buffer.
1374 indentation [] [] 8 or more SPACEs at beginning of line.
1375 space-before-tab [] [] SPACEs before TAB.
1376 trailing [] [] SPACEs or TABs at end of line.
1377 space-after-tab [] [] 8 or more SPACEs after TAB.\n\n"
1378 "Text for whitespace bogus report.")
1379
1380
1381(defconst whitespace-report-buffer-name "*Whitespace Report*"
1382 "The buffer name for whitespace bogus report.")
1304 1383
1305 1384
1306;;;###autoload 1385;;;###autoload
1307(defun whitespace-buffer () 1386(defun whitespace-report (&optional force report-if-bogus)
1308 "Turn on `whitespace-mode' forcing some settings. 1387 "Report some whitespace problems in buffer.
1309 1388
1310It forces `whitespace-style' to have `color'. 1389Return nil if there is no whitespace problem; otherwise, return
1390non-nil.
1311 1391
1312It also forces `whitespace-chars' to have: 1392If FORCE is non-nil or \\[universal-argument] was pressed just before calling
1393`whitespace-report' interactively, it forces `whitespace-chars' to
1394have:
1313 1395
1314 trailing 1396 empty
1315 indentation 1397 indentation
1316 space-before-tab 1398 space-before-tab
1399 trailing
1400 space-after-tab
1401
1402If REPORT-IF-BOGUS is non-nil, it reports only when there are any
1403whitespace problems in buffer.
1404
1405Report if some of the following whitespace problems exist:
1406
1407 empty 1. empty lines at beginning of buffer.
1408 empty 2. empty lines at end of buffer.
1409 indentation 3. 8 or more SPACEs at beginning of line.
1410 space-before-tab 4. SPACEs before TAB.
1411 trailing 5. SPACEs or TABs at end of line.
1412 space-after-tab 6. 8 or more SPACEs after TAB.
1413
1414See `whitespace-chars' and `whitespace-style' for documentation.
1415See also `whitespace-cleanup' and `whitespace-cleanup-region' for
1416cleaning up these problems."
1417 (interactive (list current-prefix-arg))
1418 (whitespace-report-region (point-min) (point-max)
1419 force report-if-bogus))
1420
1421
1422;;;###autoload
1423(defun whitespace-report-region (start end &optional force report-if-bogus)
1424 "Report some whitespace problems in a region.
1425
1426Return nil if there is no whitespace problem; otherwise, return
1427non-nil.
1428
1429If FORCE is non-nil or \\[universal-argument] was pressed just before calling
1430`whitespace-report-region' interactively, it forces `whitespace-chars'
1431to have:
1432
1317 empty 1433 empty
1434 indentation
1435 space-before-tab
1436 trailing
1318 space-after-tab 1437 space-after-tab
1319 1438
1320So, it is possible to visualize the following problems: 1439If REPORT-IF-BOGUS is non-nil, it reports only when there are any
1440whitespace problems in buffer.
1441
1442Report if some of the following whitespace problems exist:
1321 1443
1322 empty 1. empty lines at beginning of buffer. 1444 empty 1. empty lines at beginning of buffer.
1323 empty 2. empty lines at end of buffer. 1445 empty 2. empty lines at end of buffer.
@@ -1329,21 +1451,41 @@ So, it is possible to visualize the following problems:
1329See `whitespace-chars' and `whitespace-style' for documentation. 1451See `whitespace-chars' and `whitespace-style' for documentation.
1330See also `whitespace-cleanup' and `whitespace-cleanup-region' for 1452See also `whitespace-cleanup' and `whitespace-cleanup-region' for
1331cleaning up these problems." 1453cleaning up these problems."
1332 (interactive) 1454 (interactive "r")
1333 (whitespace-mode 0) ; assure is off 1455 (setq force (or current-prefix-arg force))
1334 ;; keep original values 1456 (save-excursion
1335 (let ((whitespace-style (copy-sequence whitespace-style)) 1457 (save-match-data
1336 (whitespace-chars (copy-sequence whitespace-chars))) 1458 (let* (has-bogus
1337 ;; adjust options for whitespace bogus blanks 1459 (rstart (min start end))
1338 (add-to-list 'whitespace-style 'color) 1460 (rend (max start end))
1339 (mapc #'(lambda (option) 1461 (bogus-list (mapcar
1340 (add-to-list 'whitespace-chars option)) 1462 #'(lambda (option)
1341 '(trailing 1463 (when force
1342 indentation 1464 (add-to-list 'whitespace-chars (car option)))
1343 space-before-tab 1465 (goto-char rstart)
1344 empty 1466 (and (re-search-forward (cdr option) rend t)
1345 space-after-tab)) 1467 (setq has-bogus t)))
1346 (whitespace-mode 1))) ; turn on 1468 whitespace-report-list)))
1469 (when (if report-if-bogus has-bogus t)
1470 (with-current-buffer (get-buffer-create
1471 whitespace-report-buffer-name)
1472 (erase-buffer)
1473 (insert whitespace-report-text)
1474 (goto-char (point-min))
1475 (forward-line 3)
1476 (dolist (option whitespace-report-list)
1477 (forward-line 1)
1478 (whitespace-mark-x 22 (memq (car option) whitespace-chars))
1479 (whitespace-mark-x 7 (car bogus-list))
1480 (setq bogus-list (cdr bogus-list)))
1481 (when has-bogus
1482 (goto-char (point-max))
1483 (insert " Type `M-x whitespace-cleanup'"
1484 " to cleanup the buffer.\n\n")
1485 (insert " Type `M-x whitespace-cleanup-region'"
1486 " to cleanup a region.\n\n"))
1487 (whitespace-display-window (current-buffer))))
1488 has-bogus))))
1347 1489
1348 1490
1349;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1491;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1392,13 +1534,18 @@ cleaning up these problems."
1392 "The buffer name for whitespace toggle options.") 1534 "The buffer name for whitespace toggle options.")
1393 1535
1394 1536
1537(defun whitespace-mark-x (nchars condition)
1538 "Insert the mark ('X' or ' ') after NCHARS depending on CONDITION."
1539 (forward-char nchars)
1540 (insert (if condition "X" " ")))
1541
1542
1395(defun whitespace-insert-option-mark (the-list the-value) 1543(defun whitespace-insert-option-mark (the-list the-value)
1396 "Insert the option mark ('X' or ' ') in toggle options buffer." 1544 "Insert the option mark ('X' or ' ') in toggle options buffer."
1397 (forward-line 1) 1545 (forward-line 1)
1398 (dolist (sym the-list) 1546 (dolist (sym the-list)
1399 (forward-line 1) 1547 (forward-line 1)
1400 (forward-char 2) 1548 (whitespace-mark-x 2 (memq sym the-value))))
1401 (insert (if (memq sym the-value) "X" " "))))
1402 1549
1403 1550
1404(defun whitespace-help-on (chars style) 1551(defun whitespace-help-on (chars style)
@@ -1415,17 +1562,22 @@ cleaning up these problems."
1415 whitespace-chars-value-list chars) 1562 whitespace-chars-value-list chars)
1416 (whitespace-insert-option-mark 1563 (whitespace-insert-option-mark
1417 whitespace-style-value-list style) 1564 whitespace-style-value-list style)
1418 (goto-char (point-min)) 1565 (whitespace-display-window buffer)))))
1419 (set-buffer-modified-p nil) 1566
1420 (let ((size (- (window-height) 1567
1421 (max window-min-height 1568(defun whitespace-display-window (buffer)
1422 (1+ (count-lines (point-min) 1569 "Display BUFFER in a new window."
1423 (point-max))))))) 1570 (goto-char (point-min))
1424 (when (<= size 0) 1571 (set-buffer-modified-p nil)
1425 (kill-buffer buffer) 1572 (let ((size (- (window-height)
1426 (error "Frame height is too small; \ 1573 (max window-min-height
1574 (1+ (count-lines (point-min)
1575 (point-max)))))))
1576 (when (<= size 0)
1577 (kill-buffer buffer)
1578 (error "Frame height is too small; \
1427can't split window to display whitespace toggle options")) 1579can't split window to display whitespace toggle options"))
1428 (set-window-buffer (split-window nil size) buffer)))))) 1580 (set-window-buffer (split-window nil size) buffer)))
1429 1581
1430 1582
1431(defun whitespace-help-off () 1583(defun whitespace-help-off ()
@@ -1538,6 +1690,7 @@ options are valid."
1538 1690
1539(defun whitespace-turn-on () 1691(defun whitespace-turn-on ()
1540 "Turn on whitespace visualization." 1692 "Turn on whitespace visualization."
1693 (whitespace-add-local-hook)
1541 (setq whitespace-active-style (if (listp whitespace-style) 1694 (setq whitespace-active-style (if (listp whitespace-style)
1542 whitespace-style 1695 whitespace-style
1543 (list whitespace-style))) 1696 (list whitespace-style)))
@@ -1552,6 +1705,7 @@ options are valid."
1552 1705
1553(defun whitespace-turn-off () 1706(defun whitespace-turn-off ()
1554 "Turn off whitespace visualization." 1707 "Turn off whitespace visualization."
1708 (whitespace-remove-local-hook)
1555 (when (memq 'color whitespace-active-style) 1709 (when (memq 'color whitespace-active-style)
1556 (whitespace-color-off)) 1710 (whitespace-color-off))
1557 (when (memq 'mark whitespace-active-style) 1711 (when (memq 'mark whitespace-active-style)
@@ -1590,8 +1744,7 @@ options are valid."
1590 nil 1744 nil
1591 (list 1745 (list
1592 ;; Show trailing blanks 1746 ;; Show trailing blanks
1593 (list (concat "\\(\\(" whitespace-trailing-regexp "\\)+\\)$") 1747 (list (whitespace-trailing-regexp) 1 whitespace-trailing t))
1594 1 whitespace-trailing t))
1595 t)) 1748 t))
1596 (when (or (memq 'lines whitespace-active-chars) 1749 (when (or (memq 'lines whitespace-active-chars)
1597 (memq 'lines-tail whitespace-active-chars)) 1750 (memq 'lines-tail whitespace-active-chars))
@@ -1727,11 +1880,7 @@ options are valid."
1727 ;; faces, font-lock faces, etc. 1880 ;; faces, font-lock faces, etc.
1728 (when (memq 'color whitespace-active-style) 1881 (when (memq 'color whitespace-active-style)
1729 (dotimes (i (length vec)) 1882 (dotimes (i (length vec))
1730 ;; Due to limitations of glyph representation, the char
1731 ;; code can not be above ?\x1FFFF. Probably, this will
1732 ;; be fixed after Emacs unicode merging.
1733 (or (eq (aref vec i) ?\n) 1883 (or (eq (aref vec i) ?\n)
1734 (> (aref vec i) #x1FFFF)
1735 (aset vec i 1884 (aset vec i
1736 (make-glyph-code (aref vec i) 1885 (make-glyph-code (aref vec i)
1737 whitespace-newline))))) 1886 whitespace-newline)))))
@@ -1752,14 +1901,70 @@ options are valid."
1752 1901
1753 1902
1754;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1903;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1904;;;; Hook
1905
1906
1907(defun whitespace-action-when-on ()
1908 "Action to be taken always when local whitespace is turned on."
1909 (cond ((memq 'cleanup whitespace-action)
1910 (whitespace-cleanup))
1911 ((memq 'report-on-bogus whitespace-action)
1912 (whitespace-report nil t))))
1913
1914
1915(defun whitespace-add-local-hook ()
1916 "Add some whitespace hooks locally."
1917 (add-hook 'write-file-functions 'whitespace-write-file-hook nil t)
1918 (add-hook 'kill-buffer-hook 'whitespace-kill-buffer-hook nil t))
1919
1920
1921(defun whitespace-remove-local-hook ()
1922 "Remove some whitespace hooks locally."
1923 (remove-hook 'write-file-functions 'whitespace-write-file-hook t)
1924 (remove-hook 'kill-buffer-hook 'whitespace-kill-buffer-hook t))
1925
1926
1927(defun whitespace-write-file-hook ()
1928 "Action to be taken when buffer is written.
1929It should be added buffer-locally to `write-file-functions'."
1930 (when (whitespace-action)
1931 (error "Abort write due to whitespace problems in %s"
1932 (buffer-name)))
1933 nil) ; continue hook processing
1934
1935
1936(defun whitespace-kill-buffer-hook ()
1937 "Action to be taken when buffer is killed.
1938It should be added buffer-locally to `kill-buffer-hook'."
1939 (whitespace-action)
1940 nil) ; continue hook processing
1941
1942
1943(defun whitespace-action ()
1944 "Action to be taken when buffer is killed or written.
1945Return t when the action should be aborted."
1946 (cond ((memq 'auto-cleanup whitespace-action)
1947 (whitespace-cleanup)
1948 nil)
1949 ((memq 'abort-on-bogus whitespace-action)
1950 (whitespace-report nil t))
1951 (t
1952 nil)))
1953
1954
1955;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1755 1956
1756 1957
1757(defun whitespace-unload-function () 1958(defun whitespace-unload-function ()
1758 "Unload the Whitespace library." 1959 "Unload the whitespace library."
1759 (let (whitespace-mode) ;; so g-w-m thinks it is nil in all buffers 1960 (global-whitespace-mode -1)
1760 (global-whitespace-mode -1)) 1961 ;; be sure all local whitespace mode is turned off
1761 ;; continue standard unloading 1962 (save-current-buffer
1762 nil) 1963 (dolist (buf (buffer-list))
1964 (set-buffer buf)
1965 (whitespace-mode -1)))
1966 nil) ; continue standard unloading
1967
1763 1968
1764(provide 'whitespace) 1969(provide 'whitespace)
1765 1970