1 ;;; xwem-desktop.el ---
3 ;; Copyright (C) 2004,2005 by XWEM Org.
5 ;; Author: Zajcev Evgeny <zevlg@yandex.ru>
6 ;; Steve Youngs <steve@youngs.au.com>
7 ;; Created: Wed Jul 14 10:16:20 MSD 2004
8 ;; Keywords: xwem, desktop
9 ;; X-CVS: $Id: xwem-desktop.el,v 1.7 2005-04-04 19:54:10 lg Exp $
11 ;; This file is part of XWEM.
13 ;; XWEM is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; XWEM is distributed in the hope that it will be useful, but WITHOUT
19 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
21 ;; License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with XEmacs; see the file COPYING. If not, write to the Free
25 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 ;;; Synched up with: Not in FSF
32 ;; To start using, add something like:
34 ;; (add-hook 'xwem-exit-hook 'xwem-desktop-save)
35 ;; (xwem-desktop-load)
41 ;; * Save registers betwean sessions, maybe by using expectances.
49 (defgroup xwem-desktop nil
50 "Group to customize xwem desktop."
51 :prefix "xwem-desktop-"
54 (defcustom xwem-desktop-goals
55 '((keymap . xwem-user-macros-prefix)
56 (xwem-read-filename-history . 100)
57 (xwem-launcher-history . 100)
58 (xwem-read-expression-history . 100)
59 (xwem-open-file-commands-alist . 1024))
60 "*List of variables to save.
61 Each element is eather symbol or cons cell in form.
62 \(symbol . maxsize\)."
64 (choice (const :tag "Frames configuration" frames-config)
65 (cons :tag "Keymap goal"
66 (const :tag "Keymap" keymap)
67 (symbol :tag "Keymap prefix"))
69 (choice (const :tag "Launcher history"
70 xwem-launcher-history)
71 (const :tag "Expression history"
72 xwem-read-expression-history)
73 (symbol :tag "Custom history"))
74 (number :tag "Max Size"))))
77 (defcustom xwem-desktop-onetime-goals
78 '((frames-config . "frames-config"))
79 "One time goals to save."
80 :type '(repeat (choice (const :tag "Frames config" frames-config)
82 (symbol :tag "Custom Symbol")
83 (number :tag "Max Size"))))
86 ;;; Internal variables
88 (defun xwem-desktop-save-element (el &optional buffer)
90 EL is one of that occurs in `xwem-desktop-goals'."
92 (setq buffer (current-buffer)))
93 (cond ((eq el 'frames-config)
94 ;; Store frames configuration here
95 (xwem-frame-config-dump1 (xwem-frame-configuration) buffer t))
98 (princ "\n;; Symbol value\n" buffer)
99 (princ (concat "(setq " (symbol-name el) " "
100 (if (listp (symbol-value el))
102 (prin1-to-string (symbol-value el)) ")")
103 (prin1-to-string (symbol-value el)))
107 ((and (consp el) (numberp (cdr el)))
108 (princ "\n;; List\n" buffer)
110 (clist (symbol-value (car el)))
112 (while (and clist (> limit 0))
113 (unless (member (car clist) result)
114 (setq result (cons (car clist) result))
116 (setq clist (cdr clist)))
117 (setq result (nreverse result))
118 (princ (concat "(setq " (symbol-name (car el)) " "
119 "(quote " (prin1-to-string result) ")"
123 ((and (consp el) (eq (car el) 'keymap))
124 (let* ((kmap (xwem-kbd-fixup-keymap (cdr el)))
125 (kmap-name (keymap-name kmap)))
126 (princ (format "\n;; Keymap (%s)\n" kmap-name) buffer)
127 (map-keymap #'(lambda (kseq fbind)
128 (princ (concat "(define-key (quote "
129 (prin1-to-string kmap-name) ") "
130 "(quote " (prin1-to-string kseq) ") "
131 "(quote " (prin1-to-string fbind) ")"
136 (t (xwem-message 'warning "Strange el: `%S', skiping .." el))))
138 ;;;###autoload(autoload 'xwem-desktop-save "xwem-desktop" nil t)
139 (define-xwem-command xwem-desktop-save (&optional file)
140 "Save things described in `xwem-desktop-goals' into FILE.
141 Defaultly FILE is ~/.xwem/xwem-desktop.el"
142 (xwem-interactive "FSave xwem desktop to: ")
144 (setq file (expand-file-name "xwem-desktop.el" xwem-dir)))
149 (format ";;; %s --- Desktop configuration for XWEM.\n"
150 (file-name-nondirectory file))
151 "\n;; NOTE: This file is automatically generated by xwem-desktop\n\n")
153 ;; Set print-XX to nil to make full printing of objects
154 (let ((print-length nil)
156 (mapc 'xwem-desktop-save-element xwem-desktop-goals))
158 (insert (format "\n;;; %s ends here\n" (file-name-nondirectory file)))
159 (write-region (point-min) (point-max) file)))
161 ;;;###autoload(autoload 'xwem-desktop-load "xwem-desktop" nil t)
162 (define-xwem-command xwem-desktop-load (&optional file)
163 "Load saved desktop from FILE.
164 Default FILE is ~/.xwem/xwem-desktop.el."
165 (xwem-interactive "FLoad xwem desktop from: ")
168 (setq file (expand-file-name "xwem-desktop.el" xwem-dir)))
172 ;;;###autoload(autoload 'xwem-desktop-save-onetime "xwem-desktop" nil t)
173 (define-xwem-command xwem-desktop-save-onetime ()
174 "Save onetime goals if necessary."
177 (let ((file (expand-file-name (cdr gg) xwem-dir)))
178 (unless (file-exists-p file)
179 (let ((xwem-desktop-goals (list (car gg))))
180 (xwem-desktop-save file)))))
181 xwem-desktop-onetime-goals))
183 ;;;###autoload(autoload 'xwem-desktop-load-onetime "xwem-desktop" nil t)
184 (define-xwem-command xwem-desktop-load-onetime ()
185 "Load onetime goals."
188 (let ((file (expand-file-name (cdr gg) xwem-dir)))
189 (when (file-exists-p file)
191 xwem-desktop-onetime-goals))
194 (provide 'xwem-desktop)
196 ;;; xwem-desktop.el ends here