[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch: goto-address -vs- font-lock-mode
From: |
Stefan Monnier |
Subject: |
Re: Patch: goto-address -vs- font-lock-mode |
Date: |
Thu, 05 Jul 2007 10:20:58 -0400 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux) |
> 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