]> code.delx.au - gnu-emacs/blob - lisp/obsolete/options.el
Convert consecutive FSF copyright years to ranges.
[gnu-emacs] / lisp / obsolete / options.el
1 ;;; options.el --- edit Options command for Emacs
2
3 ;; Copyright (C) 1985, 2001-2011 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6
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
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;; This file has been obsolete since Emacs 22.1.
25
26 ;; This code provides functions to list and edit the values of all global
27 ;; option variables known to loaded Emacs Lisp code. There are two entry
28 ;; points, `list-options' and `edit' options'. The latter enters a major
29 ;; mode specifically for editing option values. Do `M-x describe-mode' in
30 ;; that context for more details.
31
32 ;; The customization buffer feature is intended to make this obsolete.
33
34 ;;; Code:
35
36 ;;;###autoload
37 (defun list-options ()
38 "Display a list of Emacs user options, with values and documentation.
39 It is now better to use Customize instead."
40 (interactive)
41 (with-output-to-temp-buffer "*List Options*"
42 (let (vars)
43 (princ "This facility is obsolete; we recommend using M-x customize instead.")
44
45 (mapatoms (function (lambda (sym)
46 (if (user-variable-p sym)
47 (setq vars (cons sym vars))))))
48 (setq vars (sort vars 'string-lessp))
49 (while vars
50 (let ((sym (car vars)))
51 (when (boundp sym)
52 (princ ";; ")
53 (prin1 sym)
54 (princ ":\n\t")
55 (prin1 (symbol-value sym))
56 (terpri)
57 (princ (substitute-command-keys
58 (documentation-property sym 'variable-documentation)))
59 (princ "\n;;\n"))
60 (setq vars (cdr vars))))
61 (with-current-buffer "*List Options*"
62 (Edit-options-mode)
63 (setq buffer-read-only t)))))
64
65 ;;;###autoload
66 (defun edit-options ()
67 "Edit a list of Emacs user option values.
68 Selects a buffer containing such a list,
69 in which there are commands to set the option values.
70 Type \\[describe-mode] in that buffer for a list of commands.
71
72 The Custom feature is intended to make this obsolete."
73 (interactive)
74 (list-options)
75 (pop-to-buffer "*List Options*"))
76
77 (defvar Edit-options-mode-map
78 (let ((map (make-keymap)))
79 (define-key map "s" 'Edit-options-set)
80 (define-key map "x" 'Edit-options-toggle)
81 (define-key map "1" 'Edit-options-t)
82 (define-key map "0" 'Edit-options-nil)
83 (define-key map "p" 'backward-paragraph)
84 (define-key map " " 'forward-paragraph)
85 (define-key map "n" 'forward-paragraph)
86 map)
87 "")
88
89 ;; Edit Options mode is suitable only for specially formatted data.
90 (put 'Edit-options-mode 'mode-class 'special)
91
92 (defun Edit-options-mode ()
93 "\\<Edit-options-mode-map>\
94 Major mode for editing Emacs user option settings.
95 Special commands are:
96 \\[Edit-options-set] -- set variable point points at. New value read using minibuffer.
97 \\[Edit-options-toggle] -- toggle variable, t -> nil, nil -> t.
98 \\[Edit-options-t] -- set variable to t.
99 \\[Edit-options-nil] -- set variable to nil.
100 Changed values made by these commands take effect immediately.
101
102 Each variable description is a paragraph.
103 For convenience, the characters \\[backward-paragraph] and \\[forward-paragraph] move back and forward by paragraphs."
104 (kill-all-local-variables)
105 (set-syntax-table emacs-lisp-mode-syntax-table)
106 (use-local-map Edit-options-mode-map)
107 (make-local-variable 'paragraph-separate)
108 (setq paragraph-separate "[^\^@-\^?]")
109 (make-local-variable 'paragraph-start)
110 (setq paragraph-start "\t")
111 (setq truncate-lines t)
112 (setq major-mode 'Edit-options-mode)
113 (setq mode-name "Options")
114 (run-mode-hooks 'Edit-options-mode-hook))
115
116 (defun Edit-options-set () (interactive)
117 (Edit-options-modify
118 (lambda (var) (eval-minibuffer (concat "New " (symbol-name var) ": ")))))
119
120 (defun Edit-options-toggle () (interactive)
121 (Edit-options-modify (lambda (var) (not (symbol-value var)))))
122
123 (defun Edit-options-t () (interactive)
124 (Edit-options-modify (lambda (var) t)))
125
126 (defun Edit-options-nil () (interactive)
127 (Edit-options-modify (lambda (var) nil)))
128
129 (defun Edit-options-modify (modfun)
130 (save-excursion
131 (let ((buffer-read-only nil) var pos)
132 (re-search-backward "^;; \\|\\`")
133 (forward-char 3)
134 (setq pos (point))
135 (save-restriction
136 (narrow-to-region pos (progn (end-of-line) (1- (point))))
137 (goto-char pos)
138 (setq var (read (current-buffer))))
139 (goto-char pos)
140 (forward-line 1)
141 (forward-char 1)
142 (save-excursion
143 (set var (funcall modfun var)))
144 (kill-sexp 1)
145 (prin1 (symbol-value var) (current-buffer)))))
146
147 (provide 'options)
148
149 ;;; options.el ends here