emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Feng Shu <tumashu@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org-contacts.el: ignore emails or phones with ignore property
Date: Thu, 30 May 2013 08:42:04 +0800	[thread overview]
Message-ID: <87vc61wb6r.fsf@news.tumashu-localhost.org> (raw)
In-Reply-To: <87li6yx8u9.fsf@news.tumashu-localhost.org> (Feng Shu's message of "Wed, 29 May 2013 20:35:10 +0800")

[-- Attachment #1: Type: text/plain, Size: 16 bytes --]


updated patch


[-- Attachment #2: 0001-Add-a-feature-which-can-ignore-emails-or-phones-with.patch --]
[-- Type: text/x-diff, Size: 4822 bytes --]

From b0851e4c48e4c2e67fd8aafdf04951e764e07ccf Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
Date: Wed, 29 May 2013 20:30:43 +0800
Subject: [PATCH] Add a feature, which can ignore emails or phones with
 property

* contrib/lisp/org-contacts.el (org-contacts-ignore-property): New variable.
(org-contacts-remove-ignored-property-values): New function, which
remove all ignore-list's elements from list.
(org-contacts-complete-name): When completing, ignore the
values which has been included into the ignore property.
(org-contacts-vcard-format): Don't export the values which has
been included into the ignore property.

If emails or phones is included into the ignore property, they will
not show in complete buffer. When the contact is exported to vcard,
they will be ignored too.
---
 contrib/lisp/org-contacts.el |   31 ++++++++++++++++++++++++++-----
 1 个文件被修改,插入 26 行(+),删除 5 行(-)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index 7b0b603..1be0ac9 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -86,6 +86,11 @@ When set to nil, all your Org files will be used."
   :type 'string
   :group 'org-contacts)
 
+(defcustom org-contacts-ignore-property "IGNORE"
+  "Name of the property,  which values will be ignored when complete or export to vcard."
+  :type 'string
+  :group 'org-contacts)
+
 
 (defcustom org-contacts-birthday-format "Birthday: %l (%Y)"
   "Format of the anniversary agenda entry.
@@ -476,6 +481,13 @@ A group FOO is composed of contacts with the tag FOO."
 		(completion-table-case-fold completion-list
 					    (not org-contacts-completion-ignore-case))))))))
 
+
+(defun org-contacts-remove-ignored-property-values (ignore-list list)
+  "Remove all ignore-list's elements from list."
+  (remove-if (lambda (el)
+	       (member el ignore-list)) 
+             list))
+
 (defun org-contacts-complete-name (start end string)
   "Complete text at START with a user name and email."
   (let* ((completion-ignore-case org-contacts-completion-ignore-case)
@@ -484,10 +496,17 @@ A group FOO is composed of contacts with the tag FOO."
 		;; The contact name is always the car of the assoc-list
 		;; returned by `org-contacts-filter'.
 		for contact-name = (car contact)
+
+		;; Build the list of the email addresses which has
+		;; been expired
+		for ignore-list = (org-contacts-split-property (or
+								(cdr (assoc-string org-contacts-ignore-property
+										   (caddr contact))) ""))
 		;; Build the list of the user email addresses.
-		for email-list = (org-contacts-split-property (or
-						(cdr (assoc-string org-contacts-email-property
-								   (caddr contact))) ""))
+		for email-list = (org-contacts-remove-ignored-property-values ignore-list
+									      (org-contacts-split-property (or
+													    (cdr (assoc-string org-contacts-email-property
+															       (caddr contact))) "")))
 		;; If the user has email addresses…
 		if email-list
 		;; … append a list of USER <EMAIL>.
@@ -869,15 +888,17 @@ to do our best."
 	 (n (org-contacts-vcard-encode-name name))
 	 (email (cdr (assoc-string org-contacts-email-property properties)))
 	 (tel  (cdr (assoc-string org-contacts-tel-property properties)))
+	 (ignore  (cdr (assoc-string org-contacts-ignore-property properties)))
 	 (note (cdr (assoc-string org-contacts-note-property properties)))
 	 (bday (org-contacts-vcard-escape (cdr (assoc-string org-contacts-birthday-property properties))))
 	 (addr (cdr (assoc-string org-contacts-address-property properties)))
 	 (nick (org-contacts-vcard-escape (cdr (assoc-string org-contacts-nickname-property properties))))
 	 (head (format "BEGIN:VCARD\nVERSION:3.0\nN:%s\nFN:%s\n" n name))
+	 (ignore-list (when ignore (setq ignore-list (org-contacts-split-property ignore))))
 	 emails-list result phones-list)
     (concat head
 	    (when email (progn
-			  (setq emails-list (org-contacts-split-property email))
+			  (setq emails-list (org-contacts-remove-ignored-property-values ignore-list (org-contacts-split-property email)))
 			  (setq result "")
 			  (while emails-list
 			    (setq result (concat result  "EMAIL:" (org-contacts-strip-link (car emails-list)) "\n"))
@@ -886,7 +907,7 @@ to do our best."
 	    (when addr
 	      (format "ADR:;;%s\n" (replace-regexp-in-string "\\, ?" ";" addr)))
 	    (when tel (progn
-			(setq phones-list (org-contacts-split-property tel))
+			(setq phones-list (org-contacts-remove-ignored-property-values ignore-list (org-contacts-split-property tel)))
 			(setq result "")
 			(while phones-list
 			  (setq result (concat result  "TEL:" (org-contacts-strip-link (car phones-list)) "\n"))
-- 
1.7.10.4


[-- Attachment #3: Type: text/plain, Size: 6 bytes --]



-- 

      parent reply	other threads:[~2013-05-30  0:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29 12:35 [PATCH] org-contacts.el: add expire feature Feng Shu
2013-05-29 21:20 ` Daimrod
2013-05-30  0:32   ` Feng Shu
2013-05-30  0:38   ` Feng Shu
2013-05-30 10:36     ` Daimrod
2013-05-30 10:49       ` Feng Shu
2013-05-30 11:32       ` Feng Shu
2013-05-30 23:59         ` Daimrod
2013-05-31  4:22           ` Feng Shu
2013-05-30 17:37   ` Karl Voit
2013-05-30 22:56     ` Feng Shu
2013-05-31  9:38       ` Karl Voit
2013-05-31  0:05     ` Daimrod
2013-05-31  9:42       ` Handling outdated contact information (was: [PATCH] org-contacts.el: add expire feature) Karl Voit
2013-05-31 11:00         ` Handling outdated contact information Daimrod
2013-05-31 12:12           ` Feng Shu
2013-05-31 13:15         ` Feng Shu
2013-05-31 21:41           ` Org-mode contacts to Android (was: Handling outdated contact information) Karl Voit
2013-05-31 22:28             ` Org-mode contacts to Android Feng Shu
2013-06-01  0:23               ` Feng Shu
2013-05-29 21:30 ` [PATCH] org-contacts.el: add expire feature Daimrod
2013-05-29 23:15   ` Feng Shu
2013-05-30  0:42 ` Feng Shu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vc61wb6r.fsf@news.tumashu-localhost.org \
    --to=tumashu@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).