Mercurial > emacs
comparison lisp/forms.el @ 7863:c4adb7401604
(forms-mode): Plug security hole by disabling `eval-buffer' unless
`enable-local-eval' is set to t.
Correct setting of `forms--mode-setup'.
(forms--local-write-file-function): New function to be used as
`local-write-file-hooks'.
(forms-mode): Use it.
(forms-find-file,forms-find-file-other-window): Locally set
`enable-local-eval' and `enable-local-variables' to t.
(forms-find-file-other-window): Remove extraneous call to
`eval-current-buffer'.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 13 Jun 1994 12:07:44 +0000 |
parents | 67b7d1ea7b2e |
children | 8d790a29a13a |
comparison
equal
deleted
inserted
replaced
7862:0b6f46029ea2 | 7863:c4adb7401604 |
---|---|
1 ;;; forms.el -- Forms mode: edit a file as a form to fill in. | 1 ;;; forms.el -- Forms mode: edit a file as a form to fill in. |
2 ;;; Copyright (C) 1991, 1993 Free Software Foundation, Inc. | 2 ;;; Copyright (C) 1991, 1993 Free Software Foundation, Inc. |
3 | 3 |
4 ;; Author: Johan Vromans <jv@nl.net> | 4 ;; Author: Johan Vromans <jv@nl.net> |
5 ;; Version: $Revision: 2.5 $ | 5 ;; Version: $Revision: 2.6 $ |
6 | 6 |
7 ;; This file is part of GNU Emacs. | 7 ;; This file is part of GNU Emacs. |
8 | 8 |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | 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 | 10 ;; it under the terms of the GNU General Public License as published by |
264 ;;; Global variables and constants: | 264 ;;; Global variables and constants: |
265 | 265 |
266 (provide 'forms) ;;; official | 266 (provide 'forms) ;;; official |
267 (provide 'forms-mode) ;;; for compatibility | 267 (provide 'forms-mode) ;;; for compatibility |
268 | 268 |
269 (defconst forms-version (substring "$Revision: 2.5 $" 11 -2) | 269 (defconst forms-version (substring "$Revision: 2.6 $" 11 -2) |
270 "The version number of forms-mode (as string). The complete RCS id is: | 270 "The version number of forms-mode (as string). The complete RCS id is: |
271 | 271 |
272 $Id: forms.el,v 2.5 1994/05/07 01:52:42 kwzh Exp rms $") | 272 $Id: forms.el,v 2.6 1994/05/22 22:07:37 rms Exp rms $") |
273 | 273 |
274 (defvar forms-mode-hooks nil | 274 (defvar forms-mode-hooks nil |
275 "Hook functions to be run upon entering Forms mode.") | 275 "Hook functions to be run upon entering Forms mode.") |
276 | 276 |
277 ;;; Mandatory variables - must be set by evaluating the control file. | 277 ;;; Mandatory variables - must be set by evaluating the control file. |
442 (make-local-variable 'forms-ro-face) | 442 (make-local-variable 'forms-ro-face) |
443 (make-local-variable 'forms-rw-face))) | 443 (make-local-variable 'forms-rw-face))) |
444 | 444 |
445 ;; eval the buffer, should set variables | 445 ;; eval the buffer, should set variables |
446 ;;(message "forms: processing control file...") | 446 ;;(message "forms: processing control file...") |
447 (eval-current-buffer) | 447 ;; If enable-local-eval is not set to t the user is asked first. |
448 (if (or (eq enable-local-eval t) | |
449 (yes-or-no-p | |
450 (concat "Evaluate lisp code in buffer " | |
451 (buffer-name) " to display forms "))) | |
452 (eval-current-buffer) | |
453 (error "`enable-local-eval' inhibits buffer evaluation")) | |
448 | 454 |
449 ;; check if the mandatory variables make sense. | 455 ;; check if the mandatory variables make sense. |
450 (or forms-file | 456 (or forms-file |
451 (error (concat "Forms control file error: " | 457 (error (concat "Forms control file error: " |
452 "'forms-file' has not been set"))) | 458 "'forms-file' has not been set"))) |
512 (erase-buffer) | 518 (erase-buffer) |
513 | 519 |
514 ;;(message "forms: setting up... done.") | 520 ;;(message "forms: setting up... done.") |
515 )) | 521 )) |
516 | 522 |
523 ;; initialization done | |
524 (setq forms--mode-setup t) | |
525 | |
517 ;; Copy desired faces to the actual variables used by the forms formatter. | 526 ;; Copy desired faces to the actual variables used by the forms formatter. |
518 (if (fboundp 'make-face) | 527 (if (fboundp 'make-face) |
519 (progn | 528 (progn |
520 (make-local-variable 'forms--ro-face) | 529 (make-local-variable 'forms--ro-face) |
521 (make-local-variable 'forms--rw-face) | 530 (make-local-variable 'forms--rw-face) |
593 (run-hooks 'forms-mode-hooks) | 602 (run-hooks 'forms-mode-hooks) |
594 ;;(message "forms: setting up... done.") | 603 ;;(message "forms: setting up... done.") |
595 | 604 |
596 ;; be helpful | 605 ;; be helpful |
597 (forms--help) | 606 (forms--help) |
598 | 607 ) |
599 ;; initialization done | |
600 (setq forms--mode-setup t)) | |
601 | 608 |
602 (defun forms--process-format-list () | 609 (defun forms--process-format-list () |
603 ;; Validate `forms-format-list' and set some global variables. | 610 ;; Validate `forms-format-list' and set some global variables. |
604 ;; Symbols in the list are evaluated, and consecutive strings are | 611 ;; Symbols in the list are evaluated, and consecutive strings are |
605 ;; concatenated. | 612 ;; concatenated. |
1161 (current-global-map)) | 1168 (current-global-map)) |
1162 (substitute-key-definition 'end-of-buffer 'forms-last-record | 1169 (substitute-key-definition 'end-of-buffer 'forms-last-record |
1163 (current-local-map) | 1170 (current-local-map) |
1164 (current-global-map)))) | 1171 (current-global-map)))) |
1165 ;; | 1172 ;; |
1166 ;; save-buffer -> forms--save-buffer | 1173 ;; Use local-write-file-hooks to invoke our own buffer save |
1174 ;; function. Note however that it usually does not work. | |
1167 (make-local-variable 'local-write-file-hooks) | 1175 (make-local-variable 'local-write-file-hooks) |
1168 (add-hook 'local-write-file-hooks | 1176 (add-hook 'local-write-file-hooks 'forms--local-write-file-function) |
1169 (function | 1177 ;; We have our own revert function - use it. |
1170 (lambda (nil) | |
1171 (forms--checkmod) | |
1172 (save-excursion | |
1173 (set-buffer forms--file-buffer) | |
1174 (save-buffer)) | |
1175 t))) | |
1176 ;; We have our own revert function - use it | |
1177 (make-local-variable 'revert-buffer-function) | 1178 (make-local-variable 'revert-buffer-function) |
1178 (setq revert-buffer-function 'forms-revert-buffer) | 1179 (setq revert-buffer-function 'forms--revert-buffer) |
1179 | 1180 |
1180 t) | 1181 t) |
1181 | 1182 |
1182 (defun forms--help () | 1183 (defun forms--help () |
1183 "Initial help for Forms mode." | 1184 "Initial help for Forms mode." |
1364 | 1365 |
1365 ;;;###autoload | 1366 ;;;###autoload |
1366 (defun forms-find-file (fn) | 1367 (defun forms-find-file (fn) |
1367 "Visit a file in Forms mode." | 1368 "Visit a file in Forms mode." |
1368 (interactive "fForms file: ") | 1369 (interactive "fForms file: ") |
1369 (find-file-read-only fn) | 1370 (let ((enable-local-eval t) |
1370 (or forms--mode-setup (forms-mode t))) | 1371 (enable-local-variables t)) |
1372 (find-file-read-only fn) | |
1373 (or forms--mode-setup (forms-mode t)))) | |
1371 | 1374 |
1372 ;;;###autoload | 1375 ;;;###autoload |
1373 (defun forms-find-file-other-window (fn) | 1376 (defun forms-find-file-other-window (fn) |
1374 "Visit a file in Forms mode in other window." | 1377 "Visit a file in Forms mode in other window." |
1375 (interactive "fFbrowse file in other window: ") | 1378 (interactive "fFbrowse file in other window: ") |
1376 (find-file-other-window fn) | 1379 (let ((enable-local-eval t) |
1377 (eval-current-buffer) | 1380 (enable-local-variables t)) |
1378 (or forms--mode-setup (forms-mode t))) | 1381 (find-file-other-window fn) |
1382 (or forms--mode-setup (forms-mode t)))) | |
1379 | 1383 |
1380 (defun forms-exit (query) | 1384 (defun forms-exit (query) |
1381 "Normal exit from Forms mode. Modified buffers are saved." | 1385 "Normal exit from Forms mode. Modified buffers are saved." |
1382 (interactive "P") | 1386 (interactive "P") |
1383 (forms--exit query t)) | 1387 (forms--exit query t)) |
1606 (setq forms--current-record the-line) | 1610 (setq forms--current-record the-line) |
1607 (forms--show-record the-record) | 1611 (forms--show-record the-record) |
1608 (re-search-forward regexp nil t)))) | 1612 (re-search-forward regexp nil t)))) |
1609 (setq forms--search-regexp regexp)) | 1613 (setq forms--search-regexp regexp)) |
1610 | 1614 |
1611 (defun forms-revert-buffer (&optional arg noconfirm) | 1615 (defun forms--local-write-file-function () |
1616 "Local write file hook." | |
1617 (forms--checkmod) | |
1618 (save-excursion | |
1619 (set-buffer forms--file-buffer) | |
1620 (save-buffer)) | |
1621 t) | |
1622 | |
1623 (defun forms--revert-buffer (&optional arg noconfirm) | |
1612 "Reverts current form to un-modified." | 1624 "Reverts current form to un-modified." |
1613 (interactive "P") | 1625 (interactive "P") |
1614 (if (or noconfirm | 1626 (if (or noconfirm |
1615 (yes-or-no-p "Revert form to unmodified? ")) | 1627 (yes-or-no-p "Revert form to unmodified? ")) |
1616 (progn | 1628 (progn |