From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: Re: [patch] [3update] Add functions, Insert a exist contact name at point Date: Tue, 04 Jun 2013 11:29:46 +0800 Message-ID: <87txle1rkl.fsf_-_@news.tumashu-localhost.org> References: <87vc5vm96n.fsf@news.tumashu-localhost.org> <87r4gin68g.fsf@news.tumashu-localhost.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40115) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujhxg-0000UP-VM for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 23:31:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ujhxf-0005Km-DH for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 23:31:04 -0400 Received: from mail-pa0-x232.google.com ([2607:f8b0:400e:c03::232]:35298) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujhxf-0005Kg-3T for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 23:31:03 -0400 Received: by mail-pa0-f50.google.com with SMTP id fb1so91174pad.23 for ; Mon, 03 Jun 2013 20:31:02 -0700 (PDT) Received: from tumashu ([110.97.82.245]) by mx.google.com with ESMTPSA id vb8sm61378418pbc.11.2013.06.03.20.30.59 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Jun 2013 20:31:01 -0700 (PDT) Received: from feng by tumashu with local (Exim 4.80) (envelope-from ) id 1UjhwQ-00017a-SU for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 11:29:46 +0800 In-Reply-To: <87r4gin68g.fsf@news.tumashu-localhost.org> (Feng Shu's message of "Tue, 04 Jun 2013 07:07:27 +0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Feng Shu writes: > Feng Shu writes: > > I will change this patch again, hard coding a templates in functions > is not a good way , maybe it is a complex method to solve a simpe things. This is the 3rd patch, which has been changed significantly, The function will be useful when used in org-capture, I want it can be included into master when it mature! But there are some problems, I think it's org-capture's bug or limit: 1. works: #+begin_example ("c" "Contacts" entry (file "~/org/i-contacts.org") "* %(org-contacts-get-exist-contact-name-string fengshu)") #+end_example 2. doesn't work #+begin_example ("c" "Contacts" entry (file "~/org/i-contacts.org") "* %(org-contacts-get-exist-contact-name-string %^{prompt)") #+end_example --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-Insert-a-exist-contact-name-s-at-point.patch Content-Transfer-Encoding: quoted-printable >From 06055532dbadbfbcb620378eeec0c5e3c8ee8c0d Mon Sep 17 00:00:00 2001 From: Feng Shu Date: Mon, 3 Jun 2013 23:17:57 +0800 Subject: [PATCH] Insert (a) exist contact name(s) at point * org-contacts.el (org-contacts-get-exist-contact-name-list): New function, which can get exist contact name(s) matched 'string, return a list. (org-contacts-get-exist-contact-name-string): New macro, get exist contact name(s) matched 'string, return names string. (org-contacts-insert-contact-name): New function, which can insert (a) exist contact name(s) matched user's input at point. Add new functions, which can insert (a) exist contact name(s) at point, which is matched user's input. --- contrib/lisp/org-contacts.el | 36 ++++++++++++++++++++++++++++++++++++ 1 =E4=B8=AA=E6=96=87=E4=BB=B6=E8=A2=AB=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=8F=92= =E5=85=A5 36 =E8=A1=8C(+) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index 5d63fcc..e3f0729 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -967,6 +967,42 @@ is created and the VCard is written into that buffer." (current-buffer) (progn (save-buffer) (kill-buffer))))) =20 +(defun org-contacts-get-exist-contact-name-list (string) + "Get exist contact name(s) matched 'string, return a list." + (let ((contact-list (nconc + (org-contacts-filter + nil nil + (cons org-contacts-alias-property string)) + (org-contacts-filter string)))) + (setq result-name-list + (delete-dups + (loop for contact in contact-list + collect + (substring-no-properties + ((lambda (contact) + (let* ((name + (org-contacts-vcard-escape (car contact)))) name)) + contact)))))) + (if result-name-list result-name-list (list string))) + +(defmacro org-contacts-get-exist-contact-name-string (string) + "Get exist contact name(s) matched 'string, return names string." + (if (stringp string) + `(mapconcat 'identity (org-contacts-get-exist-contact-name-list ,stri= ng) " ") + `(mapconcat 'identity (org-contacts-get-exist-contact-name-list ,(forma= t "%s" string)) " "))) + +(defun org-contacts-insert-contact-name (string) + "At point insert (a) exist contact name(s) matched 'input." + (interactive (list (read-string "Contact Alias or Name: "))) + (current-buffer) + (let ((inhibit-read-only t))) + (when (fboundp 'set-buffer-file-coding-system) + (set-buffer-file-coding-system coding-system-for-write)) + (let ((name-list (org-contacts-get-exist-contact-name-list string))) + (while name-list + (insert (concat (car name-list) " ")) + (setq name-list (cdr name-list))))) + (defun org-contacts-show-map (&optional name) "Show contacts on a map. Requires google-maps-el." --=20 1.7.10.4 --=-=-= Content-Type: text/plain -- --=-=-=--