Search now working.
[elpher.git] / elopher.el
index b40007f..959bc68 100644 (file)
@@ -56,6 +56,8 @@
   "Face used for info records.")
 (defcustom elopher-image-face '(foreground-color . "green")
   "Face used for image records.")
+(defcustom elopher-search-face '(foreground-color . "orange")
+  "Face used for image records.")
 (defcustom elopher-unknown-face '(foreground-color . "red")
   "Face used for unknown record types.")
 
                               'action #'elopher-click-link
                               'follow-link t
                               'help-echo help-string))
-      (?p (elopher-insert-margin "im")
+      ((or ?g ?p ?I) (elopher-insert-margin "im")
           (insert-text-button display-string
                               'face elopher-image-face
                               'elopher-node (elopher-make-node elopher-current-node
                               'action #'elopher-click-link
                               'follow-link t
                               'help-echo help-string))
+      (?7 (elopher-insert-margin "?")
+          (insert-text-button display-string
+                              'face elopher-search-face
+                              'elopher-node (elopher-make-node elopher-current-node
+                                                              address
+                                                              #'elopher-get-search-node)
+                              'action #'elopher-click-link
+                              'follow-link t
+                              'help-echo help-string))
       (?.) ; Occurs at end of index, can safely ignore.
       (tp (elopher-insert-margin (concat (char-to-string tp) "?"))
           (insert (propertize display-string
 (defun elopher-get-selector (address after &optional binary)
   "Retrieve selector specified by ADDRESS and store it in the
 string elopher-selector-string, then execute AFTER as the
-sentinal function.
-
-If BINARY is non-nil, the selector is expected to return a
-binary result, otherwise otherwise utf-8 is assumed."
+sentinal function."
   (setq elopher-selector-string "")
   (let ((p (get-process "elopher-process")))
     (if p (delete-process p)))
@@ -230,9 +238,6 @@ binary result, otherwise otherwise utf-8 is assumed."
    :name "elopher-process"
    :host (elopher-address-host address)
    :service (elopher-address-port address)
-   :coding (if binary
-               '(utf-8 . binary)
-             '(utf-8 . utf-8))
    :filter (lambda (proc string)
              (setq elopher-selector-string (concat elopher-selector-string string)))
    :sentinel after)
@@ -250,13 +255,17 @@ binary result, otherwise otherwise utf-8 is assumed."
             (insert content))
           (elopher-restore-pos))
       (if address
-          (elopher-get-selector address
-                                (lambda (proc event)
-                                  (let ((inhibit-read-only t))
-                                    (elopher-insert-index elopher-selector-string))
-                                  (elopher-restore-pos)
-                                  (elopher-set-node-content elopher-current-node
-                                                            (buffer-string))))
+          (progn
+            (let ((inhibit-read-only t))
+              (insert "LOADING DIRECTORY..."))
+            (elopher-get-selector address
+                                  (lambda (proc event)
+                                    (let ((inhibit-read-only t))
+                                      (erase-buffer)
+                                      (elopher-insert-index elopher-selector-string))
+                                    (elopher-restore-pos)
+                                    (elopher-set-node-content elopher-current-node
+                                                              (buffer-string)))))
         (progn
           (let ((inhibit-read-only t))
             (elopher-insert-index elopher-start-index))
@@ -277,13 +286,17 @@ binary result, otherwise otherwise utf-8 is assumed."
           (let ((inhibit-read-only t))
             (insert content))
           (elopher-restore-pos))
-      (elopher-get-selector address
-                            (lambda (proc event)
-                              (let ((inhibit-read-only t))
-                                (insert (elopher-strip-CRs elopher-selector-string)))
-                              (elopher-restore-pos)
-                              (elopher-set-node-content elopher-current-node
-                                                        (buffer-string)))))))
+      (progn
+        (let ((inhibit-read-only t))
+          (insert "LOADING TEXT..."))
+        (elopher-get-selector address
+                              (lambda (proc event)
+                                (let ((inhibit-read-only t))
+                                  (erase-buffer)
+                                  (insert (elopher-strip-CRs elopher-selector-string)))
+                                (elopher-restore-pos)
+                                (elopher-set-node-content elopher-current-node
+                                                          (buffer-string))))))))
 
 ;; Image retrieval
 
@@ -294,17 +307,50 @@ binary result, otherwise otherwise utf-8 is assumed."
         (progn
           (let ((inhibit-read-only t))
             (insert-image content))
+          (setq cursor-type nil)
           (elopher-restore-pos))
-      (elopher-get-selector address
-                            (lambda (proc event)
-                              (let ((image (create-image elopher-selector-string))
-                                    (inhibit-read-only t))
-                                (insert-image image)
-                                (elopher-restore-pos)
-                                (elopher-set-node-content image)))
-                            'binary))))
-        
-  
+      (progn
+        (let ((inhibit-read-only t))
+          (insert "LOADING IMAGE..."))
+        (elopher-get-selector address
+                              (lambda (proc event)
+                                (let ((image (create-image
+                                              (string-as-unibyte elopher-selector-string)
+                                              nil t))
+                                      (inhibit-read-only t))
+                                  (erase-buffer)
+                                  (insert-image image)
+                                  (setq cursor-type nil)
+                                  (elopher-restore-pos)
+                                  (elopher-set-node-content elopher-current-node image))))))))
+
+;; Search retrieval
+
+(defun elopher-get-search-node ()
+  (let* ((content (elopher-node-content elopher-current-node))
+         (address (elopher-node-address elopher-current-node)))
+    (if content
+        (progn
+          (let ((inhibit-read-only t))
+            (insert content))
+          (elopher-restore-pos)
+          (message "Displaying cached search results. Reload to perform a new search."))
+      (let* ((inhibit-read-only t)
+             (query-string (read-from-minibuffer "Query: "))
+             (query-selector (concat (elopher-address-selector address) "\t" query-string))
+             (search-address (elopher-make-address query-selector
+                                                   (elopher-address-host address)
+                                                   (elopher-address-port address))))
+        (insert "LOADING RESULTS...")
+        (elopher-get-selector search-address
+                              (lambda (proc event)
+                                (let ((inhibit-read-only t))
+                                  (erase-buffer)
+                                  (elopher-insert-index elopher-selector-string))
+                                (goto-char (point-min))
+                                (elopher-set-node-content elopher-current-node
+                                                          (buffer-string))))))))
+
 
 ;;; Navigation procedures
 ;;