Mercurial > emacs
comparison lisp/net/xesam.el @ 97517:352b14f1dab0
* net/xesam.el (xesam-vendor, xesam-notify-function): New local
variables.
(xesam-mode): Extend docstring. Initialize `xesam-notify-function'.
(xesam-refresh-entry): Use `xesam-notify-function' if set. Remove
Debbugs specific code; it shall be enabled via `xesam-mode-hooks'.
(xesam-new-search): Initialize `xesam-vendor'.
author | Michael Albinus <michael.albinus@gmx.de> |
---|---|
date | Sun, 17 Aug 2008 20:02:23 +0000 |
parents | a5d0ee62856d |
children | 9fb28094a3cf |
comparison
equal
deleted
inserted
replaced
97516:a05ebaaf6031 | 97517:352b14f1dab0 |
---|---|
294 | 294 |
295 (defvar xesam-minibuffer-query-history nil | 295 (defvar xesam-minibuffer-query-history nil |
296 "Interactive query history.") | 296 "Interactive query history.") |
297 | 297 |
298 ;; Pacify byte compiler. | 298 ;; Pacify byte compiler. |
299 (defvar xesam-vendor nil) | |
300 (make-variable-buffer-local 'xesam-vendor) | |
301 (put 'xesam-vendor 'permanent-local t) | |
302 | |
299 (defvar xesam-engine nil) | 303 (defvar xesam-engine nil) |
300 (defvar xesam-search nil) | 304 (defvar xesam-search nil) |
301 (defvar xesam-type nil) | 305 (defvar xesam-type nil) |
302 (defvar xesam-query nil) | 306 (defvar xesam-query nil) |
303 (defvar xesam-xml-string nil) | 307 (defvar xesam-xml-string nil) |
304 (defvar xesam-objects nil) | 308 (defvar xesam-objects nil) |
305 (defvar xesam-current nil) | 309 (defvar xesam-current nil) |
306 (defvar xesam-count nil) | 310 (defvar xesam-count nil) |
307 (defvar xesam-to nil) | 311 (defvar xesam-to nil) |
312 (defvar xesam-notify-function nil) | |
308 (defvar xesam-refreshing nil) | 313 (defvar xesam-refreshing nil) |
309 | 314 |
310 | 315 |
311 ;;; Search engines. | 316 ;;; Search engines. |
312 | 317 |
416 (define-derived-mode xesam-mode nil "Xesam" | 421 (define-derived-mode xesam-mode nil "Xesam" |
417 "Major mode for presenting search results of a Xesam search. | 422 "Major mode for presenting search results of a Xesam search. |
418 In this mode, widgets represent the search results. | 423 In this mode, widgets represent the search results. |
419 | 424 |
420 \\{xesam-mode-map} | 425 \\{xesam-mode-map} |
421 Turning on Xesam mode runs the normal hook `xesam-mode-hook'." | 426 Turning on Xesam mode runs the normal hook `xesam-mode-hook'. It |
427 can be used to set `xesam-notify-function', which must a search | |
428 engine specific, widget :notify function to visualize xesam:url." | |
429 (set (make-local-variable 'xesam-notify-function) nil) | |
430 | |
422 ;; Keymap. | 431 ;; Keymap. |
423 (setq xesam-mode-map (copy-keymap special-mode-map)) | 432 (setq xesam-mode-map (copy-keymap special-mode-map)) |
424 (set-keymap-parent xesam-mode-map widget-keymap) | 433 (set-keymap-parent xesam-mode-map widget-keymap) |
425 (define-key xesam-mode-map "z" 'kill-this-buffer) | 434 (define-key xesam-mode-map "z" 'kill-this-buffer) |
426 | 435 |
438 (set (make-local-variable 'xesam-current) 0) | 447 (set (make-local-variable 'xesam-current) 0) |
439 ;; `xesam-count' is the number of hits reported by the search engine. | 448 ;; `xesam-count' is the number of hits reported by the search engine. |
440 (set (make-local-variable 'xesam-count) 0) | 449 (set (make-local-variable 'xesam-count) 0) |
441 ;; `xesam-to' is the upper hit number to be presented. | 450 ;; `xesam-to' is the upper hit number to be presented. |
442 (set (make-local-variable 'xesam-to) xesam-hits-per-page) | 451 (set (make-local-variable 'xesam-to) xesam-hits-per-page) |
452 ;; `xesam-notify-function' can be a search engine specific function | |
453 ;; to visualize xesam:url. It can be overwritten in `xesam-mode'. | |
454 (set (make-local-variable 'xesam-notify-function) nil) | |
443 ;; `xesam-refreshing' is an indicator, whether the buffer is just | 455 ;; `xesam-refreshing' is an indicator, whether the buffer is just |
444 ;; being updated. Needed, because `xesam-refresh-search-buffer' | 456 ;; being updated. Needed, because `xesam-refresh-search-buffer' |
445 ;; can be triggered by an event. | 457 ;; can be triggered by an event. |
446 (set (make-local-variable 'xesam-refreshing) nil) | 458 (set (make-local-variable 'xesam-refreshing) nil) |
447 ;; Mode line position returns hit counters. | 459 ;; Mode line position returns hit counters. |
558 | 570 |
559 ;; Second line: :value. | 571 ;; Second line: :value. |
560 (widget-put widget :value (widget-get widget :xesam:url)) | 572 (widget-put widget :value (widget-get widget :xesam:url)) |
561 | 573 |
562 (cond | 574 (cond |
575 ;; A search engine can set `xesam-notify-function' via | |
576 ;; `xesam-mode-hooks'. | |
577 (xesam-notify-function | |
578 (widget-put widget :notify xesam-notify-function)) | |
579 | |
563 ;; In case of HTML, we use a URL link. | 580 ;; In case of HTML, we use a URL link. |
564 ((and (widget-member widget :xesam:mimeType) | 581 ((and (widget-member widget :xesam:mimeType) |
565 (string-equal "text/html" (widget-get widget :xesam:mimeType))) | 582 (string-equal "text/html" (widget-get widget :xesam:mimeType))) |
566 (setcar widget 'url-link)) | 583 (setcar widget 'url-link)) |
567 | |
568 ;; Debbugs hits shall be displayed. | |
569 ((and (widget-member widget :xesam:mimeType) | |
570 (string-equal "application/x-debbugs" | |
571 (widget-get widget :xesam:mimeType))) | |
572 (widget-put | |
573 widget :notify | |
574 (lambda (widget &rest ignore) | |
575 (save-excursion | |
576 ;; We toggle. If there are already children, we delete them. | |
577 (if (widget-get widget :children) | |
578 (widget-children-value-delete widget) | |
579 | |
580 ;; No children. Let's display the messages. | |
581 (widget-end-of-line) | |
582 ;; Get hit data. Loop over results. | |
583 (dolist (data | |
584 ;; "GetHitData" returns a list. But we have | |
585 ;; requested just one element only. | |
586 (car | |
587 (xesam-dbus-call-method | |
588 :session (car xesam-engine) xesam-path-search | |
589 xesam-interface-search "GetHitData" xesam-search | |
590 (list (widget-get widget :debbugs:key)) | |
591 '("debbugs:key")))) | |
592 (let ((child | |
593 (widget-create-child-and-convert | |
594 ;; The result is a variant. So we must apply `car'. | |
595 widget '(link) :format "\n%h" :doc (car data)))) | |
596 ;; Add child to parent's list. Needed, in order to be | |
597 ;; able to delete it next toggle. | |
598 (widget-put | |
599 widget | |
600 :children (cons child (widget-get widget :children)))))))))) | |
601 | 584 |
602 ;; For local files, we will open the file as default action. | 585 ;; For local files, we will open the file as default action. |
603 ((string-match "file" | 586 ((string-match "file" |
604 (url-type (url-generic-parse-url | 587 (url-type (url-generic-parse-url |
605 (widget-get widget :xesam:url)))) | 588 (widget-get widget :xesam:url)))) |
766 | 749 |
767 ;; Create the search buffer. | 750 ;; Create the search buffer. |
768 (with-current-buffer | 751 (with-current-buffer |
769 (generate-new-buffer (xesam-buffer-name service search)) | 752 (generate-new-buffer (xesam-buffer-name service search)) |
770 (switch-to-buffer-other-window (current-buffer)) | 753 (switch-to-buffer-other-window (current-buffer)) |
754 ;; Inialize buffer with `xesam-mode'. `xesam-vendor' must be | |
755 ;; set before calling `xesam-mode', because we want to give the | |
756 ;; hook functions a chance to identify their search engine. | |
757 (setq xesam-vendor (xesam-get-cached-property engine "vendor.id")) | |
771 (xesam-mode) | 758 (xesam-mode) |
772 (setq xesam-engine engine | 759 (setq xesam-engine engine |
773 xesam-search search | 760 xesam-search search |
774 ;; `xesam-type', `xesam-query' and `xesam-xml-string' | 761 ;; `xesam-type', `xesam-query' and `xesam-xml-string' |
775 ;; are displayed in the header line. | 762 ;; are displayed in the header line. |
780 ;; The buffer identification shall indicate the search | 767 ;; The buffer identification shall indicate the search |
781 ;; engine. The `help-echo' property is used for debug | 768 ;; engine. The `help-echo' property is used for debug |
782 ;; information, when applicable. | 769 ;; information, when applicable. |
783 mode-line-buffer-identification | 770 mode-line-buffer-identification |
784 (if (not xesam-debug) | 771 (if (not xesam-debug) |
785 (list | 772 (list 12 (propertized-buffer-identification xesam-vendor)) |
786 12 (propertized-buffer-identification | |
787 (xesam-get-cached-property engine "vendor.id"))) | |
788 (propertize | 773 (propertize |
789 (xesam-get-cached-property engine "vendor.id") | 774 xesam-vendor |
790 'help-echo | 775 'help-echo |
791 (mapconcat | 776 (mapconcat |
792 (lambda (x) | 777 (lambda (x) |
793 (format "%s: %s" x (xesam-get-cached-property engine x))) | 778 (format "%s: %s" x (xesam-get-cached-property engine x))) |
794 '("vendor.id" "vendor.version" "vendor.display" "vendor.xesam" | 779 '("vendor.id" "vendor.version" "vendor.display" "vendor.xesam" |