From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Christopher M. Miles" Newsgroups: gmane.emacs.help Subject: Re: [QUESTION] I have problem on my org-contacts capf function source code Date: Mon, 15 Nov 2021 23:43:59 +0800 Message-ID: References: Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25633"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.0; emacs 28.0.60 Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 15 16:52:23 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mmeHN-0006P4-FI for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Nov 2021 16:52:21 +0100 Original-Received: from localhost ([::1]:56764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmeHL-00026n-Mn for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 15 Nov 2021 10:52:19 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:41966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmeGc-00026c-UR for help-gnu-emacs@gnu.org; Mon, 15 Nov 2021 10:51:34 -0500 Original-Received: from mail-vi1eur05olkn2013.outbound.protection.outlook.com ([40.92.90.13]:22657 helo=EUR05-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmeGa-0007A6-2j for help-gnu-emacs@gnu.org; Mon, 15 Nov 2021 10:51:34 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=haeL9KLwWMbVeyBwiZVjx5YiuVvpuWOAPGRrHFI26FzDfe0jnsSfhtgITUly/FfSkCbRpWnTz4P1afE6Gh3A6ED+2M4Se301eYW+mJZCvA1CGhIL/+2Du0GRhkqB0HCHiYnL0uvSSuK1gnteexEA7tHkLeC5W295r8iNGpXJq53Lq7KVBe+g6nx67g3ruN6s+032tkjCPIMtHSRiIF3gcAF1guNj3cH4e4prCYtPilJiYiXwlEr3pz89Ac/FSbWlJbIrvESUSLpiDIgtnHhUqIqqIrpULO0OmEQ59gjnuK1Y1w4C1crfF/YVhwrp5/r4ByuOh2raqSsLDbva7MxHvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LfPZg989QgybBeIWtkvwziIMGgJ5rExad1hR0a/ra4E=; b=i8oxdIf1vXBtwvvwneyjtOEhQQhuYkQJ8Liqt7pZXyUsTiSSMZ1nV12DmxUpcG8dbmtZ31FI/+a7luwMTcDGjqZCdmUYipTeF/AS3911Jj8ZB+/aWXyPEE5jOJjJOwzMrUs5uzlAKXLBgxw85aAo1wAQkKY5zPODLuqm/t0x0zUUDF3YmxAz03jH9kf9EAQKuDkgkjPAIFWzSgcVI2rIaM9AaZDHSovIQCKoc2vo8GkPVA+mr2NvVtXEGqwzbz7h8RYuTNyaMPPpN0fG+VV8bzN3UgzJqjt8/4oHB+hWBl3FwhSZZScfBI3OFUgnl4BInY0d0AhYWjRrjuolLOGzgg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LfPZg989QgybBeIWtkvwziIMGgJ5rExad1hR0a/ra4E=; b=l8wlN3KzVqyrlbW/wR5t0ZI9K4XK0Rg06UUmp2jIhzicSt+6ZXTG1R25SaWjNCu3JhhiydUgfIasP1HYlUp7pinHBXlngRLENZ9rSTfPvIl6mDrZjjhAdKHe2UQZl0pqpzMoTvPvvG8QMbiHT4PRpIl5rTYOHBrISQlEvzEuUfJ7WpmM2WKxxP6Qn0Rh77Zy74JOWUT1iAWAEuKkBygaaUnbioKKuA5k8S4/oaOTpEAc43957RBYu/DM2MPf8awmvK6V+qspGhA8PCGaoSMB7fwjlk0tu1W7zoyiVvRmm1MNDlOzESh7tRzCChC4PiTR3VsMPT8K246iHaqEFmLZuQ== Original-Received: from PAXPR08MB6640.eurprd08.prod.outlook.com (2603:10a6:102:dd::5) by PAXPR08MB6351.eurprd08.prod.outlook.com (2603:10a6:102:15b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4649.15; Mon, 15 Nov 2021 15:51:28 +0000 Original-Received: from PAXPR08MB6640.eurprd08.prod.outlook.com ([fe80::90c1:4e36:aaac:49d0]) by PAXPR08MB6640.eurprd08.prod.outlook.com ([fe80::90c1:4e36:aaac:49d0%6]) with mapi id 15.20.4690.027; Mon, 15 Nov 2021 15:51:28 +0000 In-reply-to: X-TMN: [EY3b1RFZmkNM9gCmRqj4Qh/1Vu+XOswx] X-ClientProxiedBy: HK2PR04CA0063.apcprd04.prod.outlook.com (2603:1096:202:14::31) To PAXPR08MB6640.eurprd08.prod.outlook.com (2603:10a6:102:dd::5) X-Microsoft-Original-Message-ID: X-MS-Exchange-MessageSentRepresentingType: 2 Original-Received: from Mac-mini.local (115.231.16.203) by HK2PR04CA0063.apcprd04.prod.outlook.com (2603:1096:202:14::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.25 via Frontend Transport; Mon, 15 Nov 2021 15:51:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a9b00341-38bd-42e4-aea4-08d9a84fc895 X-MS-TrafficTypeDiagnostic: PAXPR08MB6351: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I75ungEH7zWnF7g5pDzXsjYJpl61WR9G1OMp2Mtxr8M/34Kc71fqzb6SPZWzyhHc1gSajoDBOhcd7zDqitjQbMjlIlgDZd2nOqOXJU2xyBzkPy3Y3LR68VJsZJ9QyekOyt8EWRMgmo2Su7Y1iWcgt6JvI5RCHdRrNTHPSUE7lRLcH6KNaSCkh+a9Od4xAaJavMPfM9IFos6WNCYICy/ZGfPDf+dBLJulh7ScfHNNQ2nIupOp6n8CzHcuO2Vtx+lD9b+JabMEaQhTDwImnfn9ndmlC2ecOXXUph5gmmgXu/gj9NU5VXJXpgnaWjqGSj76R9i+BKcomqSGz9dAYgUKmlrv64CdibQdHfUMOFHV2gzvB3jkla1NR34vh7tkXuq22CX4JCo8i7DEqVJ6tOxQ8M6bDX4QUXMmSnvTjQQj4ciJ5TX1L0jau0z8oxU/TnfSWBouiQQsIuQVMEK6oIZC1Dqhak1fQBtlyaetDvqfA+V4PI1S3N7ud1QN+eXgAFfJgiPYhsjpzXU45ECUOGHar0F6amBHT3H+u2hZoweo5n0XO6/JbfaA39bMdwMipH9dR35te6mtcE3t2xvE2bRMUA== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aRdn+5Bina71xxmmANg8/qjFCplJpEABgM6SQ6URY0X5Up06GTtGp5iuXZeCqFu9ZqfXsQxBzT9adB2WLxcUTzrtzQPnIXf6SI49eDz8oC/UapMqtEsnR16hjSH3NybxJHJLh1JkFFOZB+8UZwjnQ8L/Saoz1bVjT8/fNkykL/P7RsCEsvTPg6XjJiwsYiOZGqoBLoO1DOOKiP4VdkvRvGiOWOTW809DDN+00QQOFRMlsr1NGqEMOll+s2XdCOIZFhWc/TgIZ22dTr/mVzBTamwFUuPxRRe/zDjJdoheRBG6JjUu2XSpW0KBLNFnCDllQmsRWptYAfdPcvTFDMh17Tl7T90LOQMwkNEmvHustG9K8mEEujQsfnYWCZBR1pbnpVbd9CW5o9Zqo9sVvm+xO2TNNBrvKHfpjWi25Y8KeRQYBaSQh5lwZmcR6sz7ajT+awJXfwLTvCYcWOSdPyJ4dgIzGNdAA0cxUiJHopMkIhIMFLIoDxBeMHTaiWtdBS+gPT3SxmgHU4+N1K6I7GK6uSXE/TbgmcypI4phzbgVt0WpwfauhU3jrGUNMKkOYHVRaF90YwdDaye1ZLj31iiLcPquhAsCzCb1RW4dERY7cwfHUhrjhVQaHJmWa5O35TNkFNBKFWdw2ZOskmsK8fLzsIQuotNSiut517dP4dMaui1OHB6HTw9l899cb0S/NMf3mrUJ6NU77/AV4n4JzB8fpQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a9b00341-38bd-42e4-aea4-08d9a84fc895 X-MS-Exchange-CrossTenant-AuthSource: PAXPR08MB6640.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2021 15:51:28.0199 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6351 Received-SPF: pass client-ip=40.92.90.13; envelope-from=stardiviner@outlook.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: 4 X-Spam_score: 0.4 X-Spam_bar: / X-Spam_report: (0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, MSGID_FROM_MTA_HEADER=0.001, NML_ADSP_CUSTOM_MED=0.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:134611 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Stefan Monnier via Users list for the GNU Emacs text editor writes: >> (add-hook 'completion-at-point-functions 'org-contacts-org-complete-func= tion nil 'local) > > I assume you're careful to run this `add-hook` in the appropriate buffer > (otherwise, of course it won't do anything useful ;-) > I test this `add-hook` in org-mode buffer and elisp-mode buffer. >> When I evaluated upper code, and test by typing in "@Chri", I have not s= een org-contacts related >> complete popup candidates. > > Try `M-x trace-function RET org-contacts-org-complete-function RET`. > Also you may prefer to first just try > > M-: (org-contacts-org-complete-function) RET > > and make sure that what it returns makes sense. > Then > > M-: (all-completions "Chr" (nth 2 (org-contacts-org-complete-function= ))) RET > > Maybe try also > > M-: (all-completions "@Chr" (nth 2 (org-contacts-org-complete-functio= n))) RET > > then check whether the BEG..END area returned by > `org-contacts-org-complete-function` contains "@Chr" or "Chr". I followed your steps. Got following trace output: #+begin_example =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (org-contacts-org-complete-function) 1 <- org-contacts-org-complete-function: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (org-contacts-org-complete-function) 1 <- org-contacts-org-complete-function: nil =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 -> (org-contacts-org-complete-function) 1 <- org-contacts-org-complete-function: nil #+end_example I found ~org-contacts-org-complete-function~ returned a special value: #+begin_example #f(compiled-function (string pred action) #) #+end_example And this code, #+begin_src emacs-lisp (completion-table-dynamic (lambda (_) (mapcar (lambda (contact) (plist-get contact :name)) (org-contacts--all-contacts)))) #+end_src returned following: #+begin_example #[771 "....." [(lambda (_) (mapcar ... ...)) nil boundaries metadata minibu= ffer-selected-window window-live-p window-buffer complete-with-action] 8 " (fn STRING PRED ACTION)"] #+end_example Don't know whether this is correct. I can confirm the bellowing basic completion with ~try-completion~ code wor= ks fine: #+begin_src emacs-lisp (try-completion "tri" (mapcar (lambda (contact) (plist-get contact :name)) (org-contacts--all-contacts))) #+end_src # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D At last, I paste my latest simple code version: #+begin_src emacs-lisp (defun org-contacts-org-complete-function () "Function used in `completion-at-point-functions' in `org-mode' to comple= te @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 And test with execute following ~add-hook~ in org-mode buffer or emacs-lisp= -mode buffer: #+begin_src emacs-lisp (add-hook 'completion-at-point-functions 'org-contacts-org-complete-functio= n nil 'local) #+end_src =2D-=20 [ 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 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAmGSgfMACgkQG13xyVro msOc8wf+P1vXHT2UxNbIZTaWx6//eYLGAD1HyMkhKImgVmUM+wm2kXHvB3CpVoUA y4gVD00V5Oq4/y9GGgrSXtCJ1BfwLpBGKkAuM44Jke98LomCnew7s9f5Zx/QI3ag s4YN4JYYZkRBMq0WwidUStx9pLfnQG32sFxprguq5k85rsosQGWGSmTZqjReniNy SoYE2uIOkl9inyMe1DqnIf8RDTXrudiDzrX+h8P69MJCzLxXVSd56BoFcQaSFfU1 u4MPIazJHp661b84697xuaZQ8TrXTTz57yfHsfexFV5JDvxN1D6G48ONzk8L7B3k r3zGBfkT2mi0Vo9wgv6gTVTCg62nhQ== =qgcI -----END PGP SIGNATURE----- --=-=-=--