wiki:Freelancing/Emacs

Emacs

Emacs is a lisp machine (a byte-code interpreter) which happens to have a few layers of DLSs for editing text.

Learning, using and customizing Emacs is the practice of problem solving using the right principles, the right language and right aesthetics. Emacs is classy as fuck.

Aside from that there are packages: python-mode, cc-mode, rust-mode, org-mode and pdf-tools, which eliminate some of suffering inherent in mundane programming tasks.

see also Emacs

Bootstrapping

Getting the sources.

git clone --depth=1 https://git.savannah.gnu.org/git/emacs.git

Some hardening.

export CFLAGS="-Wformat -Wformat-security -Werror=format-security \
    -Wstack-protector -fstack-protector-all --param ssp-buffer-size=1 \
    -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
    -fPIE \
    -fno-omit-frame-pointer \
    -Wstrict-aliasing=2 -fno-strict-aliasing \
    -fasynchronous-unwind-tables \
    -m64 -D_FILE_OFFSET_BITS=64 \
    -pthread -D_REENTRANT \
    -march=native -mtune=native -O3 \
    -fopenmp=libomp \
    -ffunction-sections -fdata-sections \
    -I/usr/local/include"
export LDFLAGS="-L/usr/local/lib \
    -pthread \
    -rtlib=compiler-rt \
    -fopenmp=libomp \
    -lm \
    -fPIE -pie \
    -Wl,--gc-sections -Wl,--as-needed \
    -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"

Compiling

cd emacs
./autogen.sh
mkdir build
cd build
../configure --prefix=/usr/local \
    --with-wide-int \
    --with-xft \
    --with-xim \
    --with-x \
    --with-x-toolkit=gtk3 \
    --with-xwidgets

make -s -j3 bootstrap
sudo make -s install

Essential configuration

Do not install ready-made configs, like Doom-emacs or Centaur or whatever. Get the understanding first, then look how they did it.

Notice how declarative instead of imperative approach works in practice.

(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)

(add-to-list 'default-frame-alist '(fullscreen . maximized))

(setq inhibit-startup-screen t)
(setq initial-scratch-message "")

(setq initial-major-mode 'emacs-lisp-mode)

(setq-default font-lock-maximum-decoration t)

(set-frame-font "SF Mono Light 16" t t)

(eval-when-compile
  (require 'package)
  (add-to-list 'package-archives
               '("melpa" . "https://melpa.org/packages/") t)
  (setq package-user-dir (expand-file-name "elpa" user-emacs-directory))
  (package-initialize))

(setq load-prefer-newer t
      package-enable-at-startup nil)

(eval-when-compile
  (unless (package-installed-p 'use-package)
    (package-refresh-contents)
    (package-install 'use-package)
    (package-install 'diminish)))

(require 'diminish)                ;; if you use :diminish
(require 'bind-key)                ;; if you use any :bind variant

(require 'use-package)

(setq use-package-always-defer nil
      use-package-always-ensure nil)

(use-package solarized-theme
  :ensure t
  :config
  (setq solarized-use-variable-pitch nil)
  :init
  (load-theme 'solarized-dark t))

(use-package guru-mode
  :ensure t
  :diminish (guru-mode)
  :config
  (guru-global-mode t))

(use-package which-key
  :ensure t
  :diminish (which-key-mode)
  :config
  (which-key-mode t))

Packages

Essential packages

parenthesis

(use-package smartparens
  :ensure t
  :diminish (smartparens-mode)
  :config
  (smartparens-global-mode t))
(use-package rainbow-delimiters
  :ensure t
  :config
  (rainbow-delimiters-mode t))

eldoc

Documentation (built-in package)

(use-package eldoc
  :diminish (eldoc-mode)
  :config
  (eldoc-mode t))

flycheck

Linters

(use-package flycheck
  :ensure t
  :config
  (global-flycheck-mode t))

company

Completions

(use-package company
  :ensure t
  :diminish (company-mode)
  :config
  (global-company-mode t))

LSP

(use-package lsp-mode
  :ensure t
  :hook (programming-mode . lsp)
  :config
  (setq lsp-prefer-flymake nil)
  (setq lsp-auto-guess-root t)
  (setq lsp-keep-workspace-alive nil)
  (require 'lsp)
  (require 'lsp-clients)
  (add-hook 'programming-mode-hook 'lsp)
  (add-hook 'lsp-after-open-hook 'lsp-enable-imenu))

(use-package lsp-ui
  :ensure t
  :after lsp
  :hook (lsp-mode . lsp-ui-mode)
  :config
  (setq lsp-ui-sideline-enable t)
  (setq lsp-ui-doc-enable t)
  (setq lsp-ui-peek-enable t)
  (setq lsp-ui-peek-always-show t))
(use-package company-lsp
  :ensure t
  :after company lsp-mode
  :config
  (push 'company-lsp company-backends))
Last modified 6 months ago Last modified on Aug 31, 2019, 3:11:06 AM
Note: See TracWiki for help on using the wiki.