*** empty log message ***
[bpt/emacs.git] / lisp / options.el
CommitLineData
07c61707
RA
1;; Edit Options command for Emacs.
2;; Copyright (C) 1985 Free Software Foundation, Inc.
3
4;; This file is part of GNU Emacs.
5
6;; GNU Emacs is free software; you can redistribute it and/or modify
7;; it under the terms of the GNU General Public License as published by
8;; the Free Software Foundation; either version 1, or (at your option)
9;; any later version.
10
11;; GNU Emacs is distributed in the hope that it will be useful,
12;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;; GNU General Public License for more details.
15
16;; You should have received a copy of the GNU General Public License
17;; along with GNU Emacs; see the file COPYING. If not, write to
18;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
21(defun list-options ()
22 "Display a list of Emacs user options, with values and documentation."
23 (interactive)
24 (save-excursion
25 (set-buffer (get-buffer-create "*List Options*"))
26 (Edit-options-mode))
27 (with-output-to-temp-buffer "*List Options*"
28 (let (vars)
29 (mapatoms (function (lambda (sym)
30 (if (user-variable-p sym)
31 (setq vars (cons sym vars))))))
32 (setq vars (sort vars 'string-lessp))
33 (while vars
34 (let ((sym (car vars)))
35 (princ ";; ")
36 (prin1 sym)
37 (princ ":\n\t")
38 (prin1 (symbol-value sym))
39 (terpri)
40 (princ (substitute-command-keys
41 (documentation-property sym 'variable-documentation)))
42 (princ "\n;;\n"))
43 (setq vars (cdr vars))))))
44
45(defun edit-options ()
46 "Edit a list of Emacs user option values.
47Selects a buffer containing such a list,
48in which there are commands to set the option values.
49Type \\[describe-mode] in that buffer for a list of commands."
50 (interactive)
51 (list-options)
52 (pop-to-buffer "*List Options*"))
53
54(defvar Edit-options-mode-map
55 (let ((map (make-keymap)))
56 (define-key map "s" 'Edit-options-set)
57 (define-key map "x" 'Edit-options-toggle)
58 (define-key map "1" 'Edit-options-t)
59 (define-key map "0" 'Edit-options-nil)
60 (define-key map "p" 'backward-paragraph)
61 (define-key map " " 'forward-paragraph)
62 (define-key map "n" 'forward-paragraph)
63 map)
64 "")
65
66;; Edit Options mode is suitable only for specially formatted data.
67(put 'Edit-options-mode 'mode-class 'special)
68
69(defun Edit-options-mode ()
70 "Major mode for editing Emacs user option settings.
71Special commands are:
72s -- set variable point points at. New value read using minibuffer.
73x -- toggle variable, t -> nil, nil -> t.
741 -- set variable to t.
750 -- set variable to nil.
76Changed values made by these commands take effect immediately.
77
78Each variable description is a paragraph.
79For convenience, the characters p and n move back and forward by paragraphs."
80 (kill-all-local-variables)
81 (set-syntax-table emacs-lisp-mode-syntax-table)
82 (use-local-map Edit-options-mode-map)
83 (make-local-variable 'paragraph-separate)
84 (setq paragraph-separate "[^\^@-\^?]")
85 (make-local-variable 'paragraph-start)
86 (setq paragraph-start "^\t")
87 (setq truncate-lines t)
88 (setq major-mode 'Edit-options-mode)
89 (setq mode-name "Options")
90 (run-hooks 'Edit-options-mode-hook))
91
92(defun Edit-options-set () (interactive)
93 (Edit-options-modify
94 '(lambda (var) (eval-minibuffer (concat "New " (symbol-name var) ": ")))))
95
96(defun Edit-options-toggle () (interactive)
97 (Edit-options-modify '(lambda (var) (not (symbol-value var)))))
98
99(defun Edit-options-t () (interactive)
100 (Edit-options-modify '(lambda (var) t)))
101
102(defun Edit-options-nil () (interactive)
103 (Edit-options-modify '(lambda (var) nil)))
104
105(defun Edit-options-modify (modfun)
106 (save-excursion
107 (let (var pos)
108 (re-search-backward "^;; \\|\\`")
109 (forward-char 3)
110 (setq pos (point))
111 (save-restriction
112 (narrow-to-region pos (progn (end-of-line) (1- (point))))
113 (goto-char pos)
114 (setq var (read (current-buffer))))
115 (goto-char pos)
116 (forward-line 1)
117 (forward-char 1)
118 (save-excursion
119 (set var (funcall modfun var)))
120 (kill-sexp 1)
121 (prin1 (symbol-value var) (current-buffer)))))
122