;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Define%20Default%20packages][Define Default packages:1]]
(defvar abedra/packages '(ac-slime
                          auto-complete
                          autopair
                          cider
                          clojure-mode
                          elpy
                          f
                          feature-mode
                          flycheck
                          graphviz-dot-mode
                          htmlize
                          magit
                          markdown-mode
                          org
                          paredit
                          powerline
                          rvm
                          smex
                          solarized-theme
                          web-mode
                          writegood-mode
                          yaml-mode)
  "Default packages")
;; Define Default packages:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Install%20Default%20packages][Install Default packages:1]]
(defun abedra/packages-installed-p ()
  (cl-loop for pkg in abedra/packages
        when (not (package-installed-p pkg)) do (cl-return nil)
        finally (cl-return t)))

(unless (abedra/packages-installed-p)
  (message "%s" "Refreshing package database...")
  (package-refresh-contents)
  (dolist (pkg abedra/packages)
    (when (not (package-installed-p pkg))
      (package-install pkg))))
;; Install Default packages:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Backup%20files][Backup files:1]]
(setq make-backup-files nil)
;; Backup files:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Yes%20and%20No][Yes and No:1]]
(defalias 'yes-or-no-p 'y-or-n-p)
;; Yes and No:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Misc][Misc:1]]
(setq echo-keystrokes 0.1
      use-dialog-box nil
      visible-bell t)
(show-paren-mode t)
;; Misc:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*repos][repos:1]]
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
;; repos:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*c++][c++:1]]
(use-package ggtags
:ensure t
:config 
(add-hook 'c-mode-common-hook
          (lambda ()
            (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
              (ggtags-mode 1))))
)
;; c++:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Orgmode][Orgmode:1]]
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cc" 'org-capture)
;;(add-hook 'after-init-hook 'org-agenda-list)
;;(delete-other-windows)
(add-to-list 'org-modules "org-habit")

;; DOCUMENTS MINTED
;(require 'ox-latex)
;(add-to-list 'org-latex-packages-alist '("" "minted"))
;(setq org-latex-listings 'minted)
;(require 'org-latex)
;(setq org-export-latex-listings 'minted)
;(add-to-list 'org-export-latex-packages-alist '("" "minted"))            
;; Minted
;  (require 'ox-latex)
;  (setq org-latex-listings 'minted)
;(setq org-latex-pdf-process
;        '("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
;          "bibtex $(basename %b)"
;          "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
;          "pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
;; Babel src evaluator
;(setq debug-on-error t)
;(org-babel-do-load-languages
;'org-babel-load-languages
;'((python . t)))






(setq org-agenda-files (list "~/Documents/org/todo.org"
			     "~/Documents/org/i.org"
			     "~/Documents/org/habits.org"
			     "~/Documents/org/links.org"
			     "~/Documents/org/school.org"))

(setq org-agenda-start-on-weekday 1)

(setq org-agenda-custom-commands
      '(("h" "Daily habits" 
         ((agenda ""))
         ((org-agenda-show-log t)
          (org-agenda-ndays 7)
          (org-agenda-log-mode-items '(state))
          (org-agenda-skip-function '(org-agenda-skip-entry-if 'notregexp ":DAILY:"))))
        ;; other commands here
        ))

(setq org-capture-templates
'(("a" "Appointment" entry (file  "~/Documents/org/i.org" )
"* %^{Appointment:}%?\n\n%^T\n\n:PROPERTIES:\n\n:END:\n\n")
("l" "Link" entry (file+headline "~/Documents/org/links.org" "Links")
"* %? %^L %^g \n%T" :prepend t)
("b" "Blog idea" entry (file+headline "~/Documents/org/i.org" "Blog Topics:")
"* %?\n%T" :prepend t)

("t" "To Do Item" entry (file+headline "~/Documents/org/todo.org" "To Do")
"* TODO %^{TODO:}\nSCHEDULED: %^t\nPROPERTIES:\n:CREATED: %u\n:END:\n%a\n" )
("m" "Meeting" entry (file "~/Documents/org/i.org")
"* MEETING with %? :MEETING:\n%t" :clock-in t :clock-resume t)

("n" "Note" entry (file+headline "~/Documents/org/i.org" "Note space")
"* %?\n%u" :prepend t)
("j" "Journal" entry (file+datetree "~/Documents/org/journal.org")
"* %?\nEntered on %U\n  %i\n  %a")
("s" "Screencast" entry (file "~/Documents/org/screencastnotes.org")
"* %?\n%i\n")


;; School templates
("T" "Test" entry (file+headline "~/Documents/org/school.org" "Testy")
	 "* TEST [#A] %^{Test:}%?\n\tDEADLINE: %^t\n:PROPERTIES:\n:CREATED: %U\n:END:\n\n" :empty-lines 1)
)) ;; end

 (setq org-log-done 'time)
;; Orgmode:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Themes%20and%20modeline][Themes and modeline:1]]
(use-package moe-theme
  :ensure t)  
(load-theme 'moe-dark t)
;; Themes and modeline:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*Htmlize][Htmlize:1]]
(use-package htmlize
  :ensure t)
;; Htmlize:1 ends here

;; [[file:~/dotfiles/emacs/.emacs.d/myinit.org::*yasnippet][yasnippet:1]]
;(global-set-key "\C-i" 'yas-expand)
(setq yas-trigger-key "TAB")
(setq yas-triggers-in-field t)

;;; use popup menu for yas-choose-value


;; trigger using TAB and disable auto-start
;(custom-set-variables
; '(ac-trigger-key "TAB")
; '(ac-auto-start nil)
; '(ac-use-menu-map t))
;(define-key ac-menu-map (kbd "<tab>") nil)
;(define-key ac-menu-map (kbd "<S-tab>") nil)




(use-package validate
:ensure t)

(defmacro validate-setq (&rest svs)
  "Like `setq', but throw an error if validation fails.
VALUE is validated against SYMBOL's custom type.
\(fn [SYM VAL] ...)"
  (let ((out))
    (while svs
      (let ((symbol (pop svs))
            (value (if (not svs)
                       (error "`validate-setq' takes an even number of arguments")
                     (pop svs))))
        (push `(if (boundp ',symbol)
                   (setq ,symbol (validate-value ,value (custom-variable-type ',symbol)))
                 (user-error "Trying to validate a variable that's not defined yet: `%s'.\nYou need to require the package before validating"
                             ',symbol))
              out)))
    `(progn ,@(reverse out))))

(use-package yasnippet
:ensure t
:diminish yas-minor-mode
:init (yas-global-mode t))
;; Autocomplete



;; Code-comprehension server

  (defun check-expansion ()
    (save-excursion
      (if (looking-at "\\_>") t
        (backward-char 1)
        (if (looking-at "\\.") t
          (backward-char 1)
          (if (looking-at "->") t nil)))))

  (defun do-yas-expand ()
    (let ((yas/fallback-behavior 'return-nil))
      (yas/expand)))

  (defun tab-indent-or-complete ()
    (interactive)
    (if (minibufferp)
        (minibuffer-complete)
      (if (or (not yas/minor-mode)
              (null (do-yas-expand)))
          (if (check-expansion)
              (company-complete-common)
            (indent-for-tab-command)))))

  (global-set-key [tab] 'tab-indent-or-complete)
(use-package yasnippet-snippets
:ensure t)
;; yasnippet:1 ends here
