Skip to content

Commit

Permalink
add: surround
Browse files Browse the repository at this point in the history
  • Loading branch information
tungd committed Oct 8, 2024
1 parent a3ecc0c commit e84a17b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 92 deletions.
6 changes: 3 additions & 3 deletions emacs/custom.el
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@
indent-guide isearch-mb kotlin-mode kotlin-ts-mode lua-mode magit
markdown-mode markdown-ts-mode minions modus-theme ob-async ob-http
ob-kotlin ob-plantuml ob-redis orderless persp-mode protobuf-mode
rainbow-mode reason-mode redis rg scad-mode tempel terraform-mode
tuareg undo-fu-session vertico visual-regexp vterm vundo web-beautify
web-mode))
rainbow-mode reason-mode redis rg scad-mode surround tempel
terraform-mode tuareg undo-fu-session vertico visual-regexp vterm vundo
web-beautify web-mode))
'(package-vc-selected-packages
'((copilot :url "https://github.com/copilot-emacs/copilot.el.git" :branch "main")))
'(safe-local-variable-values
Expand Down
100 changes: 11 additions & 89 deletions emacs/init.org
Original file line number Diff line number Diff line change
Expand Up @@ -514,19 +514,7 @@ Cleanup whitespaces automatically on save.

** Parenthesis

Parenthesis come in pairs, that's why they are cumbersome to deal with. Better
use =smart-parens= to manage them. However the command name use words from an
arcane language :(, so I put together a table of human-readable description of
the commands. All key bindings are started with =M-s=.

| Bindings | Command | Description |
|-----------+------------------------+-----------------------------------------------------|
| =DEL= | =sp-splice-sexp= | Delete surrounding pair |
| =M-S= | =sp-rewrap-sexp= | Replace the surrounding pair |
| =<right>= | =sp-slurp-hybrid-sexp= | Extend the pair to include items to the right |
| =<left>= | =sp-forward-barf-sexp= | Shrink the pair, the right-most item is put outside |

NOTE: This package is huge, I'm still learning it.
Parenthesis come in pairs, that's why they are cumbersome to deal with.

#+begin_src emacs-lisp
(use-package paren
Expand All @@ -539,6 +527,12 @@ NOTE: This package is huge, I'm still learning it.
:hook (after-init . electric-pair-mode))
#+end_src

#+begin_src emacs-lisp
(use-package surround
:ensure t
:bind-keymap ("M-s" . surround-keymap))
#+end_src

#+begin_src emacs-lisp
(defun td/mark-line-dwim ()
(interactive)
Expand Down Expand Up @@ -739,17 +733,11 @@ Some speedup for Tramp:

Native LSP support via =Eglot= since Emacs 29.1

#+begin_src emacs-lisp
;; https://github.com/fwcd/kotlin-language-server/blob/main/TROUBLESHOOTING.md
(setenv "JAVA_OPTS" "-Xmx4g")
#+end_src

#+begin_src emacs-lisp
(setq read-process-output-max (* 8 1024 1024))

(use-package eglot
:hook ((kotlin-ts-mode . eglot-ensure)
(js-ts-mode . eglot-ensure)
:hook ((js-ts-mode . eglot-ensure)
(typescript-ts-mode . eglot-ensure)
(tsx-ts-mode . eglot-ensure)
(go-ts-mode . eglot-ensure)
Expand All @@ -765,34 +753,13 @@ Native LSP support via =Eglot= since Emacs 29.1
:documentOnTypeFormattingProvider
:documentHighlightProvider))
:config
(add-to-list 'eglot-server-programs '(kotlin-ts-mode "kotlin-language-server"))
(add-to-list 'eglot-server-programs '(ocaml-ts-mode "ocamllsp"))
(add-to-list 'eglot-server-programs '((web-mode :language-id "typescriptreact") "typescript-language-server" "--stdio"))
;; https://www.reddit.com/r/emacs/comments/17jrsmv/comment/k74b3tg/?utm_source=share&utm_medium=web2x&context=3
;; (advice-add 'jsonrpc--log-event :override #'ignore)
)
#+end_src

#+begin_src emacs-lisp :tangle no
(use-package lsp-mode
:ensure t
:commands lsp
:hook ((kotlin-ts-mode . lsp)
(js-ts-mode . lsp)
(typescript-ts-mode . lsp)
(tsx-ts-mode . lsp)
(go-ts-mode . lsp)
(tuareg-mode . lsp)
(python-mode . lsp)
(lsp-mode . lsp-enable-which-key-integration))
:custom
(lsp-keymap-prefix "C-c l")
(lsp-headerline-breadcrumb-enable nil)
(lsp-enable-indentation nil)
(lsp-enable-on-type-formatting nil)
(lsp-enable-symbol-highlighting nil))
#+end_src

#+begin_src emacs-lisp
(use-package eldoc
:config
Expand Down Expand Up @@ -832,10 +799,8 @@ Native Tree-sitter support since Emacs 29
treesit-node-end
treesit-node-prev-sibling)
:config
(add-to-list 'treesit-language-source-alist '(dockerfile . ("https://github.com/camdencheek/tree-sitter-dockerfile.git")))
(add-to-list 'treesit-language-source-alist '(kotlin . ("https://github.com/fwcd/tree-sitter-kotlin.git")))
(add-to-list 'treesit-language-source-alist '(org . ("https://github.com/milisims/tree-sitter-org.git")))
(add-to-list 'treesit-language-source-alist '(nix . ("https://github.com/nix-community/tree-sitter-nix.git")))
(add-to-list 'treesit-language-source-alist '(tsx . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "tsx/src")))
(add-to-list 'treesit-language-source-alist '(typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "v0.20.3" "typescript/src"))))

