Open paul-xie-rs opened 7 years ago
You can save the current state of the ivy-views
variable to your config. That's about it.
It might be useful to have a command to save it, but a lot of decisions have to be made:
~/.emacs.d/
); maybe there's some API for this, I don't knowIt's doable in general, but maybe it's better to leave it up to the user to configure it to their preference. Or maybe have a separate package like ivy-save-view-mode
(akin to recentf-mode
) that lets the user configure everything to their liking without bloating ivy.el too much.
Thank you. Sometimes I just need to restart Emacs. But I don't want to lost all of my ivy-views. So I wrote some functions to do this:
(defun peng-save-ivy-views () (interactive) (with-temp-file "~/.emacs.d/ivy-views" (prin1 ivy-views (current-buffer)) (message "save ivy-views to ~/.emacs.d/ivy-views")))
(defun peng-load-ivy-views () (interactive) (setq ivy-views (with-temp-buffer (insert-file-contents "~/.emacs.d/ivy-views") (read (current-buffer)))) (message "load ivy-views"))
It enough for me.
Thank you very much.
You're welcome.
does this actually work? prin1
simply outputs a list whose 2nd item is #<window-configuration>
. That seems like a placeholder for some complicated data that stores the actual window configuration.
You can save the current state of the
ivy-views
variable to your config.
I have 4 buffers split horizontally across a single window. After ivy-push-view
, I looked at the ivy-views
variable. Here is what it shows:
(("{} some name" #<window-configuration>))
How do I save the object #<window-configuration>
to my config? The command prin1
will only provide a readable representation of the object.
does this actually work?
As long as your ivy-views
doesn't contain window configuration objects, I don't see why it wouldn't work (disclaimer: I don't use ivy-views
and have not tested this).
prin1
simply outputs a list whose 2nd item is#<window-configuration>
.
This is expected, as window configuration objects can't be read or printed. See (info "(elisp) Window Configuration Type")
.
That seems like a placeholder for some complicated data that stores the actual window configuration.
Yes, specifically it's an opaque Elisp object.
How do I save the object
#<window-configuration>
to my config?
You can't, since window configurations don't have read/print syntax and cannot persist across Emacs sessions. But you can use window states instead. Quoth (info "(elisp) Window Configurations")
:
The objects returned by ‘current-window-configuration’ die together
with the Emacs process. In order to store a window configuration on
disk and read it back in another Emacs session, you can use the
functions described next. These functions are also useful to clone the
state of a frame into an arbitrary live window
(‘set-window-configuration’ effectively clones the windows of a frame
into the root window of that very frame only).
-- Function: window-state-get &optional window writable
This function returns the state of WINDOW as a Lisp object. The
argument WINDOW must be a valid window and defaults to the root
window of the selected frame.
If the optional argument WRITABLE is non-‘nil’, this means to not
use markers for sampling positions like ‘window-point’ or
‘window-start’. This argument should be non-‘nil’ when the state
will be written to disk and read back in another session.
Together, the argument WRITABLE and the variable
‘window-persistent-parameters’ specify which window parameters are
saved by this function. See Window Parameters.
The value returned by ‘window-state-get’ can be used in the same
session to make a clone of a window in another window. It can be also
written to disk and read back in another session. In either case, use
the following function to restore the state of the window.
-- Function: window-state-put state &optional window ignore
This function puts the window state STATE into WINDOW. The
argument STATE should be the state of a window returned by an
earlier invocation of ‘window-state-get’, see above. The optional
argument WINDOW can be either a live window or an internal window
(see Windows and Frames). If WINDOW is not a live window, it
is replaced by a new live window created on the same frame before
putting STATE into it. If WINDOW is ‘nil’, it puts the window
state into a new window.
If the optional argument IGNORE is non-‘nil’, it means to ignore
minimum window sizes and fixed-size restrictions. If IGNORE is
‘safe’, this means windows can get as small as one line and/or two
columns.
Reopening due to the continued discussions and unresolved issues in #1113 and #2909.
I use ivy-push-view to save the windows layout. It's very useful for me. But when I restart my Emacs. The views are all lost. Can I do something to save the views to file and load them again when restart Emacs?