Moving to Doom Emacs!

This commit is contained in:
Derek Taylor
2019-12-16 20:21:19 -06:00
parent d9f2f456f1
commit d4b4c33550
683 changed files with 51877 additions and 100 deletions

View File

@@ -0,0 +1,108 @@
#+TITLE: term/vterm
#+DATE: January 16, 2019
#+SINCE: 2.1
#+STARTUP: inlineimages
* Table of Contents :TOC_3:noexport:
- [[#description][Description]]
- [[#module-flags][Module Flags]]
- [[#plugins][Plugins]]
- [[#prerequisites][Prerequisites]]
- [[#dynamic-module-support][Dynamic Module support]]
- [[#libvterm][libvterm]]
- [[#compilation-tools-for-vterm-moduleso][Compilation tools for vterm-module.so]]
* Description
This module provides a terminal emulator powered by libvterm. It is still in
alpha and requires a component be compiled (=vterm-module.sh=).
The following commands are available to open it:
+ ~+vterm/toggle~ (=SPC o t=): Toggle vterm pop up window in the current project
+ ~+vterm/here~ (=SPC o T=): Opens vterm in the current window
** Module Flags
This module provides no flags.
** Plugins
+ [[https://github.com/akermu/emacs-libvterm][vterm]]
* Prerequisites
+ Emacs must be built with dynamic module support, i.e. compiled with the
=--with-modules= option.
+ You need =libvterm= installed on your system.
+ You need =make=, =cmake= and a C compiler such as =gcc= so that vterm can
build =vterm-module.so=.
** Dynamic Module support
To check if your build of Emacs was built with dynamic module support, check
~bin/doom info~ for ~MODULES~ next to "System features". If it's there, you're
good to go.
You can also check for =--with-modules= in the ~system-configuration-options~
variable (=SPC h v system-configuration-options=).
- Archlinux or Manjaro users who installed Emacs through pacman will have
support baked in.
- MacOS users:
- If you use [[https://emacsformacosx.com/][Emacs For Mac OS X]], this option is enabled.
- If you use [[https://github.com/d12frosted/homebrew-emacs-plus][emacs-plus]], this option is enabled by default.
- If you use [[https://github.com/railwaycat/homebrew-emacsmacport][emacs-mac]], this options is *not* enabled by default. You may have
to reinstall emacs with the option: ~brew install emacs-mac --with-modules~
** libvterm
+ Ubuntu or Debian users: ~apt-get install libvterm-dev~
+ ArchLinux or Manjaro: ~pacman -S libvterm~
+ MacOS: ~libvterm~
+ NixOS:
#+BEGIN_SRC nix
systemPackages = with pkgs; [
# emacs # no need for this, the next line includes emacs
((emacsPackagesNgGen emacs).emacsWithPackages (epkgs: [
epkgs.emacs-libvterm
]))
];
#+END_SRC
Or for home-manager users:
#+BEGIN_SRC nix
programs.emacs = {
enable = true;
extraPackages = epkgs: [ epkgs.emacs-libvterm ];
};
#+END_SRC
** Compilation tools for vterm-module.so
When you first load vterm, it will compile =vterm-module.so= for you. For this
to succeed, you need the following:
+ =make=
+ =cmake=
+ A C compiler like =gcc=
+ An internet connection (=cmake= will download needed libraries)
There are several ways to manually install the module:
1. You can use =M-x vterm-module-compile= to let emacs automatically compile and
install the module.
*WARNING*: Emacs will hang during the compilation. It may take a while.
2. You can compile and install the module yourself. Go to the vterm installation
directory (usually =~/.emacs.d/.local/packages/elpa/vterm-<version>=) and run
the following:
#+BEGIN_SRC sh
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make
#+END_SRC
3. You can also compile =vterm-module.sh= elsewhere, but the module must be
moved/symlinked to
=~/.emacs.d/.local/packages/elpa/vterm-<version>/vterm-module.so=
=vterm-module.so=. Keep in mind that this folder will be deleted whenever the
vterm package is updated.

View File

@@ -0,0 +1,57 @@
;;; term/vterm/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +vterm/toggle (arg)
"Toggles a terminal popup window at project root.
If prefix ARG is non-nil, recreate vterm buffer in the current project's root."
(interactive "P")
(unless (fboundp 'module-load)
(user-error "Your build of Emacs lacks dynamic modules support and cannot load vterm"))
(let ((buffer-name
(format "*doom:vterm-popup:%s*"
(if (bound-and-true-p persp-mode)
(safe-persp-name (get-current-persp))
"main")))
confirm-kill-processes
current-prefix-arg)
(when arg
(let ((buffer (get-buffer buffer-name))
(window (get-buffer-window buffer-name)))
(when (buffer-live-p buffer)
(kill-buffer buffer))
(when (window-live-p window)
(delete-window window))))
(if-let (win (get-buffer-window buffer-name))
(if (eq (selected-window) win)
(delete-window win)
(select-window win)
(when (bound-and-true-p evil-local-mode)
(evil-change-to-initial-state))
(goto-char (point-max)))
(require 'vterm)
(setenv "PROOT" (or (doom-project-root) default-directory))
(let ((buffer (get-buffer-create buffer-name)))
(with-current-buffer buffer
(doom-mark-buffer-as-real-h)
(unless (eq major-mode 'vterm-mode)
(vterm-mode)))
(pop-to-buffer buffer)))))
;;;###autoload
(defun +vterm/here (arg)
"Open a terminal buffer in the current window at project root.
If prefix ARG is non-nil, cd into `default-directory' instead of project root."
(interactive "P")
(unless (fboundp 'module-load)
(user-error "Your build of Emacs lacks dynamic modules support and cannot load vterm"))
(require 'vterm)
;; This hack forces vterm to redraw, fixing strange artefacting in the tty.
(save-window-excursion
(pop-to-buffer "*scratch*"))
(let ((default-directory
(if arg
default-directory
(or (doom-project-root) default-directory))))
(vterm)))

View File

@@ -0,0 +1,18 @@
;;; term/vterm/config.el -*- lexical-binding: t; -*-
(use-package! vterm
:when module-file-suffix
:defer t
:preface (setq vterm-install t)
:config
(set-popup-rule! "^vterm" :size 0.25 :vslot -4 :select t :quit nil :ttl 0)
(add-hook 'vterm-mode-hook #'doom-mark-buffer-as-real-h)
;; Automatically kill buffer when vterm exits.
(add-hook! 'vterm-exit-functions
(defun +vterm-kill-buffer-on-quit-fn (buffer event)
(if buffer (kill-buffer buffer))))
;; Modeline serves no purpose in vterm
(add-hook 'vterm-mode-hook #'hide-mode-line-mode)
;; Don't prompt about processes when killing vterm
(setq-hook! 'vterm-mode-hook confirm-kill-processes nil))

View File

@@ -0,0 +1,13 @@
;;; term/vterm/doctor.el -*- lexical-binding: t; -*-
(unless (executable-find "vterm-ctrl")
(warn! "Couldn't find libvterm. Vterm module won't compile"))
(unless (executable-find "make")
(warn! "Couldn't find make command. Vterm module won't compile"))
(unless (executable-find "cmake")
(warn! "Couldn't find cmake command. Vterm module won't compile"))
(unless (fboundp 'module-load)
(warn! "Your emacs wasn't built with dynamic modules support. The vterm module won't build"))

View File

@@ -0,0 +1,4 @@
;; -*- no-byte-compile: t; -*-
;;; term/vterm/packages.el
(package! vterm :built-in 'prefer)