3

Is there a setting in emacs to remember the search/replace string across multiple sessions?

%> emacs -nw fileA
<replace X with Y>

%> emacs -nw fileB
<replace>

should automatically replace X with Y (without having to enter both again)

1
  • 1
    The desktop.el library (when activated) creates a destop file when killing Emacs, which when opened reveals a (setq search-ring . . . and (setq regexp-search-ring . . ., among other saved settings. However, I've never tried to do what you are proposing -- perhaps its worth looking into.
    – lawlist
    Nov 7, 2014 at 6:23

1 Answer 1

2

There's savehist-mode specifically for that kind of saving/restoring:

(savehist-mode 1)
(add-to-list 'savehist-additional-variables 'query-replace-defaults)
3
  • savehist-mode must come last for the settings to take
    – vfclists
    Jul 19, 2017 at 18:31
  • @vfclists: What makes you think so? The way you changed the code, it signals an error because savehist-additional-variables is a void variable at the time the add-to-list is executed.
    – Stefan
    Jul 19, 2017 at 21:30
  • In the examples I see` (savehist-mode 1)` is placed after the add-to-list command. I think initialization must be done via M-x in a live Emacs session, but in the init.el it has to come after the add-to-list commands
    – vfclists
    Jul 19, 2017 at 22:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .