#+TITLE: Emacs konfiguráció
* Preferenciák beállítása
  #+BEGIN_SRC emacs-lisp
(add-to-list 'default-frame-alist
             '(font . "Hack 11"))
(setq visible-bell 1)
(setq inhibit-startup-screen t)
(setq debug-on-error t)
  #+END_SRC
* Csomagok betöltése
** Melpa
   #+BEGIN_SRC emacs-lisp
;;(require 'init-security)

(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
  ;; and `package-pinned-packages`. Most users will not need or want to do this.
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  )
(package-initialize)
(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 'doom-solarized-dark)
 '(package-selected-packages
   (quote
    (nyan-mode neotree flycheck))))
;;(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.
;; )
   #+END_SRC
** Cask
   #+BEGIN_SRC emacs-lisp
;;(package-initialize)
;;(require 'cask "~/.cask/cask.el")
;;(cask-initialize)
   #+END_SRC
** Plugin-ok betöltése
*** RTags
    #+BEGIN_SRC emacs-lisp
(require 'rtags)
(require 'company-rtags)

(setq rtags-completions-enabled t)
(eval-after-load 'company
  '(add-to-list
    'company-backends 'company-rtags))
(setq rtags-autostart-diagnostics t)
(rtags-enable-standard-keybindings)
    #+END_SRC
*** Irony-mode
    #+BEGIN_SRC emacs-lisp
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)

(defun my-irony-mode-hook ()
  (define-key irony-mode-map [remap completion-at-point]
    'irony-completion-at-point-async)
  (define-key irony-mode-map [remap complete-symbol]
    'irony-completion-at-point-async))

(add-hook 'irony-mode-hook 'my-irony-mode-hook)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
    #+END_SRC
*** Comany-irony
    #+BEGIN_SRC emacs-lisp
(add-hook 'irony-mode-hook 'company-irony-setup-begin-commands)
(setq company-backends (delete 'company-semantic company-backends))
(eval-after-load 'company
  '(add-to-list
    'company-backends 'company-irony))
(setq company-idle-delay 0)
(define-key c-mode-map [(tab)] 'company-complete)
(define-key c++-mode-map [(tab)] 'company-complete)
    #+END_SRC
*** Flycheck
    #+BEGIN_SRC emacs-lisp
(add-hook 'c++-mode-hook 'flycheck-mode)
(add-hook 'c-mode-hook 'flycheck-mode)
(require 'flycheck-rtags)

(defun my-flycheck-rtags-setup ()
  (flycheck-select-checker 'rtags)
  (setq-local flycheck-highlighting-mode nil) ;; RTags creates more accurate overlays.
  (setq-local flycheck-check-syntax-automatically nil))
;; c-mode-common-hook is also called by c++-mode
(add-hook 'c-mode-common-hook #'my-flycheck-rtags-setup)
;;Integrate to irony
(eval-after-load 'flycheck
  '(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
    #+END_SRC
*** Flycheck-clang-tidy
    #+BEGIN_SRC emacs-lisp
(eval-after-load 'flycheck
  '(add-hook 'flycheck-mode-hook #'flycheck-clang-tidy-setup))
    #+END_SRC
*** Cmake-ide
    #+BEGIN_SRC emacs-lisp
(cmake-ide-setup)
    #+END_SRC
*** Highlight beállítások
    #+BEGIN_SRC emacs-lisp
(add-hook 'irony-mode-hook 'highlight-numbers-mode)
(add-hook 'irony-mode-hook 'preproc-font-lock-mode)
    #+END_SRC
*** Srefactor
    #+BEGIN_SRC emacs-lisp
    (require 'srefactor)
    (require 'srefactor-lisp)
    
    ;; OPTIONAL: ADD IT ONLY IF YOU USE C/C++. 
    (semantic-mode 1) ;; -> this is optional for Lisp
    
    (define-key c-mode-map (kbd "M-RET") 'srefactor-refactor-at-point)
    (define-key c++-mode-map (kbd "M-RET") 'srefactor-refactor-at-point)
    (global-set-key (kbd "M-RET o") 'srefactor-lisp-one-line)
    (global-set-key (kbd "M-RET m") 'srefactor-lisp-format-sexp)
    (global-set-key (kbd "M-RET d") 'srefactor-lisp-format-defun)
    (global-set-key (kbd "M-RET b") 'srefactor-lisp-format-buffer)
    #+END_SRC
*** Discord-Emacs
#+BEGIN_SRC emacs-lisp
(load-file "~/.emacs.d/elpa/discord-emacs.el/discord-emacs.el")
#+END_SRC
*** Smex
#+BEGIN_SRC emacs-lisp
(require 'smex) ; Not needed if you use package.el
  (smex-initialize) ; Can be omitted. This might cause a (minimal) delay
                    ; when Smex is auto-initialized on its first run.
#+END_SRC
*** Yasnippet
#+BEGIN_SRC emacs-lisp
(add-to-list 'load-path
              "~/.emacs.d/plugins/yasnippet")
(require 'yasnippet)
(yas-global-mode 1)

(add-hook 'c-mode-hook #'yas-minor-mode)
(add-hook 'c++-mode-hook #'yas-minor-mode)

#+END_SRC
*** Drag-stuff
#+BEGIN_SRC emacs-lisp
(drag-stuff-mode t)
#+END_SRC
*** ORG-bullets
    #+BEGIN_SRC emacs-lisp
(require 'org-bullets)
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
    #+END_SRC
*** Nyan-mode
     #+BEGIN_SRC emacs-lisp
 (nyan-mode)
     #+END_SRC
*** Neotree
      #+BEGIN_SRC emacs-lisp
  ;;(add-to-list 'load-path "/some/path/neotree")
  (require 'neotree)
  (global-set-key [f8] 'neotree-toggle)
      #+END_SRC
* Makró beállítások
** Rtags
   #+BEGIN_SRC emacs-lisp
(define-key c-mode-base-map (kbd "M-.") (function rtags-find-symbol-at-point))
(define-key c-mode-base-map (kbd "M-,") (function rtags-find-references-at-point))
(define-key c-mode-base-map (kbd "M-;") (function rtags-find-file))
(define-key c-mode-base-map (kbd "C-.") (function rtags-find-symbol))
(define-key c-mode-base-map (kbd "C-,") (function rtags-find-references))
(define-key c-mode-base-map (kbd "C-<") (function rtags-find-virtuals-at-point))
(define-key c-mode-base-map (kbd "M-i") (function rtags-imenu))
   #+END_SRC
** Open config
   #+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-c o") (lambda () (interactive)
  (find-file "/home/balazs/.emacs.d/conf.org")
  (message "Opened:  %s" (buffer-name))))
(global-set-key (kbd "C-c r") (lambda () (interactive)
   (kill-buffer (buffer-name))
   (load-file "/home/balazs/.emacs.d/init.el")
   (message "Configuration reloaded")  
))
   #+END_SRC
** Cmake build and run
   #+BEGIN_SRC emacs-lisp

(defvar cmake-last-target nil)

(defun cmake-build-and-run ()
  "Asks for cmake target, then compiles and runs it."
  (interactive)
  (let ((target
	 (ido-completing-read "Choose build target: " (remove "" (split-string
								  (shell-command-to-string "cmake --build ./cmake-build-debug --target help | awk '{if($2 != \"all\" && $2!= \"clean\" && $2 != \"following\" && $2 != \"edit_cache\" && $2 != \"rebuild_cache\" && $2 != \"depend\" && $2 !~ /\\./){print $2}}'") "\n")))))
    (setq cmake-last-target target)
    (async-shell-command (format "cmake --build ./cmake-build-debug --target %s && ./cmake-build-debug/%s" target target))))

(defun cmake-build-last-target ()
   (interactive)
   (if (not (null cmake-last-target))
   (async-shell-command (format "cmake --build ./cmake-build-debug --target %s && ./cmake-build-debug/%s" cmake-last-target cmake-last-target))
   (cmake-build-and-run))
)
(define-key c-mode-base-map (kbd "C-c C-r") (function cmake-build-and-run))
(define-key c-mode-base-map [f5] 'cmake-build-last-target)
   #+END_SRC

** Kód indentálás
   #+BEGIN_SRC emacs-lisp
    (defun indent-buffer ()
      (interactive)
      (save-excursion
        (indent-region (point-min) (point-max) nil)))
    (global-set-key [f6] 'indent-buffer)
   #+END_SRC
** LaTeX kód fordítása
#+BEGIN_SRC emacs-lisp
  
#+END_SRC
** Org export
#+BEGIN_SRC emacs-lisp
(define-key org-mode-map (kbd "M-p") 'org-latex-export-to-pdf)
#+END_SRC
** Magit
#+BEGIN_SRC emacs-lisp
(global-set-key (kbd "C-x g") 'magit-status)
#+END_SRC
** Smex
#+BEGIN_SRC emacs-lisp
  (global-set-key (kbd "M-x") 'smex)
  (global-set-key (kbd "M-X") 'smex-major-mode-commands)
  ;; This is your old M-x.
  (global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
#+END_SRC
* Saját változók
** Csomag változók
   #+BEGIN_SRC emacs-lisp

   #+END_SRC
** Minibuffer
   #+BEGIN_SRC emacs-lisp
(setq minibuffer-completion-confirm nil)
   #+END_SRC
** Téma betöltése
   #+BEGIN_SRC emacs-lisp
;;(load-theme "humanoid-dark" t)
;;(add-hook 'after-init-hook (lambda () (load-theme "humanoid-dark")))
   #+END_SRC
** Org-mode
   #+BEGIN_SRC emacs-lisp
(setq org-todo-keywords
   '((squence "TODO" "WAITING" "|" "DONE(!)")))
(setq org-highlight-latex-and-related '(latex script entities))

(add-hook 'org-mode-hook '(lambda () (setq fill-column 80)))
(add-hook 'org-mode-hook 'auto-fill-mode)
   #+END_SRC
#+BEGIN_SRC emacs-lisp
;; Source: http://www.emacswiki.org/emacs-en/download/misc-cmds.el
(global-auto-revert-mode 1)
(setq org-format-latex-options (plist-put org-format-latex-options :scale 2.0))
#+END_SRC
** LaTeX
#+BEGIN_SRC emacs-lisp
(setq TeX-auto-save t)
(setq TeX-parse-self t)
(setq-default TeX-master nil)
#+END_SRC
** Docs view
#+BEGIN_SRC emacs-lisp
(setq doc-view-continuous t)
#+END_SRC
** Hunspell
#+BEGIN_SRC emacs-lisp
(setq ispell-program-name "hunspell"
      ispell-local-dictionary "hu_HU"
      ispell-skip-html t
      ispell-local-dictionary-alist
      '(("hu_HU" "\[\[:alpha:\]\]" "[^[:alpha:]]" "[']" nil ("-d" "hu_HU") nil utf-8)))
(setq ispell-dictionary "hu_HU")
#+END_SRC
** Teszt
   #+BEGIN_SRC emacs-lisp
;(cd "~/CLionProjects/prog2/")
   #+END_SRC
