(defun tangle-init ()
"If the current buffer is 'init.org' the code-blocks are
tangled, and the tangled file is compiled."
(when (equal (buffer-file-name)
(expand-file-name (concat user-emacs-directory "init.org")))
;; Avoid running hooks when tangling.
(let ((prog-mode-hook nil))
(org-babel-tangle)
(byte-compile-file (concat user-emacs-directory "init.el")))))
(add-hook 'after-save-hook 'tangle-init)
(load-theme 'leuven)
(package-initialize)
(setq-default c-basic-offset 2)
(electric-pair-mode 1)
(setq-default indent-tabs-mode nil)
(setq tab-width 2)
(setq standard-indent 2)
(global-auto-revert-mode t)
(tool-bar-mode -1)
(set-face-attribute 'default nil :font "Fira Mono" )
(set-frame-font "Fira Mono" nil t)
(set-face-font 'variable-pitch "Fira Sans")
Emoji~~
(defun --set-emoji-font (frame)
"Adjust the font settings of FRAME so Emacs can display emoji properly."
(if (eq system-type 'darwin)
;; For NS/Cocoa
(set-fontset-font t 'symbol (font-spec :family "Apple Color Emoji") frame 'prepend)
;; For Linux
(set-fontset-font t 'symbol (font-spec :family "Symbola") frame 'prepend)))
;; For when Emacs is started in GUI mode:
(--set-emoji-font nil)
;; Hook for when a frame is created with emacsclient
;; see https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Frames.html
(add-hook 'after-make-frame-functions '--set-emoji-font)
(setq package-archives
'(("gnu" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
("melpa" . "http://melpa.milkbox.net/packages/")))
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize))
;; Fontify the whole line for headings (with a background color).
(setq org-fontify-whole-heading-line t)
;; You can turn off the display of all the asterisks in a heading but the last one
(setq org-hide-leading-stars t)
;; Auto-Indent
(setq org-indent-mode t)
;; Auto-list
(add-hook 'org-mode-hook (lambda () (org-autolist-mode)))
;; Bullets
(add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
;; Clip-link
(global-set-key (kbd "C-x p i") 'org-cliplink)
;; (add-hook 'org-mode-hook (lambda () (variable-pitch-mode t)))
;; active Babel languages
(org-babel-do-load-languages
'org-babel-load-languages
'((js . t)
(C . t)
(ruby . t)
(http . t)
))
;; stop asking me!
(setq org-confirm-babel-evaluate nil)
(add-hook 'after-init-hook #'global-flycheck-mode)
(with-eval-after-load 'flycheck
'(setq-default flycheck-disabled-checkers
(append flycheck-disabled-checkers
'(javascript-jshint)))
(flycheck-add-mode 'javascript-eslint 'web-mode))
(add-to-list 'auto-mode-alist '("\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(with-eval-after-load 'web-mode
'(setq web-mode-markup-indent-offset 2)
'(setq web-mode-css-indent-offset 2)
'(setq web-mode-code-indent-offset 2)
'(setq web-mode-style-padding 1)
'(setq web-mode-script-padding 1)
'(setq web-mode-enable-css-colorization t))
(add-hook 'js2-mode-hook 'skewer-mode)
(add-hook 'css-mode-hook 'skewer-css-mode)
(add-hook 'html-mode-hook 'skewer-html-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . js2-mode))
(add-to-list 'interpreter-mode-alist '("node" . js2-mode))
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(add-hook 'js2-mode-hook #'js2-highlight-vars-mode)
(setq-default js2-basic-offset 2)
(add-hook 'after-init-hook 'helm-mode)
(add-hook 'after-init-hook 'projectile-global-mode)
(setq projectile-completion-system 'helm)
(add-hook 'projectile-mode-hook 'helm-projectile-on)
(add-hook 'after-init-hook 'global-company-mode)
(with-eval-after-load 'company
(add-to-list 'company-backends 'company-math-symbols-unicode)
(add-to-list 'company-backends 'company-emoji)
(company-quickhelp-mode 1))
(add-hook 'json-mode-hook
(lambda ()
(make-local-variable 'js-indent-level)
(setq js-indent-level 2)))
(defun rename-current-buffer-file ()
"Renames current buffer and file it is visiting."
(interactive)
(let ((name (buffer-name))
(filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
(error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
(if (get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name)
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))))
(global-set-key (kbd "C-x C-r") 'rename-current-buffer-file)