;; emacs dotfile
;; Daniel Bowling <dbowling@akamai>
;; May 2020
;; version 0.5

(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.
 '(custom-enabled-themes '(tango-dark))
 '(ignored-local-variable-values
   '((eval setq flycheck-perl-include-path
           (add-to-list 'flycheck-perl-include-path
                        (concat
                         (projectile-project-root)
                         "lib")))))
 '(package-selected-packages
   '(flycheck js2-mode flycheck-raku company yasnippet project eglot dockerfile-mode php-mode web-mode kotlin-mode markdown-mode elpher yaml-mode raku-mode emojify)))
(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.
 )

;; Don't blink cursor
(blink-cursor-mode (- (*) (*) (*)))
(setq visible-cursor nil)

;; Use spaces for indent
(setq-default indent-tabs-mode nil)

;; Put backup files in one place
(setq backup-directory-alist '(("." . "~/.emacs.d")))

;; Put auto-save files in one place
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/" t)))

;; Show column number next to line number
(setq column-number-mode t)

;; Make next line command skip wrapped lines
(setq line-move-visual nil)

;; Highlight matching brackets when under cursor
(setq show-paren-delay 0)
(show-paren-mode 1)

;; Highlight brackets if visible; else entire expression
(setq show-paren-style 'mixed)

;; Show stray whitespace.
(setq-default show-trailing-whitespace t)
(setq-default indicate-empty-lines t)
(setq-default indicate-buffer-boundaries 'left)

;; Load package system
(when (>= emacs-major-version 24)
  (package-initialize)
  (require 'package)
;  (add-to-list
;   'package-archives
;   '("melpa-stable" . "http://stable.melpa.org/packages/") t)
  (add-to-list
   'package-archives
   '("melpa" . "http://melpa.org/packages/") t)
  )

;; GUI specific config
(when window-system
  ;; Confirm before exit
  (setq confirm-kill-emacs 'yes-or-no-p)
  ;; For small screens (uncomment as needed)
  ;(set-frame-height (selected-frame) 29)
  )

;; MacOS specific config
(when (eq system-type 'darwin)
;; Need this fix for homebrew
  (setq ispell-program-name "/opt/homebrew/bin/ispell")
  ;; Work-around for dir not getting set correctly on macOS
  (cd (getenv "HOME"))
  )

;; web-mode config
(defun my-web-mode-hook ()
  "Hooks for Web mode."
  (setq web-mode-markup-indent-offset 2)
)
(add-hook 'web-mode-hook 'my-web-mode-hook)

;; cperl-mode config
(defalias 'perl-mode 'cperl-mode)
(setq cperl-electric-parens t
      cperl-electric-linefeed t
      cperl-electric-keywords t
      cperl-info-on-command-no-prompt t
      cperl-clobber-lisp-bindings t
      cperl-lazy-help-time 3
      cperl-indent-level 4
      cperl-close-paren-offset 0
      cperl-continued-statement-offset 4
      cperl-indent-parens-as-block t
      cperl-tab-always-indent t
      cperl-indent-subs-specially nil
      cperl-highlight-variables-indiscriminately t
      cperl-invalid-face nil)

;; raku-mode cope
(add-hook 'raku-mode-hook
          (lambda ()
            (setq tab-width 4)
            (local-set-key (kbd "TAB") 'tab-to-tab-stop)
            (electric-indent-local-mode -1)))

;; JS cope
(setq js-switch-indent-offset 4)

;; Flycheck
(when (require 'flycheck nil 'noerror)
  (add-hook 'after-init-hook #'global-flycheck-mode)
  (setq flycheck-perl-include-path '("$HOME/perl5/lib/perl5")))