* gnus-cite.el (gnus-cite-face-list): Set the value of
authorKatsumi Yamaoka <yamaoka@jpl.org>
Wed, 7 Feb 2007 09:24:08 +0000 (09:24 +0000)
committerKatsumi Yamaoka <yamaoka@jpl.org>
Wed, 7 Feb 2007 09:24:08 +0000 (09:24 +0000)
 gnus-message-max-citation-depth.
(gnus-message-max-citation-depth): Use defvar rather than defconst.
(gnus-message-cite-prefix-regexp): New variable.
(gnus-message-search-citation-line): Use it;
 protect against long citation prefix;
 fill match data with nil rather than 0 for XEmacs;
 set the 0th match data for Emacs.
(gnus-message-citation-keywords): Set LAXMATCH flag in every HIGHLIGHT.
(gnus-message-add-citation-keywords): Append keywords rather than prepending;
 emulate font-lock-add-keywords if it is not available.
(gnus-message-remove-citation-keywords): Emulate font-lock-remove-keywords if
 it is not available.

* gnus-msg.el (gnus-message-highlight-citation): Default to t.

* message.el (message-cite-prefix-regexp): Set the value of
 gnus-message-cite-prefix-regexp.

lisp/ChangeLog
lisp/gnus-cite.el
lisp/gnus-msg.el
lisp/message.el

index 9b28e76..0ac41ad 100644 (file)
@@ -1,3 +1,23 @@
+2007-02-07  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+       * gnus-cite.el (gnus-cite-face-list): Set the value of
+       gnus-message-max-citation-depth.
+       (gnus-message-max-citation-depth): Use defvar rather than defconst.
+       (gnus-message-cite-prefix-regexp): New variable.
+       (gnus-message-search-citation-line): Use it; protect against long
+       citation prefix; fill match data with nil rather than 0 for XEmacs; set
+       the 0th match data for Emacs.
+       (gnus-message-citation-keywords): Set LAXMATCH flag in every HIGHLIGHT.
+       (gnus-message-add-citation-keywords): Append keywords rather than
+       prepending; emulate font-lock-add-keywords if it is not available.
+       (gnus-message-remove-citation-keywords): Emulate
+       font-lock-remove-keywords if it is not available.
+
+       * gnus-msg.el (gnus-message-highlight-citation): Default to t.
+
+       * message.el (message-cite-prefix-regexp): Set the value of
+       gnus-message-cite-prefix-regexp.
+
 2007-02-01  Andreas Seltenreich  <uwi7@rz.uni-karlsruhe.de>
 
        * nnweb.el (nnweb-google-parse-1): Update parser.
index 1196284..d186986 100644 (file)
@@ -304,7 +304,12 @@ When there are citations from multiple articles in the same message,
 Gnus will try to give each citation from each article its own face.
 This should make it easier to see who wrote what."
   :group 'gnus-cite
