My GNU Emacs configuration "Program"

Source: Internet
Author: User

Er ...... Generally, it is called a configuration file, right. Of course, that's what I call it. Let's continue with this name, which is called the Emacs configuration file.

 

The configuration file is the most important part for us to customize and expand Emacs. Generally, the most common configuration file is =. emacs =. Of course, it can also be other files. For more information, see GNU Emacs manual.

 

However, with the use of the day and time, more and more custom settings, =. emacs = becomes more and more large, and gradually increases to the point where it is difficult to maintain. It was not until one day that emacser.cn saw the skills of the file content of Wang chunye's organization. emacs, and divided the configuration information into multiple files, so that the maintenance difficulties were slightly mitigated. However, even after the split, the file will still become very large, and it is still increasing, and the maintenance is still under great pressure. Is there a good solution? I have not carefully read the idea of Ahei. After all, he is too big, and my configuration is not as big as that. What I hope is a simple and efficient solution. Can I only care about the content in my configuration file, without any additional information?

 

Until recently, I began to explore lisp and realized the powerful descriptive and abstract capabilities of the lisp language. Then I began to write a large number of configuration details into simple and clear = List =, then use the lisp code for processing, so that you can remove the endless method calls in the configuration file. After taking this path, the original "configuration file" changes to "configuration program.

. Emacs

If you don't want to talk about it, start fishing. Let's start with the basic =. emacs =. In this way, =. emacs = file is very simple. There are only two lines in the core part.

 

(add-to-list 'load-path "~/Shell/config/emacs.el" "~/Shell/config/emacs.init")

(mapc 'load (directory-files "~/Shell/config/emacs.init" t "^[a-zA-Z0-9].*.el$"))

The first line uses = load-Path = to register the location of the extension file. The second line is loaded one by one using = mapcar = function "= ~ All configuration files in the/Shell/config/Emacs. init = "directory. That's simple. Most of the remaining content is the code added by Emacs customization. In other words, the file =. emacs = is left for Emacs.

 

In fact, I didn't need any customization before using this method. Of course, the cost is obvious. The problem is that under the original configuration method, =. emacs = itself is too messy. If the customization of Emacs is messy, it is more difficult to maintain and control it. But now it's okay. I only use two rows in total, and write the rest wherever necessary. So now I have modified ANSI-color with customization. The blue directory in the default color is too dazzling.

Code

 (custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector [default default default italic underline bold bold-italic modeline])
'(ansi-color-names-vector ["black" "red" "PaleGreen" "yellow" "DodgerBlue1" "magenta" "cyan" "white"]))

 

In addition, I have reserved some Chinese font settings in =. emacs =. In the past, someone in emacser.com sent text settings. However, since GNU Emacs 23 and later basically work in the daemon mode, if you directly set the Chinese font in the original method, it is invalid in the emacsclient, therefore, add it to the hook of = make-frame =. In this way, the frame generated every time = emacsclient-c = is a specified Chinese font. Of course, there is another defect in this function, that is, if the daemon method is not used ...... You know, the fish and the bear's paw cannot have both.

 

Code

(Add-hook 'after-make-frame-Functions
(Lambda (ARG)
(If (> = (length (frame-list) 1)
(Set-fontset-font "fontset-startup" 'Chinese-GBK (font-spec: Family "wenquanyi micron black") Nil 'prepend)
)
) T
)
Color-theme.el

Where can I write my own configuration information? Let's see "= ~ Files in the/Shell/config/Emacs. init = "Directory

Code

2 : 2023 : 13:03:26 : ~/Shell/config/emacs.init 
dove@bash-4.1$ du -sh *.el
8.0K calendar-setup.el
28K color-theme.el
28K dove-ext.el
4.0K keybindings.el
8.0K org-mode.el
8.0K plugins.el
4.0K settings.el

2 : 2024 : 13:03:35 : ~/Shell/config/emacs.init
dove@bash-4.1$ du -sh .emacs
4.0K .emacs

2 : 2025 : 13:04:07 : ~/Shell/config/emacs.init
dove@bash-4.1$

That's all. The role of each file is clearly indicated by the file name. Only this "= dove-ext.el =" file needs to be explained, where it stores all the extended functions I write myself.

 

Let's take a look at the contents of these files one by one. "= Calendar-setup.el =" don't say, this file is basically searched from the Internet, I am also defining a few festivals.

"= Color-theme.el =" is the topic settings file. Basically it is a flip of = color-theme-gnome2 =, I made some simple modifications. The reason why he exists in a separate file is that = color-theme = is too long, and the file in which he is put will affect other content.

Code

(Eval-when-compile (require 'color-theme ))

(Defun my-color-theme ()
"Color theme created 2010-04-09 ."
; (Interactive)
(Color-theme-install
'(My-color-theme
; (Background-color. "#102c29 ")
(Background-color. "darkslategrey ")
; (Background-color. "Black ")
(Background-mode. Dark)
(Border-color. "Black ")
(Cursor-color. "lightgray ")
...... Theme is too long and omitted in the middle
(Woman-bold-face (T (: bold T: weight bold ))))
(Woman-italic-face (T (: foreground "beige "))))
(Woman-unknown-face (T (: foreground "lightsalmon "))))
(Zmacs-region (T (: background "Dark cyan": foreground "cyan ")))))))

(Eval-when-compile (require 'color-theme ))
(Color-theme-Initialize)

(Add-hook 'after-make-frame-Functions
(Lambda (ARG)
""
(My-color-theme) T)

In addition, I made a processing when loading color-theme, and added = My-color-theme = to the hook = after-make-frame-functions =, in this way, = My-color-theme = is executed only when the frame is created. If the environment is not = x =, for example, when using = emacs-nw =, do not load = My-color-theme =. Because this topic is in terminal mode, the background color cannot be viewed at all ). Even though I always work in = x =.

 

Some solutions to this problem are found on the Internet to determine whether it is = Window-system =. This method will cause errors in the daemon mode. It seems that the configuration method in the daemon mode after Emacs 23 still needs to be further studied. Everything is put in = after-make-frame-functions =. After all, this is not a problem.

Settings. El

Next we will look at settings. El. The settings task is actually very simple, that is, setting global variables. The setting of global variables is = setq =. This is a simple task. However, countless = setq = values, whether written or read, are depressing. Fortunately, we remember that = setq = not only can we set a variable, but it can actually process a = List =. Hi, since it's okay, why keep him idle? Let's get started, write all the variables and values in a = List =, and delete all the extra = setq =.

Code

 (Menu-bar-mode-1)
(Tool-bar-mode-1)
(Icomplete-mode 1)
(Scroll-bar-mode-1)
; (Ruler-mode-1)

(Setq save-abbrevs t
X-select-enable-clipboard t
Ispell-Dictionary "English"
Frame-title-format "% B % N % I"
Inhibit-startup-message t
Column-number-mode t
There are too many contents, and the content is omitted in the middle.
Ido-toggle-Regexp t
Dim: Switch-window-relative Nil
Shell-file-name "/usr/bin/bash"
Default-Major-mode 'text-Mode
)

; Misc
(Setq-default abbrev-mode t
Line-spacing 4
)

(Setenv "emacsshell" shell-file-name)

 

To be continued ...... ......

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.