Skip to content

Instantly share code, notes, and snippets.

@sunilw
Created March 9, 2022 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunilw/a36c28d177335e78bd97d5a2c8c3b286 to your computer and use it in GitHub Desktop.
Save sunilw/a36c28d177335e78bd97d5a2c8c3b286 to your computer and use it in GitHub Desktop.
;; init.el --- Spacemacs Initialization File -*- no-byte-compile: t -*-
;;
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; Without this comment emacs25 adds (package-initialize) here
;; (package-initialize)
;; Avoid garbage collection during startup.
;; see `SPC h . dotspacemacs-gc-cons' for more info
(defconst emacs-start-time (current-time))
(setq gc-cons-threshold 402653184 gc-cons-percentage 0.6)
(load (concat (file-name-directory load-file-name)
"core/core-versions")
nil (not init-file-debug))
(load (concat (file-name-directory load-file-name)
"core/core-load-paths")
nil (not init-file-debug))
(load (concat spacemacs-core-directory "core-dumper")
nil (not init-file-debug))
;; Remove compiled core files if they become stale or Emacs version has changed.
(load (concat spacemacs-core-directory "core-compilation")
nil (not init-file-debug))
(load spacemacs--last-emacs-version-file t (not init-file-debug))
(when (or (not (string= spacemacs--last-emacs-version emacs-version))
(spacemacs//dir-contains-stale-byte-compiled-files-p
spacemacs-core-directory))
(spacemacs//remove-byte-compiled-files-in-dir spacemacs-core-directory))
;; Update saved Emacs version.
(unless (string= spacemacs--last-emacs-version emacs-version)
(spacemacs//update-last-emacs-version))
(if (not (version<= spacemacs-emacs-min-version emacs-version))
(error (concat "Your version of Emacs (%s) is too old. "
"Spacemacs requires Emacs version %s or above.")
emacs-version spacemacs-emacs-min-version)
;; Disable file-name-handlers for a speed boost during init
(let ((file-name-handler-alist nil))
(require 'core-spacemacs)
(spacemacs/dump-restore-load-path)
(configuration-layer/load-lock-file)
(spacemacs/init)
(configuration-layer/stable-elpa-init)
(configuration-layer/load)
(spacemacs-buffer/display-startup-note)
(spacemacs/setup-startup-hook)
(spacemacs/dump-eval-delayed-functions)
(when (and dotspacemacs-enable-server (not (spacemacs-is-dumping-p)))
(require 'server)
(when dotspacemacs-server-socket-dir
(setq server-socket-dir dotspacemacs-server-socket-dir))
(unless (server-running-p)
(message "Starting a server...")
(server-start)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Sunil's own configs start from here
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path "~/.emacs.d/lisp")
(require 'helm-config)
(global-set-key (kbd "C-<tab>") 'helm-mini)
(savehist-mode 1)
(recentf-mode 1)
(global-linum-mode 1)
(global-auto-revert-mode t)
(global-set-key (kbd "<tab>") 'yas-expand)
(setq yas/prompt-functions '(yas/x-prompt yas/dropdown-prompt))
;; https://stackoverflow.com/questions/30456233/is-it-possible-to-make-autocomplete-to-complete-a-yasnippet-in-emacs
(eval-after-load "auto-complete"
'(add-to-list 'ac-sources 'ac-source-yasnippet))
(setq-default dotspacemacs-configuration-layers
'((auto-completion :variables
auto-completion-enable-snippets-in-popup t)))
(add-hook 'yasnippet-mode-hook
(lambda ()
(local-set-key [f1] 'help-for-help)))
(add-hook 'scss-mode-hook 'yas-minor-mode)
(add-hook 'php-mode-hook 'yas-minor-mode)
(add-hook 'web-mode-hook 'yas-minor-mode)
(add-hook 'rjsx-mode-hook 'yas-minor-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Try to set up web-mode as the default mode for php
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; You can configure web-mode to use php instead like this:
(with-eval-after-load "lsp"
(assq-delete-all 'web-mode lsp-language-id-configuration)
(add-to-list 'lsp-language-id-configuration '(web-mode . "php")))
;; and then associate php files with web-mode and start lsp mode. (elisp newbie here as well)
(add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))
(add-hook 'web-mode-hook #'lsp)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Lets try some yas conf
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'popup)
;; add some shotcuts in popup menu mode
(define-key popup-menu-keymap (kbd "M-n") 'popup-next)
(define-key popup-menu-keymap (kbd "TAB") 'popup-next)
(define-key popup-menu-keymap (kbd "<tab>") 'popup-next)
(define-key popup-menu-keymap (kbd "<backtab>") 'popup-previous)
(define-key popup-menu-keymap (kbd "M-p") 'popup-previous)
(defun yas/popup-isearch-prompt (prompt choices &optional display-fn)
(when (featurep 'popup)
(popup-menu*
(mapcar
(lambda (choice)
(popup-make-item
(or (and display-fn (funcall display-fn choice))
choice)
:value choice))
choices)
:prompt prompt
;; start isearch mode immediately
:isearch t
)))
(setq yas/prompt-functions '(yas/popup-isearch-prompt yas/no-prompt))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Don't automatically compile scss
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (remove-hook HOOK FUNCTION &optional LOCAL)
(setq scss-compile-at-save nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; transparency
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set-frame-parameter (selected-frame) 'alpha '(96 . 96))
(add-to-list 'default-frame-alist '(alpha . (96 . 96)))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
'(auto-revert-check-vc-info t)
'(browse-url-browser-function 'browse-url-chromium)
'(custom-safe-themes
'("f47a7e08d0dc9b0e069cec223c4b044647f3b6f26881698f1a4a39e2adce012b" "81c3de64d684e23455236abde277cda4b66509ef2c28f66e059aa925b8b12534" "b9e9ba5aeedcc5ba8be99f1cc9301f6679912910ff92fdf7980929c2fc83ab4d" "3c83b3676d796422704082049fc38b6966bcad960f896669dfc21a7a37a748fa" "698f6c799733e1f051f41ba2f2e0a9487178834ceb495b3c21e06fb999699779" default))
'(electric-pair-mode t)
'(erc-server-coding-system '(utf-8 . utf-8))
'(inhibit-startup-screen t)
'(jabber-account-list '(("") ("sunilw@chat.facebook.com")))
'(package-selected-packages
'(solaire-mode neotree dired-sidebar eev graphql magit paredit add-node-modules-path rjsx-mode region-convert company-lsp skewer-mode scss-mode restclient-test sass-mode web-mode s))
'(require-final-newline nil)
'(show-paren-mode t)
'(tabbar-background-color "gray20")
'(tabbar-separator '(0.5))
'(tabbar-use-images nil)
'(tool-bar-mode nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:family "Source Sans Pro" :foundry "adobe" :slant normal :weight light :height 162 :width normal))) nil '(nil ((t (:foreground "Green"))) t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Indent the buffer
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; indent the buffer
(defun iwb ()
"indent whole buffer"
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; erc - loud ignore
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun erc-cmd-IGNORE-LOUDLY (nick)
"Ignore NICK then mention it."
(erc-cmd-IGNORE nick)
(erc-send-message (format "ignoring you now, %s" nick)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; get lock files and autosaves out of the way
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq backup-directory-alist `(("." . "~/.saves")))
(setq backup-by-copying t)
(setq delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
(setq auto-save-file-name-transforms
`((".*" ,"~/.saves/" t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; prevent annoying "really really close buffer?" crap
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; yasnippet
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/yasnippets") )
(yas-global-mode)
(yas-reload-all)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; web mode
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun web-mode-init ()
"web-mode config."
(setq web-mode-markup-indent-offset 4)
(setq web-mode-code-indent-offset 4)
(setq web-mode-indent-style 2)
(setq web-mode-prefer-server-commenting t)
(comment-auto-fill)
(auto-complete-init)
(emmet-mode t)
(yas-minor-mode t)
(linum-mode t)
)
(add-hook 'web-mode-hook 'web-mode-init)
( add-hook 'web-mode-hook
'(lambda ()
(yas-minor-mode)
(linum-mode)
(electric-pair-mode)
(emmet-mode)
(auto-complete-mode)
)
)
(setq web-mode-ac-sources-alist
'(("css" . (ac-source-words-in-buffer ac-source-css-property))
("html" . (ac-source-words-in-buffer ac-source-abbrev))
("php" . (ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-dictionary))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; emmet
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'web-mode-hook 'emmet-mode)
(add-hook 'rhtml-mode-hook 'emmet-mode)
(add-hook 'js-mode-hook 'emmet-mode)
(add-hook 'php-mode-hook 'emmet-mode)
(add-hook 'php-mode-hook 'rjsx-mode)
(add-hook 'emmet-mode-hook (lambda () (setq emmet-indentation 2)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; erc notify
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'erc-nick-notify)
;; utf-8 always and forever
(setq erc-server-coding-system '(utf-8 ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (autoload 'erc-nick-notify-mode "erc-nick-notify" ;;
;; "Minor mode that calls `erc-nick-notify-cmd' when his nick gets ;;
;; mentioned in an erc channel" t) ;;
;; (eval-after-load 'erc '(erc-nick-notify-mode t)) ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; default browser
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "chromium-browser")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; hack config for typescript
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun dotspacemacs/user-config ()
;; ...
;; tide def func:
(defun tide-setup-hook ()
(tide-setup)
(eldoc-mode)
(tide-hl-identifier-mode +1)
(setq web-mode-enable-auto-quoting nil)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-code-indent-offset 2)
(setq web-mode-attr-indent-offset 2)
(setq web-mode-attr-value-indent-offset 2)
(setq lsp-eslint-server-command '("node" (concat (getenv "HOME") "/var/src/vscode-eslint/server/out/eslintServer.js") "--stdio"))
(set (make-local-variable 'company-backends)
'((company-tide company-files :with company-yasnippet)
(company-dabbrev-code company-dabbrev))))
)
;; hooks
(add-hook 'before-save-hook 'tide-format-before-save)
;; use rjsx-mode for .js* files except json and use tide with rjsx
(add-to-list 'auto-mode-alist '("\\.js.*$" . rjsx-mode))
(add-to-list 'auto-mode-alist '("\\.json$" . json-mode))
(add-hook 'rjsx-mode-hook 'tide-setup-hook)
;; web-mode extra config
(add-hook 'web-mode-hook 'tide-setup-hook
(lambda () (pcase (file-name-extension buffer-file-name)
("tsx" ('tide-setup-hook))
(_ (my-web-mode-hook)))))
;; (flycheck-add-mode 'typescript-tslint 'web-mode)
(add-hook 'web-mode-hook 'company-mode)
(add-hook 'web-mode-hook 'prettier-js-mode)
(add-hook 'web-mode-hook #'turn-on-smartparens-mode t)
;; typescript with jsx
;;(add-to-list 'auto-mode-alist '("\\.tsx\\'" . typescript-mode))
;; flycheck
(global-flycheck-mode)
(add-hook 'after-init-hook #'global-flycheck-mode)
;; company-mode
(global-company-mode)
;; tide settings
;; (add-hook 'text-mode-hook 'turn-on-auto-fill)
;;(add-hook 'prog-mode-hook 'hs-minor-mode)
(add-hook 'typescript-mode-hook 'auto-complete)
(add-hook 'typescript-mode-hook 'yasnippet)
(add-hook 'typescript-mode-hook 'lsp-mode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment