8. Other Customizations
You can modify the behavior of Emacs in minor ways permanently by
putting your changes in your ‘init.el’ 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
‘init.el’ 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(see section Major and Minor Modes), put the following in your
‘init.el’ 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-VERSION/etc/sample.init.el’.
8.1 Other Customizations
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:
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 ‘init.el’
file :
| (setq case-fold-search nil)
|
This statement will make searches case-sensitive only in the current
buffer which is the ‘init.el’ 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:
- 1
Set the value of the variable to t (non-nil).
- 0
Set the value of the variable to nil.
- n
Move to the next variable.
- p
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 (xemacs)Variables section ‘Variables’ in XEmacs User’s Manual, for information on
these options.
8.2 Init File Examples
For customizing Emacs, you need to put Lisp expressions in your
‘init.el’ file. The following are some useful Lisp expressions. If
you find any of them useful, just type them in your ‘init.el’ file:
-
The following expression will make <TAB> in C mode insert a real tab
character if the cursor or point is in the middle of the line. Now
hitting the <TAB> key will indent a line only if the cursor is at
the left margin or in the line’s indentation:
| (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.
-
This expression will turn on the auto-fill-mode when you are in
text mode:
| (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.
-
The following expression will enable the use of eval-expression
without confirmation:
| (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.
-
This expression will remove the binding of C-x C-c, because its
easy to hit this key by mistake and you will exit Emacs
unintentionally. You can use the Exit Emacs option from the File
menu to exit Emacs.
| (global-set-key "\C-x\C-c" nil)
|
Now if you type C-x C-c, you won’t exit Emacs.
-
The following expression will make the <BACKSPACE> and the <DEL>
key work in the same manner:
| (global-set-key 'backspace [delete])
|
-
This expression will make searches case sensitive:
| (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 ‘init.el’ 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".
-
This expression will enable the font-lock mode when you are using
texinfo mode:
| (add-hook 'texinfo-mode-hook 'turn-on-font-lock)
|
See section Minor Modes, for information on font-lock mode.
-
Rebinds the key C-x l to run the function
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)
|
-
The following expression will bind C-x l to run the function
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>.
-
You can bind the function
undo
i.e. C-x u to any key, for
example to <F2>:
| (global-set-key 'f2 'undo)
|
-
The following statement will display the current time in the modeline of
the buffer:
-
This displays the current line number on which the cursor is present in
the modeline:
| (setq line-number-mode t)
|
-
If you don’t want the text to be highlighted when you use commands for
marking regions so as to use the kill and yank commands
later, you can use the following expression in your ‘init.el’ file:
Now if you use a command like C-x C-p (mark-page
), the text
will not be highlighted.
-
To control the number of buffers listed when you select the Buffers
menu, you need to set the variable
buffers-menu-max-size
to
whatever value you wish. For example, if you want 20 buffers to be listed
when you select Buffers use:
| (setq buffers-menu-max-size 20)
|
-
If you want the window title area to display the full directory/name of
the current buffer’s file, and not just the name, use:
| (setq frame-title-format "%S: %f")
|
-
To get rid of the menu, use :
-
If you want an extensive menu-bar use the following expression in your
‘init.el’ file.
If you want to write your own menus, you can look at some of the
examples in
‘/usr/local/lib/xemacs/xemacs-packages/lisp/edit-utils/big-menubar.el’ file.
For more information on initializing your ‘init.el’ file,
See (xemacs)Init File section ‘Init File’ in XEmacs User’s Manual. You should also look at
‘/usr/local/lib/xemacs-VERSION/etc/sample.init.el’, which is a sample
‘init.el’ file. It contains some of the commonly desired
customizations in Emacs.
This document was generated by Aidan Kehoe on December 27, 2016 using texi2html 1.82.