#+AUTHOR: qorg11
#+TITLE: emacs config

* qorg's Emacs config
  
  
  This is my Emacs configuration. Hope you like it.

** Installation

   Just copy this repository to your .emacs.d. Nothing else is needed.

** Why?
   * I can
   * I don't like doom emacs
   * I don't like spacemacs
   * I don't want to learn doom emacs
   * I don't want to learn spacemacs
   * I don't like Vim
** About me
   Here I set variables about personal information i'll use later in
   this config.
   #+BEGIN_SRC emacs-lisp
	(setq name "qorg11")
	(setq email "qorg@vxempire.xyz")
	(setq website "qorg11.net")
   #+END_SRC
** Dependencies
   The only no emacs related dependence in this configuration is the
   IBM Plex Mono font. Install it from your distribution packages.
   You can change it before opening Emacs with this configuration for
   the first time.

   For irony-mode (C autocompletion) irony-sever must be
   installed. You can install it with M-x irony-install-server or via
   distribution's packages, in Debian case, apt install irony-server.
   Using M-x irony-install-server requires cmake and a lot of
   dependences I'm to lazy to install.

** Configuration
   Yeah, this configuration file has a configuration, ironic ha?
   #+BEGIN_SRC emacs-lisp
	(setq i-just-use-emacs-to-be-cool nil) ;; Repleace to true to use EVIL

   #+END_SRC
   
* gc
  #+begin_src emacs-lisp
    ;; Minimize garbage collection during startup
    (setq gc-cons-threshold most-positive-fixnum)

    ;; Lower threshold back to 8 MiB (default is 800kB)
    (add-hook 'emacs-startup-hook
		    (lambda ()
			 (setq gc-cons-threshold (expt 2 23))))
  #+end_src
