kostafey / ejc-sql

Emacs SQL client uses Clojure JDBC.
278 stars 29 forks source link

want imploded ivy! #142

Closed sincebyte closed 3 years ago

sincebyte commented 3 years ago

Is it possible to use the ivy plugin when M-x ejc-connect choose. Can you give an example about the config?

kostafey commented 3 years ago

Yoy can define a function like that:

(defun ejc-connect-ivy ()
  (interactive)
  (let* ((conn-list (mapcar 'car ejc-connections))
         (conn-statistics (ejc-load-conn-statistics))
         (conn-list-sorted (-sort (lambda (c1 c2)
                                    (> (or (lax-plist-get conn-statistics c1) 0)
                                       (or (lax-plist-get conn-statistics c2) 0)))
                                  conn-list)))
    (ivy-read "DataBase connection name: " conn-list-sorted
              :keymap ivy-minibuffer-map
              :preselect (car conn-list-sorted)
              :action #'ejc-connect)))

Then use it just like ejc-connect in any sql-mode/org-mode buffers: M-x ejc-connect-ivy

tpeacock19 commented 3 years ago

You can also change the two instances of ido-completing-read to completing-read in the ejc-sql.el file and it should work with any completion framework.

@kostafey is there a reason ido is hardcoded?

kostafey commented 3 years ago

@tpeacock19 as far as I see, I can't use flx-ido if ido-completing-read is replaced by completing-read despite this settings:

(ido-mode 1)
(ido-everywhere 1)
(flx-ido-mode 1)

The reason for ido is it's flx fuzzy matching engine, which is handy. But ok, it's only my habits, so it's worth to use modern completion frameworks for most of the users. The solution may look like this:

+(defalias 'ejc-completing-read 'completing-read)
+
 (defun ejc-read-connection-name ()
   "Read connection-name in minibuffer."
-  (ido-completing-read
+  (ejc-completing-read
 ...

so, to keep backward compatibility, one can set in personal .emacs a setting like that:

(defalias 'ejc-completing-read 'ido-completing-read)

Furthermore, fell free to make a pull request if you agree with this idea.

tpeacock19 commented 3 years ago

Great, yeah I'll send over what I have shortly. Most of it is lifted from projectile.el.

As far as ido, perhaps you can set the completing-read-function to ido-completing-read. I'm not sure of any side effects as I use selectrum and orderless to handle my completion and would highly suggest them.

sincebyte commented 3 years ago

Thank you,ejc-sql is so cool~

kostafey commented 3 years ago

Fixed.

sincebyte commented 3 years ago

Yoy can define a function like that:

(defun ejc-connect-ivy ()
  (interactive)
  (let* ((conn-list (mapcar 'car ejc-connections))
         (conn-statistics (ejc-load-conn-statistics))
         (conn-list-sorted (-sort (lambda (c1 c2)
                                    (> (or (lax-plist-get conn-statistics c1) 0)
                                       (or (lax-plist-get conn-statistics c2) 0)))
                                  conn-list)))
    (ivy-read "DataBase connection name: " conn-list-sorted
              :keymap ivy-minibuffer-map
              :preselect (car conn-list-sorted)
              :action #'ejc-connect)))

Then use it just like ejc-connect in any sql-mode/org-mode buffers: M-x ejc-connect-ivy

Thanks for your ejc-connect-ivy function, I have used it for a long time. However, there is a problem in my emacs environment. And the problem is that I must execute ejc-connect first, otherwise the system shows "let*: Symbol’s value as variable is void: ejc-connections". How to achieve my goal by only executing 'ejc-connect-ivy' rather than executing 2 steps.