Skip to content

Instantly share code, notes, and snippets.

@kfischer-okarin
Last active November 15, 2021 09:54
Show Gist options
  • Save kfischer-okarin/39b2a8440c5940e52f2d74c2607432bd to your computer and use it in GitHub Desktop.
Save kfischer-okarin/39b2a8440c5940e52f2d74c2607432bd to your computer and use it in GitHub Desktop.
My Emacs Configuration
(defvar init-file-location "~/.emacs.d/init.el")
(defun find-init-file ()
(interactive)
(find-file init-file-location))
(defun reload-init-file ()
(interactive)
(load-file init-file-location))
(global-set-key (kbd "<A-tab>") 'other-window)
(global-set-key (kbd "s-q") 'delete-window)
(global-set-key (kbd "s-s") 'save-buffer)
(global-set-key (kbd "s-/") 'comment-line)
(global-set-key (kbd "C-c i") 'find-init-file)
(global-set-key (kbd "C-c r") 'reload-init-file)
(defun duplicate-line()
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
(open-line 1)
(next-line 1)
(yank)
)
(global-set-key (kbd "s-c") 'duplicate-line)
;;; ----------------------------------------------------------------------
;;; Packages
;;; ----------------------------------------------------------------------
; Straight.el package manager setup
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(straight-use-package 'company)
(add-hook 'after-init-hook 'global-company-mode)
(straight-use-package 'dart-mode)
(straight-use-package 'enh-ruby-mode)
(add-to-list 'auto-mode-alist
'("\\(?:\\.rb\\|ru\\|rake\\|thor\\|jbuilder\\|gemspec\\|podspec\\|/\\(?:Gem\\|Rake\\|Cap\\|Thor\\|Vagrant\\|Guard\\|Pod\\)file\\)\\'" . enh-ruby-mode))
(add-to-list 'interpreter-mode-alist
'("ruby" . enh-ruby-mode))
(straight-use-package 'exec-path-from-shell)
(defun exec-path-from-shell-when-mac ()
(when (eq window-system 'mac) (exec-path-from-shell-initialize)))
(add-hook 'after-init-hook 'exec-path-from-shell-when-mac)
(straight-use-package 'eyebrowse)
(global-set-key (kbd "<s-left>") 'eyebrowse-prev-window-config)
(global-set-key (kbd "<s-right>") 'eyebrowse-next-window-config)
(global-set-key (kbd "s-w") 'eyebrowse-close-window-config)
(global-set-key (kbd "s-0") 'eyebrowse-switch-to-window-config-0)
(global-set-key (kbd "s-1") 'eyebrowse-switch-to-window-config-1)
(global-set-key (kbd "s-2") 'eyebrowse-switch-to-window-config-2)
(global-set-key (kbd "s-3") 'eyebrowse-switch-to-window-config-3)
(global-set-key (kbd "s-4") 'eyebrowse-switch-to-window-config-4)
(global-set-key (kbd "s-5") 'eyebrowse-switch-to-window-config-5)
(global-set-key (kbd "s-6") 'eyebrowse-switch-to-window-config-6)
(global-set-key (kbd "s-7") 'eyebrowse-switch-to-window-config-7)
(global-set-key (kbd "s-8") 'eyebrowse-switch-to-window-config-8)
(global-set-key (kbd "s-9") 'eyebrowse-switch-to-window-config-9)
(straight-use-package 'flycheck)
(flycheck-mode)
(setf (flycheck-checker-get 'ruby-reek 'working-directory) #'flycheck-ruby--find-project-root)
(setf (flycheck-checker-get 'ruby-reek 'standard-input) t)
(setf (flycheck-checker-get 'ruby-reek 'command)
'("reek" "--format" "json" (config-file "--config" flycheck-reekrc) "--stdin-filename" source-original))
(straight-use-package 'helm)
(helm-mode t)
(straight-use-package 'helm-ag)
(straight-use-package 'helm-projectile)
(global-set-key (kbd "M-x") #'helm-M-x)
(global-set-key (kbd "s-a") #'helm-apropos)
(helm-projectile-on)
(straight-use-package 'hover)
(straight-use-package 'lsp-dart)
(add-hook 'dart-mode-hook 'lsp)
(straight-use-package 'lsp-mode)
(straight-use-package 'lsp-treemacs)
(straight-use-package 'lsp-ui)
(straight-use-package 'magit)
(global-set-key (kbd "s-g") 'magit-file-dispatch)
(global-set-key (kbd "s-G") 'magit-dispatch)
(straight-use-package 'markdown-mode)
(straight-use-package 'markdown-preview-mode)
(straight-use-package 'projectile)
(projectile-mode 1)
(defvar dragonruby-path "~/workspace-personal/dragonruby/current/dragonruby")
(defun dragonruby-related-files (game-prefix path)
(let ((tests-prefix (concat game-prefix "/tests")))
(if (string-equal (substring path 0 (length tests-prefix)) tests-prefix)
(list :impl (concat game-prefix (substring path (length tests-prefix))))
(list :test (concat tests-prefix (substring path (length game-prefix)))))))
(projectile-register-project-type 'dragonruby-game '("game/app/main.rb")
:run (concat dragonruby-path " game")
:test (concat dragonruby-path " game --test tests/main.rb")
:related-files-fn (apply-partially 'dragonruby-related-files "game"))
(projectile-register-project-type 'dragonruby-app '("app/app/main.rb")
:run (concat dragonruby-path " app")
:test (concat dragonruby-path " app --test tests/main.rb")
:related-files-fn (apply-partially 'dragonruby-related-files "app"))
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
;(global-set-key (kbd "<s-right>") 'projectile-next-project-buffer)
;(global-set-key (kbd "<s-left>") 'projectile-previous-project-buffer)
(straight-use-package 'treemacs)
(global-set-key (kbd "s-t") 'treemacs)
; Start and quit immediately just to initialize
(treemacs)
(treemacs)
(straight-use-package 'vterm)
(straight-use-package 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-mode))
(straight-use-package 'zenburn-theme)
(defun load-zenburn-if-terminal ()
(when (eq window-system nil)
(load-theme 'zenburn)))
(add-hook 'after-init-hook 'load-zenburn-if-terminal)
;;; ----------------------------------------------------------------------
;;; Mode-specific settings
;;; ----------------------------------------------------------------------
(defun kfischer-prog-settings ()
(flycheck-mode t)
(whitespace-mode t)
(display-fill-column-indicator-mode t)
(setq display-line-numbers t))
(add-hook 'prog-mode-hook #'kfischer-prog-settings)
(defun gemfile-in-project-root-p ()
(file-exists-p (expand-file-name "Gemfile" (projectile-project-root))))
(defun convert-to-bundle-exec-call-if-necessary (command)
(let ((executable (car command)) (rest (cdr command)))
(cond
((string-match-p "rubocop" executable) (append '("bundle" "exec" "rubocop") rest))
((string-match-p "reek" executable) (append '("bundle" "exec" "reek") rest))
(t command))))
;; (defun convert-absolute-path-to-relative-path (command)
(defun kfischer-ruby-flycheck-command-wrapper (command)
(convert-to-bundle-exec-call-if-necessary command))
(defun kfischer-ruby-settings ()
(setq flycheck-checker 'ruby-rubocop)
(if (gemfile-in-project-root-p)
(setq flycheck-command-wrapper-function 'kfischer-ruby-flycheck-command-wrapper)))
(add-hook 'enh-ruby-mode-hook #'kfischer-ruby-settings)
(defun prepend-vendor-bundle-to-exec-path (root)
(let ((exec-path-without-vendor-bundle
(seq-remove (apply-partially 'string-match-p "vendor/bundle") exec-path))
(vendor-bundle-in-root (expand-file-name "vendor/bundle/ruby/2.7.0/bin" root)))
(setq exec-path (cons vendor-bundle-in-root exec-path-without-vendor-bundle))))
(defun treemacs-switch-or-create-workspace (name)
(let ((switch-result (treemacs-do-switch-workspace name)))
(pcase switch-result
(`('success ,workspace)
(treemacs-do-create-workspace name)
(treemacs-do-switch-workspace name)
(treemacs-do-add-project-to-workspace (projectile-project-root) (projectile-project-name))
(_ nil)))))
(defun kfischer-projectile-project-settings ()
(prepend-vendor-bundle-to-exec-path (projectile-project-root))
(treemacs-switch-or-create-workspace (projectile-project-name)))
(add-hook 'projectile-after-switch-project-hook #'kfischer-projectile-project-settings)
;;; ----------------------------------------------------------------------
;;; Functions defined specifically to be used in customize
;;; ----------------------------------------------------------------------
(defun not-in-workspace-p (path)
(unless (string-match-p "workspace" path) t))
(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.
'(column-number-mode t)
'(company-minimum-prefix-length 1 nil nil "For dart completion")
'(compilation-read-command nil)
'(compilation-scroll-output t)
'(custom-safe-themes
'("ea5822c1b2fb8bb6194a7ee61af3fe2cc7e2c7bab272cbb498a0234984e1b2d9" default))
'(eyebrowse-mode t)
'(eyebrowse-wrap-around t)
'(fill-column 120)
'(global-hl-line-mode t)
'(helm-completion-style 'helm-fuzzy)
'(indent-tabs-mode nil)
'(lsp-lens-enable t)
'(lsp-signature-auto-activate nil)
'(mac-command-modifier 'super)
'(mac-mouse-wheel-mode t)
'(mac-option-modifier '(:ordinary meta :function alt :mouse alt))
'(projectile-create-missing-test-files t)
'(projectile-ignored-project-function 'not-in-workspace-p)
'(safe-local-variable-values '((flycheck-mode)))
'(standard-indent 2)
'(tab-width 2)
'(whitespace-style '(face trailing empty)))
;;; Variable settings for Flutter Development
(setq gc-cons-treshold (* 100 1024 1024)
read-process-output-max (* 1024 1024))
(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.
'(eyebrowse-mode-line-active ((t (:background "light green")))))
;; Local Variables:
;; flycheck-mode: nil
;; End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment