X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=elopher.el;h=b8170c5521da6792e4192bb6faa0d6feae25ee7b;hb=ce7691f3d1a8f26f309fd9693b979ddec8cef4af;hp=ebab261a0959a95ba32897495890e89d25fc6f4d;hpb=0e408c92b155d79826eb98a2665a1d1b04aeeae6;p=elpher.git diff --git a/elopher.el b/elopher.el index ebab261..b8170c5 100644 --- a/elopher.el +++ b/elopher.el @@ -16,7 +16,8 @@ "Width of left-hand margin used when rendering indicies.") (defconst elopher-start-index - (mapconcat 'identity + (mapconcat + 'identity (list "i\tfake\tfake\t1" "i--------------------------------------------\tfake\tfake\t1" "i Elopher Gopher Client \tfake\tfake\t1" @@ -30,7 +31,8 @@ "i - u: return to parent directory entry\tfake\tfake\t1" "i - g: go to a particular page\tfake\tfake\t1" "i - r: reload current page\tfake\tfake\t1" - "i - t: display the current page as text (i.e. \"source\")\tfake\tfake\t1" + "i - d: download directory entry under cursor\tfake\tfake\t1" + "i - w: display the raw server response for the current page\tfake\tfake\t1" "i\tfake\tfake\t1" "iPlaces to start exploring Gopherspace:\tfake\tfake\t1" "i\tfake\tfake\t1" @@ -141,13 +143,11 @@ Otherwise, use the system browser via the BROWSE-URL function." (defvar elopher-current-node) -(defun elopher-visit-node (node &optional text) +(defun elopher-visit-node (node &optional raw) (elopher-save-pos) (setq elopher-current-node node) - (if text - (progn - (elopher-set-node-content elopher-current-node nil) - (elopher-get-text-node)) + (if raw + (elopher-get-node-raw) (funcall (elopher-node-getter node)))) (defun elopher-visit-parent-node () @@ -292,8 +292,6 @@ The result is stored as a string in the variable elopher-selector-string." (progn (elopher-with-clean-buffer (insert "LOADING DIRECTORY...")) - ;; (let ((inhibit-read-only t)) - ;; (insert "LOADING DIRECTORY...")) (elopher-get-selector address (lambda (proc event) (elopher-with-clean-buffer @@ -310,8 +308,9 @@ The result is stored as a string in the variable elopher-selector-string." ;; Text retrieval -(defun elopher-strip-CRs (string) - (replace-regexp-in-string "\r" "" string)) +(defun elopher-process-text (string) + (let ((chopped-str (replace-regexp-in-string "\r\n\.\r\n$" "\r\n" string))) + (replace-regexp-in-string "\r" "" chopped-str))) (defun elopher-get-text-node () (let ((content (elopher-node-content elopher-current-node)) @@ -327,7 +326,7 @@ The result is stored as a string in the variable elopher-selector-string." (elopher-get-selector address (lambda (proc event) (elopher-with-clean-buffer - (insert (elopher-strip-CRs elopher-selector-string))) + (insert (elopher-process-text elopher-selector-string))) (elopher-restore-pos) (elopher-set-node-content elopher-current-node (buffer-string)))))))) @@ -367,7 +366,7 @@ The result is stored as a string in the variable elopher-selector-string." (elopher-with-clean-buffer (insert content)) (elopher-restore-pos) - (message "Displaying cached search results. Reload to perform a new search.")) + (message "Displaying cached search results. Reload to perform a new search.")) (let* ((query-string (read-string "Query: ")) (query-selector (concat (elopher-address-selector address) "\t" query-string)) (search-address (elopher-make-address query-selector @@ -383,6 +382,41 @@ The result is stored as a string in the variable elopher-selector-string." (elopher-set-node-content elopher-current-node (buffer-string)))))))) +;; Raw server response retrieval + +(defun elopher-get-node-raw () + (let* ((content (elopher-node-content elopher-current-node)) + (address (elopher-node-address elopher-current-node))) + (elopher-with-clean-buffer + (insert "LOADING RAW SERVER RESPONSE...")) + (if address + (elopher-get-selector address + (lambda (proc event) + (elopher-with-clean-buffer + (insert elopher-selector-string)) + (goto-char (point-min)))) + (progn + (elopher-with-clean-buffer + (insert elopher-start-index)) + (goto-char (point-min))))) + (message "Displaying raw server response. Reload to return to standard view.")) + + +;; File export retrieval + +(defvar elopher-download-filename) + +(defun elopher-download-node (node filename) + (let* ((address (elopher-node-address node))) + (message "Downloading...") + (setq elopher-download-filename filename) + (elopher-get-selector address + (lambda (proc event) + (let ((coding-system-for-write 'binary)) + (with-temp-file elopher-download-filename + (insert elopher-selector-string))) + (message (format "Download complate, saved to file %s." + elopher-download-filename)))))) ;;; Navigation procedures ;; @@ -427,7 +461,7 @@ The result is stored as a string in the variable elopher-selector-string." (interactive) (elopher-reload-current-node)) -(defun elopher-view-text () +(defun elopher-view-raw () "View current page as plain text." (interactive) (elopher-visit-node elopher-current-node t)) @@ -439,6 +473,22 @@ The result is stored as a string in the variable elopher-selector-string." (elopher-visit-parent-node) (message "No previous site."))) +(defun elopher-download () + "Download the link at point." + (interactive) + (let ((button (button-at (point)))) + (if button + (let* ((node (button-get button 'elopher-node)) + (address (elopher-node-address node)) + (selector (elopher-address-selector address)) + (filename-proposal (file-name-nondirectory selector)) + (filename (read-file-name "Name of file to write: " + nil nil nil + (if (> (length filename-proposal) 0) + filename-proposal + "gopher.file")))) + (elopher-download-node node filename)) + (message "No link selected.")))) ;;; Mode and keymap ;; @@ -450,7 +500,8 @@ The result is stored as a string in the variable elopher-selector-string." (define-key map (kbd "u") 'elopher-back) (define-key map (kbd "g") 'elopher-go) (define-key map (kbd "r") 'elopher-reload) - (define-key map (kbd "t") 'elopher-view-text) + (define-key map (kbd "w") 'elopher-view-raw) + (define-key map (kbd "d") 'elopher-download) (when (fboundp 'evil-define-key) (evil-define-key 'normal map (kbd "C-]") 'elopher-follow-closest-link @@ -458,7 +509,8 @@ The result is stored as a string in the variable elopher-selector-string." (kbd "u") 'elopher-back (kbd "g") 'elopher-go (kbd "r") 'elopher-reload - (kbd "t") 'elopher-view-text)) + (kbd "w") 'elopher-view-raw + (kbd "d") 'elopher-download)) map) "Keymap for gopher client.")