Skip to content

Commit

Permalink
When converting notes to text for LLMs, don't font-lock (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyatt authored Jan 12, 2025
1 parent 942457b commit aed37eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 2 additions & 0 deletions doc/ekg.org
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ triples library is already installed.
(require 'ekg)
#+end_src
* Changelog
** Version 0.6.5
- Speed up for LLM calls with notes as context
** Version 0.6.4
- Fix display of extended structured data in notes.
- Add contrib directory and =ekg-email= as a contribution to import emails to notes in a structured way.
Expand Down
10 changes: 10 additions & 0 deletions doc/ekg.texi
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Installation
Changelog
* Version 0.6.5: Version 065.
* Version 0.6.4: Version 064.
* Version 0.6.3: Version 063.
* Version 0.6.2: Version 062.
Expand Down Expand Up @@ -204,6 +205,7 @@ triples library is already installed.
@chapter Changelog

@menu
* Version 0.6.5: Version 065.
* Version 0.6.4: Version 064.
* Version 0.6.3: Version 063.
* Version 0.6.2: Version 062.
Expand All @@ -223,6 +225,14 @@ triples library is already installed.
* Version 0.2: Version 02.
@end menu

@node Version 065
@section Version 0.6.5

@itemize
@item
Speed up for LLM calls with notes as context
@end itemize

@node Version 064
@section Version 0.6.4

Expand Down
3 changes: 1 addition & 2 deletions ekg-llm.el
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ structs."
(let ((result `((tags . ,(ekg-note-tags note))
(created . ,(ekg-llm-format-time (ekg-note-creation-time note)))
(modified . ,(ekg-llm-format-time (ekg-note-modified-time note)))
(text . ,(substring-no-properties (substring-no-properties
(ekg-display-note-text note))))))
(text . ,(substring-no-properties (ekg-display-note-text note nil t)))))
(json-encoding-pretty-print t))
(when (ekg-should-show-id-p note)
(push (cons "id" (ekg-note-id note)) result))
Expand Down
21 changes: 14 additions & 7 deletions ekg.el
Original file line number Diff line number Diff line change
Expand Up @@ -769,26 +769,33 @@ However, if FORCE is non-nil, it will be shown regardless."
'face 'ekg-resource)
""))

(defun ekg-display-note-text (note &optional numwords)
(defun ekg-display-note-text (note &optional numwords plaintext)
"Return text, with mode-specific properties, of NOTE.
NUMWORDS is the max number of words to display in the note, or
nil for all words."
nil for all words.

If PLAINTEXT is non-nil, return the text without any formatting."
(with-temp-buffer
(when (ekg-note-text note)
(insert (ekg-insert-inlines-results
(ekg-note-text note)
(ekg-note-inlines note)
note)))
(when (ekg-note-mode note)
(when (and (not plaintext) (ekg-note-mode note))
(let ((mode-func (intern (format "%s-mode" (ekg-note-mode note)))))
(if (fboundp mode-func) (funcall mode-func)
(funcall (ekg-note-mode note)))))
(mapc #'funcall ekg-format-funcs)
(font-lock-ensure)
(put-text-property (point-min) (point-max) 'ekg-note-id (ekg-note-id note))
(unless plaintext
(font-lock-ensure)
(put-text-property (point-min) (point-max) 'ekg-note-id (ekg-note-id note)))
(concat (string-trim-right
(ekg-truncate-at (buffer-string)
(or numwords ekg-note-inline-max-words))) "\n")))
(let ((buftext (if plaintext
(buffer-substring-no-properties (point-min)(point-max))
(buffer-string))))
(if numwords
(ekg-truncate-at buftext (or numwords ekg-note-inline-max-words))
buftext))) "\n")))

(defun ekg-display-note-tagged (note)
"Return text of the tags of NOTE."
Expand Down

0 comments on commit aed37eb

Please sign in to comment.