[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
You can modify the behavior of Emacs in minor ways permanently by putting your changes in your ‘.emacs’ file. This file contains Lisp function call expressions. Each of these expressions will consist of a function name followed by arguments, all surrounded by parentheses. For example, to turn on the auto-fill-mode (i.e. break lines automatically when they become too long) , put the following line in your ‘.emacs’ file:
(add-hook 'text-mode-hook '(lambda() (auto-fill-mode 1)))
Emacs has a function named "turn-on-auto-fill" which is defined as "(lambda() (auto-fill-mode 1))". Therefore you can also write the above as:
(add-hook 'text-mode-hook 'turn-on-auto-fill)
Emacs provides a number of hooks for the sake of customization. The hook variables contain list of functions to be called with no arguments. To turn on the auto-fill-mode, add the appropriate hook as shown in the example above.
Similarly, to enable the "font-lock mode" which displays your program in different fonts and colors(@pxref{Modes}), put the following in your ‘.emacs’ file. The comments above the statement explain what the statements do.
;;; enables the font-lock-mode in Lisp Mode (add-hook 'lisp-mode-hook 'turn-on-font-lock) ;;; enables the font-lock-mode in Texinfo Mode (add-hook 'texinfo-mode-hook 'turn-on-font-lock) ;;; enables the font-lock mode in C Mode (add-hook 'c-mode-hook 'turn-on-font-lock)
To turn on the font-lock mode in other Major Modes like emacs-lisp, just put the name of the mode with "-hook" appended to it as the middle parameter in the above examples. You can also select the color that the functions, comments or other keywords should be displayed in :
;;; the function names will now be displayed in blue color (set-face-foreground 'font-lock-function-name-face "blue") ;;; the comments will be displayed in forest green (set-face-foreground 'font-lock-comment-face "forest green")
For other customizations regarding the font-lock face, look at the file ‘/usr/local/lib/xemacs-19.11/etc/sample.emacs’.
1.1 Other Customizations | Customizing Emacs variables | |
1.2 Init File Examples | Some examples of Lisp expressions in .emacs file |
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
In XEmacs, variables are used for internal record-keeping and customizations. There are some variables called "options" which you can use for customizations. To examine a variable use:
;;; print the value and documentation of the variable, use either of the ;;; following commands C-h v M-x describe variable
After you type any of the above commands, you will be prompted for a variable name in the echo area. Type in the name of the variable, for example, type case-fold-search <RET> Your window will split into two and you will see the following message in that window:
case-fold-search's value is t This value is specific to the current buffer. Documentation: *Non-nil if searches should ignore case. Automatically becomes buffer-local when set in any fashion.
Since this variable’s value is ’t’ searches will ignore case. If you want case-sensitive-search (i.e. if you are searching for "Foo" and you do not want "foo" to be included in the search, you need to set this variable to "nil". In order to do that, use:
M-x set-variable
Emacs will prompt you for the variable which you wish to set. Type in "case-fold-search" and hit <RET>. You will see the following message:
Set case-fold-search to value:
Type "nil" and hit <RET>. Now if you again use M-x describe variable , you will see that the new value of case-fold-search will be "nil" and your searches will be case-sensitive. This will be effective only for that Emacs session. If you want to change the value of a variable permanently put the following statement in your ‘.emacs’ file :
(setq case-fold-search nil)
This statement will make searches case-sensitive only in the current buffer which is the ‘.emacs’ file. This will not be very useful. To make searches case-sensitive globally in all buffers, use:
(setq-default case-fold-search nil)
If you want to change the value of any other variable, use :
(setq <variable-name> <new value>)
"setq" will assign the "new value" to the "variable-name" .
If you want a list of the "options" i.e. the variables available for customization type:
;;; displays a buffer listing names, values and documentation of options M-x list-options ;;; displays options and allows you to edit those list of options M-x edit-options
Try these options. If you are using edit-options to edit a variable, just point at the variable you wish to edit and use one of the following commands:
Set the value of the variable to t (non-nil).
Set the value of the variable to nil.
Move to the next variable.
Move to the previous variable.
There are some other options available to make the value of a variable local to a buffer and then to switch to its global value. You can also have a local variables list in a file which specifies the values to use for certain Emacs variables when you edit that file. See ‘Variables’ in XEmacs Reference Manual, for information on these options.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
For customizing Emacs, you need to put Lisp expressions in your ‘.emacs’ file. The following are some useful Lisp expressions. If you find any of them useful, just type them in your ‘.emacs’ file:
(setq c-tab-always-indent nil)
The value of the variable c-tab-always-indent is usually ‘t’ for ‘true’. When this variable is true, then hitting the <TAB> key always indents the current line.
(setq text-mode-hook 'turn-on-auto-fill)
This mode will automatically break lines when you type a space so that the lines don’t become too long. The length of the lines is controlled by the variable fill-column. You can set this variable to a value you wish. Look at the documentation for this variable to see its default value. To change the value to 75 for example, use:
(setq-default fill-column 75)
This will change the value of this variable globally.
(put 'eval-expression 'disabled nil)
Now when you use eval-expression, it will print the value of the expression you specify in the echo area without confirming with you.
(global-set-key "\C-x\C-c" nil)
Now if you type C-x C-c, you won’t exit Emacs.
(global-set-key 'backspace [delete])
(setq-default case-fold-search nil)
If we use "setq" instead of "setq-default" then searches will be case-sensitive only in the current buffer’s local value. In this case the buffer would be the ‘.emacs’ file. Since this would not be too helpful and we want to have case-sensitive searches in all buffers, we have to use "setq-default".
(add-hook 'texinfo-mode-hook 'turn-on-font-lock)
@xref{Minor Modes}, for information on font-lock mode.
make-symbolic-link
:
(global-set-key "\C-xl" 'make-symbolic-link)
We use the single quote before "make-symbolic-link" because its a function name. You can also use the following expression which does the same thing:
(define-key global-map "C-xl" 'make-symbolic-link)
make-symbolic-link
in C mode only:
(define-key c-mode-map "C-xl" 'make-symbolic-link)
Instead of binding C-xl to run make-symbolic-link
, you can
bind the <F1> key to run this function:
(define-key c-mode-map 'f1 'make-symbolic-link)
Here, you have to use lower case for naming function keys like <F1>.
undo
i.e. C-x u to any key, for
example to <F2>:
(global-set-key 'f2 'undo)
(display-time)
(setq line-number-mode t)
(setq zmacs-regions nil)
Now if you use a command like C-x C-p (mark-page
), the text
will not be highlighted.
(setq buffers-menu-max-size 20)
(setq frame-title-format "%S: %f")
(set-menubar nil)
(load "big-menubar")
If you want to write your own menus, you can look at some of the examples in ‘/usr/local/lib/xemacs-19.13/lisp/packages/big-menubar.el’ file.
For more information on initializing your ‘.emacs’ file, See ‘Init File’ in XEmacs Reference Manual. You should also look at ‘/usr/local/lib/xemacs-19.13/etc/sample.emacs’, which is a sample ‘.emacs’ file. It contains some of the commonly desired customizations in Emacs.
[Top] | [Contents] | [Index] | [ ? ] |
This document was generated on December 6, 2024 using texi2html 5.0.
The buttons in the navigation panels have the following meaning:
Button | Name | Go to | From 1.2.3 go to |
---|---|---|---|
[ << ] | FastBack | Beginning of this chapter or previous chapter | 1 |
[ < ] | Back | Previous section in reading order | 1.2.2 |
[ Up ] | Up | Up section | 1.2 |
[ > ] | Forward | Next section in reading order | 1.2.4 |
[ >> ] | FastForward | Next chapter | 2 |
[Top] | Top | Cover (top) of document | |
[Contents] | Contents | Table of contents | |
[Index] | Index | Index | |
[ ? ] | About | About (help) |
where the Example assumes that the current position is at Subsubsection One-Two-Three of a document of the following structure:
This document was generated on December 6, 2024 using texi2html 5.0.