diff options
| author | Michael Albinus | 2008-07-31 19:30:14 +0000 |
|---|---|---|
| committer | Michael Albinus | 2008-07-31 19:30:14 +0000 |
| commit | 5dd3307831450a85e96175c099f294199125d2ff (patch) | |
| tree | 8c2b6d7f99915645252574fc503620e2e405b752 | |
| parent | 6c5f631991718f5db15d34804384f85c6738e04b (diff) | |
| download | emacs-5dd3307831450a85e96175c099f294199125d2ff.tar.gz emacs-5dd3307831450a85e96175c099f294199125d2ff.zip | |
* net/xesam.el (xesam-type, xesam-query, xesam-xml-string): New
defvar.
(xesam-mode): Rework implementation.
(xesam-new-search): Additional parameter TYPE.
(xesam-search): Adapt call of `xesam-new-search'.
| -rw-r--r-- | lisp/net/xesam.el | 124 |
1 files changed, 81 insertions, 43 deletions
diff --git a/lisp/net/xesam.el b/lisp/net/xesam.el index b508f9f497b..53581d6b6f7 100644 --- a/lisp/net/xesam.el +++ b/lisp/net/xesam.el | |||
| @@ -28,7 +28,7 @@ | |||
| 28 | ;; | 28 | ;; |
| 29 | ;; xesam-glib 0.3.4, xesam-tools 0.6.1 | 29 | ;; xesam-glib 0.3.4, xesam-tools 0.6.1 |
| 30 | ;; beagle 0.3.7, beagle-xesam 0.2 | 30 | ;; beagle 0.3.7, beagle-xesam 0.2 |
| 31 | ;; strigi 0.5.10 | 31 | ;; strigi 0.5.11 |
| 32 | 32 | ||
| 33 | ;; The precondition for this package is a D-Bus aware Emacs. This is | 33 | ;; The precondition for this package is a D-Bus aware Emacs. This is |
| 34 | ;; configured per default, when Emacs is built on a machine running | 34 | ;; configured per default, when Emacs is built on a machine running |
| @@ -281,6 +281,9 @@ from VALUE, depending on what the search engine accepts." | |||
| 281 | ;; Pacify byte compiler. | 281 | ;; Pacify byte compiler. |
| 282 | (defvar xesam-engine nil) | 282 | (defvar xesam-engine nil) |
| 283 | (defvar xesam-search nil) | 283 | (defvar xesam-search nil) |
| 284 | (defvar xesam-type nil) | ||
| 285 | (defvar xesam-query nil) | ||
| 286 | (defvar xesam-xml-string nil) | ||
| 284 | (defvar xesam-current nil) | 287 | (defvar xesam-current nil) |
| 285 | (defvar xesam-count nil) | 288 | (defvar xesam-count nil) |
| 286 | (defvar xesam-to nil) | 289 | (defvar xesam-to nil) |
| @@ -368,42 +371,62 @@ If there is no registered search engine at all, the function returns `nil'." | |||
| 368 | 371 | ||
| 369 | ;;; Search buffers. | 372 | ;;; Search buffers. |
| 370 | 373 | ||
| 371 | (define-derived-mode xesam-mode special-mode "Xesam" | 374 | (define-derived-mode xesam-mode nil "Xesam" |
| 372 | "Major mode for presenting search results of a Xesam search. | 375 | "Major mode for presenting search results of a Xesam search. |
| 373 | In this mode, widgets represent the search results. | 376 | In this mode, widgets represent the search results. |
| 374 | 377 | ||
| 375 | \\{xesam-mode-map} | 378 | \\{xesam-mode-map} |
| 376 | Turning on Xesam mode runs the normal hook `xesam-mode-hook'." | 379 | Turning on Xesam mode runs the normal hook `xesam-mode-hook'." |
| 380 | ;; Keymap. | ||
| 381 | (setq xesam-mode-map (copy-keymap special-mode-map)) | ||
| 382 | (set-keymap-parent xesam-mode-map widget-keymap) | ||
| 383 | (define-key xesam-mode-map "z" 'kill-this-buffer) | ||
| 384 | |||
| 385 | ;; Maybe we implement something useful, later on. | ||
| 386 | (set (make-local-variable 'revert-buffer-function) 'ignore) | ||
| 387 | ;; `xesam-engine', `xesam-search', `xesam-type', `xesam-query', and | ||
| 388 | ;; `xesam-xml-string' will be set in `xesam-new-search'. | ||
| 389 | (set (make-local-variable 'xesam-engine) nil) | ||
| 390 | (set (make-local-variable 'xesam-search) nil) | ||
| 391 | (set (make-local-variable 'xesam-type) "") | ||
| 392 | (set (make-local-variable 'xesam-query) "") | ||
| 393 | (set (make-local-variable 'xesam-xml-string) "") | ||
| 394 | ;; `xesam-current' is the last hit put into the search buffer, | ||
| 395 | (set (make-local-variable 'xesam-current) 0) | ||
| 396 | ;; `xesam-count' is the number of hits reported by the search engine. | ||
| 397 | (set (make-local-variable 'xesam-count) 0) | ||
| 398 | ;; `xesam-to' is the upper hit number to be presented. | ||
| 399 | (set (make-local-variable 'xesam-to) xesam-hits-per-page) | ||
| 400 | ;; `xesam-refreshing' is an indicator, whether the buffer is just | ||
| 401 | ;; being updated. Needed, because `xesam-refresh-search-buffer' | ||
| 402 | ;; can be triggered by an event. | ||
| 403 | (set (make-local-variable 'xesam-refreshing) nil) | ||
| 404 | ;; Mode line position returns hit counters. | ||
| 405 | (set (make-local-variable 'mode-line-position) | ||
| 406 | (list '(-3 "%p%") | ||
| 407 | '(10 (:eval (format " (%d/%d)" xesam-current xesam-count))))) | ||
| 408 | ;; Header line contains the query string. | ||
| 409 | (set (make-local-variable 'header-line-format) | ||
| 410 | (list '(20 | ||
| 411 | (:eval | ||
| 412 | (list "Type: " | ||
| 413 | (propertize xesam-type 'face 'font-lock-type-face)))) | ||
| 414 | '(10 | ||
| 415 | (:eval | ||
| 416 | (list " Query: " | ||
| 417 | (propertize | ||
| 418 | xesam-query | ||
| 419 | 'face 'font-lock-type-face | ||
| 420 | 'help-echo xesam-xml-string)))))) | ||
| 421 | |||
| 377 | (when (not (interactive-p)) | 422 | (when (not (interactive-p)) |
| 378 | ;; Initialize buffer. | 423 | ;; Initialize buffer. |
| 379 | (setq buffer-read-only t) | 424 | (setq buffer-read-only t) |
| 380 | (let ((inhibit-read-only t)) | 425 | (let ((inhibit-read-only t)) |
| 381 | (erase-buffer)) | 426 | (erase-buffer)))) |
| 382 | 427 | ||
| 383 | ;; Keymap. | 428 | ;; It doesn't make sense to call it interactively. |
| 384 | (setq xesam-mode-map (copy-keymap special-mode-map)) | 429 | (put 'xesam-mode 'disabled t) |
| 385 | (set-keymap-parent xesam-mode-map widget-keymap) | ||
| 386 | (define-key xesam-mode-map "z" 'kill-this-buffer) | ||
| 387 | |||
| 388 | ;; Maybe we implement something useful, later on. | ||
| 389 | (set (make-local-variable 'revert-buffer-function) 'ignore) | ||
| 390 | ;; `xesam-engine' and `xesam-search' will be set in `xesam-new-search'. | ||
| 391 | (set (make-local-variable 'xesam-engine) nil) | ||
| 392 | (set (make-local-variable 'xesam-search) nil) | ||
| 393 | ;; `xesam-current' is the last hit put into the search buffer, | ||
| 394 | (set (make-local-variable 'xesam-current) 0) | ||
| 395 | ;; `xesam-count' is the number of hits reported by the search engine. | ||
| 396 | (set (make-local-variable 'xesam-count) 0) | ||
| 397 | ;; `xesam-to' is the upper hit number to be presented. | ||
| 398 | (set (make-local-variable 'xesam-to) xesam-hits-per-page) | ||
| 399 | ;; `xesam-refreshing' is an indicator, whether the buffer is just | ||
| 400 | ;; being updated. Needed, because `xesam-refresh-search-buffer' | ||
| 401 | ;; can be triggered by an event. | ||
| 402 | (set (make-local-variable 'xesam-refreshing) nil) | ||
| 403 | ;; Mode line position returns hit counters. | ||
| 404 | (set (make-local-variable 'mode-line-position) | ||
| 405 | (list '(-3 "%p%") | ||
| 406 | '(10 (:eval (format " (%d/%d)" xesam-current xesam-count))))))) | ||
| 407 | 430 | ||
| 408 | (defun xesam-buffer-name (service search) | 431 | (defun xesam-buffer-name (service search) |
| 409 | "Return the buffer name where to present search results. | 432 | "Return the buffer name where to present search results. |
| @@ -583,16 +606,21 @@ SEARCH is the search identification in that engine. Both must be strings." | |||
| 583 | (propertize " Done" 'face 'font-lock-type-face)) | 606 | (propertize " Done" 'face 'font-lock-type-face)) |
| 584 | (force-mode-line-update))))))) | 607 | (force-mode-line-update))))))) |
| 585 | 608 | ||
| 586 | (defun xesam-new-search (engine query) | 609 | (defun xesam-new-search (engine type query) |
| 587 | "Create a new search session. | 610 | "Create a new search session. |
| 588 | ENGINE identifies the search engine. QUERY is a string in the | 611 | ENGINE identifies the search engine. TYPE is the query type, it |
| 589 | Xesam user query language. A string, identifying the search, is | 612 | can be either `fulltext-query', or `user-query'. QUERY is a |
| 590 | returned." | 613 | string in the Xesam query language. A string, identifying the |
| 614 | search, is returned." | ||
| 591 | (let* ((service (car engine)) | 615 | (let* ((service (car engine)) |
| 592 | (session (cdr engine)) | 616 | (session (cdr engine)) |
| 617 | (xml-string | ||
| 618 | (format | ||
| 619 | (if (eq type 'user-query) xesam-user-query xesam-fulltext-query) | ||
| 620 | query)) | ||
| 593 | (search (dbus-call-method | 621 | (search (dbus-call-method |
| 594 | :session service xesam-path-search | 622 | :session service xesam-path-search |
| 595 | xesam-interface-search "NewSearch" session query))) | 623 | xesam-interface-search "NewSearch" session xml-string))) |
| 596 | 624 | ||
| 597 | ;; Let us notify for relevant signals. We ignore "HitsRemoved", | 625 | ;; Let us notify for relevant signals. We ignore "HitsRemoved", |
| 598 | ;; "HitsModified" and "StateChanged"; there is nothing to do for | 626 | ;; "HitsModified" and "StateChanged"; there is nothing to do for |
| @@ -605,9 +633,6 @@ returned." | |||
| 605 | :session service xesam-path-search | 633 | :session service xesam-path-search |
| 606 | xesam-interface-search "SearchDone" | 634 | xesam-interface-search "SearchDone" |
| 607 | 'xesam-signal-handler search) | 635 | 'xesam-signal-handler search) |
| 608 | (dbus-call-method | ||
| 609 | :session (car engine) xesam-path-search | ||
| 610 | xesam-interface-search "StartSearch" search) | ||
| 611 | 636 | ||
| 612 | ;; Create the search buffer. | 637 | ;; Create the search buffer. |
| 613 | (with-current-buffer | 638 | (with-current-buffer |
| @@ -616,6 +641,11 @@ returned." | |||
| 616 | (xesam-mode) | 641 | (xesam-mode) |
| 617 | (setq xesam-engine engine | 642 | (setq xesam-engine engine |
| 618 | xesam-search search | 643 | xesam-search search |
| 644 | ;; `xesam-type', `xesam-query' and `xesam-xml-string' | ||
| 645 | ;; are displayed in the header line. | ||
| 646 | xesam-type (symbol-name type) | ||
| 647 | xesam-query query | ||
| 648 | xesam-xml-string xml-string | ||
| 619 | ;; The buffer identification shall indicate the search | 649 | ;; The buffer identification shall indicate the search |
| 620 | ;; engine. The `help-echo' property is used for debug | 650 | ;; engine. The `help-echo' property is used for debug |
| 621 | ;; information, when applicable. | 651 | ;; information, when applicable. |
| @@ -632,7 +662,13 @@ returned." | |||
| 632 | "vendor.ontology.fields" "vendor.ontology.contents" | 662 | "vendor.ontology.fields" "vendor.ontology.contents" |
| 633 | "vendor.ontology.sources" "vendor.extensions" | 663 | "vendor.ontology.sources" "vendor.extensions" |
| 634 | "vendor.ontologies" "vendor.maxhits") | 664 | "vendor.ontologies" "vendor.maxhits") |
| 635 | "\n"))))) | 665 | "\n")))) |
| 666 | (force-mode-line-update)) | ||
| 667 | |||
| 668 | ;; Start the search. | ||
| 669 | (dbus-call-method | ||
| 670 | :session (car engine) xesam-path-search | ||
| 671 | xesam-interface-search "StartSearch" search) | ||
| 636 | 672 | ||
| 637 | ;; Return search id. | 673 | ;; Return search id. |
| 638 | search)) | 674 | search)) |
| @@ -670,18 +706,20 @@ Example: | |||
| 670 | "Enter search string: " nil nil nil | 706 | "Enter search string: " nil nil nil |
| 671 | 'xesam-minibuffer-query-history))))) | 707 | 'xesam-minibuffer-query-history))))) |
| 672 | 708 | ||
| 673 | (if (and engine (stringp query)) | 709 | (if (null engine) |
| 674 | (if (eq xesam-query-type 'user-query) | 710 | (message "No search engine running") |
| 675 | (xesam-new-search engine (format xesam-user-query query)) | 711 | (if (zerop (length query)) |
| 676 | (xesam-new-search engine (format xesam-fulltext-query query))) | 712 | (message "No query applied") |
| 677 | ;; There might be no search engine available ATM. | 713 | (xesam-new-search engine xesam-query-type query)))) |
| 678 | (message "No query applied"))) | ||
| 679 | 714 | ||
| 680 | (provide 'xesam) | 715 | (provide 'xesam) |
| 681 | 716 | ||
| 682 | ;;; TODO: | 717 | ;;; TODO: |
| 683 | 718 | ||
| 719 | ;; * Solve error, that xesam-mode does not work the very first time. | ||
| 684 | ;; * Retrieve several results at once. | 720 | ;; * Retrieve several results at once. |
| 721 | ;; * Retrieve hits for the next page in advance. | ||
| 722 | ;; * With prefix, let's chosse search engine. | ||
| 685 | ;; * Improve mode-line handling. Show search string etc. | 723 | ;; * Improve mode-line handling. Show search string etc. |
| 686 | ;; * Minibuffer completion for user queries. | 724 | ;; * Minibuffer completion for user queries. |
| 687 | ;; * `revert-buffer-function' implementation. | 725 | ;; * `revert-buffer-function' implementation. |