reddit / emacs

Minor problems with vterm in emacs on MacOS

chiathrowaway123 · 2022-12-27 02:46
So I love vterm 99% of the time, but there are a few things that are annoying \- If I need to use brew install, I can't do it in emacs. It just says \`brew not found\`. So I have to switch into iterm and then brew install from there. I don't use brew much at all, but when I need it it's annoying that vterm or any of emacs' shell tools can't find it. \- Vterm doesn't have access to the kill ring. If I try to M-y anything from the kill ring vterm says \`Buffer is read only\`, which it certainly isn't. \- Using the universal modifier to include a string of digits doesn't work: C-u 12 C-u 0 should insert 12 "0"s, but it just inserts 1. There are other gripes but these are the three top of mind. I'm not sure if there's something I'm missing about vterm, but I can't find any way to correct these issues which frustrates me since I'm now so used to everything working seamlessly everywhere else. If anyone has ideas for solutions to these problems, I'm all ears :)
TheSnowIsCold-46 · 2022-12-27 04:51
Not sure about points 2 and 3, although it could depend on the version and port of emacs you are using (how was it installed, etc). For example, I use the emacsplus brew recipe and don't have issues with #2 (vterm has access to kill ring and copy/paste using Mac keyboard shortcuts also works) For one, do you use the [exec-path-from-shell](https://github.com/purcell/exec-path-from-shell) package? That should do the trick for path issues when using Emacs vterm. It's likely when emacs is loading it's not correctly loading in the $PATH values from your system. You can check the path values in emacs by checking the value of exec-path. Apologies for the issues with formatting, on mobile.
bravosierrasierra · 2022-12-27 09:08
1. this is not vterm problem. Check PATH environment variable and \~/.bash\_profile. I have symlink \~/.bashrc to \~/.bash\_profile 2. just map your function to what you want. After many trash paste into root sessions from hidden emacs selections, i wrote this copy-paste functions for vterm. Hidden emacs selections is my pain in the ass with copy-paste into vterm. With these 2 functions and M-e i found happiness inside vterm copy-paste. ``` ;; simple solution ;; (define-key vterm-mode-map (kbd "M-c") 'kill-ring-save) ;; (define-key vterm-mode-map (kbd "M-v") 'vterm-yank) ;; (define-key vterm-mode-map (kbd "C-M-v") 'helm-show-kill-ring) ;; My solution ;; Toggle copy mode in vterm (define-key vterm-mode-map (kbd "M-e") 'vterm-copy-mode) (define-key vterm-copy-mode-map (kbd "M-e") '(lambda () (interactive) (vterm-copy-mode -1))) (setq vterm-clipboard-warning-max-lines 20 vterm-clipboard-warning-max-chars 256) ;; Safe copy selection to clipboard (defun bss/vterm-kill-ring-save () (interactive) (let* ((str "") (len 0) (lines 0) (lines-raw 0) (msg "!!! Warning, too big cut into clipboard!!!:") (need-warning nil) ) (if (not (region-active-p)) (message "!!! Warning: region not selected !!!") (unless vterm-copy-mode (vterm-copy-mode 1)) (call-interactively 'kill-ring-save) (vterm-copy-mode -1) (setq str (substring-no-properties (current-kill 0)) len (length str) lines-raw (with-temp-buffer (insert str) (count-lines (point-min) (point-max))) lines (if (null lines-raw) 0 lines-raw)) (if (length> str vterm-clipboard-warning-max-chars ) (setq need-warning t msg (format "%s Too many symbols (%d > %d)." msg len vterm-clipboard-warning-max-chars ))) (if (> lines vterm-clipboard-warning-max-lines ) (setq need-warning t msg (format "%s Too many lines (%d > %d)." msg lines vterm-clipboard-warning-max-lines ))) (if (not need-warning) (message "%d lines / %d chars copied into clipboard" lines len) (message "%s\nStarts with '%s',\nEnds with '%s'" msg (substring str 0 60) (substring str -60 -1))) ))) (define-key vterm-mode-map (kbd "M-c") 'bss/vterm-kill-ring-save) (define-key vterm-copy-mode-map (kbd "M-c") 'bss/vterm-kill-ring-save) (define-key vterm-mode-map (kbd "s-c") 'bss/vterm-kill-ring-save) ;; Safe paste to clipboard (defun bss/vterm-kill-ring-paste () (interactive) (let* ( (str (substring-no-properties (current-kill 0))) (len (length str)) (lines-raw (with-temp-buffer (insert str) (count-lines (point-min) (point-max)))) (lines (if (null lines-raw) 0 lines-raw)) (msg "!!! Warning, too big clipboard to paste!!!:") (need-warning nil) ) ;; autoexit from copy mode (vterm-copy-mode -1) (if (length> str vterm-clipboard-warning-max-chars ) (setq need-warning t msg (format "%s Too many symbols (%d > %d)." msg len vterm-clipboard-warning-max-chars ))) (if (> lines vterm-clipboard-warning-max-lines ) (setq need-warning t msg (format "%s Too many lines (%d > %d)." msg lines vterm-clipboard-warning-max-lines ))) (if need-warning (setq msg (format "%s\nStarts with '%s',\nEnds with '%s'\nConfirm paste" msg (substring str 0 60) (substring str -60 -1)))) (if (not need-warning) (call-interactively 'vterm-yank) (if (y-or-n-p msg) (call-interactively 'vterm-yank))) ) ) (define-key vterm-mode-map (kbd "M-v") 'bss/vterm-kill-ring-paste) (define-key vterm-copy-mode-map (kbd "M-v") 'bss/vterm-kill-ring-paste) ```