2

New to Emacs: I am trying to populate a completion collection from a sql query: All goes according to plan except the completion list is ends up as individual words rather than the complete list item as a string with spaces.

(defun test_sql_interactive2()

(interactive)

(setq look (emacsql db2 [:select [Accounts:acc_name]:from Accounts]))
 (setq var (completing-read
       "Complete an Account Name: "
       look
       nil t ))
 (insert var))

the variable look is the result of the sql query which returns: ((Collective Retirement Account) (Stocks and Shares) (Current Account) (Savings Account))

but the emacs completing-read function sees this as 8 words to use as the collection to complete from rather than 4 strings, so instead of "Collective Retirement Account" being offered as a completion, it is only "Collective".

How can I have the completion return the entire string with spaces?

Drew
  • 29,895
  • 7
  • 74
  • 104

1 Answers1

1

Change the contents of the alist (value of look) that you pass to completing-read to be strings:

(("Collective Retirement Account") 
 ("Stocks and Shares")
 ("Current Account")
 ("Savings Account"))

This does that:

(let ((look  '((Collective Retirement Account)
               (Stocks and Shares)
               (Current Account)
               (Savings Account))))
  (mapcar (lambda (xx) (list (substring (format "%s" xx) 1 -1)))
          look))
Drew
  • 29,895
  • 7
  • 74
  • 104