From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Comint: handle raw tab Date: Tue, 13 Sep 2011 14:19:09 -0400 Message-ID: References: <87vcsw1rev.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1315937969 10939 80.91.229.12 (13 Sep 2011 18:19:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 13 Sep 2011 18:19:29 +0000 (UTC) Cc: =?utf-8?B?xaB0xJtww6FuIE7Em21lYw==?= , Emacs-Devel devel To: Fabian Ezequiel Gallina Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Sep 13 20:19:24 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R3XZs-0002DA-9n for ged-emacs-devel@m.gmane.org; Tue, 13 Sep 2011 20:19:24 +0200 Original-Received: from localhost ([::1]:52320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3XZr-0001fb-MU for ged-emacs-devel@m.gmane.org; Tue, 13 Sep 2011 14:19:23 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:33518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3XZl-0001fT-0X for emacs-devel@gnu.org; Tue, 13 Sep 2011 14:19:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3XZj-0006GN-4k for emacs-devel@gnu.org; Tue, 13 Sep 2011 14:19:16 -0400 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:55543) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3XZi-0006G0-Th for emacs-devel@gnu.org; Tue, 13 Sep 2011 14:19:15 -0400 Original-Received: from faina.iro.umontreal.ca (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id p8DIJ8Kv010667; Tue, 13 Sep 2011 14:19:08 -0400 Original-Received: by faina.iro.umontreal.ca (Postfix, from userid 20848) id 64C7F13007E; Tue, 13 Sep 2011 14:19:09 -0400 (EDT) In-Reply-To: (Fabian Ezequiel Gallina's message of "Tue, 13 Sep 2011 12:23:51 -0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3979=0 X-NAI-Spam-Version: 2.2.0.9286 : core <3979> : streams <681268> : uri <958598> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 132.204.246.22 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:143977 Archived-At: >> 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))))))