[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] An org-contacts merge function, may be it is useful to someone
From: |
Feng Shu |
Subject: |
[O] An org-contacts merge function, may be it is useful to someone |
Date: |
Fri, 06 Sep 2013 09:49:27 +0800 |
User-agent: |
Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux) |
This is a contacts merge function, you can use it to merge duplicate
contacts
-----------------------------------------------------------------------
(defun eh-org-contacts-merge-contacts ()
"Merge duplicate contacts"
(interactive)
(dolist (name (let ((contact-list (org-contacts-filter nil nil)))
(delete-dups
(loop for contact in contact-list
collect (substring-no-properties
(org-contacts-vcard-escape (car contact)))))))
;; let UPDATE be the first contact matching NAME
(let* ((contacts (org-contacts-filter (concat "\\b" name "\\b")))
(update (first contacts)))
(save-excursion
(with-current-buffer (marker-buffer (second update))
(goto-char (marker-position (second update)))
;; for all other contacts matching NAME as CONTACT
(dolist (contact (rest contacts))
;; add all properties to UPDATE
(loop with special-properties = (mapcar 'first
(org-entry-properties nil 'special))
for (property . value) in (third contact)
unless (member property special-properties)
do (if (or (string= property "TAGS") (string= property
"ALLTAGS"))
(org-set-tags-to (delete-dups
(nconc (org-get-tags-at)
(split-string (if value value
"") ":" t))))
(let ((second-value (org-entry-get nil property)))
(unless (string= (org-contacts-strip-link (if
second-value second-value ""))
(org-contacts-strip-link (if value
value "")))
(org-entry-put nil property
(concat (org-entry-get nil property)
" " value))))))
;; delete CONTACT
(save-excursion
(with-current-buffer (marker-buffer (second contact))
(goto-char (marker-position (second contact)))
(let ((plist (second (org-element-at-point))))
(delete-region (plist-get plist :begin)
(plist-get plist :end)))))))))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] An org-contacts merge function, may be it is useful to someone,
Feng Shu <=