Unicode characters in emacs term-mode - unicode

I use ansi-term for my normal terminal sessions. I tend to use unicode characters in my prompt to do things like set the trailing character based on the type of source control I'm using.
I use the character "±" as my prompt for git repositories.
In Emacs' ansi-term, my prompt isn't rendered as unicode, and shows as "\302\261". Displaying the current coding system shows that it defaults to utf-8-unix for input to the process, but I get raw binary as the decoding output. I can hit C-c RET p to change the encoding and decoding coding systems. I'm drawing a blank as to how to set this automatically when I start a terminal? I've tried adding to term-mode-hook to set the buffer's coding system to no avail. I think I've found what I'm looking for in term.el, but I don't care to tweak the distribution elisp, and it appears the raw binary was added to fix a bug somewhere else.
EDIT: This was unclear originally. I'm having issues setting the default process coding system for ansi-term running under Cocoa-ized Emacs 23.3 on MacOS. Emacs itself isn't running in a terminal, my terminal is running in Emacs.

The following worked for me:
(add-hook 'term-exec-hook
(function
(lambda ()
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))))
ansi-term seems to ignore the default-process-coding-system variable, so I had to set it buffer-locally after it executes my shell.

After getting a better understanding of term.el, the following works:
(defadvice ansi-term (after advise-ansi-term-coding-system)
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))
(ad-activate 'ansi-term)
Trying this with term-mode-hook is broken because in term.el, term-mode-hook is called before switching to the terminal buffer, so set-buffer-process-coding-system breaks due to the lack of a process associated with the buffer.

Try
(set-terminal-coding-system 'utf-8-unix)
That's C-x RET t not C-x RET p.
So C-x RET p helps?
Unless C-h v default-process-coding-system is (utf-8-unix . utf-8-unix) try
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))

Related

How to use terminal keyboard shortcuts inside emacs multi-term

I know there's some questions that are kind of related to this already, and I know you can do stuff like
(defun term-send-esc ()
"Send ESC in term mode."
(interactive)
(term-send-raw-string "\e"))
but it would be very convenient if there was kind of a univerisal override keybinding. For example, I just ssh:ed into a remote server and tried to nano a file and couldn't figure out how to exit because Ctl-x listens for emacs bindings. Is there such a thing?
There are two term sub modes, term-char-mode (C-x C-k) and term-line-mode (C-x C-j). Char mode is closer to a terminal, line mode is closer to a regular buffer. IIRC, multiterm starts in char mode, but it rebinds some keys to make it more Emacs-like. Look at the keys that multiterm rebinds; it has some alists that are used to modify the existing term-mode keymaps instead of using its own keymap. Or use sane-term, which is not much more than some commands to create new term buffers (no mucking with key bindings).
Ctl-x listens for emacs bindings.
Not in the default term-char-mode it doesn't, so your problem is most likely with your own config.
Run a terminal in emacs -Q to confirm the standard behaviour.

I'm having issues setting up ansi-term in emacs [duplicate]

I use ansi-term for my normal terminal sessions. I tend to use unicode characters in my prompt to do things like set the trailing character based on the type of source control I'm using.
I use the character "±" as my prompt for git repositories.
In Emacs' ansi-term, my prompt isn't rendered as unicode, and shows as "\302\261". Displaying the current coding system shows that it defaults to utf-8-unix for input to the process, but I get raw binary as the decoding output. I can hit C-c RET p to change the encoding and decoding coding systems. I'm drawing a blank as to how to set this automatically when I start a terminal? I've tried adding to term-mode-hook to set the buffer's coding system to no avail. I think I've found what I'm looking for in term.el, but I don't care to tweak the distribution elisp, and it appears the raw binary was added to fix a bug somewhere else.
EDIT: This was unclear originally. I'm having issues setting the default process coding system for ansi-term running under Cocoa-ized Emacs 23.3 on MacOS. Emacs itself isn't running in a terminal, my terminal is running in Emacs.
The following worked for me:
(add-hook 'term-exec-hook
(function
(lambda ()
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))))
ansi-term seems to ignore the default-process-coding-system variable, so I had to set it buffer-locally after it executes my shell.
After getting a better understanding of term.el, the following works:
(defadvice ansi-term (after advise-ansi-term-coding-system)
(set-buffer-process-coding-system 'utf-8-unix 'utf-8-unix))
(ad-activate 'ansi-term)
Trying this with term-mode-hook is broken because in term.el, term-mode-hook is called before switching to the terminal buffer, so set-buffer-process-coding-system breaks due to the lack of a process associated with the buffer.
Try
(set-terminal-coding-system 'utf-8-unix)
That's C-x RET t not C-x RET p.
So C-x RET p helps?
Unless C-h v default-process-coding-system is (utf-8-unix . utf-8-unix) try
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))

Use semicolon in global-set-key for function in .emacs

