From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Fabian Ezequiel Gallina <galli.87@gmail.com>
Cc: "Štěpán Němec" <stepnem@gmail.com>,
"Emacs-Devel devel" <emacs-devel@gnu.org>
Subject: Re: Comint: handle raw tab
Date: Tue, 13 Sep 2011 14:19:09 -0400 [thread overview]
Message-ID: <jwvpqj45n0e.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CABq4mQv3vR+aPW=m_NRaydJxMFe6VdayERdEjP-rsCMvd93Tpw@mail.gmail.com> (Fabian Ezequiel Gallina's message of "Tue, 13 Sep 2011 12:23:51 -0300")
>> IMO native tab completion for subprocess REPLs is a common enough need
>> that the basic machinery should be handled by Emacs itself, i.e.
>> probably the comint library. I'm somewhat surprised there is no such
>> code yet (or is there, outside Emacs perhaps?).
> I agree with the exposed above, many modern REPLs comint can interact with
> have TAB completion out of the box. We should use that when it's available
> instead of duplicating efforts.
I agree that would be good.
You can check the gdb completion code in gud.el for an example.
Stefan
(defun gud-gdb-completions (context command)
"Completion table for GDB commands.
COMMAND is the prefix for which we seek completion.
CONTEXT is the text before COMMAND on the line."
(let* ((start (- (point) (field-beginning)))
(complete-list
(gud-gdb-run-command-fetch-lines (concat "complete " context command)
(current-buffer)
;; From string-match above.
(length context))))
;; `gud-gdb-run-command-fetch-lines' has some nasty side-effects on the
;; buffer (via `gud-delete-prompt-marker'): it removes the prompt and then
;; re-adds it later, thus messing up markers and overlays along the way.
;; This is a problem for completion-in-region which uses an overlay to
;; create a field.
;; So we restore completion-in-region's field if needed.
;; FIXME: change gud-gdb-run-command-fetch-lines so it doesn't modify the
;; buffer at all.
(when (/= start (- (point) (field-beginning)))
(dolist (ol (overlays-at (1- (point))))
(when (eq (overlay-get ol 'field) 'completion)
(move-overlay ol (- (point) start) (overlay-end ol)))))
;; Protect against old versions of GDB.
(and complete-list
(string-match "^Undefined command: \"complete\"" (car complete-list))
(error "This version of GDB doesn't support the `complete' command"))
;; Sort the list like readline.
(setq complete-list (sort complete-list (function string-lessp)))
;; Remove duplicates.
(let ((first complete-list)
(second (cdr complete-list)))
(while second
(if (string-equal (car first) (car second))
(setcdr first (setq second (cdr second)))
(setq first second
second (cdr second)))))
;; Add a trailing single quote if there is a unique completion
;; and it contains an odd number of unquoted single quotes.
(and (= (length complete-list) 1)
(let ((str (car complete-list))
(pos 0)
(count 0))
(while (string-match "\\([^'\\]\\|\\\\'\\)*'" str pos)
(setq count (1+ count)
pos (match-end 0)))
(and (= (mod count 2) 1)
(setq complete-list (list (concat str "'"))))))
complete-list))
(defun gud-gdb-completion-at-point ()
"Return the data to complete the GDB command before point."
(let ((end (point))
(start
(save-excursion
(skip-chars-backward "^ " (comint-line-beginning-position))
(point))))
(list start end
(completion-table-dynamic
(apply-partially #'gud-gdb-completions
(buffer-substring (comint-line-beginning-position)
start))))))
next prev parent reply other threads:[~2011-09-13 18:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-12 3:34 Comint: handle raw tab Fabian Ezequiel Gallina
2011-09-13 12:43 ` Stefan Monnier
2011-09-13 13:51 ` Štěpán Němec
2011-09-13 15:23 ` Fabian Ezequiel Gallina
2011-09-13 18:19 ` Stefan Monnier [this message]
2011-09-26 1:30 ` Fabian Ezequiel Gallina
2011-09-13 15:20 ` Fabian Ezequiel Gallina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvpqj45n0e.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=galli.87@gmail.com \
--cc=stepnem@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.