emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ellama d3cc009816 2/7: Merge pull request #140 from s-k


From: ELPA Syncer
Subject: [elpa] externals/ellama d3cc009816 2/7: Merge pull request #140 from s-kostyaev/improve-quotes
Date: Wed, 10 Jul 2024 15:58:17 -0400 (EDT)

branch: externals/ellama
commit d3cc009816b15a54a188946af102d2902014a09f
Merge: 811d6aa821 ac523d9f23
Author: Sergey Kostyaev <s-kostyaev@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #140 from s-kostyaev/improve-quotes
    
    Add link to quoted content in a separate buffer
---
 ellama.el            | 29 ++++++++++++++++++++++-------
 tests/test-ellama.el | 12 ++++++------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/ellama.el b/ellama.el
index 4ad5e7e5ab..f61bbdb5f2 100644
--- a/ellama.el
+++ b/ellama.el
@@ -956,6 +956,15 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
   "Extract the content of the context ELEMENT."
   (oref element content))
 
+(defun ellama--quote-buffer (quote)
+  "Return buffer name for QUOTE."
+  (let* ((buf-name (concat (make-temp-name "*ellama-quote-") "*"))
+        (buf (get-buffer-create buf-name t)))
+    (with-current-buffer buf
+      (with-silent-modifications
+       (insert quote)))
+    buf-name))
+
 (cl-defmethod ellama-context-element-format
   ((element ellama-context-element-webpage-quote) (mode (eql 'markdown-mode)))
   "Format the context ELEMENT for the major MODE."
@@ -965,7 +974,9 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
        (format "[%s](%s):\n%s\n\n"
                name url
                (ellama--md-quote content))
-      (format "[%s](%s)" name url))))
+      (format
+       "[%s](%s):\n```emacs-lisp\n(display-buffer \"%s\")\n```\n"
+       name url (ellama--quote-buffer content)))))
 
 (defun ellama--md-quote (content)
   "Return quoted CONTENT for markdown."
@@ -992,7 +1003,8 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
     (if ellama-show-quotes
        (format "[[%s][%s]]:\n#+BEGIN_QUOTE\n%s\n#+END_QUOTE\n"
                url name (ellama--org-quote content))
-      (format "[[%s][%s]]" url name))))
+      (format "[[%s][%s]] [[elisp:(display-buffer \"%s\")][show]]"
+             url name (ellama--quote-buffer content)))))
 
 ;; Info node quote context elements
 
@@ -1015,7 +1027,7 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
        (format "```emacs-lisp\n(info \"%s\")\n```\n%s\n\n"
                name
                (ellama--md-quote content))
-      (format "```emacs-lisp\n(info \"%s\")\n```\n" name))))
+      (format "```emacs-lisp\n(info 
\"%s\")\n```\nshow:\n```emacs-lisp\n(display-buffer \"%s\")\n```\n" name 
(ellama--quote-buffer content)))))
 
 (cl-defmethod ellama-context-element-format
   ((element ellama-context-element-info-node-quote) (mode (eql 'org-mode)))
@@ -1031,13 +1043,14 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
                    (ellama--translate-string name)
                  name)
                (ellama--org-quote content))
-      (format "[[%s][%s]]"
+      (format "[[%s][%s]] [[elisp:(display-buffer \"%s\")][show]]"
              (replace-regexp-in-string
               "(\\(.?*\\)) \\(.*\\)" "info:\\1#\\2" name)
              (if (and ellama-chat-translation-enabled
                       (not ellama--current-session))
                  (ellama--translate-string name)
-               name)))))
+               name)
+             (ellama--quote-buffer content)))))
 
 ;; File quote context elements
 
@@ -1060,7 +1073,8 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
        (format "[%s](%s):\n%s\n\n"
                path path
                (ellama--md-quote content))
-      (format "[%s](%s)" path path))))
+      (format "[%s](%s):\n```emacs-lisp\n(display-buffer \"%s\")"
+             path path (ellama--quote-buffer content)))))
 
 (cl-defmethod ellama-context-element-format
   ((element ellama-context-element-file-quote) (mode (eql 'org-mode)))
@@ -1070,7 +1084,8 @@ If EPHEMERAL non nil new session will not be associated 
with any file."
     (if ellama-show-quotes
        (format "[[%s][%s]]:\n#+BEGIN_QUOTE\n%s\n#+END_QUOTE\n"
                path path (ellama--org-quote content))
-      (format "[[%s][%s]]" path path))))
+      (format "[[%s][%s]] [[elisp:(display-buffer \"%s\")][show]]"
+             path path (ellama--quote-buffer content)))))
 
 
 ;;;###autoload
