emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer
@ 2013-06-03 16:49 Feng Shu
  2013-06-03 23:07 ` Feng Shu
  2013-06-04  9:55 ` [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Bastien
  0 siblings, 2 replies; 6+ messages in thread
From: Feng Shu @ 2013-06-03 16:49 UTC (permalink / raw)
  To: orgmode

[-- Attachment #1: 0001-Quickly-insert-a-template-s-in-current-buffer.patch --]
[-- Type: text/x-diff, Size: 3418 bytes --]

From 938c2d0e3eb04faf2fd9708a382da9bac43d0bf9 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
Date: Mon, 3 Jun 2013 23:17:57 +0800
Subject: [PATCH] Quickly insert (a) template(s) in current buffer

* contrib/lisp/org-contacts.el (org-contacts-build-template-with-exist-contact):Build
a contact template with exist contact, It is useful when you want to update exist contact(s).
(org-contacts-build-template-with-string): Build contact template with
a string, It is useful when you want to add a new contact.
(org-contacts-insert-template): Insert contact template(s) at point,
the template(s) will be built with the input string and exist contacts
informations.

Add a new function, which can quickly insert (a) contact templete(s),
the templete(s) are built using user's input and the exist contacts information.
---
 contrib/lisp/org-contacts.el |   48 ++++++++++++++++++++++++++++++++++++++++++
 1 个文件被修改,插入 48 行(+)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index ffd17a1..78e7fef 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -951,6 +951,54 @@ is created and the VCard is written into that buffer."
 	(current-buffer)
       (progn (save-buffer) (kill-buffer)))))
 
