help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question: Is there any way to use the bash completion feature from E


From: Oleksandr Gavenko
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
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]