From: Fabian Ezequiel Gallina <galli.87@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "Štěpán Němec" <stepnem@gmail.com>,
"Emacs-Devel devel" <emacs-devel@gnu.org>
Subject: Re: Comint: handle raw tab
Date: Sun, 25 Sep 2011 22:30:06 -0300 [thread overview]
Message-ID: <CABq4mQtKHDSDd_9GVBDZcFjfxA9o5J27xb3LZY7ZghM8uCkUiw@mail.gmail.com> (raw)
In-Reply-To: <jwvpqj45n0e.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 4161 bytes --]
Hi all,
2011/9/13 Stefan Monnier <monnier@iro.umontreal.ca>
> >> 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.
>
>
The current shell completion machinery of my python.el works pretty much
like the gdb does, the thing is that on the python shell this approach is
likely to break on multi-line statements.
Good news is that this weekend I got back to try stuff again to get native
TAB support on the comint process, and while travelling back to my hometown
from the PyCon Argentina (the Bus ride was getting boring) I found something
that made the shell react pretty much like the real thing when sending a raw
tab: I started the comint process in the same way ansi-term would, using sh
+ stty.
Here is the quick snippet:
(defun python-shell-make-comint (cmd proc-name &optional pop)
"Create a python shell comint buffer.
CMD is the python command to be executed and PROC-NAME is the
process name the comint buffer will get. After the comint buffer
is created the `inferior-python-mode' is activated. If POP is
non-nil the buffer is shown."
(save-excursion
(let* ((proc-buffer-name (format "*%s*" proc-name))
(process-environment
(python-shell-calculate-process-environment))
(exec-path (python-shell-calculate-exec-path)))
(when (not (comint-check-proc proc-buffer-name))
(let* ((cmdlist (split-string-and-unquote cmd))
(sh-executable (executable-find "sh"))
(stty-executable (executable-find "stty"))
(buffer (if (and sh-executable stty-executable)
(apply 'make-comint proc-name
sh-executable nil "-c"
(format "%s -nl echo rows %d columns
%d sane 2>/dev/null;\
if [ $1 = .. ]; then shift; fi; exec \"$@\""
stty-executable
(window-height) (1-
(window-width)))
".."
(car cmdlist) (cdr cmdlist))
(apply 'make-comint proc-name (car cmdlist) nil
(cdr cmdlist))))
(current-buffer (current-buffer)))
(with-current-buffer buffer
(inferior-python-mode)
(python-util-clone-local-variables current-buffer))))
(when pop
(pop-to-buffer proc-buffer-name))
proc-buffer-name)))
After that, when I evaled:
(process-send-string (get-buffer-process (current-buffer)) "Tru ")
The shell got updated and said True.
If I evaled:
(process-send-string (get-buffer-process (current-buffer)) "T ")
TabError True TypeError
Got returned and the shell displayed correctly as it does on a full featured
terminal.
I need to work a little more on the extra bookkeeping involved into getting
comint know about the stuff that got inserted in the process but this got me
really close to have it working as intended.
What worries me is the Window support for this, is there something similar
like stty there? What I'm thinking is a good approach would be that when sh
and stty are not found via `executable-find', fallback to the old style
completion.
I'll continue working on this in the following days (hopefully I'll get
lucky). After that we can see if there is some kind of improvement we can do
in the comint library itself.
Regards,
Fabián E. Gallina
[-- Attachment #2: Type: text/html, Size: 4754 bytes --]
next prev parent reply other threads:[~2011-09-26 1:30 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
2011-09-26 1:30 ` Fabian Ezequiel Gallina [this message]
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=CABq4mQtKHDSDd_9GVBDZcFjfxA9o5J27xb3LZY7ZghM8uCkUiw@mail.gmail.com \
--to=galli.87@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--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.