Re: [PATCH] TAB completion for organization field

2013-01-03 Thread Roland Winkler
On Thu Jan 3 2013 Stefan Monnier wrote:
> You can use a minibuffer-with-setup-hook to change the keymap used in
> your particular completing-read-multiple calls.

Thanks, that seems reasonable.

> Yes, that's currently a limitation of crm.el.  Patch welcome.

I already looked into crm.el. I'll let you know.

Roland

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [PATCH] TAB completion for organization field

2012-12-31 Thread Eric Abrahamsen
"Roland Winkler"  writes:

> On Fri Dec 28 2012 Stefan Monnier wrote:
>> > rewrite. But I believe it does not (yet?) offer completion when the
>> > result of the completion is supposed to be a list of values.
>> 
>> IIUC completing-read-multiple should do what you want (and has been
>> included in Emacs for a while, at least since Emacs-22 if not longer).
>
> The keymap used by completing-read-multiple binds SPC to
> crm-complete-word. For users not expecting completion, this has two
> consequence that might appear counterintuitive:
>
> - If one string in the list of return values is supposed to contain
>   the SPC character (which I do not find unusual in the context of,
>   say, the organization field of BBDB), this requires C-q SPC.
>
> - In BBDB, the list of organizations is displayed with the
>   two-character string ", " as separator. Likewise, this list of
>   organizations is generated from the return value of read-string
>   using split-string with separator "[ \t\n]*[;,][ \t\n]*". Such
>   regexps are not supported by crm-separator. (The latter must be a
>   single character string).
>
> I still believe that completing-read-multiple is a cool feature and
> I might like to use it myself for entering organizations into BBDB.
> Yet I do not know whether all users will be happy with this feature
> in the context of BBDB's organization field. So it might be better
> to make it customizable whether BBDB uses read-string or
> completing-read-multiple.

Yeah, I've been poking at it and you're right it would be hard to
integrate it seamlessly, without any surprises to the user. Let me see
if I can come up with an okay compromise.


--
Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS
and more. Get SQL Server skills now (including 2012) with LearnDevNow -
200+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only - learn more at:
http://p.sf.net/sfu/learnmore_122512
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [PATCH] TAB completion for organization field

2012-12-30 Thread Roland Winkler
On Fri Dec 28 2012 Stefan Monnier wrote:
> > rewrite. But I believe it does not (yet?) offer completion when the
> > result of the completion is supposed to be a list of values.
> 
> IIUC completing-read-multiple should do what you want (and has been
> included in Emacs for a while, at least since Emacs-22 if not longer).

The keymap used by completing-read-multiple binds SPC to
crm-complete-word. For users not expecting completion, this has two
consequence that might appear counterintuitive:

- If one string in the list of return values is supposed to contain
  the SPC character (which I do not find unusual in the context of,
  say, the organization field of BBDB), this requires C-q SPC.

- In BBDB, the list of organizations is displayed with the
  two-character string ", " as separator. Likewise, this list of
  organizations is generated from the return value of read-string
  using split-string with separator "[ \t\n]*[;,][ \t\n]*". Such
  regexps are not supported by crm-separator. (The latter must be a
  single character string).

I still believe that completing-read-multiple is a cool feature and
I might like to use it myself for entering organizations into BBDB.
Yet I do not know whether all users will be happy with this feature
in the context of BBDB's organization field. So it might be better
to make it customizable whether BBDB uses read-string or
completing-read-multiple.

Roland

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [PATCH] TAB completion for organization field

2012-12-28 Thread Roland Winkler
On Fri Dec 28 2012 Stefan Monnier wrote:
> > rewrite. But I believe it does not (yet?) offer completion when the
> > result of the completion is supposed to be a list of values.
> 
> IIUC completing-read-multiple should do what you want (and has been
> included in Emacs for a while, at least since Emacs-22 if not longer).

Thank you, I learned something new here.

Roland

--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [PATCH] TAB completion for organization field

2012-12-28 Thread Eric Abrahamsen
"Roland Winkler"  writes:

> On Fri Dec 28 2012 Eric Abrahamsen wrote:
>> Yup, I thought of this problem but it seems like it's fudged in
>> other places (ie you can't complete on subsequent values in an AKA
>> field) so I figured this was good enough for now.
>
> It's different in the sense that the values of the organization
> field are shared more often among different records. For something
> like AKA this would be odd.  But AKAs are used in the MUA interface.
> For the organization field this would not be possible. Ultimately,
> this defines the difference between these fields from a more
> conceptual point of view.

