emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-contacts email completion by tags
@ 2014-06-04 23:16 John Kitchin
  2014-06-05  4:51 ` Daimrod
  0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2014-06-04 23:16 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

Hi all,

I have setup org-contacts and completion of emails in message mode. I have
some contacts that are tagged :group: and some tagged :group:ms:

If I put +group in the email To field, it completes to all of the entries
(awesome!)

But +group-ms does not work. Is that a bug, or a known limit of
org-contacts? That search works fine with C-c am.

Thanks,

John

-----------------------------------
John Kitchin
Associate Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

[-- Attachment #2: Type: text/html, Size: 868 bytes --]

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

* Re: org-contacts email completion by tags
  2014-06-04 23:16 org-contacts email completion by tags John Kitchin
@ 2014-06-05  4:51 ` Daimrod
  2014-06-05 11:33   ` John Kitchin
  0 siblings, 1 reply; 8+ messages in thread
From: Daimrod @ 2014-06-05  4:51 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode@gnu.org

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Hi all,
>
> I have setup org-contacts and completion of emails in message mode. I have some contacts that are tagged :group: and some tagged :group:ms:
>
> If I put +group in the email To field, it completes to all of the entries (awesome!)
>
> But +group-ms does not work. Is that a bug, or a known limit of org-contacts? That search works fine with C-c am.

An unknown limitation of org-contacts. ;)

org-contacts doesn't use `org-tags-view', that's why it doesn't support
this match syntax.

ATM, it is unclear to me how such syntax could be integrated with the
completion mechanism.

Also, I haven't look at the code that handles this in org-mode so I
don't know how easy or hard it would be to use it with org-contacts.


An alternative would be to provide a way to store the addresses of
contacts in a sparse tree or in the *org-agenda* buffer.

e.g.
C-x b contacts.org RET
C-c a m foo+bar RET
M-x org-contacts-copy-contacts RET
C-x b *Group* RET ;; Switch to Gnus
m                 ;; compose a message
C-c C-f           ;; goto From
C-y

WDYT?


Best,
-- 
Daimrod/Greg

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

* Re: org-contacts email completion by tags
  2014-06-05  4:51 ` Daimrod
@ 2014-06-05 11:33   ` John Kitchin
  2014-06-05 11:50     ` Daimrod
  0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2014-06-05 11:33 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode@gnu.org

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

neat idea. This code does exactly what I need for the completion for a
whole tag query. It should be possible to integrate that into completion.

(defun insert-emails-from-tags (tags)
  (interactive "sTags: ")
  (insert
   (save-window-excursion
     (find-file "contacts-bbdb.org")
     (mapconcat
      'identity
      (let ((todo-only nil))
    (org-scan-tags
     (lambda ()
       (org-entry-get (point) "EMAIL")) ; action
     (cdr (org-make-tags-matcher tags)) ; matcher
     nil)) ", "))))

It should be possible to integrate this into the org-contacts database to
get this with completion. I will look into this later today. Thanks for the
ideas.



John

-----------------------------------
John Kitchin
Associate Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu



On Thu, Jun 5, 2014 at 12:51 AM, Daimrod <daimrod@gmail.com> wrote:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
> > Hi all,
> >
> > I have setup org-contacts and completion of emails in message mode. I
> have some contacts that are tagged :group: and some tagged :group:ms:
> >
> > If I put +group in the email To field, it completes to all of the
> entries (awesome!)
> >
> > But +group-ms does not work. Is that a bug, or a known limit of
> org-contacts? That search works fine with C-c am.
>
> An unknown limitation of org-contacts. ;)
>
> org-contacts doesn't use `org-tags-view', that's why it doesn't support
> this match syntax.
>
> ATM, it is unclear to me how such syntax could be integrated with the
> completion mechanism.
>
> Also, I haven't look at the code that handles this in org-mode so I
> don't know how easy or hard it would be to use it with org-contacts.
>
>
> An alternative would be to provide a way to store the addresses of
> contacts in a sparse tree or in the *org-agenda* buffer.
>
> e.g.
> C-x b contacts.org RET
> C-c a m foo+bar RET
> M-x org-contacts-copy-contacts RET
> C-x b *Group* RET ;; Switch to Gnus
> m                 ;; compose a message
> C-c C-f           ;; goto From
> C-y
>
> WDYT?
>
>
> Best,
> --
> Daimrod/Greg
>

