Hot answers tagged

44

In Shift+Up isn't recognized by Emacs in a terminal I explain how terminals translate most function keys into escape sequences, because the interface between applications and terminals transmits characters (or rather bytes), not keys. Only a few modifier+character combinations have their own character: Ctrl plus a letter or one of @[\]^_ turns into ...


32

M-x shell is the standard interface to OS's shell. On linux, it calls bash (or whatever your default), on Windows, it calls cmd.exe. M-x shell is the most frequently used. M-x eshell is a shell written in emacs lisp entirely. It has a syntax similar to bash, but is integrated with elisp well. e.g. you can eval elisp code right there. Eshell is especially ...


23

First, the more general issue: terminal emulators are often limited in the control and escape sequences they can send. So: it may be the case that the terminal swallows your special characters before they reach Emacs. As a general diagnostic, you can hit C-h l (or M-x view-lossage) to see if your key combinations make it into Emacs. For more discussion of ...


21

You will be more comfortable in an X11 Emacs, which can receive keyboard input and display text without going through encoding and decoding for the terminal. The main reason to use a text mode editor is to run it inside screen or tmux on a remote machine, but thanks to Tramp, it's usually easier to edit the remote file in your local Emacs. That being said, ...


16

In term-mode, there are two input modes. In the default input mode -- char-mode -- all keypresses (except C-c) are sent to the terminal to do what it wishes with. If you change the input mode to line-mode, then regular Emacs commands work. You can switch to line-mode with C-c C-j. You can switch back to char-mode with C-c C-k.


12

