diff --git a/init.el b/init.el index 971bcbd..e084ecb 100644 --- a/init.el +++ b/init.el @@ -218,6 +218,13 @@ Apply OLDFUN with to ARGS." ;; Make cursor more visible (global-hl-line-mode 1) +(defun my/locally-disable-hl-line () + "Disable `global-hl-line-mode' in the current buffer." + (when (bound-and-true-p global-hl-line-mode) + (setq-local global-hl-line-mode nil) + (face-remap-add-relative 'line-number-current-line 'line-number)) + (when (bound-and-true-p hl-line-mode) + (hl-line-mode -1))) (blink-cursor-mode -1) ;; Enable all disabled stuff @@ -2995,23 +3002,41 @@ Actually, return the method name." (use-package vterm :bind (("C-c V" . my/project-vterm-or-default) :map vterm-mode-map - ("C-w" . evil-window-map)) + ("C-w" . evil-window-map) + ("M-:" . eval-expression)) :hook ((vterm-mode . my/-setup-vterm-mode) (vterm-copy-mode . my/-setup-vterm-copy-mode)) :custom (vterm-kill-buffer-on-exit nil) :config - ;; disable `evil--sw-refresh-cursor' in vterm buffers - (defun my/-disable-evil--sw-refresh-cursor-in-vterm (oldfun &rest r) - (unless (derived-mode-p 'vterm-mode) - (apply oldfun r))) - (advice-add 'evil--sw-refresh-cursor :around - #'my/-disable-evil--sw-refresh-cursor-in-vterm) - + (evil-define-motion my/vterm-evil-goto-line (count) + "`evil-goto-line' for `vterm' buffers." + :jump t + :type line + (if count + (evil-goto-line count) + (goto-char (point-max)) + (vterm-previous-prompt 1))) + (evil-define-key 'motion vterm-copy-mode-map + (kbd "G") #'my/vterm-evil-goto-line) + (add-to-list 'vterm-environment "COLORTERM=truecolor") (defun my/-vterm-copy-mode-on-exit (&rest _r) (vterm-copy-mode)) (add-hook 'vterm-exit-functions #'my/-vterm-copy-mode-on-exit) + (defun my/-evil-dont-update-vterm-cursor (oldfun &rest r) + (when (or (not (derived-mode-p 'vterm-mode)) + vterm-copy-mode) + (apply oldfun r))) + (advice-add 'evil-refresh-cursor :around #'my/-evil-dont-update-vterm-cursor) + + ;; fix the random percent characters in the vterm buffer + (defun my/-vterm-fix-percent-characters () + (save-window-excursion + (select-window (cl-second (window-list-1))) + (redraw-frame)) + (remove-hook 'post-command-hook #'my/-vterm-fix-percent-characters t)) + (defvar-local my/-vterm-pre-copy-mode-cursor nil "The cursor to restore after exiting `vterm-copy-mode'.") (defun my/-setup-vterm-copy-mode () @@ -3023,16 +3048,47 @@ Actually, return the method name." (evil-define-key 'motion vterm-copy-mode-map (kbd "i") #'vterm-copy-mode) (evil-set-initial-state 'vterm-mode 'emacs) - (defun my/-setup-vterm-mode () - (setq-local global-hl-line-mode nil) - (visual-line-mode -1) - (visual-wrap-prefix-mode -1)) (defun my/-vterm-shell-for-cwd () "Return a good shell for CWD, or nil if the default shell should be used." (cond ((my/dir-container-p) "/bin/sh") ;; idk why zsh dosen't work ((my/dir-really-remote-p) "/bin/sh") (t shell-file-name))) + (defconst my/-vterm-hostname-regexp + (rx (any "a-z" "A-Z" "0-9") (** 0 252 (any "a-z" "A-Z" "0-9" ?. ?-))) + "Regexp for hostnames.") + (defvar my/vterm-term-prompt-regexp nil + "Regexp to use for vterm `term-prompt-regexp'.") + (defun my/vterm-term-prompt-regexp () + "Return a sane regexp for vterm for `term-prompt-regexp'." + (or my/vterm-term-prompt-regexp + (let* ((is-remote (file-remote-p default-directory)) + (shell (my/-vterm-shell-for-cwd)) + (hostname-regexp (if is-remote + my/-vterm-hostname-regexp + (regexp-quote (system-name)))) + (username-regexp (if is-remote + (rx (+ (not "@"))) + (regexp-opt (list user-login-name "root"))))) + (cl-flet ((shell-match-p (name) + (string-match-p (rx (or bos "/") (literal name) eos) + shell))) + (cond* + ((shell-match-p "bash") + (rx bol "[" (regexp username-regexp) + "@" (regexp hostname-regexp) "]" + (or "$" "#") " ")) + ((bind* (is-zsh (shell-match-p "zsh")))) + ((and is-zsh is-remote) + (rx bol (regexp hostname-regexp) (or "%" "#") " ")) + (is-zsh + (rx bol (or "❯" "❮") " "))))))) + (defun my/-setup-vterm-mode () + (setq-local term-prompt-regexp (my/vterm-term-prompt-regexp)) + (add-hook 'post-command-hook #'my/-vterm-fix-percent-characters nil t) + (my/locally-disable-hl-line) + (visual-line-mode -1) + (visual-wrap-prefix-mode -1)) (defun my/project-vterm (&optional arg prompt) "Switch to or create a vterm buffer in the current projects root." (interactive (list current-prefix-arg t)) @@ -3628,7 +3684,7 @@ This is the same as `evil-ret' except that it works for links in (mu4e--view-browse-url-from-binding url) (funcall-interactively #'evil-ret count))) (defun my/-mu4e-setup-view-mode () - (setq-local global-hl-line-mode nil) + (my/locally-disable-hl-line) (display-line-numbers-mode -1)) (defun my/-mu4e-setup-main-mode () (setq-local default-directory "~/")