X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=elopher.el;h=dfb5c776b6f0f556d1ff4962f9ab936e5d10db03;hb=20fb5d3a386e6546ed881d5005a6acb77521388d;hp=8237b63f823da19ac12b479d9fb308e8afc7f182;hpb=997b7d99faa7b7d1ceca2eae5fa4ce40a780ba96;p=elpher.git diff --git a/elopher.el b/elopher.el index 8237b63..dfb5c77 100644 --- a/elopher.el +++ b/elopher.el @@ -77,6 +77,10 @@ "Face used for image records." :type '(face)) +(defcustom elopher-binary-face '(foreground-color . "magenta") + "Face used for image records." + :type '(face)) + (defcustom elopher-unknown-face '(foreground-color . "red") "Face used for unknown record types." :type '(face)) @@ -145,6 +149,7 @@ Otherwise, use the system browser via the BROWSE-URL function." (defun elopher-visit-node (node &optional getter) (elopher-save-pos) + (elopher-process-cleanup) (setq elopher-current-node node) (if getter (funcall getter) @@ -163,6 +168,7 @@ Otherwise, use the system browser via the BROWSE-URL function." ;; (defmacro elopher-with-clean-buffer (&rest args) + "Evaluate ARGS with a clean *elopher* buffer as current." (list 'progn '(switch-to-buffer "*elopher*") '(elopher-mode) @@ -203,10 +209,10 @@ Otherwise, use the system browser via the BROWSE-URL function." (help-string (format "mouse-1, RET: open %s on %s port %s" selector host port))) (pcase type - (?i (elopher-insert-margin) + (?i (elopher-insert-margin) ; Information (insert (propertize display-string 'face elopher-info-face))) - (?0 (elopher-insert-margin "T") + (?0 (elopher-insert-margin "T") ; Text (insert-text-button display-string 'face elopher-text-face 'elopher-node (elopher-make-node elopher-current-node @@ -215,7 +221,7 @@ Otherwise, use the system browser via the BROWSE-URL function." 'action #'elopher-click-link 'follow-link t 'help-echo help-string)) - (?1 (elopher-insert-margin "/") + (?1 (elopher-insert-margin "/") ; Index (insert-text-button display-string 'face elopher-index-face 'elopher-node (elopher-make-node elopher-current-node @@ -224,21 +230,30 @@ Otherwise, use the system browser via the BROWSE-URL function." 'action #'elopher-click-link 'follow-link t 'help-echo help-string)) - ((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 - address - #'elopher-get-image-node) - 'action #'elopher-click-link - 'follow-link t - 'help-echo help-string)) + ((or ?g ?p ?I) (elopher-insert-margin "im") ; Image + (insert-text-button display-string + 'face elopher-image-face + 'elopher-node (elopher-make-node elopher-current-node + address + #'elopher-get-image-node) + 'action #'elopher-click-link + 'follow-link t + 'help-echo help-string)) + ((or ?4 ?9) (elopher-insert-margin "B") ; Binary + (insert-text-button display-string + 'face elopher-binary-face + 'elopher-node (elopher-make-node elopher-current-node + address + #'elopher-get-node-download) + 'action #'elopher-click-link + 'follow-link t + 'help-echo help-string)) (?7 (elopher-insert-margin "S") (insert-text-button display-string 'face elopher-search-face 'elopher-node (elopher-make-node elopher-current-node - address - #'elopher-get-search-node) + address + #'elopher-get-search-node) 'action #'elopher-click-link 'follow-link t 'help-echo help-string)) @@ -260,14 +275,17 @@ Otherwise, use the system browser via the BROWSE-URL function." ;;; Selector retrieval (all kinds) ;; +(defun elopher-process-cleanup () + "Immediately shut down any extant elopher process." + (let ((p (get-process "elopher-process"))) + (if p (delete-process p)))) + (defvar elopher-selector-string) (defun elopher-get-selector (address after) "Retrieve selector specified by ADDRESS, then execute AFTER. The result is stored as a string in the variable elopher-selector-string." (setq elopher-selector-string "") - (let ((p (get-process "elopher-process"))) - (if p (delete-process p))) (make-network-process :name "elopher-process" :host (elopher-address-host address) @@ -286,7 +304,7 @@ The result is stored as a string in the variable elopher-selector-string." (if content (progn (elopher-with-clean-buffer - (insert content)) + (insert content)) (elopher-restore-pos)) (if address (progn @@ -294,14 +312,15 @@ The result is stored as a string in the variable elopher-selector-string." (insert "LOADING DIRECTORY...")) (elopher-get-selector address (lambda (proc event) - (elopher-with-clean-buffer - (elopher-insert-index elopher-selector-string)) - (elopher-restore-pos) - (elopher-set-node-content elopher-current-node - (buffer-string))))) + (unless (string-prefix-p "deleted" event) + (elopher-with-clean-buffer + (elopher-insert-index elopher-selector-string)) + (elopher-restore-pos) + (elopher-set-node-content elopher-current-node + (buffer-string)))))) (progn (elopher-with-clean-buffer - (elopher-insert-index elopher-start-index)) + (elopher-insert-index elopher-start-index)) (elopher-restore-pos) (elopher-set-node-content elopher-current-node (buffer-string))))))) @@ -318,18 +337,19 @@ The result is stored as a string in the variable elopher-selector-string." (if content (progn (elopher-with-clean-buffer - (insert content)) + (insert content)) (elopher-restore-pos)) (progn (elopher-with-clean-buffer - (insert "LOADING TEXT...")) + (insert "LOADING TEXT...")) (elopher-get-selector address (lambda (proc event) - (elopher-with-clean-buffer - (insert (elopher-process-text elopher-selector-string))) - (elopher-restore-pos) - (elopher-set-node-content elopher-current-node - (buffer-string)))))))) + (unless (string-prefix-p "deleted" event) + (elopher-with-clean-buffer + (insert (elopher-process-text elopher-selector-string))) + (elopher-restore-pos) + (elopher-set-node-content elopher-current-node + (buffer-string))))))))) ;; Image retrieval @@ -339,22 +359,24 @@ The result is stored as a string in the variable elopher-selector-string." (if content (progn (elopher-with-clean-buffer - (insert-image content)) + (insert-image content)) (setq cursor-type nil) (elopher-restore-pos)) (progn (elopher-with-clean-buffer - (insert "LOADING IMAGE...")) + (insert "LOADING IMAGE...")) (elopher-get-selector address (lambda (proc event) - (let ((image (create-image - (string-as-unibyte elopher-selector-string) - nil t))) - (elopher-with-clean-buffer - (insert-image image)) - (setq cursor-type nil) - (elopher-restore-pos) - (elopher-set-node-content elopher-current-node image)))))))) + (unless (string-prefix-p "deleted" event) + (let ((image (create-image + (string-as-unibyte elopher-selector-string) + nil t))) + (elopher-with-clean-buffer + (insert-image image)) + (setq cursor-type nil) + (elopher-restore-pos) + (elopher-set-node-content elopher-current-node + image))))))))) ;; Search retrieval @@ -376,11 +398,12 @@ The result is stored as a string in the variable elopher-selector-string." (insert "LOADING RESULTS...")) (elopher-get-selector search-address (lambda (proc event) - (elopher-with-clean-buffer - (elopher-insert-index elopher-selector-string)) - (goto-char (point-min)) - (elopher-set-node-content elopher-current-node - (buffer-string)))))))) + (unless (string-prefix-p "deleted" event) + (elopher-with-clean-buffer + (elopher-insert-index elopher-selector-string)) + (goto-char (point-min)) + (elopher-set-node-content elopher-current-node + (buffer-string))))))))) ;; Raw server response retrieval @@ -392,9 +415,10 @@ The result is stored as a string in the variable elopher-selector-string." (if address (elopher-get-selector address (lambda (proc event) - (elopher-with-clean-buffer - (insert elopher-selector-string)) - (goto-char (point-min)))) + (unless (string-prefix-p "deleted" event) + (elopher-with-clean-buffer + (insert elopher-selector-string)) + (goto-char (point-min))))) (progn (elopher-with-clean-buffer (insert elopher-start-index))