(setq inhibit-startup-message t)

(add-hook 'window-setup-hook 'toggle-frame-maximized t)

(scroll-bar-mode -1)        ; Disable visible scrollbar
(tool-bar-mode -1)          ; Disable the toolbar
(tooltip-mode -1)           ; Disable tooltips
(set-fringe-mode 10)        ; Give some breathing room

(menu-bar-mode -1)            ; Disable the menu bar

;; setup dashboard

(require 'dashboard)
(use-package dashboard
  :ensure t
  :config
  (dashboard-setup-startup-hook))

;; Set the title
(setq dashboard-banner-logo-title "Welcome to Emacs Dashboard")
;; Set the banner
(setq dashboard-startup-banner 'logo)
;; Value can be
;;'official which displays the official emacs logo
;;'logo which displays an alternative emacs logo
;;1, 2 or 3 which displays one of the text banners
;;"path/to/your/image.png" or "path/to/your/text.txt" which displays whatever image/text you would prefer

;; Content is not centered by default. To center, set
(setq dashboard-center-content t)


(set-face-attribute 'default nil :font "Cascadia Code" :height 100)


;; Make ESC quit prompts
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)

;; Initialize package sources
(require 'package)

(setq package-archives '(("melpa" . "https://melpa.org/packages/")
                         ("org" . "https://orgmode.org/elpa/")
                         ("elpa" . "https://elpa.gnu.org/packages/")))

(package-initialize)
(unless package-archive-contents
 (package-refresh-contents))

;; Initialize use-package on non-Linux platforms
(unless (package-installed-p 'use-package)
   (package-install 'use-package))

(require 'use-package)
(setq use-package-always-ensure t)

(column-number-mode)
(global-display-line-numbers-mode t)

;; Disable line numbers for some modes
(dolist (mode '(org-mode-hook
		term-mode-hook
		shell-mode-hook
		erc-mode-hook
		mu4e-main-mode-hook
		mu4e-headers-mode-hook
		mu4e-view-mode-hook
		eshell-mode-hook))
  (add-hook mode (lambda () (display-line-numbers-mode 0))))

(use-package command-log-mode)

(use-package ivy
  :diminish
  :bind (("C-s" . swiper)
         :map ivy-minibuffer-map
         ("TAB" . ivy-alt-done)	
         ("C-l" . ivy-alt-done)
         ("C-j" . ivy-next-line)
         ("C-k" . ivy-previous-line)
         :map ivy-switch-buffer-map
         ("C-k" . ivy-previous-line)
         ("C-l" . ivy-done)
         ("C-d" . ivy-switch-buffer-kill)
         :map ivy-reverse-i-search-map
         ("C-k" . ivy-previous-line)
         ("C-d" . ivy-reverse-i-search-kill))
  :config
  (ivy-mode 1))


(use-package all-the-icons)

(use-package doom-modeline
  :ensure t
  :init (doom-modeline-mode 1)
  :custom ((doom-modeline-height 15)))

(use-package doom-themes)
(load-theme 'doom-palenight t)


(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode))

(use-package which-key
  :init (which-key-mode)
  :diminish which-key-mode
  :config
  (setq which-key-idle-delay 0.1))

(use-package ivy-rich
  :init
  (ivy-rich-mode 1))
  
(use-package general)

(general-define-key
 "C-M-j" 'counsel-switch-buffer
 "C-M-t" 'counsel-load-theme
 "C-M-A" 'text-scale-adjust)


;; transparency configuration
;;(set-frame-parameter (selected-frame) 'alpha '(<active> . <inactive>))
;;(set-frame-parameter (selected-frame) 'alpha <both>)
(set-frame-parameter (selected-frame) 'alpha '(85 . 50))
(add-to-list 'default-frame-alist '(alpha . (85 . 50)))

 (defun toggle-transparency ()
   (interactive)
   (let ((alpha (frame-parameter nil 'alpha)))
     (set-frame-parameter
      nil 'alpha
      (if (eql (cond ((numberp alpha) alpha)
                     ((numberp (cdr alpha)) (cdr alpha))
                     ;; Also handle undocumented (<active> <inactive>) form.
                     ((numberp (cadr alpha)) (cadr alpha)))
               100)
          '(85 . 50) '(100 . 100)))))
 (global-set-key (kbd "C-c t") 'toggle-transparency)

;; Set transparency of emacs
 (defun transparency (value)
   "Sets the transparency of the frame window. 0=transparent/100=opaque"
   (interactive "nTransparency Value 0 - 100 opaque:")
   (set-frame-parameter (selected-frame) 'alpha value))


(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.
 '(package-selected-packages
   '(elpher evil-mu4e exwm org-inline-pdf mu4e evil-magit magit general workgroups2 ERC dashboard doom-themes counsel ivy-rich which-key rainbow-delimiters doom-modeline use-package shrink-path ivy command-log-mode all-the-icons))
 '(send-mail-function 'smtpmail-send-it)
 '(smtpmail-smtp-server "disroot.org")
 '(smtpmail-smtp-service 25))
(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.
 )

(use-package counsel
  :bind (("M-x" . counsel-M-x)
	 ("C-x b" . counsel-ibuffer)
	 ("C-x C-f" . counsel-find-file)
	 :map minibuffer-local-map
	 ("C-r" . 'counsel-minibuffer-history)))



(require 'mu4e)

(setq user-full-name "Syed Ahmed")
(setq user-mail-address "9ahmed@disroot.org")
(setq mu4e-get-mail-command "mbsync -a")


(require 'mu4e)

(setq user-full-name "Syed Ahmed")
(setq user-mail-address "syedahmed@riseup.net")
(setq mu4e-get-mail-command "mbsync -a")


(require 'erc)

(setq
 erc-autojoin-timing 'ident
 erc-fill-function   'erc-fill-static
 erc-join-channel    'general
 erc-hide-list       '("JOIN" "PART" "QUIT")
 erc-fill-static-center 0
 erc-server-reconnect-attempts 5
 erc-server-reconnect-timeout  3)

(global-set-key "\C-ch"
		(lambda ()
		  (interactive)
		  (erc :server    "rnbunker.ydns.eu"
		       :port      "6667"
		       :nick      "ahmd"
		       :full-name "Am")))


(use-package mu4e
  :ensure nil
  :config

  ;; This is set to 't' to avoid mail syncing issues when using mbsync
  (setq mu4e-change-filenames-when-moving t)

  ;; Refresh mail using isync every 10 minutes
  (setq mu4e-update-interval (* 10 60))
  (setq mu4e-get-mail-command "mbsync -a")
  (setq mu4e-maildir "~/Mail")

  (setq mu4e-contexts
        (list
         ;; Work account
         (make-mu4e-context
          :name "Work"
          :match-func
            (lambda (msg)
              (when msg
                (string-prefix-p "/Riseup" (mu4e-message-field msg :maildir))))
          :vars '((user-mail-address . "syedahmed@riseup.net")
                  (user-full-name    . "Syed Ahmed")
                  (mu4e-drafts-folder  . "/Riseup/[Riseup]/Drafts")
                  (mu4e-sent-folder  . "/Riseup/[Riseup]/Sent Mail")
                  (mu4e-refile-folder  . "/Riseup/[Riseup]/All Mail")
                  (mu4e-trash-folder  . "/Riseup/[Riseup]/Trash")))

         ;; Personal account
         (make-mu4e-context
          :name "Personal"
          :match-func
            (lambda (msg)
              (when msg
                (string-prefix-p "/Disroot" (mu4e-message-field msg :maildir))))
          :vars '((user-mail-address . "9ahmed@disroot.org")
                  (user-full-name    . "Syed Ahmed")
                  (mu4e-drafts-folder  . "/Disroot/Drafts")
                  (mu4e-sent-folder  . "/Disroot/Sent")
                  (mu4e-refile-folder  . "/Disroot/Archive")
                  (mu4e-trash-folder  . "/Disroot/Trash")))))

  (setq mu4e-maildir-shortcuts
      '(("/Inbox"             . ?i)
        ("/Riseup/[Riseup]/Sent Mail" . ?s)
        ("/Riseup/[Riseup]/Trash"     . ?t)
        ("/Riseup/[Riseup]/Drafts"    . ?d)
        ("/Riseup/[Riseup]/All Mail"  . ?a))))
