From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: Re: [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Date: Tue, 04 Jun 2013 07:07:27 +0800 Message-ID: <87r4gin68g.fsf@news.tumashu-localhost.org> References: <87vc5vm96n.fsf@news.tumashu-localhost.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujdrs-0006fm-GG for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 19:08:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ujdrn-0001MX-Lu for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 19:08:48 -0400 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]:59528) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ujdrn-0001MS-Ag for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 19:08:43 -0400 Received: by mail-pa0-f48.google.com with SMTP id kp6so5136pab.21 for ; Mon, 03 Jun 2013 16:08:42 -0700 (PDT) Received: from tumashu ([110.97.82.245]) by mx.google.com with ESMTPSA id cq1sm60638381pbc.13.2013.06.03.16.08.39 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Jun 2013 16:08:41 -0700 (PDT) Received: from feng by news.tumashu-localhost.org with local (Exim 4.80) (envelope-from ) id 1UjdqZ-0007wY-Nv for emacs-orgmode@gnu.org; Tue, 04 Jun 2013 07:07:27 +0800 In-Reply-To: <87vc5vm96n.fsf@news.tumashu-localhost.org> (Feng Shu's message of "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 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. > 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-co= ntact):Build > a contact template with exist contact, It is useful when you want to upda= te 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 infor= mation. > --- > 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=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-strin= g 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 --=20