set-language-environment and M-x shell - emacs

I am using shells using UTF-8 and others using Latin-1. However, when I change the default with set-language-environment, also the existing shells change their buffer-coding-system - indicator in the status-line.
How can I make a shell-buffer stick to its encoding?

Have you tried looking at the Emacs Wiki? It has a tip on how to edit the ~/.emacs file:
Working around a broken LANG
If your LANG is not set up correctly, and you don’t want to fix it,
you can do the setup in your ~/.emacs file:
(set-language-environment "Latin-1")
Usually you would do it interactively: ‘C-x RET l’.
To check the environment you want see ‘M-x
describe-language-environment’ and TAB to see all completions.

as suggested here,
simply create a shell script such as e.g.latinshell.sh (adjust the desired variables):
#!/bin/sh
LANG=de_DE:Latin-1
and then run it in a shell with:
. latinshell.sh

Related

How to use vim LatexSuite with a Makefile?

I would like to type :make in Vim to compile my LaTeX document. I wrote down compilation rules in a Makefile, but as soon as I enable the LatexSuite Vim extension, the Makefile is no longer used. Instead, Vim runs latex -interaction=nonstopmode (note the absence of a filename) and hangs in that command. I did not change the g:Tex_UseMakefile option from its default 1 to 0 and according to the documentation, that should cause my Makefile to be used, but it's not.
What configuration is needed to tell LatexSuite to just use my Makefile?
LatexSuite was obtained via OpenSuSE repositories: vim-plugin-latex-20120125-21.1.1.noarch
You can override this via following setting in your vimrc.
autocmd FileType tex let g:Tex_CompileRule_dvi = 'make'
Alternatively, set makeprg in $HOME/.vim/after/ftplugin/tex.vim
set makeprg='make'
Helpful in-source documentation of file <latex-suite-root-folder>/compiler/tex.vim
Section " Customization of 'makeprg': {{{
This (g:Tex_CompileRule_dvi) is a string which should be directly be able to be cast into
" &makeprg.

Can I change the location of the file emacs writes to in the process of printing?

Our network system is set up such that we can not write directly to the root directory (C:) so I get the following error when attempting to print.
Spooling with options (page headers are not supported)...
direct-print-region-helper: Opening output file: permission denied, c:/IP_139.222.92.102
If I could somehow change the location that emacs is attempting to write to (anywhere else) it would likely work.
GNU emacs 24.3.1 running on MS Win 7
I tried various solutions given in this thread and others with no success. I saw someone has commented about quoting the slashes. So, I entered
(setq printer-name "\\\\MyComputer\\HP8600")
(setq ps-printer-name "\\\\MyComputer\\HP8600")
in the .emacs file, and SUCCESS. Obviously you will have to change the names "MyComputer" to match your computer and HP8600 to your printer name (both available via Control Panel).
Adjust pr-temp-dir, e.g.:
(setq pr-temp-dir "c:/some/other/location")
After requiring 'printing, C-h v pr-temp-dir on my Linux system gives:
pr-temp-dir is a variable defined in `printing.el'.
Its value is "/tmp/"
Documentation:
Specify a directory for temporary files during printing.
See also `pr-ps-temp-file' and `pr-file-modes'.
You can customize this variable.
You may have to play with quoting or escaping a Windows-style path.

Open zsh scripts in sh-mode in emacs

