*** empty log message ***
[emacs.git] / lisp / options.el
blob3697de1080c35aa70cd0e9f5fb86330e9f638996
1 ;;; options.el --- edit Options command for Emacs.
3 ;; Copyright (C) 1985 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
7 ;; This file is part of GNU Emacs.
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 2, or (at your option)
12 ;; any later version.
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.
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 the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
24 ;;; Commentary:
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.
32 ;; The customization buffer feature is intended to make this obsolete.
34 ;;; Code:
36 ;;;###autoload
37 (defun list-options ()
38 "Display a list of Emacs user options, with values and documentation."
39 (interactive)
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 (when (boundp sym)
49 (princ ";; ")
50 (prin1 sym)
51 (princ ":\n\t")
52 (prin1 (symbol-value sym))
53 (terpri)
54 (princ (substitute-command-keys
55 (documentation-property sym 'variable-documentation)))
56 (princ "\n;;\n"))
57 (setq vars (cdr vars))))
58 (with-current-buffer "*List Options*"
59 (Edit-options-mode)
60 (setq buffer-read-only t)))))
62 ;;;###autoload
63 (defun edit-options ()
64 "Edit a list of Emacs user option values.
65 Selects a buffer containing such a list,
66 in which there are commands to set the option values.
67 Type \\[describe-mode] in that buffer for a list of commands.
69 The Custom feature is intended to make this obsolete."
70 (interactive)
71 (list-options)
72 (pop-to-buffer "*List Options*"))
74 (defvar Edit-options-mode-map
75 (let ((map (make-keymap)))
76 (define-key map "s" 'Edit-options-set)
77 (define-key map "x" 'Edit-options-toggle)
78 (define-key map "1" 'Edit-options-t)
79 (define-key map "0" 'Edit-options-nil)
80 (define-key map "p" 'backward-paragraph)
81 (define-key map " " 'forward-paragraph)
82 (define-key map "n" 'forward-paragraph)
83 map)
84 "")
86 ;; Edit Options mode is suitable only for specially formatted data.
87 (put 'Edit-options-mode 'mode-class 'special)
89 (defun Edit-options-mode ()
90 "\\<Edit-options-mode-map>\
91 Major mode for editing Emacs user option settings.
92 Special commands are:
93 \\[Edit-options-set] -- set variable point points at. New value read using minibuffer.
94 \\[Edit-options-toggle] -- toggle variable, t -> nil, nil -> t.
95 \\[Edit-options-t] -- set variable to t.
96 \\[Edit-options-nil] -- set variable to nil.
97 Changed values made by these commands take effect immediately.
99 Each variable description is a paragraph.
100 For convenience, the characters \\[backward-paragraph] and \\[forward-paragraph] move back and forward by paragraphs."
101 (kill-all-local-variables)
102 (set-syntax-table emacs-lisp-mode-syntax-table)
103 (use-local-map Edit-options-mode-map)
104 (make-local-variable 'paragraph-separate)
105 (setq paragraph-separate "[^\^@-\^?]")
106 (make-local-variable 'paragraph-start)
107 (setq paragraph-start "\t")
108 (setq truncate-lines t)
109 (setq major-mode 'Edit-options-mode)
110 (setq mode-name "Options")
111 (run-hooks 'Edit-options-mode-hook))
113 (defun Edit-options-set () (interactive)
114 (Edit-options-modify
115 '(lambda (var) (eval-minibuffer (concat "New " (symbol-name var) ": ")))))
117 (defun Edit-options-toggle () (interactive)
118 (Edit-options-modify '(lambda (var) (not (symbol-value var)))))
120 (defun Edit-options-t () (interactive)
121 (Edit-options-modify '(lambda (var) t)))
123 (defun Edit-options-nil () (interactive)
124 (Edit-options-modify '(lambda (var) nil)))
126 (defun Edit-options-modify (modfun)
127 (save-excursion
128 (let ((buffer-read-only nil) var pos)
129 (re-search-backward "^;; \\|\\`")
130 (forward-char 3)
131 (setq pos (point))
132 (save-restriction
133 (narrow-to-region pos (progn (end-of-line) (1- (point))))
134 (goto-char pos)
135 (setq var (read (current-buffer))))
136 (goto-char pos)
137 (forward-line 1)
138 (forward-char 1)
139 (save-excursion
140 (set var (funcall modfun var)))
141 (kill-sexp 1)
142 (prin1 (symbol-value var) (current-buffer)))))
144 (provide 'options)
146 ;;; options.el ends here