emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/blank-mode.el, v [EMACS_22_BASE]


From: Vinicius Jose Latorre
Subject: [Emacs-diffs] Changes to emacs/lisp/blank-mode.el, v [EMACS_22_BASE]
Date: Sat, 26 Jan 2008 01:49:20 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Branch:         EMACS_22_BASE
Changes by:     Vinicius Jose Latorre <viniciusjl>      08/01/26 01:49:18

Index: blank-mode.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/blank-mode.el,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -b -r1.1.2.6 -r1.1.2.7
--- blank-mode.el       25 Jan 2008 14:10:35 -0000      1.1.2.6
+++ blank-mode.el       26 Jan 2008 01:49:18 -0000      1.1.2.7
@@ -6,7 +6,7 @@
 ;; Author: Vinicius Jose Latorre <address@hidden>
 ;; Maintainer: Vinicius Jose Latorre <address@hidden>
 ;; Keywords: data, wp
-;; Version: 9.0
+;; Version: 9.1
 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
 
 ;; This file is part of GNU Emacs.
@@ -264,7 +264,7 @@
 ;; `blank-space-after-tab-regexp'      Specify regexp for 8 or more
 ;;                                     SPACEs after TAB.
 ;;
-;; `blank-line-length'         Specify length beyond which the line
+;; `blank-line-column'         Specify column beyond which the line
 ;;                             is highlighted.
 ;;
 ;; `blank-display-mappings'    Specify an alist of mappings for
@@ -277,6 +277,9 @@
 ;; Acknowledgements
 ;; ----------------
 ;;
+;; Thanks to nschum (EmacsWiki) for the idea about highlight "long"
+;; lines tail.  See EightyColumnRule (EmacsWiki).
+;;
 ;; Thanks to Juri Linkov <address@hidden> for suggesting:
 ;;    * `define-minor-mode'.
 ;;    * `global-blank-*' name for global commands.
@@ -366,8 +369,18 @@
 
    spaces              SPACEs and HARD SPACEs are visualized.
 
-   lines               lines whose length is greater than
-                       `blank-line-length' are highlighted.
+   lines               lines whose have columns beyond
+                       `blank-line-column' are highlighted.
+                       Whole line is highlighted.
+                       It has precedence over
+                       `lines-tail' (see below).
+
+   lines-tail          lines whose have columns beyond
+                       `blank-line-column' are highlighted.
+                       But only the part of line which goes
+                       beyond `blank-line-column' column.
+                       It has effect only if `lines' (see above)
+                       is not present in `blank-chars'.
 
    space-before-tab    SPACEs before TAB are visualized.
 
@@ -501,7 +514,7 @@
 (defcustom blank-line 'blank-line
   "*Symbol face used to visualize \"long\" lines.
 
-See `blank-line-length'.
+See `blank-line-column'.
 
 Used when `blank-style' has `color' as an element."
   :type 'face
@@ -513,7 +526,7 @@
     (t (:background "gray20" :foreground "violet")))
   "Face used to visualize \"long\" lines.
 
-See `blank-line-length'."
+See `blank-line-column'."
   :group 'blank)
 
 
@@ -754,11 +767,11 @@
   :group 'blank)
 
 
-(defcustom blank-line-length 80
-  "*Specify length beyond which the line is highlighted.
+(defcustom blank-line-column 80
+  "*Specify column beyond which the line is highlighted.
 
 Used when `blank-style' has `color' as an element, and
-`blank-chars' has `lines' as an element."
+`blank-chars' has `lines' or `lines-tail' as an element."
   :type '(integer :tag "Line Length")
   :group 'blank)
 
@@ -944,6 +957,7 @@
     trailing
     space-before-tab
     lines
+    lines-tail
     newline
     indentation
     empty
@@ -965,6 +979,7 @@
     (?r . trailing)
     (?b . space-before-tab)
     (?l . lines)
+    (?L . lines-tail)
     (?n . newline)
     (?i . indentation)
     (?e . empty)
@@ -1015,6 +1030,7 @@
    r   toggle trailing blanks visualization
    b   toggle SPACEs before TAB visualization
    l   toggle \"long lines\" visualization
+   L   toggle \"long lines\" tail visualization
    n   toggle NEWLINE visualization
    i   toggle indentation SPACEs visualization
    e   toggle empty line at bob and/or eob visualization
@@ -1033,6 +1049,7 @@
    trailing            toggle trailing blanks visualization
    space-before-tab    toggle SPACEs before TAB visualization
    lines               toggle \"long lines\" visualization
+   lines-tail          toggle \"long lines\" tail visualization
    newline             toggle NEWLINE visualization
    indentation         toggle indentation SPACEs visualization
    empty               toggle empty line at bob and/or eob visualization
@@ -1078,6 +1095,7 @@
    r   toggle trailing blanks visualization
    b   toggle SPACEs before TAB visualization
    l   toggle \"long lines\" visualization
+   L   toggle \"long lines\" tail visualization
    n   toggle NEWLINE visualization
    i   toggle indentation SPACEs visualization
    e   toggle empty line at bob and/or eob visualization
@@ -1096,6 +1114,7 @@
    trailing            toggle trailing blanks visualization
    space-before-tab    toggle SPACEs before TAB visualization
    lines               toggle \"long lines\" visualization
+   lines-tail          toggle \"long lines\" tail visualization
    newline             toggle NEWLINE visualization
    indentation         toggle indentation SPACEs visualization
    empty               toggle empty line at bob and/or eob visualization
@@ -1170,6 +1189,7 @@
       (blank-cleanup-region (region-beginning) (region-end))
     ;; whole buffer
     (save-excursion
+      (save-match-data
       ;; problem 1: empty lines at bob
       ;; problem 2: empty lines at eob
       ;; action: remove all empty lines at bob and/or eob
@@ -1179,12 +1199,12 @@
          (when (re-search-forward blank-empty-at-bob-regexp nil t)
            (delete-region (match-beginning 1) (match-end 1)))
          (when (re-search-forward blank-empty-at-eob-regexp nil t)
-           (delete-region (match-beginning 1) (match-end 1)))))
+             (delete-region (match-beginning 1) (match-end 1)))))))
       ;; problem 3: 8 or more SPACEs at bol
       ;; problem 4: SPACEs before TAB
       ;; problem 5: SPACEs or TABs at eol
       ;; problem 6: 8 or more SPACEs after TAB
