From df5eed3f28e228eb6879deb8441ace5114d965f2 Mon Sep 17 00:00:00 2001 From: Andre Henriques Date: Sat, 25 Mar 2023 20:51:06 +0000 Subject: [PATCH] semi working with js --- init.el | 27 ++++- settings.org | 316 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 323 insertions(+), 20 deletions(-) diff --git a/init.el b/init.el index 8665f13..4b5e298 100644 --- a/init.el +++ b/init.el @@ -3,11 +3,27 @@ (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) -(unless (package-installed-p 'use-package) - (package-refresh-contents) - (package-install 'use-package)) +;;(unless (package-installed-p 'use-package) +;; (package-refresh-contents) +;; (package-install 'use-package)) + +;;(require 'use-package) + +(defvar bootstrap-version) +(let ((bootstrap-file + (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory)) + (bootstrap-version 6)) + (unless (file-exists-p bootstrap-file) + (with-current-buffer + (url-retrieve-synchronously + "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" + 'silent 'inhibit-cookies) + (goto-char (point-max)) + (eval-print-last-sexp))) + (load bootstrap-file nil 'nomessage)) + +(straight-use-package 'use-package) -(require 'use-package) ; always follow symlinks ; (setq vc-follow-symlinks t) @@ -25,7 +41,8 @@ ;; If there is more than one, they won't work right. '(custom-safe-themes '("bfc0b9c3de0382e452a878a1fb4726e1302bf9da20e69d6ec1cd1d5d82f61e3d" default)) - '(package-selected-packages '(evil-mode))) + '(package-selected-packages + '(web-mode flycheck-postframe lsp-ui lsp-mode tree-sitter-langs tree-sitter evil-mode))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. diff --git a/settings.org b/settings.org index 974d10c..f74eaff 100644 --- a/settings.org +++ b/settings.org @@ -1,7 +1,7 @@ * Looks ** Font #+begin_src emacs-lisp - (set-frame-font "FiraCode 16" nil t) + (set-frame-font "MonoLisa 18" nil t) (set-fontset-font t '(#x1f000 . #x1faff) (font-spec :family "Myne Noto Color Emoji")) #+end_src ** Themes @@ -56,15 +56,42 @@ Configure layout ) #+end_src -Evil dashboard setup +Try to make dashboard appear when opening a file as well #+begin_src emacs-lisp - (defun dashboard-load-function () - (interactive) - (dashboard-next-section 1)) + ;; (defun setup-dashboard-on-multiple () + ;; (interactive) + ;; (if (> (length command-line-args) 2) + ;; (progn + ;; (split-window-below) + ;; (balance-windows) + ;; (other-window 1) + ;; ) + ;; (message (concat "Got" (number-to-string (length command-line-args))))) + (defun open-dashboard-on-split () + "Opens the dashboard on a new split window" + (interactive) + (split-window-below) + (balance-windows) + (other-window 1) + (generate-new-buffer "*dashboard*") + (switch-to-buffer "*dashboard*") + (dashboard-insert-startupify-lists) + (window-resize (get-buffer-window) (- (floor (* (window-total-height (get-buffer-window)) 0.4)))) + (other-window 1)) + + (defun setup-dashboard-on-multiple () + "Setups the dashboard when args are provided" + (interactive) + (if (>= (length command-line-args) 2) + (open-dashboard-on-split))) +#+end_src + +Setup stuff +#+begin_src emacs-lisp (defun evil-dashboard-setup () - (setup-dashboard-looks) - (add-hook 'dashboard-mode-hook 'dashboard-load-function)) + (setup-dashboard-looks) + (setup-dashboard-on-multiple)) #+end_src #+begin_src emacs-lisp @@ -102,14 +129,96 @@ Consel (tool-bar-mode -1) #+end_src +** Langs +Set up tree sitter +#+begin_src emacs-lisp + (use-package tree-sitter + :ensure t + :hook (tree-sitter-after-on . tree-sitter-hl-mode) + :config + (global-tree-sitter-mode)) + (use-package tree-sitter-langs + :ensure t) +#+end_src +*** ts +Setup typescript mode +#+begin_src emacs-lisp + (use-package typescript-mode + :ensure t + :after (tree-sitter) + :config + ;;(define-derived-mode typescriptreact-mode typescript-mode + ;; "TypeScript TSX") + ;;(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescriptreact-mode)) + ;;(add-to-list 'tree-sitter-major-mode-language-alist '(typescriptreact-mode . tsx)) + ) +#+end_src +Setup tree sitter based indentation +#+begin_src emacs-lisp + ;; great tree-sitter-based indentation for typescript/tsx, css, json +;; (use-package tsi +; +;; :quelpa (tsi :fetcher github :repo "orzechowskid/tsi.el") +;; ;; define autoload definitions which when actually invoked will cause package to be loaded +;; :commands (tsi-typescript-mode tsi-json-mode tsi-css-mode) +;; :init +;; (add-hook 'typescript-mode-hook (lambda () (tsi-typescript-mode 1))) +;; (add-hook 'json-mode-hook (lambda () (tsi-json-mode 1))) +;; (add-hook 'css-mode-hook (lambda () (tsi-css-mode 1))) +;; (add-hook 'scss-mode-hook (lambda () (tsi-scss-mode 1)))) +#+end_src +*** tsx +#+begin_src emacs-lisp + (use-package coverlay + :ensure t) + + (use-package origami + :ensure t) + + (use-package css-in-js-mode + :straight '(css-in-js-mode + :type git + :host github + :repo "orzechowskid/tree-sitter-css-in-js")) + + (use-package corfu + :ensure t) + + (setq eglot-server-programs '()) + (use-package tsx-mode + :straight '(tsx-mode + :type git + :host github + :repo "orzechowskid/tsx-mode.el" + :branch "emacs29") + :config + (add-to-list 'auto-mode-alist '("\\.tsx?\\'" . tsx-mode))) +#+end_src +*** webmode +#+begin_src emacs-lisp + (use-package web-mode + :ensure t + :config + ;;(add-to-list 'auto-mode-alist '("\\.tsx?\\'" . web-mode)) + ) +#+end_src * Settings ** Backup files #+begin_src emacs-lisp (setq + make-backup-files nil backup-directory-alist '(("." . "/tmp/")) auto-save-file-name-transforms '((".*" "/tmp/" t))) #+end_src +** Startup screen +#+begin_src emacs-lisp + (setq inhibit-splash-screen t) +#+end_src +** Tabs +#+begin_src emacs-lisp + (setq-default tab-width 4) +#+end_src * Evil ** Base Functions #+begin_src emacs-lisp @@ -130,8 +239,14 @@ Consel *** Configure #+begin_src emacs-lisp (defun setup-evil-mode () - (evil-define-key 'insert global-map (kbd "C-SPC") 'company-complete) - ) + (evil-define-key 'insert global-map (kbd "C-SPC") 'company-complete) + (evil-define-key 'normal global-map + (kbd "]e") 'flycheck-next-error + (kbd "[e") 'flycheck-previous-error + (kbd "gd") 'lsp-find-definition + (kbd "K") 'lsp-ui-doc-show + (kbd "gr") 'lsp-find-references) + ) #+end_src *** Install #+begin_src emacs-lisp @@ -152,12 +267,26 @@ Consel (evil-leader/set-leader "") (evil-leader/set-key "f" 'find-file - "g" 'magit + "SPC" 'projectile-find-file "d" 'dired + "b" 'ivy-switch-buffer + "c" '("config" . (keymap)) - "cf" '("config file" . (lambda ()(interactive) (find-file (expand-file-name "~/.emacs.d/settings.org"))))) - (evil-leader/set-key-for-mode 'org-mode "is" 'org-insert-structure-template) - (evil-leader/set-key-for-mode 'org-mode "e" 'org-edit-src-code) + "cf" '("config file" . (lambda ()(interactive) (find-file (expand-file-name "~/.emacs.d/settings.org")))) + "c+" '("config file" . (lambda ()(interactive) (text-scale-increase))) + "c-" '("config file" . (lambda ()(interactive) (text-scale-decrease))) + + "p" '("project" . (keymap)) + "pf" '("file" . (lambda () (interactive)(projectile-find-file))) + + "g" '("goto" . (keymap)) + "gg" 'magit + "gd" '("Goto Definition" . (lambda () (interactive)(evil-goto-definition))) + + ) + (evil-leader/set-key-for-mode 'org-mode + "is" 'org-insert-structure-template + "e" 'org-edit-src-code) ) #+end_src ** Org Mode @@ -174,8 +303,9 @@ Consel (use-package projectile :ensure t :config - (projectile-mode +1) - (define-key projectile-mode-map (kbd "C-p") 'projectile-command-map)) + (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map) + ;;(setq projectile-git-command "git-ls-all-files") + (projectile-mode +1)) #+end_src ** Magit #+begin_src emacs-lisp @@ -183,6 +313,7 @@ Consel :ensure t) #+end_src Auto complete +* LSP ** Company #+begin_src emacs-lisp (use-package company @@ -190,4 +321,159 @@ Auto complete :config (global-company-mode)) #+end_src +*** Comapny box +#+begin_src emacs-lisp + (use-package company-box + :ensure t + :hook (company-mode . company-box-mode)) +#+end_src ** LSP +Set up lsp +#+begin_src emacs-lisp + (use-package lsp-mode + :init + (setq lsp-keymap-prefix "C-c l") + :ensure t + :hook ( + ;;(XXX-mode . lsp-mode) + + ;;(typescriptreact-mode . lsp-mode) + (typescript-mode . lsp-mode) + (tsx-mode . lsp-mode) + (tsx-ts-mode . lsp-mode) + (web-mode . lsp-mode) + + (lsp-mode . lsp-enable-which-key-integration)) + :commands lsp + :config + (add-hook 'tsx-mode-hook 'lsp-mode)) +#+end_src +Set up lsp ui +#+begin_src emacs-lisp + (use-package lsp-ui + :ensure t + :commands lsp-ui-mode + :config + ;; sideline + (setq lsp-ui-sideline-show-diagnostics nil) + (setq lsp-ui-sideline-show-code-actions nil) + (setq lsp-ui-sideline-show-hover t) + (setq lsp-ui-sideline-delay 0) + ;; ui-doc + (setq lsp-ui-doc-enable t) + (setq lsp-ui-doc-delay 1) + (setq lsp-ui-doc-show-with-cursor t) + (setq lsp-ui-doc-show-with-mouse nil) + (setq lsp-ui-doc-position 'at-point) + ) +#+end_src +Set up ivy +#+begin_src emacs-lisp + (use-package lsp-ivy + :ensure t + :commands lsp-ivy-workspace-symbol) +#+end_src +** Flycheck +#+begin_src emacs-lisp + (use-package flycheck + :ensure t + :init(global-flycheck-mode) + :config + ;; Show indicators in the left margin + (setq flycheck-indication-mode 'left-margin) + + ;; Adjust margins and fringe widths… + (defun my/set-flycheck-margins () + (setq left-fringe-width 0 right-fringe-width 0 + left-margin-width 2 right-margin-width 0) + (setq flycheck-default-margin-str "🆓") + (flycheck-refresh-fringes-and-margins)) + + (flycheck-define-error-level 'error + :severity 100 + :compilation-level 2 + :overlay-category 'flycheck-error-overlay + :margin-spec (flycheck-make-margin-spec "❤️" 'flycheck-fringe-error) + :fringe-bitmap 'flycheck-fringe-bitmap-double-arrow + :fringe-face 'flycheck-fringe-error + :error-list-face 'flycheck-error-list-error) + + (flycheck-define-error-level 'warning + :severity 10 + :compilation-level 1 + :overlay-category 'flycheck-warning-overlay + :margin-spec (flycheck-make-margin-spec "😞" 'flycheck-fringe-warning) + :fringe-bitmap'flycheck-fringe-bitmap-double-arrow + :fringe-face 'flycheck-fringe-warning + :error-list-face 'flycheck-error-list-warning) + + (flycheck-define-error-level 'info + :severity -10 + :compilation-level 0 + :overlay-category 'flycheck-info-overlay + :margin-spec (flycheck-make-margin-spec "🅰" 'flycheck-fringe-info) + :fringe-bitmap'flycheck-fringe-bitmap-double-arrow + :fringe-face 'flycheck-fringe-info + :error-list-face 'flycheck-error-list-info) + + (flycheck-define-error-level 'lsp-flycheck-info-unnecessary + :severity -10 + :compilation-level 0 + :overlay-category 'flycheck-info-overlay + :margin-spec (flycheck-make-margin-spec "🅰" 'flycheck-fringe-info) + :fringe-bitmap'flycheck-fringe-bitmap-double-arrow + :fringe-face 'flycheck-fringe-info + :error-list-face 'flycheck-error-list-info) + + (flycheck-define-error-level 'hint + :severity -20 + :compilation-level -1 + :overlay-category 'flycheck-info-overlay + :margin-spec (flycheck-make-margin-spec "🆓" 'flycheck-fringe-info) + :fringe-bitmap'flycheck-fringe-bitmap-double-arrow + :fringe-face 'flycheck-fringe-info + :error-list-face 'flycheck-error-list-info) + + ;; …every time Flycheck is activated in a new buffer + (add-hook 'flycheck-mode-hook #'my/set-flycheck-margins) + ) +#+end_src +Fly check post tip +#+begin_src emacs-lisp +;; (use-package flycheck-pos-tip +;; :ensure t +;; :hook (flycheck-mode . flycheck-pos-tip-mode)) +#+end_src +Fly check inline +#+begin_src emacs-lisp + (use-package flycheck-posframe + :ensure t + :after flycheck + :hook (flycheck-mode . flycheck-posframe-mode) + :config + (flycheck-posframe-configure-pretty-defaults) + (setq flycheck-posframe-error-prefix "☣️❤️") + (setq flycheck-posframe-warning-prefix "🅰😞") + (setq flycheck-posframe-info-prefix "🅰🆓") + (set-face-attribute 'flycheck-posframe-error-face + nil + :inherit nil + :foreground "#b72c01") + (set-face-attribute 'flycheck-posframe-warning-face + nil + :foreground "#b77401") + + (set-face-attribute 'flycheck-posframe-info-face + nil + :foreground "#0156b7") + + (setq flycheck-posframe-border-width 3) + (set-face-attribute 'flycheck-posframe-border-face + nil + :foreground "#dc752f") + (add-to-list 'flycheck-posframe-inhibit-functions #'(lambda () company-backend))) +#+end_src + + + +