blog-public/content/post/gotovim-emacs.md
Denis Zheleztsov a5dd73f274 Initial public
Some content was deleted before this project
has been moved to public
2021-10-18 19:45:57 +03:00

3.1 KiB
Raw Blame History

+++ date = "2017-10-31T17:23:44+03:00" draft = true title = "Готовим конфиг GNU Emacs" tags = ["emacs"] comments = true +++

Часто конфигурационный файл GNU Emacs выглядит, как помойка - нагромождение копипасты и говнокода. Почти на каждую строчку ругается flycheck. Все очень плохо. Попробуем это исправить.

Итак. Создадим чистый ~/.emacs.d/init.el и сразу подключаем репозитории пакетов.

;;; init.el --- main emacs config
;;; Commentary:
;;; Code:

;; Packages
(require 'package) ;; You might already have this line
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
    (add-to-list 'package-archives (cons "melpa" url) t))
(when (< emacs-major-version 24)
    ;; For important compatibility libraries like cl-lib
    (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line

;;; init.el ends here

Следующим шагом скажем Gnu Emacs, чтобы он запускал сервер если работает на GNU/Linux или MacOS.

;; define system
(defun system-is-linux()
	(string-equal system-type "gnu/linux"))

(defun system-is-darwin()
    (string-equal system-type "darwin"))

;; Start Emacs as server. Linux and MacOS support
(when (or (system-is-linux) (system-is-darwin))
	(require 'server)
	(unless (server-running-p)
		(server-start)))

Прелесть в запуске сервера - мгновенное открытие новых окон емакс и шаринг буферов между ними. А теперь можно начать готовить красивый конфиг разделенный по назначению. Создаем файлы ~/.emacs.d/config/common/common.el, ~/.emacs.d/config/common/packages-config.el. В packages-config.el выносим код из init.el и оборачиваем в функцию. packages-config.el станет выглядеть примерно так:

;;; packages-config.el --- repo config
;;; COMMENTARY:
;;; Code:

(require 'package)

(defun configure-packages ()
    "Set MELPA and ELPA repositories."
    (let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                        (not (gnutls-available-p))))
           (url (concat (if no-ssl "http" "https") "://melpa.org/packages/")))
        (add-to-list 'package-archives (cons "melpa" url) t))
    (when (< emacs-major-version 24)
        ;; For important compatibility libraries like cl-lib
        (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
    (package-initialize))

(provide 'packages-config)

;;; packages-config.el ends here

В common.el пишем

;;; common.el --- base configuration
;;; COMMENTARY:
;;; Code:

(require 'packages-config)

(package-install "use-package")

(provide 'common)

;;; common.el ends here