# HG changeset patch # User Michael Albinus # Date 1219003343 0 # Node ID 352b14f1dab078087e3ce2e58fbc5b7e705cebfa # Parent a05ebaaf6031ff6c0f7e6db6c55fe4fe031b7612 * 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'. diff -r a05ebaaf6031 -r 352b14f1dab0 lisp/net/xesam.el --- a/lisp/net/xesam.el Sun Aug 17 15:12:59 2008 +0000 +++ b/lisp/net/xesam.el Sun Aug 17 20:02:23 2008 +0000 @@ -296,6 +296,10 @@ "Interactive query history.") ;; Pacify byte compiler. +(defvar xesam-vendor nil) +(make-variable-buffer-local 'xesam-vendor) +(put 'xesam-vendor 'permanent-local t) + (defvar xesam-engine nil) (defvar xesam-search nil) (defvar xesam-type nil) @@ -305,6 +309,7 @@ (defvar xesam-current nil) (defvar xesam-count nil) (defvar xesam-to nil) +(defvar xesam-notify-function nil) (defvar xesam-refreshing nil) @@ -418,7 +423,11 @@ In this mode, widgets represent the search results. \\{xesam-mode-map} -Turning on Xesam mode runs the normal hook `xesam-mode-hook'." +Turning on Xesam mode runs the normal hook `xesam-mode-hook'. It +can be used to set `xesam-notify-function', which must a search +engine specific, widget :notify function to visualize xesam:url." + (set (make-local-variable 'xesam-notify-function) nil) + ;; Keymap. (setq xesam-mode-map (copy-keymap special-mode-map)) (set-keymap-parent xesam-mode-map widget-keymap) @@ -440,6 +449,9 @@ (set (make-local-variable 'xesam-count) 0) ;; `xesam-to' is the upper hit number to be presented. (set (make-local-variable 'xesam-to) xesam-hits-per-page) + ;; `xesam-notify-function' can be a search engine specific function + ;; to visualize xesam:url. It can be overwritten in `xesam-mode'. + (set (make-local-variable 'xesam-notify-function) nil) ;; `xesam-refreshing' is an indicator, whether the buffer is just ;; being updated. Needed, because `xesam-refresh-search-buffer' ;; can be triggered by an event. @@ -560,45 +572,16 @@ (widget-put widget :value (widget-get widget :xesam:url)) (cond + ;; A search engine can set `xesam-notify-function' via + ;; `xesam-mode-hooks'. + (xesam-notify-function + (widget-put widget :notify xesam-notify-function)) + ;; In case of HTML, we use a URL link. ((and (widget-member widget :xesam:mimeType) (string-equal "text/html" (widget-get widget :xesam:mimeType))) (setcar widget 'url-link)) - ;; Debbugs hits shall be displayed. - ((and (widget-member widget :xesam:mimeType) - (string-equal "application/x-debbugs" - (widget-get widget :xesam:mimeType))) - (widget-put - widget :notify - (lambda (widget &rest ignore) - (save-excursion - ;; We toggle. If there are already children, we delete them. - (if (widget-get widget :children) - (widget-children-value-delete widget) - - ;; No children. Let's display the messages. - (widget-end-of-line) - ;; Get hit data. Loop over results. - (dolist (data - ;; "GetHitData" returns a list. But we have - ;; requested just one element only. - (car - (xesam-dbus-call-method - :session (car xesam-engine) xesam-path-search - xesam-interface-search "GetHitData" xesam-search - (list (widget-get widget :debbugs:key)) - '("debbugs:key")))) - (let ((child - (widget-create-child-and-convert - ;; The result is a variant. So we must apply `car'. - widget '(link) :format "\n%h" :doc (car data)))) - ;; Add child to parent's list. Needed, in order to be - ;; able to delete it next toggle. - (widget-put - widget - :children (cons child (widget-get widget :children)))))))))) - ;; For local files, we will open the file as default action. ((string-match "file" (url-type (url-generic-parse-url @@ -768,6 +751,10 @@ (with-current-buffer (generate-new-buffer (xesam-buffer-name service search)) (switch-to-buffer-other-window (current-buffer)) + ;; Inialize buffer with `xesam-mode'. `xesam-vendor' must be + ;; set before calling `xesam-mode', because we want to give the + ;; hook functions a chance to identify their search engine. + (setq xesam-vendor (xesam-get-cached-property engine "vendor.id")) (xesam-mode) (setq xesam-engine engine xesam-search search @@ -782,11 +769,9 @@ ;; information, when applicable. mode-line-buffer-identification (if (not xesam-debug) - (list - 12 (propertized-buffer-identification - (xesam-get-cached-property engine "vendor.id"))) + (list 12 (propertized-buffer-identification xesam-vendor)) (propertize - (xesam-get-cached-property engine "vendor.id") + xesam-vendor 'help-echo (mapconcat (lambda (x)