ahyatt / ekg

The emacs knowledge graph, app for notes and structured data.
GNU General Public License v3.0
230 stars 19 forks source link

Company error in the ekg-capture buffer #89

Closed Gleek closed 1 year ago

Gleek commented 1 year ago

The (company-capf) command seems to error out when running in the ekg-capture buffer.

Following is the error backtrace I receive when this error happens:

Debugger entered--Lisp error: (args-out-of-range #<buffer *EKG Capture (note 33775668291)*> 26 25)
  company-capf(prefix)
  apply(company-capf prefix)
  company-call-backend-raw(prefix)
  company--force-sync(company-call-backend-raw (prefix) company-capf)
  company-call-backend(prefix)
  company--begin-new()
  company--perform()
  company-auto-begin()

The issue seems to be with the ekg--transclude-titled-note-completion function when the ">t" is not present in the line. Having a minor check to validate the value of begin fixes it in my case.

Here's the updated function I use:

(defun ekg--transclude-titled-note-completion ()
  "Completion function for file transclusion."
  (let ((begin (save-excursion
                 (search-backward ">t" (line-beginning-position) t)
                 (+ 1 (point))))
        (end (point)))
    (unless (> begin end)
      (list begin end
            (completion-table-dynamic (lambda (_)
                                        (mapcar (lambda (title-cons)
                                                  (cons (cdr title-cons)
                                                        (car title-cons)))
                                                (ekg-document-titles))))
            :exclusive t :exit-function #'ekg--transclude-cap-exit))))

My emacs is built from the master branch on 11th May 2023 and I'm using the latest stable ekg version (v0.3.3)

ahyatt commented 1 year ago

Thank you for the bug report and suggested fix! I'm not sure why company is different, but your code makes sense. I altered it slightly to clarify it and checked in a fix in the develop branch. I'm anticipating releasing the new version in the next month.