branch: externals/ellama commit 80bdeab8f1890d1a74477ca68a53b306d4d73243 Author: Sergey Kostyaev <sskosty...@gmail.com> Commit: Sergey Kostyaev <sskosty...@gmail.com>
Add info node to context. Fix some org links. --- README.org | 5 +++++ ellama.el | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index ed09e41aa5..49017d0cb9 100644 --- a/README.org +++ b/README.org @@ -203,6 +203,10 @@ Add buffer to context. Add selected region to context. +*** ellama-context-add-info-node + +Add info node to context. + ** Keymap Here is a table of keybindings and their associated functions in @@ -237,6 +241,7 @@ Ellama, using the ~ellama-keymap-prefix~ prefix (not set by default): | "x b" | ellama-context-add-buffer | Context add buffer | | "x f" | ellama-context-add-file | Context add file | | "x s" | ellama-context-add-selection | Context add selection | +| "x i" | ellama-context-add-info-node | Context add info node | | "p s" | ellama-provider-select | Provider select | ** Configuration diff --git a/ellama.el b/ellama.el index 1712325fce..f511819fd3 100644 --- a/ellama.el +++ b/ellama.el @@ -39,6 +39,7 @@ (require 'llm) (require 'spinner) (require 'dash) +(require 'info) (eval-when-compile (require 'rx)) (defgroup ellama nil @@ -126,6 +127,7 @@ (define-key map (kbd "x b") 'ellama-context-add-buffer) (define-key map (kbd "x f") 'ellama-context-add-file) (define-key map (kbd "x s") 'ellama-context-add-selection) + (define-key map (kbd "x i") 'ellama-context-add-info-node) ;; provider (define-key map (kbd "p s") 'ellama-provider-select) map) @@ -727,15 +729,30 @@ If EPHEMERAL non nil new session will not be associated with any file." (push (cons 'text content) (ellama-session-context session)) (push (cons 'text content) ellama--new-session-context))) +;;;###autoload +(defun ellama-context-add-info-node (node) + "Add info NODE to context." + (interactive (list (Info-copy-current-node-name))) + (if-let* ((id ellama--current-session-id) + (session (with-current-buffer (ellama-get-session-buffer id) + ellama--current-session))) + (push (cons 'info node) (ellama-session-context session)) + (push (cons 'info node) ellama--new-session-context))) + (defun ellama--org-format-context-element (elt) "Format context ELT for org mode." (pcase (car elt) ('file - (format "file:%s" (cdr elt))) + (format "[[file:%s][%s]]" (cdr elt) (cdr elt))) ('buffer - (format "elisp:(display-buffer \"%s\")" (cdr elt))) + (format "[[elisp:(display-buffer \"%s\")][%s]]" (cdr elt) (cdr elt))) ('text (cdr elt)) + ('info + (format "[[%s][%s]]" + (replace-regexp-in-string + "(\\(.?*\\)) \\(.*\\)" "info:\\1#\\2" (cdr elt)) + (cdr elt))) (_ (user-error "Unsupported context element")))) @@ -750,6 +767,8 @@ If EPHEMERAL non nil new session will not be associated with any file." (format "```emacs-lisp\n(display-buffer \"%s\")\n```\n" (cdr elt))) ('text (cdr elt)) + ('info + (format "```emacs-lisp\n(info \"%s\")\n```\n" (cdr elt))) (_ (user-error "Unsupported context element")))) @@ -762,6 +781,9 @@ If EPHEMERAL non nil new session will not be associated with any file." ('file (with-temp-buffer (find-file-literally (cdr elt)) (buffer-substring-no-properties (point-min) (point-max)))) + ('info (with-temp-buffer + (info (cdr elt) (current-buffer)) + (buffer-substring-no-properties (point-min) (point-max)))) (_ (user-error "Unsupported context element"))))