wiki:Emacs

Emacs

Emacs is a big miracle of software engineering. Like the Nature itself, it has been evolved, not created.)

It is a programmable via DSLs embedded in Emacs Lisp editor.

It is definitely worth learning, to realize how simple and flexible large systems could be.


Sometimes it is good to have two versions of emacs on your Linux machine.

Here is how to produce a bare-bones, text-only version of Emacs to run it quickly in a terminal (it is very nice to use temacs in a Linux framebuffer console, especially with fbterm and Source Code Pro true-type font)

$ cd emacs
$ ./autogen.sh
$ mkdir build
$ cd build
$ export CC=gcc CXX=g++; ../configure --prefix=/usr/local --program-prefix=t --without-all --without-x --with-wide-int --with-xml2 && make -s bootstrap
$ sudo make -s install

Which will give you a slim binary that would look something like this

$ ldd `which temacs`
	linux-vdso.so.1 =>  (0x00007fffff368000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f15a0f5a000)
	libxml2.so.2 => /usr/lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f15a0bf4000)
	libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f15a09ca000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f15a07ac000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f15a04a6000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15a00e0000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f159fedc000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f159fcc3000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f159faa0000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f15a1183000)

We have libxml2 here because we want built-in eww browser for things like Common Lisp Hyperspec.

Now we could build a full-blown version from the same sources.

$ make -s maintainer-clean
$ export CC=gcc CXX=g++; ../configure --prefix=/usr/local  --with-x-toolkit=gtk3 --with-wide-int  && make -s bootstrap
$ sudo make -s install

which uses about 80 shared libs.)

$ ldd `which emacs` |wc -l
81

Here is my .emacs as a template. It is already stuffed with non-fundamental micro-optimizations, but this is what I have

