 ;; to work even in split windows
 (setq-default truncate-partial-width-windows nil)
 
-;; Visual Line Mode
+(bind-key "C-x t" #'toggle-truncate-lines modi-mode-map)
+
+;;; Visual Line Mode
 ;; Do word wrapping only at word boundaries
 (defconst modi/visual-line-mode-hooks '(org-mode-hook
                                         markdown-mode-hook)

                                   (dired-directory dired-directory "%b")))))
(add-hook 'after-init-hook #'modi/update-frame-title)

;; 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
;; 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
(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."
  (interactive "p")
  (if (= arg 0)
      (setq font-size-pt default-font-size-pt)
    (setq font-size-pt (+ font-size-pt arg)))
  ;; 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
;; 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 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
