Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening a new empty file shouldn't give message: File digest doesn’t match, so undo history will be discarded. #17

Open
nordlow opened this issue Jan 24, 2024 · 3 comments

Comments

@nordlow
Copy link

nordlow commented Jan 24, 2024

One solution is

(defun undohist-recover-safe ()
  (when (file-exists-p buffer-file-name)
	(condition-case var
		(undohist-recover-1)
      (error (message "Can not recover undo history: %s" var)))))

. Another is

(defun undohist-recover-1 ()
  (let* ((buffer (current-buffer))
         (file (buffer-file-name buffer)))
	(when (file-exists-p file)
	  (let* ((undo-file (make-undohist-file-name file))
			 undo-list)
		(when (and (undohist-recover-file-p file)
				   (file-exists-p undo-file)
				   (or (null buffer-undo-list)
					   (yes-or-no-p "\
buffer-undo-list is not empty. Do you want to recover now? ")))
		  (with-temp-buffer
			(insert-file-contents undo-file)
			(goto-char (point-min))
			(let ((alist (undohist-decode (read (current-buffer)))))
			  (if (string= (md5 buffer) (assoc-default 'digest alist))
				  (setq undo-list (assoc-default 'undo-list alist))
				(message "\
File digest doesn't match, so undo history will be discarded."))))
		  (when (consp undo-list)
			(setq buffer-undo-list undo-list)))))))

.

@jcs090218
Copy link
Collaborator

I don't use this package for a long time. Therefore, feel free to open PRs to fix any issue you've encountered.

@nordlow
Copy link
Author

nordlow commented Jan 24, 2024

I don't use this package for a long time. Therefore, feel free to open PRs to fix any issue you've encountered.

Ok. Do you use another package in place of undohist?

@jcs090218
Copy link
Collaborator

I recommend undo-tree, but I've heard it is hard for Emacs beginners. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants