                                    (dired-directory dired-directory "%b")))))
 (add-hook 'after-init-hook #'modi/update-frame-title)
 
+;;; Fonts
+
+;;;; Font Lock
 ;; Enable font-lock or syntax highlighting globally
 (global-font-lock-mode 1)
 ;; Use the maximum decoration level available for color highlighting
 (setq font-lock-maximum-decoration t)
 
-;; FONTS
+;;;;; Syntax highlight .vimrc files (I know, blasphemy!)
+;; http://stackoverflow.com/a/4238738/1219634
+(define-generic-mode 'vimrc-generic-mode
+  '()
+  '()
+  '(("^[\t ]*:?\\(!\\|ab\\|map\\|unmap\\)[^\r\n\"]*\"[^\r\n\"]*\\(\"[^\r\n\"]*\"[^\r\n\"]*\\)*$"
+     (0 font-lock-warning-face))
+    ("\\(^\\|[\t ]\\)\\(\".*\\)$"
+     (2 font-lock-comment-face))
+    ("\"\\([^\n\r\"\\]\\|\\.\\)*\""
+     (0 font-lock-string-face)))
+  '("/vimrc\\'" "\\.vim\\(rc\\)?\\'")
+  '((lambda ()
+      (modify-syntax-entry ?\" ".")))
+  "Generic mode for Vim configuration files.")
+
+(setq auto-mode-alist (append '(("\\.vimrc.*\\'" . vimrc-generic-mode)
+                                ("\\.vim\\'"     . vimrc-generic-mode))
+                              auto-mode-alist))
+
+;;;; Fix italics
 ;; Make the italics show as actual italics. For some unknown reason, the below
 ;; is needed to render the italics in org-mode. The issue could be related to
 ;; the fonts in use. But having this doesn't hurt regardless.
 (set-face-attribute 'italic nil :inherit nil :slant 'italic)
 
