unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: rms@gnu.org
Cc: Tom Tromey <tromey@redhat.com>, emacs-devel@gnu.org
Subject: Re: Patch: goto-address -vs- font-lock-mode
Date: Thu, 05 Jul 2007 10:20:58 -0400	[thread overview]
Message-ID: <jwvbqerosac.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <E1I6GAR-0006Qh-JQ@fencepost.gnu.org> (Richard Stallman's message of "Wed\, 04 Jul 2007 21\:29\:59 -0400")

>     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

  parent reply	other threads:[~2007-07-05 14:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-03 18:03 Patch: goto-address -vs- font-lock-mode Tom Tromey
2007-07-05  1:29 ` Richard Stallman
2007-07-05  1:37   ` Tom Tromey
2007-07-05 14:20   ` Stefan Monnier [this message]
2007-07-05 14:29 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvbqerosac.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=rms@gnu.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).