[-- Attachment #2: Type: text/html, Size: 3156 bytes --]

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

* Re: org-contacts email completion by tags
  2014-06-05 11:33   ` John Kitchin
@ 2014-06-05 11:50     ` Daimrod
  2014-06-05 16:54       ` John Kitchin
  0 siblings, 1 reply; 8+ messages in thread
From: Daimrod @ 2014-06-05 11:50 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode@gnu.org

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> neat idea. This code does exactly what I need for the completion for a
> whole tag query. It should be possible to integrate that into
> completion.
>
> (defun insert-emails-from-tags (tags)
>   (interactive "sTags: ")
>   (insert
>    (save-window-excursion
>      (find-file "contacts-bbdb.org")
>      (mapconcat
>       'identity
>       (let ((todo-only nil))
>     (org-scan-tags
>      (lambda ()
>        (org-entry-get (point) "EMAIL")) ; action
>      (cdr (org-make-tags-matcher tags)) ; matcher
>      nil)) ", "))))
>
> It should be possible to integrate this into the org-contacts database
> to get this with completion. I will look into this later today. Thanks
> for the ideas.

The completion for group based on tags is done in the function
`org-contacts-complete-group'.

It's been a long time since I played with the completion mechanism, so I
don't remember exactly how it worked. Maybe you can replace the mapcar
with your function, but it might a bit more tricky than that, especially
to handle empty result.

Thanks for your work :)

Best,

-- 
Daimrod/Greg

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

* Re: org-contacts email completion by tags
  2014-06-05 11:50     ` Daimrod
@ 2014-06-05 16:54       ` John Kitchin
  2014-06-07  1:39         ` John Kitchin
  0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2014-06-05 16:54 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode@gnu.org

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

On Thu, Jun 5, 2014 at 7:50 AM, Daimrod <daimrod@gmail.com> wrote:

> org-contacts-complete-group


Here is a better function I think. It uses the builtin org-contacts
database:

(defun insert-emails-from-tags (tag-expression)
  "insert emails from org-contacts that match the tags expression. For
example:
group-phd will match entries tagged with group but not with phd."
  (interactive "sTags: ")
  (insert
   (mapconcat 'identity
          (loop for contact in (org-contacts-filter)
            for contact-name = (car contact)
            for email = (org-contacts-strip-link (car
(org-contacts-split-property
                                   (or
                                (cdr (assoc-string
org-contacts-email-property
                                           (caddr contact)))
                                ""))))
            for tags = (cdr (assoc "TAGS" (nth 2 contact)))
            for tags-list = (if tags
                    (split-string (substring (cdr (assoc "TAGS" (nth 2
contact))) 1 -1) ":")
                      '())
            if (let ((todo-only nil))
             (eval (cdr (org-make-tags-matcher tag-expression))))

            collect (org-contacts-format-email contact-name email))
          ",")))


John

-----------------------------------
John Kitchin
Associate Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

[-- Attachment #2: Type: text/html, Size: 2378 bytes --]

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

* Re: org-contacts email completion by tags
  2014-06-05 16:54       ` John Kitchin
@ 2014-06-07  1:39         ` John Kitchin
  2014-06-17  7:45           ` Daimrod
  0 siblings, 1 reply; 8+ messages in thread
From: John Kitchin @ 2014-06-07  1:39 UTC (permalink / raw)
  To: Daimrod; +Cc: emacs-orgmode@gnu.org

Here is what I finally ended up with to allow completion with tag
expressions. I did not figure out how to avoid overwriting an
org-contacts function. I thought I could find the right hooks to use,
but I could not figure it out. It is only a one line modification to the
org-contacts function. This works for tag expressions, but I have not
gotten it to work with properties.


(defun org-contacts-complete-tags (start end tag-expression)
  "insert emails from org-contacts that match the tags expression. For example:
group-phd will match entries tagged with group but not with phd."
  (let* ((completion-ignore-case org-contacts-completion-ignore-case)
	 (group-completion-p t))
    (let ((result (mapconcat 'identity
		     (loop for contact in (org-contacts-db)
			   for contact-name = (car contact)
			   for email = (org-contacts-strip-link (car (org-contacts-split-property
								      (or
								       (cdr (assoc-string org-contacts-email-property
											  (caddr contact)))
								       ""))))
			   for tags = (cdr (assoc "TAGS" (nth 2 contact)))
			   for tags-list = (if tags
					       (split-string (substring (cdr (assoc "TAGS" (nth 2 contact))) 1 -1) ":")
					     '())
			   if (let ((todo-only nil))
				(eval (cdr (org-make-tags-matcher tag-expression))))
			   
			   collect (org-contacts-format-email contact-name email))
		     ",")))
      (when (not (string= "" result))
	;; return (start end function)
	(lexical-let* ((to-return result))
	  (list start end
		(lambda (string pred &optional to-ignore) to-return)))))))
	  
this is the function I overwrote in my init files:
	  
(defun org-contacts-message-complete-function (&optional start)
  "Function used in `completion-at-point-functions' in `message-mode'."
  ;; Avoid to complete in `post-command-hook'.
  (when completion-in-region-mode
    (remove-hook 'post-command-hook #'completion-in-region--postch))
  (let ((mail-abbrev-mode-regexp
         "^\\(Resent-To\\|To\\|B?Cc\\|Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\|Disposition-Notification-To\\|Return-Receipt-To\\):"))
    (when (mail-abbrev-in-expansion-header-p)
      (lexical-let*
	  ((end (point))
	   (start (or start
		      (save-excursion
			(re-search-backward "\\(\\`\\|[\n:,]\\)[ \t]*")
			(goto-char (match-end 0))
			(point))))
	   (string (buffer-substring start end)))
	(or
	 ;; I added the next line
	 (org-contacts-complete-tags start end string)
	 (org-contacts-complete-group start end string)
	 (org-contacts-complete-name start end string))))))

