Skip to content

Instantly share code, notes, and snippets.

@oizhaolei
Last active March 13, 2022 13:29
Show Gist options
  • Save oizhaolei/00d9cba6eff31ccd80fb948114c8fa34 to your computer and use it in GitHub Desktop.
Save oizhaolei/00d9cba6eff31ccd80fb948114c8fa34 to your computer and use it in GitHub Desktop.
config.el for purcell
;;; init-local.el --- Settings and helpers for package.el -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(setq url-proxy-services
'(("no_proxy" . "^\\(localhost\\|10.*\\)")
("http" . "localhost:55776")
("https" . "localhost:55776")))
(desktop-save-mode nil)
(set-frame-position (selected-frame) 80 0)
(set-frame-size (selected-frame) 260 83)
;;; Code:
(global-set-key (kbd "C-c C-m") 'imenu)
(global-set-key (kbd "C-x f") 'projectile-find-file)
(global-set-key (kbd "C--") 'er/contract-region)
(global-undo-tree-mode)
(magit-todos-mode)
(require-package 'web-mode)
(require-package 'tern-auto-complete)
(require-package 'tern)
(require-package 'smartparens)
(require-package 'org-tree-slide)
(require-package 'hydra)
(require-package 'ivy-hydra)
(require-package 'counsel-tramp)
(require-package 'counsel-etags)
(require-package 'company-tern)
(require-package 'auto-complete)
(require-package 'undo-tree)
(require-package 'tide)
(require-package 'ag)
(require-package 'window-numbering)
(window-numbering-mode)
(require-package 'rjsx-mode)
;;; string-inflection
(require-package 'string-inflection)
(global-set-key (kbd "C-c C-u") 'string-inflection-all-cycle)
(add-hook 'ruby-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-u") 'string-inflection-ruby-style-cycle)))
(add-hook 'java-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-u") 'string-inflection-java-style-cycle)))
(add-hook 'python-mode-hook
'(lambda ()
(local-set-key (kbd "C-c C-u") 'string-inflection-python-style-cycle)))
;;; yas
(require-package 'yasnippet)
(yas-global-mode 1)
(require-package 'yasnippet-snippets)
(global-set-key (kbd "C-c C-t") 'yas-describe-tables)
;; neotree
(require-package 'neotree)
(global-set-key (kbd "C-c C-n") 'neotree-toggle)
;; iedit
(require-package 'iedit)
(global-set-key (kbd "C-c ;") 'iedit-mode)
;; crux
(require-package 'crux)
(global-set-key (kbd "C-c o") 'crux-open-with)
(global-set-key (kbd "C-c C-e") 'crux-eval-and-replace)
;; ivy
(require-package 'ivy)
(global-set-key (kbd "C-c s") 'swiper)
;;(global-set-key (kbd "C-c k") 'counsel-ag)
(global-set-key (kbd "C-c l") 'counsel-locate)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
;; emmet
(require-package 'emmet-mode)
(require-package 'gist)
;; twitter
(require-package 'twittering-mode)
(setq twittering-proxy-use t)
(setq twittering-proxy-server "localhost")
;; google translate
(require-package 'google-translate)
(global-set-key "\C-ct" 'google-translate-at-point)
;; tide
(defun setup-tide-mode ()
"Setup tide mode."
(interactive)
(tide-setup)
(flycheck-mode +1)
(setq flycheck-check-syntax-automatically '(save mode-enabled))
(eldoc-mode +1)
(tide-hl-identifier-mode +1)
(company-mode +1))
;; aligns annotation to the right hand side
(setq company-tooltip-align-annotations t)
;; formats the buffer before saving
(add-hook 'before-save-hook 'tide-format-before-save)
(add-hook 'typescript-mode-hook #'setup-tide-mode)
(require-package 'web-mode)
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
(add-hook 'web-mode-hook
(lambda ()
(when (string-equal "tsx" (file-name-extension buffer-file-name))
(setup-tide-mode))))
;; enable typescript-tslint checker
(eval-after-load 'flycheck
'(progn
(flycheck-add-mode 'typescript-tslint 'web-mode)))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
(add-hook 'web-mode-hook
(lambda ()
(when (string-equal "jsx" (file-name-extension buffer-file-name))
(setup-tide-mode))))
;; configure jsx-tide checker to run after your default jsx checker
(flycheck-add-mode 'javascript-eslint 'web-mode)
(flycheck-add-next-checker 'javascript-eslint 'jsx-tide 'append)
;;
(defun kill-all-buffers ()
"Kill all buffers."
(interactive)
(dolist (buffer (buffer-list))
(kill-buffer buffer)))
(defun my/select-inside-quotes ()
"Select text between double/single straight quotes on each side of cursor."
(interactive)
(let (p1 p2)
(skip-chars-backward "^[\"']")
(setq p1 (point))
(skip-chars-forward "^[\"']")
(setq p2 (point))
(goto-char p1)
(push-mark p2)
(setq mark-active t)))
(defun my/select-outside-quotes ()
"Select text between double/single straight quotes on each side of cursor."
(interactive)
(let (p1 p2)
(skip-chars-backward "^[\"']")
(setq p1 (- (point) 1))
(skip-chars-forward "^[\"']")
(setq p2 (+ (point) 1))
(goto-char p1)
(push-mark p2)
(setq mark-active t)))
(defun my/today ()
"Out put current date."
(interactive)
(insert (format-time-string "%Y-%m-%d"))
)
(global-set-key (kbd "C-c m .") 'my/today)
(defun my/js-console-log-region ()
"Write console.log of curent region to new line."
(interactive)
(let (curr)
(setq curr (thing-at-point 'word))
(end-of-line)
(newline)
(insert (format "console.log('%s:', %s);" curr curr))
))
(global-set-key (kbd "C-c m c") 'my/js-console-log-region)
(global-set-key (kbd "C-c m b") 'crux-create-scratch-buffer)
(provide 'init-local)
;;; init-local ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment