There is a function called term-paste
, but it is bound to S-insert
by default. Who wants that? Use
(require 'term)
(define-key term-raw-map (kbd "C-c y") 'term-paste)
(define-key term-raw-map (kbd "C-c C-y") 'term-paste)
to rebind it to C-c C-y
To conveniently open files from terminal even on remote machines, I use tmacswrap
You can define a function to quickly open a tmacs-term with
(defun tmacs--find-free-number ()
"use this function to create a reasonable buffer name"
(cl-do ((num 0 (+ 1 num)))
((not (get-buffer (format "*tmacs<%s>*" num)))
num)))
(defun tmacs ()
(interactive)
(ansi-term "/bin/bash" (format "tmacs<%s>" (tmacs--find-free-number))))
and then open it with M-x tmacs
.
Add to your ~~/.bashrc~:
if [ -n "$INSIDE_EMACS" ]; then
export VISUAL=emacsclient # use tmacs here, if you want
export EDITOR=$VISUAL
fi
Don’t use emacsclient -n
because that would confuse programs like
git
when you edit your commit messages with this.
It may be a problem if one mistypes on a password prompt in tramp, because emacs might lock up your account if there is a limit of unsuccessful logins.
- tell ssh to not ask for password
- override tramp function to ask for password and error out.
;; ~/.emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; tramp
(setq tramp-ssh-controlmaster-options "-o PasswordAuthentication=no")
;; don't ever ask for passwords!
;; TODO: implement as advice
(defun tramp-read-passwd (proc &optional prompt)
(message "Tramp tries to ask for password, inhibiting")
(error "Tramp tried to ask for password")) ;; just fail
To allow emacs to TRAMP somewhere, nonetheless, use a controlmaster connection
# ~/.ssh/config # use this, if you have a domain. Else something might not work when using shortnames # CanonicalizeHostname yes # CanonicalDomains my.domain.com host * ControlMaster auto ControlPath ~/.ssh/control/%C ControlPersist 15m
In older emacs versions ansi-term was allegedly very slow clearing the screen. In version 26.1 the problem seems to be fixed, but still triggered in a different way: Scrolling fast, if the terminal buffer is already full. I solved this problem by using this[fn:1]
;; Terminal buffer configuration.
(add-hook 'term-mode-hook 'my-term-mode-hook)
(defun my-term-mode-hook ()
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=20611
(setq bidi-paragraph-direction 'left-to-right))
Resizing the terminal in which emacs runs doesn’t inform inferior terminals that they should be resized, too. Use this[fn:2]:
(add-hook 'window-configuration-change-hook (lambda (frame) (window--adjust-process-windows)))
[fn:1] https://www.emacswiki.org/emacs/AnsiTermHints#h5o-8 [fn:2] https://gnu.emacs.bug.narkive.com/nNqAqMND/bug-43126-26-1-ansi-term-not-resized-after-x-window-resize