On Mon, Feb 23, 2009 at 11:56:03AM -0500, Peter S Galbraith wrote:
> I'm sorry that this bug is almost a year old now.  I can no longer
> find the upstream author of apt-sources.el.  If he is off the grid,
> I make simply take over the file.  :-(

I started on this, but lost interest before getting it completely
right.  See attached.
--- /usr/share/emacs/site-lisp/debian-el/apt-sources.el	2003-12-12 07:27:43.000000000 +1100
+++ apt-sources.el	2009-03-02 17:34:03.000000000 +1100
@@ -155,36 +155,62 @@
   :type 'string
   :group 'apt-sources)  
 
-;;Regexps for identifying source line parts for font-lock.
-(defvar apt-sources-font-lock-deb-regexp "\\(deb \\|deb-src \\)"
-  "A regexp that matches 'deb' or 'deb-src' at the begining of line.")
-
-(defvar apt-sources-font-lock-uri-regexp
-  "\\([^ ]*\\)"
-  "A regexp that matches the URI part of the source line.")
-
-(defvar apt-sources-font-lock-distribution-regexp
-  "\\( [^ \n]*\\)"
-  "A regexp that matches the distribution name part of the source line.")
-
-
 (defvar apt-sources-font-lock-keywords
-  (list
-   ;; Comments
-   '("^#.*$" . font-lock-comment-face)
-   ;; sources.list lines:
-   ;; deb http://http.us.debian.org/debian unstable main contrib
-   (cons
-    (concat "^"
-	    apt-sources-font-lock-deb-regexp
-	    apt-sources-font-lock-uri-regexp
-	    apt-sources-font-lock-distribution-regexp
-	    "\\(.*\\)$")
-    '(
-      (1 font-lock-constant-face)
-      (2 font-lock-variable-name-face)
-      (3 font-lock-type-face)
-      (4 font-lock-keyword-face))))
+  (prog1
+      '(("\\(?:^\\|[[:space:]]\\)\\(#.*\\)$" . font-lock-comment-face)
+        ("^[[:blank:]]*\\(\\(?:deb\\(?:-src\\)?\\)\\)[[:blank:]]+\\([^[:space:]]+\\)[[:blank:]]+\\([^[:space:]]+\\)\\(\\(?:[[:blank:]]+[^[:space:]]+\\)+\\)"
+         (1 font-lock-constant-face)
+         (2 font-lock-variable-name-face)
+         (3 font-lock-type-face)
+         (4 font-lock-keyword-face))
+        ("^[[:blank:]]*\\(\\(?:deb\\(?:-src\\)?\\)\\)[[:blank:]]+\\([^[:space:]]+\\)[[:blank:]]+\\([^[:space:]]+\\)"
+         (1 font-lock-constant-face)
+         (2 font-lock-variable-name-face)
+         (3 font-lock-builtin-face)))
+    ;; the rx definition that a human wrote (compiles to the form above)
+    (quote                          ; the original rx-based definition
+     (list
+      ;; Comments
+      (cons (rx line-start
+                (zero-or-more (any blank))
+                (group "#" (zero-or-more not-newline)))
+            'font-lock-comment-face)
+      ;; sources.list lines:
+      ;; deb http://http.us.debian.org/debian unstable main contrib
+      (cons (rx line-start
+                (zero-or-more (any blank))
+                (group (or "deb" "deb-src"))
+                (one-or-more (any blank))
+                (group (one-or-more (not (in space)))) ; uri
+                (one-or-more (any blank))
+                (group (one-or-more (not (in space)))) ; release
+                (group
+                 (one-or-more
+                  (one-or-more (any blank))
+                  (one-or-more (not (in space))))) ; categories
+                (zero-or-one
+                 (zero-or-more (any blank))
+                 (group "#" (zero-or-more not-newline)))) ; comment
+            '((1 font-lock-constant-face)
+              (2 font-lock-variable-name-face)
+              (3 font-lock-type-face)
+              (4 font-lock-keyword-face)
+              (5 font-lock-comment-face)))
+      ;; deb http://foo.org/ packages/
+      (cons (rx line-start
+                (zero-or-more (any blank))
+                (group (or "deb" "deb-src"))
+                (one-or-more (any blank))
+                (group (one-or-more (not (in space)))) ; uri
+                (one-or-more (any blank))
+                (group (one-or-more (not (in space)))) ; subdir
+                (zero-or-one
+                 (zero-or-more (any blank))
+                 (group "#" (zero-or-more not-newline)))) ; comment
+            '((1 font-lock-constant-face)
+              (2 font-lock-variable-name-face)
+              (3 font-lock-builtin-face)
+              (4 font-lock-comment-face))))))
   "Info for function `font-lock-mode'.")
 
 (defvar apt-sources-mode-map nil

Reply via email to