-;; Default fonts for Windows
+;;;; Windows Font
 (when (eq system-type 'windows-nt)
   (set-face-attribute 'default nil :family "Consolas"))
 
-(defun modi/font-size-adj (&optional arg)
-  "The default C-x C-0/-/= bindings do an excellent job of font resizing.
-They, though, do not change the font sizes for the text outside the buffer,
-example in mode-line. Below function changes the font size in those areas too.
-
-M-<NUM> M-x modi/font-size-adj increases font size by NUM points if NUM is +ve,
-                               decreases font size by NUM points if NUM is -ve
-                               resets    font size if NUM is 0."
+;;;; Global Font Resize
+(defun modi/global-font-size-adj (scale &optional absolute)
+  "Adjust the font sizes globally: in all the buffers, mode line, echo area, etc.
+
+The inbuilt `text-scale-adjust' function (bound to C-x C-0/-/= by default)
+does an excellent job of font resizing. But it does not change the font sizes
+of text outside the current buffer; for example, in the mode line.
+
+M-<SCALE> COMMAND increases font size by SCALE points if SCALE is +ve,
+                  decreases font size by SCALE points if SCALE is -ve
+                  resets    font size if SCALE is 0.
+
+If ABSOLUTE is non-nil, text scale is applied relative to the default font size
+`default-font-size-pt'. Else, the text scale is applied relative to the current
+font size."
   (interactive "p")
-  (if (= arg 0)
+  (if (= scale 0)
       (setq font-size-pt default-font-size-pt)
-    (setq font-size-pt (+ font-size-pt arg)))
+    (if (bound-and-true-p absolute)
+        (setq font-size-pt (+ default-font-size-pt scale))
+      (setq font-size-pt (+ font-size-pt scale))))
   ;; The internal font size value is 10x the font size in points unit.
   ;; So a 10pt font size is equal to 100 in internal font size value.
   (set-face-attribute 'default nil :height (* font-size-pt 10)))
 
-(defun modi/font-size-incr ()  (interactive) (modi/font-size-adj +1))
-(defun modi/font-size-decr ()  (interactive) (modi/font-size-adj -1))
-(defun modi/font-size-reset () (interactive) (modi/font-size-adj 0))
-
-(modi/font-size-reset) ; Initialize font-size-pt var to the default value
-
-;; Line truncation
+(defun modi/global-font-size-incr ()  (interactive) (modi/global-font-size-adj +1))
+(defun modi/global-font-size-decr ()  (interactive) (modi/global-font-size-adj -1))
+(defun modi/global-font-size-reset () (interactive) (modi/global-font-size-adj 0))
+
+;; Initialize font-size-pt var to the default value
+(modi/global-font-size-reset)
+
+;; Usage: C-c - = - 0 = = = = - - 0
+;; Usage: C-c = = 0 - = - = = = = - - 0
+(defhydra hydra-font-resize (nil
+                             "C-c"
+                             :bind (lambda (key cmd) (bind-key key cmd modi-mode-map))
+                             :color red
+                             :hint nil)
+  "
+[Font Size]     _C--_/_-_ Decrease     _C-=_/_=_ Increase     _C-0_/_0_ Reset     _q_ Cancel
+"
+  ("C--" modi/global-font-size-decr)
+  ("-"   modi/global-font-size-decr :bind nil)
+  ("C-=" modi/global-font-size-incr)
+  ("="   modi/global-font-size-incr :bind nil)
+  ("+"   modi/global-font-size-incr :bind nil)
+  ("C-0" modi/global-font-size-reset :color blue)
+  ("0"   modi/global-font-size-reset :bind nil)
+  ("q"   nil :color blue))
+
+(global-unset-key (kbd "<C-down-mouse-1>"))
+;; <C-down-mouse-1> is bound to `mouse-buffer-menu' by default. It is
+;; inconvenient when that mouse menu pops up when I don't need it
+;; to. And actually I have never used that menu :P
+
+(bind-keys
+ :map modi-mode-map
+  ;; Make Control+mousewheel do increase/decrease font-size
+  ;; http://ergoemacs.org/emacs/emacs_mouse_wheel_config.html
+  ("<C-mouse-1>" . modi/global-font-size-reset) ; C + left mouse click
+  ("<C-mouse-4>" . modi/global-font-size-incr) ; C + wheel-up
+  ("<C-mouse-5>" . modi/global-font-size-decr)) ; C + wheel-down
+
+(>=e "25.0"
+    ;; Do not resize the frame when adjusting the font size
+    (add-to-list 'frame-inhibit-implied-resize 'font))
+
+;;; Line truncation
 ;; Enable truncation. This setting does NOT apply to windows split using `C-x 3`
 (setq-default truncate-lines t)
 ;; Do `M-x toggle-truncate-lines` to toggle truncation mode.

    (setq header-line-format nil))
  (force-mode-line-update))

;; Enable / Disable Fringe
(defun enable-fringe ()
  (interactive)
  (fringe-mode '(nil . nil) ))
(defun disable-fringe ()
  (interactive)
  (fringe-mode '(0 . 0) ))

;; Generic mode to syntax highlight .vimrc files (I know, blasphemy!)
;; http://stackoverflow.com/a/4238738/1219634
(define-generic-mode 'vimrc-generic-mode
  '()
  '()
  '(("^[\t ]*:?\\(!\\|ab\\|map\\|unmap\\)[^\r\n\"]*\"[^\r\n\"]*\\(\"[^\r\n\"]*\"[^\r\n\"]*\\)*$"
     (0 font-lock-warning-face))
    ("\\(^\\|[\t ]\\)\\(\".*\\)$"
     (2 font-lock-comment-face))
    ("\"\\([^\n\r\"\\]\\|\\.\\)*\""
     (0 font-lock-string-face)))
  '("/vimrc\\'" "\\.vim\\(rc\\)?\\'")
  '((lambda ()
      (modify-syntax-entry ?\" ".")))
  "Generic mode for Vim configuration files.")

(setq auto-mode-alist (append '(("\\.vimrc.*\\'" . vimrc-generic-mode)
                                ("\\.vim\\'"     . vimrc-generic-mode))
                              auto-mode-alist))

;; Coloring regions that have ANSI color codes in them
;; http://unix.stackexchange.com/a/19505/57923
(defun ansi-color-apply-on-region-int (beg end)
  "Colorize using the ANSI color codes."
  (interactive "r")
  (ansi-color-apply-on-region beg end))

;; Show long lines
;; http://stackoverflow.com/a/6346547/1219634
(use-package whitespace
  :commands (modi/show-long-lines)

      (setq hcz-set-cursor-color-buffer (buffer-name)))))
(add-hook 'post-command-hook #'hcz-set-cursor-color-according-to-mode)

;;; Prez Mode
(defvar prez-mode--buffer-name nil
  "Variable to store the name of the buffer in which the `prez-mode' was enabled.")

(defvar prez-mode--frame-configuration nil
  "Variable to store the frame configuration before `prez-mode' was enabled.")

(define-minor-mode prez-mode
  "Minor mode for presentations.

- The frame size is reduced.
- All windows other than the current one are deleted.
- Font size is increased.
- Theme is toggled from the default dark theme to light theme.

Toggling off this mode reverts everything to their original states."
  :init-value nil
  :lighter    " Prez"
  (if prez-mode
      ;; Enable prez mode
      (progn
        (setq prez-mode--buffer-name (buffer-name))
        (setq prez-mode--frame-configuration (current-frame-configuration))
        (set-frame-size nil 110 40) ; rows and columns w h
        (delete-other-windows)
        (modi/global-font-size-adj +3 :absolute)
        (toggle-theme))
    ;; Disable prez mode
    (progn
      (set-frame-configuration prez-mode--frame-configuration)
      (switch-to-buffer prez-mode--buffer-name)
      (modi/global-font-size-reset)
      (toggle-theme))))

(defun turn-on-prez-mode ()
  "Turns on prez-mode."
  (interactive)
  (prez-mode 1))

(define-globalized-minor-mode global-prez-mode prez-mode turn-on-prez-mode)

;; F8 key can't be used as it launches the VNC menu
;; It can though be used with shift/ctrl/alt keys
(bind-key "<S-f8>" #'prez-mode modi-mode-map)
(key-chord-define-global "8i" #'prez-mode) ; alternative to S-F8

;;; Hidden Mode Line Mode
;; (works only when one window is open)
;; FIXME: Make this activate only if one window is open
;; See http://bzg.fr/emacs-hide-mode-line.html