I am trying to set [Ctrl]-[;] as a keybinding in my .emacs like this
(global-set-key "\C-;" 'comment-or-uncomment-region)
however it doesn't work when I try (i don't get any error messages, it just has no effect). It will work though if i try a normal character (such as setting it to "\C-p").
I have also tried
(global-set-key (kbd "C-;") 'comment-or-uncomment-region)
but I don't like this option because for me it doesn't work when i run "emacs -nw". Any thoughts on how I can do this?
EDIT:
When I run C-hcC-; in emacs -nw I get the output:
; runs the command self-insert-command
which is exactly the same as when I run C-hc; in emacs -nw
So I believe phils is right, that it is a terminal problem, because emacs never actually sees C-;, it only sees ;
Indeed C-; is typically not something your terminal is able to send to an underlying application like Emacs (so it works under a GUI but not in a terminal). But I wonder: why do you need such a binding anyway, given that M-; is already bound to comment-dwim which does comment/uncomment the region when the region is selected, so it provides a superset of comment-or-uncomment-region.
Using (kbd "C-;") is absolutely fine and correct.
I suspect when you type C-; when running emacs -nw, your terminal is not actually sending anything to Emacs.
So your problem is more likely to be a question of how to get your terminal to send C-; to Emacs (or alternatively how to get Emacs to recognise the sequence which is sent).
If you run emacs -Q -nw and type C-hcC-;, do you get a "C-; is undefined" message?
Assuming that it is a terminal issue, here are some related Q&As which may point you in the right direction, but it's going to depend upon the particular terminal you are using.
Binding M-<up> / M-<down> in Emacs 23.1.1
Send "C-(" to Emacs in VT100/xterm terminal (Mac OS X's Terminal)?
How does one send S-RET to Emacs in a terminal?
emacs -nw issues with cscope and terminals

running scheme from emacs

I'm a newbie to LISP.
I am attempting to invoke the scheme interpreter from within emacs (version 23 running on windows). I loaded the xscheme library by telling emacs to M-x load-library and then entering xscheme at the prompt in the minibuffer. The library loaded, and then I issued the M-x run-scheme command. (I realize that all this loading can be done from .emacs at startup, but I am not concerned with that at the moment.)
So far so good - the *scheme* buffer has been created, and now I'm hoping that I'm able to talk to the scheme interpreter.
However, when I try to evaluate something in that *scheme*buffer (e.g. (define shoe-size 14)), I get this Output file descriptor of scheme is closed message in the minibuffer.
Does anybody know how to fix this in emacs?
(Also, how does one set the major-mode as REPL in the *scheme* buffer?)
Thank you.
Try setting the scheme-program-name variable to the path to your Scheme interpreter. The major-mode of the scheme buffer is probably just comint and you cannot do much about it unless you switch to something more capable like Geiser - something that I'd recommend you do.
Add this line to your .emacs file:
(setq scheme-program-name "gsi")
(Replace "gsi" with the name of your Scheme interpreter.)
You can then start the interpreter with M-x run-scheme. You can evaluate pieces of code by using C-x C-e (to evaluate the sexp before the point) or with C-M-x to evaluate the sexp you're in right now. You can also load a file with C-c C-l.
I'll start by saying that I'm very new to programming, scheme and SICP, but I'm trying to work through the course and watch the lectures that are online.
I'm running emacs on Ubuntu 12.10 and I really wanted to get MIT scheme working in emacs instead of relying on Edwin.
The above tips didn't work for me, but here's the step-by-step instructions that did work:
Install emacs 24 from the Ubuntu Software Center (search "emacs" and install it!)
Open a terminal (ALT + CTRL + t)
Go to your home directory (cd ~)
Open the hidden file .emacs in gedit (gedit .emacs)
On the first line of the file, type exactly what's after the colon: (require 'xscheme)
Save the changes to .emacs
That's it!!!
You can now open .scm files in emacs and use commands like C-x C-e.
*directions courtesy of http://alexott.net/en/writings/emacs-devenv/EmacsScheme.html#sec14
My guess is that it's just a known issue I still dunno how to sort that out (it's out of my current skills) but I got a macro that probably helps: just after writing the s-exp you can do Cc-Cz (it calls the geiser REPL) then C-spc, C-M-b, M-w, C-x-o, C-y and RET.
There are a variation (same, placed just after writing the s-exp): C-spc, C-M-b, M-w, C-c Cz, C-y and RET

Customizing Literate Haskell + LaTeX mode

I'm having a hard time forcing literate-haskell-mode to produce PDFlatex output by default. When I use C-c C-t C-f it just parses the lhs file with latex binary producing dvi. I know I can always use the shell to manually run pdflatex whatever.lhs, but that's not the emacs way. There must be a way of customizing the default C-c C-t C-f behavior, but I've been googling and searching, and I still haven't found what I'm looking for.
Anyone?
Cheers;
Piotr
I guess this uses LaTeX-mode in the backend so probably something like this should help:
(setq TeX-PDF-mode t)
This tell LaTeX-mode to use pdflatex by default.