org-contacts.el 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. ;;; org-contacts.el --- Contacts management
  2. ;; Copyright (C) 2010-2014 Julien Danjou <julien@danjou.info>
  3. ;; Author: Julien Danjou <julien@danjou.info>
  4. ;; Keywords: outlines, hypermedia, calendar
  5. ;;
  6. ;; This file is NOT part of GNU Emacs.
  7. ;;
  8. ;; This program is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; This program is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;;
  20. ;;; Commentary:
  21. ;; This file contains the code for managing your contacts into Org-mode.
  22. ;; To enter new contacts, you can use `org-capture' and a minimal template just like
  23. ;; this:
  24. ;; ("c" "Contacts" entry (file "~/Org/contacts.org")
  25. ;; "* %(org-contacts-template-name)
  26. ;; :PROPERTIES:
  27. ;; :EMAIL: %(org-contacts-template-email)
  28. ;; :END:")))
  29. ;;
  30. ;; You can also use a complex template, for example:
  31. ;;
  32. ;; ("c" "Contacts" entry (file "~/Org/contacts.org")
  33. ;; "* %(org-contacts-template-name)
  34. ;; :PROPERTIES:
  35. ;; :EMAIL: %(org-contacts-template-email)
  36. ;; :PHONE:
  37. ;; :ALIAS:
  38. ;; :NICKNAME:
  39. ;; :IGNORE:
  40. ;; :ICON:
  41. ;; :NOTE:
  42. ;; :ADDRESS:
  43. ;; :BIRTHDAY:
  44. ;; :END:")))
  45. ;;
  46. ;;; Code:
  47. (eval-when-compile
  48. (require 'cl))
  49. (require 'org)
  50. (require 'gnus-util)
  51. (require 'gnus-art)
  52. (require 'mail-utils)
  53. (require 'org-agenda)
  54. (require 'org-capture)
  55. (defgroup org-contacts nil
  56. "Options about contacts management."
  57. :group 'org)
  58. (defcustom org-contacts-files nil
  59. "List of Org files to use as contacts source.
  60. When set to nil, all your Org files will be used."
  61. :type '(repeat file)
  62. :group 'org-contacts)
  63. (defcustom org-contacts-email-property "EMAIL"
  64. "Name of the property for contact email address."
  65. :type 'string
  66. :group 'org-contacts)
  67. (defcustom org-contacts-tel-property "PHONE"
  68. "Name of the property for contact phone number."
  69. :type 'string
  70. :group 'org-contacts)
  71. (defcustom org-contacts-address-property "ADDRESS"
  72. "Name of the property for contact address."
  73. :type 'string
  74. :group 'org-contacts)
  75. (defcustom org-contacts-birthday-property "BIRTHDAY"
  76. "Name of the property for contact birthday date."
  77. :type 'string
  78. :group 'org-contacts)
  79. (defcustom org-contacts-note-property "NOTE"
  80. "Name of the property for contact note."
  81. :type 'string
  82. :group 'org-contacts)
  83. (defcustom org-contacts-alias-property "ALIAS"
  84. "Name of the property for contact name alias."
  85. :type 'string
  86. :group 'org-contacts)
  87. (defcustom org-contacts-ignore-property "IGNORE"
  88. "Name of the property, which values will be ignored when
  89. completing or exporting to vcard."
  90. :type 'string
  91. :group 'org-contacts)
  92. (defcustom org-contacts-birthday-format "Birthday: %l (%Y)"
  93. "Format of the anniversary agenda entry.
  94. The following replacements are available:
  95. %h - Heading name
  96. %l - Link to the heading
  97. %y - Number of year
  98. %Y - Number of year (ordinal)"
  99. :type 'string
  100. :group 'org-contacts)
  101. (defcustom org-contacts-last-read-mail-property "LAST_READ_MAIL"
  102. "Name of the property for contact last read email link storage."
  103. :type 'string
  104. :group 'org-contacts)
  105. (defcustom org-contacts-icon-property "ICON"
  106. "Name of the property for contact icon."
  107. :type 'string
  108. :group 'org-contacts)
  109. (defcustom org-contacts-nickname-property "NICKNAME"
  110. "Name of the property for IRC nickname match."
  111. :type 'string
  112. :group 'org-contacts)
  113. (defcustom org-contacts-icon-size 32
  114. "Size of the contacts icons."
  115. :type 'string
  116. :group 'org-contacts)
  117. (defcustom org-contacts-icon-use-gravatar (fboundp 'gravatar-retrieve)
  118. "Whether use Gravatar to fetch contact icons."
  119. :type 'boolean
  120. :group 'org-contacts)
  121. (defcustom org-contacts-completion-ignore-case t
  122. "Ignore case when completing contacts."
  123. :type 'boolean
  124. :group 'org-contacts)
  125. (defcustom org-contacts-group-prefix "+"
  126. "Group prefix."
  127. :type 'string
  128. :group 'org-contacts)
  129. (defcustom org-contacts-tags-props-prefix "#"
  130. "Tags and properties prefix."
  131. :type 'string
  132. :group 'org-contacts)
  133. (defcustom org-contacts-matcher
  134. (mapconcat 'identity (list org-contacts-email-property
  135. org-contacts-alias-property
  136. org-contacts-tel-property
  137. org-contacts-address-property
  138. org-contacts-birthday-property)
  139. "<>\"\"|")
  140. "Matching rule for finding heading that are contacts.
  141. This can be a tag name, or a property check."
  142. :type 'string
  143. :group 'org-contacts)
  144. (defcustom org-contacts-email-link-description-format "%s (%d)"
  145. "Format used to store links to email.
  146. This overrides `org-email-link-description-format' if set."
  147. :group 'org-contacts
  148. :type 'string)
  149. (defcustom org-contacts-vcard-file "contacts.vcf"
  150. "Default file for vcard export."
  151. :group 'org-contacts
  152. :type 'file)
  153. (defcustom org-contacts-enable-completion t
  154. "Enable or not the completion in `message-mode' with `org-contacts'."
  155. :group 'org-contacts
  156. :type 'boolean)
  157. (defcustom org-contacts-complete-functions
  158. '(org-contacts-complete-group org-contacts-complete-tags-props org-contacts-complete-name)
  159. "List of functions used to complete contacts in `message-mode'."
  160. :group 'org-contacts
  161. :type 'hook)
  162. ;; Decalre external functions and variables
  163. (declare-function org-reverse-string "org")
  164. (declare-function diary-ordinal-suffix "ext:diary-lib")
  165. (declare-function wl-summary-message-number "ext:wl-summary")
  166. (declare-function wl-address-header-extract-address "ext:wl-address")
  167. (declare-function wl-address-header-extract-realname "ext:wl-address")
  168. (declare-function erc-buffer-list "ext:erc")
  169. (declare-function erc-get-channel-user-list "ext:erc")
  170. (declare-function google-maps-static-show "ext:google-maps-static")
  171. (declare-function elmo-message-field "ext:elmo-pipe")
  172. (declare-function std11-narrow-to-header "ext:std11")
  173. (declare-function std11-fetch-field "ext:std11")
  174. (defconst org-contacts-property-values-separators "[,; \f\t\n\r\v]+"
  175. "The default value of separators for `org-contacts-split-property'.
  176. A regexp matching strings of whitespace, `,' and `;'.")
  177. (defvar org-contacts-keymap
  178. (let ((map (make-sparse-keymap)))
  179. (define-key map "M" 'org-contacts-view-send-email)
  180. (define-key map "i" 'org-contacts-view-switch-to-irc-buffer)
  181. map)
  182. "The keymap used in `org-contacts' result list.")
  183. (defvar org-contacts-db nil
  184. "Org Contacts database.")
  185. (defvar org-contacts-last-update nil
  186. "Last time the Org Contacts database has been updated.")
  187. (defun org-contacts-files ()
  188. "Return list of Org files to use for contact management."
  189. (or org-contacts-files (org-agenda-files t 'ifmode)))
  190. (defun org-contacts-db-need-update-p ()
  191. "Determine whether `org-contacts-db' needs to be refreshed."
  192. (or (null org-contacts-last-update)
  193. (org-find-if (lambda (file)
  194. (or (time-less-p org-contacts-last-update
  195. (elt (file-attributes file) 5))))
  196. (org-contacts-files))
  197. (org-contacts-db-has-dead-markers-p org-contacts-db)))
  198. (defun org-contacts-db-has-dead-markers-p (org-contacts-db)
  199. "Returns t if at least one dead marker is found in
  200. ORG-CONTACTS-DB. A dead marker in this case is a marker pointing
  201. to dead or no buffer."
  202. ;; Scan contacts list looking for dead markers, and return t at first found.
  203. (catch 'dead-marker-found
  204. (while org-contacts-db
  205. (unless (marker-buffer (nth 1 (car org-contacts-db)))
  206. (throw 'dead-marker-found t))
  207. (setq org-contacts-db (cdr org-contacts-db)))
  208. nil))
  209. (defun org-contacts-db ()
  210. "Return the latest Org Contacts Database."
  211. (let* (todo-only
  212. (contacts-matcher
  213. (cdr (org-make-tags-matcher org-contacts-matcher)))
  214. result)
  215. (when (org-contacts-db-need-update-p)
  216. (let ((progress-reporter
  217. (make-progress-reporter "Updating Org Contacts Database..." 0 (length org-contacts-files)))
  218. (i 0))
  219. (dolist (file (org-contacts-files))
  220. (org-check-agenda-file file)
  221. (with-current-buffer (org-get-agenda-file-buffer file)
  222. (unless (eq major-mode 'org-mode)
  223. (error "File %s is not in `org-mode'" file))
  224. (setf result
  225. (append result
  226. (org-scan-tags
  227. 'org-contacts-at-point
  228. contacts-matcher
  229. todo-only))))
  230. (progress-reporter-update progress-reporter (setq i (1+ i))))
  231. (setf org-contacts-db result
  232. org-contacts-last-update (current-time))
  233. (progress-reporter-done progress-reporter)))
  234. org-contacts-db))
  235. (defun org-contacts-at-point (&optional pom)
  236. "Return the contacts at point-or-marker POM or current position
  237. if nil."
  238. (setq pom (or pom (point)))
  239. (org-with-point-at pom
  240. (list (org-get-heading t) (set-marker (make-marker) pom) (org-entry-properties pom 'all))))
  241. (defun org-contacts-filter (&optional name-match tags-match prop-match)
  242. "Search for a contact matching any of NAME-MATCH, TAGS-MATCH, PROP-MATCH.
  243. If all match values are nil, return all contacts.
  244. The optional PROP-MATCH argument is a single (PROP . VALUE) cons
  245. cell corresponding to the contact properties.
  246. "
  247. (if (and (null name-match)
  248. (null prop-match)
  249. (null tags-match))
  250. (org-contacts-db)
  251. (loop for contact in (org-contacts-db)
  252. if (or
  253. (and name-match
  254. (org-string-match-p name-match
  255. (first contact)))
  256. (and prop-match
  257. (org-find-if (lambda (prop)
  258. (and (string= (car prop-match) (car prop))
  259. (org-string-match-p (cdr prop-match) (cdr prop))))
  260. (caddr contact)))
  261. (and tags-match
  262. (org-find-if (lambda (tag)
  263. (org-string-match-p tags-match tag))
  264. (org-split-string
  265. (or (cdr (assoc-string "ALLTAGS" (caddr contact))) "") ":"))))
  266. collect contact)))
  267. (when (not (fboundp 'completion-table-case-fold))
  268. ;; That function is new in Emacs 24...
  269. (defun completion-table-case-fold (table &optional dont-fold)
  270. (lambda (string pred action)
  271. (let ((completion-ignore-case (not dont-fold)))
  272. (complete-with-action action table string pred)))))
  273. (defun org-contacts-try-completion-prefix (to-match collection &optional predicate)
  274. "Custom implementation of `try-completion'.
  275. This version works only with list and alist and it looks at all
  276. prefixes rather than just the beginning of the string."
  277. (loop with regexp = (concat "\\b" (regexp-quote to-match))
  278. with ret = nil
  279. with ret-start = nil
  280. with ret-end = nil
  281. for el in collection
  282. for string = (if (listp el) (car el) el)
  283. for start = (when (or (null predicate) (funcall predicate string))
  284. (string-match regexp string))
  285. if start
  286. do (let ((end (match-end 0))
  287. (len (length string)))
  288. (if (= end len)
  289. (return t)
  290. (destructuring-bind (string start end)
  291. (if (null ret)
  292. (values string start end)
  293. (org-contacts-common-substring
  294. ret ret-start ret-end
  295. string start end))
  296. (setf ret string
  297. ret-start start
  298. ret-end end))))
  299. finally (return
  300. (replace-regexp-in-string "\\`[ \t\n]*" "" ret))))
  301. (defun org-contacts-compare-strings (s1 start1 end1 s2 start2 end2 &optional ignore-case)
  302. "Compare the contents of two strings, using `compare-strings'.
  303. This function works like `compare-strings' excepted that it
  304. returns a cons.
  305. - The CAR is the number of characters that match at the beginning.
  306. - The CDR is T is the two strings are the same and NIL otherwise."
  307. (let ((ret (compare-strings s1 start1 end1 s2 start2 end2 ignore-case)))
  308. (if (eq ret t)
  309. (cons (or end1 (length s1)) t)
  310. (cons (1- (abs ret)) nil))))
  311. (defun org-contacts-common-substring (s1 start1 end1 s2 start2 end2)
  312. "Extract the common substring between S1 and S2.
  313. This function extracts the common substring between S1 and S2 and
  314. adjust the part that remains common.
  315. START1 and END1 delimit the part in S1 that we know is common
  316. between the two strings. This applies to START2 and END2 for S2.
  317. This function returns a list whose contains:
  318. - The common substring found.
  319. - The new value of the start of the known inner substring.
  320. - The new value of the end of the known inner substring."
  321. ;; Given two strings:
  322. ;; s1: "foo bar baz"
  323. ;; s2: "fooo bar baz"
  324. ;; and the inner substring is "bar"
  325. ;; then: start1 = 4, end1 = 6, start2 = 5, end2 = 7
  326. ;;
  327. ;; To find the common substring we will compare two substrings:
  328. ;; " oof" and " ooof" to find the beginning of the common substring.
  329. ;; " baz" and " baz" to find the end of the common substring.
  330. (let* ((len1 (length s1))
  331. (start1 (or start1 0))
  332. (end1 (or end1 len1))
  333. (len2 (length s2))
  334. (start2 (or start2 0))
  335. (end2 (or end2 len2))
  336. (new-start (car (org-contacts-compare-strings
  337. (substring (org-reverse-string s1) (- len1 start1)) nil nil
  338. (substring (org-reverse-string s2) (- len2 start2)) nil nil)))
  339. (new-end (+ end1 (car (org-contacts-compare-strings
  340. (substring s1 end1) nil nil
  341. (substring s2 end2) nil nil)))))
  342. (list (substring s1 (- start1 new-start) new-end)
  343. new-start
  344. (+ new-start (- end1 start1)))))
  345. (defun org-contacts-all-completions-prefix (to-match collection &optional predicate)
  346. "Custom version of `all-completions'.
  347. This version works only with list and alist and it looks at all
  348. prefixes rather than just the beginning of the string."
  349. (loop with regexp = (concat "\\b" (regexp-quote to-match))
  350. for el in collection
  351. for string = (if (listp el) (car el) el)
  352. for match? = (when (and (or (null predicate) (funcall predicate string)))
  353. (string-match regexp string))
  354. if match?
  355. collect (progn
  356. (let ((end (match-end 0)))
  357. (org-no-properties string)
  358. (when (< end (length string))
  359. ;; Here we add a text property that will be used
  360. ;; later to highlight the character right after
  361. ;; the common part between each addresses.
  362. ;; See `org-contacts-display-sort-function'.
  363. (put-text-property end (1+ end) 'org-contacts-prefix 't string)))
  364. string)))
  365. (defun org-contacts-make-collection-prefix (collection)
  366. "Make a collection function from COLLECTION which will match on prefixes."
  367. (lexical-let ((collection collection))
  368. (lambda (string predicate flag)
  369. (cond ((eq flag nil)
  370. (org-contacts-try-completion-prefix string collection predicate))
  371. ((eq flag t)
  372. ;; `org-contacts-all-completions-prefix' has already been
  373. ;; used to compute `all-completions'.
  374. collection)
  375. ((eq flag 'lambda)
  376. (org-contacts-test-completion-prefix string collection predicate))
  377. ((and (listp flag) (eq (car flag) 'boundaries))
  378. (destructuring-bind (to-ignore &rest suffix)
  379. flag
  380. (org-contacts-boundaries-prefix string collection predicate suffix)))
  381. ((eq flag 'metadata)
  382. (org-contacts-metadata-prefix string collection predicate))
  383. (t nil ; operation unsupported
  384. )))))
  385. (defun org-contacts-display-sort-function (completions)
  386. "Sort function for contacts display."
  387. (mapcar (lambda (string)
  388. (loop with len = (1- (length string))
  389. for i upfrom 0 to len
  390. if (memq 'org-contacts-prefix
  391. (text-properties-at i string))
  392. do (set-text-properties
  393. i (1+ i)
  394. (list 'font-lock-face
  395. (if (char-equal (aref string i)
  396. (string-to-char " "))
  397. ;; Spaces can't be bold.
  398. 'underline
  399. 'bold)) string)
  400. else
  401. do (set-text-properties i (1+ i) nil string)
  402. finally (return string)))
  403. completions))
  404. (defun org-contacts-test-completion-prefix (string collection predicate)
  405. ;; Prevents `org-find-if' from redefining `predicate' and going into
  406. ;; an infinite loop.
  407. (lexical-let ((predicate predicate))
  408. (org-find-if (lambda (el)
  409. (and (or (null predicate) (funcall predicate el))
  410. (string= string el)))
  411. collection)))
  412. (defun org-contacts-boundaries-prefix (string collection predicate suffix)
  413. (list* 'boundaries (completion-boundaries string collection predicate suffix)))
  414. (defun org-contacts-metadata-prefix (string collection predicate)
  415. '(metadata .
  416. ((cycle-sort-function . org-contacts-display-sort-function)
  417. (display-sort-function . org-contacts-display-sort-function))))
  418. (defun org-contacts-complete-group (start end string)
  419. "Complete text at START from a group.
  420. A group FOO is composed of contacts with the tag FOO."
  421. (let* ((completion-ignore-case org-contacts-completion-ignore-case)
  422. (group-completion-p (org-string-match-p
  423. (concat "^" org-contacts-group-prefix) string)))
  424. (when group-completion-p
  425. (let ((completion-list
  426. (all-completions
  427. string
  428. (mapcar (lambda (group)
  429. (propertize (concat org-contacts-group-prefix group)
  430. 'org-contacts-group group))
  431. (org-uniquify
  432. (loop for contact in (org-contacts-filter)
  433. nconc (org-split-string
  434. (or (cdr (assoc-string "ALLTAGS" (caddr contact))) "") ":")))))))
  435. (list start end
  436. (if (= (length completion-list) 1)
  437. ;; We've found the correct group, returns the address
  438. (lexical-let ((tag (get-text-property 0 'org-contacts-group
  439. (car completion-list))))
  440. (lambda (string pred &optional to-ignore)
  441. (mapconcat 'identity
  442. (loop for contact in (org-contacts-filter
  443. nil
  444. tag)
  445. ;; The contact name is always the car of the assoc-list
  446. ;; returned by `org-contacts-filter'.
  447. for contact-name = (car contact)
  448. ;; Grab the first email of the contact
  449. for email = (org-contacts-strip-link
  450. (or (car (org-contacts-split-property
  451. (or
  452. (cdr (assoc-string org-contacts-email-property
  453. (caddr contact)))
  454. ""))) ""))
  455. ;; If the user has an email address, append USER <EMAIL>.
  456. if email collect (org-contacts-format-email contact-name email))
  457. ", ")))
  458. ;; We haven't found the correct group
  459. (completion-table-case-fold completion-list
  460. (not org-contacts-completion-ignore-case))))))))
  461. (defun org-contacts-complete-tags-props (start end string)
  462. "Insert emails that match the tags expression.
  463. For example: FOO-BAR will match entries tagged with FOO but not
  464. with BAR.
  465. See (org) Matching tags and properties for a complete
  466. description."
  467. (let* ((completion-ignore-case org-contacts-completion-ignore-case)
  468. (completion-p (org-string-match-p
  469. (concat "^" org-contacts-tags-props-prefix) string)))
  470. (when completion-p
  471. (let ((result
  472. (mapconcat
  473. 'identity
  474. (loop for contact in (org-contacts-db)
  475. for contact-name = (car contact)
  476. for email = (org-contacts-strip-link (or (car (org-contacts-split-property
  477. (or
  478. (cdr (assoc-string org-contacts-email-property
  479. (caddr contact)))
  480. ""))) ""))
  481. for tags = (cdr (assoc "TAGS" (nth 2 contact)))
  482. for tags-list = (if tags
  483. (split-string (substring (cdr (assoc "TAGS" (nth 2 contact))) 1 -1) ":")
  484. '())
  485. for marker = (second contact)
  486. if (with-current-buffer (marker-buffer marker)
  487. (save-excursion
  488. (goto-char marker)
  489. (let (todo-only)
  490. (eval (cdr (org-make-tags-matcher (subseq string 1)))))))
  491. collect (org-contacts-format-email contact-name email))
  492. ",")))
  493. (when (not (string= "" result))
  494. ;; return (start end function)
  495. (lexical-let* ((to-return result))
  496. (list start end
  497. (lambda (string pred &optional to-ignore) to-return))))))))
  498. (defun org-contacts-remove-ignored-property-values (ignore-list list)
  499. "Remove all ignore-list's elements from list and you can use
  500. regular expressions in the ignore list."
  501. (org-remove-if (lambda (el)
  502. (org-find-if (lambda (x)
  503. (string-match-p x el))
  504. ignore-list))
  505. list))
  506. (defun org-contacts-complete-name (start end string)
  507. "Complete text at START with a user name and email."
  508. (let* ((completion-ignore-case org-contacts-completion-ignore-case)
  509. (completion-list
  510. (loop for contact in (org-contacts-filter)
  511. ;; The contact name is always the car of the assoc-list
  512. ;; returned by `org-contacts-filter'.
  513. for contact-name = (car contact)
  514. ;; Build the list of the email addresses which has
  515. ;; been expired
  516. for ignore-list = (org-contacts-split-property
  517. (or (cdr (assoc-string org-contacts-ignore-property
  518. (caddr contact))) ""))
  519. ;; Build the list of the user email addresses.
  520. for email-list = (org-contacts-remove-ignored-property-values
  521. ignore-list
  522. (org-contacts-split-property
  523. (or (cdr (assoc-string org-contacts-email-property
  524. (caddr contact))) "")))
  525. ;; If the user has email addresses…
  526. if email-list
  527. ;; … append a list of USER <EMAIL>.
  528. nconc (loop for email in email-list
  529. collect (org-contacts-format-email contact-name (org-contacts-strip-link email)))))
  530. (completion-list (org-contacts-all-completions-prefix
  531. string
  532. (org-uniquify completion-list))))
  533. (when completion-list
  534. (list start end
  535. (org-contacts-make-collection-prefix completion-list)))))
  536. (defun org-contacts-message-complete-function (&optional start)
  537. "Function used in `completion-at-point-functions' in `message-mode'."
  538. ;; Avoid to complete in `post-command-hook'.
  539. (when completion-in-region-mode
  540. (remove-hook 'post-command-hook #'completion-in-region--postch))
  541. (let ((mail-abbrev-mode-regexp
  542. "^\\(Resent-To\\|To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\|Disposition-Notification-To\\|Return-Receipt-To\\):"))
  543. (when (mail-abbrev-in-expansion-header-p)
  544. (lexical-let*
  545. ((end (point))
  546. (start (or start
  547. (save-excursion
  548. (re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
  549. (goto-char (match-end 0))
  550. (point))))
  551. (string (buffer-substring start end)))
  552. (run-hook-with-args-until-success
  553. 'org-contacts-complete-functions start end string)))))
  554. (defun org-contacts-gnus-get-name-email ()
  555. "Get name and email address from Gnus message."
  556. (if (gnus-alive-p)
  557. (gnus-with-article-headers
  558. (mail-extract-address-components
  559. (or (mail-fetch-field "From") "")))))
  560. (defun org-contacts-gnus-article-from-get-marker ()
  561. "Return a marker for a contact based on From."
  562. (let* ((address (org-contacts-gnus-get-name-email))
  563. (name (car address))
  564. (email (cadr address)))
  565. (cadar (or (org-contacts-filter
  566. nil
  567. nil
  568. (cons org-contacts-email-property (concat "\\b" (regexp-quote email) "\\b")))
  569. (when name
  570. (org-contacts-filter
  571. (concat "^" name "$")))))))
  572. (defun org-contacts-gnus-article-from-goto ()
  573. "Go to contact in the From address of current Gnus message."
  574. (interactive)
  575. (let ((marker (org-contacts-gnus-article-from-get-marker)))
  576. (when marker
  577. (switch-to-buffer-other-window (marker-buffer marker))
  578. (goto-char marker)
  579. (when (eq major-mode 'org-mode)
  580. (org-show-context 'agenda)
  581. (save-excursion
  582. (and (outline-next-heading)
  583. ;; show the next heading
  584. (org-flag-heading nil)))))))
  585. (org-no-warnings (defvar date)) ;; unprefixed, from calendar.el
  586. (defun org-contacts-anniversaries (&optional field format)
  587. "Compute FIELD anniversary for each contact, returning FORMAT.
  588. Default FIELD value is \"BIRTHDAY\".
  589. Format is a string matching the following format specification:
  590. %h - Heading name
  591. %l - Link to the heading
  592. %y - Number of year
  593. %Y - Number of year (ordinal)"
  594. (let ((calendar-date-style 'american)
  595. (entry ""))
  596. (unless format (setq format org-contacts-birthday-format))
  597. (loop for contact in (org-contacts-filter)
  598. for anniv = (let ((anniv (cdr (assoc-string
  599. (or field org-contacts-birthday-property)
  600. (caddr contact)))))
  601. (when anniv
  602. (calendar-gregorian-from-absolute
  603. (org-time-string-to-absolute anniv))))
  604. ;; Use `diary-anniversary' to compute anniversary.
  605. if (and anniv (apply 'diary-anniversary anniv))
  606. collect (format-spec format
  607. `((?l . ,(org-with-point-at (cadr contact) (org-store-link nil)))
  608. (?h . ,(car contact))
  609. (?y . ,(- (calendar-extract-year date)
  610. (calendar-extract-year anniv)))
  611. (?Y . ,(let ((years (- (calendar-extract-year date)
  612. (calendar-extract-year anniv))))
  613. (format "%d%s" years (diary-ordinal-suffix years)))))))))
  614. (defun org-completing-read-date (prompt collection
  615. &optional predicate require-match initial-input
  616. hist def inherit-input-method)
  617. "Like `completing-read' but reads a date.
  618. Only PROMPT and DEF are really used."
  619. (org-read-date nil nil nil prompt nil def))
  620. (add-to-list 'org-property-set-functions-alist
  621. `(,org-contacts-birthday-property . org-completing-read-date))
  622. (defun org-contacts-template-name (&optional return-value)
  623. "Try to return the contact name for a template.
  624. If not found return RETURN-VALUE or something that would ask the user."
  625. (or (car (org-contacts-gnus-get-name-email))
  626. return-value
  627. "%^{Name}"))
  628. (defun org-contacts-template-email (&optional return-value)
  629. "Try to return the contact email for a template.
  630. If not found return RETURN-VALUE or something that would ask the user."
  631. (or (cadr (org-contacts-gnus-get-name-email))
  632. return-value
  633. (concat "%^{" org-contacts-email-property "}p")))
  634. (defun org-contacts-gnus-store-last-mail ()
  635. "Store a link between mails and contacts.
  636. This function should be called from `gnus-article-prepare-hook'."
  637. (let ((marker (org-contacts-gnus-article-from-get-marker)))
  638. (when marker
  639. (with-current-buffer (marker-buffer marker)
  640. (save-excursion
  641. (goto-char marker)
  642. (let* ((org-email-link-description-format (or org-contacts-email-link-description-format
  643. org-email-link-description-format))
  644. (link (gnus-with-article-buffer (org-store-link nil))))
  645. (org-set-property org-contacts-last-read-mail-property link)))))))
  646. (defun org-contacts-icon-as-string ()
  647. "Return the contact icon as a string."
  648. (let ((image (org-contacts-get-icon)))
  649. (concat
  650. (propertize "-" 'display
  651. (append
  652. (if image
  653. image
  654. `'(space :width (,org-contacts-icon-size)))
  655. '(:ascent center)))
  656. " ")))
  657. ;;;###autoload
  658. (defun org-contacts (name)
  659. "Create agenda view for contacts matching NAME."
  660. (interactive (list (read-string "Name: ")))
  661. (let ((org-agenda-files (org-contacts-files))
  662. (org-agenda-skip-function
  663. (lambda () (org-agenda-skip-if nil `(notregexp ,name))))
  664. (org-agenda-prefix-format (propertize
  665. "%(org-contacts-icon-as-string)% s%(org-contacts-irc-number-of-unread-messages) "
  666. 'keymap org-contacts-keymap))
  667. (org-agenda-overriding-header
  668. (or org-agenda-overriding-header
  669. (concat "List of contacts matching `" name "':"))))
  670. (setq org-agenda-skip-regexp name)
  671. (org-tags-view nil org-contacts-matcher)
  672. (with-current-buffer org-agenda-buffer-name
  673. (setq org-agenda-redo-command
  674. (list 'org-contacts name)))))
  675. (defun org-contacts-completing-read (prompt
  676. &optional predicate
  677. initial-input hist def inherit-input-method)
  678. "Call `completing-read' with contacts name as collection."
  679. (org-completing-read
  680. prompt (org-contacts-filter) predicate t initial-input hist def inherit-input-method))
  681. (defun org-contacts-format-name (name)
  682. "Trim any local formatting to get a bare NAME."
  683. ;; Remove radio targets characters
  684. (replace-regexp-in-string org-radio-target-regexp "\\1" name))
  685. (defun org-contacts-format-email (name email)
  686. "Format an EMAIL address corresponding to NAME."
  687. (unless email
  688. (error "`email' cannot be nul"))
  689. (if name
  690. (concat (org-contacts-format-name name) " <" email ">")
  691. email))
  692. (defun org-contacts-check-mail-address (mail)
  693. "Add MAIL address to contact at point if it does not have it."
  694. (let ((mails (org-entry-get (point) org-contacts-email-property)))
  695. (unless (member mail (split-string mails))
  696. (when (yes-or-no-p
  697. (format "Do you want to add this address to %s?" (org-get-heading t)))
  698. (org-set-property org-contacts-email-property (concat mails " " mail))))))
  699. (defun org-contacts-gnus-check-mail-address ()
  700. "Check that contact has the current address recorded.
  701. This function should be called from `gnus-article-prepare-hook'."
  702. (let ((marker (org-contacts-gnus-article-from-get-marker)))
  703. (when marker
  704. (org-with-point-at marker
  705. (org-contacts-check-mail-address (cadr (org-contacts-gnus-get-name-email)))))))
  706. (defun org-contacts-gnus-insinuate ()
  707. "Add some hooks for Gnus user.
  708. This adds `org-contacts-gnus-check-mail-address' and
  709. `org-contacts-gnus-store-last-mail' to
  710. `gnus-article-prepare-hook'. It also adds a binding on `;' in
  711. `gnus-summary-mode-map' to `org-contacts-gnus-article-from-goto'"
  712. (require 'gnus)
  713. (require 'gnus-art)
  714. (define-key gnus-summary-mode-map ";" 'org-contacts-gnus-article-from-goto)
  715. (add-hook 'gnus-article-prepare-hook 'org-contacts-gnus-check-mail-address)
  716. (add-hook 'gnus-article-prepare-hook 'org-contacts-gnus-store-last-mail))
  717. (defun org-contacts-setup-completion-at-point ()
  718. "Add `org-contacts-message-complete-function' as a new function
  719. to complete the thing at point."
  720. (add-to-list 'completion-at-point-functions
  721. 'org-contacts-message-complete-function))
  722. (defun org-contacts-unload-hook ()
  723. (remove-hook 'message-mode-hook 'org-contacts-setup-completion-at-point))
  724. (when (and org-contacts-enable-completion
  725. (boundp 'completion-at-point-functions))
  726. (add-hook 'message-mode-hook 'org-contacts-setup-completion-at-point))
  727. (defun org-contacts-wl-get-from-header-content ()
  728. "Retrieve the content of the `From' header of an email.
  729. Works from wl-summary-mode and mime-view-mode - that is while viewing email.
  730. Depends on Wanderlust been loaded."
  731. (with-current-buffer (org-capture-get :original-buffer)
  732. (cond
  733. ((eq major-mode 'wl-summary-mode) (when (and (boundp 'wl-summary-buffer-elmo-folder)
  734. wl-summary-buffer-elmo-folder)
  735. (elmo-message-field
  736. wl-summary-buffer-elmo-folder
  737. (wl-summary-message-number)
  738. 'from)))
  739. ((eq major-mode 'mime-view-mode) (std11-narrow-to-header)
  740. (prog1
  741. (std11-fetch-field "From")
  742. (widen))))))
  743. (defun org-contacts-wl-get-name-email ()
  744. "Get name and email address from Wanderlust email.
  745. See `org-contacts-wl-get-from-header-content' for limitations."
  746. (let ((from (org-contacts-wl-get-from-header-content)))
  747. (when from
  748. (list (wl-address-header-extract-realname from)
  749. (wl-address-header-extract-address from)))))
  750. (defun org-contacts-template-wl-name (&optional return-value)
  751. "Try to return the contact name for a template from wl.
  752. If not found, return RETURN-VALUE or something that would ask the
  753. user."
  754. (or (car (org-contacts-wl-get-name-email))
  755. return-value
  756. "%^{Name}"))
  757. (defun org-contacts-template-wl-email (&optional return-value)
  758. "Try to return the contact email for a template from Wanderlust.
  759. If not found return RETURN-VALUE or something that would ask the user."
  760. (or (cadr (org-contacts-wl-get-name-email))
  761. return-value
  762. (concat "%^{" org-contacts-email-property "}p")))
  763. (defun org-contacts-view-send-email (&optional ask)
  764. "Send email to the contact at point.
  765. If ASK is set, ask for the email address even if there's only one
  766. address."
  767. (interactive "P")
  768. (let ((marker (org-get-at-bol 'org-hd-marker)))
  769. (org-with-point-at marker
  770. (let ((emails (org-entry-get (point) org-contacts-email-property)))
  771. (if emails
  772. (let ((email-list (org-contacts-split-property emails)))
  773. (if (and (= (length email-list) 1) (not ask))
  774. (compose-mail (org-contacts-format-email
  775. (org-get-heading t) emails))
  776. (let ((email (completing-read "Send mail to which address: " email-list)))
  777. (setq email (org-contacts-strip-link email))
  778. (org-contacts-check-mail-address email)
  779. (compose-mail (org-contacts-format-email (org-get-heading t) email)))))
  780. (error (format "This contact has no mail address set (no %s property)."
  781. org-contacts-email-property)))))))
  782. (defun org-contacts-get-icon (&optional pom)
  783. "Get icon for contact at POM."
  784. (setq pom (or pom (point)))
  785. (catch 'icon
  786. ;; Use `org-contacts-icon-property'
  787. (let ((image-data (org-entry-get pom org-contacts-icon-property)))
  788. (when image-data
  789. (throw 'icon
  790. (if (fboundp 'gnus-rescale-image)
  791. (gnus-rescale-image (create-image image-data)
  792. (cons org-contacts-icon-size org-contacts-icon-size))
  793. (create-image image-data)))))
  794. ;; Next, try Gravatar
  795. (when org-contacts-icon-use-gravatar
  796. (let* ((gravatar-size org-contacts-icon-size)
  797. (email-list (org-entry-get pom org-contacts-email-property))
  798. (gravatar
  799. (when email-list
  800. (loop for email in (org-contacts-split-property email-list)
  801. for gravatar = (gravatar-retrieve-synchronously (org-contacts-strip-link email))
  802. if (and gravatar
  803. (not (eq gravatar 'error)))
  804. return gravatar))))
  805. (when gravatar (throw 'icon gravatar))))))
  806. (defun org-contacts-irc-buffer (&optional pom)
  807. "Get the IRC buffer associated with the entry at POM."
  808. (setq pom (or pom (point)))
  809. (let ((nick (org-entry-get pom org-contacts-nickname-property)))
  810. (when nick
  811. (let ((buffer (get-buffer nick)))
  812. (when buffer
  813. (with-current-buffer buffer
  814. (when (eq major-mode 'erc-mode)
  815. buffer)))))))
  816. (defun org-contacts-irc-number-of-unread-messages (&optional pom)
  817. "Return the number of unread messages for contact at POM."
  818. (when (boundp 'erc-modified-channels-alist)
  819. (let ((number (cadr (assoc (org-contacts-irc-buffer pom) erc-modified-channels-alist))))
  820. (if number
  821. (format (concat "%3d unread message" (if (> number 1) "s" " ") " ") number)
  822. (make-string 21 ? )))))
  823. (defun org-contacts-view-switch-to-irc-buffer ()
  824. "Switch to the IRC buffer of the current contact if it has one."
  825. (interactive)
  826. (let ((marker (org-get-at-bol 'org-hd-marker)))
  827. (org-with-point-at marker
  828. (switch-to-buffer-other-window (org-contacts-irc-buffer)))))
  829. (defun org-contacts-completing-read-nickname (prompt collection
  830. &optional predicate require-match initial-input
  831. hist def inherit-input-method)
  832. "Like `completing-read' but reads a nickname."
  833. (org-completing-read prompt (append collection (erc-nicknames-list)) predicate require-match
  834. initial-input hist def inherit-input-method))
  835. (defun erc-nicknames-list ()
  836. "Return all nicknames of all ERC buffers."
  837. (loop for buffer in (erc-buffer-list)
  838. nconc (with-current-buffer buffer
  839. (loop for user-entry in (mapcar 'car (erc-get-channel-user-list))
  840. collect (elt user-entry 1)))))
  841. (add-to-list 'org-property-set-functions-alist
  842. `(,org-contacts-nickname-property . org-contacts-completing-read-nickname))
  843. (defun org-contacts-vcard-escape (str)
  844. "Escape ; , and \n in STR for the VCard format."
  845. ;; Thanks to this library for the regexp:
  846. ;; http://www.emacswiki.org/cgi-bin/wiki/bbdb-vcard-export.el
  847. (when str
  848. (replace-regexp-in-string
  849. "\n" "\\\\n"
  850. (replace-regexp-in-string "\\(;\\|,\\|\\\\\\)" "\\\\\\1" str))))
  851. (defun org-contacts-vcard-encode-name (name)
  852. "Try to encode NAME as VCard's N property.
  853. The N property expects
  854. FamilyName;GivenName;AdditionalNames;Prefix;Postfix.
  855. Org-contacts does not specify how to encode the name. So we try
  856. to do our best."
  857. (concat (replace-regexp-in-string "\\(\\w+\\) \\(.*\\)" "\\2;\\1" name) ";;;"))
  858. (defun org-contacts-vcard-format (contact)
  859. "Formats CONTACT in VCard 3.0 format."
  860. (let* ((properties (caddr contact))
  861. (name (org-contacts-vcard-escape (car contact)))
  862. (n (org-contacts-vcard-encode-name name))
  863. (email (cdr (assoc-string org-contacts-email-property properties)))
  864. (tel (cdr (assoc-string org-contacts-tel-property properties)))
  865. (ignore-list (cdr (assoc-string org-contacts-ignore-property properties)))
  866. (ignore-list (when ignore-list
  867. (org-contacts-split-property ignore-list)))
  868. (note (cdr (assoc-string org-contacts-note-property properties)))
  869. (bday (org-contacts-vcard-escape (cdr (assoc-string org-contacts-birthday-property properties))))
  870. (addr (cdr (assoc-string org-contacts-address-property properties)))
  871. (nick (org-contacts-vcard-escape (cdr (assoc-string org-contacts-nickname-property properties))))
  872. (head (format "BEGIN:VCARD\nVERSION:3.0\nN:%s\nFN:%s\n" n name))
  873. emails-list result phones-list)
  874. (concat head
  875. (when email (progn
  876. (setq emails-list (org-contacts-remove-ignored-property-values ignore-list (org-contacts-split-property email)))
  877. (setq result "")
  878. (while emails-list
  879. (setq result (concat result "EMAIL:" (org-contacts-strip-link (car emails-list)) "\n"))
  880. (setq emails-list (cdr emails-list)))
  881. result))
  882. (when addr
  883. (format "ADR:;;%s\n" (replace-regexp-in-string "\\, ?" ";" addr)))
  884. (when tel (progn
  885. (setq phones-list (org-contacts-remove-ignored-property-values ignore-list (org-contacts-split-property tel)))
  886. (setq result "")
  887. (while phones-list
  888. (setq result (concat result "TEL:" (org-link-unescape (org-contacts-strip-link (car phones-list))) "\n"))
  889. (setq phones-list (cdr phones-list)))
  890. result))
  891. (when bday
  892. (let ((cal-bday (calendar-gregorian-from-absolute (org-time-string-to-absolute bday))))
  893. (format "BDAY:%04d-%02d-%02d\n"
  894. (calendar-extract-year cal-bday)
  895. (calendar-extract-month cal-bday)
  896. (calendar-extract-day cal-bday))))
  897. (when nick (format "NICKNAME:%s\n" nick))
  898. (when note (format "NOTE:%s\n" note))
  899. "END:VCARD\n\n")))
  900. (defun org-contacts-export-as-vcard (&optional name file to-buffer)
  901. "Export org contacts to V-Card 3.0.
  902. By default, all contacts are exported to `org-contacts-vcard-file'.
  903. When NAME is \\[universal-argument], prompts for a contact name.
  904. When NAME is \\[universal-argument] \\[universal-argument],
  905. prompts for a contact name and a file name where to export.
  906. When NAME is \\[universal-argument] \\[universal-argument]
  907. \\[universal-argument], prompts for a contact name and a buffer where to export.
  908. If the function is not called interactively, all parameters are
  909. passed to `org-contacts-export-as-vcard-internal'."
  910. (interactive "P")
  911. (when (called-interactively-p 'any)
  912. (cl-psetf name
  913. (when name
  914. (read-string "Contact name: "
  915. (first (org-contacts-at-point))))
  916. file
  917. (when (equal name '(16))
  918. (read-file-name "File: " nil org-contacts-vcard-file))
  919. to-buffer
  920. (when (equal name '(64))
  921. (read-buffer "Buffer: "))))
  922. (org-contacts-export-as-vcard-internal name file to-buffer))
  923. (defun org-contacts-export-as-vcard-internal (&optional name file to-buffer)
  924. "Export all contacts matching NAME as VCard 3.0.
  925. If TO-BUFFER is nil, the content is written to FILE or
  926. `org-contacts-vcard-file'. If TO-BUFFER is non-nil, the buffer
  927. is created and the VCard is written into that buffer."
  928. (let* ((filename (or file org-contacts-vcard-file))
  929. (buffer (if to-buffer
  930. (get-buffer-create to-buffer)
  931. (find-file-noselect filename))))
  932. (message "Exporting...")
  933. (set-buffer buffer)
  934. (let ((inhibit-read-only t)) (erase-buffer))
  935. (fundamental-mode)
  936. (when (fboundp 'set-buffer-file-coding-system)
  937. (set-buffer-file-coding-system coding-system-for-write))
  938. (loop for contact in (org-contacts-filter name)
  939. do (insert (org-contacts-vcard-format contact)))
  940. (if to-buffer
  941. (current-buffer)
  942. (progn (save-buffer) (kill-buffer)))))
  943. (defun org-contacts-show-map (&optional name)
  944. "Show contacts on a map.
  945. Requires google-maps-el."
  946. (interactive)
  947. (unless (fboundp 'google-maps-static-show)
  948. (error "`org-contacts-show-map' requires `google-maps-el'"))
  949. (google-maps-static-show
  950. :markers
  951. (loop
  952. for contact in (org-contacts-filter name)
  953. for addr = (cdr (assoc-string org-contacts-address-property (caddr contact)))
  954. if addr
  955. collect (cons (list addr) (list :label (string-to-char (car contact)))))))
  956. (defun org-contacts-strip-link (link)
  957. "Remove brackets, description, link type and colon from an org
  958. link string and return the pure link target."
  959. (let (startpos colonpos endpos)
  960. (setq startpos (string-match (regexp-opt '("[[tel:" "[[mailto:")) link))
  961. (if startpos
  962. (progn
  963. (setq colonpos (string-match ":" link))
  964. (setq endpos (string-match "\\]" link))
  965. (if endpos (substring link (1+ colonpos) endpos) link))
  966. (progn
  967. (setq startpos (string-match "mailto:" link))
  968. (setq colonpos (string-match ":" link))
  969. (if startpos (substring link (1+ colonpos)) link)))))
  970. (defun org-contacts-split-property (string &optional separators omit-nulls)
  971. "Custom version of `split-string'.
  972. Split a property STRING into sub-strings bounded by matches
  973. for SEPARATORS but keep Org links intact.
  974. The beginning and end of STRING, and each match for SEPARATORS, are
  975. splitting points. The substrings matching SEPARATORS are removed, and
  976. the substrings between the splitting points are collected as a list,
  977. which is returned.
  978. If SEPARATORS is non-nil, it should be a regular expression
  979. matching text which separates, but is not part of, the
  980. substrings. If nil it defaults to `org-contacts-property-values-separators',
  981. normally \"[,; \f\t\n\r\v]+\", and OMIT-NULLS is forced to t.
  982. If OMIT-NULLS is t, zero-length substrings are omitted from the list \(so
  983. that for the default value of SEPARATORS leading and trailing whitespace
  984. are effectively trimmed). If nil, all zero-length substrings are retained."
  985. (let* ((omit-nulls (if separators omit-nulls t))
  986. (rexp (or separators org-contacts-property-values-separators))
  987. (inputlist (split-string string rexp omit-nulls))
  988. (linkstring "")
  989. (bufferstring "")
  990. (proplist (list "")))
  991. (while inputlist
  992. (setq bufferstring (pop inputlist))
  993. (if (string-match "\\[\\[" bufferstring)
  994. (progn
  995. (setq linkstring (concat bufferstring " "))
  996. (while (not (string-match "\\]\\]" bufferstring))
  997. (setq bufferstring (pop inputlist))
  998. (setq linkstring (concat linkstring bufferstring " ")))
  999. (setq proplist (cons (org-trim linkstring) proplist)))
  1000. (setq proplist (cons bufferstring proplist))))
  1001. (cdr (reverse proplist))))
  1002. (provide 'org-contacts)
  1003. ;;; org-contacts.el ends here