[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: [QUESTION] I have problem on my org-contacts capf function

From: Christopher M. Miles
Subject: [SOLVED] Re: [QUESTION] I have problem on my org-contacts capf function source code
Date: Thu, 18 Nov 2021 14:56:45 +0800
User-agent: mu4e 1.7.0; emacs 28.0.60

I found the problem reason.

> 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.

Here is my workable code:

#+begin_src emacs-lisp
(defun org-contacts-org-complete--annotation-function (candidate)
  "Return org-contacts tags of contact candidate."
  ;; TODO
  "Tags: ")

(defun org-contacts-org-complete--doc-function (candidate)
  "Return org-contacts content of contact candidate."
  (let ((name (plist-get candidate :name))
        (file (plist-get candidate :file))
        (position (plist-get candidate :position)))
     ;; 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))
               (t (org-narrow-to-subtree)))
         (buffer-substring (point-min) (point-max)))))))

(defun org-contacts-org-complete--location-function (candidate)
  "Return org-contacts location of contact 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))))

(defun org-contacts-org-complete-function ()
  "Function used in `completion-at-point-functions' in `org-mode' to complete 
  (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
            ;; (all-completions
            ;;  prefix
            ;;  (mapcar
            ;;   (lambda (contact) (plist-get contact :name))
            ;;   (org-contacts--all-contacts))
            ;;  'stringp)

             (lambda (_)
                (lambda (contact) (concat "@" (plist-get contact :name))) ; 
<----- prepend "@" solved the problem.

            ;; :predicate 'stringp
            ;; :exclusive 'no
            ;; properties check out `completion-extra-properties'
            ;; :annotation-function 
            ;; :exit-function ; TODO change completion candidate inserted 
contact name into org-contact link??

            ;; :company-docsig #'identity                                    ; 
            ;; :company-doc-buffer #'org-contacts-org-complete--doc-function ; 
doc popup
            ;; :company-location #'org-contacts-org-complete--location-function

;; (add-hook 'completion-at-point-functions 'org-contacts-org-complete-function 
nil 'local)

Also learned your other detailed suggestion. Learned lot from you. Thanks for 
your teaching. 😄

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

       IRC(freenode): stardiviner, Matrix: stardiviner
       GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]