]> git.eshelyaron.com Git - emacs.git/commitdiff
* net/xesam.el (xesam-highlight-string): Precise doc string.
authorMichael Albinus <michael.albinus@gmx.de>
Wed, 20 Aug 2008 20:08:50 +0000 (20:08 +0000)
committerMichael Albinus <michael.albinus@gmx.de>
Wed, 20 Aug 2008 20:08:50 +0000 (20:08 +0000)
(xesam-highlight-buffer): New defun.
(xesam-refresh-entry): Use it.  Better check for sourceModified.

lisp/ChangeLog
lisp/net/xesam.el

index e696e85181b2e091ee9a4a2ba80b35bce2d45e54..5edc571cca99750b6646f2ce53c7e24999cb4de6 100644 (file)
@@ -1,3 +1,9 @@
+2008-08-20  Michael Albinus  <michael.albinus@gmx.de>
+
+       * net/xesam.el (xesam-highlight-string): Precise doc string.
+       (xesam-highlight-buffer): New defun.
+       (xesam-refresh-entry): Use it.  Better check for sourceModified.
+
 2008-08-19  Chong Yidong  <cyd@stupidchicken.com>
 
        * edmacro.el (edmacro-parse-keys): Catch events with spaces in
index dda12607d9adecdff36c0a68cbd2f8d67365f63d..a7b1cca8aa79e634521571f239417f884633b6b8 100644 (file)
@@ -494,7 +494,8 @@ SEARCH is the search identification in that engine.  Both must be strings."
   (format "*%s/%s*" service search))
 
 (defun xesam-highlight-string (string)
-  "Highlight text enclosed by <b> and </b>."
+  "Highlight text enclosed by <b> and </b>.
+Return propertized STRING."
   (while (string-match "\\(.*\\)\\(<b>\\)\\(.*\\)\\(</b>\\)\\(.*\\)" string)
     (setq string
          (format
@@ -504,6 +505,18 @@ SEARCH is the search identification in that engine.  Both must be strings."
           (match-string 5 string))))
   string)
 
+(defun xesam-highlight-buffer (regexp &optional buffer)
+  "Highlight text matching REGEXP in BUFFER.
+If BUFFER is nil, use the current buffer"
+  (with-current-buffer (or buffer (current-buffer))
+    (save-excursion
+      (let ((case-fold-search t))
+       (goto-char (point-min))
+       (while (re-search-forward regexp nil t)
+         (overlay-put
+          (make-overlay
+           (match-beginning 0) (match-end 0)) 'face 'xesam-highlight))))))
+
 (defun xesam-refresh-entry (engine entry)
   "Refreshes one entry in the search buffer."
   (let* ((result (nth (1- xesam-current) xesam-objects))
@@ -557,7 +570,10 @@ SEARCH is the search identification in that engine.  Both must be strings."
        widget :tag (xesam-highlight-string (widget-get widget :tag))))
 
     ;; Last Modified.
-    (when (widget-member widget :xesam:sourceModified)
+    (when (and (widget-member widget :xesam:sourceModified)
+              (not
+               (zerop
+                (string-to-number (widget-get widget :xesam:sourceModified)))))
       (widget-put
        widget :tag
        (format
@@ -589,8 +605,10 @@ SEARCH is the search identification in that engine.  Both must be strings."
       (widget-put
        widget :notify
        (lambda (widget &rest ignore)
-        (find-file
-         (url-filename (url-generic-parse-url (widget-value widget))))))
+        (let ((query xesam-query))
+          (find-file
+           (url-filename (url-generic-parse-url (widget-value widget))))
+          (xesam-highlight-buffer (regexp-opt (split-string query nil t))))))
       (widget-put
        widget :value
        (url-filename (url-generic-parse-url (widget-get widget :xesam:url))))))
@@ -837,6 +855,7 @@ Example:
 
 ;;; TODO:
 
+;; * Buffer highlighting needs better analysis of query string.
 ;; * Accept input while retrieving prefetched hits. `run-at-time'?
 ;; * With prefix, let's choose search engine.
 ;; * Minibuffer completion for user queries.