dotfiles/emacs/init.el

631 lines
22 KiB
EmacsLisp
Raw Normal View History

2021-06-08 09:05:42 +00:00
;;; Init.el --- Summary
;;; Commentary:
;;; Initialization
;;; Code:
(require 'package)
2019-02-14 19:58:51 +00:00
(add-to-list 'package-archives
'("MELPA" . "https://melpa.org/packages/") t)
2018-08-23 19:41:28 +00:00
(package-initialize)
2019-02-26 10:25:08 +00:00
;;; Custom
2018-08-23 19:41:28 +00:00
(defvar
haskell-language-extensions
2020-02-13 15:42:25 +00:00
(quote
("ConstraintKinds"
"DeriveAnyClass"
"DeriveGeneric"
"DerivingStrategies"
;; "DerivingVia"
"EmptyCase"
"ExplicitForAll"
"FlexibleContexts"
"FlexibleInstances"
"GADTs"
"GeneralizedNewtypeDeriving"
"KindSignatures"
"LambdaCase"
"MultiParamTypeClasses"
"MultiWayIf"
"NamedFieldPuns"
"NamedWildCards"
"OverloadedStrings"
"RecordWildCards"
"ScopedTypeVariables"
"StandaloneDeriving"
"TupleSections"
"TypeApplications"
"TypeFamilies"
"TypeSynonymInstances"
"UnicodeSyntax"
"ViewPatterns"))
"List of enabled Haskell language extensions.")
2018-08-23 19:41:28 +00:00
(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.
'(Buffer-menu-name-width 30)
2018-08-23 19:41:28 +00:00
'(agda2-program-args nil)
2020-07-23 08:25:34 +00:00
'(async-shell-command-buffer 'new-buffer)
2020-03-11 09:07:20 +00:00
'(auth-sources '("~/.authinfo.gpg" "~/.authinfo" "~/.netrc"))
2018-08-23 19:41:28 +00:00
'(blink-cursor-mode nil)
'(column-number-mode t)
'(company-tooltip-minimum-width 35)
2020-02-13 15:42:25 +00:00
'(compilation-disable-input t)
2020-03-11 09:07:20 +00:00
'(confirm-kill-emacs 'yes-or-no-p)
2019-05-14 21:56:08 +00:00
'(css-indent-offset 2)
'(custom-safe-themes
2020-05-25 07:27:59 +00:00
'("670df6cad1a732850a5d90ce2b0326969bd7596881dc1fed6b35091520a3da97" "cfca08e1a703af85a52840c6839ec6ae6568fbdf2f4f6e344fb807345fca45b8" default))
2020-07-23 08:25:34 +00:00
'(custom-search-field nil)
2020-02-13 15:42:25 +00:00
'(dashboard-set-footer nil)
'(delete-selection-mode t)
2020-02-13 15:42:25 +00:00
'(dhall-repl-executable "dhall-repl")
'(dhall-use-header-line nil)
'(dired-isearch-filenames t)
2020-03-11 09:07:20 +00:00
'(dired-use-ls-dired nil)
'(display-buffer-alist
2020-03-11 09:07:20 +00:00
'(("*Man*" display-buffer-same-window)
("*Buffer List*" display-buffer-same-window)))
2018-12-02 20:58:20 +00:00
'(echo-keystrokes 1e-10)
2020-03-11 09:07:20 +00:00
'(erc-autojoin-channels-alist '(("irc.freenode.net" "#haskell" "#data.coop")))
2019-03-26 16:06:20 +00:00
'(erc-autojoin-mode t)
'(erc-nick "fredefox")
2019-03-26 16:06:20 +00:00
'(erc-port 6667)
'(erc-prompt-for-password nil)
'(erc-server "irc.freenode.net")
'(exec-path-from-shell-check-startup-files nil)
2020-03-11 09:07:20 +00:00
'(flycheck-emacs-lisp-load-path 'inherit)
'(flycheck-ghc-language-extensions (symbol-value 'haskell-language-extensions))
'(flycheck-hlint-language-extensions (symbol-value 'haskell-language-extensions))
2020-08-27 10:07:43 +00:00
'(flycheck-idris-executable "idris2")
2020-11-08 11:39:44 +00:00
'(flycheck-javascript-eslint-executable nil)
'(forge-alist
2020-03-11 09:07:20 +00:00
'(("github.com" "api.github.com" "github.com" forge-github-repository)
("gitlab.com" "gitlab.com/api/v4" "gitlab.com" forge-gitlab-repository)
("salsa.debian.org" "salsa.debian.org/api/v4" "salsa.debian.org" forge-gitlab-repository)
("framagit.org" "framagit.org/api/v4" "framagit.org" forge-gitlab-repository)
("codeberg.org" "codeberg.org/api/v1" "codeberg.org" forge-gitea-repository)
("code.orgmode.org" "code.orgmode.org/api/v1" "code.orgmode.org" forge-gogs-repository)
("bitbucket.org" "api.bitbucket.org/2.0" "bitbucket.org" forge-bitbucket-repository)
("git.savannah.gnu.org" nil "git.savannah.gnu.org" forge-cgit*-repository)
("git.kernel.org" nil "git.kernel.org" forge-cgit-repository)
("repo.or.cz" nil "repo.or.cz" forge-repoorcz-repository)
("git.suckless.org" nil "git.suckless.org" forge-stagit-repository)
("git.sr.ht" nil "git.sr.ht" forge-srht-repository)
2020-03-11 09:07:20 +00:00
("git.data.coop" "git.data.coop/api/v1" "git.data.coop" forge-gitea-repository)))
'(global-company-mode t)
2020-07-23 08:25:34 +00:00
'(graphql-extra-headers
'(("Content-Type" . "application/json")
("Authorization" . "Basic YWRtaW5AemQtZGV2LmNvbToxMjM0NTY=")
("Host" . "mondocam.zd-dev.com")))
'(graphql-url "https://mondocam.zd-dev.com/gather/badges/graphql")
2020-03-27 09:26:28 +00:00
'(graphviz-dot-indent-width 2)
2019-02-02 12:27:42 +00:00
'(haskell-indentation-where-post-offset 0)
'(haskell-indentation-where-pre-offset 0)
2020-03-11 09:07:20 +00:00
'(haskell-language-extensions (symbol-value 'haskell-language-extensions))
2019-02-14 19:58:51 +00:00
'(haskell-tags-on-save t)
2021-06-08 09:05:42 +00:00
'(ido-case-fold nil)
'(ido-enable-dot-prefix t)
'(ido-enter-matching-directory nil)
'(ido-show-dot-for-dired t)
2020-08-27 10:07:43 +00:00
'(idris-interpreter-path "idris2")
2020-11-08 11:39:44 +00:00
'(idris-semantic-source-highlighting nil)
'(indent-tabs-mode nil)
2019-02-16 19:06:45 +00:00
'(initial-scratch-message nil)
2019-02-02 12:27:42 +00:00
'(js-indent-level 2)
2019-05-14 21:56:08 +00:00
'(js2-basic-offset 2)
2020-03-11 09:07:20 +00:00
'(js2-global-externs (list 'this))
2020-02-13 15:42:25 +00:00
'(kill-whole-line t)
2019-02-14 19:58:51 +00:00
'(line-move-visual nil)
2020-02-13 15:42:25 +00:00
'(lsp-auto-guess-root t)
2020-11-08 11:39:44 +00:00
'(lsp-ui-sideline-show-code-actions nil)
2020-05-25 07:27:59 +00:00
'(magit-diff-refine-hunk "all")
2020-03-11 09:07:20 +00:00
'(magit-display-buffer-function 'magit-display-buffer-same-window-except-diff-v1)
2019-02-26 10:25:08 +00:00
'(magit-popup-display-buffer-action nil)
2019-02-02 12:27:42 +00:00
'(markdown-command "pandoc -t html")
'(menu-bar-mode nil)
2020-03-11 09:07:20 +00:00
'(message-send-mail-function 'smtpmail-send-it)
'(mode-line-percent-position '(6 "%q"))
2019-02-26 10:25:08 +00:00
'(org-agenda-files "~/.config/orgmode/agenda_files")
2020-03-27 09:26:28 +00:00
'(org-hide-leading-stars t)
2018-08-23 19:41:28 +00:00
'(package-selected-packages
2021-06-08 09:05:42 +00:00
'(git-gutter jsonnet-mode eslint-fix nhexl-mode idris-mode realgud-trepan-ni realgud-node-inspect realgud graphviz-dot-mode rust-mode lsp forge tide origami dhall-mode docker-tramp graphql-mode enh-ruby-mode scala-mode string-inflection prettier-js quelpa typescript-mode visual-fill-column ag ripgrep fill-column-indicator rjsx-mode image+ company org-jira which-key flycheck es-mode lsp-haskell projectile exec-path-from-shell lsp-ui lsp-Mode editorconfig purescript-mode markdown-mode+ ssh-agency dash yaml-mode restart-emacs markdown-mode magit helm haskell-mode haml-mode form-feed dashboard))
'(prettier-js-args nil)
2020-05-25 07:27:59 +00:00
'(prettier-js-command "prettier")
2021-06-08 09:05:42 +00:00
'(projectile-auto-discover nil)
'(projectile-completion-system 'ido)
'(projectile-globally-ignored-directories
2020-03-11 09:07:20 +00:00
'(".idea" ".ensime_cache" ".eunit" ".git" ".hg" ".fslckout" "_FOSSIL_" ".bzr" "_darcs" ".tox" ".svn" ".stack-work" "node_modules" "vendor"))
'(projectile-globally-ignored-files '("/TAGS" "/vendor" "/.bundle" "/node_modules"))
2021-06-08 09:05:42 +00:00
'(projectile-known-projects
2020-03-11 09:07:20 +00:00
(seq-filter 'file-directory-p
2021-06-08 09:05:42 +00:00
(file-expand-wildcards "~/git/*/*")) t)
'(projectile-mode t nil (projectile))
2020-05-25 07:27:59 +00:00
'(projectile-switch-project-action 'magit-status)
2020-07-23 08:25:34 +00:00
'(projectile-use-git-grep t)
2020-03-11 09:07:20 +00:00
'(purescript-mode-hook '(turn-on-purescript-indentation))
'(recentf-max-menu-items 255)
'(recentf-mode t)
2019-05-08 07:05:23 +00:00
'(ruby-align-chained-calls t)
2019-05-14 21:56:08 +00:00
'(ruby-align-to-stmt-keywords t)
'(ruby-chained-calls t)
2019-03-27 15:12:50 +00:00
'(ruby-insert-encoding-magic-comment nil)
2020-03-11 09:07:20 +00:00
'(rust-indent-offset 2)
2020-02-13 15:42:25 +00:00
'(safe-local-eval-forms
2020-03-11 09:07:20 +00:00
'((add-hook 'write-file-hooks 'time-stamp)
(add-hook 'write-file-functions 'time-stamp)
(add-hook 'before-save-hook 'time-stamp nil t)
(add-hook 'before-save-hook 'delete-trailing-whitespace nil t)
2020-02-13 15:42:25 +00:00
(format "cd ~/git/zendesk/guide-acceptance-tests && rspec --no-color '%s'"
2020-03-11 09:07:20 +00:00
(projectile-get-relative-path-buffer))))
'(safe-local-variable-values
2021-06-08 09:05:42 +00:00
'((magit-disabled-section-inserters quote
(magit-insert-status-headers magit-insert-staged-changes forge-insert-pullreqs magit-insert-stashes magit-insert-unpulled-from-upstream magit-insert-unpushed-to-upstream-or-recent))
(magit-disabled-section-inserters quote
(magit-insert-status-headers))
(eval remove-hook 'magit-status-sections-hook 'magit-insert-unpulled-from-upstream)
(eval remove-hook 'magit-status-sections-hook 'magit-insert-stashes)
(eval remove-hook 'magit-status-sections-hook 'forge-insert-pullreqs)
(eval remove-hook 'magit-status-sections-hook 'magit-insert-staged-changes)
(eval remove-hook 'magit-status-sections-hook 'magit-insert-status-headers)
(eval remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-upstream-or-recent)
(eval local-set-key
2020-11-08 11:39:44 +00:00
(kbd "C-M-\\")
'prettier-js)
(add-to-list 'auto-mode-alist
2020-08-27 10:07:43 +00:00
'("\\.js\\'" . js-mode))
(prettier-js-mode)
2020-07-23 08:25:34 +00:00
(prettier-mode)
(compilation-disable-input . t)
2020-02-13 15:42:25 +00:00
(sgml-basic-offset . 2)
(electric-indent-mode)
2020-03-11 09:07:20 +00:00
(eval add-hook 'js2-mode-hook
2020-02-13 15:42:25 +00:00
(prettier-js-mode 0))
2020-03-11 09:07:20 +00:00
(eval add-hook 'js-mode-hook
2020-02-13 15:42:25 +00:00
(prettier-js-mode 0))
(js-mode
((prettier-js-mode . 0)))
(prettier-js-mode . 0)
(chruby-use . "2.5.5")
(magit-git-debug . 1)
(magit-refresh-verbose . 1)
(setq magit-refresh-verbose 1)
2020-03-11 09:07:20 +00:00
(eval remove-hook 'magit-refs-sections-hook 'magit-insert-tags)
(eval
2020-03-11 09:07:20 +00:00
(remove-hook 'magit-refs-sections-hook 'magit-insert-tags))
(magit-refresh-buffers)
2020-03-11 09:07:20 +00:00
(git-commit-major-mode . git-commit-elisp-text-mode)
2020-03-27 09:26:28 +00:00
(magit-status-headers-hook)))
'(scroll-bar-mode nil)
'(scroll-conservatively 101)
2019-03-26 16:06:20 +00:00
'(scroll-margin 0)
'(select-enable-clipboard t)
2020-03-11 09:07:20 +00:00
'(send-mail-function 'smtpmail-send-it)
2019-03-27 08:26:33 +00:00
'(set-mark-command-repeat-pop t)
2020-02-13 15:42:25 +00:00
'(sgml-basic-offset 1)
2020-05-25 07:27:59 +00:00
'(sh-basic-offset 2)
2020-11-08 11:39:44 +00:00
'(sh-here-document-word "eof")
2020-07-23 08:25:34 +00:00
'(show-paren-delay 0)
'(show-paren-mode t)
2019-02-16 19:06:45 +00:00
'(shr-width 80)
'(split-window-keep-point nil)
2020-07-23 08:25:34 +00:00
'(tab-line-close-button-show nil)
2019-03-27 15:12:50 +00:00
'(tags-add-tables t)
2019-02-14 19:58:51 +00:00
'(temp-buffer-resize-mode nil)
'(tool-bar-mode nil)
2020-05-25 07:27:59 +00:00
'(typescript--keywords
'("abstract" "any" "as" "async" "await" "boolean" "bigint" "break" "case" "catch" "class" "const" "constructor" "continue" "declare" "default" "delete" "do" "else" "enum" "export" "extends" "extern" "false" "finally" "for" "function" "from" "goto" "if" "implements" "import" "in" "instanceof" "interface" "keyof" "let" "module" "namespace" "never" "new" "null" "number" "object" "of" "private" "protected" "public" "readonly" "return" "static" "string" "super" "switch" "this" "throw" "true" "try" "type" "typeof" "unknown" "var" "void" "while"))
2020-02-13 15:42:25 +00:00
'(typescript-indent-level 2)
2019-02-14 19:58:51 +00:00
'(vc-follow-symlinks nil)
2021-06-08 09:05:42 +00:00
'(warning-suppress-log-types '((comp)))
2020-03-11 09:07:20 +00:00
'(which-key-idle-delay 1e-05)
'(window-combination-resize t)
2020-11-08 11:39:44 +00:00
'(window-resize-pixelwise t)
'(yaml-backspace-function 'delete-backward-char))
2018-08-23 19:41:28 +00:00
2019-05-14 21:56:08 +00:00
;;;; MAC setup
(defun set-xdg-variables ()
"Set the XDG base directory variables to sane defaults."
(setenv "XDG_CONFIG_HOME" (substitute-in-file-name "$HOME/.config"))
(setenv "XDG_DATA_HOME" (substitute-in-file-name "$HOME/.local/share"))
(setenv "XDG_CACHE_HOME" (substitute-in-file-name "$HOME/.cache")))
(defun load-monokai ()
"Load the monokai dark theme."
(add-to-list 'custom-theme-load-path
(substitute-in-file-name
"$XDG_CONFIG_HOME/emacs/lisp/monokai-dark-theme/"))
(load-theme 'monokai-dark))
2019-05-14 21:56:08 +00:00
(defun x11-shim ()
"Replace some behaviour otherwise handled by other system services."
;; (load-theme 'monokai-dark)
;; TODO Why is this not handled by the magic with the load-path above?
(set-xdg-variables)
(load-monokai))
2019-05-14 21:56:08 +00:00
;;; Needed on MAC because we're not using Xresources :(
(if (eq window-system 'ns)
2019-05-14 21:56:08 +00:00
(x11-shim))
2019-02-26 10:25:08 +00:00
;;;; Additional packages
;;;; Maybe we should use qelpa to mangage these.
2019-05-15 00:02:42 +00:00
(defvar extra-libs-root (substitute-in-file-name "$XDG_CONFIG_HOME/emacs/lisp/"))
(defvar additional-packages
2021-06-08 09:05:42 +00:00
'(
;; (agda2-mode . "agda-mode/")
2019-05-15 07:19:03 +00:00
(psc-ide . "psc-ide/")
2019-05-15 00:02:42 +00:00
;; (org-jira . "org-jira/")
(jira . "jira/")
(spark . "spark/")
2020-02-13 15:42:25 +00:00
(chruby . "chruby/")
(ruby-trace-mode . "ruby-trace-mode/")
(js2-globals . "js2-globals/")
(datadog . "datadog/")
2020-03-27 09:26:28 +00:00
(solargraph . "solargraph/")
2020-02-13 15:42:25 +00:00
(zdi . "zdi/")))
2019-05-15 00:02:42 +00:00
(defun load-additional-packages ()
"Load the additional packages as specified by additional-packages."
(dolist (spec additional-packages)
(let* ((package (car spec))
(package-path (cdr spec))
(path (concat extra-libs-root package-path)))
(add-to-list 'load-path path)
(require package))))
(load-additional-packages)
(defun load-additional-themes ()
"Load additional themes."
2019-05-23 18:16:30 +00:00
(add-to-list 'custom-theme-load-path (concat extra-libs-root "inheritance-theme/"))
2019-05-15 00:02:42 +00:00
(load-theme 'inheritance))
(load-additional-themes)
2018-08-23 19:41:28 +00:00
2020-03-11 09:07:20 +00:00
;; (quelpa '(lsp :url "git@github.com:emacs-lsp/lsp-mode.git" :fetcher git :commit "026ad0edf93e1a9e1d7927635a2bb431874541c5"))
2019-02-16 19:06:45 +00:00
;; (require 'lsp)
;; Shame! `lsp-ui` is emitting:
;; Eager macro-expansion failure: (wrong-type-argument listp kind)
;; (require 'lsp-ui)
;; (require 'lsp-haskell)
;; (add-hook 'lsp-mode-hook 'lsp-ui-mode)
;; (add-hook 'haskell-mode-hook #'lsp)
2020-02-13 15:42:25 +00:00
;; (require 'lsp-mode)
;; (add-hook 'haskell-mode-hook #'lsp)
;; (setq lsp-prefer-flymake nil)
;; (require 'lsp-ui)
;; (lsp-ui-flycheck-enable t)
;; (require 'lsp-haskell)
;;;; Faces
(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.
2020-08-27 10:07:43 +00:00
'(compilation-info ((t (:inherit link))))
2020-07-23 08:25:34 +00:00
'(compilation-mode-line-exit ((t (:inherit compilation-info :weight bold))))
'(compilation-mode-line-fail ((t (:inherit compilation-error :weight bold))))
2020-02-13 15:42:25 +00:00
'(enh-ruby-heredoc-delimiter-face ((t (:inherit font-lock-string-face))))
'(enh-ruby-op-face ((t (:inherit font-lock-variable-name-face))))
'(enh-ruby-string-delimiter-face ((t (:inherit font-lock-string-face))))
'(erm-syn-errline ((t (:inherit flycheck-error))))
'(erm-syn-warnline ((t (:inherit flycheck-warning))))
2020-08-27 10:07:43 +00:00
'(error ((t (:foreground "Pink" :weight bold))))
'(fixed-pitch-serif ((t (:family "Monospace Serif"))))
2019-05-14 21:56:08 +00:00
'(font-lock-comment-face ((t (:foreground "chocolate1"))))
2021-06-08 09:05:42 +00:00
'(ido-first-match ((t (:inherit completions-common-part))))
'(ido-only-match ((t (:inherit completions-common-part))))
'(ido-subdir ((t nil)))
2020-08-27 10:07:43 +00:00
'(isearch ((t (:background "palevioletred2" :foreground "white"))))
2020-02-13 15:42:25 +00:00
'(magit-diff-hunk-heading ((t (:inherit lazy-highlight))))
'(magit-diff-hunk-heading-highlight ((t (:inherit highlight))))
2020-08-27 10:07:43 +00:00
'(magit-mode-line-process-error ((t (:inherit error))))
2019-05-14 21:56:08 +00:00
'(region ((t (:background "#285b89"))))
'(success ((t (:foreground "Green3" :weight bold)))))
2018-08-23 19:41:28 +00:00
;;;; Captain Hook
(global-set-key (kbd "C-x C-r") 'recentf-open-files)
(global-unset-key (kbd "s-q"))
2020-02-13 15:42:25 +00:00
(global-unset-key (kbd "C-x C-l")) ;; downcase-region
2020-05-25 07:27:59 +00:00
(global-set-key (kbd "C-<left>") 'previous-buffer)
(global-set-key (kbd "C-<right>") 'next-buffer)
(global-set-key (kbd "C-c C-c") 'compile)
2019-03-26 16:06:20 +00:00
(global-set-key (kbd "C-x r v") 'revert-buffer)
(add-hook 'text-mode-hook
2019-03-27 15:12:50 +00:00
(lambda ()
2019-05-08 07:05:23 +00:00
(toggle-word-wrap t)
2019-03-27 15:12:50 +00:00
(recentf-mode)
(flyspell-mode)))
2020-02-13 15:42:25 +00:00
(add-hook 'yaml-mode-hook
(lambda ()
2020-11-08 11:39:44 +00:00
(flyspell-mode -1)
(local-set-key (kbd "DEL") 'delete-backward-char)))
2020-02-13 15:42:25 +00:00
2020-07-23 08:25:34 +00:00
(defvar html--html-template (concat
"<head>\n"
" <title>%s</title>\n"
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
" </head>\n"
" <body>\n"
" <main>\n"
" <h1>%s</h1>\n"
" </main>\n"
" </body>"))
(require 'sgml-mode)
2019-05-08 07:05:23 +00:00
(add-hook 'html-mode-hook
(lambda ()
2020-07-23 08:25:34 +00:00
(flyspell-mode -1)
(add-to-list 'sgml-tag-alist '("html" (\n (format html--html-template (setq title (read-string "Title: ")) title))))))
(add-hook 'shell-mode-hook 'goto-address-mode)
;; This is overwritten by a keymap added by comint-mode... In org-mode
;; the same keymap is also bound to something. Think it's org-goto.
(add-hook 'goto-address-mode
(lambda ()
(local-set-key (kbd "C-c C-o") 'goto-address-at-point)))
(add-hook 'mhtml-mode
(lambda ()
(local-set-key (kbd "C-c C-o") 'browse-url-of-buffer)
(local-set-key (kbd "C-c C-v") 'sgml-validate)))
2019-05-08 07:05:23 +00:00
(add-hook 'prog-mode-hook
(lambda ()
(form-feed-mode)
2020-02-13 15:42:25 +00:00
(flycheck-mode 1)))
2018-08-23 19:41:28 +00:00
;; I think this breaks e.g. the color-picker
; (add-hook 'text-mode-hook 'form-feed-mode)
2019-05-08 07:05:23 +00:00
(add-hook 'haskell-mode-hook (lambda ()
(subword-mode t)
(interactive-haskell-mode t)))
2018-08-23 19:41:28 +00:00
;; global-company-mode keeps recentering the point on the screen for
;; some reason
; (add-hook 'after-init-hook 'global-company-mode)
;; (add-hook 'after-init-hook 'flycheck-mode)
;; ;; (require 'haskell-unicode-input-method)
2020-05-25 07:27:59 +00:00
(require 'prettier-js)
(add-hook
'js-mode-hook
(lambda ()
2020-02-13 15:42:25 +00:00
(subword-mode t)
2020-05-25 07:27:59 +00:00
(prettier-js-mode 1)
(local-set-key (kbd "C-M-\\") 'prettier-js)))
2020-02-13 15:42:25 +00:00
(add-hook
'js2-mode-hook
(lambda ()
(local-set-key (kbd "C-c F n") 'js2-next-error)
(local-set-key (kbd "C-c F l") 'js2-display-error-list)
2020-05-25 07:27:59 +00:00
(local-set-key (kbd "C-M-\\") 'prettier-js)
2020-02-13 15:42:25 +00:00
(prettier-js-mode 1)))
(require 'js2-globals)
(require 'js2-mode)
(setq js2-global-externs js2-globals)
2021-06-08 09:05:42 +00:00
(require 'sh-script)
(setq sh-electric-here-document-mode nil)
2020-11-08 11:39:44 +00:00
(add-hook 'sh-mode-hook
(lambda ()
(sh-electric-here-document-mode -1)
(set (make-local-variable 'compile-command)
(buffer-file-name (current-buffer)))
(local-set-key (kbd "C-c C-c") 'compile)))
2018-08-23 19:41:28 +00:00
;;;; Projectile
(require 'projectile)
2018-08-23 19:41:28 +00:00
2021-06-08 09:05:42 +00:00
(projectile-mode 1)
2019-02-14 19:58:51 +00:00
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
2018-08-23 19:41:28 +00:00
2018-08-23 19:41:28 +00:00
;;;; Dashboard
(require 'dashboard)
2018-08-23 19:41:28 +00:00
(dashboard-setup-startup-hook)
2019-05-08 07:05:23 +00:00
(setq dashboard-startup-banner (substitute-in-file-name "$XDG_DATA_HOME/emacs/banner.png"))
(setq dashboard-items '((recents . 40)))
(add-hook 'dashboard-mode-hook
(lambda ()
(local-set-key "n" 'dashboard-next-line)
(local-set-key "p" 'dashboard-previous-line)))
;;;; Miscelaneous
(setq-default indent-tabs-mode nil)
2018-08-23 19:41:28 +00:00
(defun mode-line-bell-set-background (bg)
"Set the background color of the mode-line to BG."
(set-face-background 'mode-line bg))
(defun mode-line-bell-blink ()
"Briefly change the color of the mode-line."
(let ((orig-bg (face-background 'mode-line)))
(mode-line-bell-set-background (face-attribute 'error :foreground))
(run-with-idle-timer 0.1 nil 'mode-line-bell-set-background orig-bg)))
(setq ring-bell-function 'mode-line-bell-blink)
2018-08-23 19:41:28 +00:00
(global-unset-key (kbd "C-z"))
2018-12-02 20:58:20 +00:00
;;;; Magit
(require 'magit)
2021-06-08 09:05:42 +00:00
(cond ((fboundp 'global-magit-file-mode) (global-magit-file-mode t)))
(global-set-key (kbd "C-c g g") 'magit-dispatch)
(global-set-key (kbd "C-c g s") 'magit-status)
(global-set-key (kbd "C-c g f") 'magit-file-dispatch)
(global-set-key (kbd "C-c g b") 'magit-blame)
2018-08-23 19:41:28 +00:00
2019-04-07 21:25:37 +00:00
(require 'haskell)
2019-03-27 15:12:50 +00:00
;;;; Ruby
(require 'ruby-mode)
2020-02-13 15:42:25 +00:00
(require 'enh-ruby-mode)
(require 'grep)
;; (add-to-list 'semantic-symref-filepattern-alist '(enh-ruby-mode "*.r[bu]" "*.rake" "*.gemspec" "*.erb" "*.haml" "Rakefile" "Thorfile" "Capfile" "Guardfile" "Vagrantfile"))
(add-to-list 'auto-mode-alist '("\\.rb\\'" . enh-ruby-mode))
(add-to-list 'auto-mode-alist '("\\.hbs\\'" . html-mode))
2020-03-11 09:07:20 +00:00
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
(add-hook 'typescript-mode-hook
(lambda ()
(lsp)
2020-05-25 07:27:59 +00:00
(subword-mode t)
(local-set-key (kbd "C-M-\\") 'prettier-js)))
2019-03-27 15:12:50 +00:00
2020-03-27 09:26:28 +00:00
(add-hook 'graphql-mode-hook
(lambda ()
(subword-mode t)))
;; I'm confused about the less worse option here. I think the best
;; option is to use smie (the default).
2019-03-27 15:12:50 +00:00
(setq ruby-deep-indent-paren nil)
(setq ruby-align-to-stmt-keywords t)
(setq select-enable-clipboard t)
2021-06-08 09:05:42 +00:00
2020-02-13 15:42:25 +00:00
(defun fredefox-ruby-mode-hook ()
"Hook to run engaging 'ruby-mode'."
2021-06-08 09:05:42 +00:00
(require 'chruby)
(require 'zdi)
2020-02-13 15:42:25 +00:00
(chruby-use-corresponding)
(subword-mode t)
(zdi-set-compile-command))
(add-hook 'ruby-mode-hook
'(lambda ()
(local-set-key (kbd "C-M-n") 'ruby-forward-sexp)
(local-set-key (kbd "C-M-p") 'ruby-backward-sexp)
(fredefox-ruby-mode-hook)))
(add-hook 'enh-ruby-mode-hook
'(lambda ()
(advice-add 'forward-list :override 'enh-ruby-end-of-block)
(advice-add 'backward-list :override 'enh-ruby-beginning-of-block)
(fredefox-ruby-mode-hook)))
2019-03-27 15:12:50 +00:00
(defun sql-beautify-region (beg end)
"Beautify SQL in region between BEG and END.
2019-03-27 15:12:50 +00:00
Dependency:
npm i -g sql-formatter-cli"
(interactive "r")
(save-excursion
(shell-command-on-region beg end "sql-formatter-cli" nil t)))
(defun sql-beautify-buffer ()
2019-03-27 15:12:50 +00:00
"Beautify SQL in buffer."
(interactive)
(sql-beautify-region (point-min) (point-max)))
(add-hook 'sql-mode-hook '(lambda ()
;; beautify region or buffer
(local-set-key (kbd "C-c t") 'sql-beautify-region)))
2019-03-27 15:12:50 +00:00
(put 'dired-find-alternate-file 'disabled nil)
;; org-jira [https://github.com/ahungry/org-jira]
;; (require 'org-jira)
;; (setq jiralib-url "https://zendesk.atlassian.net")
2019-03-27 15:12:50 +00:00
;;; Jira
;; (require 'jira)
2020-07-23 08:25:34 +00:00
(add-hook 'jira-mode-hook 'org-mode)
(global-set-key (kbd "C-c j") 'jira)
2019-03-27 15:12:50 +00:00
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
2020-03-27 09:26:28 +00:00
(put 'scroll-left 'disabled nil)
(when (memq window-system '(mac ns))
2019-03-27 15:12:50 +00:00
(exec-path-from-shell-initialize))
(require 'flycheck)
(define-key flycheck-mode-map flycheck-keymap-prefix nil)
(setq flycheck-keymap-prefix (kbd "C-c f"))
(define-key flycheck-mode-map flycheck-keymap-prefix
flycheck-command-map)
2020-02-13 15:42:25 +00:00
(global-set-key (kbd "M-\"") 'insert-pair)
(global-set-key (kbd "M-'") 'insert-pair)
(defun sql-prettyprint (beg end)
"Reformats SQL syntax in region (BEG to END).
Requires that `sqlformat` is installed."
(interactive "r")
(shell-command-on-region beg end "sqlformat --reindent /dev/stdin" nil t))
(add-hook 'dired-mode-hook
(lambda ()
(dired-hide-details-mode 1)))
(defalias 'yes-or-no-p 'y-or-n-p)
2020-07-23 08:25:34 +00:00
(require 'ansi-color)
(defun colorize-compilation-buffer ()
"Use ansi-color to translate SGR control sequences into overlays."
(ansi-color-apply-on-region compilation-filter-start (point)))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
2020-11-08 11:39:44 +00:00
(defun projectile--buffer-file-relative-path ()
"Get the project relative path of FILE-NAME."
(file-relative-name buffer-file-name (projectile-project-root)))
(defun projectile-eslint ()
"Run eslint on current buffers file."
(interactive)
(shell-command (format "yarn eslint --fix %s" (projectile--buffer-file-relative-path))))
(defun forge-browse-file ()
"Browse the currently visited file on the remote."
(interactive
(browse-url
(let
((rev (magit-get-current-branch))
(repo (forge-get-repository 'stub))
(file (projectile--buffer-file-relative-path)))
(forge--format repo "https://%h/%o/%n/blob/%r/%f"
`((?r . ,rev) (?f . ,file)))))))
(defun sort-words (beg end)
"Sort words between BEG and END."
(interactive "r")
(sort-regexp-fields nil "\\w+" "\\&" beg end))
2021-06-08 09:05:42 +00:00
(windmove-default-keybindings)
(global-set-key (kbd "M-u") 'upcase-dwim)
(global-set-key (kbd "M-l") 'downcase-dwim)
;;; init.el ends here