1

While editing files, time to time I regret deleting some redundant parts which afterwards become necessary.

Let's say you are writing a letter and first you explained your thoughts with redundantly very long sentences. Later on, you come up with an on-spot phrase for them and rephrase with them. But later again, on 2nd thought, you think the words weren't right phrasing.

To go back to original sentences, in my knowledge, is to use undo, or undo-tree, to go back in history. But you have to keep pressing the key til it hits that version.

Is there any easy way to search in undo-history to get back to the version? I'm looking for something along the line of helm-occur functionality, which searches your word in current buffer and lists all the matching lines with line number, but works for the undo-history.

Prasanna
  • 1,540
  • 16
  • 30
Dummy
  • 19
  • 3
  • you can use version control software to keep various versions of your text and all that with a same file name . I would recommend you to look into VC manual – Prasanna Oct 06 '16 at 02:28
  • I have so little experience in version control, git. Can version control search things in historical changes? As far as I know, no such function in git. – Dummy Oct 06 '16 at 03:57
  • Looks like https://www.emacswiki.org/emacs/BrowseKillRing fits your special purpose. If the changes are not too old they are still in the kill ring and you can search the kill ring in the browse-kill-ring buffer. – Tobias Oct 06 '16 at 09:04
  • @Tobias Not all changes are kills though. – T. Verron Oct 06 '16 at 09:36
  • @Dummy I'm pretty sure that you can get the VC history in an emacs buffer where you can use your favorite search tool. – T. Verron Oct 06 '16 at 09:37
  • Searching the changes in git version control for a word foobar works with git log --patch -Sfoobar. The --patch option causes git to output also the differences and the -S option is used for the search in the differences. If you only want to see the log messages of the changes where foobar occurs you can also just use git log -Sfoobar. – Tobias Oct 06 '16 at 10:07
  • Related question maybe (without any better answer though) : http://emacs.stackexchange.com/q/27602/184 – T. Verron Oct 06 '16 at 14:35
  • @Tobias thanks, right you are. the kill-ring is very close to what I want. only problem is that it is shared through all buffers. I have too many buffer tabs open with helm-elscreen. I don't think I can keep track of which kill belongs to which buffer. – Dummy Oct 08 '16 at 02:24
  • @T. Verron Thanks, I gave a try at magit with same command Tobias mentioned. A bit complex but it seems it does the job. – Dummy Oct 08 '16 at 02:24
  • Restrict browse-kill-ring to current buffer: (require 'browse-kill-ring) (defun browse-kill-ring-current-buffer (itemsArg) (list (cl-delete-if (lambda (item) (let ((buf (get-text-property 0 'src-buffer item))) (null (and buf (equal buf browse-kill-ring-original-buffer))))) (car itemsArg)))) (advice-add #'browse-kill-ring-insert-as-separated :filter-args #'browse-kill-ring-current-buffer) (defun browse-kill-ring-add-src-buffer-to-kill (str) (propertize str 'src-buffer (current-buffer))) (advice-add #'filter-buffer-substring :filter-return #'browse-kill-ring-add-src-buffer-to-kill) – Tobias Oct 08 '16 at 13:14
  • Sorry for the mess in the previous comment. (Limited number of characters and limited formatting.) You may also need to add (require 'cl-lib) at the front. Also note, that this is a dirty hack. – Tobias Oct 08 '16 at 13:17

0 Answers0