*.zsh files open in the default mode (text-mode for me). However, sh-mode is actually multiple modes including behaviours for zsh, bash, etc. How can I tell emacs to open *.zsh files specifically in the zsh flavor of sh-mode?
The flavor of sh-mode is autodetected from the shebang line (first line of your script). If you have "#!/bin/zsh", zsh will be assumed and (for instance) autoload will be recognized as a keyword. autoload will be not recognized as such if first line is "#!/bin/bash"
To make emacs recognize *.zsh files as shell scripts, just add this to your init file:
(add-to-list 'auto-mode-alist '("\\.zsh\\'" . sh-mode))
A programmatic way of selecting a flavor when you don't want to use the shebang is doing this in a sh-mode buffer:
(sh-set-shell "zsh")
So in your case what you need (unless you use shebang) is to update the auto-mode-alist as above and
(add-hook 'sh-mode-hook
(lambda ()
(if (string-match "\\.zsh$" buffer-file-name)
(sh-set-shell "zsh"))))
Whether your file has a #! shebang or not, you can always use a file mode line or a local variables section to set shell-script mode. Having one of these in your script will allow Emacs to do the right thing even if you haven't updated the auto-mode-alist, so is recommended for any non-standard file extension.
The Emacs file mode line for shell scripts is -*- mode: sh -*-. It should be in a comment, and must appear on the first line (or the second line if the first one is a shebang line).
If you can't put it on the first (second) line for some reason, you can create a local variables section at the end of the file (in the last 3000 characters of the file, and on the last page, according to the manual):
# Local Variables:
# mode: sh
# End:
Note that just setting the Emacs mode will still rely on a shebang line for shell type autodetection, and if no shebang line is detected will default to the current SHELL environment variable or the value of sh-shell-file if set).
If you can't have a shebang line, but want the correct shell type to be selected, the only way to do this is with an eval in the mode line or local variables section. Adding this will generate a confirmation prompt every time the file is loaded into Emacs, so this is not generally recommended, but may be acceptable in some cases.
The mode line would be -*- mode: sh; eval: (sh-set-shell "zsh") -*-, and the local variables form would be:
# Local Variables:
# mode: sh
# eval: (sh-set-shell "zsh")
# End:
If you use the shebang method, a more robust form is
#!/usr/bin/env zsh
# env will search the path for zsh. Some distros may put it a different place.
# env is pretty much guaranteed to be in /usr/bin

VIM: FileType specific mapping not working when defined in ftplugin

I am trying to set a mapping for FileType perl. The mapping is for the case when I forgot to use semicolon at the end of the line.
So first I tried adding in my .vimrc autocmd! FileType perl nnoremap <leader>; $a;<esc> and it worked fine but than I thought of using ftlugin/perl.vim .
So I added the below line in my corresponding ~/.vim/after/ftplugin/perl.vim
nnoremap <buffer> <leader>; $a;<esc>
but it didn't work.
Any idea why it is not working ?
My perl version is perl 5, version 14.
Try putting the file in ~/.vim/ftplugin/perl.vim instead of ~/.vim/after/ftplugin/perl.vim. From :help after-directory:
*after-directory*
4. In the "after" directory in the system-wide Vim directory. This is
for the system administrator to overrule or add to the distributed
defaults (rarely needed)
5. In the "after" directory in your home directory. This is for
personal preferences to overrule or add to the distributed defaults
or system-wide settings (rarely needed).
From :help ftplugin:
If you do want to use the default plugin, but overrule one of the settings,
you can write the different setting in a script: >
setlocal textwidth=70
Now write this in the "after" directory, so that it gets sourced after the
distributed "vim.vim" ftplugin |after-directory|. For Unix this would be
"~/.vim/after/ftplugin/vim.vim". Note that the default plugin will have set
"b:did_ftplugin", but it is ignored here.
One thing I just noticed that was driving me crazy: <buffer> must be lowercase! Out of habit, I uppercase all of my <BRACKET> prefixes... and I had done the same for <BUFFER>. None of my ftplugin mappings worked and I couldn't figure it out... until I wasted hours trying different things, only to find that it must be lowercase <buffer>.

compile command across emacs sessions

how do i maintain a compile command across emacs sessions for a given file?
so, suppose I have file1.x, and I would like to use tool XComp to compile it. To do this, I need to run the following hypothetical command:
Xcomp file1.x && extract file1.x && Xlink file1.obj
So I do M-x compile, and write that thing. Now I have it available until I close emacs. How do I make that compile command persistent across emacs sessions, maybe a
% -*-
line somewhere? Any help appreciated.
The variable is "compile-command" so you could put this on the first line in your file:
// -*- compile-command: "Xcomp file1.x && extract file1.x && Xlink file1.obj" -*-
You may want to change the "//" for whatever you need to do for comments.