
;;(setq find-file-hook nil)
(add-hook 'find-file-hook 'd-movement--find-file-hook)
;;(setq find-file-hook '(save-place-find-file-hook d-movement--find-file-hook))
;;(setq find-file-hook '(d-movement--find-file-hook))
;;(setq find-file-hook '(save-place-find-file-hook d-movement--find-file-hook))

(defun d-movement--find-file-hook ()
  (if (d-movement--is-correct-mode)
    (let (m)
      (setq m (point-marker))
      ;;(d-splat (make-string 1 ?\r) "")
      (set-buffer-modified-p nil)
      (d-movement--unpad-buffer)
      (d-movement--pad-buffer)
      ;;(error "smeg")
      (goto-char (marker-position m))
      (set-marker m nil)
      )))

;;(add-hook 'kill-buffer-hook 'd-movement--kill-buffer-hook) ;; save-place-to-alist
;;(add-hook 'kill-emacs-hook 'd-movement--unpad-buffers) ;; save-place-kill-emacs-hook

(defun d-movement--unpad-buffers ()
  (save-excursion
    (let* ((list (buffer-list))
           (ptr  list))
      (while ptr
        (set-buffer (car ptr))
        (if (d-movement--is-correct-mode)
            (d-movement--unpad-buffer))
        (setq ptr (cdr ptr))))))

;;
;; (setq kill-buffer-hook '(save-place-to-alist d-movement--kill-buffer-hook))
;; (add-hook 'kill-buffer-hook 'd-movement--kill-buffer-hook)

(defun d-movement--kill-buffer-hook ()
  (interactive)
  "Not called"
  (if (d-movement--is-correct-mode)
      (let ((m (point-marker)))
        ;;(d-beeps "bufname=%s" (buffer-file-name (current-buffer)))
        ;;(d-foo)
        (d-movement--unpad-buffer)
        (d-splat (make-string 1 ?\r) "")
        (goto-char (marker-position m))
        (set-marker m nil))))

;;(add-hook 'apropos-mode-hook 'd-movement--apropos-mode-hook)
;;(setq apropos-mode-hook 'd-movement--apropos-mode-hook)
;;
;;(defun d-movement--apropos-mode-hook ()
;;  ;;(d-foo)
;;  (message "major-mode=%s" major-mode)
;;  (d-movement--pad-buffer))
;;
(provide 'd-movement-hooks)
