`
agile_boy
  • 浏览: 556977 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Answers to some common problems and faq's

阅读更多

Remark:
For changes in the .emacs file to take effect, you need to restart emacs or type "M-x eval-buffer <ret>"

 

Q: What does fontlocking do ?
A:  Font Lock mode is a minor mode, always local to a particular buffer,
which highlights (or "fontifies") using various faces according to the
syntax of the text you are editing.  It can recognize comments and
strings in most languages; in several languages, it can also recognize
and properly highlight various other important constructs--for example,
names of functions being defined or reserved keywords.
Font Locking is turned on automatically in the emacs-default file. It
recognizes fileformats based on their extension (e.g. .tex for a latex file,
.c for a c-file or .C for a c++-file).

Q: How do I change the colors of my text ?
A: Font Lock recognizes patterns and assigns a face-value to them.
You can change the color and font-properties of this face yourself.
If you want to see the list of all used faces, type M-x list-faces-display
(with M the meta or alt key) or go to "Edit" "Text Properties" "Display
Faces" in the menu bar.

You can create your own faces or change properties of an existing face.
Some possible properties are:

  • background
  • boldness
  • font
  • foreground
  • italic
  • underline

If you want to change the foreground color of all comments to yellow for instance,
add the following lines to your .emacs file:

(set-face-foreground 'font-lock-comment-face "Yellow" )
(set-variable font-lock-comment-face 'font-lock-comment-face)

You can find the name font-lock-comment-face via the list of the faces.
The function set-face-foreground sets the color.

Q: How do I add keywords or patterns to a certain mode ?
A: Font Lock highlighting patterns already exist for many modes, but you
may want to fontify additional patterns.  You can use the function
`font-lock-add-keywords', to add your own highlighting patterns for a
particular mode.  For example,  if you want to put the string with the filename
after an include or import statement in a c-file in the same face as the word
include or import , put the following in your .emacs file

(font-lock-add-keywords
 'c-mode
; put the string after include and import in the same color
 '(("^#[ \t]*\\(import\\|include\\)[ \t]*\\(<[^>\"\n]*>?\\)" 2 font-lock-builtin-face t)
; put the # before the keywords in the same color
 ("^#[ \t]*\\(import\\|include\\|ifdef\\|endif\\|ifndef\\|elif\\|endif\\|define\\)[ \t]*" 0 font-lock-builtin-face t)))

Q: What's a keybinding ?
A: A keybinding "binds" a certain key to a command that is executed every time
the key is pressed. For instance M-v (Meta-v or Alt-v) is bound to PgUp.

Q: How do I set my own keybindings ?
A: You might want to set keybindings of your own. You can do this with the command
global-set-key
A particular interesting key-binding for me for instance is the one for "goto-line"
Put the following line in your .emacs:

