From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: [PATCH] Expand current word or string in region with matched contact names. (was: [3update] Add functions, Insert a exist contact name at point) Date: Tue, 04 Jun 2013 23:51:20 +0800 Message-ID: <878v2p3mdj.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]:53580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjtXO-00081Z-Q0 for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 11:52:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjtXJ-0005iH-Sh for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 11:52:42 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:63046) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjtXJ-0005i5-L8 for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 11:52:37 -0400 Received: by mail-pd0-f173.google.com with SMTP id v10so439380pde.18 for ; Tue, 04 Jun 2013 08:52:36 -0700 (PDT) Received: from tumashu ([110.97.82.245]) by mx.google.com with ESMTPSA id un15sm66469545pab.7.2013.06.04.08.52.33 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 04 Jun 2013 08:52:35 -0700 (PDT) Received: from feng by news.tumashu-localhost.org with local (Exim 4.80) (envelope-from ) id 1UjtW4-0004rw-Qw for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 23:51:20 +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: orgmode --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi: the function 'org-contacts-get-exist-contact-name-string will be used in org-capthure template, for example: #+begin_example ("c" "Contacts: =E6=89=8B=E5=8A=A8=E8=BE=93=E5=85=A5" entry (file "~/org/i-= contacts.org") "* %(org-contacts-get-exist-contact-name-string %^{prompt})" #+end_example Note: This function can't work as expect and I fail to find the solution at this moment. If someone have good ideas, please mail me. Thanks! --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-Expand-current-word-or-string-in-region-with-matched.patch Content-Transfer-Encoding: quoted-printable >From 9db95556f60e83165edcec18c18e3d5aa65890af Mon Sep 17 00:00:00 2001 From: Feng Shu Date: Mon, 3 Jun 2013 23:17:57 +0800 Subject: [PATCH] Expand current word or string in region with matched conta= ct names * org-contacts.el (org-contacts-get-exist-contact-name-list): New function, return a list, which elements are matched contact names. (org-contacts-get-exist-contact-name-string): New macro, return a string concated with all matched contact names. (org-contacts-expand-with-contact-names): New function, expand current word or string in region with matched contact names. Add new functions, which can expand current word or string in region with matched contact names. By default, match contact name and alias. --- contrib/lisp/org-contacts.el | 40 ++++++++++++++++++++++++++++++++++++++= ++ 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 40 =E8=A1=8C(+) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index 5d63fcc..b0eb838 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -967,6 +967,46 @@ 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) + "Return a list, which elements are matched contact names." + (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) + "Return a string, which are concated with all matched contact names." + (if (stringp string) + `(mapconcat 'identity (org-contacts-get-exist-contact-name-list ,stri= ng) " ") + `(mapconcat 'identity (org-contacts-get-exist-contact-name-list (symbo= l-name (quote ,string))) " "))) + +(defun org-contacts-expand-with-contact-names () + "Expand current word or string in region with matched contact names." + (interactive) + (let ((str (if mark-active + (buffer-substring-no-properties (region-beginning) (region-end)) + (current-word nil t)))) + (current-buffer) + (let ((inhibit-read-only t))) + (when (fboundp 'set-buffer-file-coding-system) + (set-buffer-file-coding-system coding-system-for-write)) + (backward-delete-char (length str)) + (insert (mapconcat + 'identity + (org-contacts-get-exist-contact-name-list str) + " ")))) + (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 feng -- --=-=-=--