Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

config example not setting capf correctly #2

Closed
bdarcus opened this issue May 16, 2022 · 18 comments
Closed

config example not setting capf correctly #2

bdarcus opened this issue May 16, 2022 · 18 comments

Comments

@bdarcus
Copy link

bdarcus commented May 16, 2022

Picking up where we earlier left off, in the hopes I can get this working, or it might help with the README instructions.

I do plan to test it with emacs -Q; I just need more time (maybe tomorrow).

If I add your use-package example, suitably modified for doom ...

Org

Value of completion-at-point-functions:

Its value is (pcomplete-completions-at-point t)
Local in buffer test.org; global value is 
(tags-completion-at-point-function citar-capf)

I do get corfu to activate with the citar completion. But if I hit RET on a candidate, it does not insert the key, but instead adds a newline to the buffer.

Aside: with the private doom corfu module I'm using, for other capfs (for example, in lisp buffers), when I highlight a candidate, it presents a preview, and when I hit RET it behaves as expected (inserts the candidate).

LaTeX

Its value is (TeX--completion-at-point t)
Local in buffer test.tex; global value is 
(tags-completion-at-point-function citar-capf)

Here I get no matches.

Markdown

No matches.

Its value is (citar-capf t)
Local in buffer test.md; global value is 
(tags-completion-at-point-function citar-capf)

Any suggestions? Is that setup as you expect with the variable?

@mclearc
Copy link
Contributor

mclearc commented May 16, 2022

I really have no idea why you're having the keybinding issue. I don't see why/how citar-capf would alter your keybinds for completion.

I was thinking though of making citar-capf a minor mode to make it easier to load in deferred loading scenarios. I could try setting a keymap and see if that helps.

Ideally citar-capf goes before the other completion frameworks. This isn't going to be consistent if you have it loading after those modes i've noticed. So one thing to check is whether you can add a hook to loading markdown and tex that runs when those modes are first loaded:

(defun citar-capf-hook () (add-hook 'completion-at-point-functions #'citar-capf -100 t))
  :config
  ;; Add hooks
(with-eval-after-load 'latex-mode
  (add-hook 'tex-mode-hook #'citar-capf-hook)
  (add-hook 'latex-mode-hook #'citar-capf-hook)
  (add-hook 'reftex-mode-hook #'citar-capf-hook))

(with-eval-after-load 'markdown-mode
  (add-hook 'markdown-mode-hook #'citar-capf-hook))

 (with-eval-after-load 'org-mode
(add-hook 'org-mode-hook #'citar-capf-hook))

EDIT: the reason you're getting no matches in latex and markdown modes is that the other completion table is clobbering citar-capf. This is why it is important that it get added first in the list (hence the -100 depth value).

@mclearc
Copy link
Contributor

mclearc commented May 16, 2022

FYI: I added a minor mode with new setup instructions that seem more reliable. See 16b5bad for details.

@bdarcus
Copy link
Author

bdarcus commented May 16, 2022

If I set the minor mode with a buffer open, it seems to set the capf correctly.

If I switch to another buffer, say in another major-mode, it doesn't. I have to deactivate and reactivate.

Do you see that?

@mclearc
Copy link
Contributor

mclearc commented May 16, 2022

I'm not seeing that. I can ping pong between an elisp, fundamental, org, and markdown buffer and the org and markdown completion works as expected.

@bdarcus
Copy link
Author

bdarcus commented May 16, 2022

OK; well that's good. Must be something with my system.

I'll take a closer look later, probably tomorrow.

EDIT: in the meantime, I've reported the bug on the doom discourse, assuming it's specific to doom, and have tried to setup lambda-emacs instead, though got stuck.

@bdarcus bdarcus changed the title not quite working config example not setting capf correctly May 16, 2022
@mclearc
Copy link
Contributor

mclearc commented May 17, 2022

FYI -- this seems to work from me with a minimal (basically emacs -Q with config necessary to load markdown, org, citar, corfu) setup. I noticed no issues with keybindings. Both return and tab complete and insert the candidate as expected.

Screen Shot 2022-05-17 at 11 40 00

@bdarcus
Copy link
Author

bdarcus commented May 17, 2022

May as well close this, and assume some weird doom conflict.

@bdarcus bdarcus closed this as completed May 17, 2022
@bdarcus
Copy link
Author

bdarcus commented May 17, 2022

Can you post the config file on a gist, or embedded here?

@mclearc
Copy link
Contributor

mclearc commented May 17, 2022

