> #+begin_src emacs-lisp
> (defun org-contacts-org-complete-function ()
> "Function used in `completion-at-point-functions' in `org-mode' to complete @name."
> (when-let* ((bounds (bounds-of-thing-at-point 'symbol))
> (begin (1- (car bounds)))
> (end (cdr bounds))
> (symbol (buffer-substring-no-properties begin end))
> (org-contacts-prefix-p (string-prefix-p "@" symbol))
> ;; (prefix (substring-no-properties symbol 1 nil))
> )
> (when org-contacts-prefix-p
> (list begin
> end
> (completion-table-dynamic
> (lambda (_)
> (mapcar
> (lambda (contact) (plist-get contact :name))
> (org-contacts--all-contacts))))))))
> #+end_src
This gives a `begin..end` region which presumably includes `@`.
Does (plist-get contact :name) return names that start with `@`?
If not, the completion will never match.
> And test with execute following ~add-hook~ in org-mode buffer or
> emacs-lisp-mode buffer:
In emacs-lisp-mode, `@` has symbol syntax, so
(bounds-of-thing-at-point 'symbol)
will include `@` in the returned region, whereas in Org mode
`@` seems to have punctuation syntax so the `@` will not be included in
the returned region.
Maybe instead of `bounds-of-thing-at-point` you want to use something
less "magic", like (skip-chars-backward "[:alnum:]@").
> I found ~org-contacts-org-complete-function~ returned a special value:
>
> #+begin_example
> #f(compiled-function (string pred action) #<bytecode -0x9e1a398d61d3acb>)
> #+end_example
I can't see any way M-: (org-contacts-org-complete-function) RET
can return the above value. So I suspect a "pilot error".
This looks like the 3rd value in the returned list (i.e. the value
returned by `completion-table-dynamic`).
> #+begin_src emacs-lisp
> (defun org-contacts-org-complete-function ()
> "Function used in `completion-at-point-functions' in `org-mode' to complete @name."
> (when-let* ((bounds (bounds-of-thing-at-point 'symbol))
> (begin (1- (car bounds)))
> (end (cdr bounds))
> (symbol (buffer-substring-no-properties begin end))
> (org-contacts-prefix-p (string-prefix-p "@" symbol))
> ;; (prefix (substring-no-properties symbol 1 nil))
> )
> (when org-contacts-prefix-p
> (list begin
> end
> (completion-table-dynamic
> (lambda (_)
> (mapcar
> (lambda (contact) (plist-get contact :name))
> (org-contacts--all-contacts))))))))
> #+end_src
This gives a `begin..end` region which presumably includes `@`.
Does (plist-get contact :name) return names that start with `@`?
If not, the completion will never match.
> And test with execute following ~add-hook~ in org-mode buffer or
> emacs-lisp-mode buffer:
In emacs-lisp-mode, `@` has symbol syntax, so
(bounds-of-thing-at-point 'symbol)
will include `@` in the returned region, whereas in Org mode
`@` seems to have punctuation syntax so the `@` will not be included in
the returned region.
Maybe instead of `bounds-of-thing-at-point` you want to use something
less "magic", like (skip-chars-backward "[:alnum:]@").
> #+begin_src emacs-lisp
> (add-hook 'completion-at-point-functions 'org-contacts-org-complete-function nil 'local)
> #+end_src
> I have get response from Strey, he said he has requested FSF for
> signing paperwork, should be ready in days.
In the mean time, here's a patch which addresses most of the compiler
warnings I got. It also adds a `Version:` since that'll be necessary
for the package to be released on GNU ELPA. And it furthermore adds
a few FIXMEs which you might want to look at.
Stefan
* org-contacts.el (org-contacts-link-store): Use `bound-and-true-p' to
check the truthiness of org-id-link-to-org-use-id, which may or may
not be bound depending on whether org-id has been loaded. This
simplifies the code.
* contrib/lisp/org-contacts.el (org-contacts-link-store): Store a link
of org-contacts in Org file.
* contrib/lisp/org-contacts.el (org-contacts-link-open): Open contact:
link in Org file.
* contrib/lisp/org-contacts.el (org-contacts-link-complete): Insert a
contact: link with completion of contacts.
* contrib/lisp/org-contacts.el (org-contacts-link-face): Set different
face for contact: link.
* lisp/org.el (org-find-if): Remove function.
(org-key):
* contrib/lisp/org-contacts.el (org-contacts-db-need-update-p):
(org-contacts-filter):
(org-contacts-test-completion-prefix):
(org-contacts-remove-ignored-property-values): Use `cl-find-if'
* lisp/org-compat.el (org-find-if): Mark function as an obsolete alias
for `cl-find-if'.
* lisp/org.el (org-show-context-detail): Change default visibility span
for agenda context.
* lisp/org-agenda.el (org-agenda-goto):
(org-agenda-todo):
(org-agenda-add-note):
(org-agenda-priority):
(org-agenda-set-tags):
(org-agenda-set-property):
(org-agenda-set-effort):
(org-agenda-toggle-archive-tag):
(org-agenda-clock-in): Special visibility is taken care of by
`org-show-context'. Do not hard-code anything else.
* contrib/lisp/org-contacts.el (org-contacts-gnus-article-from-goto):
Special visibility is taken care of by `org-show-context'. Do not
hard-code anything else.
* lisp/org.el (org-make-tags-matcher): Return a function instead of
a sexp. Refactor code.
(org--matcher-tags-todo-only): New variable. Replace `todo-only'
dynamic binding.
(org-scan-tags): Apply changes to `org-make-tags-matcher'.
(org-match-sparse-tree):
(org-map-entries): Use new variable.
* lisp/org-crypt.el (org-encrypt-entries):
(org-decrypt-entries): Use new variable.
* lisp/org-clock.el (org-clock-get-table-data): Apply changes to
`org-make-tags-matcher'.
* lisp/org-agenda.el (org-tags-view): Use new variable.