From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Patch: goto-address -vs- font-lock-mode Date: Tue, 03 Jul 2007 12:03:42 -0600 Message-ID: Reply-To: Tom Tromey NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1183487298 15582 80.91.229.12 (3 Jul 2007 18:28:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 3 Jul 2007 18:28:18 +0000 (UTC) To: Emacs Hackers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 03 20:28:15 2007 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I5n6k-00061Y-6A for ged-emacs-devel@m.gmane.org; Tue, 03 Jul 2007 20:28:14 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I5n6j-00025P-Dy for ged-emacs-devel@m.gmane.org; Tue, 03 Jul 2007 14:28:13 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I5n6f-00024w-LN for emacs-devel@gnu.org; Tue, 03 Jul 2007 14:28:09 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I5n6f-00024i-5n for emacs-devel@gnu.org; Tue, 03 Jul 2007 14:28:09 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I5n6f-00024f-0a for emacs-devel@gnu.org; Tue, 03 Jul 2007 14:28:09 -0400 Original-Received: from mx1.redhat.com ([66.187.233.31]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I5n6X-0002hP-8y for emacs-devel@gnu.org; Tue, 03 Jul 2007 14:28:07 -0400 Original-Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.1/8.13.1) with ESMTP id l63IRi1E005284 for ; Tue, 3 Jul 2007 14:28:00 -0400 Original-Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l63INrfJ000333 for ; Tue, 3 Jul 2007 14:23:53 -0400 Original-Received: from opsy.redhat.com (ton.toronto.redhat.com [172.16.14.15]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l63INq8X013331; Tue, 3 Jul 2007 14:23:52 -0400 Original-Received: by opsy.redhat.com (Postfix, from userid 500) id 09F8188826B; Tue, 3 Jul 2007 12:03:43 -0600 (MDT) X-Attribution: Tom X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:74247 Archived-At: This patch adds a new minor mode that acts like `goto-address'. Unlike goto-address, it uses font-lock to add properties to text in the buffer. This means that changes to the buffer which add URLs or email address will automatically be detected. This patch is not quite ready for checkin. I wanted some advice first. This code works by adding multiple properties via font-lock-keywords. It then adds these new properties to font-lock-extra-managed-props. This seems a bit error-prone in the case where multiple callers want to do this. For instance, I have a separate minor mode that adds similar functionality for bugzilla references -- it is nearly the same code and wants to set the same properties. In this situation there would be a conflict if the minor mode tries to clean up after itself by removing items from font-lock-extra-managed-props. I suppose one idea would be to generalize this code. It could take a list of entries (each one a regular expression, a couple of faces, and a function). This would work by mandating that only one minor mode at a time be allowed to do this in a buffer. (I'm not super happy with this idea, just throwing it out there...) Also, I initially wrote this for use in change-log-mode. However while writing it, it occurred to me that this would be very useful in just about any source code buffer, provided the new font-lock keywords were restricted to comments. I didn't see an easy way to do that, though. Let me know what you think. Thanks, Tom lisp/ChangeLog: 2007-07-03 Tom Tromey * net/goto-addr.el (goto-address-font-lock-mode): New minor mode. Index: lisp/net/goto-addr.el =================================================================== RCS file: /sources/emacs/emacs/lisp/net/goto-addr.el,v retrieving revision 1.29 diff -u -r1.29 goto-addr.el --- lisp/net/goto-addr.el 21 Jan 2007 03:02:10 -0000 1.29 +++ lisp/net/goto-addr.el 3 Jul 2007 18:13:31 -0000 @@ -252,6 +252,41 @@ (goto-address-fontify))) ;;;###autoload(put 'goto-address 'safe-local-eval-function t) +(define-minor-mode goto-address-font-lock-mode + "A minor mode that adds `goto-address' functionality via `font-lock-mode'. +Allows user to use mouse/keyboard command to click to go to a URL +or to send e-mail. +Enables `font-lock-mode' in the current buffer if not already enabled." + nil + "" + nil + (let ((keywords + `((,goto-address-mail-regexp + . (0 '(face ,goto-address-mail-face + mouse-face ,goto-address-mail-mouse-face + help-echo "mouse-2, C-c RET: mail this address" + keymap ,goto-address-highlight-keymap + follow-link t + goto-address t))) + (,goto-address-url-regexp + . (0 '(face ,goto-address-url-face + mouse-face ,goto-address-mail-mouse-face + help-echo "mouse-2, C-c RET: follow URL" + keymap ,goto-address-highlight-keymap + follow-link t + goto-address t)))))) + (if goto-address-font-lock-mode + (progn + (font-lock-mode 1) + (font-lock-add-keywords nil keywords) + ;; FIXME: what if other modes want to do this? + (setq font-lock-extra-managed-props '(mouse-face help-echo + keymap + follow-link + goto-address))) + (font-lock-remove-keywords nil keywords)) + (font-lock-fontify-buffer))) + (provide 'goto-addr) ;; arch-tag: ca47c505-5661-425d-a471-62bc6e75cf0a