emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [patch] [3update] Add functions, Insert a exist contact name at


From: Feng Shu
Subject: Re: [O] [patch] [3update] Add functions, Insert a exist contact name at point
Date: Tue, 04 Jun 2013 11:29:46 +0800
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.2 (gnu/linux)

Feng Shu <address@hidden> writes:

> Feng Shu <address@hidden> writes:
>
> I will change this patch again, hard coding a templates in functions
> is not a good way , maybe it is a complex method to  solve a simpe things.

This is the 3rd patch, which has been changed significantly, 
The function will be useful when used in  org-capture, 

I want it can be included into master when it mature!

But there are some problems, I think it's org-capture's bug or limit:

1. works:
#+begin_example
("c" "Contacts" entry (file "~/org/i-contacts.org")
               "* %(org-contacts-get-exist-contact-name-string fengshu)")
#+end_example

2. doesn't work
#+begin_example
("c" "Contacts" entry (file "~/org/i-contacts.org")
               "* %(org-contacts-get-exist-contact-name-string %^{prompt)")
#+end_example


>From 06055532dbadbfbcb620378eeec0c5e3c8ee8c0d Mon Sep 17 00:00:00 2001
From: Feng Shu <address@hidden>
Date: Mon, 3 Jun 2013 23:17:57 +0800
Subject: [PATCH] Insert (a) exist contact name(s) at point

* org-contacts.el (org-contacts-get-exist-contact-name-list): New
function, which can get exist contact name(s) matched 'string, return
a list.
(org-contacts-get-exist-contact-name-string): New macro, get exist
contact name(s) matched 'string, return names string.
(org-contacts-insert-contact-name): New function, which can insert (a)
exist contact name(s) matched user's input at point.

Add new functions, which can insert (a) exist contact name(s) at point,
which is matched user's input.
---
 contrib/lisp/org-contacts.el |   36 ++++++++++++++++++++++++++++++++++++
 1 个文件被修改,插入 36 行(+)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index 5d63fcc..e3f0729 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -967,6 +967,42 @@ is created and the VCard is written into that buffer."
        (current-buffer)
       (progn (save-buffer) (kill-buffer)))))
 
+(defun org-contacts-get-exist-contact-name-list (string)
+  "Get exist contact name(s) matched 'string, return a list."
+  (let ((contact-list (nconc
+                      (org-contacts-filter
+                       nil nil
+                       (cons org-contacts-alias-property string))
+                      (org-contacts-filter string))))
+    (setq result-name-list
+         (delete-dups
+          (loop for contact in contact-list
+                collect
+                (substring-no-properties
+                 ((lambda (contact)
+                    (let* ((name
+                            (org-contacts-vcard-escape (car contact)))) name))
+                  contact))))))
+  (if result-name-list result-name-list (list string)))
+
+(defmacro org-contacts-get-exist-contact-name-string (string)
+  "Get exist contact name(s) matched 'string, return names string."
+ (if (stringp string)
+     `(mapconcat 'identity (org-contacts-get-exist-contact-name-list ,string) 
" ")
+   `(mapconcat 'identity (org-contacts-get-exist-contact-name-list ,(format 
"%s" string)) " ")))
+
+(defun org-contacts-insert-contact-name (string)
+  "At point insert (a) exist contact name(s) matched 'input."
+  (interactive (list (read-string "Contact Alias or Name: ")))
+  (current-buffer)
+  (let ((inhibit-read-only t)))
+  (when (fboundp 'set-buffer-file-coding-system)
+    (set-buffer-file-coding-system coding-system-for-write))
+  (let ((name-list (org-contacts-get-exist-contact-name-list string)))
+    (while name-list
+      (insert (concat (car name-list) " "))
+    (setq name-list (cdr name-list)))))
+
 (defun org-contacts-show-map (&optional name)
   "Show contacts on a map.
 Requires google-maps-el."
-- 
1.7.10.4


-- 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]