Yes, I guess it's sort of the same idea in reverse. Anyhow in this case
Stefan's suggestion of `completing-read-multiple' works. I've tried
using that in `bbdb-read-string' and it works as advertised. Looking
through the code, the only thing this would screw up would be completing
labels for phones and addresses -- suddenly it would be possible to add
multiple labels to phones/addresses, which would be nonsensical. There
would be a number of relatively simple ways around that, though.

>> I can make a record for an organization, with its organization name in
>> the name field, and say an office front desk number in the phone field,
>> etc, but them is there a way of indicating that a separate record (for a
>> person), works there? I can't fill the person's organization field with
>> a "foreign key" to the organization record, right?
>> 
>> I realize this is approaching a relational database model, and is
>> a can of worms that's probably not worth opening. I was just curious.
>
> Ultimately this is not so different from, say, families of friends.
> In a a way, families are just small organizations. It would be nice
> if such records could share fields like the mailing address and home
> phone numbers. But I have no clue how to implement that within BBDB.

Probably you'd end up using EIEIO to make different classes for people,
phones, addresses and organizations, and linking them together. I've
thought before (in a very idle way) that the structs BBDB currently uses
might be better replaced by classes. Awful lot of work, though.


--
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [PATCH] TAB completion for organization field

2012-12-28 Thread Roland Winkler
On Fri Dec 28 2012 Eric Abrahamsen wrote:
> Yup, I thought of this problem but it seems like it's fudged in
> other places (ie you can't complete on subsequent values in an AKA
> field) so I figured this was good enough for now.

It's different in the sense that the values of the organization
field are shared more often among different records. For something
like AKA this would be odd.  But AKAs are used in the MUA interface.
For the organization field this would not be possible. Ultimately,
this defines the difference between these fields from a more
conceptual point of view.

> Not quite sure I understood that... I was under the impression
> that the organization field just holds a list of strings: the
> names of various organizations. Is that what you meant by
> "attributes for a record"?

Yes. The organization field is an attribute in the sense that
usually it is useless to distinguish individual records. But it can
help to classify the records in BBDB.

> I can make a record for an organization, with its organization name in
> the name field, and say an office front desk number in the phone field,
> etc, but them is there a way of indicating that a separate record (for a
> person), works there? I can't fill the person's organization field with
> a "foreign key" to the organization record, right?
> 
> I realize this is approaching a relational database model, and is
> a can of worms that's probably not worth opening. I was just curious.

Ultimately this is not so different from, say, families of friends.
In a a way, families are just small organizations. It would be nice
if such records could share fields like the mailing address and home
phone numbers. But I have no clue how to implement that within BBDB.

Roland

--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [PATCH] TAB completion for organization field

2012-12-27 Thread Eric Abrahamsen
"Roland Winkler"  writes:

> On Fri Dec 28 2012 Eric Abrahamsen wrote:
>> No one asked for this, but it's something I've wanted for a while, so I
>> did it, and am attaching a patch if it's of general interest.
>> 
>> I often add multiple records for different people at the same
>> organization, and have wanted tab completion when creating/editing the
>> organization field. This patch creates and populates a
>> bbdb-organization-list variable on startup, and offers completion from
>> that list when editing or creating organization fields.
>
> Thanks. Me too, I thought about this. So far, I did not implement
> this because the organization field holds a list of values. This
> makes tab completion more tricky if one wants to put multiple
> entries into this field.

Yup, I thought of this problem but it seems like it's fudged in other
places (ie you can't complete on subsequent values in an AKA field) so I
figured this was good enough for now. That would be very cool if the
completing-read engine grew the ability to deal with this.

>> Just out of curiosity, has there ever been a plan to make organizations
>> first-class citizens in the database?
>
> What's that? - The organization field holds (a list of) ATTRIBUTES
> for a record. If a record should refer to a (single) organization
> instead of a person such that the organization is not the attribute
> for something else, I suggest that the name of that organization
> should go into the name field. I think that anything else asks for
> trouble. (Say, typically multiple records will have the same entries
> in the organization field for all your friends / colleagues in an
> organization.)

Not quite sure I understood that... I was under the impression that the
organization field just holds a list of strings: the names of various
organizations. Is that what you meant by "attributes for a record"?

I can make a record for an organization, with its organization name in
the name field, and say an office front desk number in the phone field,
etc, but them is there a way of indicating that a separate record (for a
person), works there? I can't fill the person's organization field with
a "foreign key" to the organization record, right?

I realize this is approaching a relational database model, and is
a can of worms that's probably not worth opening. I was just curious.

E


--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


Re: [PATCH] TAB completion for organization field

2012-12-27 Thread Roland Winkler
On Fri Dec 28 2012 Eric Abrahamsen wrote:
> No one asked for this, but it's something I've wanted for a while, so I
> did it, and am attaching a patch if it's of general interest.
> 
> I often add multiple records for different people at the same
> organization, and have wanted tab completion when creating/editing the
> organization field. This patch creates and populates a
> bbdb-organization-list variable on startup, and offers completion from
> that list when editing or creating organization fields.

Thanks. Me too, I thought about this. So far, I did not implement
this because the organization field holds a list of values. This
makes tab completion more tricky if one wants to put multiple
entries into this field.

Recently the GNU Emacs completion engine went through a major
rewrite. But I believe it does not (yet?) offer completion when the
result of the completion is supposed to be a list of values.

(Stefan, you were largely involved in this rewrite. Can you comment?
Thanks.)

> Just out of curiosity, has there ever been a plan to make organizations
> first-class citizens in the database?

What's that? - The organization field holds (a list of) ATTRIBUTES
for a record. If a record should refer to a (single) organization
instead of a person such that the organization is not the attribute
for something else, I suggest that the name of that organization
should go into the name field. I think that anything else asks for
trouble. (Say, typically multiple records will have the same entries
in the organization field for all your friends / colleagues in an
organization.)

Roland

--
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
___
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/


[PATCH] TAB completion for organization field

2012-12-27 Thread Eric Abrahamsen
No one asked for this, but it's something I've wanted for a while, so I
did it, and am attaching a patch if it's of general interest.

I often add multiple records for different people at the same
organization, and have wanted tab completion when creating/editing the
organization field. This patch creates and populates a
bbdb-organization-list variable on startup, and offers completion from
that list when editing or creating organization fields.

Two things it doesn't do:

1. Offer completion at the '/ o' search prompt -- this might be a bad
idea anyway.

2. Update bbdb-organization-list when the database is saved. I could add
this functionality, and might do so on my own regardless.

If the general idea here is acceptable but there's something wrong with
the implementation, let me know and I'll be happy to edit. But it seemed
pretty straightforward.

Just out of curiosity, has there ever been a plan to make organizations
first-class citizens in the database?

Eric

>From d886366b44d453454a06493c3ffa80009493972b Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen 
Date: Fri, 28 Dec 2012 11:37:03 +0800
Subject: [PATCH] TAB completion for editing/creating organization fields

---
 lisp/bbdb-com.el | 13 -
 lisp/bbdb.el |  9 +
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/lisp/bbdb-com.el b/lisp/bbdb-com.el
index 79e2e7e..8623507 100644
--- a/lisp/bbdb-com.el
+++ b/lisp/bbdb-com.el
@@ -618,7 +618,7 @@ but does ensure that there will not be name collisions."
  (setq name (bbdb-read-name first-and-last))
  (bbdb-check-name (car name) (cdr name)))
 (let ((organizations (bbdb-split 'organization
- (bbdb-read-string "Organizations: ")))
+ (bbdb-read-string "Organizations: " nil bbdb-organization-list)))
   ;; mail
   (mail (bbdb-split 'mail (bbdb-read-string "E-Mail Addresses: ")))
   ;; address
@@ -847,7 +847,7 @@ value of \"\", the default) means do not alter the address."
   (cond (;; affix
  (eq field 'affix) (bbdb-read-string "Affix: " init))
 ;; organization
-((eq field 'organization) (bbdb-read-string "Organization: " init))
+((eq field 'organization) (bbdb-read-string "Organization: " init bbdb-organization-list))
 ;; mail
 ((eq field 'mail)
  (let ((mail (bbdb-read-string "Mail: " init)))
@@ -939,7 +939,9 @@ a phone number or address with VALUE being nil."
   ((eq field 'address)
(unless value (error "No address specified"))
(bbdb-record-edit-address value nil flag))
-  ((setq edit-str (assq field '((affix . "Affix")
+  ((setq collection (if (eq field 'organization)
+bbdb-organization-list nil)
+		 edit-str (assq field '((affix . "Affix")
 (organization . "Organization")
 (mail . "Mail") (aka . "AKA"
(bbdb-record-set-field
@@ -947,8 +949,9 @@ a phone number or address with VALUE being nil."
 (bbdb-split field (bbdb-read-string
(format "%s: " (cdr edit-str))
(bbdb-concat field (funcall (intern (format "bbdb-record-%s" field))
-   record))
-  (t ; xfield
+   record))
+			   collection
+  (t; xfield
(bbdb-record-set-xfield
 record field
 (bbdb-read-string (format "%s: " field)
diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index fdb9883..72aa144 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -1533,6 +1533,11 @@ In the *BBDB* buffers it includes the records that are actually displayed
 and its elements are (RECORD DISPLAY-FORMAT MARKER-POS).")
 (make-variable-buffer-local 'bbdb-records)
 
+(defvar bbdb-organization-list nil
+  "All organizations currently using in the database, for use as
+  completion candidates when adding or editing records'
+  organization field.")
+
 (defvar bbdb-changed-records nil
   "List of records that has been changed since BBDB was last saved.")
 
@@ -2789,6 +2794,10 @@ If `bbdb-file' uses an outdated format, it is migrated to `bbdb-file-format'."
 (dolist (xfield (bbdb-record-xfields record))
   (unless (memq (setq label (car xfield)) bbdb-xfield-label-list)
 (push label bbdb-xfield-label-list)))
+	;; populate bbdb-organization-list
+	(dolist (organization (bbdb-record-organization record))
+	  (unless (member organization bbdb-organization-list)
+		(push organization bbdb-organization-list)))
 
 (let ((name (bbdb-concat 'name-first-last
  (bbdb-record-firstname record)
-- 
1.8.0.2

--
Master HTML5, CSS3, ASP.NET, MVC,