Expand Down Expand Up @@ -899,13 +864,6 @@ Native Tree-sitter support since Emacs 29
:custom
(go-ts-mode-indent-offset 2))

(use-package dockerfile-ts-mode
:mode ("Dockerfile$" . dockerfile-ts-mode))

(use-package yaml-ts-mode
:mode (("\\.yaml\\'" . yaml-ts-mode)
("\\.yml\\'" . yaml-ts-mode)))

(setq
major-mode-remap-alist
'((js-mode . js-ts-mode)
Expand All @@ -918,20 +876,7 @@ Native Tree-sitter support since Emacs 29

** Auto completion

I use auto completion sparingly, using Corfu.

#+begin_src emacs-lisp
;; (use-package corfu
;; :ensure t
;; :hook (after-init . global-corfu-mode)
;; :bind* (:map corfu-map
;; ("SPC" . corfu-insert-separator)
;; ("C-n" . corfu-next)
;; ("C-p" . corfu-previous))
;; :custom
;; (corfu-cycle t)
;; (corfu-echo-documentation 0.1))
#+end_src
I use auto completion sparingly.

#+begin_src emacs-lisp
(use-package dabbrev
Expand Down Expand Up @@ -1080,7 +1025,7 @@ including JSX. Since I'm no longer write as much JavaScript, and I will use

#+begin_src emacs-lisp
(use-package js
:mode (("\\.eslintrc$" . js-ts-mode))
:mode (("\\.eslintrc$" . json-ts-mode))
:config
(setq js-indent-level 2
js-indent-first-init 'dynamic
Expand All @@ -1090,30 +1035,6 @@ including JSX. Since I'm no longer write as much JavaScript, and I will use

** Python

** Haskell

I'm also a Haskell beginner :). Setting up Haskell with Emacs is relatively
easy. There's also a catch-all IDE-like mode called =intero=, by the very
same folk who runs =stack=.

#+begin_src emacs-lisp :tangle no
(use-package haskell-mode
:ensure t
:mode (("\\.hs\\'" . haskell-mode))
:hook ((haskell-mode . copilot-mode)
(haskell-mode . eglot-ensure))
:bind (([remap haskell-mode-format-imports] . haskell-sort-imports))
:custom
(haskell-program-name "cabal repl"))
#+end_src

#+begin_src emacs-lisp :tangle no
(use-package lsp-haskell
:ensure t
:custom
(lsp-haskell-server-path "haskell-language-server-wrapper"))
#+end_src

** OCaml

I'm a Python veteran. When I have the opportunity to, I tried to use
Expand Down Expand Up @@ -1492,6 +1413,7 @@ down compiler error :(.
(use-package display-line-numbers
:hook ((prog-mode . display-line-numbers-mode)
(org-mode . display-line-numbers-mode)
(yaml-mode . display-line-numbers-mode)
(conf-mode . display-line-numbers-mode))
:custom
(display-line-numbers-width-start 100))
Expand Down

0 comments on commit e84a17b

Please sign in to comment.