 ;;
 
 ;;; Change log:
+;;
+;; 2019/07/20
+;;      * Finish document.
 ;;
 ;; 2019/05/16
 ;;      * First released.


(define-derived-mode snails-mode text-mode "snails"
  (interactive)
  (kill-all-local-variables)
  (setq major-mode 'snails-mode)
  (setq mode-name "snails")
  (use-local-map snails-mode-map)
  (run-hooks 'snails-mode-hook))

(defun snails ()
  (interactive)
  (snails-create-input-buffer)
  (snails-create-content-buffer)
  (snails-search "")
  (snails-create-frame)
  )

(defun snails-create-input-buffer ()
  (with-current-buffer (get-buffer-create snails-input-buffer)
    (erase-buffer)
    (snails-mode)
    (buffer-face-set '(:background "#222" :foreground "gold" :height 250))
    (set-face-background 'hl-line "#222")
    (setq-local global-hl-line-overlay nil)
    (setq-local header-line-format nil)
    (setq-local mode-line-format nil)
    ))

(defun snails-create-content-buffer ()
  (with-current-buffer (get-buffer-create snails-content-buffer)
    (erase-buffer)
    (buffer-face-set '(:background "#111" :height 130))
    (setq-local header-line-format nil)
    (setq-local mode-line-format nil)
    (setq-local cursor-type nil)
    ))

(defun snails-monitor-input (begin end length)
  (when (string-equal (buffer-name) snails-input-buffer)
    (with-current-buffer snails-content-buffer
      (let* ((input (with-current-buffer snails-input-buffer

          candidate-name-start
          candidate-name-end
          candidate-content-start
          candidate-content-end)
      ;; Render backend result.
      (dolist (candiate-list snails-candiate-list)
        ;; Just render backend result when return candidate is not nil.
        (when candiate-list
          ;; Render header line with overlay.
          (setq header-line-start (point))
          (insert (format "%s\n" (nth candiate-index backend-names)))
          (backward-char)
