Mercurial > emacs
comparison lisp/net/xesam.el @ 97572:9fb28094a3cf
* net/xesam.el (xesam-highlight-string): Precise doc string.
(xesam-highlight-buffer): New defun.
(xesam-refresh-entry): Use it. Better check for sourceModified.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Wed, 20 Aug 2008 20:08:16 +0000 |
parents | 352b14f1dab0 |
children | 1f7e10e015fd |
comparison
equal
deleted
inserted
replaced
97571:c532aa80972d | 97572:9fb28094a3cf |
---|---|
492 SERVICE is the D-Bus unique service name of the Xesam search engine. | 492 SERVICE is the D-Bus unique service name of the Xesam search engine. |
493 SEARCH is the search identification in that engine. Both must be strings." | 493 SEARCH is the search identification in that engine. Both must be strings." |
494 (format "*%s/%s*" service search)) | 494 (format "*%s/%s*" service search)) |
495 | 495 |
496 (defun xesam-highlight-string (string) | 496 (defun xesam-highlight-string (string) |
497 "Highlight text enclosed by <b> and </b>." | 497 "Highlight text enclosed by <b> and </b>. |
498 Return propertized STRING." | |
498 (while (string-match "\\(.*\\)\\(<b>\\)\\(.*\\)\\(</b>\\)\\(.*\\)" string) | 499 (while (string-match "\\(.*\\)\\(<b>\\)\\(.*\\)\\(</b>\\)\\(.*\\)" string) |
499 (setq string | 500 (setq string |
500 (format | 501 (format |
501 "%s%s%s" | 502 "%s%s%s" |
502 (match-string 1 string) | 503 (match-string 1 string) |
503 (propertize (match-string 3 string) 'face 'xesam-highlight) | 504 (propertize (match-string 3 string) 'face 'xesam-highlight) |
504 (match-string 5 string)))) | 505 (match-string 5 string)))) |
505 string) | 506 string) |
507 | |
508 (defun xesam-highlight-buffer (regexp &optional buffer) | |
509 "Highlight text matching REGEXP in BUFFER. | |
510 If BUFFER is nil, use the current buffer" | |
511 (with-current-buffer (or buffer (current-buffer)) | |
512 (save-excursion | |
513 (let ((case-fold-search t)) | |
514 (goto-char (point-min)) | |
515 (while (re-search-forward regexp nil t) | |
516 (overlay-put | |
517 (make-overlay | |
518 (match-beginning 0) (match-end 0)) 'face 'xesam-highlight)))))) | |
506 | 519 |
507 (defun xesam-refresh-entry (engine entry) | 520 (defun xesam-refresh-entry (engine entry) |
508 "Refreshes one entry in the search buffer." | 521 "Refreshes one entry in the search buffer." |
509 (let* ((result (nth (1- xesam-current) xesam-objects)) | 522 (let* ((result (nth (1- xesam-current) xesam-objects)) |
510 widget) | 523 widget) |
555 (when (widget-member widget :tag) | 568 (when (widget-member widget :tag) |
556 (widget-put | 569 (widget-put |
557 widget :tag (xesam-highlight-string (widget-get widget :tag)))) | 570 widget :tag (xesam-highlight-string (widget-get widget :tag)))) |
558 | 571 |
559 ;; Last Modified. | 572 ;; Last Modified. |
560 (when (widget-member widget :xesam:sourceModified) | 573 (when (and (widget-member widget :xesam:sourceModified) |
574 (not | |
575 (zerop | |
576 (string-to-number (widget-get widget :xesam:sourceModified))))) | |
561 (widget-put | 577 (widget-put |
562 widget :tag | 578 widget :tag |
563 (format | 579 (format |
564 "%s\nLast Modified: %s" | 580 "%s\nLast Modified: %s" |
565 (or (widget-get widget :tag) "") | 581 (or (widget-get widget :tag) "") |
587 (url-type (url-generic-parse-url | 603 (url-type (url-generic-parse-url |
588 (widget-get widget :xesam:url)))) | 604 (widget-get widget :xesam:url)))) |
589 (widget-put | 605 (widget-put |
590 widget :notify | 606 widget :notify |
591 (lambda (widget &rest ignore) | 607 (lambda (widget &rest ignore) |
592 (find-file | 608 (let ((query xesam-query)) |
593 (url-filename (url-generic-parse-url (widget-value widget)))))) | 609 (find-file |
610 (url-filename (url-generic-parse-url (widget-value widget)))) | |
611 (xesam-highlight-buffer (regexp-opt (split-string query nil t)))))) | |
594 (widget-put | 612 (widget-put |
595 widget :value | 613 widget :value |
596 (url-filename (url-generic-parse-url (widget-get widget :xesam:url)))))) | 614 (url-filename (url-generic-parse-url (widget-get widget :xesam:url)))))) |
597 | 615 |
598 ;; Third line: :doc. | 616 ;; Third line: :doc. |
835 | 853 |
836 (provide 'xesam) | 854 (provide 'xesam) |
837 | 855 |
838 ;;; TODO: | 856 ;;; TODO: |
839 | 857 |
858 ;; * Buffer highlighting needs better analysis of query string. | |
840 ;; * Accept input while retrieving prefetched hits. `run-at-time'? | 859 ;; * Accept input while retrieving prefetched hits. `run-at-time'? |
841 ;; * With prefix, let's choose search engine. | 860 ;; * With prefix, let's choose search engine. |
842 ;; * Minibuffer completion for user queries. | 861 ;; * Minibuffer completion for user queries. |
843 ;; * `revert-buffer-function' implementation. | 862 ;; * `revert-buffer-function' implementation. |
844 ;; | 863 ;; |