-- 
-----------------------------------
John Kitchin
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

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

* Re: org-contacts email completion by tags
  2014-06-07  1:39         ` John Kitchin
@ 2014-06-17  7:45           ` Daimrod
  2014-07-13 10:48             ` Daimrod
  0 siblings, 1 reply; 8+ messages in thread
From: Daimrod @ 2014-06-17  7:45 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode@gnu.org

John Kitchin <jkitchin@andrew.cmu.edu> writes:

Hi,

First, sorry for the late reply.

> Here is what I finally ended up with to allow completion with tag
> expressions. I did not figure out how to avoid overwriting an
> org-contacts function. I thought I could find the right hooks to use,
> but I could not figure it out. It is only a one line modification to the
> org-contacts function.

I've added a new hook `org-contacts-complete-functions' that you can use
to plug your function.

> This works for tag expressions, but I have not
> gotten it to work with properties.
>
> (defun org-contacts-complete-tags (start end tag-expression)
>   "insert emails from org-contacts that match the tags expression. For example:
> group-phd will match entries tagged with group but not with phd."
>   (let* ((completion-ignore-case org-contacts-completion-ignore-case)
> 	 (group-completion-p t))
>     (let ((result (mapconcat 'identity
> 		     (loop for contact in (org-contacts-db)
> 			   for contact-name = (car contact)
> 			   for email = (org-contacts-strip-link (car (org-contacts-split-property
> 								      (or
> 								       (cdr (assoc-string org-contacts-email-property
> 											  (caddr contact)))
> 								       ""))))
> 			   for tags = (cdr (assoc "TAGS" (nth 2 contact)))
> 			   for tags-list = (if tags
> 					       (split-string (substring (cdr (assoc "TAGS" (nth 2 contact))) 1 -1) ":")
> 					     '())
> 			   if (let ((todo-only nil))
> 				(eval (cdr (org-make-tags-matcher tag-expression))))
> 			   
> 			   collect (org-contacts-format-email contact-name email))
> 		     ",")))
>       (when (not (string= "" result))
> 	;; return (start end function)
> 	(lexical-let* ((to-return result))
> 	  (list start end
> 		(lambda (string pred &optional to-ignore) to-return)))))))
>

Thanks, but I'm refactoring org-contacts a bit, and I think I have found
a slightly better way to do that, but in the meantime you can use the
aforementioned hook for your function.

Best,

-- 
Daimrod/Greg

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

* Re: org-contacts email completion by tags
  2014-06-17  7:45           ` Daimrod
@ 2014-07-13 10:48             ` Daimrod
  0 siblings, 0 replies; 8+ messages in thread
From: Daimrod @ 2014-07-13 10:48 UTC (permalink / raw)
  To: John Kitchin; +Cc: emacs-orgmode@gnu.org

Daimrod <daimrod@gmail.com> writes:

> Thanks, but I'm refactoring org-contacts a bit, and I think I have found
> a slightly better way to do that, but in the meantime you can use the
> aforementioned hook for your function.

It turns out that my idea was wrong, so I have used a version very
similar to yours.

The function is triggered by the prefix '#' (customizable) and can be
used to match tags and properties.
e.g. the following expression:
#work-phd&BIRTHDAY<>""
will look for contacts with the tag 'work' but not the tag 'phd' and for
which there is a BIRTHDAY properties.

Best,

-- 
Daimrod/Greg

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

end of thread, other threads:[~2014-07-13 10:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-04 23:16 org-contacts email completion by tags John Kitchin
2014-06-05  4:51 ` Daimrod
2014-06-05 11:33   ` John Kitchin
2014-06-05 11:50     ` Daimrod
2014-06-05 16:54       ` John Kitchin
2014-06-07  1:39         ` John Kitchin
2014-06-17  7:45           ` Daimrod
2014-07-13 10:48             ` Daimrod

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