I love the cyrillic-translit input method for Emacs. However, after I set the wonderful Terminus as my default font, the Russian characters appear in Arial or something (in any case it's not Terminus).
How do I fix this? Setting the default font to UTF-8 (Emacs equivalent "-outline-Terminus-normal-normal-normal-mono-16-*-*-*-c-*-iso10646-1") doesn't help. I guess this possibly means that Terminus lacks decent UTF-8 support?
Anyhow, I'm using the following snippet for switching between cyrillic-translit input method and the "normal" mode:
(defun toggle-cyrillic-input-method ()
"toggle between French and no input method"
(interactive)
(if (string= current-input-method "cyrillic-translit")
(set-input-method nil)
(set-input-method "cyrillic-translit")))
(global-set-key [f9] 'toggle-cyrillic-input-method)
Now -- is there a way to make the snippet not only switch over to cyrillic-translit but also switch the codepage when I press F9?
In other words, how do I make it also toggle the font between "-outline-Terminus-normal-normal-normal-mono-16-*-*-*-c-*-iso8859-1" (Latin) and "-outline-Terminus-normal-normal-normal-mono-16-*-*-*-c-*-iso8859-5" (Russian)?
It's the only workaround I (as a non-programmer) could think of. Any other ideas are welcome, too. Thanks!
Related
I frequently use abbrev-mode in Emacs when writing prose or just taking notes. It would be nice if there was any way to define language-specific abbreviations, e.g. if I write "proj" in an English text, it would expand to "project", whereas if I write it in a Swedish text, it would expand to "projekt". Likewise, "riskfac" would expand to "risk factor" in English but "riskfaktor" in Swedish. How to accomplish this?
It would be especially nice if this could be coupled to the ispell-dictionary that is currently used. I know there are different abbrev-tables, but these are specific to modes, not languages.
Any ideas here?
For free text, I tend to use pabbrev.el (which I wrote!) but there are several other packages which now do the same thing -- a dynamic abbreviation expansion depending on what you have already written. This tends to give a degree of language specificity in practice.
Otherwise, I think you need something to switch the abbrev tables in different buffers. Perhaps you could hook this into input methods if you are using them, then Emacs would know which language you were using.
Consider trying dynamic-completion-mode (standard library completion.el).
You can change between different dynamic-completion files, one for each language. Option save-completions-file-name holds the file name, but nothing says that you cannot change its value dynamically, e.g. using a command, in order to switch among several sets of completions. (Naturally, such a command should save to one file before switching to another.)
The "doc" for dynamic-completion-mode is in the Commentary of library completion.el. The library is old, but still quite useful, IMHO. Excerpts from the Commentary:
This watches all the words that you type and remembers them. When
typing a new word, pressing "complete" (meta-return) "completes" the
word by inserting the most recently used word that begins with the
same characters. If you press meta-return repeatedly, it cycles
through all the words it knows about.
If you like the completion then just continue typing, it is as if you
entered the text by hand. If you want the inserted extra characters
to go away, type control-w or delete. More options are described below.
The guesses are made in the order of the most recently "used". Typing
in a word and then typing a separator character (such as a space) "uses"
the word. So does moving a cursor over the word. If no words are found,
it uses an extended version of the dabbrev style completion.
(See also Icicles completion for dynamic-completion-mode.)
I had the same requirement (and am also switching between writing
English and Swedish in Emacs) and solved it by defining two modes, one
for English and one for Swedish. Both derive from a special "writer
mode" that has some useful features when I am just writing text. I have
some convenient keybindings (and even abbrevs that run code) to switch
modes/languages. Since each language has its own mode, I can keep
different abbrevs for the two languages.
Here is part of my setup:
(define-derived-mode writer-mode text-mode "W-EN"
"Writer mode."
(abbrev-mode 1))
(define-derived-mode writer-english-mode writer-mode "W-EN"
"Writer mode - English.")
(define-derived-mode writer-swedish-mode writer-mode "W-SV"
"Writer mode - Swedish.")
...
(defun writer-swedish ()
(interactive)
(writer-swedish-mode)
(set-input-method 'swedish-postfix)
(setq header-line-format " SV> ")
(setq mode-line-format nil)
(flyspell-mode -1)
(writer-setup-bindings))
(defun writer-english ()
(interactive)
(writer-english-mode)
(deactivate-input-method)
(setq header-line-format " EN> ")
(setq mode-line-format nil)
(flyspell-mode 1)
(writer-setup-bindings))
As you can see I also use an input method when writing Swedish. I have a
keyboard with Swedish letters but try to stay with English keyboard
layout since it is generally better when writing code.
I have emacs version 25.0, I enable prettify-symbols-mode, and type (lambda () t) but it doesn't prettify. How do I use this mode? Also what symbols are available and how can I configure it? Any references are appreciated.
Edit: Nothing happened in scratch buffer and Markdown mode, but when I tried in a Emacs-lisp mode, It did prettify, but now I got a question mark instead of the lambda symbol, how do I fix that?
Edit: I asked the related question here.
Edit: This SO question solved the unicode problem.
prettify-symbols-mode is buffer-local. If you want to enable it globally, use global-prettify-symbols-mode.
The question mark you are seeing is probably because Emacs can't find a font that contains a lambda character. Try switching to a font with decent Unicode support like DejaVu Sans Mono.
I believe that only Lambda prettifies out of the box, and only in emacs-lisp-mode buffers. Check the value of prettify-symbols-alist from a buffer with prettify-symbols enabled to see the current replacements table.
If you wish to add prettification of other symbols you can do something like this, from C-h f prettify-symbols-mode RET:
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(push '("<=" . ?≤) prettify-symbols-alist)))
all
Now I'm editing c sources with emacs under c-mode. How ever auto-fill-mode doesn't seem to work at all. Here how I enabled and tried to use it.
M-x auto-fill-mode (enable auto-fill-mode)
Typed in a line longer than auto-fill size(which 80 characters for now) --> didn't break the line
Tried to auto-filled by issuing M-q
However above attempt didn't work out at all.
Could anybody point out that what have I done wrong?
Thanks for your help in advance.
When you use auto-fill-mode in c-mode, the default behavior is to wrap text only when writing text, as in a comment. You can override this by customizing the value of c-ignore-auto-fill. Note that emacs will wrap and indent your code as text, which is probably not what you want.
A better solution is probably to bind space to a function like this:
(defun insert-space-or-newline-and-indent ()
(interactive)
(if (>= (current-column) fill-column)
(newline-and-indent)
(insert-char ? )))
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))
When I do M-! in my emacs 21.4 the ANSI codes gets literal. Eg: ls --color
^[[0m^[[0m05420273.pdf^[[0m
^[[0m100829_Baño1.pdf^[[0m
Is there a way of having it with color and UTF8?
The same question has been answered in SO before but with not totally satisfactory results (the solution given was to open a shell-mode). I know how to have colors in a shell. I only want to know how I can have color with M! (shell-command) or if it is not possible at all.
A shell mode is too intrusive when you want only to show something quick and don't want to move to this buffer and you would like to have it disappear automatically without C-x-k. Obviously there are situations where a shell buffer is more convenient but thanks to the other question I found how to put color to the shell-mode.
[note] emacs in use
GNU Emacs 21.4.1 (x86_64-redhat-linux-gnu, X toolkit, Xaw3d scroll bars) of 2008-06-15 on builder6.centos.org
ansi-color.el contains the functions to process ANSI color codes. Unfortunately, there's not really a good way to hook it into shell-command. This is something of a hack, but it works:
(require 'ansi-color)
(defadvice display-message-or-buffer (before ansi-color activate)
"Process ANSI color codes in shell output."
(let ((buf (ad-get-arg 0)))
(and (bufferp buf)
(string= (buffer-name buf) "*Shell Command Output*")
(with-current-buffer buf
(ansi-color-apply-on-region (point-min) (point-max))))))
About UTF-8:
To specify a coding system for
converting non-ASCII characters in the
shell command output, use C-x RET c
before this command.
Noninteractive callers can specify
coding systems by binding
coding-system-for-read' and
coding-system-for-write'.
This is from the documentation of shell-command.