From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Patch: goto-address -vs- font-lock-mode Date: Thu, 05 Jul 2007 10:20:58 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1183645291 14288 80.91.229.12 (5 Jul 2007 14:21:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 5 Jul 2007 14:21:31 +0000 (UTC) Cc: Tom Tromey , emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 05 16:21:26 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 1I6SCy-0002Wn-3i for ged-emacs-devel@m.gmane.org; Thu, 05 Jul 2007 16:21:24 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I6SCx-0002WM-Gn for ged-emacs-devel@m.gmane.org; Thu, 05 Jul 2007 10:21:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I6SCh-0002N5-R1 for emacs-devel@gnu.org; Thu, 05 Jul 2007 10:21:07 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I6SCg-0002Mc-RY for emacs-devel@gnu.org; Thu, 05 Jul 2007 10:21:07 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I6SCg-0002MX-Kn for emacs-devel@gnu.org; Thu, 05 Jul 2007 10:21:06 -0400 Original-Received: from mercure.iro.umontreal.ca ([132.204.24.67]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I6SCd-0005ic-A0; Thu, 05 Jul 2007 10:21:03 -0400 Original-Received: from hidalgo.iro.umontreal.ca (hidalgo.iro.umontreal.ca [132.204.27.50]) by mercure.iro.umontreal.ca (Postfix) with ESMTP id AD9E52CF273; Thu, 5 Jul 2007 10:21:02 -0400 (EDT) Original-Received: from faina.iro.umontreal.ca (faina.iro.umontreal.ca [132.204.26.177]) by hidalgo.iro.umontreal.ca (Postfix) with ESMTP id B72AB3FE1; Thu, 5 Jul 2007 10:20:58 -0400 (EDT) Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id A23F76C8CC; Thu, 5 Jul 2007 10:20:58 -0400 (EDT) In-Reply-To: (Richard Stallman's message of "Wed\, 04 Jul 2007 21\:29\:59 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) X-DIRO-MailScanner-Information: Please contact the ISP for more information X-DIRO-MailScanner: Found to be clean X-DIRO-MailScanner-SpamCheck: n'est pas un polluriel, SpamAssassin (score=-2.82, requis 5, autolearn=not spam, ALL_TRUSTED -2.82) X-DIRO-MailScanner-From: monnier@iro.umontreal.ca X-detected-kernel: Linux 2.6 (newer, 3) 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:74342 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. > Would it be more appropriate to use overlays for this? > You wouldn't want to copy those properties ever, and it is better > if adding them does not modify the buffer. Unless there are many URLs in the buffer, overlays do seem better suited. > Is it feasible to use the font-lock mechanism to add overlays? Of course, since font-lock provides the hooks to plug any piece of elisp code. You could do something like: (defun g-a-f-l-add-overlay (type) (let ((ol (make-overlay (match-beginning 0) (match-end 0)))) (overlay-put ol 'goto-address t) (case type (url ...) (mail ...)) ...)) (defun g-a-f-l-remove-overlays (b e) (remove-overlays b e 'goto-address 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 nil (let ((keywords `((,goto-address-mail-regexp . (0 (g-a-f-l-add-overlay 'mail))) (,goto-address-url-regexp . (0 (g-a-f-l-add-overlay 'url)))))) (font-lock-remove-keywords nil keywords) (remove-hook 'font-lock-unfontify-region-function 'g-a-f-l-remove-overlays t) (when goto-address-font-lock-mode (font-lock-mode 1) (font-lock-add-keywords nil keywords) (add-hook 'font-lock-unfontify-region-function 'g-a-f-l-remove-overlays nil t))) (font-lock-fontify-buffer)) But then you could also hook into jit-lock rather than font-lock, which would have the advantage of not depending on (on infringing on) the user's choice to use font-lock or not. Stefan