comparison lisp/gnus/gnus-art.el @ 112372:539ff9c0e704

gnus-art.el (gnus-article-add-buttons): Simplify condition. (gnus-button-push): Remove gnus-button-entry function, it fails heavily if you have the same regexp several times. (gnus-button-push): Fix matching when regexp is symbol. spam.el (spam-spamassassin-register-with-sa-learn): Insert a full From header with a date and "nobody" as the sender.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Wed, 19 Jan 2011 22:22:18 +0000
parents c24551a0cd95
children f279fb6c0f32
comparison
equal deleted inserted replaced
112371:1a3d4c7ba327 112372:539ff9c0e704
4411 (when gnus-summary-tool-bar-map 4411 (when gnus-summary-tool-bar-map
4412 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))) 4412 (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
4413 (gnus-update-format-specifications nil 'article-mode) 4413 (gnus-update-format-specifications nil 'article-mode)
4414 (set (make-local-variable 'page-delimiter) gnus-page-delimiter) 4414 (set (make-local-variable 'page-delimiter) gnus-page-delimiter)
4415 (set (make-local-variable 'gnus-page-broken) nil) 4415 (set (make-local-variable 'gnus-page-broken) nil)
4416 (make-local-variable 'gnus-button-marker-list)
4417 (make-local-variable 'gnus-article-current-summary) 4416 (make-local-variable 'gnus-article-current-summary)
4418 (make-local-variable 'gnus-article-mime-handles) 4417 (make-local-variable 'gnus-article-mime-handles)
4419 (make-local-variable 'gnus-article-decoded-p) 4418 (make-local-variable 'gnus-article-decoded-p)
4420 (make-local-variable 'gnus-article-mime-handle-alist) 4419 (make-local-variable 'gnus-article-mime-handle-alist)
4421 (make-local-variable 'gnus-article-wash-types) 4420 (make-local-variable 'gnus-article-wash-types)
4433 (setq buffer-read-only t 4432 (setq buffer-read-only t
4434 show-trailing-whitespace nil) 4433 show-trailing-whitespace nil)
4435 (set-syntax-table gnus-article-mode-syntax-table) 4434 (set-syntax-table gnus-article-mode-syntax-table)
4436 (mm-enable-multibyte) 4435 (mm-enable-multibyte)
4437 (gnus-run-mode-hooks 'gnus-article-mode-hook)) 4436 (gnus-run-mode-hooks 'gnus-article-mode-hook))
4438
4439 (defvar gnus-button-marker-list nil
4440 "Regexp matching any of the regexps from `gnus-button-alist'.
4441 Internal variable.")
4442 4437
4443 (defun gnus-article-setup-buffer () 4438 (defun gnus-article-setup-buffer ()
4444 "Initialize the article buffer." 4439 "Initialize the article buffer."
4445 (let* ((name (if gnus-single-article-buffer "*Article*" 4440 (let* ((name (if gnus-single-article-buffer "*Article*"
4446 (concat "*Article " gnus-newsgroup-name "*"))) 4441 (concat "*Article " gnus-newsgroup-name "*")))
4481 (setq gnus-article-mime-handles nil)) 4476 (setq gnus-article-mime-handles nil))
4482 ;; Set it to nil in article-buffer! 4477 ;; Set it to nil in article-buffer!
4483 (setq gnus-article-mime-handle-alist nil) 4478 (setq gnus-article-mime-handle-alist nil)
4484 (buffer-disable-undo) 4479 (buffer-disable-undo)
4485 (setq buffer-read-only t) 4480 (setq buffer-read-only t)
4486 ;; This list just keeps growing if we don't reset it.
4487 (setq gnus-button-marker-list nil)
4488 (unless (eq major-mode 'gnus-article-mode) 4481 (unless (eq major-mode 'gnus-article-mode)
4489 (gnus-article-mode)) 4482 (gnus-article-mode))
4490 (setq truncate-lines gnus-article-truncate-lines) 4483 (setq truncate-lines gnus-article-truncate-lines)
4491 (current-buffer)) 4484 (current-buffer))
4492 (with-current-buffer (gnus-get-buffer-create name) 4485 (with-current-buffer (gnus-get-buffer-create name)
7724 7717
7725 (defun gnus-button-in-region-p (b e prop) 7718 (defun gnus-button-in-region-p (b e prop)
7726 "Say whether PROP exists in the region." 7719 "Say whether PROP exists in the region."
7727 (text-property-not-all b e prop nil)) 7720 (text-property-not-all b e prop nil))
7728 7721
7729 (defun gnus-article-add-buttons (&optional force) 7722 (defun gnus-article-add-buttons ()
7730 "Find external references in the article and make buttons of them. 7723 "Find external references in the article and make buttons of them.
7731 \"External references\" are things like Message-IDs and URLs, as 7724 \"External references\" are things like Message-IDs and URLs, as
7732 specified by `gnus-button-alist'." 7725 specified by `gnus-button-alist'."
7733 (interactive (list 'force)) 7726 (interactive)
7734 (gnus-with-article-buffer 7727 (gnus-with-article-buffer
7735 (let ((inhibit-point-motion-hooks t) 7728 (let ((inhibit-point-motion-hooks t)
7736 (case-fold-search t) 7729 (case-fold-search t)
7737 (alist gnus-button-alist) 7730 (alist gnus-button-alist)
7738 beg entry regexp) 7731 beg entry regexp)
7739 ;; Remove all old markers.
7740 (let (marker entry new-list)
7741 (while (setq marker (pop gnus-button-marker-list))
7742 (if (or (< marker (point-min)) (>= marker (point-max)))
7743 (push marker new-list)
7744 (goto-char marker)
7745 (when (setq entry (gnus-button-entry))
7746 (put-text-property (match-beginning (nth 1 entry))
7747 (match-end (nth 1 entry))
7748 'gnus-callback nil))
7749 (set-marker marker nil)))
7750 (setq gnus-button-marker-list new-list))
7751 ;; We skip the headers. 7732 ;; We skip the headers.
7752 (article-goto-body) 7733 (article-goto-body)
7753 (setq beg (point)) 7734 (setq beg (point))
7754 (while (setq entry (pop alist)) 7735 (while (setq entry (pop alist))
7755 (setq regexp (eval (car entry))) 7736 (setq regexp (eval (car entry)))
7756 (goto-char beg) 7737 (goto-char beg)
7757 (while (re-search-forward regexp nil t) 7738 (while (re-search-forward regexp nil t)
7758 (let ((start (match-beginning (nth 1 entry))) 7739 (let ((start (match-beginning (nth 1 entry)))
7759 (end (match-end (nth 1 entry))) 7740 (end (match-end (nth 1 entry)))
7760 (from (match-beginning 0))) 7741 (from (match-beginning 0)))
7761 (when (and (or (eq t (nth 2 entry)) 7742 (when (and (eval (nth 2 entry))
7762 (eval (nth 2 entry)))
7763 (not (gnus-button-in-region-p 7743 (not (gnus-button-in-region-p
7764 start end 'gnus-callback))) 7744 start end 'gnus-callback)))
7765 ;; That optional form returned non-nil, so we add the 7745 ;; That optional form returned non-nil, so we add the
7766 ;; button. 7746 ;; button.
7767 (setq from (set-marker (make-marker) from)) 7747 (setq from (set-marker (make-marker) from))
7768 (push from gnus-button-marker-list)
7769 (unless (and (eq (car entry) 'gnus-button-url-regexp) 7748 (unless (and (eq (car entry) 'gnus-button-url-regexp)
7770 (gnus-article-extend-url-button from start end)) 7749 (gnus-article-extend-url-button from start end))
7771 (gnus-article-add-button start end 7750 (gnus-article-add-button start end
7772 'gnus-button-push from) 7751 'gnus-button-push (list from entry))
7773 (gnus-put-text-property 7752 (gnus-put-text-property
7774 start end 7753 start end
7775 'gnus-string (buffer-substring-no-properties 7754 'gnus-string (buffer-substring-no-properties
7776 start end)))))))))) 7755 start end))))))))))
7777 7756
7914 (cons 'article-type (cons 'signature 7893 (cons 'article-type (cons 'signature
7915 gnus-hidden-properties))))) 7894 gnus-hidden-properties)))))
7916 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist)) 7895 (let ((gnus-article-mime-handle-alist-1 gnus-article-mime-handle-alist))
7917 (gnus-set-mode-line 'article)))) 7896 (gnus-set-mode-line 'article))))
7918 7897
7919 (defun gnus-button-entry () 7898 (defun gnus-button-push (marker-and-entry)
7920 ;; Return the first entry in `gnus-button-alist' matching this place.
7921 (let ((alist gnus-button-alist)
7922 (entry nil))
7923 (while alist
7924 (setq entry (pop alist))
7925 (if (looking-at (eval (car entry)))
7926 (setq alist nil)
7927 (setq entry nil)))
7928 entry))
7929
7930 (defun gnus-button-push (marker)
7931 ;; Push button starting at MARKER. 7899 ;; Push button starting at MARKER.
7932 (save-excursion 7900 (save-excursion
7933 (goto-char marker) 7901 (let* ((marker (car marker-and-entry))
7934 (let* ((entry (gnus-button-entry)) 7902 (entry (cadr marker-and-entry))
7935 (inhibit-point-motion-hooks t) 7903 (regexp (car entry))
7936 (fun (nth 3 entry)) 7904 (inhibit-point-motion-hooks t))
7937 (args (or (and (eq (car entry) 'gnus-button-url-regexp) 7905 (goto-char marker)
7938 (get-char-property marker 'gnus-button-url)) 7906 ;; This is obviously true, or something bad is happening :)
7939 (mapcar (lambda (group) 7907 ;; But we need it to have the match-data
7940 (let ((string (match-string group))) 7908 (when (looking-at (or (if (symbolp regexp)
7941 (set-text-properties 7909 (symbol-value regexp)
7942 0 (length string) nil string) 7910 regexp)))
7943 string)) 7911 (let ((fun (nth 3 entry))
7944 (nthcdr 4 entry))))) 7912 (args (or (and (eq (car entry) 'gnus-button-url-regexp)
7945 (cond 7913 (get-char-property marker 'gnus-button-url))
7946 ((fboundp fun) 7914 (mapcar (lambda (group)
7947 (apply fun args)) 7915 (let ((string (match-string group)))
7948 ((and (boundp fun) 7916 (set-text-properties
7949 (fboundp (symbol-value fun))) 7917 0 (length string) nil string)
7950 (apply (symbol-value fun) args)) 7918 string))
7951 (t 7919 (nthcdr 4 entry)))))
7952 (gnus-message 1 "You must define `%S' to use this button" 7920
7953 (cons fun args))))))) 7921 (cond
7922 ((fboundp fun)
7923 (apply fun args))
7924 ((and (boundp fun)
7925 (fboundp (symbol-value fun)))
7926 (apply (symbol-value fun) args))
7927 (t
7928 (gnus-message 1 "You must define `%S' to use this button"
7929 (cons fun args)))))))))
7954 7930
7955 (defun gnus-parse-news-url (url) 7931 (defun gnus-parse-news-url (url)
7956 (let (scheme server port group message-id articles) 7932 (let (scheme server port group message-id articles)
7957 (with-temp-buffer 7933 (with-temp-buffer
7958 (insert url) 7934 (insert url)