* melpa crap, and basic packages installation
  melpa, where you get the packages. This also installs use-package,
  and other packages I use.
  #+BEGIN_SRC emacs-lisp
    (require 'package)
    (let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
				    (not (gnutls-available-p))))
		 (proto (if no-ssl "http" "https")))
	 ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
	 (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
	 ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
	 (when (< emacs-major-version 24)
	   ;; For important compatibility libraries like cl-lib
	   (add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))

    (if (< emacs-major-version 27)
	   (package-initialize))
    (unless (package-installed-p 'use-package)
	 (package-refresh-contents)
	 (package-install 'use-package))
  #+END_SRC
** Generic packages
   Here I install some packages that don't need configuration.
   Remember to run M-x all-the-icons-install-fonts after the first
   init to install the fonts.
   #+BEGIN_SRC emacs-lisp

	(use-package markdown-mode
	  :defer 1
	  :ensure t)
	(use-package all-the-icons
	  :defer 1
	  :ensure t)
	(use-package which-key
	  :ensure t
	  :init (which-key-mode))
   #+END_SRC
* Autoindentation
  C-c n for indent-buffer. I don't use the rest.
  #+BEGIN_SRC emacs-lisp
    (setq-default tab-width 5)
    (defvaralias 'sgml-basic-offset 'tab-width)
    (add-hook 'html-mode-hook
		    (lambda ()
			 (set-fill-column 100)))
    (defun indent-buffer ()
	 (interactive)
	 (save-excursion
	   (indent-region (point-min) (point-max) nil)))
    (global-set-key (kbd "C-c n") 'indent-buffer)
    ;; C bullshit
    (c-set-offset 'arglist-cont-nonempty '+)
  #+END_SRC

* Shorcuts
  Probably this overwrites another keybinding. But since I overwrited
  it. I don't think i'd ever use the overwritten.
  #+BEGIN_SRC emacs-lisp
    (global-set-key (kbd "M-m") 'mark-whole-buffer)
  #+END_SRC
* No idea
  #+BEGIN_SRC emacs-lisp
    (setq package-enable-at-startup nil) (package-initialize)

    (setq make-backup-files nil) ; stop creating backup~ files
    (setq auto-save-default nil) ; stop creating #autosave# files
    (put 'upcase-region 'disabled nil)


    (defun contextual-menubar (&optional frame)
	 "Display the menubar in FRAME (default: selected frame) if on a
    graphical display, but hide it if in terminal."
	 (interactive)
	 (set-frame-parameter frame 'menu-bar-lines
					  (if (display-graphic-p frame)
						 1 0)))

    (add-hook 'after-make-frame-functions 'contextual-menubar)
    (use-package zencoding-mode
	 :ensure t
	 :defer 1
	 :init
	 (add-hook 'sgml-mode-hook 'zencoding-mode))
  #+END_SRC

* customization
  Emacs customization, Here is where most of the configuration is.
** Disable bars font and pandoc export optxions.
   #+BEGIN_SRC emacs-lisp
	(tool-bar-mode -1)
	(menu-bar-mode -1)
	(set-frame-font "Terminus 14" nil t)
	(use-package smex
	  :ensure t
	  :init
	  (global-set-key (kbd "M-x") 'helm-M-x))
	(setq-default major-mode 'text-mode)
	(defalias 'yes-or-no-p 'y-or-n-p)
   #+END_SRC

** Highlight matching parentheses
   #+BEGIN_SRC emacs-lisp
	(show-paren-mode 1)
	(setq show-paren-style 'mixed)

	(setq startup/gc-cons-threshold gc-cons-threshold)
	(setq gc-cons-threshold most-positive-fixnum)
	(defun startup/reset-gc () (setq gc-cons-threshold startup/gc-cons-threshold))
	(add-hook 'emacs-startup-hook 'startup/reset-gc)
   #+END_SRC
** Tramp mode shit
   #+begin_src emacs-lisp
	(set-variable 'tramp-copy-size-limit 122222222222)
	(set-variable 'tramp-inline-compress-start-size 12222222222222)
   #+end_src
** theme
   #+BEGIN_SRC emacs-lisp
	(load-theme 'cyberpunk t)

   #+END_SRC
** Lines and columns
   #+BEGIN_SRC emacs-lisp
	(global-display-line-numbers-mode 1)
	(setq display-line-numbers-type 'relative)
	(global-hl-line-mode 1)
	(column-number-mode 1)
   #+END_SRC
** Flycheck
   Flycheck is a syntax validator or somehting like that
   #+BEGIN_SRC emacs-lisp
	(use-package flycheck
	  :ensure t
	  :init
	  (add-hook 'after-init-hook #'global-flycheck-mode))
   #+END_SRC
** Shell
   #+BEGIN_SRC emacs-lisp
	(setq shell "/bin/mksh")
	(defadvice ansi-term (before force-mksh)
	  (interactive (list shell)))
	(ad-activate 'ansi-term)
	(global-set-key (kbd "<C-return>") 'ansi-term)
   #+END_SRC
** Swiper
   #+BEGIN_SRC emacs-lisp
	(use-package swiper
	  :ensure t
	  :defer 1
	  :init
	  (global-set-key "\C-s" 'swiper))
   #+END_SRC
** Company and Irony
   Some shit for autocompletion and that kind of shit.

   #+BEGIN_SRC emacs-lisp
	(use-package company
	  :defer 1
	  :ensure t
	  :config
	  (setq company-idle-delay 0)
	  (setq company-minimum-prefix-length 1)
	  (global-company-mode))
	(with-eval-after-load 'company
	  (define-key company-active-map (kbd "M-n") nil)
	  (define-key company-active-map (kbd "M-p") nil)
	  (define-key company-active-map (kbd "C-n") #'company-select-next)
	  (define-key company-active-map (kbd "C-p") #'company-select-previous))

	(use-package company-irony
	  :defer 1
	  :ensure t
	  :config
	  (require 'company)
	  (add-to-list 'company-backends 'company-irony))

	(use-package irony
	  :defer 1
	  :ensure t
	  :config
	  (add-hook 'c-mode-hook 'irony-mode)
	  (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))
	(with-eval-after-load 'company
	  (add-hook 'c-mode-hook 'company-mode))
   #+END_SRC
** Idk what to name this
   Here I put things you can do in M-x or something idk
   #+BEGIN_SRC emacs-lisp
	(blink-cursor-mode 0)
	(global-hl-line-mode 0)
	(setq-default cursor-type 'block)
   #+END_SRC
** Programming language things
*** Lisp
    Parentheses highlight in lisp modes. So you can easily identify
    them.
    #+BEGIN_SRC emacs-lisp
	 (use-package rainbow-delimiters
	   :ensure t
	   :init
	   (add-hook 'emacs-lisp-mode-hook 'rainbow-delimiters-mode)
	   (add-hook 'lisp-mode-hook 'rainbow-delimiters-mode)
	   (add-hook 'scheme-mode-hook 'rainbow-delimiters-mode))

    #+END_SRC
*** Perl
    Cperl-mode is better than perl-mode. You can't change my mind.
    #+BEGIN_SRC emacs-lisp
	 (defalias 'perl-mode 'cperl-mode)

    #+END_SRC
*** C*
    This use c-eldoc mode so it prints the function's prototype in the
    minibuffer. Which is very useful since Irony works when it wants
    to.
    #+BEGIN_SRC emacs-lisp
	 (use-package c-eldoc
	   :ensure t
	   :init
	   (add-hook 'c-mode-hook 'c-turn-on-eldoc-mode))
	 (setq c-default-style "k&r")
    #+END_SRC

** Extra functions
   Here I put functions I won't bother to document because they're so
   simple.
   #+BEGIN_SRC emacs-lisp
	(defun git-pushall ()
	  (interactive)
	  (shell-command "git pushall"))

	(defun kill-inner-word ()
	  (interactive)
	  (forward-word 1)
	  (backward-word)
	  (kill-word 1))
	(global-set-key (kbd "C-x w k") 'kill-inner-word)
	(defun kill-kill ()
	  (interactive)
	  (beginning-of-line)
	  (kill-line)
	  (kill-line))
	(global-set-key (kbd "M-.") 'repeat)
	(global-set-key (kbd "C-x k") 'kill-buffer)
	(global-set-key (kbd "C-c k") 'kill-kill)
	(global-set-key (kbd "C-k") 'kill-line)

	(global-set-key (kbd "C-x -") 'comment-region)
	(global-set-key (kbd "C-x +") 'uncomment-region)
   #+END_SRC
** Hunspell
   For some reason, there is no ispell spanish in void linux. so i had
   to fallback to hunspell. which does the same.
   #+BEGIN_SRC emacs-lisp
	(defvar ispell-program-name "hunspell") ;; Or whatever you use
	;; (ispell, aspell...)

   #+END_SRC
** Dired
   Ahhh, the emacs file browser, better than ranger and others...

   Hide dotfiles:
   #+BEGIN_SRC emacs-lisp

	(use-package dired-hide-dotfiles
	  :ensure t
	  :init

	  (defun my-dired-mode-hook ()
	    "My `dired' mode hook."
	    ;; To hide dot-files by default
	    (dired-hide-dotfiles-mode)

	    ;; To toggle hiding
	    (define-key dired-mode-map "." #'dired-hide-dotfiles-mode))

	  (add-hook 'dired-mode-hook #'my-dired-mode-hook))

	(use-package async
	  :ensure t
	  :init (dired-async-mode 1))
   #+END_SRC
** kill ring popup
   #+BEGIN_SRC emacs-lisp
	(use-package popup-kill-ring
	  :ensure t
	  :bind ("M-y" . popup-kill-ring))

   #+END_SRC

** Dired
   #+BEGIN_SRC emacs-lisp
	(add-hook 'dired-mode-hook
			(lambda ()
			  (dired-hide-details-mode)))

   #+END_SRC

** Scrolling
   
   #+begin_src emacs-lisp
	(setq scroll-step 1)
	(setq scroll-conservatively 10000)
	(setq auto-window-vscroll nil)
	(scroll-bar-mode -1)
   #+end_src
** Sidebar
   
   #+BEGIN_SRC emacs-lisp
	(use-package dired-sidebar
	  :ensure t
	  :commands (dired-sidebar-toggle-sidebar))
	(global-set-key (kbd "<f8>") 'dired-sidebar-toggle-sidebar)
   #+END_SRC
*** Shell
    #+begin_src emacs-lisp
	 (add-hook 'shell-mode-hook 'yas-minor-mode)
	 (add-hook 'shell-mode-hook 'flycheck-mode)
	 (add-hook 'shell-mode-hook 'company-mode)

	 (defun shell-mode-company-init ()
	   (setq-local company-backends '((company-shell
								company-shell-env
								company-etags
								company-dabbrev-code))))

	 (use-package company-shell
	   :ensure t
	   :config
	   (require 'company)
	   (add-hook 'shell-mode-hook 'shell-mode-company-init))
    #+end_src

** Mark multiple
   It's like multiple cursors but well done
   #+begin_src emacs-lisp
	(use-package "mark-multiple"
	  :ensure t
	  :bind ("C-c q" . 'mark-next-like-this))

   #+end_src

* Helm
  fuck ido lol
  #+begin_src emacs-lisp
    (use-package helm
	 :ensure t
	 :bind
	 ("C-x C-f" . 'helm-find-files)
	 ("C-x C-b" . 'helm-buffers-list)
	 ("M-x" . 'helm-M-x)
	 :config
	 (setq helm-autoresize-max-height 0
		  helm-autoresize-min-height 40
		  helm-M-x-fuzzy-match t
		  helm-buffers-fuzzy-matching t
		  helm-recentf-fuzzy-match t
		  helm-semantic-fuzzy-match t
		  helm-imenu-fuzzy-match t
		  helm-split-window-in-side-p nil
		  helm-move-to-line-cycle-in-source nil
		  helm-ff-search-library-in-sexp t
		  helm-scroll-amount 8 
		  helm-echo-input-in-header-line t)
	 :init
	 (helm-mode 1))

    (require 'helm-config)    
    (helm-autoresize-mode 1)
    (define-key helm-find-files-map (kbd "C-b") 'helm-find-files-up-one-level)
    (define-key helm-find-files-map (kbd "C-f") 'helm-execute-persistent-action)
  #+end_src

* Dashboard
  Dashboard. You can change
  ~/.emacs.d/img/logo.png
  own logo instead of Lain.
  #+BEGIN_SRC emacs-lisp
    (use-package dashboard
	 :ensure t
	 :init
	 (dashboard-setup-startup-hook)
	 (setq dashboard-items '((recents  . 7)
						(bookmarks . 7)))
	 (setq dashboard-startup-banner 'logo)
	 (setq dashboard-banner-logo-title "Welcome to Editor MACroS")
	 (setq dashboard-startup-banner "~/.emacs.d/img/banner.txt")
	 (setq dashboard-set-heading-icons t)
	 (setq dashboard-set-file-icons t))
  #+END_SRC