unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Oleksandr Gavenko <gavenkoa@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Question: Is there any way to use the bash completion feature from Emacs shell mode.
Date: Wed, 12 Oct 2016 21:50:33 +0300	[thread overview]
Message-ID: <87lgxt4d1i.fsf@gavenkoa.example.com> (raw)
In-Reply-To: a6a03dd7-8fdb-ff57-bc96-540efb7c6a56@yk.rim.or.jp

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/




  reply	other threads:[~2016-10-12 18:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2016-10-19  1:12     ` Robert Thorpe

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lgxt4d1i.fsf@gavenkoa.example.com \
    --to=gavenkoa@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
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).