From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Date: Tue, 04 Jun 2013 00:49:04 +0800 Message-ID: <87vc5vm96n.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]:48049) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjXxf-0004s5-EC for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 12:50:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjXxd-0004Zn-Ef for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 12:50:23 -0400 Received: from mail-pb0-x230.google.com ([2607:f8b0:400e:c01::230]:62680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjXxd-0004ZX-5h for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 12:50:21 -0400 Received: by mail-pb0-f48.google.com with SMTP id md4so5925871pbc.21 for ; Mon, 03 Jun 2013 09:50:20 -0700 (PDT) Received: from tumashu ([110.97.81.95]) by mx.google.com with ESMTPSA id iq2sm25256441pbb.19.2013.06.03.09.50.16 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Jun 2013 09:50:18 -0700 (PDT) Received: from feng by tumashu with local (Exim 4.80) (envelope-from ) id 1UjXwO-0007L2-Mo for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 00:49:04 +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/x-diff; charset=utf-8 Content-Disposition: inline; filename=0001-Quickly-insert-a-template-s-in-current-buffer.patch Content-Transfer-Encoding: quoted-printable >From 938c2d0e3eb04faf2fd9708a382da9bac43d0bf9 Mon Sep 17 00:00:00 2001 From: Feng Shu Date: Mon, 3 Jun 2013 23:17:57 +0800 Subject: [PATCH] Quickly insert (a) template(s) in current buffer * contrib/lisp/org-contacts.el (org-contacts-build-template-with-exist-cont= act):Build a contact template with exist contact, It is useful when you want to update= exist contact(s). (org-contacts-build-template-with-string): Build contact template with a string, It is useful when you want to add a new contact. (org-contacts-insert-template): Insert contact template(s) at point, the template(s) will be built with the input string and exist contacts informations. Add a new function, which can quickly insert (a) contact templete(s), the templete(s) are built using user's input and the exist contacts informa= tion. --- contrib/lisp/org-contacts.el | 48 ++++++++++++++++++++++++++++++++++++++= ++++ 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 48 =E8=A1=8C(+) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index ffd17a1..78e7fef 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -951,6 +951,54 @@ is created and the VCard is written into that buffer." (current-buffer) (progn (save-buffer) (kill-buffer))))) =20 +(defun org-contacts-build-template-with-exist-contact (contact) + "Build a contact template with exist contact, It is useful +when you want to update exist contact(s)." + (let* ((properties (caddr contact)) + (name (org-contacts-vcard-escape (car contact))) + (n (org-contacts-vcard-encode-name name)) + (alias (cdr (assoc-string org-contacts-alias-property properties)))) + (concat "** " name "\n" + ":PROPERTIES:\n" + ":" org-contacts-alias-property ": " alias "\n" + ":" org-contacts-note-property ":\n" + ":" org-contacts-email-property ":\n" + ":" org-contacts-tel-property ":\n" + ":" org-contacts-ignore-property ":\n" + ":END:\n\n"))) + +(defun org-contacts-build-template-with-string (string) + "Build contact template with a string, It is useful +when you want to add a new contact." + (concat "** " string "\n" + ":PROPERTIES:\n" + ":" org-contacts-alias-property ": " string "\n" + ":" org-contacts-note-property ":\n" + ":" org-contacts-email-property ":\n" + ":" org-contacts-tel-property ":\n" + ":" org-contacts-ignore-property ":\n" + ":END:\n\n")) + +(defun org-contacts-insert-template (string) + "Insert contact template(s) at point, the template(s) will be built +with the input string and exist contacts informations." + (interactive (list (read-string "Name or Alias: "))) + (let ((point (point)) + (contact-list + (delete-dups (nconc + (org-contacts-filter + nil nil + (cons org-contacts-alias-property string)) + (org-contacts-filter string))))) + (current-buffer) + (let ((inhibit-read-only t))) + (when (fboundp 'set-buffer-file-coding-system) + (set-buffer-file-coding-system coding-system-for-write)) + (loop for contact in contact-list + do (insert (org-contacts-build-template-with-exist-contact contact))) + (if contact-list nil (insert (org-contacts-build-template-with-string = string))) + (goto-char point))) + (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 -- --=-=-=--