Basics of Emacs Configuration Files (reproduced)

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/schumyxp/article/details/2278268

Emacs's configuration file, called. Emacs, is a hidden file that exists under the current user's root directory, which is ~/.emacs

Emacs's configuration file uses Elisp as the language of the profile, derived from the powerful Lisp language. Let me briefly say a little bit about the Emacs configuration file. Although the content is not much, but also very superficial, but know this, at least when writing their own configuration files, not so disorderly.

Inside the configuration file, the quotation marks (;) start with a comment, such as the following line
; This is the Emacs config file

Let me give you some examples, a brief talk about configuration files.

(setq Transient-mark-mode T)
This line means to set the value to True for the variable Transient-mark-mode. can also be abbreviated to the following look
(Transient-mark-mode)
However, when I use the 22 version of Emacs, I will appear warning, pointing out that I do not recommend the shorthand form. Therefore, it is recommended that you write the first form, namely:
(setq Transient-mark-mode T)

The previous setq is a system keyword that represents the assignment of a value to the following variable. T indicates that True,nil represents false. If you want to turn off this feature, set it to nil.

This variable is transient-mark-mode to indicate whether a secondary mode is turned on. This secondary mode can highlight the selected text. If this option is not turned on, that is, not set (the default is off), or set to nil, then the text you select does not change. To be clear, you simply can't see what text you have selected!!

All right, go ahead.
(Setq Load-path (cons (Expand-file-name "~/.EMACS.D")
Load-path))
This line indicates the setting of Load-path. This load-path is the loading path of the custom library for Emacs. Load-path (Cons (Expand-file-name "~/.EMACS.D") Load-path) is a Lisp language, meaning that, in front of the original Load-path, append path ~/.EMACS.D. After that, we just put the library to be loaded (that is, the. el file) under the. emacs.d directory, and Emacs will automatically load it.

Look at these two lines again.
(Require ' template)
(template-initialize)
This is done when the template is loaded.

(Require ' template) means that the template is called,
(template-initialize) indicates that a method called Template-initialize is called. With these two lines, Emacs will be able to load the template. Many of the libraries in the latter configuration are similar to this.

The following is a careful talk about Add-hook.
For example, if we were to edit C + + code files, Emacs would invoke the main mode of C + +. But some of the settings in this pattern are different from the global setting, and I want to make some personalized settings. For example, when I want to enter a semicolon (;), Emacs automatically wraps and aligns the next line with the line above. For example, the length of the indentation, I would like to set the length of 4 spaces (of course, if you want to set the personality of 5 can also). This time, you need to use the Add-hook, it can be the specified main mode of personalized changes. Look at the following content:
;; Set C program Style
(Add-hook ' C-mode-hook ' Linux-c-mode)
(setq imenu-sort-function ' Imenu--sort-by-name)
( Defun Linux-c-mode ()
  (Define-key c-mode-map [Return] ' Newline-and-indent)
  (interactive)
  (C-set-style "K&r")
  (c-toggle-auto-state)
  (c-toggle-hungry-state)
  (setq C-basic-offset 4)
  (Imenu-add-menubar-index)
  (which-function-mode)
)
This is the personalization mode that modifies the C language.
(Add-hook ' C-mode-hook ' Linux-c-mode)
in this line, C-mode-hook is something inside the system, and the linux-c-mode behind it is a way we write ourselves. By C-mode-hook, we can change the main mode of the C language. What does that change to look like? Is the linux-c-mode inside the definition of the appearance. In Linux-c-mode, each line represents a change. For example, the first line:
(Define-key c-mode-map [Return] ' Newline-and-indent)
Re-defines the ENTER key. When you enter a carriage return, it is automatically indented.

Finally say the definition of the key, such as:
(Global-set-key [F8] ' gdb ')
is to define a global key, the function button F8, corresponding to the gdb above. Click on F8,emacs to start gdb for you.

In-depth stuff, please take a look at Elisp's article for yourself. I was just beginning to see, many still do not understand, can only write these first.

Basics of Emacs Configuration Files (reproduced)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.