X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=elpher.git;a=blobdiff_plain;f=elpher.el;h=b323cbb2ec49374f991a11eba1da596d1964a2e3;hp=6cc34746e5feddc9694ac75cb1bd5ad2ae19af99;hb=f2d1b1a74b7198401442cfc0d2ae00866fa7397e;hpb=7c60d1ffd2e07b32d3904bab21debc288ed51d3d diff --git a/elpher.el b/elpher.el index 6cc3474..b323cbb 100644 --- a/elpher.el +++ b/elpher.el @@ -258,6 +258,10 @@ Otherwise, the SOCKS proxy is only used for connections to onion services." '((t :inherit fixed-pitch)) "Face used for pre-formatted gemini text blocks.") +(defface elpher-gemini-quoted + '((t :inherit font-lock-doc-face)) + "Face used for gemini quoted texts.") + ;;; Model ;; @@ -484,7 +488,7 @@ unless NO-HISTORY is non-nil." (if previous-page (elpher-visit-page previous-page nil t) (error "No previous page")))) - + (defun elpher-reload-current-page () "Reload the current page, discarding any existing cached content." (elpher-cache-content (elpher-page-address elpher-current-page) nil) @@ -1069,7 +1073,7 @@ The response is rendered using the rendering function RENDERER." (elpher-get-gopher-response search-address renderer)) (if aborted (elpher-visit-previous-page)))))) - + ;; Raw server response rendering (defun elpher-render-raw (data &optional mime-type-string) @@ -1375,7 +1379,7 @@ treatment that a separate function is warranted." 'help-echo #'elpher--page-button-help)) (insert (propertize display-string 'face 'elpher-unknown))) (insert "\n")))) - + (defun elpher-gemini-insert-header (header-line) "Insert header described by HEADER-LINE into a text/gemini document. The gemini map file line describing the header is given @@ -1383,14 +1387,11 @@ by HEADER-LINE." (when (string-match "^\\(#+\\)[ \t]*" header-line) (let* ((level (length (match-string 1 header-line))) (header (substring header-line (match-end 0))) - (face (pcase level + (face (pcase level (1 'elpher-gemini-heading1) (2 'elpher-gemini-heading2) (3 'elpher-gemini-heading3) - (_ 'default))) - (fill-column (/ (* fill-column - (font-get (font-spec :name (face-font 'default)) :size)) - (font-get (font-spec :name (face-font face)) :size)))) + (_ 'default)))) (unless (display-graphic-p) (insert (make-string level ?#) " ")) (insert (propertize header 'face face)) @@ -1401,17 +1402,20 @@ by HEADER-LINE." This function uses Emacs' auto-fill to wrap text sensibly to a maximum width defined by elpher-gemini-max-fill-width." (string-match "\\(^[ \t]*\\)\\(\*[ \t]+\\|>[ \t]*\\)?" text-line) - (let* ((processed-text-line (if (match-string 2 text-line) - (concat - (replace-regexp-in-string "\*" - elpher-gemini-bullet-string - (match-string 0 text-line)) - (substring text-line (match-end 0))) - text-line)) - (adaptive-fill-mode nil) - (fill-prefix (if (match-string 2 text-line) - (replace-regexp-in-string "[>\*]" " " (match-string 0 text-line)) - nil))) + (let* ((line-prefix (match-string 2 text-line)) + (processed-text-line + (if line-prefix + (cond ((string-prefix-p "*" line-prefix) + (concat + (replace-regexp-in-string "\*" + elpher-gemini-bullet-string + (match-string 0 text-line)) + (substring text-line (match-end 0)))) + ((string-prefix-p ">" line-prefix) + (propertize text-line 'face 'elpher-gemini-quoted)) + (t text-line)) + text-line)) + (adaptive-fill-mode nil)) (insert (elpher-process-text-for-display processed-text-line)) (newline))) @@ -1608,7 +1612,7 @@ The result is rendered using RENDERER." 'help-echo help-string)) (insert "\n") (elpher-restore-pos))) - + ;;; Bookmarks ;; @@ -1618,7 +1622,7 @@ The result is rendered using RENDERER." DISPLAY-STRING determines how the bookmark will appear in the bookmark list, while URL is the url of the entry." (list display-string url)) - + (defun elpher-bookmark-display-string (bookmark) "Get the display string of BOOKMARK." (elt bookmark 0)) @@ -1634,6 +1638,9 @@ bookmark list, while URL is the url of the entry." (defun elpher-save-bookmarks (bookmarks) "Record the bookmark list BOOKMARKS to the user's bookmark file. Beware that this completely replaces the existing contents of the file." + (let ((bookmark-dir (file-name-directory elpher-bookmarks-file))) + (unless (file-directory-p bookmark-dir) + (make-directory bookmark-dir))) (with-temp-file elpher-bookmarks-file (erase-buffer) (insert "; Elpher bookmarks file\n\n" @@ -1697,6 +1704,7 @@ If ADDRESS is already bookmarked, update the label only." (interactive) (push-button)) +;;;###autoload (defun elpher-go (host-or-url) "Go to a particular gopher site HOST-OR-URL. When run interactively HOST-OR-URL is read from the minibuffer." @@ -1882,6 +1890,7 @@ When run interactively HOST-OR-URL is read from the minibuffer." (message "Bookmark removed."))) (error "No link selected")))) +;;;###autoload (defun elpher-bookmarks () "Visit bookmarks page." (interactive) @@ -1904,7 +1913,7 @@ When run interactively HOST-OR-URL is read from the minibuffer." (if button (elpher-info-page (button-get button 'elpher-page)) (error "No item selected")))) - + (defun elpher-info-current () "Display information on current page." (interactive)