emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/org-contacts f3fa9fc0b8 125/154: use less magic symbol


From: ELPA Syncer
Subject: [elpa] externals/org-contacts f3fa9fc0b8 125/154: use less magic symbol extract code
Date: Fri, 9 Sep 2022 15:58:54 -0400 (EDT)

branch: externals/org-contacts
commit f3fa9fc0b83b0ad3cd42cd73751e95950c49fe38
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>

    use less magic symbol extract code
    
    > #+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:]@").
---
 org-contacts.el | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/org-contacts.el b/org-contacts.el
index ec26017323..55054bdad6 100644
--- a/org-contacts.el
+++ b/org-contacts.el
@@ -677,9 +677,8 @@ description."
 
 (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))
+  (when-let* ((end (point))
+              (begin (save-excursion (skip-chars-backward "[:alnum:]@") 
(point)))
               (symbol (buffer-substring-no-properties begin end))
               (org-contacts-prefix-p (string-prefix-p "@" symbol))
               ;; (prefix (substring-no-properties symbol 1 nil))



reply via email to

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