diff --git a/tests/test-ellama.el b/tests/test-ellama.el
index 2d1fc4fad8..e102da4813 100644
--- a/tests/test-ellama.el
+++ b/tests/test-ellama.el
@@ -89,7 +89,7 @@
 (ert-deftest 
test-ellama-context-element-format-webpage-quote-disabled-markdown ()
   (let ((element (ellama-context-element-webpage-quote :name "test name" :url 
"https://example.com/"; :content "1\n\n2"))
        (ellama-show-quotes nil))
-    (should (equal "[test name](https://example.com/)" 
(ellama-context-element-format element 'markdown-mode)))))
+    (should (string-match "\\[test 
name\\](https://example.com/):\n```emacs-lisp\n(display-buffer 
\"\\*ellama-quote-.+\\*\")\n```\n" (ellama-context-element-format element 
'markdown-mode)))))
 
 (ert-deftest test-ellama-context-element-format-webpage-quote-enabled-markdown 
()
   (let ((element (ellama-context-element-webpage-quote :name "test name" :url 
"https://example.com/"; :content "1\n\n2"))
@@ -105,7 +105,7 @@
 (ert-deftest 
test-ellama-context-element-format-webpage-quote-disabled-org-mode ()
   (let ((element (ellama-context-element-webpage-quote :name "test name" :url 
"https://example.com/"; :content "1\n\n2"))
        (ellama-show-quotes nil))
-    (should (equal "[[https://example.com/][test name]]" 
(ellama-context-element-format element 'org-mode)))))
+    (should (string-match "\\[\\[https://example.com/\\]\\[test name\\]\\] 
\\[\\[elisp:(display-buffer \"\\*ellama-quote-.+\\*\")\\]\\[show\\]\\]" 
(ellama-context-element-format element 'org-mode)))))
 
 (ert-deftest test-ellama-context-element-format-webpage-quote-enabled-org-mode 
()
   (let ((element (ellama-context-element-webpage-quote :name "test name" :url 
"https://example.com/"; :content "1\n\n* 2"))
@@ -122,7 +122,7 @@
 (ert-deftest 
test-ellama-context-element-format-info-node-quote-disabled-markdown ()
   (let ((element (ellama-context-element-info-node-quote :name "(emacs)Top" 
:content "1\n\n2"))
        (ellama-show-quotes nil))
-    (should (equal "```emacs-lisp\n(info \"(emacs)Top\")\n```\n" 
(ellama-context-element-format element 'markdown-mode)))))
+    (should (string-match "```emacs-lisp\n(info 
\"(emacs)Top\")\n```\nshow:\n```emacs-lisp\n(display-buffer 
\"\\*ellama-quote-.+\\*\")\n```\n" (ellama-context-element-format element 
'markdown-mode)))))
 
 (ert-deftest 
test-ellama-context-element-format-info-node-quote-enabled-markdown ()
   (let ((element (ellama-context-element-info-node-quote :name "(emacs)Top" 
:content "1\n\n2"))
@@ -133,7 +133,7 @@
 (ert-deftest 
test-ellama-context-element-format-info-node-quote-disabled-org-mode ()
   (let ((element (ellama-context-element-info-node-quote :name "(emacs)Top" 
:content "1\n\n2"))
        (ellama-show-quotes nil))
-    (should (equal "[[(emacs)Top][(emacs)Top]]" (ellama-context-element-format 
element 'org-mode)))))
+    (should (string-match "\\[\\[(emacs)Top\\]\\[(emacs)Top\\]\\] 
\\[\\[elisp:(display-buffer \"\\*ellama-quote-.+\\*\")\\]\\[show\\]\\]" 
(ellama-context-element-format element 'org-mode)))))
 
 (ert-deftest 
test-ellama-context-element-format-info-node-quote-enabled-org-mode ()
   (let ((element (ellama-context-element-info-node-quote :name "(emacs)Top" 
:content "1\n\n* 2"))
@@ -144,7 +144,7 @@
 (ert-deftest test-ellama-context-element-format-file-quote-disabled-markdown ()
   (let ((element (ellama-context-element-file-quote :path "/tmp/test.txt" 
:content "1\n\n2"))
        (ellama-show-quotes nil))
-    (should (equal "[/tmp/test.txt](/tmp/test.txt)" 
(ellama-context-element-format element 'markdown-mode)))))
+    (should (string-match 
"\\[/tmp/test.txt\\](/tmp/test.txt):\n```emacs-lisp\n(display-buffer 
\"\\*ellama-quote-.+\\*\")" (ellama-context-element-format element 
'markdown-mode)))))
 
 (ert-deftest test-ellama-context-element-format-file-quote-enabled-markdown ()
   (let ((element (ellama-context-element-file-quote :path "/tmp/test.txt" 
:content "1\n\n2"))
@@ -160,7 +160,7 @@
 (ert-deftest test-ellama-context-element-format-file-quote-disabled-org-mode ()
   (let ((element (ellama-context-element-file-quote :path "/tmp/test.txt" 
:content "1\n\n2"))
        (ellama-show-quotes nil))
-    (should (equal "[[/tmp/test.txt][/tmp/test.txt]]" 
(ellama-context-element-format element 'org-mode)))))
+    (should (string-match "\\[\\[/tmp/test.txt\\]\\[/tmp/test.txt\\]\\] 
\\[\\[elisp:(display-buffer \"\\*ellama-quote-.+\\*\")\\]\\[show\\]\\]" 
(ellama-context-element-format element 'org-mode)))))
 
 (ert-deftest test-ellama-context-element-format-file-quote-enabled-org-mode ()
   (let ((element (ellama-context-element-file-quote :path "/tmp/test.txt" 
:content "1\n\n* 2"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]