mirror of
https://gitlab.com/dwt1/dotfiles.git
synced 2026-04-22 02:50:24 +10:00
Updating Doom Emacs.
This commit is contained in:
@@ -6,33 +6,35 @@
|
||||
(defvar company-pcomplete-available 'unknown)
|
||||
|
||||
(defun company-pcomplete--prefix ()
|
||||
(let* ((pcomplete-stub)
|
||||
pcomplete-seen
|
||||
pcomplete-norm-func
|
||||
pcomplete-args
|
||||
pcomplete-last pcomplete-index
|
||||
(pcomplete-autolist pcomplete-autolist)
|
||||
(pcomplete-suffix-list pcomplete-suffix-list))
|
||||
(pcomplete-completions)
|
||||
(buffer-substring (pcomplete-begin) (point))))
|
||||
(with-no-warnings
|
||||
(let* ((pcomplete-stub)
|
||||
pcomplete-seen
|
||||
pcomplete-norm-func
|
||||
pcomplete-args
|
||||
pcomplete-last pcomplete-index
|
||||
(pcomplete-autolist pcomplete-autolist)
|
||||
(pcomplete-suffix-list pcomplete-suffix-list))
|
||||
(pcomplete-completions)
|
||||
(buffer-substring (pcomplete-begin) (point)))))
|
||||
|
||||
(defun company-pcomplete--candidates ()
|
||||
(let* ((pcomplete-stub)
|
||||
(pcomplete-show-list t)
|
||||
pcomplete-seen pcomplete-norm-func
|
||||
pcomplete-args pcomplete-last pcomplete-index
|
||||
(pcomplete-autolist pcomplete-autolist)
|
||||
(pcomplete-suffix-list pcomplete-suffix-list)
|
||||
(candidates (pcomplete-completions))
|
||||
(prefix (buffer-substring (pcomplete-begin) (point)))
|
||||
;; Collect all possible completions for the current stub
|
||||
(cnds (all-completions pcomplete-stub candidates))
|
||||
(bnds (completion-boundaries pcomplete-stub candidates nil ""))
|
||||
(skip (- (length pcomplete-stub) (car bnds))))
|
||||
;; Replace the stub at the beginning of each candidate by the prefix
|
||||
(mapcar (lambda (cand)
|
||||
(concat prefix (substring cand skip)))
|
||||
cnds)))
|
||||
(with-no-warnings
|
||||
(let* ((pcomplete-stub)
|
||||
(pcomplete-show-list t)
|
||||
pcomplete-seen pcomplete-norm-func
|
||||
pcomplete-args pcomplete-last pcomplete-index
|
||||
(pcomplete-autolist pcomplete-autolist)
|
||||
(pcomplete-suffix-list pcomplete-suffix-list)
|
||||
(candidates (pcomplete-completions))
|
||||
(prefix (buffer-substring (pcomplete-begin) (point)))
|
||||
;; Collect all possible completions for the current stub
|
||||
(cnds (all-completions pcomplete-stub candidates))
|
||||
(bnds (completion-boundaries pcomplete-stub candidates nil ""))
|
||||
(skip (- (length pcomplete-stub) (car bnds))))
|
||||
;; Replace the stub at the beginning of each candidate by the prefix
|
||||
(mapcar (lambda (cand)
|
||||
(concat prefix (substring cand skip)))
|
||||
cnds))))
|
||||
|
||||
;;;###autoload
|
||||
(defun company-pcomplete-available ()
|
||||
|
||||
@@ -21,13 +21,15 @@
|
||||
t))
|
||||
|
||||
(defun +eshell--bury-buffer (&optional dedicated-p)
|
||||
(unless (switch-to-prev-buffer nil 'bury)
|
||||
(switch-to-buffer (doom-fallback-buffer)))
|
||||
(when (eq major-mode 'eshell-mode)
|
||||
(switch-to-buffer (doom-fallback-buffer)))
|
||||
(when +eshell-enable-new-shell-on-split
|
||||
(when-let (win (get-buffer-window (+eshell/here)))
|
||||
(set-window-dedicated-p win dedicated-p))))
|
||||
(let ((directory default-directory))
|
||||
(unless (switch-to-prev-buffer nil 'bury)
|
||||
(switch-to-buffer (doom-fallback-buffer)))
|
||||
(when (eq major-mode 'eshell-mode)
|
||||
(switch-to-buffer (doom-fallback-buffer)))
|
||||
(when +eshell-enable-new-shell-on-split
|
||||
(let ((default-directory directory))
|
||||
(when-let (win (get-buffer-window (+eshell/here t)))
|
||||
(set-window-dedicated-p win dedicated-p))))))
|
||||
|
||||
(defun +eshell--setup-window (window &optional flag)
|
||||
(when (window-live-p window)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"TODO"
|
||||
(interactive "<fsh><!>")
|
||||
(let ((buffer (+eshell-last-buffer))
|
||||
(command (+evil-resolve-vim-path-a command)))
|
||||
(command (+evil-replace-filename-modifiers-a command)))
|
||||
(cond (buffer
|
||||
(select-window (get-buffer-window buffer))
|
||||
(+eshell-run-command command buffer))
|
||||
|
||||
@@ -12,11 +12,16 @@
|
||||
|
||||
|
||||
(defun +eshell--current-git-branch ()
|
||||
;; TODO Refactor me
|
||||
(cl-destructuring-bind (status . output)
|
||||
(doom-call-process "git" "name-rev" "--name-only" "HEAD")
|
||||
(doom-call-process "git" "symbolic-ref" "-q" "--short" "HEAD")
|
||||
(if (equal status 0)
|
||||
(format " [%s]" output)
|
||||
"")))
|
||||
(cl-destructuring-bind (status . output)
|
||||
(doom-call-process "git" "describe" "--all" "--always" "HEAD")
|
||||
(if (equal status 0)
|
||||
(format " [%s]" output)
|
||||
"")))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +eshell-default-prompt-fn ()
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
"Where to store eshell configuration files, as opposed to
|
||||
`eshell-directory-name', which is where Doom will store temporary/data files.")
|
||||
|
||||
(defvar eshell-directory-name (concat doom-etc-dir "eshell")
|
||||
"Where to store temporary/data files, as opposed to `eshell-config-dir',
|
||||
which is where Doom will store eshell configuration files.")
|
||||
|
||||
(defvar +eshell-enable-new-shell-on-split t
|
||||
"If non-nil, spawn a new eshell session after splitting from an eshell
|
||||
buffer.")
|
||||
@@ -22,11 +26,13 @@ buffer.")
|
||||
(defvar +eshell-aliases
|
||||
'(("q" "exit") ; built-in
|
||||
("f" "find-file $1")
|
||||
("ff" "find-file $1")
|
||||
("d" "dired $1")
|
||||
("bd" "eshell-up $1")
|
||||
("rg" "rg --color=always $*")
|
||||
("l" "ls -lh")
|
||||
("ll" "ls -lah")
|
||||
("l" "ls -lh $*")
|
||||
("ll" "ls -lah $*")
|
||||
("gg" "magit-status")
|
||||
("clear" "clear-scrollback")) ; more sensible than default
|
||||
"An alist of default eshell aliases, meant to emulate useful shell utilities,
|
||||
like fasd and bd. Note that you may overwrite these in your
|
||||
@@ -35,20 +41,16 @@ to define your aliases.
|
||||
|
||||
You should use `set-eshell-alias!' to change this.")
|
||||
|
||||
;;
|
||||
(defvar eshell-directory-name (concat doom-etc-dir "eshell"))
|
||||
|
||||
;; These files are exceptions, because they may contain configuration
|
||||
(defvar eshell-aliases-file (concat +eshell-config-dir "aliases"))
|
||||
(defvar eshell-rc-script (concat +eshell-config-dir "profile"))
|
||||
(defvar eshell-login-script (concat +eshell-config-dir "login"))
|
||||
|
||||
|
||||
(defvar +eshell--default-aliases nil)
|
||||
|
||||
|
||||
;;
|
||||
;; Packages
|
||||
;;; Packages
|
||||
|
||||
(after! eshell ; built-in
|
||||
(setq eshell-banner-message
|
||||
@@ -116,10 +118,6 @@ You should use `set-eshell-alias!' to change this.")
|
||||
(append eshell-command-aliases-list
|
||||
+eshell-aliases))))
|
||||
|
||||
(when (featurep! :editor evil +everywhere)
|
||||
(advice-add #'evil-collection-eshell-next-prompt-on-insert
|
||||
:override #'+eshell-goto-prompt-on-insert-a))
|
||||
|
||||
(add-hook! 'eshell-first-time-mode-hook
|
||||
(defun +eshell-init-keymap-h ()
|
||||
;; Keys must be bound in a hook because eshell resets its keymap every
|
||||
@@ -132,9 +130,13 @@ You should use `set-eshell-alias!' to change this.")
|
||||
:n "C" #'+eshell/evil-change-line
|
||||
:n "d" #'+eshell/evil-delete
|
||||
:n "D" #'+eshell/evil-delete-line
|
||||
:ni "C-j" #'eshell-next-matching-input-from-input
|
||||
:ni "C-k" #'eshell-previous-matching-input-from-input
|
||||
:ig "C-d" #'+eshell/quit-or-delete-char
|
||||
"TAB" #'+eshell/pcomplete
|
||||
[tab] #'+eshell/pcomplete
|
||||
:i "C-c h" #'evil-window-left
|
||||
:i "C-c j" #'evil-window-down
|
||||
:i "C-c k" #'evil-window-up
|
||||
:i "C-c l" #'evil-window-right
|
||||
"C-s" #'+eshell/search-history
|
||||
;; Emacs bindings
|
||||
"C-e" #'end-of-line
|
||||
@@ -142,24 +144,17 @@ You should use `set-eshell-alias!' to change this.")
|
||||
"C-c s" #'+eshell/split-below
|
||||
"C-c v" #'+eshell/split-right
|
||||
"C-c x" #'+eshell/kill-and-close
|
||||
"C-c h" #'windmove-left
|
||||
"C-c j" #'windmove-down
|
||||
"C-c k" #'windmove-up
|
||||
"C-c l" #'windmove-right
|
||||
[remap split-window-below] #'+eshell/split-below
|
||||
[remap split-window-right] #'+eshell/split-right
|
||||
[remap doom/backward-to-bol-or-indent] #'eshell-bol
|
||||
[remap doom/backward-kill-to-bol-and-indent] #'eshell-kill-input
|
||||
[remap evil-delete-back-to-indentation] #'eshell-kill-input
|
||||
[remap evil-window-split] #'+eshell/split-below
|
||||
[remap evil-window-vsplit] #'+eshell/split-right)))
|
||||
(add-hook! 'eshell-mode-hook
|
||||
(defun +eshell-init-company-h ()
|
||||
(when (featurep! :completion company)
|
||||
(company-mode +1)
|
||||
(setq-local company-backends '(company-pcomplete))
|
||||
(setq-local company-frontends (cons 'company-tng-frontend company-frontends))
|
||||
(when (bound-and-true-p evil-local-mode)
|
||||
(evil-normalize-keymaps))))))
|
||||
[remap evil-window-vsplit] #'+eshell/split-right
|
||||
(:localleader
|
||||
"b" #'eshell-insert-buffer-name
|
||||
"e" #'eshell-insert-envvar
|
||||
"s" #'+eshell/search-history)))))
|
||||
|
||||
|
||||
(use-package! eshell-up
|
||||
@@ -178,3 +173,28 @@ You should use `set-eshell-alias!' to change this.")
|
||||
(use-package! esh-help
|
||||
:after eshell
|
||||
:config (setup-esh-help-eldoc))
|
||||
|
||||
|
||||
(use-package! eshell-did-you-mean
|
||||
:after esh-mode ; Specifically esh-mode, not eshell
|
||||
:config
|
||||
(eshell-did-you-mean-setup)
|
||||
;; HACK There is a known issue with `eshell-did-you-mean' where it does not
|
||||
;; work on first invocation, so we invoke it once manually by setting the
|
||||
;; last command and then calling the output filter.
|
||||
(setq eshell-last-command-name "catt")
|
||||
(eshell-did-you-mean-output-filter "catt: command not found"))
|
||||
|
||||
|
||||
(use-package! fish-completion
|
||||
:unless IS-WINDOWS
|
||||
:hook (eshell-mode . fish-completion-mode)
|
||||
:init (setq fish-completion-fallback-on-bash-p t)
|
||||
:config
|
||||
;; HACK Even with `fish-completion-fallback-on-bash-p' non-nil,
|
||||
;; `fish-completion--list-completions-with-desc' will throw an error if
|
||||
;; fish isn't installed (and so, will fail to fall back to bash), so we
|
||||
;; advise it to fail silently.
|
||||
(defadvice! +eshell--fallback-to-bash-a (&rest _)
|
||||
:before-until #'fish-completion--list-completions-with-desc
|
||||
(unless (executable-find "fish") "")))
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; term/eshell/packages.el
|
||||
|
||||
(package! eshell-up)
|
||||
(package! eshell-z)
|
||||
(package! shrink-path)
|
||||
(package! esh-help)
|
||||
(package! eshell-up :pin "9c100bae5c3020e8d9307e4332d3b64e7dc28519")
|
||||
(package! eshell-z :pin "337cb241e17bd472bd3677ff166a0800f684213c")
|
||||
(package! shrink-path :pin "c14882c8599aec79a6e8ef2d06454254bb3e1e41")
|
||||
(package! esh-help :pin "417673ed18a983930a66a6692dbfb288a995cb80")
|
||||
(package! eshell-did-you-mean :pin "7cb6ef8e2274d0a50a9e114d412307a6543533d5")
|
||||
|
||||
(unless IS-WINDOWS
|
||||
(when (featurep! :completion company)
|
||||
(package! fish-completion :pin "10384881817b5ae38cf6197a077a663420090d2c")
|
||||
(package! bash-completion :pin "96ce14af9674f3e605bacca87abc0c23b8f13cd5")))
|
||||
|
||||
@@ -41,6 +41,18 @@ prompt."
|
||||
(when (memq (process-status process) '(exit stop))
|
||||
(kill-buffer (process-buffer process))))
|
||||
|
||||
(defun +shell--send-input (buffer input &optional no-newline)
|
||||
(when input
|
||||
(with-current-buffer buffer
|
||||
(unless (number-or-marker-p (cdr comint-last-prompt))
|
||||
(message "Waiting for shell to start up...")
|
||||
(while (not (number-or-marker-p (cdr comint-last-prompt)))
|
||||
(sleep-for 0.1)))
|
||||
(goto-char (cdr comint-last-prompt))
|
||||
(delete-region (cdr comint-last-prompt) (point-max))
|
||||
(insert input)
|
||||
(comint-send-input no-newline))))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun +shell/toggle (&optional command)
|
||||
@@ -69,12 +81,11 @@ If popup is focused, kill it."
|
||||
(with-current-buffer (pop-to-buffer buffer)
|
||||
(if (not (eq major-mode 'shell-mode))
|
||||
(shell buffer)
|
||||
(run-mode-hooks 'shell-mode-hook)
|
||||
(cd dir))
|
||||
(let ((process (get-buffer-process (current-buffer))))
|
||||
(set-process-sentinel process #'+shell--sentinel)
|
||||
(when command
|
||||
(comint-send-string process command)))))))
|
||||
(cd dir)
|
||||
(run-mode-hooks 'shell-mode-hook))))
|
||||
(when-let (process (get-buffer-process buffer))
|
||||
(set-process-sentinel process #'+shell--sentinel)
|
||||
(+shell--send-input buffer command))))
|
||||
|
||||
;;;###autoload
|
||||
(defun +shell/here (&optional command)
|
||||
@@ -85,14 +96,12 @@ If already in a shell buffer, clear it and cd into the current directory."
|
||||
(let ((buffer (+shell-unused-buffer))
|
||||
(dir default-directory))
|
||||
(with-current-buffer (switch-to-buffer buffer)
|
||||
(if (not (eq major-mode 'shell-mode))
|
||||
(shell buffer)
|
||||
(erase-buffer)
|
||||
(cd dir))
|
||||
(let ((process (get-buffer-process (current-buffer))))
|
||||
(if (eq major-mode 'shell-mode)
|
||||
(+shell--send-input buffer (format "cd %S" dir))
|
||||
(shell buffer))
|
||||
(let ((process (get-buffer-process buffer)))
|
||||
(set-process-sentinel process #'+shell--sentinel)
|
||||
(when command
|
||||
(comint-send-string process command))))
|
||||
(+shell--send-input buffer command)))
|
||||
buffer))
|
||||
|
||||
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
|
||||
;;;###package multi-term
|
||||
(setq multi-term-dedicated-window-height 20
|
||||
multi-term-switch-after-close 'PREVIOUS)
|
||||
multi-term-switch-after-close 'PREVIOUS
|
||||
multi-term-buffer-name "doom:terminal")
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
;;; term/term/packages.el
|
||||
|
||||
(package! term :built-in t)
|
||||
(package! multi-term)
|
||||
(package! multi-term :pin "7307ddd456db44045206253e5a905d3d8c143d5c")
|
||||
|
||||
@@ -88,6 +88,13 @@ 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.
|
||||
|
||||
Modify ~vterm-module-cmake-args~ to pass arguments to the cmake build script.
|
||||
e.g. To use a local build of libvterm instead of the included one.
|
||||
|
||||
#+BEGIN_SRC elisp
|
||||
(setq vterm-module-cmake-args "-DUSE_SYSTEM_LIBVTERM=yes")
|
||||
#+END_SRC
|
||||
|
||||
*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
|
||||
|
||||
@@ -29,13 +29,12 @@ If prefix ARG is non-nil, recreate vterm buffer in the current project's root."
|
||||
(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)))
|
||||
(vterm-mode))
|
||||
(+vterm--change-directory-if-remote))
|
||||
(pop-to-buffer buffer)))))
|
||||
|
||||
;;;###autoload
|
||||
@@ -50,8 +49,44 @@ If prefix ARG is non-nil, cd into `default-directory' instead of project root."
|
||||
;; 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)))
|
||||
(let* ((project-root (or (doom-project-root) default-directory))
|
||||
(default-directory
|
||||
(if arg
|
||||
default-directory
|
||||
project-root))
|
||||
display-buffer-alist)
|
||||
(setenv "PROOT" project-root)
|
||||
(vterm)
|
||||
(+vterm--change-directory-if-remote)))
|
||||
|
||||
(defun +vterm--change-directory-if-remote ()
|
||||
"When `default-directory` is remote, use the corresponding
|
||||
method to prepare vterm at the corresponding remote directory."
|
||||
(when (and (featurep 'tramp)
|
||||
(tramp-tramp-file-p default-directory))
|
||||
(message "default-directory is %s" default-directory)
|
||||
(with-parsed-tramp-file-name default-directory path
|
||||
(let ((method (cadr (assoc `tramp-login-program
|
||||
(assoc path-method tramp-methods)))))
|
||||
(vterm-send-string
|
||||
(concat method " "
|
||||
(when path-user (concat path-user "@")) path-host))
|
||||
(vterm-send-return)
|
||||
(vterm-send-string
|
||||
(concat "cd " path-localname))
|
||||
(vterm-send-return)))))
|
||||
|
||||
|
||||
(defvar +vterm--insert-point nil)
|
||||
|
||||
;;;###autoload
|
||||
(defun +vterm-remember-insert-point-h ()
|
||||
"Remember point when leaving insert mode."
|
||||
(setq-local +vterm--insert-point (point)))
|
||||
|
||||
;;;###autoload
|
||||
(defun +vterm-goto-insert-point-h ()
|
||||
"Go to the point we were at when we left insert mode."
|
||||
(when +vterm--insert-point
|
||||
(goto-char +vterm--insert-point)
|
||||
(setq-local +vterm--insert-point nil)))
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
;;; term/vterm/config.el -*- lexical-binding: t; -*-
|
||||
|
||||
(use-package! vterm
|
||||
:when module-file-suffix
|
||||
:defer t
|
||||
:preface (setq vterm-install t)
|
||||
:when (bound-and-true-p module-file-suffix)
|
||||
:commands vterm vterm-mode
|
||||
:preface (setq vterm-install t) ; compile the package when you load vterm
|
||||
:hook (vterm-mode . doom-mark-buffer-as-real-h)
|
||||
:hook (vterm-mode . hide-mode-line-mode) ; modeline serves no purpose in vterm
|
||||
: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))
|
||||
;; Once vterm is dead, the vterm buffer is useless. Why keep it around? We can
|
||||
;; spawn another if want one.
|
||||
(setq vterm-kill-buffer-on-exit t)
|
||||
|
||||
(setq-hook! 'vterm-mode-hook
|
||||
;; Don't prompt about dying processes when killing vterm
|
||||
confirm-kill-processes nil
|
||||
;; Prevent premature horizontal scrolling
|
||||
hscroll-margin 0)
|
||||
|
||||
;; Restore the point's location when leaving and re-entering insert mode.
|
||||
(when (featurep! :editor evil)
|
||||
(add-hook! 'vterm-mode-hook
|
||||
(defun +vterm-init-remember-point-h ()
|
||||
(add-hook 'evil-insert-state-exit-hook #'+vterm-remember-insert-point-h nil t)
|
||||
(add-hook 'evil-insert-state-entry-hook #'+vterm-goto-insert-point-h nil t)))))
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
;; -*- no-byte-compile: t; -*-
|
||||
;;; term/vterm/packages.el
|
||||
|
||||
(package! vterm :built-in 'prefer)
|
||||
(package! vterm
|
||||
:built-in 'prefer
|
||||
:pin "422ffe029b92c47e4acf0e2ed06cbc83636d7e44")
|
||||
|
||||
Reference in New Issue
Block a user