emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Feng Shu <tumashu@gmail.com>
To: orgmode <emacs-orgmode@gnu.org>
Subject: An org-contacts merge function, may be it is useful to someone
Date: Fri, 06 Sep 2013 09:49:27 +0800	[thread overview]
Message-ID: <87eh92ra6w.fsf@news.tumashu-localhost.org> (raw)


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

                 reply	other threads:[~2013-09-06  1:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=87eh92ra6w.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).