1 ;;; options.el --- edit Options command for Emacs
3 ;; Copyright (C) 1985, 2002, 2003, 2004, 2005,
4 ;; 2006 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; This code provides functions to list and edit the values of all global
28 ;; option variables known to loaded Emacs Lisp code. There are two entry
29 ;; points, `list-options' and `edit' options'. The latter enters a major
30 ;; mode specifically for editing option values. Do `M-x describe-mode' in
31 ;; that context for more details.
33 ;; The customization buffer feature is intended to make this obsolete.
38 (defun list-options ()
39 "Display a list of Emacs user options, with values and documentation.
40 It is now better to use Customize instead."
42 (with-output-to-temp-buffer "*List Options*"
44 (mapatoms (function (lambda (sym)
45 (if (user-variable-p sym)
46 (setq vars (cons sym vars))))))
47 (setq vars (sort vars 'string-lessp))
49 (let ((sym (car vars)))
54 (prin1 (symbol-value sym))
56 (princ (substitute-command-keys
57 (documentation-property sym 'variable-documentation)))
59 (setq vars (cdr vars))))
60 (with-current-buffer "*List Options*"
62 (setq buffer-read-only t)))))
65 (defun edit-options ()
66 "Edit a list of Emacs user option values.
67 Selects a buffer containing such a list,
68 in which there are commands to set the option values.
69 Type \\[describe-mode] in that buffer for a list of commands.
71 The Custom feature is intended to make this obsolete."
74 (pop-to-buffer "*List Options*"))
76 (defvar Edit-options-mode-map
77 (let ((map (make-keymap)))
78 (define-key map "s" 'Edit-options-set)
79 (define-key map "x" 'Edit-options-toggle)
80 (define-key map "1" 'Edit-options-t)
81 (define-key map "0" 'Edit-options-nil)
82 (define-key map "p" 'backward-paragraph)
83 (define-key map " " 'forward-paragraph)
84 (define-key map "n" 'forward-paragraph)
88 ;; Edit Options mode is suitable only for specially formatted data.
89 (put 'Edit-options-mode 'mode-class 'special)
91 (defun Edit-options-mode ()
92 "\\<Edit-options-mode-map>\
93 Major mode for editing Emacs user option settings.
95 \\[Edit-options-set] -- set variable point points at. New value read using minibuffer.
96 \\[Edit-options-toggle] -- toggle variable, t -> nil, nil -> t.
97 \\[Edit-options-t] -- set variable to t.
98 \\[Edit-options-nil] -- set variable to nil.
99 Changed values made by these commands take effect immediately.
101 Each variable description is a paragraph.
102 For convenience, the characters \\[backward-paragraph] and \\[forward-paragraph] move back and forward by paragraphs."
103 (kill-all-local-variables)
104 (set-syntax-table emacs-lisp-mode-syntax-table)
105 (use-local-map Edit-options-mode-map)
106 (make-local-variable 'paragraph-separate)
107 (setq paragraph-separate "[^\^@-\^?]")
108 (make-local-variable 'paragraph-start)
109 (setq paragraph-start "\t")
110 (setq truncate-lines t)
111 (setq major-mode 'Edit-options-mode)
112 (setq mode-name "Options")
113 (run-mode-hooks 'Edit-options-mode-hook))
115 (defun Edit-options-set () (interactive)
117 (lambda (var) (eval-minibuffer (concat "New " (symbol-name var) ": ")))))
119 (defun Edit-options-toggle () (interactive)
120 (Edit-options-modify (lambda (var) (not (symbol-value var)))))
122 (defun Edit-options-t () (interactive)
123 (Edit-options-modify (lambda (var) t)))
125 (defun Edit-options-nil () (interactive)
126 (Edit-options-modify (lambda (var) nil)))
128 (defun Edit-options-modify (modfun)
130 (let ((buffer-read-only nil) var pos)
131 (re-search-backward "^;; \\|\\`")
135 (narrow-to-region pos (progn (end-of-line) (1- (point))))
137 (setq var (read (current-buffer))))
142 (set var (funcall modfun var)))
144 (prin1 (symbol-value var) (current-buffer)))))
148 ;;; arch-tag: d18211a1-f3fb-48c9-a449-d5acde406a3c
149 ;;; options.el ends here