-      (blank-cleanup-region (point-min) (point-max)))))
+    (blank-cleanup-region (point-min) (point-max))))
 
 
 ;;;###autoload
@@ -1216,6 +1236,7 @@
        overwrite-mode                  ; enforce no overwrite
        tmp)
     (save-excursion
+      (save-match-data
       ;; problem 1: 8 or more SPACEs at bol
       ;; action: replace 8 or more SPACEs at bol by TABs
       (when (memq 'indentation blank-chars)
@@ -1228,41 +1249,38 @@
       ;; problem 3: SPACEs or TABs at eol
       ;; action: remove all SPACEs or TABs at eol
       (when (memq 'trailing blank-chars)
-       (let ((regexp
-              (concat "\\(\\(" blank-trailing-regexp "\\)+\\)$")))
+         (let ((regexp (concat "\\(\\(" blank-trailing-regexp
+                               "\\)+\\)$")))
          (goto-char rstart)
          (while (re-search-forward regexp rend t)
            (delete-region (match-beginning 1) (match-end 1)))))
       ;; problem 4: 8 or more SPACEs after TAB
       ;; action: replace 8 or more SPACEs by TABs
       (when (memq 'space-after-tab blank-chars)
-       (goto-char rstart)
-       (while (re-search-forward blank-space-after-tab-regexp rend t)
-         (goto-char (match-beginning 1))
-         (let ((scol (current-column))
-               (ecol (save-excursion
-                       (goto-char (match-end 1))
-                       (current-column))))
-           (delete-region (match-beginning 1) (match-end 1))
-           (insert-char ?\t (/ (- ecol scol) 8)))))
+         (blank-replace-spaces-by-tabs
+          rstart rend blank-space-after-tab-regexp))
       ;; problem 2: SPACEs before TAB
       ;; action: replace SPACEs before TAB by TABs
       (when (memq 'space-before-tab blank-chars)
+         (blank-replace-spaces-by-tabs
+          rstart rend blank-space-before-tab-regexp))))
+    (set-marker rend nil)))            ; point marker to nowhere
+
+
+(defun blank-replace-spaces-by-tabs (rstart rend regexp)
+  "Replace all SPACEs by TABs matched by REGEXP between RSTART and REND."
        (goto-char rstart)
-       (while (re-search-forward blank-space-before-tab-regexp rend t)
+  (while (re-search-forward regexp rend t)
          (goto-char (match-beginning 1))
          (let* ((scol         (current-column))
                 (ecol         (save-excursion
                                 (goto-char (match-end 1))
-                                (current-column)))
-                (next-tab-col (* (/ (+ scol 8) 8) 8)))
+                  (current-column))))
            (delete-region (match-beginning 1) (match-end 1))
-           (when (<= next-tab-col ecol)
              (insert-char ?\t
                           (/ (- (- ecol (% ecol 8))  ; prev end col
                                 (- scol (% scol 8))) ; prev start col
-                             8)))))))
-    (set-marker rend nil)))            ; point marker to nowhere
+                     8)))))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1291,6 +1309,7 @@
  []  r - toggle trailing blanks visualization
  []  b - toggle SPACEs before TAB visualization
  []  l - toggle \"long lines\" visualization
+ []  L - toggle \"long lines\" tail visualization
  []  n - toggle NEWLINE visualization
  []  i - toggle indentation SPACEs visualization
  []  e - toggle empty line at bob and/or eob visualization
@@ -1365,6 +1384,7 @@
    r   toggle trailing blanks visualization
    b   toggle SPACEs before TAB visualization
    l   toggle \"long lines\" visualization
+   L   toggle \"long lines\" tail visualization
    n   toggle NEWLINE visualization
    i   toggle indentation SPACEs visualization
    e   toggle empty line at bob and/or eob visualization
@@ -1504,14 +1524,25 @@
        (list (concat "\\(\\(" blank-trailing-regexp "\\)+\\)$")
              1 blank-trailing t))
        t))
-    (when (memq 'lines blank-active-chars)
+    (when (or (memq 'lines      blank-active-chars)
+             (memq 'lines-tail blank-active-chars))
       (font-lock-add-keywords
        nil
        (list
        ;; Show "long" lines
-       (list (concat "^\\(.\\{" (int-to-string blank-line-length)
-                     ",\\}\\)$")
-             1 blank-line t))
+       (list
+        (format
+         "^\\([^\t\n]\\{%s\\}\\|[^\t\n]\\{0,%s\\}\t\\)\\{%d\\}%s\\(.+\\)$"
+         tab-width (1- tab-width)
+         (/ blank-line-column tab-width)
+         (let ((rem (% blank-line-column tab-width)))
+           (if (zerop rem)
+               ""
+             (format ".\\{%d\\}" rem))))
+        (if (memq 'lines blank-active-chars)
+            0                          ; whole line
+          2)                           ; line tail
+        blank-line t))
        t))
     (when (memq 'space-before-tab blank-active-chars)
       (font-lock-add-keywords




reply via email to

[Prev in Thread] Current Thread [Next in Thread]