diff --git a/.emacs.d/init.el b/.emacs.d/init.el index ba83bd3..902a3be 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -39,6 +39,8 @@ (setq my/lowpower (string= (system-name) "pntk")) +(setq my/slow-ssh (string= (getenv "IS_TRAMP") "true")) + (use-package conda :straight t :config @@ -434,7 +436,9 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." :straight t :config (projectile-mode +1) - (setq projectile-project-search-path '("~/Code" "~/Documents"))) + (setq projectile-project-search-path '("~/Code" "~/Documents")) + (defadvice projectile-project-root (around ignore-remote first activate) + (unless (file-remote-p default-directory) ad-do-it))) (use-package counsel-projectile :after (counsel projectile) @@ -486,6 +490,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." (use-package git-gutter :straight t + :if (not my/slow-ssh) :config (global-git-gutter-mode +1)) @@ -496,7 +501,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." (use-package editorconfig :straight t :config - (editorconfig-mode 1) + (unless my/slow-ssh (editorconfig-mode 1)) (add-to-list 'editorconfig-indentation-alist '(emmet-mode emmet-indentation))) @@ -753,7 +758,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." (use-package all-the-icons-dired :straight t - :if (not my/lowpower) + :if (not (or my/lowpower my/slow-ssh)) :hook (dired-mode . all-the-icons-dired-mode) :config (advice-add 'dired-add-entry :around #'all-the-icons-dired--refresh-advice) @@ -771,6 +776,14 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." :keymaps 'dired-narrow-map [escape] 'keyboard-quit)) +(setq tramp-verbose 1) + +(setq remote-file-name-inhibit-cache nil) +(setq vc-ignore-dir-regexp + (format "\\(%s\\)\\|\\(%s\\)" + vc-ignore-dir-regexp + tramp-file-name-regexp)) + (use-package vterm :straight t :commands (vterm vterm-other-window) @@ -809,8 +822,6 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." "M-l" 'vterm-send-right "M-h" 'vterm-send-left)) -(general-nmap "~" 'vterm) - (add-to-list 'display-buffer-alist `(,"vterm-subterminal.*" (display-buffer-reuse-window @@ -835,8 +846,9 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." (kill-buffer (current-buffer)) (select-window vterm-window)) (vterm-other-window "vterm-subterminal")))) - -(general-nmap "`" 'my/toggle-vterm-subteminal) +(unless my/slow-ssh + (general-nmap "`" 'my/toggle-vterm-subteminal) + (general-nmap "~" 'vterm)) (defun my/configure-eshell () (add-hook 'eshell-pre-command-hook 'eshell-save-some-history) @@ -868,8 +880,9 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." (setq eshell-highlight-prompt nil) (setq eshell-prompt-function 'epe-theme-pipeline)) -;; (general-nmap "`" 'aweshell-dedicated-toggle) -;; (general-nmap "~" 'eshell) +(when my/slow-ssh + (general-nmap "`" 'aweshell-dedicated-toggle) + (general-nmap "~" 'eshell)) (use-package org :straight (:type built-in) @@ -939,8 +952,10 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." :states '(normal emacs) "L" 'org-shiftright "H" 'org-shiftleft - "S-" 'org-babel-next-src-block - "S-" 'org-babel-previous-src-block + "S-" 'org-next-visible-heading + "S-" 'org-previous-visible-heading + "M-0" 'org-next-visible-heading + "M-9" 'org-previous-visible-heading "M-]" 'org-babel-next-src-block "M-[" 'org-babel-previous-src-block) @@ -1043,14 +1058,17 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." files)))) (defun my/insert-jupyter-kernel () + "Insert a path to an active Jupyter kernel into the buffer" (interactive) (insert (my/select-jupyter-kernel))) (defun my/jupyter-connect-repl () + "Open an emacs-jupyter REPL, connected to a Jupyter kernel" (interactive) (jupyter-connect-repl (my/select-jupyter-kernel) nil nil nil t)) (defun my/jupyter-qtconsole () + "Open Jupyter QtConsole, connected to a Jupyter kernel" (interactive) (start-process "jupyter-qtconsole" nil "setsid" "jupyter" "qtconsole" "--existing" (file-name-nondirectory (my/select-jupyter-kernel)))) @@ -1176,6 +1194,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." (use-package lsp-mode :straight t + :if (not my/slow-ssh) :hook ( (typescript-mode . lsp) (vue-mode . lsp) @@ -1192,7 +1211,7 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." (setq lsp-eslint-server-command '("node" "/home/pavel/.emacs.d/.cache/lsp/eslint/unzipped/extension/server/out/eslintServer.js" "--stdio")) (setq lsp-eslint-run "onSave") (setq lsp-signature-render-documentation nil) - ; (lsp-headerline-breadcrumb-mode nil) + ;; (lsp-headerline-breadcrumb-mode nil) (setq lsp-headerline-breadcrumb-enable nil) (add-to-list 'lsp-language-id-configuration '(svelte-mode . "svelte"))) @@ -1460,8 +1479,12 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." ("." . "\\cdot") ("v" . "\\forall") ("s" . "\\sum_{$1}^{$2}$0") + ("p" . "\\prod_{$1}^{$2}$0") ("e" . "\\exists") - ("i" . "\\int_{$1}^{$2}$0"))) + ("i" . "\\int_{$1}^{$2}$0") + ("c" . "\\cap") + ("u" . "\\cup") + ("0" . "\\emptyset"))) (setq my/latex-math-prefix "''") @@ -1630,8 +1653,12 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." ("." . "\\cdot") ("v" . "\\forall") ("s" . "\\sum_{$1}^{$2}$0") + ("p" . "\\prod_{$1}^{$2}$0") ("e" . "\\exists") - ("i" . "\\int_{$1}^{$2}$0"))) + ("i" . "\\int_{$1}^{$2}$0") + ("c" . "\\cap") + ("u" . "\\cup") + ("0" . "\\emptyset"))) (setq my/latex-math-prefix "''") @@ -1841,6 +1868,10 @@ then it takes a second \\[keyboard-quit] to abort the minibuffer." :config (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))) +(use-package dotenv-mode + :straight t + :mode "\\.env\\..*\\'") + (use-package csv-mode :straight t :mode "\\.csv\\'") diff --git a/Emacs.org b/Emacs.org index 2912378..d5ad40c 100644 --- a/Emacs.org +++ b/Emacs.org @@ -91,6 +91,7 @@ As with other files in the repo, parts prefixed with (OFF) are not used but kept - [[#dired][Dired]] - [[#basic-config--keybindings][Basic config & keybindings]] - [[#addons][Addons]] + - [[#tramp][TRAMP]] - [[#shells][Shells]] - [[#vterm][vterm]] - [[#configuration][Configuration]] @@ -104,7 +105,7 @@ As with other files in the repo, parts prefixed with (OFF) are not used but kept - [[#python][Python]] - [[#view-html-in-browser][View HTML in browser]] - [[#setup][Setup]] - - [[#select-active-jupyter-kernel][Select active Jupyter kernel]] + - [[#managing-jupyter-kernels][Managing Jupyter kernels]] - [[#ui][UI]] - [[#instant-equations-preview][Instant equations preview]] - [[#latex-fragments][LaTeX fragments]] @@ -114,7 +115,7 @@ As with other files in the repo, parts prefixed with (OFF) are not used but kept - [[#hugo][Hugo]] - [[#jupyter-notebook][Jupyter Notebook]] - [[#html-export][Html export]] - - [[#off-latex][(OFF) LaTeX]] + - [[#latex][LaTeX]] - [[#keybindings--stuff][Keybindings & stuff]] - [[#copy-a-link][Copy a link]] - [[#presentations][Presentations]] @@ -172,6 +173,7 @@ As with other files in the repo, parts prefixed with (OFF) are not used but kept - [[#haskell][Haskell]] - [[#json][JSON]] - [[#yaml][YAML]] + - [[#env][.env]] - [[#csv][CSV]] - [[#docker][Docker]] - [[#apps--misc][Apps & Misc]] @@ -264,6 +266,11 @@ The following variable is true when my machine is not powerful enough for some r #+begin_src emacs-lisp (setq my/lowpower (string= (system-name) "pntk")) #+end_src + +And the following is true if Emacs is meant to be used with TRAMP over slow ssh +#+begin_src emacs-lisp +(setq my/slow-ssh (string= (getenv "IS_TRAMP") "true")) +#+end_src ** Anaconda & environment [[https://www.anaconda.com/][Anaconda]] is a free package and environment manager. I currently use it to manage multiple versions of Python and Node.js @@ -889,12 +896,15 @@ Integrates with evil, magit and projectile. ** Projectile [[https://github.com/bbatsov/projectile][Projectile]] gives a bunch of useful functions for managing projects, like finding files within a project, fuzzy-find, replace, etc. +~defadvice~ is meant to speed projectile up with TRAMP a bit. #+begin_src emacs-lisp (use-package projectile :straight t :config (projectile-mode +1) - (setq projectile-project-search-path '("~/Code" "~/Documents"))) + (setq projectile-project-search-path '("~/Code" "~/Documents")) + (defadvice projectile-project-root (around ignore-remote first activate) + (unless (file-remote-p default-directory) ad-do-it))) (use-package counsel-projectile :after (counsel projectile) @@ -966,6 +976,7 @@ Also, [[https://github.com/emacsorphanage/git-gutter][git-gutter]] is plugin whi (use-package git-gutter :straight t + :if (not my/slow-ssh) :config (global-git-gutter-mode +1)) @@ -984,7 +995,7 @@ References: (use-package editorconfig :straight t :config - (editorconfig-mode 1) + (unless my/slow-ssh (editorconfig-mode 1)) (add-to-list 'editorconfig-indentation-alist '(emmet-mode emmet-indentation))) #+end_src @@ -1372,7 +1383,7 @@ Display icons for files. #+begin_src emacs-lisp (use-package all-the-icons-dired :straight t - :if (not my/lowpower) + :if (not (or my/lowpower my/slow-ssh)) :hook (dired-mode . all-the-icons-dired-mode) :config (advice-add 'dired-add-entry :around #'all-the-icons-dired--refresh-advice) @@ -1396,6 +1407,36 @@ vifm-like filter :keymaps 'dired-narrow-map [escape] 'keyboard-quit)) #+end_src +** TRAMP +TRAMP is a package which provides remote editing capacities. It is particularly useful for remote server management. + +One of the reasons why TRAMP may be slow is that some plugins do too much requests to filesystem. To debug these issues, set the following variable to 6: +#+begin_src emacs-lisp +(setq tramp-verbose 1) +#+end_src + +To check if a file is remote, you can use ~file-remote-p~. E.g. ~(file-remote-p default-directory)~ for a current buffer. The problem with this approach is that it's rather awkward to add these checks in every hook, especially for global modes, so for now I just set environment variable for Emacs which disables these modes. + +So far I found the following problematic plugins: +| Plugin | Note | Solution | +|---------------------+------------------------------------------+-------------------------------| +| editorconfig | looks for .editorconfig in the file tree | do not enable globally | +| all-the-icons-dired | runs test on every file in the directory | disable | +| projectile | looks for .git, .svn, etc | advice ~projectile-file-name~ | +| lsp | does a whole lot of stuff | disable | +| git-gutter | runs git | disable | +| vterm | no proper TRAMP integration | use eshell | + +At any rate, it's usable, although not perfect. + +Some other optimization settings: +#+begin_src emacs-lisp +(setq remote-file-name-inhibit-cache nil) +(setq vc-ignore-dir-regexp + (format "\\(%s\\)\\|\\(%s\\)" + vc-ignore-dir-regexp + tramp-file-name-regexp)) +#+end_src * Shells ** vterm My terminal emulator of choice. @@ -1442,7 +1483,7 @@ References: "M-l" 'vterm-send-right "M-h" 'vterm-send-left)) -(general-nmap "~" 'vterm) + #+end_src *** Subterminal Open a terminal in the lower third of the frame with the =`= key. That's mostly how I use vterm. @@ -1472,8 +1513,9 @@ Open a terminal in the lower third of the frame with the =`= key. That's mostly (kill-buffer (current-buffer)) (select-window vterm-window)) (vterm-other-window "vterm-subterminal")))) - -(general-nmap "`" 'my/toggle-vterm-subteminal) +(unless my/slow-ssh + (general-nmap "`" 'my/toggle-vterm-subteminal) + (general-nmap "~" 'vterm)) #+end_src ** Eshell A shell written in Emacs lisp. I don't use it as of now, but keep the config just in case. @@ -1508,8 +1550,9 @@ A shell written in Emacs lisp. I don't use it as of now, but keep the config jus (setq eshell-highlight-prompt nil) (setq eshell-prompt-function 'epe-theme-pipeline)) -;; (general-nmap "`" 'aweshell-dedicated-toggle) -;; (general-nmap "~" 'eshell) +(when my/slow-ssh + (general-nmap "`" 'aweshell-dedicated-toggle) + (general-nmap "~" 'eshell)) #+end_src * Org Mode The best feature of Emacs. Just after every other best feature of Emacs, probably. @@ -1691,14 +1734,17 @@ Requirements: =ss= files)))) (defun my/insert-jupyter-kernel () + "Insert a path to an active Jupyter kernel into the buffer" (interactive) (insert (my/select-jupyter-kernel))) (defun my/jupyter-connect-repl () + "Open an emacs-jupyter REPL, connected to a Jupyter kernel" (interactive) (jupyter-connect-repl (my/select-jupyter-kernel) nil nil nil t)) (defun my/jupyter-qtconsole () + "Open Jupyter QtConsole, connected to a Jupyter kernel" (interactive) (start-process "jupyter-qtconsole" nil "setsid" "jupyter" "qtconsole" "--existing" (file-name-nondirectory (my/select-jupyter-kernel)))) @@ -1800,9 +1846,10 @@ Scale latex fragments preview. Add a custom LaTeX template without default packages. Packages are indented to be imported with function from [[Import *.sty]]. #+begin_src emacs-lisp :tangle no (defun my/setup-org-latex () - (setq org-latex-compiler "xelatex") - (setq org-latex-listings 'minted) - (setq org-latex-minted-options + (setq org-latex-compiler "xelatex") ;; Probably not necessary + (setq org-latex-pdf-process '("latexmk -outdir=%o %f")) ;; Use latexmk + (setq org-latex-listings 'minted) ;; Use minted to highlight source code + (setq org-latex-minted-options ;; Some minted options I like '(("breaklines" "true") ("tabsize" "4") ("autogobble") @@ -1810,7 +1857,7 @@ Add a custom LaTeX template without default packages. Packages are indented to b ("numbersep" "0.5cm") ("xleftmargin" "1cm") ("frame" "single"))) - (setq org-latex-pdf-process '("latexmk -outdir=%o %f")) + ;; Use extarticle without the default packages (add-to-list 'org-latex-classes '("org-plain-extarticle" "\\documentclass{extarticle} @@ -1823,6 +1870,7 @@ Add a custom LaTeX template without default packages. Packages are indented to b ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))) +;; Make sure to eval the function when org-latex-classes list already exists (with-eval-after-load 'ox-latex (my/setup-org-latex)) #+end_src @@ -1840,8 +1888,10 @@ Add a custom LaTeX template without default packages. Packages are indented to b :states '(normal emacs) "L" 'org-shiftright "H" 'org-shiftleft - "S-" 'org-babel-next-src-block - "S-" 'org-babel-previous-src-block + "S-" 'org-next-visible-heading + "S-" 'org-previous-visible-heading + "M-0" 'org-next-visible-heading + "M-9" 'org-previous-visible-heading "M-]" 'org-babel-next-src-block "M-[" 'org-babel-previous-src-block) @@ -1972,6 +2022,7 @@ References: #+begin_src emacs-lisp (use-package lsp-mode :straight t + :if (not my/slow-ssh) :hook ( (typescript-mode . lsp) (vue-mode . lsp) @@ -1988,7 +2039,7 @@ References: (setq lsp-eslint-server-command '("node" "/home/pavel/.emacs.d/.cache/lsp/eslint/unzipped/extension/server/out/eslintServer.js" "--stdio")) (setq lsp-eslint-run "onSave") (setq lsp-signature-render-documentation nil) - ; (lsp-headerline-breadcrumb-mode nil) + ;; (lsp-headerline-breadcrumb-mode nil) (setq lsp-headerline-breadcrumb-enable nil) (add-to-list 'lsp-language-id-configuration '(svelte-mode . "svelte"))) @@ -2501,8 +2552,12 @@ Noweb points to the AUCTeX config block. ("." . "\\cdot") ("v" . "\\forall") ("s" . "\\sum_{$1}^{$2}$0") + ("p" . "\\prod_{$1}^{$2}$0") ("e" . "\\exists") - ("i" . "\\int_{$1}^{$2}$0"))) + ("i" . "\\int_{$1}^{$2}$0") + ("c" . "\\cap") + ("u" . "\\cup") + ("0" . "\\emptyset"))) (setq my/latex-math-prefix "''") @@ -2768,6 +2823,12 @@ Use [[https://github.com/Microsoft/python-language-server][Microsoft Language Se :config (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))) #+end_src +** .env +#+begin_src emacs-lisp +(use-package dotenv-mode + :straight t + :mode "\\.env\\..*\\'") +#+end_src ** CSV #+begin_src emacs-lisp (use-package csv-mode