ement.el icon indicating copy to clipboard operation
ement.el copied to clipboard

Using TAB for completion in the minibuffer and compose buffer

Open alphapapa opened this issue 2 years ago • 5 comments

This seems to work, but binding some of these variables may not actually be necessary:

diff --git a/ement-room.el b/ement-room.el
index 0bd1b95..fd74e96 100644
--- a/ement-room.el
+++ b/ement-room.el
@@ -182,6 +182,7 @@ (defvar ement-room-minibuffer-map
   (let ((map (make-sparse-keymap)))
     (set-keymap-parent map minibuffer-local-map)
     (define-key map (kbd "C-c '") #'ement-room-compose-from-minibuffer)
+    (define-key map (kbd "TAB") #'complete-symbol)
     map)
   "Keymap used in `ement-room-read-string'.")
 
@@ -2145,7 +2146,9 @@ (defun ement-room-read-string (prompt &optional initial-input history default-va
           (setq-local completion-at-point-functions
                       '(ement-room--complete-members-at-point ement-room--complete-rooms-at-point))
           (visual-line-mode 1)
-          (run-hooks 'ement-room-read-string-setup-hook))
+          (run-hooks 'ement-room-read-string-setup-hook)
+          (setq-local tab-always-indent 'complete
+                      tab-first-completion t))
       (read-from-minibuffer prompt initial-input ement-room-minibuffer-map
                             nil history default-value inherit-input-method))))
 
@@ -3903,12 +3906,15 @@ (defun ement-room-init-compose-buffer (room session)
   (setf ement-room-compose-buffer t)
   (setq-local completion-at-point-functions
               (append '(ement-room--complete-members-at-point ement-room--complete-rooms-at-point)
-                      completion-at-point-functions))
+                      completion-at-point-functions)
+              tab-always-indent 'complete
+              tab-first-completion t)
   ;; FIXME: Compose with local map?
   (use-local-map (if (current-local-map)
                      (copy-keymap (current-local-map))
                    (make-sparse-keymap)))
   (local-set-key [remap save-buffer] #'ement-room-compose-send)
+  (keymap-set (current-local-map) "TAB" #'indent-for-tab-command)
   (setq header-line-format (substitute-command-keys
                             (format " Press \\[save-buffer] to send message to room (%s)"
                                     (ement-room-display-name room)))))

alphapapa avatar Sep 21 '23 02:09 alphapapa

If anyone's interested, please test this patch to confirm that it works as intended. Also, please test how it works without setting those variables, with the intention of reducing the patch to the minimum necessary for it to work.

alphapapa avatar Feb 22 '24 04:02 alphapapa

For compose-buffers specifically, see also:

https://github.com/alphapapa/ement.el/pull/236/commits/0d9451a25324a7ec71fa6ff7447c999ec508020e#diff-048a63da9ad36159d461f74387e769a0c74b8f150b4bc23631b693bae069da20

phil-s avatar Feb 24 '24 04:02 phil-s

tab-first-completion doesn't list t as a value with any specific meaning. It gets used in indent-for-tab-command like this:

       ((and (eq tab-always-indent 'complete)
             (eql old-point (point))
             (eql old-tick (buffer-chars-modified-tick))
             (or (eq last-command this-command)
                 (let ((syn (syntax-class (syntax-after (point)))))
                   (pcase tab-first-completion
                     ('nil t)
                     ('eol (eolp))
                     ('word (not (eql 2 syn)))
                     ('word-or-paren (not (memq syn '(2 4 5))))
                     ('word-or-paren-or-punct (not (memq syn '(2 4 5 1))))))))
        (completion-at-point))

So t would be "none of the above", effectively reducing that last part to just (eq last-command this-command) -- but I'm unclear whether that's the intention?

phil-s avatar Feb 24 '24 06:02 phil-s

Ah, I use org-tempo a lot when posting code snippets (e.g. typing <s then TAB to get the #+begin_src ... #+end_src delimiters), so that's a conflict.

phil-s avatar Feb 26 '24 04:02 phil-s

Ah, I use org-tempo a lot when posting code snippets (e.g. typing <s then TAB to get the #+begin_src ... #+end_src delimiters), so that's a conflict.

I used to use that, but FYI the new C-c C-, binding does the same thing, and I don't miss the old style anymore. If you haven't tried it, you might end up liking it.

alphapapa avatar Feb 26 '24 06:02 alphapapa