I have written an interactive function to connect to multiple mysql databases

(defun mysql-connect (name)
  "Connect to a predefined MySQL connection."
    (completing-read "Connect to: " sql-connection-alist
             nil t nil 'pyvenv-workon-history nil nil)))
  (when (not (or (equal name "")
             (equal name nil)))
    (mysql-connect-preset name)))

If I run M-x mysql-connect, it will prompt user to select available options. But I want to invoke it via script.

If I run (mysql-connect 'some-choice) it will work, but I dont want that. I just want to invoke mysql-connect and let user to select choice.

How can I just invoke that function?

  • Doesn't simply evaluating (mysql-connect) offer you the choices in the same manner as an interactive call? – Quarky Sep 17 '15 at 13:32
  • No, it will throw error as it requires one argument. – ChillarAnand Sep 17 '15 at 13:34

You need to use call-interactively here.

Usage example:

(call-interactively #'foo)

You can learn more about it by doing C-h i g (elisp) Interactive Call and C-h f call-interactively.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.