Enable gemini-write to use the auth-source library
This commit is contained in:
parent
a96d087104
commit
e975fa032d
|
@ -33,3 +33,11 @@ of how to set it all up:
|
||||||
;; make sure "e" can be used to edit raw pages
|
;; make sure "e" can be used to edit raw pages
|
||||||
(eval-after-load "elpher" '(load-library "gemini-write"))
|
(eval-after-load "elpher" '(load-library "gemini-write"))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Tokens
|
||||||
|
|
||||||
|
`gemini-write` can pull tokens from the `elpher-gemini-tokens` alist, or from the `auth-source` library. A gemini-write token entry in ~/.authsource should contain the host and the port, which by default is 1965, along with the token in the `password` field, like this:
|
||||||
|
|
||||||
|
```
|
||||||
|
machine example.com port 1965 password example-password
|
||||||
|
```
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
|
|
||||||
(require 'elpher)
|
(require 'elpher)
|
||||||
(require 'gemini-mode)
|
(require 'gemini-mode)
|
||||||
|
(require 'auth-source)
|
||||||
|
|
||||||
;;; gemini-write support
|
;;; gemini-write support
|
||||||
|
|
||||||
|
@ -109,6 +110,11 @@ used when writing Gemini pages."
|
||||||
:type '(alist :key-type (string :tag "Host") :value-type (string :tag "Token"))
|
:type '(alist :key-type (string :tag "Host") :value-type (string :tag "Token"))
|
||||||
:group 'gemini-mode)
|
:group 'gemini-mode)
|
||||||
|
|
||||||
|
(defcustom gemini-write-use-auth-source t
|
||||||
|
"Enable password fetching from `auth-source', as well as from `elpher-gemini-tokens'."
|
||||||
|
:type 'boolean
|
||||||
|
:group 'gemini-mode)
|
||||||
|
|
||||||
(defun get-elpher-buffer-showing (page)
|
(defun get-elpher-buffer-showing (page)
|
||||||
"Return the first Elpher buffer showing PAGE."
|
"Return the first Elpher buffer showing PAGE."
|
||||||
(catch 'buf
|
(catch 'buf
|
||||||
|
@ -122,6 +128,23 @@ used when writing Gemini pages."
|
||||||
address)))
|
address)))
|
||||||
(throw 'buf buf)))))))
|
(throw 'buf buf)))))))
|
||||||
|
|
||||||
|
(defun gemini-write-get-token (host &optional port)
|
||||||
|
"Get a token from `elpher-gemini-tokens', or `auth-sources' if `gemini-write-use-auth-source' is enabled."
|
||||||
|
(if-let (token (cdr (assoc host elpher-gemini-tokens)))
|
||||||
|
token
|
||||||
|
(if gemini-write-use-auth-source
|
||||||
|
(let ((info (nth 0 (auth-source-search
|
||||||
|
:host host
|
||||||
|
:port (or port 1965)
|
||||||
|
:require '(:secret)))))
|
||||||
|
(if info
|
||||||
|
(let ((secret (plist-get info :secret)))
|
||||||
|
(if (functionp secret)
|
||||||
|
(funcall secret)
|
||||||
|
secret))
|
||||||
|
nil))
|
||||||
|
nil)))
|
||||||
|
|
||||||
(defun gemini-write ()
|
(defun gemini-write ()
|
||||||
"Save the current Gemini buffer.
|
"Save the current Gemini buffer.
|
||||||
This will be saved to `elpher-current-page'. If there's an Elpher
|
This will be saved to `elpher-current-page'. If there's an Elpher
|
||||||
|
@ -137,7 +160,7 @@ going to use. Otherwise, a new buffer is used."
|
||||||
(generate-new-buffer (default-value 'elpher-buffer-name))
|
(generate-new-buffer (default-value 'elpher-buffer-name))
|
||||||
(elpher-mode)
|
(elpher-mode)
|
||||||
(current-buffer))))
|
(current-buffer))))
|
||||||
(token (cdr (assoc (url-host address) elpher-gemini-tokens)))
|
(token (gemini-write-get-token (url-host address)))
|
||||||
(data (encode-coding-string (buffer-string) 'utf-8 t)))
|
(data (encode-coding-string (buffer-string) 'utf-8 t)))
|
||||||
(switch-to-buffer buf)
|
(switch-to-buffer buf)
|
||||||
(setq-local elpher-current-page page)
|
(setq-local elpher-current-page page)
|
||||||
|
@ -164,7 +187,7 @@ going to use. Otherwise, a new buffer is used."
|
||||||
(elpher-mode)
|
(elpher-mode)
|
||||||
(current-buffer)))
|
(current-buffer)))
|
||||||
(address (elpher-address-from-url url))
|
(address (elpher-address-from-url url))
|
||||||
(token (cdr (assoc (url-host address) elpher-gemini-tokens)))
|
(token (gemini-write-get-token (url-host address)))
|
||||||
(mime-type (completing-read "MIME type: " (mailcap-mime-types) nil t
|
(mime-type (completing-read "MIME type: " (mailcap-mime-types) nil t
|
||||||
(mailcap-extension-to-mime
|
(mailcap-extension-to-mime
|
||||||
(file-name-extension file t))))
|
(file-name-extension file t))))
|
||||||
|
|
Loading…
Reference in New Issue