Difference between revisions of "Desktop.el"

From WikEmacs
Jump to navigation Jump to search
(desktop.el)
 
(desktop tips)
Line 7: Line 7:
 
Use the [[desktop]] library to save the state of Emacs from one session to another. Once you save the Emacs desktop (the buffers, their file names, major modes, buffer positions, and so on) then subsequent Emacs sessions reload the saved desktop.  
 
Use the [[desktop]] library to save the state of Emacs from one session to another. Once you save the Emacs desktop (the buffers, their file names, major modes, buffer positions, and so on) then subsequent Emacs sessions reload the saved desktop.  
  
= Save and restore sessions manually =
+
= Usage =
 +
 
 +
== Save and restore sessions manually ==
  
 
You can save the desktop manually with the command {{Command | desktop-save}}, and you can load a saved one with {{Command| desktop-read}}.
 
You can save the desktop manually with the command {{Command | desktop-save}}, and you can load a saved one with {{Command| desktop-read}}.
  
= Save and restore sessions automatically =
+
== Save and restore sessions automatically ==
  
 
You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: add this line in your init file:
 
You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: add this line in your init file:
Line 19: Line 21:
 
If you turn on desktop-save-mode in your init file, then when Emacs starts, it looks for a saved desktop in the current directory. (More precisely, it looks in the directories specified by desktop-path, and uses the first desktop it finds.) Thus, you can have separate saved desktops in different directories, and the starting directory determines which one Emacs reloads. You can save the current desktop and reload one saved in another directory by typing {{Command|desktop-change-dir}}. Typing {{Command|desktop-revert}} reverts to the desktop previously reloaded.  
 
If you turn on desktop-save-mode in your init file, then when Emacs starts, it looks for a saved desktop in the current directory. (More precisely, it looks in the directories specified by desktop-path, and uses the first desktop it finds.) Thus, you can have separate saved desktops in different directories, and the starting directory determines which one Emacs reloads. You can save the current desktop and reload one saved in another directory by typing {{Command|desktop-change-dir}}. Typing {{Command|desktop-revert}} reverts to the desktop previously reloaded.  
  
== Restore big sessions smoothly ==
 
  
By default, all the buffers in the desktop are restored at one go. However, this may be slow if there are a lot of buffers in the desktop. You can specify the maximum number of buffers to restore immediately with the variable <code>desktop-restore-eager</code>; the remaining buffers are restored “lazily”, when Emacs is idle.
 
  
 
= Tips =
 
= Tips =
Line 28: Line 28:
  
 
Type {{Command|desktop-clear}} to empty the Emacs desktop. This kills all buffers except for internal ones, and clears the global variables listed in <code>desktop-globals-to-clear</code>. If you want this to preserve certain buffers, customize the variable <code>desktop-clear-preserve-buffers-regexp</code>, whose value is a regular expression matching the names of buffers not to kill.  
 
Type {{Command|desktop-clear}} to empty the Emacs desktop. This kills all buffers except for internal ones, and clears the global variables listed in <code>desktop-globals-to-clear</code>. If you want this to preserve certain buffers, customize the variable <code>desktop-clear-preserve-buffers-regexp</code>, whose value is a regular expression matching the names of buffers not to kill.  
 +
 +
== Do not save given files or modes ==
 +
 +
You can specify buffers which should not be saved, by name or by mode, e.g.:
 +
 +
  (setq desktop-buffers-not-to-save
 +
        (concat "\\("
 +
                "^nn\\.a[0-9]+\\|\\.log\\|(ftp)\\|^tags\\|^TAGS"
 +
                "\\|\\.emacs.*\\|\\.diary\\|\\.newsrc-dribble\\|\\.bbdb"
 +
                "\\)$"))
 +
  (add-to-list 'desktop-modes-not-to-save 'dired-mode)
 +
  (add-to-list 'desktop-modes-not-to-save 'Info-mode)
 +
  (add-to-list 'desktop-modes-not-to-save 'info-lookup-mode)
 +
  (add-to-list 'desktop-modes-not-to-save 'fundamental-mode)
 +
 +
== Desktops as Bookmarks ==
 +
 +
