[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lisp/net/goto-addr.el,v
From: |
Glenn Morris |
Subject: |
[Emacs-diffs] Changes to emacs/lisp/net/goto-addr.el,v |
Date: |
Thu, 24 Apr 2008 05:48:08 +0000 |
CVSROOT: /sources/emacs
Module name: emacs
Changes by: Glenn Morris <gm> 08/04/24 05:48:08
Index: goto-addr.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/goto-addr.el,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- goto-addr.el 8 Jan 2008 20:45:54 -0000 1.31
+++ goto-addr.el 24 Apr 2008 05:48:08 -0000 1.32
@@ -151,24 +151,32 @@
:type 'face
:group 'goto-address)
+(defun goto-address-unfontify (start end)
+ "Remove `goto-address' fontification from the given region."
+ (dolist (overlay (overlays-in start end))
+ (if (overlay-get overlay 'goto-address)
+ (delete-overlay overlay))))
+
(defun goto-address-fontify ()
"Fontify the URLs and e-mail addresses in the current buffer.
This function implements `goto-address-highlight-p'
and `goto-address-fontify-p'."
;; Clean up from any previous go.
- (dolist (overlay (overlays-in (point-min) (point-max)))
- (if (overlay-get overlay 'goto-address)
- (delete-overlay overlay)))
+ (goto-address-unfontify (point-min) (point-max))
(save-excursion
(let ((inhibit-point-motion-hooks t))
(goto-char (point-min))
- (if (or (eq t goto-address-fontify-maximum-size)
+ (when (or (eq t goto-address-fontify-maximum-size)
(< (- (point-max) (point)) goto-address-fontify-maximum-size))
- (progn
(while (re-search-forward goto-address-url-regexp nil t)
(let* ((s (match-beginning 0))
(e (match-end 0))
- (this-overlay (make-overlay s e)))
+ this-overlay)
+ (when (or (not goto-address-prog-mode)
+ ;; This tests for both comment and string
+ ;; syntax.
+ (nth 8 (syntax-ppss)))
+ (setq this-overlay (make-overlay s e))
(and goto-address-fontify-p
(overlay-put this-overlay 'face goto-address-url-face))
(overlay-put this-overlay 'evaporate t)
@@ -179,12 +187,17 @@
'help-echo "mouse-2, C-c RET: follow URL")
(overlay-put this-overlay
'keymap goto-address-highlight-keymap)
- (overlay-put this-overlay 'goto-address t)))
+ (overlay-put this-overlay 'goto-address t))))
(goto-char (point-min))
(while (re-search-forward goto-address-mail-regexp nil t)
(let* ((s (match-beginning 0))
(e (match-end 0))
- (this-overlay (make-overlay s e)))
+ this-overlay)
+ (when (or (not goto-address-prog-mode)
+ ;; This tests for both comment and string
+ ;; syntax.
+ (nth 8 (syntax-ppss)))
+ (setq this-overlay (make-overlay s e))
(and goto-address-fontify-p
(overlay-put this-overlay 'face goto-address-mail-face))
(overlay-put this-overlay 'evaporate t)
@@ -197,6 +210,15 @@
'keymap goto-address-highlight-keymap)
(overlay-put this-overlay 'goto-address t))))))))
+(defun goto-address-fontify-region (start end)
+ "Fontify URLs and e-mail addresses in the given region."
+ (save-excursion
+ (save-restriction
+ (let ((beg-line (progn (goto-char start) (line-beginning-position)))
+ (end-line (progn (goto-char end) (line-end-position))))
+ (narrow-to-region beg-line end-line)
+ (goto-address-fontify)))))
+
;; code to find and goto addresses; much of this has been blatantly
;; snarfed from browse-url.el
@@ -252,6 +274,32 @@
(goto-address-fontify)))
;;;###autoload(put 'goto-address 'safe-local-eval-function t)
+;;;###autoload
+(define-minor-mode goto-address-mode
+ "Minor mode to buttonize URLs and e-mail addresses in the current buffer."
+ nil
+ ""
+ nil
+ (if goto-address-mode
+ (jit-lock-register #'goto-address-fontify-region)
+ (jit-lock-unregister #'goto-address-fontify-region)
+ (save-restriction
+ (widen)
+ (goto-address-unfontify (point-min) (point-max)))))
+
+;;;###autoload
+(define-minor-mode goto-address-prog-mode
+ "Turn on `goto-address-mode', but only in comments and strings."
+ nil
+ ""
+ nil
+ (if goto-address-prog-mode
+ (jit-lock-register #'goto-address-fontify-region)
+ (jit-lock-unregister #'goto-address-fontify-region)
+ (save-restriction
+ (widen)
+ (goto-address-unfontify (point-min) (point-max)))))
+
(provide 'goto-addr)
;; arch-tag: ca47c505-5661-425d-a471-62bc6e75cf0a
- [Emacs-diffs] Changes to emacs/lisp/net/goto-addr.el,v,
Glenn Morris <=