1

I’m using Distel for my erlang development but the function that is used for completion is printing its output in an ibuffer. I would like to get it in the minibuffer with ido support instead, does anyone know of a way to do it?

Here is the code:

(defun erl-complete (node)
  "Complete the module or remote function name at point."
  (interactive (list (erl-target-node)))
  (let ((win (get-buffer-window "*Completions*" 0)))
    (if win (with-selected-window win (bury-buffer))))
  (let ((end (point))
    (beg (ignore-errors 
           (save-excursion (backward-sexp 1)
                   ;; FIXME: see erl-goto-end-of-call-name
                   (when (eql (char-before) ?:)
                 (backward-sexp 1))
                   (point)))))
    (when beg
      (let* ((str (buffer-substring-no-properties beg end))
         (buf (current-buffer))
         (continuing (equal last-command (cons 'erl-complete str))))
    (setq this-command (cons 'erl-complete str))
    (if (string-match "^\\(.*\\):\\(.*\\)$" str)
        ;; completing function in module:function
        (let ((mod (intern (match-string 1 str)))
          (pref (match-string 2 str))
          (beg (+ beg (match-beginning 2))))
          (erl-spawn
        (erl-send-rpc node 'distel 'functions (list mod pref))
        (&erl-receive-completions "function" beg end pref buf
                      continuing
                      #'erl-complete-sole-function)))
      ;; completing just a module
      (erl-spawn
        (erl-send-rpc node 'distel 'modules (list str))
        (&erl-receive-completions "module" beg end str buf continuing
                      #'erl-complete-sole-module)))))))

(defun &erl-receive-completions (what beg end prefix buf continuing sole)
  (let ((state (erl-async-state buf)))
    (erl-receive (what state beg end prefix buf continuing sole)
    ((['rex ['ok completions]]
      (when (equal state (erl-async-state buf))
        (with-current-buffer buf
          (erl-complete-thing what continuing beg end prefix
                  completions sole))))
     (['rex ['error reason]]
      (message "Error: %s" reason))
     (other
      (message "Unexpected reply: %S" other))))))
SpaceOgre
  • 107
  • 1
  • 12
  • I don't quite understand. You're talking about doing completion in the minibuffer, but the code you show seems to be about doing completion "in buffer". So I think you want to setup a `completion-at-point-functions`. – Stefan Jun 18 '13 at 23:04
  • Yeah, that was my question more or less: How do I change this code so all the alternatives for completion is shown in the minibuffer (with ido support) instead of a interactive buffer. I have not written the code above it is from the [Distel](https://github.com/massemanet/distel) package, and to be frank my elisp knowledge is not enough so that I can wrap my head around this function. – SpaceOgre Jun 19 '13 at 07:29
  • Oh, so I think what you want is something like `icomplete-mode` but for "in-buffer" completion. I.e. the completion itself does not take place in a minibuffer but the list of completion candidates is displayed in the echo-area (and auto-updated as you edit the text to complete) rather than in \*Completions\*. Making `icomplete-mode` work with `completion-at-point-function` is still on my todo list, tho. – Stefan Jun 19 '13 at 18:57
  • Yes that is it! When I'm coding and want to try and complete a function, I don't want the alternatives in a new buffer but some place so that I can either choose among the alternatives right away or type some more to narrow it down. – SpaceOgre Jun 20 '13 at 07:44
  • If the major mode provides a `completion-at-point-function`, then `company-mode` can show you the candidates in a "popup list" (dynamically updated as you type) rather than in a separate buffer. – Stefan Jun 20 '13 at 13:49

1 Answers1

0

The company-mode suggested by Stefan did what I wanted so no rewrite needed.

Thank you for you help and time Stefan!

SpaceOgre
  • 107
  • 1
  • 12
  • Incidentally: `M-x ibuffer`. You wrote "ibuffer" twice in the question, but surely you meant something different? I've never encountered the term in any other context. – phils Jun 27 '13 at 22:51