From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: [patch] Add functions, which can quickly insert org-contacts template(s) in current buffer Date: Mon, 03 Jun 2013 23:23:52 +0800 Message-ID: <87zjv7md4n.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]:50820) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjWdG-00007G-L4 for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 11:25:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UjWdB-0002BA-KY for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 11:25:14 -0400 Received: from mail-pa0-x236.google.com ([2607:f8b0:400e:c03::236]:64755) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UjWdB-0002AL-D6 for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 11:25:09 -0400 Received: by mail-pa0-f54.google.com with SMTP id kx1so935066pab.41 for ; Mon, 03 Jun 2013 08:25:08 -0700 (PDT) Received: from news.tumashu-localhost.org ([110.97.81.95]) by mx.google.com with ESMTPSA id 6sm6472204pbn.45.2013.06.03.08.25.05 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 03 Jun 2013 08:25:07 -0700 (PDT) Received: from feng by news.tumashu-localhost.org with local (Exim 4.80) (envelope-from ) id 1UjWbw-0006vn-Fa for emacs-orgmode@gnu.org; Mon, 03 Jun 2013 23:23:52 +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 6080af9fa0183bde6946cd7036d4b30937a10a39 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 | 49 ++++++++++++++++++++++++++++++++++++++= ++++ 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 49 =E8=A1=8C(+) diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el index ffd17a1..84c4473 100644 --- a/contrib/lisp/org-contacts.el +++ b/contrib/lisp/org-contacts.el @@ -951,6 +951,55 @@ 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))) + (fundamental-mode) + (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 -- --=-=-=--