I think the first part of your question can be done with dirtrack-mode. First, you set your shell prompt to include the present working directory. Next, you set dirtrack-list to a regex that tells dirtrack-mode how to extract it. Example: I set PS1 in Bash to be this: export PS1="[\h:\w] $ " and in Emacs I set dirtrack-list and turn on dirtrack-mode: (...


12

Like most terminals, Emacs' term has a scrollback limit -- which will naturally mess with the consistency of linum's counting, as lines will be deleted from the beginning of the buffer. The term-buffer-maximum-size variable controls this, and sure enough it has a default value of 2048. So linum was telling you the truth: the terminal buffer was never more ...


12

There are a few answers here. Quitting Emacs without C-x C-c First, you can quit emacs by running the command that C-x C-c is bound to: M-x save-buffers-kill-terminal. Alternatives to recursive Emacs Emacs is able to edit files on remote servers, so you don't even need to ssh into the remote server, and you won't need an Emacs inside a term inside your ...


9

From the Emacs manual, node DEL Does Not Delete: On a text terminal, if you find that <BACKSPACE> prompts for a Help command, like Control-h, instead of deleting a character, it means that key is actually sending the BS character. Emacs ought to be treating <BS> as <DEL>, but it isn’t. In all of those cases, the immediate ...


7

shell is the oldest of the two. It uses Emacs's comint-mode to run a subshell (e.g. bash). In this mode, you're using Emacs to edit a command line. The subprocess doesn't see any input until you press Enter. Emacs is acting like a dumb terminal. It does support color codes, but not things like moving the cursor around, so you can't run curses-based ...


7

maybe using ansi-term instead would be slightly less annoying, since it exposes a C-x prefix, allowing you to use, say, C-x o or C-x k without any special trick. If that's not sufficient, you can use the following approach: (defun expose-global-binding-in-term (binding) (define-key term-raw-map binding (lookup-key (current-global-map) binding))) (...


7

In term-mode, any regular C-x whatever keybinding becomes C-c whatever instead. Courtesy of Josh Matthews Now to define keybindings that will be active only in term mode, try this: (add-hook 'term-mode-hook (lambda () (define-key term-raw-map (kbd "M-J") 'other-window) (define-key term-raw-map (kbd "M-k") 'kill-buffer)))


7

Another try that disowns the process so your terminal will survive even after emacs is killed. (defun run-gnome-terminal-here () (interactive "@") (shell-command (concat "konsole --workdir" (file-name-directory (or load-file-name buffer-file-name)) " > /dev/null 2>&1 & disown") nil nil))


7

The info reader in Emacs can be accessed with C-h i. There you can jump directly into the some-node node with g (some-node) RET. Alternatively, you can go to the some-node node by eval'ing (info "some-node"). Note that the info reader on the terminal picks man pages when info nodes cannot be found. There is no "glibc" info node, but just a man page. To ...


7

The Emacs manual says you can set the option frame-resize-pixelwise to non-nil to allow frame sizes by pixel. Normally the frame dimensions (not counting the menu bar, tool bar, etc) are integer multiples of frame-char-height in height and frame-char-width in width. The manual notes that you need to set this variable to non-nil in your init file so that it ...


7

In my .emacs I first define a function like so (defun my-bash-on-windows-shell () (let ((explicit-shell-file-name "C:/Windows/System32/bash.exe")) (shell))) and I call at the bottom using: (my-bash-on-windows-shell) Note that Emacs shell mode does not handle the default colored prompt very well, however changing my PS1 to: PS1='\u@\h:\w\$ ' in my ...


7

Quoting startup.el: ;; Subprocesses of Emacs do not have direct access to the terminal, so ;; unless told otherwise they should only assume a dumb terminal. ;; We are careful to do it late (after term-setup-hook), although the ;; new multi-tty code does not use $TERM any more there anyway. (setenv "TERM" "dumb") If Emacs didn't set TERM=dumb then every ...


6

There's a very underappreciated feature most libraries that handle fonts provide for us, automatic fallback to different fonts if the font one has specified does not have all glyphs necessary to display the requested text correctly. urxvt however does intentionally not come with automatic font fallback, at least not if you're not using fonts with the xft: ...


6

The bi-directional text support introduced in Emacs 24 interacts badly with term.el when large numbers of spaces or tabs are inserted, and many applications clear the screen (often drawing a new background colour) by writing WIDTHxHEIGHT spaces (which, if the terminal’s dimensions are sufficiently large, may take several seconds). The workaround is to ...


6

Looking at term.el it seems char mode is enabled right after running term-mode (and hence term-mode-hook) as such enabling term-line-mode in term-mode-hook would not work. The only option I can think of is advicing the function term and ansi-term, like so (defun my-enable-term-line-mode (&rest ignored) (term-line-mode)) (advice-add 'ansi-term :after #...


6

TERM is an environment variable, you set it in your environment. This could be the environment of a particular shell that you've opened, by running export TERM=foo, or all of your shells by adding the same command to your .bashrc (or a similar file for your shell, if you don't use bash. but you probably do use bash). terminfo and termcap are databases ...


6

I believe that the @ symbols in your terminfo example are part of the Texinfo markup, rather than part of the terminfo code. Your terminfo entry should look like: # Use colon separators. xterm-24bit|xterm with 24-bit direct color mode, use=xterm-256color, setb24=\E[48:2:%p1%{65536}%/%d:%p1%{256}%/%{255}%&%d:%p1%{255}%&%dm, setf24=\E[38:2:%...


5

Gilles' answer stated: On OSX, you can configure iTerm2 by selecting an escape sequence for each key combination, one by one. I had a little trouble getting there, so here a detailed explanation in case you are like me, confused. If, when running Emacs in a terminal (e.g., Mac's default Terminal.app), C-x C-; does not run comment-line, and you would like ...


5

In general, a terminal application like emacs -nw has only very limited information about what colors are available. The shell will have an environment variable called TERM which contains the name of the terminal you're using. The application can then use a library such as terminfo to pick the right escape sequences to use each feature of the terminal. This ...


5

There is a way! The problem with using term is that term doesn't understand some of the escape sequences Julia sends, which causes term to put a bunch of extra prompts on the screen that make it unusable. This method should also work for more or less any REPL or terminal application you could want to run. There is a ridiculously useful terminal application ...


5

Termcap and terminfo are both methods for an application running in a terminal to obtain information about the terminal — what it can do and how (e.g. its size, how to move the cursor around, etc.). Both consist of a database that associates terminal capability descriptions to terminal names, as well as a library of code to query the database. The TERM ...


5

On a terminal, you can't change the shape of cursor. From the Emacs manual: On a text terminal, the cursor’s appearance is controlled by the terminal, largely out of the control of Emacs. Some terminals offer two different cursors: a “visible” static cursor, and a “very visible” blinking cursor. By default, Emacs uses the very visible cursor, and ...


5

If you're in term buffer in char mode, you have to escape C-c. So, if you're running a terminal Emacs instance inside the term buffer, running save-buffers-kill-terminal requires an extra C-c: C-x C-c C-c. If you're running an Emacs instance in a term buffer in line mode, I don't think there's a direct way to kill the nested Emacs. You have to switch back ...


5

It's an off by one error in term-handle-ansi-escape, I've posted a patch in Bug#31690. --- c/lisp/term.el +++ w/lisp/term.el @@ -3386,11 +3386,10 @@ term-handle-ansi-escape ;; \E[B - cursor down (terminfo: cud) ((eq char ?B) (let ((tcr (term-current-row))) - (unless (= tcr (1- term-scroll-end)) + (unless (>= tcr term-scroll-end) ...


5

You can add: For C-M-left: Send escape sequence: [1;7D For C-M-right: Send escape sequence: [1;7C For C-M-up: Send escape sequence: [1;7A For C-M-down: Send escape sequence: [1;7B And this will work with Emacs if you set the term in iTerm2 to be reported as xterm. To know how to figure all this out, well its complicated, and I just went down this rabbit ...


Only top voted, non community-wiki answers of a minimum length are eligible