+(defun org-contacts-build-template-with-exist-contact (contact)
+  "Build a contact template with exist contact, It is useful
+when you want to update exist contact(s)."
+  (let* ((properties (caddr contact))
+	 (name (org-contacts-vcard-escape (car contact)))
+	 (n (org-contacts-vcard-encode-name name))
+	 (alias (cdr (assoc-string org-contacts-alias-property properties))))
+    (concat "** " name "\n"
+	    ":PROPERTIES:\n"
+	    ":" org-contacts-alias-property ": " alias "\n"
+	    ":" org-contacts-note-property ":\n"
+	    ":" org-contacts-email-property ":\n"
+	    ":" org-contacts-tel-property ":\n"
+	    ":" org-contacts-ignore-property ":\n"
+	    ":END:\n\n")))
+
+(defun org-contacts-build-template-with-string (string)
+  "Build contact template with a string, It is useful
+when you want to add a new contact."
+  (concat "** " string "\n"
+	  ":PROPERTIES:\n"
+	  ":" org-contacts-alias-property ": " string "\n"
+	  ":" org-contacts-note-property ":\n"
+	  ":" org-contacts-email-property ":\n"
+	  ":" org-contacts-tel-property ":\n"
+	  ":" org-contacts-ignore-property ":\n"
+	  ":END:\n\n"))
+
+(defun org-contacts-insert-template (string)
+  "Insert contact template(s) at point, the template(s) will be built
+with the input string and exist contacts informations."
+  (interactive (list (read-string "Name or Alias: ")))
+  (let ((point (point))
+        (contact-list
+	 (delete-dups (nconc
+		       (org-contacts-filter
+			nil nil
+			(cons org-contacts-alias-property string))
+		       (org-contacts-filter string)))))
+    (current-buffer)
+    (let ((inhibit-read-only t)))
+    (when (fboundp 'set-buffer-file-coding-system)
+      (set-buffer-file-coding-system coding-system-for-write))
+    (loop for contact in contact-list
+	  do (insert (org-contacts-build-template-with-exist-contact contact)))
+    (if contact-list nil (insert (org-contacts-build-template-with-string string)))
+    (goto-char point)))
+
 (defun org-contacts-show-map (&optional name)
   "Show contacts on a map.
 Requires google-maps-el."
-- 
1.7.10.4


[-- Attachment #2: Type: text/plain, Size: 5 bytes --]


-- 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer
  2013-06-03 16:49 [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Feng Shu
@ 2013-06-03 23:07 ` Feng Shu
  2013-06-04  3:29   ` [patch] [3update] Add functions, Insert a exist contact name at point Feng Shu
  2013-06-04  9:55 ` [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Bastien
  1 sibling, 1 reply; 6+ messages in thread
From: Feng Shu @ 2013-06-03 23:07 UTC (permalink / raw)
  To: orgmode

Feng Shu <tumashu@gmail.com> 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.

> From 938c2d0e3eb04faf2fd9708a382da9bac43d0bf9 Mon Sep 17 00:00:00 2001
> From: Feng Shu <tumashu@gmail.com>
> Date: Mon, 3 Jun 2013 23:17:57 +0800
> Subject: [PATCH] Quickly insert (a) template(s) in current buffer
>
> * contrib/lisp/org-contacts.el (org-contacts-build-template-with-exist-contact):Build
> a contact template with exist contact, It is useful when you want to update exist contact(s).
> (org-contacts-build-template-with-string): Build contact template with
> a string, It is useful when you want to add a new contact.
> (org-contacts-insert-template): Insert contact template(s) at point,
> the template(s) will be built with the input string and exist contacts
> informations.
>
> Add a new function, which can quickly insert (a) contact templete(s),
> the templete(s) are built using user's input and the exist contacts information.
> ---
>  contrib/lisp/org-contacts.el |   48 ++++++++++++++++++++++++++++++++++++++++++
>  1 个文件被修改,插入 48 行(+)
>
> diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
> index ffd17a1..78e7fef 100644
> --- a/contrib/lisp/org-contacts.el
> +++ b/contrib/lisp/org-contacts.el
> @@ -951,6 +951,54 @@ is created and the VCard is written into that buffer."
>  	(current-buffer)
>        (progn (save-buffer) (kill-buffer)))))
>  
> +(defun org-contacts-build-template-with-exist-contact (contact)
> +  "Build a contact template with exist contact, It is useful
> +when you want to update exist contact(s)."
> +  (let* ((properties (caddr contact))
> +	 (name (org-contacts-vcard-escape (car contact)))
> +	 (n (org-contacts-vcard-encode-name name))
> +	 (alias (cdr (assoc-string org-contacts-alias-property properties))))
> +    (concat "** " name "\n"
> +	    ":PROPERTIES:\n"
> +	    ":" org-contacts-alias-property ": " alias "\n"
> +	    ":" org-contacts-note-property ":\n"
> +	    ":" org-contacts-email-property ":\n"
> +	    ":" org-contacts-tel-property ":\n"
> +	    ":" org-contacts-ignore-property ":\n"
> +	    ":END:\n\n")))
> +
> +(defun org-contacts-build-template-with-string (string)
> +  "Build contact template with a string, It is useful
> +when you want to add a new contact."
> +  (concat "** " string "\n"
> +	  ":PROPERTIES:\n"
> +	  ":" org-contacts-alias-property ": " string "\n"
> +	  ":" org-contacts-note-property ":\n"
> +	  ":" org-contacts-email-property ":\n"
> +	  ":" org-contacts-tel-property ":\n"
> +	  ":" org-contacts-ignore-property ":\n"
> +	  ":END:\n\n"))
> +
> +(defun org-contacts-insert-template (string)
> +  "Insert contact template(s) at point, the template(s) will be built
> +with the input string and exist contacts informations."
> +  (interactive (list (read-string "Name or Alias: ")))
> +  (let ((point (point))
> +        (contact-list
> +	 (delete-dups (nconc
> +		       (org-contacts-filter
> +			nil nil
> +			(cons org-contacts-alias-property string))
> +		       (org-contacts-filter string)))))
> +    (current-buffer)
> +    (let ((inhibit-read-only t)))
> +    (when (fboundp 'set-buffer-file-coding-system)
> +      (set-buffer-file-coding-system coding-system-for-write))
> +    (loop for contact in contact-list
> +	  do (insert (org-contacts-build-template-with-exist-contact contact)))
> +    (if contact-list nil (insert (org-contacts-build-template-with-string string)))
> +    (goto-char point)))
> +
>  (defun org-contacts-show-map (&optional name)
>    "Show contacts on a map.
>  Requires google-maps-el."
> -- 
> 1.7.10.4

-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] [3update] Add functions, Insert a exist contact name at point
  2013-06-03 23:07 ` Feng Shu
@ 2013-06-04  3:29   ` Feng Shu
  2013-06-04  9:41     ` Feng Shu
  0 siblings, 1 reply; 6+ messages in thread
From: Feng Shu @ 2013-06-04  3:29 UTC (permalink / raw)
  To: emacs-orgmode

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

Feng Shu <tumashu@gmail.com> writes:

> Feng Shu <tumashu@gmail.com> 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



[-- Attachment #2: 0001-Insert-a-exist-contact-name-s-at-point.patch --]
[-- Type: text/x-diff, Size: 2772 bytes --]

From 06055532dbadbfbcb620378eeec0c5e3c8ee8c0d Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
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


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



-- 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [patch] [3update] Add functions, Insert a exist contact name at point
  2013-06-04  3:29   ` [patch] [3update] Add functions, Insert a exist contact name at point Feng Shu
@ 2013-06-04  9:41     ` Feng Shu
  0 siblings, 0 replies; 6+ messages in thread
From: Feng Shu @ 2013-06-04  9:41 UTC (permalink / raw)
  To: emacs-orgmode

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



This is 4 update:


[-- Attachment #2: 0001-Insert-a-exist-contact-name-s-at-point.patch --]
[-- Type: text/x-diff, Size: 2781 bytes --]

From 326642e8cdcfcb507d82a2508e1cde91e9236540 Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
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..70a78e1 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  (symbol-name (quote ,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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer
  2013-06-03 16:49 [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Feng Shu
  2013-06-03 23:07 ` Feng Shu
@ 2013-06-04  9:55 ` Bastien
  2013-06-04 11:17   ` Feng Shu
  1 sibling, 1 reply; 6+ messages in thread
From: Bastien @ 2013-06-04  9:55 UTC (permalink / raw)
  To: Feng Shu; +Cc: orgmode

Hi Feng,

Feng Shu <tumashu@gmail.com> writes:

> * contrib/lisp/org-contacts.el (org-contacts-build-template-with-exist-contact):Build
> a contact template with exist contact, It is useful when you want to update exist contact(s).
> (org-contacts-build-template-with-string): Build contact template with
> a string, It is useful when you want to add a new contact.
> (org-contacts-insert-template): Insert contact template(s) at point,
> the template(s) will be built with the input string and exist contacts
> informations.

Here is a reformatted ChangeLog for your patch:

* contrib/lisp/org-contacts.el
(org-contacts-build-template-with-exist-contact)
(org-contacts-build-template-with-string): New methods for
building a contact template.
(org-contacts-insert-template): Insert a contact template at
point.  The template will be built with the input string and
existing contact informations.

The point is: try to be a bit more terse in your explanations,
and to pay attention to the punctuation.

Sorry to nitpick about this -- even if the change is for contrib/,
it's good to know about the rules early on, and to lower the work
of maintainers because all the change logs need to be reviewed
at some point.

Thanks for your efforts and your work on org-contacts.el!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer
  2013-06-04  9:55 ` [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Bastien
@ 2013-06-04 11:17   ` Feng Shu
  0 siblings, 0 replies; 6+ messages in thread
From: Feng Shu @ 2013-06-04 11:17 UTC (permalink / raw)
  To: Bastien; +Cc: orgmode

Bastien <bzg@gnu.org> writes:

> Hi Feng,
>
> Feng Shu <tumashu@gmail.com> writes:
>
>> * contrib/lisp/org-contacts.el
>> (org-contacts-build-template-with-exist-contact):Build
>> a contact template with exist contact, It is useful when you want to
>> update exist contact(s).
>> (org-contacts-build-template-with-string): Build contact template with
>> a string, It is useful when you want to add a new contact.
>> (org-contacts-insert-template): Insert contact template(s) at point,
>> the template(s) will be built with the input string and exist contacts
>> informations.
>
> Here is a reformatted ChangeLog for your patch:
>
> * contrib/lisp/org-contacts.el
> (org-contacts-build-template-with-exist-contact)
> (org-contacts-build-template-with-string): New methods for
> building a contact template.
> (org-contacts-insert-template): Insert a contact template at
> point.  The template will be built with the input string and
> existing contact informations.
>
> The point is: try to be a bit more terse in your explanations,
> and to pay attention to the punctuation.
>
> Sorry to nitpick about this -- even if the change is for contrib/,
> it's good to know about the rules early on, and to lower the work
> of maintainers because all the change logs need to be reviewed
> at some point.

Thanks for you information, I think this patch use a complex way to 
solve a simple problem, so I have writen a different patch to replace 
this patch! But the problem is that the new macro in the new patch 
can't work with org-capture and I can't figure out why ....


I am afraid to write commit message, for I don't know many words.
I have to write the commit message in chinese and google translate it ......

So you can see many Chinese style English in my commit. :-(


>
> Thanks for your efforts and your work on org-contacts.el!

-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-06-04 11:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-03 16:49 [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Feng Shu
2013-06-03 23:07 ` Feng Shu
2013-06-04  3:29   ` [patch] [3update] Add functions, Insert a exist contact name at point Feng Shu
2013-06-04  9:41     ` Feng Shu
2013-06-04  9:55 ` [patch] [2update] Add functions, which can quickly insert org-contacts template(s) in current buffer Bastien
2013-06-04 11:17   ` 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).