all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [QUESTION] I have problem on my org-contacts capf function source code
@ 2021-11-14  9:59 Christopher M. Miles
  2021-11-14 23:10 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 7+ messages in thread
From: Christopher M. Miles @ 2021-11-14  9:59 UTC (permalink / raw)
  To: Emacs Help

[-- Attachment #1: Type: text/plain, Size: 3309 bytes --]


I try to write a capf function for org-contacts to auto complete contact names after "@". Here is my
code, but it still does not work. Can someone help me to review my code and figure out the problem.
If you provide problem solution is welcome. Thanks a lot.

#+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* ((@-prefix-p (string-prefix-p "@" (thing-at-point 'symbol)))
              (symbol (thing-at-point 'symbol))
              (prefix (substring-no-properties symbol 1 nil))
              (bounds (bounds-of-thing-at-point 'symbol))
              (begin (car bounds))
              (end (cdr bounds)))
    (list begin
          end
          (all-completions
           prefix
           (mapcar
            (lambda (contact) (plist-get contact :name))
            (org-contacts--all-contacts))
           'stringp)

          ;; (completion-table-dynamic
          ;;  (lambda (input)
          ;;    (mapcar
          ;;     (lambda (contact) (plist-get contact :name))
          ;;     (org-contacts--all-contacts))))

          :exclusive 'no
          :annotation-function          ; tags
          ;; TODO
          (lambda (candidate)
            "Tags: ")
          :company-docsig #'identity         ; metadata
          :company-doc-buffer                ; doc popup
          (lambda (candidate)
            (let ((name (plist-get candidate :name))
                  (file (plist-get candidate :file))
                  (position (plist-get candidate :position)))
              (company-doc-buffer
               ;; get org-contact headline and property drawer.
               (with-current-buffer (find-file-noselect file)
                 (goto-char position)
                 (when (derived-mode-p 'org-mode)
                   ;; `org-edit-src-code' is not a real narrowing command.
                   ;; Remove this first conditional if you don't want it.
                   (cond ((ignore-errors (org-edit-src-code))
                          (delete-other-windows))
                         ((org-at-block-p)
                          (org-narrow-to-block))
                         (t (org-narrow-to-subtree)))
                   (buffer-substring (point-min) (point-max)))))))
          :company-location (lambda (candidate)
                              (let ((name (plist-get candidate :name))
                                    (file (plist-get candidate :file))
                                    (position (plist-get candidate :position)))
                                (with-current-buffer (find-file-noselect file)
                                  (goto-char position)
                                  (cons (current-buffer) position)))))))

;;; @Chr
(add-hook 'completion-at-point-functions 'org-contacts-completion-at-point nil 'local)
;; (add-to-list 'completion-at-point-functions 'org-contacts-completion-at-point)
#+end_src


-- 
[ stardiviner ]
       I try to make every word tell the meaning that I want to express.

       Blog: https://stardiviner.github.io/
       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-11-18  6:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-14  9:59 [QUESTION] I have problem on my org-contacts capf function source code Christopher M. Miles
2021-11-14 23:10 ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-11-15  9:05   ` Christopher M. Miles
2021-11-15 13:50     ` Stefan Monnier via Users list for the GNU Emacs text editor
2021-11-15 15:43       ` Christopher M. Miles
2021-11-15 21:30         ` Stefan Monnier
2021-11-18  6:56           ` [SOLVED] " Christopher M. Miles

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.