|
|
1.1 root 1: ;; Edit Options command for Emacs.
2: ;; Copyright (C) 1985 Richard M. Stallman.
3:
4: ;; This file is part of GNU Emacs.
5:
6: ;; GNU Emacs is distributed in the hope that it will be useful,
7: ;; but WITHOUT ANY WARRANTY. No author or distributor
8: ;; accepts responsibility to anyone for the consequences of using it
9: ;; or for whether it serves any particular purpose or works at all,
10: ;; unless he says so in writing. Refer to the GNU Emacs General Public
11: ;; License for full details.
12:
13: ;; Everyone is granted permission to copy, modify and redistribute
14: ;; GNU Emacs, but only under the conditions described in the
15: ;; GNU Emacs General Public License. A copy of this license is
16: ;; supposed to have been given to you along with GNU Emacs so you
17: ;; can know your rights and responsibilities. It should be in a
18: ;; file named COPYING. Among other things, the copyright notice
19: ;; and this notice must be preserved on all copies.
20:
21:
22: (defun list-options ()
23: "Display a list of Emacs user options, with values and documentation."
24: (interactive)
25: (save-excursion
26: (set-buffer (get-buffer-create "*List Options*"))
27: (Edit-options-mode))
28: (with-output-to-temp-buffer "*List Options*"
29: (let (vars)
30: (mapatoms (function (lambda (sym)
31: (let ((vdoc (get sym 'variable-documentation)))
32: (and vdoc
33: (> (length vdoc) 0)
34: (= (aref vdoc 0) ?*)
35: (setq vars (cons sym vars)))))))
36: (setq vars (sort vars 'string-lessp))
37: (while vars
38: (let ((sym (car vars)))
39: (princ ";; ")
40: (prin1 sym)
41: (princ ":\n\t")
42: (prin1 (symbol-value sym))
43: (terpri)
44: (princ (substitute-command-keys (get sym 'variable-documentation)))
45: (princ "\n;;\n"))
46: (setq vars (cdr vars))))))
47:
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*"))
56:
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: "")
68:
69: (defun Edit-options-mode ()
70: "Major mode for editing Emacs user option settings.
71: Special commands are:
72: s -- set variable point points at. New value read using minibuffer.
73: x -- toggle variable, t -> nil, nil -> t.
74: 1 -- set variable to t.
75: 0 -- set variable to nil.
76: Each variable description is a paragraph.
77: For convenience, the characters p and n move back and forward by paragraphs."
78: (kill-all-local-variables)
79: (set-syntax-table lisp-mode-syntax-table)
80: (use-local-map Edit-options-mode-map)
81: (make-local-variable 'paragraph-separate)
82: (setq paragraph-separate "[^\^@-\^?]")
83: (make-local-variable 'paragraph-start)
84: (setq paragraph-start "^\t")
85: (setq truncate-lines t)
86: (setq major-mode 'Edit-options-mode)
87: (setq mode-name "Options"))
88:
89: (defun Edit-options-set () (interactive)
90: (Edit-options-modify
91: '(lambda (var) (eval-minibuffer (concat "New " (symbol-name var) ": ")))))
92:
93: (defun Edit-options-toggle () (interactive)
94: (Edit-options-modify '(lambda (var) (not (symbol-value var)))))
95:
96: (defun Edit-options-t () (interactive)
97: (Edit-options-modify '(lambda (var) t)))
98:
99: (defun Edit-options-nil () (interactive)
100: (Edit-options-modify '(lambda (var) nil)))
101:
102: (defun Edit-options-modify (modfun)
103: (save-excursion
104: (let (var pos)
105: (re-search-backward "^;; ")
106: (forward-char 3)
107: (setq pos (point))
108: (save-restriction
109: (narrow-to-region pos (progn (end-of-line) (1- (point))))
110: (goto-char pos)
111: (setq var (read (current-buffer))))
112: (goto-char pos)
113: (forward-line 1)
114: (forward-char 1)
115: (save-excursion
116: (set var (funcall modfun var)))
117: (kill-sexp 1)
118: (prin1 (symbol-value var) (current-buffer)))))
119:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.