-  :type '(repeat face))
+  :type '(repeat face)
+  :set (lambda (symbol value)
+        (prog1
+            (custom-set-default symbol value)
+          (if (boundp 'gnus-message-max-citation-depth)
+              (setq gnus-message-max-citation-depth (length value))))))
 
 (defcustom gnus-cite-hide-percentage 50
   "Only hide excess citation if above this percentage of the body."
@@ -1106,37 +1111,31 @@ See also the documentation for `gnus-article-highlight-citation'."
 
 
 ;; Highlighting of different citation levels in message-mode.
-;;
-;; Known bugs:
-;;
-;; - XEmacs compatibility: `font-lock-add-keywords' is missing in XEmacs.
-;;
-;; - message-cite-prefix should not be fontified.
+;; - message-cite-prefix will be overridden if this is enabled.
 
-(defconst gnus-message-max-citation-depth
+(defvar gnus-message-max-citation-depth
   (length gnus-cite-face-list)
   "Maximum supported level of citation.")
 
+(defvar gnus-message-cite-prefix-regexp
+  (concat "^\\(?:" message-cite-prefix-regexp "\\)"))
+
 (defun gnus-message-search-citation-line (limit)
   "Search for a cited line and set match data accordingly.
 Returns nil if there is no such line before LIMIT, t otherwise."
-  (when (re-search-forward (eval-when-compile
-                            (concat "^\\(?:"
-                                    message-cite-prefix-regexp
-                                    "\\)"))
-                          limit t)
-    (let ((cdepth
-          (length (apply 'concat
-                         (split-string
-                          (match-string-no-properties 0)
-                          "[ \t [:alnum:]]+"))))
-         (mlist (make-list (* (1+ gnus-message-max-citation-depth)
-                              2)
-                           0)))
-      (setcar (nthcdr (* cdepth 2) mlist)
-             (line-beginning-position))
-      (setcar (nthcdr (1+ (* cdepth 2)) mlist)
-             (line-end-position))
+  (when (re-search-forward gnus-message-cite-prefix-regexp limit t)
+    (let ((cdepth (min (length (apply 'concat
+                                     (split-string
+                                      (match-string-no-properties 0)
+                                      "[ \t [:alnum:]]+")))
+                      gnus-message-max-citation-depth))
+         (mlist (make-list (* (1+ gnus-message-max-citation-depth) 2) nil))
+         (start (line-beginning-position))
+         (end (line-end-position)))
+      (setcar mlist start)
+      (setcar (cdr mlist) end)
+      (setcar (nthcdr (* cdepth 2) mlist) start)
+      (setcar (nthcdr (1+ (* cdepth 2)) mlist) end)
       (set-match-data mlist))
     t))
 
@@ -1147,21 +1146,51 @@ Returns nil if there is no such line before LIMIT, t otherwise."
             (count 1))
         ;; (require 'gnus-cite)
         (dolist (face gnus-cite-face-list (nreverse list))
-          (push (list count (list 'quote face) 'prepend) list)
+          (push (list count (list 'quote face) 'prepend t) list)
           (setq count (1+ count)))))) ;;
   "Keywords for highlighting different levels of message citations.")
 
+(eval-when-compile
+  (autoload 'font-lock-compile-keywords "font-lock")
+  (defvar font-lock-keywords)
+  (unless (fboundp 'font-lock-add-keywords)
+    (autoload 'font-lock-add-keywords "font-lock"))
+  (unless (fboundp 'font-lock-remove-keywords)
+    (autoload 'font-lock-remove-keywords "font-lock")))
+
 (defun gnus-message-add-citation-keywords ()
   "Add font-lock for nested citations to current buffer."
   (if (fboundp 'font-lock-add-keywords)
-      (font-lock-add-keywords nil gnus-message-citation-keywords)
-    (gnus-message 1 "`font-lock-add-keywords' not supported.")))
+      (font-lock-add-keywords nil gnus-message-citation-keywords 'append)
+    (font-lock-set-defaults)
+    (let ((was-compiled (eq (car font-lock-keywords) t)))
+      (setq font-lock-keywords (copy-sequence (if was-compiled
+                                                 (cadr font-lock-keywords)
+                                               font-lock-keywords)))
+      (dolist (keyword gnus-message-citation-keywords)
+       (setq font-lock-keywords (delete keyword font-lock-keywords)))
+      (let ((old (if (eq (car-safe font-lock-keywords) t)
+                    (cdr font-lock-keywords)
+                  font-lock-keywords)))
+       (setq font-lock-keywords (append old gnus-message-citation-keywords)))
+      (if was-compiled
+         (setq font-lock-keywords
+               (font-lock-compile-keywords font-lock-keywords))))))
 
 (defun gnus-message-remove-citation-keywords ()
   "Remove font-lock for nested citations from current buffer."
   (if (fboundp 'font-lock-remove-keywords)
       (font-lock-remove-keywords nil gnus-message-citation-keywords)
-    (gnus-message 1 "`font-lock-remove-keywords' not supported.")))
+    (font-lock-set-defaults)
+    (let ((was-compiled (eq (car font-lock-keywords) t)))
+      (if was-compiled
+         (setq font-lock-keywords (cadr font-lock-keywords)))
+      (setq font-lock-keywords (copy-sequence font-lock-keywords))
+      (dolist (keyword gnus-message-citation-keywords)
+       (setq font-lock-keywords (delete keyword font-lock-keywords)))
+      (if was-compiled
+         (setq font-lock-keywords
+               (font-lock-compile-keywords font-lock-keywords))))))
 
 (define-minor-mode gnus-message-citation-mode
   "Toggle `gnus-message-citation-mode' in current buffer.
index 2edf0bf..fd058fa 100644 (file)
@@ -290,8 +290,7 @@ If nil, the address field will always be empty after invoking
   :type 'boolean)
 
 (defcustom gnus-message-highlight-citation
-  (and t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
-       (fboundp 'font-lock-add-keywords))
+  t ;; gnus-treat-highlight-citation ;; gnus-cite dependency
   "Enable highlighting of different citation levels in message-mode."
   :version "23.0" ;; No Gnus
   :group 'gnus-cite
index 2a42c49..b04b0e3 100644 (file)
@@ -583,7 +583,13 @@ Done before generating the new subject of a forward."
   :version "22.1"
   :group 'message-insertion
   :link '(custom-manual "(message)Insertion Variables")
-  :type 'regexp)
+  :type 'regexp
+  :set (lambda (symbol value)
+        (prog1
+            (custom-set-default symbol value)
+          (if (boundp 'gnus-message-cite-prefix-regexp)
+              (setq gnus-message-cite-prefix-regexp
+                    (concat "^\\(?:" value "\\)"))))))
 
 (defcustom message-cancel-message "I am canceling my own article.\n"
   "Message to be inserted in the cancel message."