emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* An org-contacts merge function, may be it is useful to someone
@ 2013-09-06  1:49 Feng Shu
  0 siblings, 0 replies; only message in thread
From: Feng Shu @ 2013-09-06  1:49 UTC (permalink / raw)
  To: orgmode


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)))))))))))

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-09-06  1:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-06  1:49 An org-contacts merge function, may be it is useful to someone Feng Shu

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).