Library desktop.el provides for the possibility of having multiple saved desktops, but only one per directory. If you use [[Bookmark+]], then you can have any number of desktops and use them as bookmarks, jumping from one to another at any time. You create a desktop bookmark using '''C-x r K''' (command {{Command|bmkp-set-desktop-bookmark}}).
 +
 +
Ordinary desktop files are used to record the information. The bookmark itself records only the location of the desktop file. Bookmarked desktops are intended to be used only as bookmarks, not in the ordinary way (e.g. at Emacs startup), so the locations of the desktop files used are unimportant. In particular, you can have any number of (bookmark) desktop files per directory.
 +
 +
== Restore big sessions smoothly ==
 +
 +
By default, all the buffers in the desktop are restored at one go. However, this may be slow if there are a lot of buffers in the desktop. You can specify the maximum number of buffers to restore immediately with the variable <code>desktop-restore-eager</code>; the remaining buffers are restored “lazily”, when Emacs is idle.
  
 
= See also =
 
= See also =
 +
 +
See the page [[Session_management]]
  
 
== Savehist: save minibuffer history ==
 
== Savehist: save minibuffer history ==

Revision as of 13:02, 30 August 2014

Desktop
Description save and restore the state of Emacs accross sessions
Author name of author
Maintainer name of maintainer
Source no link provided
Part of Emacs yes

Use the desktop library to save the state of Emacs from one session to another. Once you save the Emacs desktop (the buffers, their file names, major modes, buffer positions, and so on) then subsequent Emacs sessions reload the saved desktop.

Usage

Save and restore sessions manually

You can save the desktop manually with the command M-x desktop-save, and you can load a saved one with M-x desktop-read.

Save and restore sessions automatically

You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: add this line in your init file:

    (desktop-save-mode 1)

If you turn on desktop-save-mode in your init file, then when Emacs starts, it looks for a saved desktop in the current directory. (More precisely, it looks in the directories specified by desktop-path, and uses the first desktop it finds.) Thus, you can have separate saved desktops in different directories, and the starting directory determines which one Emacs reloads. You can save the current desktop and reload one saved in another directory by typing M-x desktop-change-dir. Typing M-x desktop-revert reverts to the desktop previously reloaded.


Tips

Clear the desktop

Type M-x desktop-clear to empty the Emacs desktop. This kills all buffers except for internal ones, and clears the global variables listed in desktop-globals-to-clear. If you want this to preserve certain buffers, customize the variable desktop-clear-preserve-buffers-regexp, whose value is a regular expression matching the names of buffers not to kill.

Do not save given files or modes

You can specify buffers which should not be saved, by name or by mode, e.g.:

  (setq desktop-buffers-not-to-save
       (concat "\\("
               "^nn\\.a[0-9]+\\|\\.log\\|(ftp)\\|^tags\\|^TAGS"
               "\\|\\.emacs.*\\|\\.diary\\|\\.newsrc-dribble\\|\\.bbdb"
               "\\)$"))
  (add-to-list 'desktop-modes-not-to-save 'dired-mode)
  (add-to-list 'desktop-modes-not-to-save 'Info-mode)
  (add-to-list 'desktop-modes-not-to-save 'info-lookup-mode)
  (add-to-list 'desktop-modes-not-to-save 'fundamental-mode)

Desktops as Bookmarks

Library desktop.el provides for the possibility of having multiple saved desktops, but only one per directory. If you use Bookmark+, then you can have any number of desktops and use them as bookmarks, jumping from one to another at any time. You create a desktop bookmark using C-x r K (command M-x bmkp-set-desktop-bookmark).

Ordinary desktop files are used to record the information. The bookmark itself records only the location of the desktop file. Bookmarked desktops are intended to be used only as bookmarks, not in the ordinary way (e.g. at Emacs startup), so the locations of the desktop files used are unimportant. In particular, you can have any number of (bookmark) desktop files per directory.

Restore big sessions smoothly

By default, all the buffers in the desktop are restored at one go. However, this may be slow if there are a lot of buffers in the desktop. You can specify the maximum number of buffers to restore immediately with the variable desktop-restore-eager; the remaining buffers are restored “lazily”, when Emacs is idle.

See also

See the page Session_management

Savehist: save minibuffer history

savehist, to save minibuffer history from one session to another.