1
0
Fork 0

Refactored the internal kagi--get-summarizer-parameters function

Take a list of promptable items, to be passed on from the caller.
This commit is contained in:
Bram Schoenmakers 2024-03-06 21:20:15 +01:00
parent 72119bd9b7
commit 3671f78c6a
Signed by: bram
GPG key ID: 0CCD19DFDC63258F

24
kagi.el
View file

@ -600,16 +600,17 @@ content."
(gethash "code" firsterror))) (gethash "code" firsterror)))
(error "An error occurred while requesting a summary"))))) (error "An error occurred while requesting a summary")))))
(defun kagi--get-summarizer-parameters (&optional prompt-insert-p prompt-cache-p) (defun kagi--get-summarizer-parameters (&optional prompts)
"Return a list of interactively obtained summarizer parameters. "Return a list of interactively obtained summarizer parameters.
Not all commands need to insert a summary, so only prompt for Some parameters need to be called interactively, however, for
this when PROMPT-INSERT-P is non-nil. some clients that doesn't make sense. E.g. we don't want to ask
to insert when the region is highlighted. Therefore, PROMPTS is a
Likewise, not all commands need to disable the cache, so only list of items that can be prompted interactively. It is
prompt when PROMPT-CACHE-P is t." a (possibly empty) list with possible elements \\='prompt-for-insert
or \\='prompt-for-no-cache."
(append (append
(when prompt-insert-p (when (seq-contains-p prompts 'prompt-for-insert)
(list (list
(and (equal current-prefix-arg '(4)) (and (equal current-prefix-arg '(4))
(not buffer-read-only) (not buffer-read-only)
@ -644,7 +645,7 @@ prompt when PROMPT-CACHE-P is t."
nil nil
#'string=)))) #'string=))))
(list (list
(and prompt-cache-p (and (seq-contains-p prompts 'prompt-for-no-cache)
(equal current-prefix-arg '(4)) (equal current-prefix-arg '(4))
(y-or-n-p "Cache the result?"))))) (y-or-n-p "Cache the result?")))))
@ -681,7 +682,8 @@ summary FORMAT to use.
INTERACTIVE-P is t when called interactively." INTERACTIVE-P is t when called interactively."
(interactive (append (interactive (append
(list (read-buffer (format-prompt "Buffer" "") nil t)) (list (read-buffer (format-prompt "Buffer" "") nil t))
(kagi--get-summarizer-parameters t t) (kagi--get-summarizer-parameters '(prompt-for-insert
prompt-for-no-cache))
(list t))) (list t)))
(let ((summary (with-current-buffer buffer (let ((summary (with-current-buffer buffer
(kagi-summarize (buffer-string) language engine format no-cache))) (kagi-summarize (buffer-string) language engine format no-cache)))
@ -717,7 +719,7 @@ prompted for which target LANGUAGE to use, which summarizer
ENGINE to use and which summary FORMAT to use." ENGINE to use and which summary FORMAT to use."
(interactive (append (interactive (append
(list (region-beginning) (region-end)) (list (region-beginning) (region-end))
(kagi--get-summarizer-parameters nil t))) (kagi--get-summarizer-parameters '(prompt-for-no-cache))))
(kagi--display-summary (kagi--display-summary
(kagi-summarize (buffer-substring-no-properties begin end) (kagi-summarize (buffer-substring-no-properties begin end)
language language
@ -764,7 +766,7 @@ types are supported:
(interactive (interactive
(cons (cons
(read-string (format-prompt "URL" "")) (read-string (format-prompt "URL" ""))
(kagi--get-summarizer-parameters t))) (kagi--get-summarizer-parameters '(prompt-for-insert))))
(let ((summary (kagi-summarize url language engine format))) (let ((summary (kagi-summarize url language engine format)))
(if (and insert (not buffer-read-only)) (if (and insert (not buffer-read-only))
(kagi--insert-summary summary) (kagi--insert-summary summary)