* Question: Is there any way to use the bash completion feature from Emacs shell mode.
@ 2016-10-08 19:14 ISHIKAWA,chiaki
2016-10-09 18:11 ` Dan Hitt
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: ISHIKAWA,chiaki @ 2016-10-08 19:14 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I have been using GNU emacs more than 30 years and thank you for
maintaining the great package.
I have a question.
Bash, the GNU shell interpreter has a feature called completion, and
over the years, people have created various completion databases for
many commands which are useful.
Case in point.
I just noticed the source control system called mercurial (known as "hg"
with its main command) has a very nice bash completion database.
The completion understands where the various so called MERCURIAL's patch
queues are stored and thus can offer the alternatives quite easily.
e.g.
After including
. /usr/share/bash-completion/completions/hg
(I am using Debian GNU/Linux and the above is where the completion code
for hg is stored.)
I can do the following inside a bash on an ordinary console.
$ hg qq [TAB]
expands to
$ hg qqueue
another couple of [TABS] expands to
--create TEST patches
--delete TEST-Q pristine
--list one-letter-C-locale submission
--purge partial4upload submission1
--rename partial4upload-1
$ hg qqueue
hitting pa[TAB] expands to
$hg qqueue pa
partial4upload partial4upload-1 patches
ishikawa@ip030:/NREF-COMM-CENTRAL/comm-central/mozilla$ hg qqueue pa
Very nice.
However, due to various reasons, I prefer to run bash inside Emacs's
shell buffer. It is easy to copy&paste the result of bash output and
reuse commands is one reason. (I am so used to keyboard and copy&paste
using mouse or other pointing device takes much longer.)
Unfortunately, bash's completion feature does not work in Emacs shell mode.
Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
Emacs's tab completion for filenames works great.
But I would like Bash's completion somehow works, too.
Is there a way?
Am I missing the obvious?
(Does using eshell mode helps?)
TIA
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-08 19:14 Question: Is there any way to use the bash completion feature from Emacs shell mode ISHIKAWA,chiaki
@ 2016-10-09 18:11 ` Dan Hitt
2016-10-10 6:06 ` Eli Zaretskii
2016-10-10 0:49 ` Bob Proulx
2016-10-10 13:40 ` Oleksandr Gavenko
2 siblings, 1 reply; 14+ messages in thread
From: Dan Hitt @ 2016-10-09 18:11 UTC (permalink / raw)
To: ISHIKAWA,chiaki; +Cc: help-gnu-emacs
On Sat, Oct 8, 2016 at 12:14 PM, ISHIKAWA,chiaki <ishikawa@yk.rim.or.jp> wrote:
> Hi,
> I have been using GNU emacs more than 30 years and thank you for maintaining
> the great package.
>
> I have a question.
>
> Bash, the GNU shell interpreter has a feature called completion, and
> over the years, people have created various completion databases for many
> commands which are useful.
>
.......
> However, due to various reasons, I prefer to run bash inside Emacs's shell
> buffer. It is easy to copy&paste the result of bash output and reuse
> commands is one reason. (I am so used to keyboard and copy&paste using mouse
> or other pointing device takes much longer.)
>
> Unfortunately, bash's completion feature does not work in Emacs shell mode.
> Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
> Emacs's tab completion for filenames works great.
> But I would like Bash's completion somehow works, too.
This is also my experience (in almost every detail).
As the OP says, emacs has improved over the decades, and all the time
new features are showing up, such as ibuffer. And emacs can do a lot
of tricks, such as looking at jpg files.
So, perhaps there is some mode like octave mode, that could run a bash
shell with much deeper integration (perhaps by keeping a second
interface to the inferior bash, such as through a socket or
something?)? Or perhaps instead of bash it could be some derivative
of bash? Or some derivative of zsh?
I'm aware of eshell, which also seems to be improving, but i think
it's very difficult to have a bash-like shell that also does elisp ---
e.g., parentheses are special to both bash and elisp, but not in the
same way. So in eshell, for example, if i type '( ls )' (without
the quotes), it expects ls to refer to a function rather than a
command. That's very natural for what eshell does, of course, and
this is not a criticism of eshell!
But it's not the same as having a strong, deeply integrated, bash
mode, where emacs has access to the internals of the inferior process.
TIA for any info or pointers regarding this!
dan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-08 19:14 Question: Is there any way to use the bash completion feature from Emacs shell mode ISHIKAWA,chiaki
2016-10-09 18:11 ` Dan Hitt
@ 2016-10-10 0:49 ` Bob Proulx
2016-10-10 13:40 ` Oleksandr Gavenko
2 siblings, 0 replies; 14+ messages in thread
From: Bob Proulx @ 2016-10-10 0:49 UTC (permalink / raw)
To: ISHIKAWA,chiaki; +Cc: help-gnu-emacs
ISHIKAWA,chiaki wrote:
> However, due to various reasons, I prefer to run bash inside Emacs's shell
> buffer. It is easy to copy&paste the result of bash output and reuse
> commands is one reason. (I am so used to keyboard and copy&paste using mouse
> or other pointing device takes much longer.)
>
> Unfortunately, bash's completion feature does not work in Emacs shell mode.
> Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
> Emacs's tab completion for filenames works great.
> But I would like Bash's completion somehow works, too.
>
> Is there a way?
> Am I missing the obvious?
> (Does using eshell mode helps?)
You mention emacs shell mode. But if you want bash to handle the
completion then I think maybe you want emacs term mode with bash.
Using term mode is different from using shell mode. But you get
exactly the bash features you wish.
M-x term
Note that most C-x keys are remapped to C-c inside that buffer.
https://www.gnu.org/software/emacs/manual/html_node/emacs/Terminal-emulator.html#Terminal-emulator
Keys are mapped:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Term-Mode.html#Term-Mode
The buffer is allocated a separate tty. The result is that most keys
are passed through directly to bash and therefore all bash completion
works from bash without emacs in between.
Bob
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-09 18:11 ` Dan Hitt
@ 2016-10-10 6:06 ` Eli Zaretskii
2016-10-10 14:05 ` Dan Hitt
0 siblings, 1 reply; 14+ messages in thread
From: Eli Zaretskii @ 2016-10-10 6:06 UTC (permalink / raw)
To: help-gnu-emacs
> From: Dan Hitt <dan.hitt@gmail.com>
> Date: Sun, 9 Oct 2016 11:11:24 -0700
> Cc: help-gnu-emacs@gnu.org
>
> On Sat, Oct 8, 2016 at 12:14 PM, ISHIKAWA,chiaki <ishikawa@yk.rim.or.jp> wrote:
> > Hi,
> > I have been using GNU emacs more than 30 years and thank you for maintaining
> > the great package.
> >
> > I have a question.
> >
> > Bash, the GNU shell interpreter has a feature called completion, and
> > over the years, people have created various completion databases for many
> > commands which are useful.
> >
> .......
> > However, due to various reasons, I prefer to run bash inside Emacs's shell
> > buffer. It is easy to copy&paste the result of bash output and reuse
> > commands is one reason. (I am so used to keyboard and copy&paste using mouse
> > or other pointing device takes much longer.)
> >
> > Unfortunately, bash's completion feature does not work in Emacs shell mode.
> > Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
> > Emacs's tab completion for filenames works great.
> > But I would like Bash's completion somehow works, too.
>
> This is also my experience (in almost every detail).
>
> As the OP says, emacs has improved over the decades, and all the time
> new features are showing up, such as ibuffer. And emacs can do a lot
> of tricks, such as looking at jpg files.
>
> So, perhaps there is some mode like octave mode, that could run a bash
> shell with much deeper integration (perhaps by keeping a second
> interface to the inferior bash, such as through a socket or
> something?)? Or perhaps instead of bash it could be some derivative
> of bash? Or some derivative of zsh?
I guess I don't understand what you guys are saying, because
completion with TAB and M-? keys does work for me in shell-mode. I
see completion on commands, files, and environment variables.
What am I missing?
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-08 19:14 Question: Is there any way to use the bash completion feature from Emacs shell mode ISHIKAWA,chiaki
2016-10-09 18:11 ` Dan Hitt
2016-10-10 0:49 ` Bob Proulx
@ 2016-10-10 13:40 ` Oleksandr Gavenko
2016-10-10 23:24 ` Dmitry Gutov
2016-10-12 0:25 ` ISHIKAWA,chiaki
2 siblings, 2 replies; 14+ messages in thread
From: Oleksandr Gavenko @ 2016-10-10 13:40 UTC (permalink / raw)
To: help-gnu-emacs
On 2016-10-08, ISHIKAWA,chiaki wrote:
> Unfortunately, bash's completion feature does not work in Emacs shell mode.
> Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
> Emacs's tab completion for filenames works great.
> But I would like Bash's completion somehow works, too.
Please look to my answer:
http://stackoverflow.com/a/28618762/173149
In short you should learn ``M-x term`` mode and a few key binding:
* ``C-C C-j``
* ``C-c C-k``
* ``C-c ...``
There is attempts to define ``comint-dynamic-complete-functions``:
--8<---------------cut here---------------start------------->8---
(defun comint-completion-at-point ()
(run-hook-with-args-until-success 'comint-dynamic-complete-functions))
--8<---------------cut here---------------end--------------->8---
for readline-enabled programs:
https://github.com/szermatt/emacs-bash-completion
--
http://defun.work/
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-10 6:06 ` Eli Zaretskii
@ 2016-10-10 14:05 ` Dan Hitt
2016-10-10 14:13 ` Dan Hitt
2016-10-11 0:59 ` Bob Proulx
0 siblings, 2 replies; 14+ messages in thread
From: Dan Hitt @ 2016-10-10 14:05 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
Tab completion certainly works, but it's the emacs completion, not the
bash completion.
Unfortunately, i don't have a good example of the difference right
now, but i'll bet Chiaki does.
(Bash can be much more intelligent about how to complete than emacs,
of course, because it has a much sharper picture of what the user is
doing and how the user is configured, while all emacs can do is
observe from a distance.)
Now, Bob's suggestion to use term-mode may just work, not sure.
I never used term mode since trying it out a few decades ago, because
i would get stuck in a buffer and not be able to get out --- unless it
was a graphical emacs and i could use the mouse to choose another
buffer --- but that would defeat the whole power of parking the mouse
and controlling everything by the keyboard.
However, Bob said that you substitute Control X with Control C, and
man that works.
So you can switch buffers using, e.g., Control-C o.
I'd still be interested in a more deeply integrated bash, but if term
doesn't have other problems, it's a very good proxy.
dan
On Sun, Oct 9, 2016 at 11:06 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Dan Hitt <dan.hitt@gmail.com>
>> Date: Sun, 9 Oct 2016 11:11:24 -0700
>> Cc: help-gnu-emacs@gnu.org
>>
>> On Sat, Oct 8, 2016 at 12:14 PM, ISHIKAWA,chiaki <ishikawa@yk.rim.or.jp> wrote:
>> > Hi,
>> > I have been using GNU emacs more than 30 years and thank you for maintaining
>> > the great package.
>> >
>> > I have a question.
>> >
>> > Bash, the GNU shell interpreter has a feature called completion, and
>> > over the years, people have created various completion databases for many
>> > commands which are useful.
>> >
>> .......
>> > However, due to various reasons, I prefer to run bash inside Emacs's shell
>> > buffer. It is easy to copy&paste the result of bash output and reuse
>> > commands is one reason. (I am so used to keyboard and copy&paste using mouse
>> > or other pointing device takes much longer.)
>> >
>> > Unfortunately, bash's completion feature does not work in Emacs shell mode.
>> > Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
>> > Emacs's tab completion for filenames works great.
>> > But I would like Bash's completion somehow works, too.
>>
>> This is also my experience (in almost every detail).
>>
>> As the OP says, emacs has improved over the decades, and all the time
>> new features are showing up, such as ibuffer. And emacs can do a lot
>> of tricks, such as looking at jpg files.
>>
>> So, perhaps there is some mode like octave mode, that could run a bash
>> shell with much deeper integration (perhaps by keeping a second
>> interface to the inferior bash, such as through a socket or
>> something?)? Or perhaps instead of bash it could be some derivative
>> of bash? Or some derivative of zsh?
>
> I guess I don't understand what you guys are saying, because
> completion with TAB and M-? keys does work for me in shell-mode. I
> see completion on commands, files, and environment variables.
>
> What am I missing?
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-10 14:05 ` Dan Hitt
@ 2016-10-10 14:13 ` Dan Hitt
2016-10-11 1:02 ` Bob Proulx
2016-10-11 0:59 ` Bob Proulx
1 sibling, 1 reply; 14+ messages in thread
From: Dan Hitt @ 2016-10-10 14:13 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs
Eli, sorry for double-posting so quickly.
But one example where emacs doesn't work as well as bash is emacs can
get confused over what directory you are in.
For example, if you have a bash alias that switches directory, emacs
cannot monitor it.
Then it will not know how to complete.
So that makes you hesitant to write little bash scripts that change
around your directory, because you know emacs will never track them.
I think term potentially can overcome that limitation, so we'll try it
out and see, although i can imagine that it may be confusing to switch
from Control-X to Control-C.
dan
On Mon, Oct 10, 2016 at 7:05 AM, Dan Hitt <dan.hitt@gmail.com> wrote:
> Tab completion certainly works, but it's the emacs completion, not the
> bash completion.
>
> Unfortunately, i don't have a good example of the difference right
> now, but i'll bet Chiaki does.
>
> (Bash can be much more intelligent about how to complete than emacs,
> of course, because it has a much sharper picture of what the user is
> doing and how the user is configured, while all emacs can do is
> observe from a distance.)
>
> Now, Bob's suggestion to use term-mode may just work, not sure.
>
> I never used term mode since trying it out a few decades ago, because
> i would get stuck in a buffer and not be able to get out --- unless it
> was a graphical emacs and i could use the mouse to choose another
> buffer --- but that would defeat the whole power of parking the mouse
> and controlling everything by the keyboard.
>
> However, Bob said that you substitute Control X with Control C, and
> man that works.
>
> So you can switch buffers using, e.g., Control-C o.
>
> I'd still be interested in a more deeply integrated bash, but if term
> doesn't have other problems, it's a very good proxy.
>
> dan
>
> On Sun, Oct 9, 2016 at 11:06 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>>> From: Dan Hitt <dan.hitt@gmail.com>
>>> Date: Sun, 9 Oct 2016 11:11:24 -0700
>>> Cc: help-gnu-emacs@gnu.org
>>>
>>> On Sat, Oct 8, 2016 at 12:14 PM, ISHIKAWA,chiaki <ishikawa@yk.rim.or.jp> wrote:
>>> > Hi,
>>> > I have been using GNU emacs more than 30 years and thank you for maintaining
>>> > the great package.
>>> >
>>> > I have a question.
>>> >
>>> > Bash, the GNU shell interpreter has a feature called completion, and
>>> > over the years, people have created various completion databases for many
>>> > commands which are useful.
>>> >
>>> .......
>>> > However, due to various reasons, I prefer to run bash inside Emacs's shell
>>> > buffer. It is easy to copy&paste the result of bash output and reuse
>>> > commands is one reason. (I am so used to keyboard and copy&paste using mouse
>>> > or other pointing device takes much longer.)
>>> >
>>> > Unfortunately, bash's completion feature does not work in Emacs shell mode.
>>> > Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
>>> > Emacs's tab completion for filenames works great.
>>> > But I would like Bash's completion somehow works, too.
>>>
>>> This is also my experience (in almost every detail).
>>>
>>> As the OP says, emacs has improved over the decades, and all the time
>>> new features are showing up, such as ibuffer. And emacs can do a lot
>>> of tricks, such as looking at jpg files.
>>>
>>> So, perhaps there is some mode like octave mode, that could run a bash
>>> shell with much deeper integration (perhaps by keeping a second
>>> interface to the inferior bash, such as through a socket or
>>> something?)? Or perhaps instead of bash it could be some derivative
>>> of bash? Or some derivative of zsh?
>>
>> I guess I don't understand what you guys are saying, because
>> completion with TAB and M-? keys does work for me in shell-mode. I
>> see completion on commands, files, and environment variables.
>>
>> What am I missing?
>>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-10 13:40 ` Oleksandr Gavenko
@ 2016-10-10 23:24 ` Dmitry Gutov
2016-10-12 0:25 ` ISHIKAWA,chiaki
1 sibling, 0 replies; 14+ messages in thread
From: Dmitry Gutov @ 2016-10-10 23:24 UTC (permalink / raw)
To: Oleksandr Gavenko, help-gnu-emacs
On 10.10.2016 16:40, Oleksandr Gavenko wrote:
> for readline-enabled programs:
>
> https://github.com/szermatt/emacs-bash-completion
There's also https://github.com/monsanto/readline-complete.el, for
company-mode and auto-complete.
Not sure how it compares.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-10 14:05 ` Dan Hitt
2016-10-10 14:13 ` Dan Hitt
@ 2016-10-11 0:59 ` Bob Proulx
2016-10-11 12:12 ` Filipp Gunbin
1 sibling, 1 reply; 14+ messages in thread
From: Bob Proulx @ 2016-10-11 0:59 UTC (permalink / raw)
To: help-gnu-emacs
Dan Hitt wrote:
> Tab completion certainly works, but it's the emacs completion, not the
> bash completion.
Right. There are really (at least) three types of completion.
1) bash completion using bash only
http://tiswww.case.edu/php/chet/bash/bashtop.html
2) bash-completion using the bash-completion 3rd party addon to bash
http://bash-completion.alioth.debian.org/
3) emacs shell-mode completion
https://www.gnu.org/software/emacs/manual/html_node/emacs/Shell.html
All three of those do completion. The second extends onto the first.
They all have slightly different behavior with pluses and minues to
each of them. Personally I only use 1 and 3 and don't miss not having
2 but I can understand people wanting it inside emacs.
> Unfortunately, i don't have a good example of the difference right
> now, but i'll bet Chiaki does.
bash (1) does this:
complete (TAB)
Attempt to perform completion on the text before point. Bash
attempts completion treating the text as a variable (if the text
begins with $), username (if the text begins with ~), hostname
(if the text begins with @), or command (including aliases and
functions) in turn. If none of these produces a match, filename
completion is attempted.
touch foo bar
ls f<TAB> will complete foo
bash-completion (2) has many additional completions including
completing options for commands that support --help.
ls --so<TAB> will complete to --sort
> I never used term mode since trying it out a few decades ago, because
> i would get stuck in a buffer and not be able to get out --- unless it
> was a graphical emacs and i could use the mouse to choose another
> buffer --- but that would defeat the whole power of parking the mouse
> and controlling everything by the keyboard.
That was specifically why I mentioned that C-x is mapped to C-c! :-)
Because if that isn't known then you are trapped. But knowing that
allows you to switch buffers away or other commands.
> However, Bob said that you substitute Control X with Control C, and
> man that works.
>
> So you can switch buffers using, e.g., Control-C o.
Or kill the buffer with C-c k RET which I usually do when done in
order to clean up and free up memory.
Also as Oleksandr Gavenko wrote the following keys are very useful:
C-c C-j switch to term-line-mode (effectively similar to shell mode)
C-c C-k switch to term-char-mode
When in term mode I switch back and forth between those modes *a lot*
as needed to deal with the immediate task. Some things are easier one
way. Some the other way. Relevant to this discussion with C-c C-k
you get bash completion. With C-c C-j you get emacs completion.
Bob
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-10 14:13 ` Dan Hitt
@ 2016-10-11 1:02 ` Bob Proulx
0 siblings, 0 replies; 14+ messages in thread
From: Bob Proulx @ 2016-10-11 1:02 UTC (permalink / raw)
To: help-gnu-emacs
Dan Hitt wrote:
> But one example where emacs doesn't work as well as bash is emacs can
> get confused over what directory you are in.
>
> For example, if you have a bash alias that switches directory, emacs
> cannot monitor it.
Perhaps this will help:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Tracking.html#Directory-Tracking
37.6 Directory Tracking
=======================
Shell mode keeps track of ‘cd’, ‘pushd’ and ‘popd’ commands given to the
subshell, in order to keep the Shell buffer’s default directory (*note
File Names::) the same as the shell’s working directory. It recognizes
these commands by examining lines of input that you send.
If you use aliases for these commands, you can tell Emacs to
recognize them also, by setting the variables ‘shell-pushd-regexp’,
‘shell-popd-regexp’, and ‘shell-cd-regexp’ to the appropriate regular
expressions (*note Regexps::). For example, if ‘shell-pushd-regexp’
matches the beginning of a shell command line, that line is regarded as
a ‘pushd’ command. These commands are recognized only at the beginning
of a shell command line.
If Emacs gets confused about changes in the working directory of the
subshell, type ‘M-x dirs’. This command asks the shell for its working
directory and updates the default directory accordingly. It works for
shells that support the most common command syntax, but may not work for
unusual shells.
You can also use Dirtrack mode, a buffer-local minor mode that
implements an alternative method of tracking the shell’s working
directory. To use this method, your shell prompt must contain the
working directory at all times, and you must supply a regular expression
for recognizing which part of the prompt contains the working directory;
see the documentation of the variable ‘dirtrack-list’ for details. To
use Dirtrack mode, type ‘M-x dirtrack-mode’ in the Shell buffer, or add
‘dirtrack-mode’ to ‘shell-mode-hook’ (*note Hooks::).
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-11 0:59 ` Bob Proulx
@ 2016-10-11 12:12 ` Filipp Gunbin
0 siblings, 0 replies; 14+ messages in thread
From: Filipp Gunbin @ 2016-10-11 12:12 UTC (permalink / raw)
To: help-gnu-emacs
On 10/10/2016 18:59 -0600, Bob Proulx wrote:
> Dan Hitt wrote:
>> Tab completion certainly works, but it's the emacs completion, not the
>> bash completion.
>
> Right. There are really (at least) three types of completion.
>
> 1) bash completion using bash only
> http://tiswww.case.edu/php/chet/bash/bashtop.html
> 2) bash-completion using the bash-completion 3rd party addon to bash
> http://bash-completion.alioth.debian.org/
> 3) emacs shell-mode completion
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Shell.html
You might want to look at emacs-bash-completion
(https://github.com/szermatt/emacs-bash-completion) which integrates
bash-completion (https://github.com/scop/bash-completion), which
provides many completion functions.
Filipp
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-10 13:40 ` Oleksandr Gavenko
2016-10-10 23:24 ` Dmitry Gutov
@ 2016-10-12 0:25 ` ISHIKAWA,chiaki
2016-10-12 18:50 ` Oleksandr Gavenko
2016-10-19 1:12 ` Robert Thorpe
1 sibling, 2 replies; 14+ messages in thread
From: ISHIKAWA,chiaki @ 2016-10-12 0:25 UTC (permalink / raw)
To: Oleksandr Gavenko, help-gnu-emacs
Hi,
Sorry for top posting.
I have tried term mode and it certainly can use the full featured bash
completion (tailored for each command, e.g. hg command, and its
subcomands even.)
However, as some mentioned, basically almost all the keys are eaten now
by term-mode. This negates the benefit of copy&paste using emacs of the
output of previous commands executed by bash, etc.
(I can use mouse to do the operation, but I prefer key binding.)
However, I did not realize C-C ad C-X are swapped there. Maybe I should
retry the experience.
emacs-bash-completion may be a way to go. I will check it out.
OTOH, I think my needs can be satisfied using
term mode, but somehow keeping C-N, C-P, C-@ and C-W for emacs.
After thinking more, I think I need C-A and C-E and C-K for emacs mode
editing, too.
But this definitely interferes with bash's idea of readline editing.
We can't have cake and eat it, too.
I will try using these different methods a few days more and report back
my experience.
I once tried using term mode, but gave up.
But the merit of bash completion is now too good to ignore these days.
It magically works for many commands!
Thank you again.
Best Regards,
Chiaki
PS: The shell mode completion can
offer the candidates for command names and arguments that are filenames.
This is useful definitely.
But bash completion database "KNOWS" the name of the options each
command takes, AND sometimes it knows where the argument which is mapped
to a file path name in one way or the other: for example,
MERCURIUM source control system command "hg" has "qqueue" subcommand to
switch between different patch queues. Patch queues are stored
under .hg/patches-QQNAMES where QQNAMES is the name of the queue.
So if we issue
hg qqueue original
it refers to .hg/patches-original queue.
hg qqueue myfix
refers to .hg/patches-myfix
And this .hg subdirector is searched if it is not under the current
directory. It will be searched in the parent directory, and so on.
Bash completion is very clever (of course, it depends on the completion
database that defines the functions to look for candidates for command
options and arguments.)
The completion of Emacs's shell mode cannot handle such advanced mapping
to a file name. But bash's completion can (!).
This is why I wanted to use bash's completion.
On 2016/10/10 22:40, Oleksandr Gavenko wrote:
> On 2016-10-08, ISHIKAWA,chiaki wrote:
>
>> Unfortunately, bash's completion feature does not work in Emacs shell mode.
>> Obviously, [TAB] is stolen by Emacs for its own handling of TAB character.
>> Emacs's tab completion for filenames works great.
>> But I would like Bash's completion somehow works, too.
>
> Please look to my answer:
>
> http://stackoverflow.com/a/28618762/173149
>
> In short you should learn ``M-x term`` mode and a few key binding:
>
> * ``C-C C-j``
> * ``C-c C-k``
> * ``C-c ...``
>
> There is attempts to define ``comint-dynamic-complete-functions``:
>
> --8<---------------cut here---------------start------------->8---
> (defun comint-completion-at-point ()
> (run-hook-with-args-until-success 'comint-dynamic-complete-functions))
> --8<---------------cut here---------------end--------------->8---
>
> for readline-enabled programs:
>
> https://github.com/szermatt/emacs-bash-completion
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-12 0:25 ` ISHIKAWA,chiaki
@ 2016-10-12 18:50 ` Oleksandr Gavenko
2016-10-19 1:12 ` Robert Thorpe
1 sibling, 0 replies; 14+ messages in thread
From: Oleksandr Gavenko @ 2016-10-12 18:50 UTC (permalink / raw)
To: help-gnu-emacs
On 2016-10-12, ISHIKAWA,chiaki wrote:
> I have tried term mode and it certainly can use the full featured bash
> completion (tailored for each command, e.g. hg command, and its subcomands
> even.)
>
> However, as some mentioned, basically almost all the keys are eaten now by
> term-mode. This negates the benefit of copy&paste using emacs of the output of
> previous commands executed by bash, etc.
> (I can use mouse to do the operation, but I prefer key binding.)
S-Insert still works in char mode (‘term-char-mode’) - in this way I insert
data from another buffers. Unfortunately cycling with M-y in not worked in
char mode so you may paste only last copied string.
If I need to copy text I use mouse selection or switch to line mode (‘C-c
C-j’).
> However, I did not realize C-C ad C-X are swapped there. Maybe I should retry
> the experience.
>
Definitely you should try.
It is inconvenient to use `C-c` prefix. You should remember:
* C-c b (ido-switch-buffer)
* C-c o (other-window)
to be able leave term buffer.
Under Linux I define Left-Win key as Super in ~/.xmodmaprc:
--8<---------------cut here---------------start------------->8---
! Win key.
clear mod3
clear mod4
keycode 133 = Super_L
! keycode 134 = Multi_key
! keycode 134 = Super_R
keycode 134 = Hyper_R
add mod3 = Super_L
add mod4 = Hyper_R
--8<---------------cut here---------------end--------------->8---
``term-raw-map`` have no any associations with Super key. In this way I define
common operation which works even in term-mode:
--8<---------------cut here---------------start------------->8---
(global-set-key [s-right] 'next-buffer)
(global-set-key [s-left] 'previous-buffer)
(global-set-key [s-delete] 'my--kill-this-buffer-maybe-switch-to-next)
(global-set-key [s-up] #'my--backward-other-window)
(global-set-key [s-down] #'other-window)
(global-set-key [s-insert] 'ibuffer)
(unless
(ignore-errors
(require 'ido)
(ido-mode 1) ; (ido-everywhere 'both)
(global-set-key [?\s-d] #'ido-dired)
(global-set-key [?\s-f] #'ido-find-file)
t)
(global-set-key [?\s-d] #'dired)
(global-set-key [?\s-f] #'find-file))
--8<---------------cut here---------------end--------------->8---
> emacs-bash-completion may be a way to go. I will check it out.
>
Please write about your experience with emacs-bash-completion. I also searched
for bash completion in ``M-x shell`` but there weren't ready solutions in
2010, so I switched to M-x term.
> OTOH, I think my needs can be satisfied using
> term mode, but somehow keeping C-N, C-P, C-@ and C-W for emacs.
> After thinking more, I think I need C-A and C-E and C-K for emacs mode
> editing, too.
> But this definitely interferes with bash's idea of readline editing.
> We can't have cake and eat it, too.
I have:
--8<---------------cut here---------------start------------->8---
(defun my-term-send-delete-word-forward () (interactive) (term-send-raw-string "\ed"))
(defun my-term-send-delete-word-backward () (interactive) (term-send-raw-string "\e\C-h"))
(define-key term-raw-map [C-delete] 'my-term-send-delete-word-forward)
(define-key term-raw-map [C-backspace] 'my-term-send-delete-word-backward)
(defun my-term-send-forward-word () (interactive) (term-send-raw-string "\ef"))
(defun my-term-send-backward-word () (interactive) (term-send-raw-string "\eb"))
(define-key term-raw-map [C-left] 'my-term-send-backward-word)
(define-key term-raw-map [C-right] 'my-term-send-forward-word)
(defun my-term-send-m-right () (interactive) (term-send-raw-string "\e[1;3C"))
(defun my-term-send-m-left () (interactive) (term-send-raw-string "\e[1;3D"))
(define-key term-raw-map [M-right] 'my-term-send-m-right)
(define-key term-raw-map [M-left] 'my-term-send-m-left)
--8<---------------cut here---------------end--------------->8---
to make navigation in readline as in Emacs.
Bash has kill buffer. C-delete add following words to it. To paste you should
C-y / M-y. Och, you should boost ~/.inputrc to make it works:
--8<---------------cut here---------------start------------->8---
# Define my favorite Emacs key bindings.
"\C-@": set-mark
"\C-w": kill-region
"\M-w": copy-region-as-kill
# Ctrl+Left/Right to move by whole words.
"\e[1;5C": forward-word
"\e[1;5D": backward-word
# Same with Shift pressed.
"\e[1;6C": forward-word
"\e[1;6D": backward-word
# Ctrl+Backspace/Delete to delete whole words.
"\e[3;5~": kill-word
"\C-_": backward-kill-word
# UP/DOWN filter history by typed string as prefix.
"\e[A": history-search-backward
"\C-p": history-search-backward
"\eOA": history-search-backward
"\e[B": history-search-forward
"\C-n": history-search-forward
"\eOB": history-search-forward
# Bind 'Shift+TAB' to complete as in Python TAB was need for another purpose.
"\e[Z": complete
# Cycling possible completion forward and backward in place.
"\e[1;3C": menu-complete # M-Right
"\e[1;3D": menu-complete-backward # M-Left
"\e[1;5I": menu-complete # C-TAB
--8<---------------cut here---------------end--------------->8---
================================================================
You can find relevant settings in my configs:
* http://hg.defun.work/skel/file/tip/.inputrc
* http://hg.defun.work/dot-emacs/file/tip/.emacs-my
--
http://defun.work/
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
2016-10-12 0:25 ` ISHIKAWA,chiaki
2016-10-12 18:50 ` Oleksandr Gavenko
@ 2016-10-19 1:12 ` Robert Thorpe
1 sibling, 0 replies; 14+ messages in thread
From: Robert Thorpe @ 2016-10-19 1:12 UTC (permalink / raw)
To: ISHIKAWA,chiaki; +Cc: help-gnu-emacs, gavenkoa
Notice that there are two flavours of term mode. In normal term-mode
the special prefix keys all begin C-c, in ansi-term mode the prefix keys
begin C-x. So, it's C-x C-j and C-x C-k to switch between char and line
mode. Apart from that the two modes are the same. Which is best
for you depends on which one tramples the fewest on the keys that you
wish to use.
BR,
Robert Thorpe
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2016-10-19 1:12 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-08 19:14 Question: Is there any way to use the bash completion feature from Emacs shell mode ISHIKAWA,chiaki
2016-10-09 18:11 ` Dan Hitt
2016-10-10 6:06 ` Eli Zaretskii
2016-10-10 14:05 ` Dan Hitt
2016-10-10 14:13 ` Dan Hitt
2016-10-11 1:02 ` Bob Proulx
2016-10-11 0:59 ` Bob Proulx
2016-10-11 12:12 ` Filipp Gunbin
2016-10-10 0:49 ` Bob Proulx
2016-10-10 13:40 ` Oleksandr Gavenko
2016-10-10 23:24 ` Dmitry Gutov
2016-10-12 0:25 ` ISHIKAWA,chiaki
2016-10-12 18:50 ` Oleksandr Gavenko
2016-10-19 1:12 ` Robert Thorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).