;;; package --- initialization for emacs
;;; Commentary:
;;; Code:
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(set-selection-coding-system 'utf-8-unix)
(prefer-coding-system 'utf-8-unix)

(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
(setq select-enable-clipboard t)

(setq-default locale-coding-system 'utf-8-unix)
(setq-default buffer-file-coding-system 'utf-8-unix)

(when (fboundp 'menu-bar-mode) (menu-bar-mode -1))

(when (featurep 'windows-system)
  (progn
    (when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
    (when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
    (when (fboundp 'fringe-mode) (fringe-mode -1))
    (setq default-frame-alist
          '((wait-for-wm . nil)
            (top . 0)
            (width . 80)
            (tool-bar-lines . 0)
            (menu-bar-lines . 0)))
    (set-frame-font "-adobe-Source Code Pro-light-normal-normal-*-*-*-*-*-m-0-iso10646-1" nil t)))

(setq-default indent-tabs-mode nil)

(setq-default tab-width 4)
(setq-default fill-column 80)

(setq-default truncate-lines t)

(setq-default next-line-add-newlines nil)
(setq-default require-final-newline t)

(setq-default show-trailing-whitespace t)
(setq-default indicate-empty-lines t)

(setq-default transient-mark-mode t)
(transient-mark-mode t)

(setq-default kill-whole-line t)
;(delete-selection-mode t)

(setq-default default-directory "~")

(add-hook 'before-save-hook
          (lambda ()
            (untabify (point-min) (point-max))
            (delete-trailing-whitespace)))

(global-auto-revert-mode t)
(savehist-mode t)
(setq history-length 1000)
(recentf-mode t)
(setq recentf-max-saved-items 100)

(require 'whitespace)
(eval-after-load 'whitespace
  '(progn
     (setq whitespace-style '(face empty tabs trailing lines-tail))
     (setq whitespace-line-column 80)
     (global-whitespace-mode t)))

(require 'ispell)
(eval-after-load "ispell"
  '(progn
     (add-to-list 'ispell-extra-args "--sug-mode=ultra")
     (add-to-list 'ispell-extra-args "-C")
     (setq ispell-encoding-command "utf-8")
     (setq ispell-skip-html t)))

(require 'flyspell)
(eval-after-load "flyspell"
  '(progn
     (setq flyspell-issue-message-flag nil)
     (setq flyspell-large-region t)
     (setq flyspell-consider-dash-as-word-delimiter-flag t)
     (define-key flyspell-mode-map (kbd "C-.") nil)))

(require 'flyspell-lazy)
(eval-after-load 'flyspell-lazy
  '(progn
     (flyspell-lazy-mode t)))

(require 'undo-tree)
(eval-after-load 'undo-tree
  '(progn
     (setq undo-tree-mode-lighter "")
     (global-undo-tree-mode)))

(add-hook 'text-mode-hook
          (lambda ()
            (turn-on-auto-fill)
            (flyspell-mode t)))

(require 'ido)
(eval-after-load 'ido
  '(progn
     (setq ido-enable-flex-matching t)
     (setq ido-use-virtual-buffers t)
     (setq ido-use-filename-at-point 'guess)
     (setq ido-auto-merge-work-directories-length -1)
     (ido-mode t)))

(require 'ido-hacks)
(eval-after-load 'ido-hacks
  '(progn
     (setq ido-everywhere t)))

(require 'flx-ido)
(eval-after-load 'flx-ido
  '(progn
     (setq ido-use-faces nil)
     (setq flx-ido-mode t)))

(require 'ido-at-point)
(ido-at-point-mode)

(require 'ido-ubiquitous)
(ido-ubiquitous-mode t)

(require 'smex)
(defun smex-update-after-load (unused)
      (when (boundp 'smex-cache)
        (smex-update)))

(eval-after-load 'smex
  '(progn
     (smex-initialize)
     (add-hook 'after-load-functions 'smex-update-after-load)
     (global-set-key (kbd "M-x") 'smex)
     (global-set-key (kbd "M-X") 'smex-major-mode-commands)))

(require 'auto-complete)
(eval-after-load "auto-complete"
  '(progn
     (require 'auto-complete-config)
     (ac-config-default)
     (ac-flyspell-workaround)
     (define-globalized-minor-mode real-global-auto-complete-mode
       auto-complete-mode (lambda ()
                            (if (not (minibufferp (current-buffer)))
                                (auto-complete-mode t))
                            ))
     (real-global-auto-complete-mode t)))

(require 'smartparens-config)
(smartparens-global-mode t)
(show-smartparens-global-mode t)

(require 'rainbow-mode)

(require 'rainbow-delimiters)

(require 'eldoc)

(require 'flycheck)

(add-hook 'prog-mode-hook
          (lambda ()
            (untabify (point-min) (point-max))
            (rainbow-mode t)
            (rainbow-delimiters-mode t)
            (smartparens-strict-mode t)
            (turn-on-eldoc-mode)
            (flyspell-prog-mode)
            (global-flycheck-mode)
;            (global-set-key (kbd "RET")
;                            (lambda ()
;                              (interactive)
;                              (newline-and-indent)
;                              (indent-according-to-mode)))
            ))

(require 'elisp-slime-nav)
(dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
  (add-hook hook 'elisp-slime-nav-mode))

;(require 'tramp)
(eval-after-load "tramp"
  '(progn
     (setq tramp-default-method 'scp)
     (setq tramp-completion-without-shell-p t)
     (setq tramp-remote-process-environment ())
     (add-to-list 'tramp-remote-process-environment "LANGUAGE=en_US:en")
     (add-to-list 'tramp-remote-process-environment "LANG=en_US.UTF-8")
     (add-to-list 'tramp-remote-process-environment "LC_ALL=en_US.UTF-8")))

;(require 'xscheme)
;(setq inferior-scheme-program "/usr/local/bin/scheme")

(require 'geiser-install)
(eval-after-load 'geiser-install
  '(progn
     (setq geiser-active-implementations '(racket))
     (setq geiser-impl-installed-implementations '(racket))
     (setq geiser-racket-binary "/opt/plt/racket/bin/racket")))

(require 'ac-geiser)
(eval-after-load 'ac-geiser
  '(progn
       (add-hook 'geiser-mode-hook 'ac-geiser-setup)
       (add-hook 'geiser-repl-mode-hook 'ac-geiser-setup)))

(eval-after-load "auto-complete"
  '(add-to-list 'ac-modes 'geiser-repl-mode))

(add-hook 'scheme-mode-hook
          (lambda ()
            (geiser-mode t)))

(require 'slime)
(eval-after-load 'slime
  '(progn
;     (setq inferior-lisp-program "/opt/cmucl/bin/lisp")
;     (setq inferior-lisp-program "/opt/ccl/ccl64 -K utf-8")
     (setq inferior-lisp-program "/usr/local/bin/sbcl")
     (setq slime-net-coding-system 'utf-8-unix)
     (setq slime-repl-history-remove-duplicates t)
     (setq slime-repl-history-trim-whitespaces t)
     (slime-setup '(slime-fancy slime-repl))))

(require 'ac-slime)
(eval-after-load 'ac-slime
  '(progn
     (add-hook 'slime-mode-hook 'set-up-slime-ac)
     (add-hook 'slime-repl-mode-hook 'set-up-slime-ac)))

(eval-after-load "auto-complete"
  '(add-to-list 'ac-modes 'slime-repl-mode))

(add-hook 'lisp-mode-hook
          (lambda ()
            (setq lisp-indent-function 'common-lisp-indent-function)
            (slime-mode t)))

(add-hook 'inferior-lisp-mode-hook
          (lambda ()
            (inferior-slime-mode t)))

(require 'haskell-mode-autoloads)
(eval-after-load 'haskell-mode
  '(progn
     (require 'hi2)
     (define-key haskell-mode-map (kbd "SPC") 'haskell-mode-contextual-space)
     (define-key haskell-mode-map (kbd "C-c C-o") 'haskell-compile)
     (define-key haskell-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)))

(eval-after-load 'haskell-cabal
  '(progn
     (define-key haskell-cabal-mode-map (kbd "C-c C-o") 'haskell-compile)
     (define-key haskell-cabal-mode-map (kbd "C-c C-z") 'haskell-interactive-switch)))

(add-hook 'haskell-mode-hook
          (lambda ()
            (custom-set-variables
             '(haskell-process-type 'cabal-repl)
             '(haskell-process-suggest-remove-import-lines t)
             '(haskell-process-auto-import-loaded-modules t)
             '(haskell-process-log t))
            (turn-on-haskell-indentation)
            (turn-on-haskell-doc-mode)
            (turn-on-hi2)))

(add-to-list 'auto-mode-alist '("\\.hs?$" . haskell-mode))
(add-to-list 'auto-mode-alist '("\\.lhs?$" . haskell-mode))

(setq erlang-root-dir "/usr/local/lib/erlang")
(add-to-list 'load-path "/usr/local/lib/erlang/lib/tools-2.7/emacs")
(add-to-list 'exec-path "/usr/local/lib/erlang/bin")
(require 'erlang-start)

(add-to-list 'load-path "/usr/local/share/distel/elisp")
(require 'distel)

(eval-after-load 'distel
  '(progn
     (distel-setup)
     (defconst distel-shell-keys
       '(("\C-\M-i"   erl-complete)
         ("\M-?"      erl-complete)
         ("\M-."      erl-find-source-under-point)
         ("\M-,"      erl-find-source-unwind)
         ("\M-*"      erl-find-source-unwind)
         )
       "Additional keys to bind when in Erlang shell.")
     (add-hook 'erlang-shell-mode-hook
               (lambda ()
                 (dolist (spec distel-shell-keys)
                   (define-key erlang-shell-mode-map (car spec) (cadr spec)))))
     ))

(add-to-list 'auto-mode-alist '("\\.erl?$" . erlang-mode))
(add-to-list 'auto-mode-alist '("\\.hrl?$" . erlang-mode))

(setq inferior-sml-program "/usr/bin/sml")
(require 'sml-mode)

;(defvar *eli-directory*)
;(setq *eli-directory* (expand-file-name "/opt/acl90express/eli/"))

;(when (and (not (string-match "xemacs" emacs-version))
;           (= emacs-major-version 20)
;           (<= emacs-minor-version 2))
;  (setq load-path (cons *eli-directory* load-path)))

;(load (format "%sfi-site-init" *eli-directory*))

(unless (featurep 'libxml2)
  '(progn
     (require 'w3m-load)
     (require 'w3m)
     (setq w3m-coding-system 'utf-8-unix
           w3m-file-coding-system 'utf-8-unix
           w3m-file-name-coding-system 'utf-8-unix
           w3m-input-coding-system 'utf-8-unix
           w3m-output-coding-system 'utf-8-unix
           w3m-terminal-coding-system 'utf-8-unix
           w3m-use-cookies t)
     (setq browse-url-browser-function 'w3m-browse-url)))

(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.
 '(auto-fill-mode t)
 '(column-number-mode t)
 '(compilation-scroll-output t)
 '(current-language-environment "UTF-8")
 '(font-use-system-font t)
 '(fringe-mode 0 nil (fringe))
 '(inhibit-startup-screen t)
 '(scroll-bar-mode nil)
 '(show-paren-mode t)
 '(tool-bar-mode nil)
 '(visible-bell nil))
(custom-set-faces
 ;; custom-set-faces 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.
 )
;;; .emacs ends here
Last modified 6 years ago Last modified on Nov 14, 2014, 2:04:05 PM
Note: See TracWiki for help on using the wiki.