emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Expand current word or string in region with matched contact names. (was: [3update] Add functions, Insert a exist contact name at point)
@ 2013-06-04 15:51 Feng Shu
  0 siblings, 0 replies; only message in thread
From: Feng Shu @ 2013-06-04 15:51 UTC (permalink / raw)
  To: orgmode

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

Hi:

the function 'org-contacts-get-exist-contact-name-string  will be
used in org-capthure template, for example:

#+begin_example
("c" "Contacts: 手动输入" entry (file "~/org/i-contacts.org")
      "* %(org-contacts-get-exist-contact-name-string %^{prompt})"
#+end_example

Note: This function can't work as expect and I fail to find the solution
at this moment. If someone have good  ideas, please mail me. Thanks!


[-- Attachment #2: 0001-Expand-current-word-or-string-in-region-with-matched.patch --]
[-- Type: text/x-diff, Size: 2913 bytes --]

From 9db95556f60e83165edcec18c18e3d5aa65890af Mon Sep 17 00:00:00 2001
From: Feng Shu <tumashu@gmail.com>
Date: Mon, 3 Jun 2013 23:17:57 +0800
Subject: [PATCH] Expand current word or string in region with matched contact
 names

* org-contacts.el (org-contacts-get-exist-contact-name-list): New
function, return a list, which elements are  matched contact names.
(org-contacts-get-exist-contact-name-string): New macro, return a
string concated with all matched contact names.
(org-contacts-expand-with-contact-names): New function, expand current
word or string in region with matched contact names.

Add new functions, which can expand current word or string in region
with matched contact names. By default, match contact name and alias.
---
 contrib/lisp/org-contacts.el |   40 ++++++++++++++++++++++++++++++++++++++++
 1 个文件被修改,插入 40 行(+)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index 5d63fcc..b0eb838 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -967,6 +967,46 @@ 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)
+  "Return a list, which elements are matched contact names."
+  (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)
+  "Return a string, which are concated with all matched contact names."
+ (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-expand-with-contact-names ()
+  "Expand current word or string in region with matched contact names."
+  (interactive)
+  (let ((str (if mark-active
+		 (buffer-substring-no-properties (region-beginning) (region-end))
+	       (current-word nil t))))
+    (current-buffer)
+    (let ((inhibit-read-only t)))
+    (when (fboundp 'set-buffer-file-coding-system)
+      (set-buffer-file-coding-system coding-system-for-write))
+    (backward-delete-char (length str))
+    (insert (mapconcat
+	     'identity
+	     (org-contacts-get-exist-contact-name-list str)
+	     " "))))
+
 (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: 12 bytes --]




feng
-- 

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

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

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-04 15:51 [PATCH] Expand current word or string in region with matched contact names. (was: [3update] Add functions, Insert a exist contact name at point) 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).