            `(CHANGE-ONLY ,changed-lines))
           ;; Case "REMOVE"
           ((> old-lines-len new-lines-len)
-           (setq removed-lines (lean-take-first-n old-lines (- old-lines-len new-lines-len)))
+           (setq removed-lines (-take (- old-lines-len new-lines-len) old-lines))
            ;; Make sure that we return it in reverse order
            (setq removed-lines (cl-sort removed-lines '>))
            (setq changed-lines new-lines)
            `(REMOVE ,removed-lines ,changed-lines))
           ;; Case "INSERT"
           ((< old-lines-len new-lines-len)
-           (setq inserted-lines (lean-take-last-n new-lines (- new-lines-len old-lines-len)))
+           (setq inserted-lines (-drop old-lines-len new-lines))
            ;; Make sure that we return it in sorted order
            (setq inserted-lines (cl-sort inserted-lines '<))
            (setq changed-lines old-lines)

 - lean-global-before-change-text            : text between beg and end

These information will be used by lean-after-changed-function."
  (setq lean-global-before-change-beg beg)
  (setq lean-global-before-change-end end)
  (setq lean-global-before-change-beg-line-number (line-number-at-pos beg))

;;

(require 'cl-lib)
(require 'dash)
(require 'dash-functional)
(require 'lean-variable)
(require 'lean-util)
(require 'lean-cmd)
(require 'lean-server)
(require 'lean-debug)
(require 'flymake)


(defun lean-fill-placeholder ()
  "Fill the placeholder with a synthesized expression by Lean."
  (interactive)
  (let* ((info-record (lean-get-info-record-at-point))
         (synth (and info-record (cl-first (lean-info-record-synth info-record)))))
    (when synth
      (let ((synth-str
             (replace-regexp-in-string "?M_[0-9]+" "_" (lean-info-synth-body-str synth))))
        (when (search " " synth-str)
          (setq synth-str (concat "(" synth-str ")")))
        (message "synth-str: %s" synth-str)
        (delete-forward-char 1)
        (insert synth-str)))))

(defun lean-eldoc-documentation-function ()
  "Show information of lean expression at point if any"
  (interactive)
  (let ((info-record (lean-get-info-record-at-point))
        info-string)
    (cond
     ((and info-record (lean-info-record-nay info-record))
      (lean-server-log "NAY Detected")
      (run-with-idle-timer lean-eldoc-nay-retry-time nil 'lean-eldoc-documentation-function))
     (info-record
      (setq info-string (lean-info-record-to-string info-record))
      (when info-string
        (message "%s" info-string))))))


;; =======================================================
;; Change Handling
;; =======================================================

(defun lean-before-change-function (beg end)
  "Function attached to before-change-functions hook.
