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