X-Git-Url: https://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-url.el;h=c502328baa6263ffbf42ce029eba8c05a41414f7;hp=449e27bc6be4c4580155f1e77bcf2b9aa7d4d124;hb=698bfd45a6f1dacb42e134b3b98fa909ca2e0c88;hpb=21290cb15e3b73ec3d7528885a5c2bad990d4b8d diff --git a/lisp/riece-url.el b/lisp/riece-url.el index 449e27b..c502328 100644 --- a/lisp/riece-url.el +++ b/lisp/riece-url.el @@ -44,21 +44,65 @@ :group 'riece-url :type 'regexp) +(defcustom riece-url-regexp-alist nil + "An alist mapping regexp to URL. +For example: + (setq riece-url-regexp-alist + '((\"\\\\bBug#\\\\([0-9]+\\\\)\\\\b\" . + \"http://bugs.debian.org/\\\\1\"))) + +This maps a string \"Bug#12345\" to a URL +\"http://bugs.debian.org/12345\"." + :type 'alist + :group 'riece-url) + (defvar riece-urls nil "A list of URL which appears in Riece buffers.") +(defvar riece-url-enabled nil) + +(defconst riece-url-description + "Collect URL in IRC buffers") + (autoload 'widget-convert-button "wid-edit") +(defun riece-url-replace-match (string) + (let ((match-data (match-data)) + (index 0) + number + replacement) + (while (string-match "\\\\[&1-9\\\\]" string index) + (if (eq (aref string (1+ (match-beginning 0))) ?&) + (setq number 0) + (unless (eq (aref string (1+ (match-beginning 0))) ?\\) + (setq number (string-to-number (substring (match-string 0 string) + 1))))) + (if number + (setq replacement + (buffer-substring (nth (* number 2) match-data) + (nth (1+ (* number 2)) match-data))) + (setq replacement "\\")) + (setq string (concat (substring string 0 (match-beginning 0)) + replacement + (substring string (match-end 0))) + index (+ index (length replacement)))) + string)) + (defun riece-url-scan-region (start end) - (save-excursion - (goto-char start) - (while (re-search-forward riece-url-regexp end t) - (let ((url (match-string 0))) - (if (memq 'riece-highlight riece-addons) - (widget-convert-button - 'url-link (match-beginning 0) (match-end 0) url)) - (unless (member url riece-urls) - (setq riece-urls (cons url riece-urls))))))) + (let ((alist (cons (cons riece-url-regexp "\\&") + riece-url-regexp-alist))) + (while alist + (save-excursion + (goto-char start) + (while (re-search-forward (car (car alist)) end t) + (let ((url (save-match-data + (riece-url-replace-match (cdr (car alist)))))) + (if (memq 'riece-highlight riece-addons) + (widget-convert-button + 'url-link (match-beginning 0) (match-end 0) url)) + (unless (member url riece-urls) + (setq riece-urls (cons url riece-urls)))))) + (setq alist (cdr alist))))) (defun riece-command-browse-url (&optional url) (interactive @@ -69,7 +113,7 @@ (mapcar (lambda (url) (vector url (list 'browse-url url))) riece-urls)) - + (defvar riece-dialogue-mode-map) (defun riece-url-requires () @@ -80,7 +124,6 @@ (defun riece-url-insinuate () (add-hook 'riece-after-insert-functions 'riece-url-scan-region) - (define-key riece-dialogue-mode-map "U" 'riece-command-browse-url) (if (memq 'riece-menu riece-addons) (add-hook 'riece-command-mode-hook (lambda () @@ -89,6 +132,14 @@ '("Open URL..." :filter riece-url-create-menu))) t))) +(defun riece-url-enable () + (define-key riece-dialogue-mode-map "U" 'riece-command-browse-url) + (setq riece-url-enabled t)) + +(defun riece-url-disable () + (define-key riece-dialogue-mode-map "U" nil) + (setq riece-url-enabled nil)) + (provide 'riece-url) ;;; riece-url.el ends here