From f61c3c7d0f7ee6e98fe1026e8aadf97bb2a23876 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jan 2024 09:16:01 +0100 Subject: [PATCH 01/15] Add kagi-fastgpt-prompt to send queries from the minibuffer or Lisp code --- kagi.el | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/kagi.el b/kagi.el index 9cf1dab..5f4cdfb 100644 --- a/kagi.el +++ b/kagi.el @@ -337,8 +337,7 @@ list of conses." (defun kagi--display-summary (summary buffer-name) "Display the SUMMARY in a buffer called BUFFER-NAME." - (with-current-buffer (get-buffer-create buffer-name) - (erase-buffer) + (with-current-buffer (generate-new-buffer-name buffer-name) (insert summary) (goto-char 0) (text-mode) @@ -359,6 +358,15 @@ Returns a formatted string to be displayed by the shell." (references (kagi--gethash parsed-response "data" "references"))) (format "%s\n\n%s" (kagi--format-output output) (kagi--format-references references)))) +(defun kagi--fastgpt-display-result (result) + "Display the RESULT of a FastGPT prompt in a new buffer." + (let ((buffer-name (generate-new-buffer-name "*fastgpt-result*"))) + (with-current-buffer (get-buffer-create buffer-name) + (save-excursion + (insert result)) + (text-mode) + (display-buffer buffer-name)))) + (defvar kagi-fastgpt--config (make-shell-maker-config :name "FastGPT" @@ -380,6 +388,20 @@ Returns a formatted string to be displayed by the shell." (interactive) (shell-maker-start kagi-fastgpt--config)) +;;;###autoload +(defun kagi-fastgpt-prompt (prompt &optional interactive) + "Feed the given PROMPT to FastGPT and return a response. + +When INTERACTIVE is nil, the response is returned as a string. + +When INTERACTIVE is non-nil, the function was called +interactively and the result is displayed in a new buffer." + (interactive "sfastgpt> \np") + (let ((result (kagi--process-prompt prompt))) + (if interactive + (kagi--fastgpt-display-result result) + result))) + ;;; Summarizer (defun kagi--get-domain-name (url) From bf599591f036c36211540350d9eebf90e8364907 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jan 2024 10:42:09 +0100 Subject: [PATCH 02/15] Extend FastGPT function to insert result at point Split the interactive and non-interactive functionality in separate functions. This allows the interactive command to be extended with an insert parameter. --- kagi.el | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/kagi.el b/kagi.el index 5f4cdfb..2a937af 100644 --- a/kagi.el +++ b/kagi.el @@ -348,10 +348,8 @@ list of conses." (save-excursion (insert (substring-no-properties summary)))) -(defun kagi--process-prompt (prompt) - "Submit a PROMPT to FastGPT and process the API response. - -Returns a formatted string to be displayed by the shell." +(defun kagi-fastgpt (prompt) + "Submit a PROMPT to FastGPT and return a formatted response string." (let* ((response (kagi--call-fastgpt prompt)) (parsed-response (json-parse-string response)) (output (kagi--gethash parsed-response "data" "output")) @@ -374,7 +372,7 @@ Returns a formatted string to be displayed by the shell." :execute-command (lambda (command _history callback error-callback) (condition-case err - (funcall callback (kagi--process-prompt command) nil) + (funcall callback (kagi-fastgpt-prompt command) nil) (json-parse-error (funcall error-callback (format "Could not parse the server response %s" (cdr err)))) (error (funcall error-callback (format "An error occurred during the request %s" (cdr err))))))) @@ -389,18 +387,17 @@ Returns a formatted string to be displayed by the shell." (shell-maker-start kagi-fastgpt--config)) ;;;###autoload -(defun kagi-fastgpt-prompt (prompt &optional interactive) - "Feed the given PROMPT to FastGPT and return a response. +(defun kagi-fastgpt-prompt (prompt &optional insert) + "Feed the given PROMPT to FastGPT. -When INTERACTIVE is nil, the response is returned as a string. - -When INTERACTIVE is non-nil, the function was called -interactively and the result is displayed in a new buffer." +If INSERT is non-nil, the response is inserted at point. +Otherwise, show the result in a separate buffer." (interactive "sfastgpt> \np") - (let ((result (kagi--process-prompt prompt))) - (if interactive - (kagi--fastgpt-display-result result) - result))) + (let ((result (kagi-fastgpt prompt))) + (if insert + (save-excursion + (insert result)) + (kagi--fastgpt-display-result result)))) ;;; Summarizer From 9e1bdf8428a98b2b803a1b0e2bbd3cec214718ce Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jan 2024 10:51:43 +0100 Subject: [PATCH 03/15] Update documentation for the new FastGPT functions --- README.org | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.org b/README.org index 5b7fa3c..4f245ee 100644 --- a/README.org +++ b/README.org @@ -23,7 +23,9 @@ Both functions are accessed through an [[https://help.kagi.com/kagi/api/overview ** FastGPT -The FastGPT functionality has only one command: =kagi-fastgpt-shell=. This opens a shell buffer in a new window where prompts can be typed. Kagi FastGPT typically returns output based on actual search results. When point is on one of the listed URLs, press =C-c RET= to open it. +- =kagi-fastgpt-shell= :: Opens a shell buffer in a new window where prompts can be typed. This Kagi FastGPT typically returns output based on actual search results. When point is on one of the listed URLs, press =C-c RET= to open it. +- =kagi-fastgpt-prompt= :: Enter a prompt in the minibuffer and show the result in a separate buffer. With a universal prefix (=C-u=), the result is inserted at point. +- =kagi-fastgpt= :: Function to retrieve a FastGPT response, to be used from Lisp code. ** Universal Summarizer From 0321b635c0ef2586751cd087e222aeaafd4d1eac Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jan 2024 11:05:27 +0100 Subject: [PATCH 04/15] Fix prefix interpretation --- kagi.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kagi.el b/kagi.el index 2a937af..414614e 100644 --- a/kagi.el +++ b/kagi.el @@ -392,7 +392,7 @@ list of conses." If INSERT is non-nil, the response is inserted at point. Otherwise, show the result in a separate buffer." - (interactive "sfastgpt> \np") + (interactive "sfastgpt> \nP") (let ((result (kagi-fastgpt prompt))) (if insert (save-excursion From a0dd0346a2bcd4a21b3d119680b4173a1e19022b Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jan 2024 11:09:25 +0100 Subject: [PATCH 05/15] Do not attempt to insert in read-only buffers --- kagi.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kagi.el b/kagi.el index 414614e..d44c662 100644 --- a/kagi.el +++ b/kagi.el @@ -394,7 +394,7 @@ If INSERT is non-nil, the response is inserted at point. Otherwise, show the result in a separate buffer." (interactive "sfastgpt> \nP") (let ((result (kagi-fastgpt prompt))) - (if insert + (if (and insert (not buffer-read-only)) (save-excursion (insert result)) (kagi--fastgpt-display-result result)))) From dfcc46e34b254570e2df7121a1a18bb5a21d32d4 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Sun, 21 Jan 2024 22:53:27 +0100 Subject: [PATCH 06/15] Add kagi-translate function --- kagi.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kagi.el b/kagi.el index d44c662..37aa28e 100644 --- a/kagi.el +++ b/kagi.el @@ -76,6 +76,11 @@ on dummy data." :type '(choice string function) :group 'kagi) +(defcustom kagi-fastgpt-translate-default-target-language nil + "The default target language for translations by function `kagi-translate'." + :type 'string + :group 'kagi) + (defcustom kagi-summarizer-api-url "https://kagi.com/api/v0/summarize" "The Kagi Summarizer API entry point." :type '(choice string function) @@ -399,6 +404,32 @@ Otherwise, show the result in a separate buffer." (insert result)) (kagi--fastgpt-display-result result)))) +(defun kagi-translate (text target-language &optional interactive-p) + "Translate the TEXT to TARGET-LANGUAGE using FastGPT. + +When INTERACTIVE-P is nil, the translation is returned as a string. + +When non-nil, the translation is shown in the echo area when the +result is short, otherwise it is displayed in a new buffer." + (interactive + (let ((default-target-language (or kagi-fastgpt-translate-default-target-language + "English"))) + (list (if (use-region-p) + (buffer-substring-no-properties (region-beginning) (region-end)) + (read-buffer (format-prompt "Buffer name or text" nil))) + (or kagi-fastgpt-translate-default-target-language + (read-string (format-prompt "Target language" default-target-language) nil nil default-target-language)) + t))) + (let* ((prompt (format "Translate the following text to %s: + +%s" + target-language text)) + (result (kagi-fastgpt prompt)) + (result-lines (length (string-lines result)))) + (cond ((and interactive-p (eql result-lines 1)) (message result)) + ((and interactive-p (> result-lines 1)) (kagi--fastgpt-display-result result)) + (t result)))) + ;;; Summarizer (defun kagi--get-domain-name (url) From d41a55fb98f057ec61de2f63a4ab3127c4ea617a Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Thu, 25 Jan 2024 06:11:33 +0100 Subject: [PATCH 07/15] Maintain an alist of (LANGUAGE . LANG-CODE) From this list, construct a user-facing string for language selection. Because having the language code embedded in the language name itself is not always desired. --- kagi.el | 87 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/kagi.el b/kagi.el index 37aa28e..35e4c8e 100644 --- a/kagi.el +++ b/kagi.el @@ -107,41 +107,47 @@ https://help.kagi.com/kagi/api/summarizer.html." :group 'kagi) (defvar kagi--summarizer-languages '(("Document language" . nil) - ("Bulgarian [BG]" . "BG") - ("Czech [CZ]" . "CZ") - ("Danish [DA]" . "DA") - ("German [DE]" . "DE") - ("Greek [EL]" . "EL") - ("English [EN]" . "EN") - ("Spanish [ES]" . "ES") - ("Estonian [ET]" . "ET") - ("Finnish [FI]" . "FI") - ("French [FR]" . "FR") - ("Hungarian [HU]" . "HU") - ("Indonesian [ID]" . "ID") - ("Italian [IT]" . "IT") - ("Japanese [JA]" . "JA") - ("Korean [KO]" . "KO") - ("Lithuanian [LT]" . "LT") - ("Latvian [LV]" . "LV") - ("Norwegian [NB]" . "NB") - ("Dutch [NL]" . "NL") - ("Polish [PL]" . "PL") - ("Portuguese [PT]" . "PT") - ("Romanian [RO]" . "RO") - ("Russian [RU]" . "RU") - ("Slovak [SK]" . "SK") - ("Slovenian [SL]" . "SL") - ("Swedish [SV]" . "SV") - ("Turkish [TR]" . "TR") - ("Ukrainian [UK]" . "UK") - ("Chinese (simplified) [ZH]" . "ZH")) + ("Bulgarian" . "BG") + ("Czech" . "CZ") + ("Danish" . "DA") + ("German" . "DE") + ("Greek" . "EL") + ("English" . "EN") + ("Spanish" . "ES") + ("Estonian" . "ET") + ("Finnish" . "FI") + ("French" . "FR") + ("Hungarian" . "HU") + ("Indonesian" . "ID") + ("Italian" . "IT") + ("Japanese" . "JA") + ("Korean" . "KO") + ("Lithuanian" . "LT") + ("Latvian" . "LV") + ("Norwegian" . "NB") + ("Dutch" . "NL") + ("Polish" . "PL") + ("Portuguese" . "PT") + ("Romanian" . "RO") + ("Russian" . "RU") + ("Slovak" . "SK") + ("Slovenian" . "SL") + ("Swedish" . "SV") + ("Turkish" . "TR") + ("Ukrainian" . "UK") + ("Chinese (simplified)" . "ZH")) "Supported languages by the Kagi Universal Summarizer.") (defcustom kagi-summarizer-default-language nil - "Default target language of the summary." + "Default target language of the summary. + +The value should be a string of two characters representing the + language. See variable `kagi--summarizer-languages' for the list + of language codes." :type (append '(choice) - (mapcar (lambda (lang) `(const :tag ,(car lang) ,(cdr lang))) + (mapcar (lambda (lang) + `(const :tag ,(format "%s [%s]" (car lang) (cdr lang)) + ,(cdr lang))) kagi--summarizer-languages)) :group 'kagi) @@ -500,13 +506,18 @@ this when PROMPT-INSERT-P is non-nil." (y-or-n-p "Insert summary at point?"))) (list (when (equal current-prefix-arg '(4)) - (alist-get - (completing-read (format-prompt "Output language" "") - kagi--summarizer-languages nil t) - kagi--summarizer-languages - (or kagi-summarizer-default-language "EN") - nil - #'string=))) + (let ((language-table (mapcar (lambda (lang) + (cons + (format "%s [%s]" (car lang) (cdr lang)) + (cdr lang))) + kagi--summarizer-languages))) + (alist-get + (completing-read (format-prompt "Output language" "") + language-table nil t) + language-table + (or kagi-summarizer-default-language "EN") + nil + #'string=)))) (list (when (equal current-prefix-arg '(4)) (completing-read (format-prompt "Engine" "") From d0cd9746833806e7e2aae35816ecc495a6dc04fc Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Thu, 25 Jan 2024 08:00:08 +0100 Subject: [PATCH 08/15] Read source and target language from the minibuffer (with history) --- kagi.el | 114 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 47 deletions(-) diff --git a/kagi.el b/kagi.el index 35e4c8e..d08ef7d 100644 --- a/kagi.el +++ b/kagi.el @@ -76,11 +76,6 @@ on dummy data." :type '(choice string function) :group 'kagi) -(defcustom kagi-fastgpt-translate-default-target-language nil - "The default target language for translations by function `kagi-translate'." - :type 'string - :group 'kagi) - (defcustom kagi-summarizer-api-url "https://kagi.com/api/v0/summarize" "The Kagi Summarizer API entry point." :type '(choice string function) @@ -106,38 +101,44 @@ https://help.kagi.com/kagi/api/summarizer.html." kagi--summarizer-engines)) :group 'kagi) -(defvar kagi--summarizer-languages '(("Document language" . nil) - ("Bulgarian" . "BG") - ("Czech" . "CZ") - ("Danish" . "DA") - ("German" . "DE") - ("Greek" . "EL") - ("English" . "EN") - ("Spanish" . "ES") - ("Estonian" . "ET") - ("Finnish" . "FI") - ("French" . "FR") - ("Hungarian" . "HU") - ("Indonesian" . "ID") - ("Italian" . "IT") - ("Japanese" . "JA") - ("Korean" . "KO") - ("Lithuanian" . "LT") - ("Latvian" . "LV") - ("Norwegian" . "NB") - ("Dutch" . "NL") - ("Polish" . "PL") - ("Portuguese" . "PT") - ("Romanian" . "RO") - ("Russian" . "RU") - ("Slovak" . "SK") - ("Slovenian" . "SL") - ("Swedish" . "SV") - ("Turkish" . "TR") - ("Ukrainian" . "UK") - ("Chinese (simplified)" . "ZH")) +(defvar kagi--languages '(("Bulgarian" . "BG") + ("Czech" . "CZ") + ("Danish" . "DA") + ("German" . "DE") + ("Greek" . "EL") + ("English" . "EN") + ("Spanish" . "ES") + ("Estonian" . "ET") + ("Finnish" . "FI") + ("French" . "FR") + ("Hungarian" . "HU") + ("Indonesian" . "ID") + ("Italian" . "IT") + ("Japanese" . "JA") + ("Korean" . "KO") + ("Lithuanian" . "LT") + ("Latvian" . "LV") + ("Norwegian" . "NB") + ("Dutch" . "NL") + ("Polish" . "PL") + ("Portuguese" . "PT") + ("Romanian" . "RO") + ("Russian" . "RU") + ("Slovak" . "SK") + ("Slovenian" . "SL") + ("Swedish" . "SV") + ("Turkish" . "TR") + ("Ukrainian" . "UK") + ("Chinese (simplified)" . "ZH")) + "Supported languages by the Kagi LLM.") + +(defvar kagi--summarizer-languages (append + '(("Document language" . nil) + kagi--languages)) "Supported languages by the Kagi Universal Summarizer.") +(defvar kagi--language-history nil) + (defcustom kagi-summarizer-default-language nil "Default target language of the summary. @@ -410,26 +411,45 @@ Otherwise, show the result in a separate buffer." (insert result)) (kagi--fastgpt-display-result result)))) -(defun kagi-translate (text target-language &optional interactive-p) +(defun kagi--read-language (prompt) + "Read a language from the minibuffer interactively. + +PROMPT is passed to the corresponding parameters of +`completing-read', refer to its documentation for more info." + (alist-get (completing-read prompt + kagi--languages + nil + nil + nil + kagi--language-history + "English") + kagi--languages)) + +(defun kagi-translate (text target-language &optional source-language interactive-p) "Translate the TEXT to TARGET-LANGUAGE using FastGPT. +With a single universal prefix, also prompt for the SOURCE-LANGUAGE. + When INTERACTIVE-P is nil, the translation is returned as a string. When non-nil, the translation is shown in the echo area when the result is short, otherwise it is displayed in a new buffer." (interactive - (let ((default-target-language (or kagi-fastgpt-translate-default-target-language - "English"))) - (list (if (use-region-p) - (buffer-substring-no-properties (region-beginning) (region-end)) - (read-buffer (format-prompt "Buffer name or text" nil))) - (or kagi-fastgpt-translate-default-target-language - (read-string (format-prompt "Target language" default-target-language) nil nil default-target-language)) - t))) - (let* ((prompt (format "Translate the following text to %s: + (list (if (use-region-p) + (buffer-substring-no-properties (region-beginning) (region-end)) + (read-buffer (format-prompt "Buffer name or text" nil))) + (kagi--read-language (format-prompt "Target language" nil)) + (when (equal current-prefix-arg '(4)) + (kagi--read-language (format-prompt "Source language" nil))) + t)) + (let* ((prompt (format "Translate the following text %sto %s: %s" - target-language text)) + target-language + (if source-language + (format "from %s " source-language) + "") + text)) (result (kagi-fastgpt prompt)) (result-lines (length (string-lines result)))) (cond ((and interactive-p (eql result-lines 1)) (message result)) @@ -513,7 +533,7 @@ this when PROMPT-INSERT-P is non-nil." kagi--summarizer-languages))) (alist-get (completing-read (format-prompt "Output language" "") - language-table nil t) + language-table nil t nil kagi--language-history) language-table (or kagi-summarizer-default-language "EN") nil From a6cf81c65291c0d0207846b354fc0b30da679712 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Thu, 25 Jan 2024 08:16:11 +0100 Subject: [PATCH 09/15] Return the language entered by the user The user is free to pick any language which is not necessarily covered by kagi--languages. --- kagi.el | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kagi.el b/kagi.el index d08ef7d..7d442a3 100644 --- a/kagi.el +++ b/kagi.el @@ -416,14 +416,12 @@ Otherwise, show the result in a separate buffer." PROMPT is passed to the corresponding parameters of `completing-read', refer to its documentation for more info." - (alist-get (completing-read prompt - kagi--languages - nil - nil - nil - kagi--language-history - "English") - kagi--languages)) + (completing-read prompt kagi--languages + nil + nil + nil + kagi--language-history + "English")) (defun kagi-translate (text target-language &optional source-language interactive-p) "Translate the TEXT to TARGET-LANGUAGE using FastGPT. From f62a79d84269992336b6808f17317167c510d60e Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Thu, 25 Jan 2024 12:30:07 +0100 Subject: [PATCH 10/15] Swap arguments, source and target language were flipped --- kagi.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kagi.el b/kagi.el index 7d442a3..641e851 100644 --- a/kagi.el +++ b/kagi.el @@ -443,10 +443,10 @@ result is short, otherwise it is displayed in a new buffer." (let* ((prompt (format "Translate the following text %sto %s: %s" - target-language (if source-language (format "from %s " source-language) "") + target-language text)) (result (kagi-fastgpt prompt)) (result-lines (length (string-lines result)))) From eabf43c3d1f37700f49100df01a3bb5cd3e4d4fe Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Thu, 25 Jan 2024 12:50:57 +0100 Subject: [PATCH 11/15] Return buffer content if the user selected a buffer --- kagi.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kagi.el b/kagi.el index 641e851..886005f 100644 --- a/kagi.el +++ b/kagi.el @@ -435,7 +435,10 @@ result is short, otherwise it is displayed in a new buffer." (interactive (list (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) - (read-buffer (format-prompt "Buffer name or text" nil))) + (let ((buffer-or-text (read-buffer (format-prompt "Buffer name or text" nil)))) + (if (get-buffer buffer-or-text) + (buffer-string) + buffer-or-text))) (kagi--read-language (format-prompt "Target language" nil)) (when (equal current-prefix-arg '(4)) (kagi--read-language (format-prompt "Source language" nil))) From 2240dd4a47afa0ccb7f6dc88ac584cf3e8b120c4 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Fri, 26 Jan 2024 07:03:38 +0100 Subject: [PATCH 12/15] Handle case when no input is given to the translator --- kagi.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kagi.el b/kagi.el index 886005f..4895ecb 100644 --- a/kagi.el +++ b/kagi.el @@ -436,9 +436,9 @@ result is short, otherwise it is displayed in a new buffer." (list (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) (let ((buffer-or-text (read-buffer (format-prompt "Buffer name or text" nil)))) - (if (get-buffer buffer-or-text) - (buffer-string) - buffer-or-text))) + (cond ((get-buffer buffer-or-text) (buffer-string)) + ((< 0 (length buffer-or-text)) buffer-or-text) + (t (error "No buffer or text entered"))))) (kagi--read-language (format-prompt "Target language" nil)) (when (equal current-prefix-arg '(4)) (kagi--read-language (format-prompt "Source language" nil))) From 4ab79511c9190243ea9ed23ad4f087d6f6729ea1 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Fri, 26 Jan 2024 07:12:47 +0100 Subject: [PATCH 13/15] Trim the translation result Make sure the result is shown in the echo area when the translation is a single line followed by a number of trailing newlines. --- kagi.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kagi.el b/kagi.el index 4895ecb..061b578 100644 --- a/kagi.el +++ b/kagi.el @@ -451,7 +451,7 @@ result is short, otherwise it is displayed in a new buffer." "") target-language text)) - (result (kagi-fastgpt prompt)) + (result (string-trim (kagi-fastgpt prompt))) (result-lines (length (string-lines result)))) (cond ((and interactive-p (eql result-lines 1)) (message result)) ((and interactive-p (> result-lines 1)) (kagi--fastgpt-display-result result)) From b9f47b194cc0ed0f70bf734b7469320043404c53 Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Fri, 26 Jan 2024 17:58:04 +0100 Subject: [PATCH 14/15] Take the buffer content if a buffer was chosen --- kagi.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kagi.el b/kagi.el index 061b578..78fb01e 100644 --- a/kagi.el +++ b/kagi.el @@ -436,7 +436,9 @@ result is short, otherwise it is displayed in a new buffer." (list (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) (let ((buffer-or-text (read-buffer (format-prompt "Buffer name or text" nil)))) - (cond ((get-buffer buffer-or-text) (buffer-string)) + (cond ((get-buffer buffer-or-text) + (with-current-buffer buffer-or-text + (buffer-string))) ((< 0 (length buffer-or-text)) buffer-or-text) (t (error "No buffer or text entered"))))) (kagi--read-language (format-prompt "Target language" nil)) From e67b76b16322df5cd9a9fabe77ac4f2b4fcdd85f Mon Sep 17 00:00:00 2001 From: Bram Schoenmakers Date: Fri, 26 Jan 2024 17:59:15 +0100 Subject: [PATCH 15/15] Mention kagi-translate --- README.org | 1 + 1 file changed, 1 insertion(+) diff --git a/README.org b/README.org index 4f245ee..145b18b 100644 --- a/README.org +++ b/README.org @@ -26,6 +26,7 @@ Both functions are accessed through an [[https://help.kagi.com/kagi/api/overview - =kagi-fastgpt-shell= :: Opens a shell buffer in a new window where prompts can be typed. This Kagi FastGPT typically returns output based on actual search results. When point is on one of the listed URLs, press =C-c RET= to open it. - =kagi-fastgpt-prompt= :: Enter a prompt in the minibuffer and show the result in a separate buffer. With a universal prefix (=C-u=), the result is inserted at point. - =kagi-fastgpt= :: Function to retrieve a FastGPT response, to be used from Lisp code. +- =kagi-translate= :: This command translates strings or complete buffers to another language (including programming languages). ** Universal Summarizer