How to make emacs accept UTF-8 (uppercase) encoding? - emacs

The following specifies file's character encoding:
# -*- coding: utf-8 -*-
But the uppercase variant:
# -*- coding: UTF-8 -*-
produces:
Warning (mule): Invalid coding system `UTF-8' is specified for the
current buffer/file by the :coding tag. It is highly recommended to
fix it before writing to a file.
Version: GNU Emacs 23.3.1
UTF-8 is an official name for the utf-8 character encoding.
The obvious add-to-coding-system-list function doesn't apply in this case. How to make UTF-8 to be alias for utf-8 in the coding declaration?

I think, that following code will help you:
(define-coding-system-alias 'UTF-8 'utf-8)

Related

yasnippet weird-input when org-mode :tag: on same line

I am trying to create a yasnippet for new projects in org-mode.
The beginning of the yasnippet looks like this.
# -*- mode: snippet -*-
# name: project
# key: project
# --
#+TAGS: project(p)
* $1
* $2 :project:
However, I have the following problem on the line with the :project: tag.
The input is input with large spaces between each letter. Is this a problem in org-mode or does the org-mode syntax for tags represent something in yasnippet definitions?
!

org-babel, ruby and encoding

When I evaluate ruby code blocks inside org-mode I encounter utf-8 errors.
and indeed If i do
#+BEGIN_SRC ruby :exports both :results output
puts RUBY_VERSION
puts __ENCODING__
#+END_SRC
#+RESULTS:
: 2.1.1
: US-ASCII
and when i try to evaluate
#+BEGIN_SRC ruby
'Aurélien'
#+END_SRC
I get this error in Org-Babel Error Output
-:3: invalid multibyte char (US-ASCII)
-:3: invalid multibyte char (US-ASCII)
-:3: syntax error, unexpected end-of-input, expecting keyword_end
'Aurélien'
If I start an inf-ruby buffer I can use utf-8, there is no problem. I think it is a problem with org-babel.
my configuration:
M-x emacs-version 24.4.1
M-x org-version 8.2.10
M-! ruby --version 2.1.1p76
from package list: inf-ruby 20141005.550 installed
In my init file I have
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(setq buffer-file-coding-system 'utf-8)
(setq erc-server-coding-system '(utf-8 . utf-8))
(setq locale-coding-system 'utf-8)
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
Is there a setting to change to have utf-8 by default for ruby code blocks and org-babel?
I found the problem.
On my mac, Emacs with a GUI default environment encoding is C.
In my init file, I specified an environment encoding with
(setenv "LANG" "fr_FR.UTF-8")
(setenv "LC_ALL" "fr_FR.UTF-8")
and org-babel picks it up correctly

Emacs: Disabling a minor mode from a file header

Though I mostly hate auto-fill-mode, Org Mode makes a good case for using it, so I don't want to disable it for Org Mode by default. However, I do have some Org files where I absolutely do not want it, and am sick of typing M-x auto-etc every time I open them.
I know you can pass variable to Emacs from file headers, and after a bit of searching I came up with this document from which I deduced that I want something like this:
-*- mode: Org; auto-fill-mode 0 -*-
as the first line of my file. But not this exactly, because that gives me an error:
Malformed mode-line: "auto-fill-mode 0"
and auto-fill mode does not start up.
I am sure it is a simple error in syntax, but it would be nice to know the right way to do this.
This is what I use:
# -*- mode: Org; eval: (auto-fill-mode 0) -*- #
Note that the # characters are optional, I just prefer them for style reasons.
$ info emacs
48.2.4.1 Specifying File Variables:
Do not use the `mode' keyword for minor modes. To enable or disable
a minor mode in a local variables list, use the `eval' keyword with a
Lisp expression that runs the mode command (*note Minor Modes::).`
As per this part of the doc, append this to the end of your file:
# Local Variables:
# eval: (auto-fill-mode 0)
# End:
You are missing a colon:
-*- mode: Org; auto-fill-mode: 0; -*-

how do I get emacs to treat a file with the wrong extension correctly?

So (let us not concern ourselves with why) I have a .emacs file which is called dotemacs, and a .bashrc file which is called dotbashrc.
When I load up dotemacs, I get no syntax highlighing (amongst other things). If I do M-x lisp-mode then all is well.
Without changing the name of the file, how do I get emacs to recognise automatically that dotemacs is a lisp file and go into lisp-mode? Similarly for bash scripts, and indeed any other type of file with the wrong (or no) extension.
You can put this at the top of the dotemacs file:
; -*- mode: lisp -*-
causing it to start elisp-mode when you load the file.
For shell scripts, putting a #!/bin/bash (for whichever shell you are using) is enough to turn on the correct mode. Or otherwise put this at the top of the file:
# -*- mode: sh -*-
I like the answer above, but here is another way you could do it :)
Add the following line to your .emacs
(add-to-list 'auto-mode-alist '(".emacs" . lisp-mode))

How to fix aHg output encoding?

Here is what I use:
- MacOS X 10.6.7
- GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
- Mercurial Distributed SCM (version 1.7.2+20101201)
- GNU Emacs 24.0.50 (build from git repo with --cocoa flag)
- aHg v0.99
Here is my emacs settings:
(set-default-coding-systems 'utf-8)
(prefer-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(set-language-environment 'UTF-8)
And here if what i got after C-c h g s:
parent: 2512:6252abcd7368 tip
JavaScript: ???????? ???????????? ????? ? ???????.
branch: default
commit: 3 modified, 6 unknown
update: (current)
Running hg log under M-x term gives me a correct result I can read (? is a russian chars...). So... How can I fix this in Emacs in aHg output?
First thing, that should be checked here - which LANG is set when Emacs was started)? (what is returned when you execute M-: (getenv "LANG")? As I remember, Mac OS X set LANG to "C" on the start of launchpad... setting of language environment don't modify LANG...
You can explicitly set the LANG environment from Emacs using (setenv "LANG" "ru_RU.UTF-8") or use "en_EN.UTF-8" if it preferable.
P.S. I just checked ahg with different LANG settings, and see question marks when I set LANG to "C", and see Russian letters when I run ahg-log in repository
It could be that the default font that is being used for output when you do C-c h g s doesn't support Cyrillic characters. You can see what font is being used by placing the point on one of the Russian characters that isn't being displayed properly and pressing C-u C-x =. To ensure that Russian is always displayed properly in Emacs, you can specify that all Russian characters will be displayed in a particular font. Since the Cyrillic characters are in the Unicode range U+0400 – U+04FF and the Arial font seems to display these characters ok, you could try the following in your Emacs init file:
(set-fontset-font "fontset-default"
'(#x400 . #x4ff)
"Arial")