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