Try this (note you'll have to set the variables)

;;; CAPF Test
;;;; Set vars
(setq lem-bibliography (concat (getenv "HOME") "/Dropbox/Work/bibfile.bib"))
(setq lem-bib-notes (concat (getenv "HOME") "/Dropbox/Work/projects/notebook/content-org/ref-notes"))
;; Set citar library path
(with-eval-after-load 'citar
  (setq citar-library-paths '("/Users/roambot/Library/Mobile Documents/iCloud~com~sonnysoftware~bot/Documents/be-library")))

;;;; Citar
(use-package citar
  :straight (:host github :repo "bdarcus/citar")
  :custom
  (citar-bibliography `(,lem-bibliography))
  (org-cite-global-bibliography `(,lem-bibliography))
  (org-cite-insert-processor 'citar)
  (org-cite-follow-processor 'citar)
  (org-cite-activate-processor 'citar)
  :config
  ;; edit notes
  (setq citar-notes-paths `(,lem-bib-notes)))

;;;; Markdown
(use-package markdown-mode)

;;;; Org-Cite
;; Eventually this should be a full replacement for org-ref
(use-package oc
  :straight nil
  :after org
  :config
  (setq org-cite-global-bibliography `(,lem-bibliography))
  (setq org-cite-export-processors
        '((beamer csl)
          (latex csl)
          (t csl))))

;; Currently only using csl
(use-package oc-csl
  :straight nil
  :after oc
  :init
  ;; make sure to download csl
  ;; https://citationstyles.org
  ;; https://github.com/citation-style-language
  ;; repos for styles & locales
  (setq org-cite-csl-styles-dir "~/.local/share/csl/styles")
  (setq org-cite-csl-locales-dir "~/.local/share/csl/locales"))

;;;; Citeproc
(use-package citeproc
  :straight (:host github :repo "andras-simonyi/citeproc-el")
  :after (oc oc-csl))

;;;; Corfu
(use-package corfu
  :straight (:type git :host github :repo "minad/corfu")
  :hook
  (after-init . global-corfu-mode)
  :custom
  ;; auto-complete
  (corfu-auto t))

;;;; Citar-Capf
(use-package citar-capf
  :straight (:local-repo "/Users/roambot/bin/lisp-projects/citar-capf")
  :hook ((org-mode markdown-mode tex-mode latex-mode reftex-mode) . citar-capf-mode))

(defun capf-citar-test ()
  (interactive)
  (progn
    (require 'citar-capf)
    (markdown-mode)
    (switch-to-buffer "*scratch*")))

you can probably skip the org-cite stuff if you just want to check that it works via markdown.

@bdarcus
Copy link
Author

bdarcus commented May 17, 2022

Alas, that's incomplete, as it doesn't include the straight setup and such.

I really wish emacs made this part easier.

@mclearc
Copy link
Contributor

mclearc commented May 17, 2022

if you ever get lambda-emacs up and running 🤣 it has a command line switch -test that you can run that loads just the packages in lem-setup-test.el and the straight setup in init.el. Useful for testing without having to download all new packages etc.

@bdarcus
Copy link
Author

bdarcus commented Jun 2, 2022

You planning to add to MELPA, post an announcement on REDDIT?

@mclearc
Copy link
Contributor

mclearc commented Jun 2, 2022

You planning to add to MELPA, post an announcement on REDDIT?

Yes -- just need to find time. Hopefully in the next week or two. I've been working on https://github.com/mclear-tools/consult-notes a bit. If you have any interest in that package I appreciate any feedback.

@bdarcus
Copy link
Author

bdarcus commented Jun 2, 2022

Two related things on notes:

  1. I started this tiny project,, which led to ...
  2. this issue at org-roam: Allow more than one node associated with a ref? org-roam/org-roam#2207

2 is actually somewhat tricky conceptually and practically; please weigh in there if you have thoughts.

@bdarcus
Copy link
Author

bdarcus commented Jun 2, 2022

BTW, I'm not committed to finishing and releasing 1.

I am working on it mostly to ensure the notes API in citar is correct.

But it might be they're complementary. I agree using consult, with its support for narrowing and such, makes sense. I wasn't planning to add that to my package.

@bdarcus
Copy link
Author

bdarcus commented Jun 6, 2022

FYI, someone else confirmed a bug in doom that was causing the problem I was seeing with the capf (but later confirmed with others capfs).

https://discourse.doomemacs.org/t/new-completion-corfu-module/2685/15

@mclearc
Copy link
Contributor

mclearc commented Jun 8, 2022

You planning to add to MELPA, post an announcement on REDDIT?

FYI @bdarcus I've put an announcement on reddit. Hopefully I'll have time this weekend to submit it on melpa.

@bdarcus
Copy link
Author

bdarcus commented Jun 8, 2022

BTW, this major change will impact this code:

emacs-citar/citar#628

But should be easy to adapt.

@bdarcus bdarcus reopened this Jun 8, 2022
@bdarcus bdarcus closed this as completed Jun 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants