[O] [PATCH] org-contacts: Implement a way to ignore certain new addresses

2013-08-22 Thread Frank Terbeck
With some bugtrackers (like the one github uses or with roundup for
example) or when you use gwene to follow certain site's RSS feeds,
you may run into situations, where `org-contacts-check-mail-address'
will ask if it should add a non-sensical email-address.

With this change, you can fine-tune in which situations org-contacts
is going ask you about whether or not you want to add a given new
address to an existing contact.

Valid values are functions that accept one argument and strings, that
will be used at regular expressions via `string-match'.

A minimal example is this:

  (add-to-list 'org-contacts-new-address-ignore
   "notifications@github\\.com")

The following is equivalent:

  (add-to-list 'org-contacts-new-address-ignore
   #'(lambda (x)
   (string-match "notifications@github\\.com" x)))

Signed-off-by: Frank Terbeck 
---

  Please keep me CC:ed, as I am not subscribed.

 contrib/lisp/org-contacts.el | 45 +++-
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index 97171d0..dd90a92 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -155,6 +155,25 @@ The following replacements are available:
   :type 'string
   :group 'org-contacts)
 
+(defcustom org-contacts-new-address-ignore
+  nil
+  "List of checks to run to determine whether or not to add a new
+email address to an existing contact.
+
+If an entry is a string, it is assumed to be a regular expression
+to match against the new address. If it is a symbol, it is
+assumed to be a function, that takes one argument, which is going
+to be set to the new address.
+
+If the regular expression matches or the function returns a
+non-nil value, the new address is not considered to be added to
+the existing account.
+
+Finally, here is an example:
+
+  (add-to-list 'org-contacts-new-address-ignore
+   \"notifications@github.com\")")
+
 (defcustom org-contacts-matcher
   (mapconcat 'identity (list org-contacts-email-property
 org-contacts-alias-property
@@ -728,13 +747,29 @@ This function should be called from 
`gnus-article-prepare-hook'."
   (concat (org-contacts-format-name name) " <" email ">")
 email))
 
+(defun org-contacts-new-address-ignored (mail)
+  "Check whether a mail address is marked to be ignored via the
+`org-contacts-new-address-ignore' list."
+  (catch 'ignored-mail
+(dolist (matcher org-contacts-new-address-ignore)
+  (cond ((stringp matcher)
+ (and (string-match matcher mail)
+  (throw 'ignored-mail t)))
+((functionp matcher)
+ (and (funcall matcher mail)
+  (throw 'ignored-mail t)))
+;; Ignore all other entries.
+(t t)))
+(throw 'ignored-mail nil)))
+
 (defun org-contacts-check-mail-address (mail)
   "Add MAIL address to contact at point if it does not have it."
-  (let ((mails (org-entry-get (point) org-contacts-email-property)))
-(unless (member mail (split-string mails))
-  (when (yes-or-no-p
- (format "Do you want to add this address to %s?" (org-get-heading 
t)))
-(org-set-property org-contacts-email-property (concat mails " " 
mail))
+  (unless (org-contacts-new-address-ignored mail)
+(let ((mails (org-entry-get (point) org-contacts-email-property)))
+  (unless (member mail (split-string mails))
+(when (yes-or-no-p
+   (format "Do you want to add this address to %s?" 
(org-get-heading t)))
+  (org-set-property org-contacts-email-property (concat mails " " 
mail)))
 
 (defun org-contacts-gnus-check-mail-address ()
   "Check that contact has the current address recorded.
-- 
1.8.3




Re: [O] [PATCH] Make `org-contacts-message-complete-function' work with byte compilation

2013-03-11 Thread Frank Terbeck
Daimrod wrote:
> Achim Gratz  writes:
>> Daimrod writes:
>>> @All: Can I use (require 'cl) and ignore the warning or is there better
>>> solution?
>>
>> You could if this would never go into mainline, where it is not allowed
>> due to the namespace pollution that cl causes.  You could use cl-lib
>> instead, but then this would be an Emacs-24 only solution.  In general,
>> the stanza ((eval-when-compile (require 'cl)) only works as intended
>> when you are only using cl macros, but you seem to use defuns.  You
>> could check how hard it is to replace these with plain elisp, aside from
>> syntactical inconveniences this is usually not a big problem.
>
> I've done this, thanks for the advice.


I've just given the latest git HEAD version a spin and it seems to work
as expected. Thanks for taking an interesting and fixing this so
promptly. ;)


Regards, Frank



[O] [PATCH] Make `org-contacts-message-complete-function' work with byte compilation

2013-03-09 Thread Frank Terbeck
Without this patch (when I am _byte-compiling_ org-contacts.el), I am
getting error messages like this (when attempting address completion via
`completion-at-point' and `org-contacts-message-complete-function'):

Symbol's function definition is void: remove-duplicates
Symbol's function definition is void: some

With this patch, it seems to be working as expected.
---

Disclaimer: I'm no Elisp expert. Maybe this should be solved
differently.

 contrib/lisp/org-contacts.el | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index ab44a7b..ac5ff6d 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -36,10 +36,8 @@
 ;;
 ;;; Code:
 
-(eval-when-compile
-  (require 'cl))
-
 (eval-and-compile
+  (require 'cl)
   (require 'org))
 (require 'gnus-util)
 (require 'gnus-art)
-- 
1.8.2.rc1




Re: [O] org-capture with org-contacts template causing problems

2013-03-04 Thread Frank Terbeck
Frank Terbeck wrote:
> Frank Terbeck wrote:
> [...]
>> When using `org-capture' (and then selecting "c" in the menu window), I
>> get the following error message in the "CAPTURE-contacts.org" buffer:
>>
>> * %![Error: (invalid-function gnus-with-article-headers)]
>> :PROPERTIES:
>> :EMAIL: %![Error: (invalid-function gnus-with-article-headers)]
>> :END:
> [...]
>
> Turns out, this problem is triggered when I byte-compile org-contacts.el
> inside my .emacs.d directory. The compilation process yields the
> following warnings:
>
> Compiling /home/hawk/.emacs.d/vendor/org-contacts.el...
[...]
> vendor/org-contacts.el:870:1:Warning: the following functions are not known to
> be defined: org-reverse-string, mail-abbrev-in-expansion-header-p,
> gnus-with-article-headers, diary-ordinal-suffix, gnus-with-article-buffer,
> elmo-message-field, std11-narrow-to-header, std11-fetch-field,
> erc-get-channel-user-list, org-install-letbind, google-maps-static-show
> Wrote /home/hawk/.emacs.d/vendor/org-contacts.elc
>
>
> `org-capture' with the `org-contacts' template works fine if I move the
> corresponding .elc file out of the way.
>
> My guess is, that there are a few `requires' missing in the
> `eval-and-compile' form on top of `org-contacts.el'. Maybe someone with
> more intimate knowledge of the involved code than myself has an idea as
> to how to fix this?

Here's a diff, that removes some of the warnings and in turn makes my
use-case work again, even with a byte-compiled `org-contacts.el':


diff --git a/vendor/org-contacts.el b/vendor/org-contacts.el
index 4ffe360..f6234b6 100644
--- a/vendor/org-contacts.el
+++ b/vendor/org-contacts.el
@@ -42,6 +42,8 @@
 (eval-and-compile
   (require 'org))
 (require 'gnus-util)
+(require 'gnus-art)
+(require 'mail-utils)
 (require 'org-agenda)
 (require 'org-capture)
 
I guess, similar additions could fix the other warnings as well.

Regards, Frank



Re: [O] org-capture with org-contacts template causing problems

2013-03-04 Thread Frank Terbeck
Frank Terbeck wrote:
[...]
> When using `org-capture' (and then selecting "c" in the menu window), I
> get the following error message in the "CAPTURE-contacts.org" buffer:
>
> * %![Error: (invalid-function gnus-with-article-headers)]
> :PROPERTIES:
> :EMAIL: %![Error: (invalid-function gnus-with-article-headers)]
> :END:
[...]

Turns out, this problem is triggered when I byte-compile org-contacts.el
inside my .emacs.d directory. The compilation process yields the
following warnings:

Compiling /home/hawk/.emacs.d/vendor/org-contacts.el...

In org-contacts-db-need-update-p:
vendor/org-contacts.el:169:14:Warning: function `some' from cl package called
at runtime

In org-contacts-filter:
vendor/org-contacts.el:211:37:Warning: function `some' from cl package called
at runtime

In org-contacts-test-completion-prefix:
vendor/org-contacts.el:373:12:Warning: function `find-if' from cl package
called at runtime

In org-contacts-complete-name:
vendor/org-contacts.el:445:71:Warning: function `remove-duplicates' from cl
package called at runtime

In org-contacts-gnus-insinuate:
vendor/org-contacts.el:646:15:Warning: reference to free variable
`gnus-summary-mode-map'

In end of data:
vendor/org-contacts.el:870:1:Warning: the following functions might not be
defined at runtime: some, find-if, remove-duplicates
vendor/org-contacts.el:870:1:Warning: the following functions are not known to
be defined: org-reverse-string, mail-abbrev-in-expansion-header-p,
gnus-with-article-headers, diary-ordinal-suffix, gnus-with-article-buffer,
elmo-message-field, std11-narrow-to-header, std11-fetch-field,
erc-get-channel-user-list, org-install-letbind, google-maps-static-show
Wrote /home/hawk/.emacs.d/vendor/org-contacts.elc


`org-capture' with the `org-contacts' template works fine if I move the
corresponding .elc file out of the way.

My guess is, that there are a few `requires' missing in the
`eval-and-compile' form on top of `org-contacts.el'. Maybe someone with
more intimate knowledge of the involved code than myself has an idea as
to how to fix this?


Regards, Frank



[O] org-capture with org-contacts template causing problems

2013-03-03 Thread Frank Terbeck
Good day!

So, I tried giving org-contacts another go.

For capturing new contacts, I have this template configured (based on
the example on org-contacts.el):

#+begin_src elisp
(add-to-list 'org-capture-templates
  '("c" "Contacts" entry (file "~/org/contacts.org")
  "
** %(org-contacts-template-name)
:PROPERTIES:
:EMAIL: %(org-contacts-template-email)
:END:"))
#+end_src

When using `org-capture' (and then selecting "c" in the menu window), I
get the following error message in the "CAPTURE-contacts.org" buffer:

* %![Error: (invalid-function gnus-with-article-headers)]
:PROPERTIES:
:EMAIL: %![Error: (invalid-function gnus-with-article-headers)]
:END:

The following however works from the `*scratch*' buffer:

#+begin_src elisp
(gnus-with-article-headers
  (mail-fetch-field "From"))
#+end_src

This is with an emacs snapshot, M-x version:
GNU Emacs 24.3.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2) of
2013-03-01 on jim, modified by Debian

M-x org-version:
Org-mode version 7.9.3e (7.9.3e-3-gb07a9b @ /usr/share/emacs/24.3.50/lisp/org/)

This is with `org-contacts.el' from org-mode's git HEAD.

I'm unsure about how to debug this. Any pointers welcome.

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
  -- RFC 1925