(global-set-key [?\M-\l] 'goto-line)

This will bind the key M-l to the goto-line function.

Q: How do I create a key to kill all characters up to the beginning of the line ?
A: First you have to define the function which performs this. You can for instance put the following code in your .emacs files

(defun kill-upto-begin-line (foo)
"Function to kill everything up to beginning of line"
(interactive "P")
(setq num (current-column))
(while (> num 0)
(backward-delete-char-untabify 1)
(setq num (current-column))))


Then you can bind the function to a key, for instance the M-k key:

(global-set-key [?\M-\k] 'kill-upto-begin-line)

Q: How can I read mail with emacs ?
A: You can read, send, dispose, ... mail with the great program "vm"
You start it by typing M-x vm (enter)
You will have to put (require 'vm) in your .emacs file first though.

Q: Are there other mail readers ?
A: Emacs has also got an internal mail reader called Rmail.

Q: How can I customize my vm mail program ?
A: You can put some customizations in a .vm file
If you want to know all possible variables to customize, read the manual !

Q: Can I see an example customization file for vm ?
A: Yes, there is one right here

Q: How can I speed up MIME encoding and decoding ?
A: VM can encode and decode MIME attachments. It uses internal functions
for this which can be very slow. A way to speed up this process is to compile
your own encoder and decoder and tell vm to use these instead.

You can find source-code for these processes right here:
 base64-encode.c   and base64-decode.c
Copy these files into a directory you own (for instance ~/bin) and compile
them with the commands

"gcc -o base64-encode base64-encode.c" and
"gcc -o base64-decode base64-decode.c"

Add the following lines into your .emacs file (or .vm file if you have one)

(setq vm-mime-base64-decoder-program "FULL_PATH_TO_FILE/base64-decode")
(setq vm-mime-base64-encoder-program "FULL_PATH_TO_FILE/base64-encode")

where FULL_PATH_TO_FILE is the correct path to your 2 executables. For instance if you
put them in ~/bin and you are a student who should graduate in 2002 with login name "janssens",
FULL_PATH_TO_FILE is "/users/prom2002/janssens"

This will do the trick.

Q: How can I read news with emacs ?
A: You can read news with the gnus program, standard for emacs.
If you want to start it, type M-x gnus (enter)
For more info, read the manual.

Q: How do I define which news-server to use ?
A: You can define a variable for this in your .emacs file
For the kuleuven news server you should use the following line:

(setq gnus-nntp-server "news.kulnet.kuleuven.ac.be")

This is the default server that has been set in the emacs-default file.

Q: How can I put the scrollbar on the right ?
A: Put the following two lines in your .emacs file:

(setq scroll-bar-mode-explicit t)
(set-scroll-bar-mode `right)

Q: What's the problem ?
A: Dos and Unix use different characters to denote an end-of-line.
Unix uses a "newline" while Dos uses a "carriage-return".
This is why a file, saved in Dos but viewed in Unix shows the typical "^M" at the end of each line.

Q: What can emacs do ?
A: emacs detects which coding system is used for representing the end-of-line.
If it's a unix file, it will show a ":" on the status line and emacs will always use the newline
character to denote an end-of-line.
If it's a dos file, you will see "(DOS)" in the status line and emacs will use the carriage return to
denote an end-of-line when saving the file. This means that emacs does not alter the coding system of
a file. You don't see the "^M" in the file but emacs will write them out when saving the file.

Q: How to convert from Dos to Unix ?
A: Since emacs doesn't show the "^M" in the file, you might believe the carriage returns have dissapeared.
This is not the case: emacs still writes the "^M" when saving the file.
To get rid of them (and thus change the file from Dos to Unix text), use the following sequence of commands:

  • type M-x  set-buffer-file-coding-system RET and choose `undecided-unix'
  • save the file

Q: What do you mean ?
A: Sometimes you want to become another user or login to another machine to be able to open and/or save a file.
You could go back to your terminal, start an ssh (or su) -session and start a new emacs.
But why go through all this trouble if you can do this inside (the already running) emacs ?!

Q: Can't I just use ange-ftp ?
A: There was the solution to this problem in emacs, called "ange-ftp".
This package uses the ftp protocol to get save files on another machine or as a different user.
The major disadvantage of this is the fact that ftp doesn't use any form of encryption.
In other words, your passwords are flying totally unprotected over the network !
Luckily there's a new package now, called TRAMP which deals with this problem.

Q: What's this Tramp package ?
A: Tramp is a package which allows you to use ssh and scp to open and save files on other machines or as another user.
These programs use encryption to protect your passwords.
You can read more about these programs here .

Q: How do I use Tramp ?
A: The usage of Tramp is very similar to that of ange-ftp.
Suppose you want to open the ".emacs" file on the machine "cassini " as user "robust ".
For this you type the following command:

C-x C-f /r@scp:robust@cassini:~/.emacs

This makes Tramp use the "scp " command to open the file.
Be careful: this only works if scp doesn't need a password to become "robust" on "cassini",
i.e. if there is an entry in the file "~robust/ssh/authorized-keys" with your key.

If this is not the case, you need to use the "ssh" command with "uuencode".
The command for this is

C-x C-f /r@su:robust@cassini:~/.emacs

Tramp will use "ssh " and will ask you for the password of "robust".
If you enter the correct password, the file will be opened. Because "ssh" is used, the password is encrypted before it is sent.

A: How do I setup Tramp ?
A: If you load the emacs-default file or if you have no .emacs file, Tramp is loaded automatically,
so you can use it immediately.
If you don't load emacs-default , you need to add the following lines to your .emacs file:

(require 'tramp)
(setq tramp-default-method "scp")
(setq tramp-remote-path
         (append '("/freeware/bin/gnu-tools"
                        ) tramp-remote-path))

Be sure to put these lines AFTER everything that has to do with ange-ftp.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics